From 807e2c7a2ca8283ba6d6f764c83320ad5e023349 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期四, 19 三月 2020 09:01:04 +0800
Subject: [PATCH] fix   放开红点的权限

---
 src/main/java/com/highdatas/mdm/controller/SysFieldController.java |  123 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 120 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/controller/SysFieldController.java b/src/main/java/com/highdatas/mdm/controller/SysFieldController.java
index 570a0a1..470b1b2 100644
--- a/src/main/java/com/highdatas/mdm/controller/SysFieldController.java
+++ b/src/main/java/com/highdatas/mdm/controller/SysFieldController.java
@@ -15,6 +15,7 @@
 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.*;
@@ -32,6 +33,7 @@
  * @author kimi
  * @since 2019-12-16
  */
+@Slf4j
 @RestController
 @RequestMapping("/field")
 public class SysFieldController {
@@ -87,8 +89,7 @@
         if (StringUtils.isEmpty(tableName)) {
             return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
         }
-        List<SysField> fieldList = fieldService.selectList(new EntityWrapper<SysField>().eq("table_name", tableName).orderBy("order_no"));
-
+        List<SysField> fieldList = fieldService.getFieldByTable(tableName);
         return Result.success(fieldList);
     }
 
@@ -160,9 +161,114 @@
         }
     }
 
+    @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);
+        }
+        String tableName = fieldList.get(0).getTableName();
+        if (StringUtils.isEmpty(tableName)) {
+            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+        }
+        String maintainId = null;
+        MaintainField maxVersion = maintainFieldService.getMaxVersion(tableName);
+        if (maxVersion != null) {
+            maintainId = maxVersion.getId();
+        }
+
+        MaintainField nowMaintain = null;
+        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 && dataMaintainMax != null) {
+                return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+            }
+
+        }else {
+            Flows flows = flowsService.selectOne(new EntityWrapper<Flows>().eq("business_id", maintainId));
+            if (flows != null){
+                //褰撳墠宸插鎵�
+                ActivitiStatus status = flows.getStatus();
+                if (status.equals(ActivitiStatus.open) || status.equals(ActivitiStatus.close)) {
+                    nowMaintain = flowsService.createNowVerion(tableName, maintainId, userId);
+                }else {
+                    return Result.error(new CodeMsg(7002, "褰撳墠瀛楁鐗堟湰姝e湪瀹℃壒,璇峰緟瀹℃壒閫氳繃鍚庡啀淇敼"));
+                }
+
+            }else {
+                //delete
+                fieldService.delete(new EntityWrapper<SysField>().eq("maintain_field_id",maintainId));
+                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()).setMaintainFieldId(nowMaintainId).setOrderNo(i).insert();
+        }
+
+        if (nowMaintain != null) {
+            nowMaintain.insertOrUpdate();
+        }
+
+        return Result.success(null);
+    }
+
     @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;
+        }
+
         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());
+                }
+                boolean update = sysField.insertOrUpdate();
+                if (update) {
+                    return Result.success(CodeMsg.SUCCESS);
+                }else {
+                    return Result.error(CodeMsg.INSERT_ERROR);
+                }
+
+            }
+        }
+        if (isInit && operate.equals(Operate.delete)) {
+            boolean delete = sysField.deleteById();
+            if (delete) {
+                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);
@@ -171,7 +277,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;
@@ -201,6 +316,7 @@
         String userId = user.getUserId();
 
         if (operate.equals(Operate.create) || operate.equals(Operate.update)) {
+
             String alias = sysField.getAlias();
             List<SysField> fieldByMaintainField;
             if (nowMaintain == null) {
@@ -289,6 +405,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