From c8aee7b9bfd79cfd741d7e5692520f4f51a31a86 Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期一, 18 五月 2020 18:30:01 +0800
Subject: [PATCH] bak  修改 获取版本数据前

---
 src/main/java/com/highdatas/mdm/controller/MasterAuthorController.java |   50 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/controller/MasterAuthorController.java b/src/main/java/com/highdatas/mdm/controller/MasterAuthorController.java
index 60d5602..d071848 100644
--- a/src/main/java/com/highdatas/mdm/controller/MasterAuthorController.java
+++ b/src/main/java/com/highdatas/mdm/controller/MasterAuthorController.java
@@ -12,6 +12,7 @@
 import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.util.Constant;
 import com.highdatas.mdm.util.DbUtils;
+import com.highdatas.mdm.util.RedisClient;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -50,6 +51,10 @@
     IMasterAuthorUnactiveService masterAuthorUnactiveService;
     @Autowired
     IMasterAuthorSubscribeService masterAuthorSubscribeService;
+    @Autowired
+    IMaintainService maintainService;
+    @Autowired
+    RedisClient redisClient;
 
     public static final String masterAuthorType = "masterAuthorType";
     public static final String masterId = "masterId";
@@ -62,6 +67,9 @@
 
     @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
     public Result deleteModel(@RequestBody MasterAuthor masterAuthor)  {
+        if (StringUtils.isEmpty(masterAuthor.getMaintainFieldId())) {
+            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
+        }
         if (!StringUtils.isEmpty(masterAuthor.getId())) {
             masterAuthor.setUpdateTime(new Date());
         }else {
@@ -82,6 +90,7 @@
 
         boolean b = masterAuthor.insertOrUpdate();
         if (b) {
+            redisClient.delByCharacter(masterAuthor.getCharacterId());
             return Result.success(masterAuthor);
         }else {
             return Result.error(CodeMsg.UPDATE_ERROR);
@@ -131,7 +140,6 @@
                             .eq(Constant.PARENT_ID, masterAuthor.getId()));
             masterAuthor.setFields(masterAuthorDetails);
         }
-
         JSONObject object = new JSONObject();
         object.fluentPut("type", type);
         object.fluentPut("author",masterAuthorList);
@@ -163,6 +171,7 @@
         }
 
         if (delete) {
+            redisClient.delByCharacter(characterId);
             return Result.success(CodeMsg.DELETE_SUCCESS);
         }else  {
             return Result.error(CodeMsg.DELETE_ERROR);
@@ -189,21 +198,23 @@
         if (count == 1 && !StringUtils.isEmpty(maintainFieldId)) {
             only = true;
         }
-        MasterAuthor masterAuthor = authorService.selectOne(masterAuthorWrapper);
-        if (masterAuthor == null) {
+        List<MasterAuthor> masterAuthors = authorService.selectList(masterAuthorWrapper);
+        if (masterAuthors == null || masterAuthors.isEmpty()) {
             return Result.success(null);
         }
-
-        boolean delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
-        if (delete) {
-            if (only){
-                delete = masterAuthor.setMaintainFieldId(null).setFieldAuto(false).setMaintainAuto(false).setUpdateTime(new Date()).updateById();
-            }else {
-                delete = masterAuthor.deleteById();
+        boolean delete = false;
+        for (MasterAuthor masterAuthor : masterAuthors) {
+            delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
+            if (delete) {
+                if (only){
+                    delete = masterAuthor.setMaintainFieldId(null).setFieldAuto(false).setMaintainAuto(false).setUpdateTime(new Date()).updateById();
+                }else {
+                    delete = masterAuthor.deleteById();
+                }
             }
         }
-
         if (delete) {
+            redisClient.delByCharacter(characterId);
             return Result.success(CodeMsg.DELETE_SUCCESS);
         }else  {
             return Result.error(CodeMsg.DELETE_ERROR);
@@ -331,11 +342,19 @@
             if (i > 0) {
                 menu.setSubscribe(true);
             }
-
         }
-
         return Result.success(result);
     }
+
+//    @RequestMapping(value = "/canLoadData/{userId}", method = RequestMethod.GET)
+//    public Result canLoadData(@PathVariable String userId, @RequestParam String tableName, HttpServletRequest request) {
+//        TUser user = DbUtils.getUserById(userId);
+//        if (user == null) {
+//            return Result.error(CodeMsg.USER_NOT_MATHED);
+//        }
+//    }
+
+
     @RequestMapping(value = "/menu/{userId}", method = RequestMethod.GET)
     public Result<List<SysMenu>> menuList(@PathVariable String userId, HttpServletRequest request) {
         TUser user = DbUtils.getUserById(userId);
@@ -380,7 +399,10 @@
                     String maintainFieldId = masterAuthor.getMaintainFieldId();
                     String tableName = masterAuthor.getTableName();
                     List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName);
-                    maintainSet.addAll(maintainByMaintainField);
+                    if (maintainByMaintainField != null) {
+                        maintainSet.addAll(maintainByMaintainField);
+                    }
+
                 }
                 int unActiveCnt = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().in("maintain_id", maintainSet).eq("user_id", userId));
                 if (maintainSet.size() != unActiveCnt) {

--
Gitblit v1.8.0