From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001 From: kimi <kimi42345@gmail.com> Date: 星期三, 27 五月 2020 09:59:29 +0800 Subject: [PATCH] merage --- src/main/java/com/highdatas/mdm/controller/SysFieldController.java | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 210 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/highdatas/mdm/controller/SysFieldController.java b/src/main/java/com/highdatas/mdm/controller/SysFieldController.java index cecb399..831e32e 100644 --- a/src/main/java/com/highdatas/mdm/controller/SysFieldController.java +++ b/src/main/java/com/highdatas/mdm/controller/SysFieldController.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.highdatas.mdm.entity.Character; import com.highdatas.mdm.entity.*; import com.highdatas.mdm.mapper.SysFieldMapper; import com.highdatas.mdm.pojo.ActivitiStatus; @@ -12,9 +13,11 @@ import com.highdatas.mdm.pojo.Operate; import com.highdatas.mdm.pojo.Result; import com.highdatas.mdm.service.*; +import com.highdatas.mdm.util.AntianaphylaxisClient; import com.highdatas.mdm.util.Constant; import com.highdatas.mdm.util.DbUtils; import com.highdatas.mdm.util.WorkflowUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -29,9 +32,11 @@ * 鍓嶇鎺у埗鍣� * </p> * + * @description 瀛楁鎺ュ彛 * @author kimi * @since 2019-12-16 */ +@Slf4j @RestController @RequestMapping("/field") public class SysFieldController { @@ -49,26 +54,91 @@ SysFieldMapper fieldMapper; @Autowired IFlowsService flowsService; + @Autowired + IMasterAuthorService masterAuthorService; + @Autowired + AntianaphylaxisClient antianaphylaxisClient; + /** + * + * @description: 閫氳繃琛ㄥ悕鑾峰彇瀛楁鍒楄〃 + * @param tableName 琛ㄥ悕 + * @return: 瀛楁鍒楄〃 + * + */ @RequestMapping(value = "/{tableName}", method = RequestMethod.GET) public Result getFields(@PathVariable String tableName, HttpServletRequest request){ + //璇锋眰澶磋幏鍙栦娇鐢ㄨ�呭寘瑁呯被 + Character character = DbUtils.getCharacter(request); String maintainId = request.getParameter("maintainId"); if (StringUtils.isEmpty(maintainId)) { + //閫氳繃琛ㄥ悕鑾峰彇瀛楁鍒楄〃 List<SysField> fieldList = fieldService.getFieldByTable(tableName); + String isDataIO = request.getParameter("isDataIO"); + if (StringUtils.isEmpty(isDataIO) && !Boolean.valueOf(isDataIO)) { + + return Result.success(fieldList); + } + //缁欎笂浼犱笅杞戒娇鐢� 缁勫悎濂藉緟鑴辨晱鐨勬暟鎹繑鍥� + antianaphylaxisClient.getHelpfulFieldBySysField(fieldList, tableName); return Result.success(fieldList); }else { + //BY 鐗堟湰鑾峰彇瀛楁 + List<SysField> field = masterAuthorService.getField(character, maintainId); + //List<SysField> fieldList = fieldService.getFieldByMaintain(maintainId); - List<SysField> fieldList = fieldService.getFieldByMaintain(maintainId); - return Result.success(fieldList); + return Result.success(field); } } - @RequestMapping(value = "total/{tableName}", method = RequestMethod.GET) - public Result getTotalFields(@PathVariable String tableName, HttpServletRequest request){ - return fieldService.getTotalFields(tableName); - } + /** + * + * @description: 閫氳繃琛ㄥ悕鍒嗛〉鑾峰彇瀛楁鍒楄〃 + * @param tableName 琛ㄥ悕 + * @param pageNo 椤垫暟 + * @return: 瀛楁鍒楄〃 + * + */ + @RequestMapping(value = "total/{tableName}/{pageNo}", method = RequestMethod.GET) + public Result getTotalFields(@PathVariable String tableName,@PathVariable Integer pageNo, HttpServletRequest request){ + //isTotal 鏄惁璧版潈闄愶紝 pageSize 姣忛〉鏁版嵁鏁� + String totalStr = request.getParameter("isTotal"); + String pageSize = request.getParameter("pageSize"); + if (StringUtils.isEmpty(totalStr) || !Boolean.valueOf(totalStr)) { + // 璧版潈闄� + String maintainId = request.getParameter("maintainId"); + if (StringUtils.isEmpty(maintainId)){ + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇鐢ㄦ埛 + TUser user = DbUtils.getUser(request); + List<SysField> field = masterAuthorService.getField(user, maintainId); + Integer size; + if(StringUtils.isEmpty(pageSize)){ + size = 15; + }else { + size = Integer.valueOf(pageSize); + } + + return fieldService.getPagedDataByList(field, pageNo, size); + + } + //鑾峰彇瀛楁鍒楄〃 + if(StringUtils.isEmpty(pageSize)){ + return fieldService.getTotalFields(tableName, pageNo, 15); + }else { + return fieldService.getTotalFields(tableName, pageNo, Integer.valueOf(pageSize)); + } + } + /** + * + * @description: 閫氳繃琛ㄥ悕鑾峰彇褰撳墠绯荤粺涓悇绉嶇姸鎬佺殑瀛楁鍒楄〃 + * @param tableName 琛ㄥ悕 + * @return: 瀛楁鍒楄〃 + * + */ @RequestMapping(value = "fix/{tableName}", method = RequestMethod.GET) public Result fix(@PathVariable String tableName, HttpServletRequest request){ Result totalFields = fieldService.getTotalFields(tableName); @@ -77,12 +147,20 @@ return totalFields; } + /** + * + * @description: 閫氳繃涓婚鑾峰彇瀛楁閲岃緭鍏ヨ〃 + * @param id 涓婚id + * @return: 瀛楁鍒楄〃 + * + */ @RequestMapping(value = "/menu/{id}", method = RequestMethod.GET) public Result getFieldByMenu(@PathVariable String id){ MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", id)); if (menuMapping == null) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); } + //閫氳繃涓婚鑾疯幏鍙栬〃鍚� String tableName = menuMapping.getTableName(); if (StringUtils.isEmpty(tableName)) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); @@ -90,7 +168,12 @@ List<SysField> fieldList = fieldService.getFieldByTable(tableName); return Result.success(fieldList); } - + /** + * + * @description: 鏇存柊瀛楁鏁版嵁 + * @return: 鏇存柊鏄惁鎴愬姛 + * + */ @RequestMapping(value = "/update", method = RequestMethod.GET) public Result update(@RequestParam String json) { try { @@ -106,7 +189,13 @@ } } - + /** + * + * @description: 鏇存柊鍩虹鍙傛暟 + * @param id sys_field 鏁版嵁id + * @return: 鏄惁鏇存柊瀹屾垚 + * + */ @RequestMapping(value = "/updateCommon/{id}", method = RequestMethod.GET) public Result addOrUpdate(@PathVariable String id, HttpServletRequest request) { //鏇存柊鍩虹鍙傛暟涓嶉渶瑕佸叧鑱旂増鏈� @@ -114,6 +203,7 @@ if (sysField == null) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); } + //鍙洿鎺ユ洿鏂扮殑鍙傛暟 String width = request.getParameter("width"); String align = request.getParameter("align"); String orderNoStr = request.getParameter("orderNo"); @@ -159,8 +249,15 @@ } } + /** + * + * @description: 涓婁紶鍚庣敓鎴愮殑瀛楁淇濆瓨鍏ュ簱 + * @return: 鏄惁淇濆瓨鎴愬姛 + * + */ @RequestMapping(value = "/loadFields", method = RequestMethod.POST) public Result loadFields(@RequestBody String fieldListStr, HttpServletRequest request) { + log.info(fieldListStr); List<SysField> fieldList = JSONObject.parseArray(fieldListStr,SysField.class); if (fieldList.size() == 0) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); @@ -179,11 +276,13 @@ HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String userId = user.getUserId(); + Maintain dataMaintainMax = maintainService.getMaxVersion(tableName); if (StringUtils.isEmpty(maintainId)) { //鍒涘缓鏂扮増鏈殑瀛楁 nowMaintain = flowsService.createNowVerion(tableName, maintainId, userId); - if (nowMaintain == null) { + + if (nowMaintain == null && dataMaintainMax != null) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); } @@ -204,17 +303,99 @@ nowMaintain = maintainFieldService.selectById(maintainId); } } + String nowMaintainId; + if (dataMaintainMax == null) { + nowMaintainId = null; + }else { + nowMaintainId = nowMaintain.getId(); + } + + + if (StringUtils.isEmpty(nowMaintainId)) { + //绗竴娆¢粯璁ら兘娓呯┖ + fieldService.delete(new EntityWrapper<SysField>().isNull("maintain_field_id").eq("table_name", tableName)); + } + for (int i = 0; i < fieldList.size(); i++) { SysField sysField = fieldList.get(i); - sysField.setCreateTime(new Date()).setId(DbUtils.getUUID()).setOperate(Operate.create).setMaintainFieldId(nowMaintain.getId()).setOrderNo(i).insert(); + sysField.setCreateTime(new Date()).setId(DbUtils.getUUID()).setMaintainFieldId(nowMaintainId).setOrderNo(i).insert(); } - nowMaintain.insertOrUpdate(); + + if (nowMaintain != null) { + nowMaintain.insertOrUpdate(); + } + return Result.success(null); } - + /** + * + * @description: 淇敼瀛楁 + * @return: 淇敼鍚庣殑瀛楁 + * + */ @RequestMapping(value = "/change", method = RequestMethod.POST) public Result addOrUpdate(@RequestBody SysField sysField, HttpServletRequest request) { + + String tableName = sysField.getTableName(); + + Maintain dataMaxVersion = maintainService.getMaxVersion(tableName); + boolean isInit = false; + if (dataMaxVersion == null) { + isInit = true; + } + if (!StringUtils.isEmpty(sysField.getId())) { + String id = sysField.getId(); + SysField field = fieldService.selectById(id); + if (field != null){ + Operate operate = field.getOperate(); + if (operate != null) { + isInit = true; + } + } + } + Operate operate = sysField.getOperate(); + + if (isInit && (operate.equals(Operate.update) || operate.equals(Operate.create))) { + if (isInit) { + if (StringUtils.isEmpty(sysField.getId())) { + sysField.setId(DbUtils.getUUID()); + } + sysField.setOperate(null); + boolean update = sysField.insertOrUpdate(); + if (update) { + return Result.success(CodeMsg.SUCCESS); + }else { + return Result.error(CodeMsg.INSERT_ERROR); + } + + } + } + if (isInit && operate.equals(Operate.delete)) { + String maintainFieldId = sysField.getMaintainFieldId(); + boolean delete = sysField.deleteById(); + if (delete) { + //鍒犻櫎鍚� 鍒ゆ柇鏄惁鏈夋湭鎻愪氦鐨勪簡 + if (StringUtils.isEmpty(maintainFieldId)) { + return Result.success(CodeMsg.SUCCESS); + } + List<SysField> fieldList = fieldService.selectList(new EntityWrapper<SysField>().eq("maintain_field_id", maintainFieldId)); + long count = fieldList.stream().filter(field -> field.getOperate() != null).count(); + if (count == 0) { + //璇存槑 褰撳墠鐗堟湰娌℃湁淇敼鐨勫瓧娈典簡 + delete = fieldService.delete(new EntityWrapper<SysField>().eq("maintain_field_id", maintainFieldId)); + delete = maintainFieldService.deleteById(maintainFieldId); + if (delete) { + return Result.success(CodeMsg.SUCCESS); + } + } + return Result.success(CodeMsg.SUCCESS); + + }else { + return Result.error(CodeMsg.DELETE_ERROR); + } + } + if (operate.equals(Operate.update)) { String id = sysField.getId(); SysField field = fieldService.selectById(id); @@ -223,7 +404,16 @@ } boolean visiableEqual = field.getVisible().equals(sysField.getVisible()); boolean aliasEqual = field.getAlias().equals(sysField.getAlias()); - boolean codeEqual = field.getCode().equals(sysField.getCode()); + String updateCode = field.getCode(); + String preCode = sysField.getCode(); + boolean codeEqual; + if (StringUtils.isEmpty(updateCode) && StringUtils.isEmpty(preCode)) { + codeEqual = true; + }else if(!StringUtils.isEmpty(updateCode) && !StringUtils.isEmpty(preCode) && updateCode.equalsIgnoreCase(preCode)){ + codeEqual = true; + }else { + codeEqual = false; + } String updateFormat = field.getFormat(); String preFormat = sysField.getFormat(); boolean formatterEqual; @@ -246,13 +436,18 @@ } } MaintainField maxVersion = maintainFieldService.getMaxVersion(sysField.getTableName()); - String maintainId = maxVersion.getId(); + String maintainId = null; + if(maxVersion != null) { + maintainId = maxVersion.getId(); + } + MaintainField nowMaintain = null; HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String userId = user.getUserId(); if (operate.equals(Operate.create) || operate.equals(Operate.update)) { + String alias = sysField.getAlias(); List<SysField> fieldByMaintainField; if (nowMaintain == null) { @@ -341,6 +536,7 @@ sysField.updateById(); } else if(operate.equals(Operate.delete)) { + SysField relatedField = fieldService.getOneFieldByMaintainField(nowMaintain.getId(), sysField.getField()); if (relatedField == null) { return Result.error(CodeMsg.OPERATR_ERROR); -- Gitblit v1.8.0