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/service/impl/MenuMappingServiceImpl.java |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 45 insertions(+), 5 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 f5da1cd..1ea506b 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MenuMappingServiceImpl.java
@@ -1,6 +1,5 @@
 package com.highdatas.mdm.service.impl;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -25,6 +24,7 @@
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpSession;
+import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.util.Map;
 
@@ -118,7 +118,7 @@
         }
         return null;
     }
-
+    @Override
     public MenuMapping create(MenuMapping menuMapping) {
         menuMapping.setCreateTime(new Date());
         menuMapping.setId(DbUtils.getUUID());
@@ -127,8 +127,21 @@
         String tableName = WorkflowUtils.toFirstChar(name.toLowerCase());
         tableName = Constant.MD + tableName;
         String tableByName = tableInfoMapper.selectTableByName(tableName);
+
         if (!StringUtils.isEmpty(tableByName)){
-            tableName =  tableName + "_" +  DbUtils.getUUID(5);
+            int sameCount = selectCount(new EntityWrapper<MenuMapping>().eq("table_name", tableName));
+            if (sameCount > 0) {
+                tableName =  tableName + "_" +  DbUtils.getUUID(5);
+            }
+        }
+        int length = 0;
+        try {
+            length = tableName.getBytes("UTF-8").length;
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        if (length > 18) {
+            tableName = Constant.MD + DbUtils.getUUID(10);
         }
         menuMapping.setTableName(tableName);
         boolean insert = this.insert(menuMapping);
@@ -185,15 +198,31 @@
         if (menuMapping == null) {
             return Result.error(new CodeMsg(10008,"褰撳墠涓婚鏃犵増鏈暟鎹�"));
         }
-
         String tableName = menuMapping.getTableName();
+        String chargeId = menuMapping.getChargeId();
+        TUser userByChargeId = DbUtils.getUserById(chargeId);
+
         TUser user = (TUser) session.getAttribute(Constant.USER);
 
-        Maintain resultMaintain = masterAuthorService.getMaxVersionMaintain(user.getUserId(), tableName);
+        Maintain resultMaintain = masterAuthorService.getMaxVersionMaintain(user, tableName);
+        Maintain nowVersion = maintainService.getNowVersion(tableName);
 
         if (resultMaintain != null) {
+            if (nowVersion.getOrderNo().equals(resultMaintain.getOrderNo())) {
+                mapping.put("maintainType", 0);
+            }else {
+                mapping.put("maintainType", 1);
+            }
             mapping.put("version", resultMaintain.getVersion());
             mapping.put("maintainId", resultMaintain.getId());
+        }
+        if (userByChargeId != null) {
+            mapping.put("userName", userByChargeId.getUserName());
+        }
+        if (nowVersion != null) {
+            mapping.put("hasData", true);
+        }else {
+            mapping.put("hasData", false);
         }
         return Result.success(mapping);
 
@@ -211,6 +240,17 @@
     }
 
     @Override
+    public MenuMapping getMenuMappingByTableName(String tableName) {
+        MenuMapping menuMapping = selectOne(new EntityWrapper<MenuMapping>().eq("table_name", tableName).orderBy("create_time desc"));
+        if (menuMapping == null) {
+            return null;
+        }
+        return menuMapping;
+    }
+
+
+
+    @Override
     public String getTableNameByMenu(String menuId) {
         MenuMapping menuMapping = selectOne(new EntityWrapper<MenuMapping>().eq("menu_id", menuId).orderBy("create_time desc"));
         if (menuMapping == null) {

--
Gitblit v1.8.0