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/MaintainServiceImpl.java |   67 +++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/service/impl/MaintainServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MaintainServiceImpl.java
index fc3971f..a1e8f76 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MaintainServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MaintainServiceImpl.java
@@ -20,10 +20,7 @@
 import org.springframework.stereotype.Service;
 
 import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -98,7 +95,10 @@
         if (status.equals(ActivitiStatus.close)) {
              String collect = maintainDetailList.stream().map(detail -> DbUtils.quotedStr(detail.getPreMergeId())).collect(Collectors.joining(Constant.COMMA));
             //delete temp
-            masterDataService.delete(tableName + Constant.RECORD, "id in (" +collect+ ")");
+            if (!StringUtils.isEmpty(collect)) {
+                masterDataService.delete(tableName + Constant.RECORD, "id in (" +collect+ ")");
+            }
+
             //delete detail
             for (MaintainDetail maintainDetail : maintainDetailList) {
                 maintainDetail.deleteById();
@@ -173,7 +173,7 @@
 
     @Override
     public Result getUnSubmitData(String tableName, Integer pageNo, String pageSize, String whereSegment) {
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNull("flow_id").orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNull("flow_id").orderBy("order_no desc");
         Maintain maintain = selectOne(versionWrapper);
         if (maintain == null) {
             return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND);
@@ -199,6 +199,49 @@
     }
 
     @Override
+    public Maintain getNextMaintain(String tableName, String userId) {
+        Maintain maintain = this.getMaxVersion(tableName);
+        Maintain unFlowMaxVersion = this.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());
+            unFlowMaxVersion.setChargeId(userId);
+            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);
+        }
+
+        nowMaintain.setChargeId(userId);
+        String maintainId = nowMaintain.getId();
+        if(StringUtils.isEmpty(maintainId)) {
+            nowMaintain.setId(DbUtils.getUUID());
+        }
+        return nowMaintain;
+    }
+
+    @Override
     public boolean checkdMaxVersion(String maintainId) {
         Maintain maintain = selectById(maintainId);
         Maintain maxVersion = getMaxVersion(maintain.getTableName());
@@ -212,7 +255,7 @@
 
     @Override
     public Maintain getMaxVersion(String tableName) {
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc");
 
         Maintain maxVersion = selectOne(versionWrapper);
         return maxVersion;
@@ -220,7 +263,7 @@
 
     @Override
     public Maintain getUnFlowMaxVersion(String tableName) {
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().isNull("flow_id").eq("table_name", tableName).orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().isNull("flow_id").eq("table_name", tableName).orderBy("order_no desc");
 
         Maintain maxVersion = selectOne(versionWrapper);
         return maxVersion;
@@ -229,7 +272,7 @@
     @Override
     public Maintain getInvalidMaxVersion(String tableName) {
         Maintain result = null;
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc");
 
         List<Maintain> maintainList = selectList(versionWrapper);
 
@@ -279,7 +322,7 @@
 
     @Override
     public Maintain getNowVersion(String tableName) {
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc");
 
         List<Maintain> maintains = selectList(versionWrapper);
         for (Maintain maintain : maintains) {
@@ -299,7 +342,7 @@
     @Override
     public Maintain getRecentHistoryVersion(String tableName) {
         Maintain nowMaintain = null;
-        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("version desc");
+        Wrapper<Maintain> versionWrapper = new EntityWrapper<Maintain>().eq("table_name", tableName).isNotNull("flow_id").orderBy("order_no desc");
         List<Maintain> maintains = selectList(versionWrapper);
         for (Maintain maintain : maintains) {
             Flows flows = flowsService.selectById(maintain.getFlowId());
@@ -316,7 +359,7 @@
             }
         }
         if (nowMaintain == null) {
-            nowMaintain = selectOne(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("version desc"));
+            nowMaintain = selectOne(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc"));
         }
         int orderNo = nowMaintain.getOrderNo();
         Maintain nowVersion = getNowVersion(tableName);

--
Gitblit v1.8.0