From 57c62dd3e7d398e253c2db549b819d020040b1a5 Mon Sep 17 00:00:00 2001
From: kimi42345 <kimi42345@outlook.com>
Date: 星期日, 29 三月 2020 20:49:17 +0800
Subject: [PATCH] no message

---
 src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java |   99 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 79 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
index d0c18b9..0ec4859 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
@@ -1,11 +1,14 @@
 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;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.highdatas.mdm.controller.MasterAuthorController;
 import com.highdatas.mdm.entity.*;
 import com.highdatas.mdm.mapper.MasterAuthorMapper;
+import com.highdatas.mdm.pojo.ActivitiStatus;
 import com.highdatas.mdm.pojo.MasterAuthorType;
 import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.util.Constant;
@@ -15,6 +18,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.security.CodeSigner;
 import java.text.MessageFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -42,6 +46,8 @@
     IMaintainFieldService maintainFieldService;
     @Autowired
     IMaintainService maintainService;
+    @Autowired
+    IFlowsService flowsService;
 
     @Override
     public HashMap<String, MasterAuthor> merageRoleAuthor(List<String> roleIds) {
@@ -82,17 +88,29 @@
     }
 
     @Override
-    public List<SysField> getField(String userId, String maintainFieldId, String maintainId) {
-        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
+    public List<SysField> getField(String userId, String maintainId) {
+        Maintain maintain = maintainService.selectById(maintainId);
+        if (maintain == null){
+            return new ArrayList<>();
+        }
+        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
+        if (isAll) {
             List<SysField> total = fieldService.getFieldByMaintain(maintainId);
             return total;
         }
-        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(this.characterId, userId).eq("maintain_field_id", maintainFieldId));
+
+        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
+        if (maintainField == null){
+            return new ArrayList<>();
+        }
+        String maintainFieldId = maintainField.getId();
+
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId));
         if (masterAuthors.size() == 0) {
             //user 鑾峰彇role
             List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId));
             List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList());
-            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(this.characterId, roleIds).eq("maintain_field_id", maintainFieldId));
+            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId));
         }
         if (masterAuthors.isEmpty()) {
             return null;
@@ -103,9 +121,9 @@
         if (codes.isEmpty()) {
             return null;
         }
-        Wrapper<SysField> wrapper = new EntityWrapper<SysField>().in(Constant.FIELD, codes);
+        Wrapper<SysField> wrapper = new EntityWrapper<SysField>().in(Constant.FIELD, codes).eq("table_name", maintain.getTableName());
 
-        if (maintainFieldId.equalsIgnoreCase(Constant.Default)) {
+        if (!maintainFieldId.equalsIgnoreCase(Constant.Default)) {
             wrapper.eq("maintain_field_id", maintainFieldId);
         }else {
             wrapper.isNull("maintain_field_id");
@@ -117,19 +135,35 @@
         return fieldList;
     }
 
+    private boolean checkUnFilterAuthor(String userId, String tableName) {
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("table_name", tableName));
+        long isAll = masterAuthors.stream().filter(masterAuthor -> masterAuthor.getMaintainFieldId().equalsIgnoreCase(Constant.All)).count();
+        if (isAll > 0) {
+            return true;
+        }
+        if (!masterAuthors.isEmpty()) {
+            return false;
+        }
+        Set<String> roleByUser = DbUtils.getRoleByUser(userId);
+        isAll = selectCount(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleByUser).eq("table_name", tableName).eq("maintain_field_id", Constant.All_UPCASE));
+        if (isAll > 0) {
+            return true;
+        }
+
+        return false;
+    }
+
     @Override
     public boolean checkMaintainAuthor(String userId, String maintainId) {
         Maintain maintain = maintainService.selectById(maintainId);
         if (maintain == null) {
             return false;
         }
-        int checked = selectCount(new EntityWrapper<MasterAuthor>()
-                .eq(Constant.TYPE, MasterAuthorType.user)
-                .eq(MasterAuthorController.character_id, userId)
-                .eq("table_name", maintain.getTableName())
-                .eq("maintain_field_id", Constant.All));
-        if(checked > 0) {
+        int checked = 0;
+        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
+        if (isAll){
             return true;
+
         }
         MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
         if (maintainField == null) {
@@ -159,17 +193,23 @@
 
     @Override
     public String getFilter(String userId, String maintainId) {
-        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
-        if (maintainField)
-        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
+        Maintain maintain = maintainService.selectById(maintainId);
+        if (maintain == null){
+            return Constant.WHERE_DEFAULTUN;
+        }
+        boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName());
+        if (isAll) {
             return Constant.WHERE_DEFAULT;
         }
-        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(this.characterId, userId).eq("maintain_field_id", maintainFieldId));
+        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
+        String maintainFieldId = maintainField.getId();
+
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId));
         if (masterAuthors.size() == 0) {
             //user 鑾峰彇role
             List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId));
             List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList());
-            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(this.characterId, roleIds).eq("maintain_field_id", maintainFieldId));
+            masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId));
         }
         if (masterAuthors.isEmpty()){
             return Constant.WHERE_DEFAULTUN;
@@ -190,8 +230,11 @@
             }
 
             Boolean preAll = segmentAllMap.get(field);
-            if (preAll && segmentMap.containsKey(field)) {
-                segmentMap.remove(field);
+            if (preAll) {
+                if (segmentMap.containsKey(field)) {
+                    segmentMap.remove(field);
+                }
+                continue;
             }
 
             String val = detail.getVal();
@@ -205,13 +248,29 @@
             String val = vals.stream()
                     .filter(s -> !StringUtils.isEmpty(s))
                     .map(s -> DbUtils.quotedStr(s)).collect(Collectors.joining(Constant.COMMA));
-            String format = MessageFormat.format(Constant.MYSQL_UUID, code, val);
+            String format = MessageFormat.format(Constant.InSql, code, val);
             builder.append(format);
         }
         String filter = builder.toString();
         return filter;
     }
 
+    @Override
+    public Maintain getMaxVersionMaintain(String userId, String tableName) {
+        List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc"));
+        for (Maintain maintain : maintainList) {
+            ActivitiStatus status = flowsService.getStatusByBusinessId(maintain.getId());
+            if (!status.equals(ActivitiStatus.open)) {
+                continue;
+            }
+            boolean b = checkMaintainAuthor(userId, maintain.getId());
+            if (b) {
+                return maintain;
+            }
+        }
+        return null;
+    }
+
     private MasterAuthor merage(MasterAuthor preMerageMasterAuthor, MasterAuthor masterAuthor) {
         // table name  masterField 涓�鏍� 鍙湁瀛楁涓嶅悓浜�
         List<MasterAuthorDetail> preFields = preMerageMasterAuthor.getFields();

--
Gitblit v1.8.0