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 |  151 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 141 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/controller/SysFieldController.java b/src/main/java/com/highdatas/mdm/controller/SysFieldController.java
index 470b1b2..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,6 +13,7 @@
 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;
@@ -30,6 +32,7 @@
  *  鍓嶇鎺у埗鍣�
  * </p>
  *
+ * @description 瀛楁鎺ュ彛
  * @author kimi
  * @since 2019-12-16
  */
@@ -51,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);
@@ -79,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);
@@ -92,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 {
@@ -108,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)  {
         //鏇存柊鍩虹鍙傛暟涓嶉渶瑕佸叧鑱旂増鏈�
@@ -116,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");
@@ -161,6 +249,12 @@
         }
     }
 
+    /**
+     *
+     * @description:  涓婁紶鍚庣敓鎴愮殑瀛楁淇濆瓨鍏ュ簱
+     * @return: 鏄惁淇濆瓨鎴愬姛
+     *
+     */
     @RequestMapping(value = "/loadFields", method = RequestMethod.POST)
     public Result loadFields(@RequestBody String fieldListStr, HttpServletRequest request)  {
         log.info(fieldListStr);
@@ -233,7 +327,12 @@
 
         return Result.success(null);
     }
-
+    /**
+     *
+     * @description:  淇敼瀛楁
+     * @return: 淇敼鍚庣殑瀛楁
+     *
+     */
     @RequestMapping(value = "/change", method = RequestMethod.POST)
     public Result addOrUpdate(@RequestBody SysField sysField, HttpServletRequest request)  {
 
@@ -244,6 +343,16 @@
         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();
 
@@ -252,6 +361,7 @@
                 if (StringUtils.isEmpty(sysField.getId())) {
                     sysField.setId(DbUtils.getUUID());
                 }
+                sysField.setOperate(null);
                 boolean update = sysField.insertOrUpdate();
                 if (update) {
                     return Result.success(CodeMsg.SUCCESS);
@@ -262,13 +372,30 @@
             }
         }
         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);
@@ -309,7 +436,11 @@
             }
         }
         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");

--
Gitblit v1.8.0