From 5bac93baf5659ce013163f884c9dce41990a860e Mon Sep 17 00:00:00 2001
From: kimi42345 <kimi42345@outlook.com>
Date: 星期一, 23 三月 2020 08:49:41 +0800
Subject: [PATCH] no message

---
 src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java |   75 +++++++++++++++++++++++--------------
 1 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
index bdb7379..a9e7d4d 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
@@ -14,7 +14,6 @@
 import com.highdatas.mdm.mapper.MenuMappingMapper;
 import com.highdatas.mdm.mapper.TableInfoMapper;
 import com.highdatas.mdm.pojo.CodeMsg;
-import com.highdatas.mdm.pojo.MaintainDataType;
 import com.highdatas.mdm.pojo.Result;
 import com.highdatas.mdm.service.ActivitiService;
 import com.highdatas.mdm.service.IMaintainService;
@@ -22,6 +21,7 @@
 import com.highdatas.mdm.service.ISysMenuService;
 import com.highdatas.mdm.util.Constant;
 import com.highdatas.mdm.util.DbUtils;
+import com.highdatas.mdm.util.WorkflowUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -58,7 +58,7 @@
     public static final String key = "process";
 
     @Override
-    public boolean create(String json, HttpSession session) {
+    public MenuMapping create(String json, HttpSession session) {
         JSONObject jsonObject = JSONObject.parseObject(json);
 //        //1
 //        Flows flows = activitiService.start(key, session);
@@ -81,9 +81,17 @@
             menuMapping = objectMapper.readValue(json, MenuMapping.class);
         } catch (JsonProcessingException e) {
             e.printStackTrace();
-            return false;
+            return null;
         }
-        //menuMapping.setMaintainId(maintainId);
+        String menuId = menuMapping.getMenuId();
+        if (StringUtils.isEmpty(menuId)) {
+            return null;
+        }
+        int cnt = selectCount(new EntityWrapper<MenuMapping>().eq("menu_id", menuId));
+        if (cnt != 0)  {
+            return null;
+        }
+        //menuMapping.setMaintainFieldId(maintainId);
         return  create(menuMapping);
     }
 
@@ -109,10 +117,25 @@
         return null;
     }
 
-    public boolean create(MenuMapping menuMapping) {
+    public MenuMapping create(MenuMapping menuMapping) {
         menuMapping.setCreateTime(new Date());
         menuMapping.setId(DbUtils.getUUID());
-        return this.insert(menuMapping);
+        String name = menuMapping.getName();
+        name = DbUtils.getChineseOrEnglishOrNumber(name);
+        String tableName = WorkflowUtils.toFirstChar(name.toLowerCase());
+        tableName = Constant.MD + tableName;
+        String tableByName = tableInfoMapper.selectTableByName(tableName);
+        if (!StringUtils.isEmpty(tableByName)){
+            tableName =  tableName + "_" +  DbUtils.getUUID(5);
+        }
+        menuMapping.setTableName(tableName);
+        boolean insert = this.insert(menuMapping);
+        if (insert) {
+            return menuMapping;
+        } else {
+            return null;
+        }
+
     }
 
     @Override
@@ -133,42 +156,36 @@
     @Override
     public Result getMapping(HttpSession session, String id) {
         SysMenu sysMenu = menuService.selectById(id);
-        MaintainDataType dataType = sysMenu.getDataType();
+        if (sysMenu == null) {
+            return Result.error(CodeMsg.SELECT_ERROR);
+        }
         String menuType = sysMenu.getMenuType();
-        if (!StringUtils.isEmpty(menuType) && menuType.equalsIgnoreCase("DataMenu")) {
-            Map mapping = menuMappingMapper.getMapping(id);
-            return Result.success(mapping);
-        }else if (!StringUtils.isEmpty(menuType) && menuType.equalsIgnoreCase("StructureMenu")) {
+        if (StringUtils.isEmpty(menuType)) {
+            return Result.error(CodeMsg.SELECT_ERROR);
+        }
+
+        if (menuType.equalsIgnoreCase("StructureMenu")) {
             return Result.success(null);
         }
-        Wrapper<MenuMapping> menuWrapper = new EntityWrapper<MenuMapping>().eq("menu_id", sysMenu.getParentId());
+
+        Map mapping = menuMappingMapper.getMapping(id);
+
+        Wrapper<MenuMapping> menuWrapper = new EntityWrapper<MenuMapping>().eq("menu_id", sysMenu.getId());
         MenuMapping menuMapping = selectOne(menuWrapper);
         if (menuMapping == null) {
             return Result.error(new CodeMsg(10008,"褰撳墠涓婚鏃犵増鏈暟鎹�"));
         }
-        String tableName = menuMapping.getTableName();
-        Maintain resultMaintain = null;
-        switch (dataType) {
-            case beforeData:
-                resultMaintain = maintainService.getRecentHistoryVersion(tableName);
-                break;
-            case afterData:
-               break;
-            case currentData:
-                resultMaintain = maintainService.getNowVersion(tableName);
-                break;
-            default:
-                Result.error(new CodeMsg(10008,"褰撳墠涓婚鏃犵増鏈暟鎹�"));
-                break;
-        }
 
-        Map<String, Object> mapping = menuMappingMapper.getMapping(sysMenu.getParentId());
+        String tableName = menuMapping.getTableName();
+        Maintain resultMaintain = maintainService.getNowVersion(tableName);
 
         if (resultMaintain != null) {
             mapping.put("version", resultMaintain.getVersion());
             mapping.put("maintainId", resultMaintain.getId());
         }
-        mapping.put("dataType", sysMenu.getDataType());
+
         return Result.success(mapping);
+
+
     }
 }

--
Gitblit v1.8.0