From f694f6ac8336866061a0caf8ff6b149a3d1f4a4b Mon Sep 17 00:00:00 2001 From: 杜洪波 <1074825718@qq.com> Date: 星期二, 27 八月 2024 17:19:23 +0800 Subject: [PATCH] 代码提交 --- src/main/java/com/product/file/service/DocumentDirectoryService.java | 90 ++++++++-------------- src/main/java/com/product/file/controller/DocumentDirectoryController.java | 82 ++------------------ src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java | 22 +--- 3 files changed, 47 insertions(+), 147 deletions(-) diff --git a/src/main/java/com/product/file/controller/DocumentDirectoryController.java b/src/main/java/com/product/file/controller/DocumentDirectoryController.java index 32ed83a..0537848 100644 --- a/src/main/java/com/product/file/controller/DocumentDirectoryController.java +++ b/src/main/java/com/product/file/controller/DocumentDirectoryController.java @@ -69,89 +69,23 @@ DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText()); } } - + /** - * 鏂板鏂囦欢澶规暟鎹� + * 鏂囨。鐩綍淇濆瓨 * * @param request * @return */ - @RequestMapping(value = "/addDocumentDirectory/{version}", method = RequestMethod.POST) + @RequestMapping(value = "/save-directory/{version}", method = RequestMethod.POST) @ApiVersion(1) - public String addDocumentDirectory(HttpServletRequest request) { + public String saveDocumentDireactory(HttpServletRequest request) { try { - // 鑾峰彇鍙傛暟 - FieldSetEntity fse = null; - Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); - if (bean != null) { - RequestParameterEntity reqp = (RequestParameterEntity) bean; - fse = reqp.getFormData(); - } - // 鍒ゆ柇鍙傛暟鏄惁涓虹┖ - if (fse == null) { - SpringMVCContextHolder.getSystemLogger().error(DocumentCode.DOCUMENT_FORM_NODATA.getValue(), - DocumentCode.DOCUMENT_FORM_NODATA.getText()); - return this.error(DocumentCode.DOCUMENT_FORM_NODATA.getValue(), - DocumentCode.DOCUMENT_FORM_NODATA.getText()); - } + FieldSetEntity fse = BaseUtil.getFieldSetEntity(request); IDocumentDirectoryService service = (IDocumentDirectoryService) getProxyInstance(documentDirectoryService); - return OK_Add(service.addDocumentDirectory(fse)); - } catch (BaseException e) { - SpringMVCContextHolder.getSystemLogger().error(e); - return this.error(e); - } catch (Exception e) { - e.printStackTrace(); - SpringMVCContextHolder.getSystemLogger().error(e); - return this.error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(), - DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText()); - } - } - - /** - * 淇敼鏂囦欢澶� - * - * @param request - * @return - */ - @RequestMapping(value = "/upDocumentDirectory/{version}", method = RequestMethod.POST) - @ApiVersion(1) - public String upDocumentDirectory(HttpServletRequest request) { - try { - // 鑾峰彇鍙傛暟 - FieldSetEntity fse = null; - Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); - if (bean != null) { - RequestParameterEntity reqp = (RequestParameterEntity) bean; - fse = reqp.getFormData(); - } - // 鍒ゆ柇鍙傛暟鏄惁涓虹┖ - if (fse == null) { - SpringMVCContextHolder.getSystemLogger().error(DocumentCode.DOCUMENT_FORM_NODATA.getValue(), - DocumentCode.DOCUMENT_FORM_NODATA.getText()); - return this.error(DocumentCode.DOCUMENT_FORM_NODATA.getValue(), - DocumentCode.DOCUMENT_FORM_NODATA.getText()); - } - String uuid = fse.getString(CmnConst.UUID);// 琛╱uid - // 瓒呯骇绠$悊鍛樹负1 鏅�氬崟浣嶇鐞嗗憳2 - SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); - int type; - if (currentUser.getUserType() == 2) { - type = CoreConst.DATA_PERMISSION_VALID_TYPE_ORG; - } else { - type = CoreConst.DATA_PERMISSION_VALID_TYPE_USER; - } - // 鏁版嵁鎿嶄綔鐨勬潈闄愰獙璇� - if (!permissionService.validDataPermission(CmnConst.PRODUCT_OA_DIRECTORY, uuid, type)) { - SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), - SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); - return this.error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(), - SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText()); - } - IDocumentDirectoryService service = (IDocumentDirectoryService) getProxyInstance(documentDirectoryService); - if (service.upDocumentDirectory(fse)) { + if(service.saveDocumentDireactory(fse)) { return OK(); } - return this.error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(), + return error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(), DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText()); } catch (BaseException e) { SpringMVCContextHolder.getSystemLogger().error(e); @@ -159,7 +93,7 @@ } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); - return this.error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(), + return error(DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getValue(), DocumentCode.DOCUMENT_CATALOG_SAVE_FAIL.getText()); } } diff --git a/src/main/java/com/product/file/service/DocumentDirectoryService.java b/src/main/java/com/product/file/service/DocumentDirectoryService.java index 7d9dd21..99e1cc3 100644 --- a/src/main/java/com/product/file/service/DocumentDirectoryService.java +++ b/src/main/java/com/product/file/service/DocumentDirectoryService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.product.common.collect.ListUtils; import com.product.common.lang.DateUtils; +import com.product.core.config.CoreConst; import com.product.core.dao.BaseDao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; @@ -52,68 +53,41 @@ return dtTree; } - @Override + /** + * 鏂囨。鐩綍淇濆瓨 + * @param fse + * @return + */ @Transactional - public String addDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException { - - String triCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_OA_DIRECTORY, CmnConst.TRICODE, - !StringUtils.isEmpty(fieldSetEntity.getString(CmnConst.TRICODE_PARENT)) - ? fieldSetEntity.getString(CmnConst.TRICODE_PARENT) - : ""); - fieldSetEntity.setValue(CmnConst.TRICODE, triCode); - String[] codes = triCode.split("-"); - String org_level_uuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid(); - fieldSetEntity.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid); - fieldSetEntity.setValue(CmnConst.DIRECTORY_TIER, codes.length); - fieldSetEntity.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 鑾峰彇鐧诲綍甯愬彿 - fieldSetEntity.setValue(CmnConst.CREATED_UTC_DATETIME, DateUtils.getDateTime());// 鍒涘缓鏃堕棿 - return baseDao.add(fieldSetEntity); - } - - @Override - @Transactional - public boolean upDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException { - String uuid = fieldSetEntity.getString(CmnConst.UUID); - FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, uuid, false); - String tricode_parent1 = fieldSetEntity.getString(CmnConst.TRICODE_PARENT); - String tricode_parent2 = fieldSet.getString(CmnConst.TRICODE_PARENT); - boolean flag; - // 涓婄骇鐩綍tricode濡傛灉涓嶇浉绛� - if (!StringUtils.isEmpty(tricode_parent1) || !StringUtils.isEmpty(tricode_parent2)) { - if (!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2) - && !tricode_parent1.equals(tricode_parent2)) { - flag = true; - } else if (!StringUtils.isEmpty(tricode_parent1) && !StringUtils.isEmpty(tricode_parent2) - && tricode_parent1.equals(tricode_parent2)) { - flag = false; - } else if (!StringUtils.isEmpty(tricode_parent1) && StringUtils.isEmpty(tricode_parent2)) { - tricode_parent2 = ""; - flag = true; - } else if (!StringUtils.isEmpty(tricode_parent2) && StringUtils.isEmpty(tricode_parent1)) { - tricode_parent1 = ""; - flag = true; - } else { - flag = false; - } + public boolean saveDocumentDireactory(FieldSetEntity fse) { + BaseUtil.createCreatorAndCreationTime(fse); + String tricode = null; + String tricodeParent = BaseUtil.strIsNull(fse.getString(CmnConst.TRICODE_PARENT)) ? "" : fse.getString(CmnConst.TRICODE_PARENT); + if(BaseUtil.strIsNull(fse.getUUID())) { + tricode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_OA_DIRECTORY, CmnConst.TRICODE, tricodeParent); } else { - flag = false; + FieldSetEntity fseOrigin = baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_DIRECTORY, fse.getUUID(), false); + if(fseOrigin == null) { + fse.remove(CoreConst.UUID); + } + String originParent = BaseUtil.strIsNull(fseOrigin.getString(CmnConst.TRICODE_PARENT)) ? "" : fseOrigin.getString(CmnConst.TRICODE_PARENT); + if (!originParent.equals(tricodeParent)) { + String originTricode = BaseUtil.strIsNull(fseOrigin.getString(CmnConst.TRICODE)) ? "" : fseOrigin.getString(CmnConst.TRICODE); + tricode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_OA_DIRECTORY, CmnConst.TRICODE, tricodeParent); + StringBuilder sql = new StringBuilder(); + sql.append("update product_oa_directory "); + sql.append("set tricode=concat(replace(substring(tricode,1,locate(?,tricode)+length(?)),?,?),substring(tricode,locate(?,tricode)+length(?)+1)), "); + sql.append("tricode_parent=concat(replace(substring(tricode_parent,1,locate(?,tricode_parent)+length(?)),?,?),substring(tricode_parent,locate(?,tricode_parent)+length(?)+1)) "); + sql.append("where tricode like ? "); + baseDao.executeUpdate(sql.toString(), new Object[] {originTricode,originTricode,originTricode,tricode,originTricode,originTricode, + originTricode,originTricode,originTricode,tricode,originTricode,originTricode,originTricode+"-%"}); + } } - - if (flag) { - StringBuffer sql = new StringBuffer(); - sql.append(" update PRODUCT_OA_directory set tricode=replace("); - sql.append(" tricode,concat(?,'-'),concat(?,'-')),"); - sql.append(" tricode_parent=(case when tricode_parent=? then replace(tricode_parent,?,?) else "); - sql.append(" replace (tricode_parent,concat(?,'-'),concat(?,'-')) end )"); - sql.append(" where tricode like ?"); - baseDao.executeUpdate(sql.toString(), new String[] { tricode_parent1, tricode_parent2, tricode_parent1, - tricode_parent1, tricode_parent2, tricode_parent1, tricode_parent2, tricode_parent1 + "-%", }); - } - - fieldSetEntity.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 鑾峰彇鐧诲綍甯愬彿 - fieldSetEntity.setValue(CmnConst.UPDATED_UTC_DATETIME, DateUtils.getDateTime());// 鍒涘缓鏃堕棿 - return baseDao.update(fieldSetEntity); + fse.setValue(CmnConst.TRICODE, tricode); + fse.setValue(CmnConst.DIRECTORY_TIER, tricode.split(",").length); + return baseDao.saveFieldSetEntity(fse); } + @Override @Transactional diff --git a/src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java b/src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java index 377d7b1..6893feb 100644 --- a/src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java +++ b/src/main/java/com/product/file/service/ide/IDocumentDirectoryService.java @@ -16,22 +16,14 @@ * @Description: 鏂囦欢澶圭鐞嗘帴鍙� */ public interface IDocumentDirectoryService { - /** - * 鏂板鏂囨。鐩綍 - * @param - * @return - * @throws BaseException - */ - String addDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException; - /** - * 淇敼鏂囨。鐩綍 - * @param - * @return - * @throws BaseException - */ - boolean upDocumentDirectory(FieldSetEntity fieldSetEntity) throws BaseException; - + /** + * 鏂囨。鐩綍淇濆瓨 + * @param fse + * @return + */ + boolean saveDocumentDireactory(FieldSetEntity fse); + /** * 鍒犻櫎鏂囨。鐩綍 * @param -- Gitblit v1.9.2