From b5636e416a2fe029f96aec6ddfd3489394925b15 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期二, 24 三月 2020 19:33:53 +0800
Subject: [PATCH] add 数据权限

---
 src/main/java/com/highdatas/mdm/controller/MasterDataController.java |  162 ++++++++++++++++++------------------------------------
 1 files changed, 54 insertions(+), 108 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/controller/MasterDataController.java b/src/main/java/com/highdatas/mdm/controller/MasterDataController.java
index b2bbb0f..d33f3d5 100644
--- a/src/main/java/com/highdatas/mdm/controller/MasterDataController.java
+++ b/src/main/java/com/highdatas/mdm/controller/MasterDataController.java
@@ -8,10 +8,8 @@
 import com.highdatas.mdm.pojo.CodeMsg;
 import com.highdatas.mdm.pojo.Operate;
 import com.highdatas.mdm.pojo.Result;
-import com.highdatas.mdm.service.IMaintainDetailService;
-import com.highdatas.mdm.service.IMaintainService;
-import com.highdatas.mdm.service.IMenuMappingService;
-import com.highdatas.mdm.service.MasterDataService;
+import com.highdatas.mdm.pojo.SysAssembleUpdateType;
+import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.util.Constant;
 import com.highdatas.mdm.util.DbUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -50,69 +48,21 @@
     @Autowired
     TableInfoMapper tableInfoMapper;
 
+    @Autowired
+    IMasterModifiedService masterModifiedService;
+
     @RequestMapping(value = "{tableName}/uploaded",  method = RequestMethod.GET)
     public Result get(@PathVariable String tableName, HttpServletRequest request) {
-        String uploadType = request.getParameter("uploadType");
-        if (StringUtils.isEmpty(uploadType)) {
-            uploadType = Constant.All;
+        String uploadTypeStr = request.getParameter("uploadType");
+        SysAssembleUpdateType uploadType;
+        if (StringUtils.isEmpty(uploadTypeStr)) {
+            uploadType = SysAssembleUpdateType.Increment;
         }
-        MenuMapping menuMapping = menuMappingService.selectOne(new EntityWrapper<MenuMapping>().eq("table_name",tableName));
-        SysOperateLog operateLog = new SysOperateLog();
-
-        Maintain maxVersion = maintainService.getMaxVersion(tableName);
-        Maintain maintain = new Maintain();
-        String biggerVersion = null;
-        if (maxVersion == null) {
-            biggerVersion = Constant.VERSION_Default;
-            maintain.setOrderNo(0);
-            operateLog.setOperate("鍒濆鍖栦富棰樻暟鎹�");
-        } else {
-            operateLog.setOperate("鏇存柊涓婚");
-            String flowId = maxVersion.getFlowId();
-            String mVersion = maxVersion.getVersion();
-            if (StringUtils.isEmpty(flowId)) {
-                biggerVersion = mVersion;
-                maintain.setOrderNo(maxVersion.getOrderNo());
-                String tempName = maxVersion.getTableName() + Constant.RECORD;
-
-                tableInfoMapper.deleteTempByMaintainId(tempName, DbUtils.quotedStr(maxVersion.getId()));
-                maintainDetailService.delete(new EntityWrapper<MaintainDetail>().eq("parent_id", maxVersion.getId()));
-
-                maxVersion.deleteById();
-            }else {
-                biggerVersion = DbUtils.versionAddBig(mVersion);
-                maintain.setOrderNo(DbUtils.getOrderNoAdd(maxVersion.getOrderNo()));
-            }
-        }
-
-        String uuid = DbUtils.getUUID();
-        maintain.setId(uuid);
+        uploadType = SysAssembleUpdateType.valueOf(uploadTypeStr);
         TUser user = (TUser) request.getSession().getAttribute(Constant.USER);
-        if (user == null) {
-            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
-        }
-        maintain.setVersion(biggerVersion);
-        maintain.setChargeId(user.getUserId());
-        maintain.setTableName(tableName);
-        maintain.setCreateTime(new Date());
-
-
-        tableInfoMapper.insertMatintainDetailFromTemp(DbUtils.quotedStr(maintain.getId()), maintain.getTableName() + Constant.RECORD);
-
-        tableInfoMapper.updateStdId( maintain.getTableName() + Constant.RECORD);
-
-        Long aLong = tableInfoMapper.tempDeal(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(maintain.getId()));
-
-        maintain.setDesp(MessageFormat.format("涓婁紶鏁版嵁{0}鏉�", aLong));
-
-        operateLog.setCreateTime(new Date())
-                .setMaintainId(maintain.getId())
-                .setId(DbUtils.getUUID())
-                .setMaintainId(menuMapping.getId())
-                .setOperate("open")
-                .setDesp(MessageFormat.format("涓婁紶鏁版嵁{0}鏉�", aLong));
-
-        maintain.insert();
+        Maintain maintain = masterDataService.uploadedData(tableName, uploadType, user.getUserId());
+        // 澶勭悊鍏宠仈浜�
+        masterModifiedService.dealAssemble(maintain.getId(), user.getUserId(), true);
         JSONObject object = new JSONObject();
         object.fluentPut("maintainId",maintain.getId());
         object.fluentPut("version",maintain.getVersion());
@@ -150,7 +100,11 @@
             version = String.valueOf(nowVersion.getVersion());
         }else if(version.equalsIgnoreCase(Constant.MAX)){
             findMax = true;
-            version = String.valueOf(maintainService.getMaxVersion(tableName).getVersion());
+            Maintain maxVersion = maintainService.getMaxVersion(tableName);
+            if (maxVersion == null)  {
+                return Result.success(null);
+            }
+            version = String.valueOf(maxVersion.getVersion());
         }
 
         if (StringUtils.isEmpty(fields)) {
@@ -182,20 +136,28 @@
     }
 
     @RequestMapping(value = "{maintainId}/modify/{operateStr}", method = RequestMethod.POST)
-    public Result modify(@RequestParam String datas, @PathVariable String maintainId, @PathVariable String operateStr, HttpServletRequest request) throws UnsupportedEncodingException {
+    public Result modify(@RequestParam String datas, @PathVariable String maintainId, @PathVariable String operateStr,  @RequestParam String modify, HttpServletRequest request) throws UnsupportedEncodingException {
         Result result = null;
         Operate operate = Operate.parse(operateStr);
         Maintain maintain = maintainService.selectById(maintainId);
+        List<String> modifyFields = null;
+        if (!StringUtils.isEmpty(modify)) {
+            String[] split = modify.split(Constant.SEMICOLON);
+            modifyFields = Arrays.stream(split).collect(Collectors.toList());
+        }
+        TUser user = (TUser) request.getSession().getAttribute("user");
+
         switch (operate) {
             case delete:
                 //datas is id;
                 Integer deleteCount = tableInfoMapper.deleteRecordByMaintainId(maintain.getTableName() + Constant.RECORD, DbUtils.quotedStr(datas), DbUtils.quotedStr(maintainId));
-
                 result = Result.success(deleteCount);
                 break;
             case update:
                 JSONObject jsonObject = JSONObject.parseObject(datas);
                 String id = (String) jsonObject.get("id");
+
+                masterModifiedService.updateModifiedUserById(maintainId, id, user.getUserId(), modifyFields);
                 jsonObject.remove(Constant.ID);
                 datas = jsonObject.toJSONString();
                 String updateSegment = masterDataService.getUpdateSegment(maintain.getTableName(), maintain.getTableName() + Constant.RECORD, datas);
@@ -206,6 +168,9 @@
             case create:
                 JSONObject createObject = JSONObject.parseObject(datas);
                 String recordId = DbUtils.getUUID();
+
+                masterModifiedService.updateModifiedUserById(maintainId, recordId, user.getUserId(), modifyFields);
+
                 createObject.fluentPut(Constant.ID, recordId);
                 createObject.fluentPut(Constant.STD_ID, DbUtils.getUUID());
                 datas = createObject.toJSONString();
@@ -232,49 +197,18 @@
 
 
     @RequestMapping(value = "{tableName}/{operateStr}", method = RequestMethod.POST)
-    public Result insert(@PathVariable String tableName,@PathVariable String operateStr, @RequestParam String datas, HttpServletRequest request) {
+    public Result insert(@PathVariable String tableName,@PathVariable String operateStr, @RequestParam String datas, @RequestParam String modify, HttpServletRequest request) {
         String fields = request.getParameter("fields");
         Operate operate = Operate.parse(operateStr);
-
-        Maintain maintain = maintainService.getMaxVersion(tableName);
-        Maintain unFlowMaxVersion = maintainService.getUnFlowMaxVersion(tableName);
-        if (unFlowMaxVersion == null) {
-            unFlowMaxVersion = new Maintain();
-            if (maintain != null) {
-                unFlowMaxVersion.setVersion(DbUtils.versionAddSub(maintain.getVersion()));
-                int orderNo = maintain.getOrderNo();
-                orderNo++;
-                unFlowMaxVersion.setOrderNo(orderNo);
-            } else {
-                unFlowMaxVersion.setVersion(Constant.VERSION_Default);
-                unFlowMaxVersion.setOrderNo(0);
-            }
-
-            unFlowMaxVersion.setId(DbUtils.getUUID());
-            TUser user = (TUser) request.getSession().getAttribute("user");
-            unFlowMaxVersion.setChargeId(user.getUserId());
-            unFlowMaxVersion.setCreateTime(new Date());
-            unFlowMaxVersion.setTableName(tableName);
-        }
-
-        Maintain nowMaintain = unFlowMaxVersion;
-        if (DbUtils.compareVersion(maintain, unFlowMaxVersion) != 0) {
-            nowMaintain = new Maintain();
-            String maintanId = DbUtils.getUUID();
-            nowMaintain.setId(maintanId);
-            nowMaintain.setCreateTime(new Date());
-            int orderNo = maintain.getOrderNo();
-            orderNo++;
-            nowMaintain.setVersion(DbUtils.versionAddSub(maintain.getVersion()));
-            nowMaintain.setOrderNo(orderNo);
-            nowMaintain.setTableName(tableName);
-        }
-
         TUser user = (TUser) request.getSession().getAttribute("user");
-        nowMaintain.setChargeId(user.getUserId());
-        String maintainId = nowMaintain.getId();
-        if(StringUtils.isEmpty(maintainId)) {
-            nowMaintain.setId(DbUtils.getUUID());
+        String userId = user.getUserId();
+        Maintain maintain = maintainService.getMaxVersion(tableName);
+        Maintain nowMaintain = maintainService.getNextMaintain(tableName, userId);
+
+        List<String> modifyFields = null;
+        if (!StringUtils.isEmpty(modify)) {
+            String[] split = modify.split(Constant.SEMICOLON);
+            modifyFields = Arrays.stream(split).collect(Collectors.toList());
         }
 
         Result result;
@@ -282,8 +216,9 @@
             String nowMaintainId = nowMaintain.getId();
             String tempId = tableInfoMapper.getTempIdByStdId(tableName + Constant.RECORD,DbUtils.quotedStr(datas), DbUtils.quotedStr(nowMaintainId));
             if (!StringUtils.isEmpty(tempId)){
-                maintainDetailService.delete(new EntityWrapper<MaintainDetail>().eq("parent_id", maintain.getId()).eq("operate",Operate.delete.name()).eq("pre_merge_id",tempId));
-               return masterDataService.deleteById(tableName + Constant.RECORD, tempId);
+                maintainDetailService.delete(new EntityWrapper<MaintainDetail>().eq("parent_id", maintain.getId()).eq("pre_merge_id",tempId));
+                result = masterDataService.deleteById(tableName + Constant.RECORD, tempId);
+                return result;
             }else {
                 result = masterDataService.selectById(tableName, datas);
                 Object data = result.getData();
@@ -295,16 +230,19 @@
         } else if (operate.equals(Operate.update)) {
             JSONObject jsonObject = JSONObject.parseObject(datas);
             Object id = jsonObject.get("id");
+
             String nowMaintainId = nowMaintain.getId();
             String tempId = tableInfoMapper.getTempIdByStdId(tableName + Constant.RECORD,DbUtils.quotedStr(id.toString()), DbUtils.quotedStr(nowMaintainId));
             if (StringUtils.isEmpty(tempId)) {
                 result = masterDataService.selectById(tableName, id.toString());
             } else {
+                masterModifiedService.updateModifiedUserById(nowMaintain.getId(), id.toString(), user.getUserId(), modifyFields);
                 jsonObject.put(Constant.STD_ID, id);
                 jsonObject.put(Constant.ID, tempId);
                 return masterDataService.updateById(tableName + Constant.RECORD, JSON.toJSONString(jsonObject), tempId,false);
             }
         }
+
 
         //merge 2 temp
         String tableTempName = tableName + Constant.RECORD;
@@ -314,6 +252,7 @@
         if (dataId == null) {
             dataId = DbUtils.getUUID();
         }
+        masterModifiedService.updateModifiedUserById(nowMaintain.getId(), dataId.toString(), user.getUserId(), modifyFields);
         object.put(Constant.STD_ID, dataId);
         object.put(Constant.ID, DbUtils.getUUID());
         datas = JSON.toJSONString(object);
@@ -394,4 +333,11 @@
             return masterDataService.delete(tableName, whereSegment);
         }
     }
+
+
+
+    @RequestMapping(value = "{tableName}/getFieldVal/{field}",  method = RequestMethod.GET)
+    public Result getFieldVal(@PathVariable String tableName, @PathVariable String field) {
+        return masterDataService.getFieldValByTable(tableName,field);
+    }
 }

--
Gitblit v1.8.0