From ccb933362251344091a3881a4950dcab33c5008f Mon Sep 17 00:00:00 2001
From: kimi <kimi42345@gmail.com>
Date: 星期六, 28 三月 2020 11:47:55 +0800
Subject: [PATCH] no message

---
 src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 160 insertions(+), 13 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 6367289..d0c18b9 100644
--- a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
+++ b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java
@@ -1,21 +1,21 @@
 package com.highdatas.mdm.service.impl;
 
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
-import com.highdatas.mdm.entity.MasterAuthor;
-import com.highdatas.mdm.entity.MasterAuthorDetail;
-import com.highdatas.mdm.entity.SysField;
-import com.highdatas.mdm.entity.SysMenu;
+import com.highdatas.mdm.controller.MasterAuthorController;
+import com.highdatas.mdm.entity.*;
 import com.highdatas.mdm.mapper.MasterAuthorMapper;
 import com.highdatas.mdm.pojo.MasterAuthorType;
-import com.highdatas.mdm.pojo.Result;
-import com.highdatas.mdm.service.IMasterAuthorDetailService;
-import com.highdatas.mdm.service.IMasterAuthorService;
+import com.highdatas.mdm.service.*;
 import com.highdatas.mdm.util.Constant;
+import com.highdatas.mdm.util.ContentBuilder;
 import com.highdatas.mdm.util.DbUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.MessageFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -32,10 +32,20 @@
     public static final String characterId = "characterId";
     @Autowired
     IMasterAuthorDetailService authorDetailService;
+    @Autowired
+    ITUserRoleService userRoleService;
+    @Autowired
+    ISysMenuService menuService;
+    @Autowired
+    ISysFieldService fieldService;
+    @Autowired
+    IMaintainFieldService maintainFieldService;
+    @Autowired
+    IMaintainService maintainService;
 
     @Override
-    public Result merageRoleAuthor(List<String> roleIds) {
-        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(this.characterId, roleIds));
+    public HashMap<String, MasterAuthor> merageRoleAuthor(List<String> roleIds) {
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds));
         HashMap<String, MasterAuthor> resultMap = new HashMap<>();
 
         for (MasterAuthor masterAuthor : masterAuthors) {
@@ -52,17 +62,154 @@
                 resultMap.put(key, preMerageMasterAuthor);
             }
         }
-        return Result.success(resultMap.values());
+        return resultMap;
     }
 
     @Override
     public List<SysMenu> getMenu(String userId) {
-        return null;
+        List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId));
+        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(MasterAuthorController.character_id, roleIds));
+        }
+        List<String> menuIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toList());
+        LinkedHashSet<String> strings = new LinkedHashSet<>(menuIds);
+        LinkedHashSet<String> byParentId = menuService.getByParentId(strings);
+        List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId);
+        return sysMenus;
     }
 
     @Override
-    public List<SysField> getField(String userId) {
-        return null;
+    public List<SysField> getField(String userId, String maintainFieldId, String maintainId) {
+        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
+            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));
+        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));
+        }
+        if (masterAuthors.isEmpty()) {
+            return null;
+        }
+        List<String> authorIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getId()).collect(Collectors.toList());
+        List<MasterAuthorDetail> masterAuthorDetails = authorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().in(Constant.PARENT_ID, authorIds));
+        Set<String> codes = masterAuthorDetails.stream().map(masterAuthorDetail -> masterAuthorDetail.getField()).collect(Collectors.toSet());
+        if (codes.isEmpty()) {
+            return null;
+        }
+        Wrapper<SysField> wrapper = new EntityWrapper<SysField>().in(Constant.FIELD, codes);
+
+        if (maintainFieldId.equalsIgnoreCase(Constant.Default)) {
+            wrapper.eq("maintain_field_id", maintainFieldId);
+        }else {
+            wrapper.isNull("maintain_field_id");
+        }
+        List<SysField> fieldList = fieldService.selectList(wrapper);
+
+
+
+        return fieldList;
+    }
+
+    @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) {
+            return true;
+        }
+        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
+        if (maintainField == null) {
+            return false;
+        }
+        //get user author
+        checked = selectCount(new EntityWrapper<MasterAuthor>()
+                .eq(Constant.TYPE, MasterAuthorType.user)
+                .eq(MasterAuthorController.character_id, userId)
+                .eq("table_name", maintain.getTableName())
+                .eq("maintain_field_id", maintainField.getId()));
+        if (checked > 0) {
+            return true;
+        }
+        List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId));
+        Set<String> collect = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toSet());
+        checked = selectCount(new EntityWrapper<MasterAuthor>()
+                .eq(Constant.TYPE, MasterAuthorType.role)
+                .in(MasterAuthorController.character_id, collect)
+                .eq("table_name", maintain.getTableName())
+                .eq("maintain_field_id", maintainField.getId()));
+        if (checked > 0) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public String getFilter(String userId, String maintainId) {
+        MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId);
+        if (maintainField)
+        if (maintainFieldId.equalsIgnoreCase(Constant.All)) {
+            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));
+        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));
+        }
+        if (masterAuthors.isEmpty()){
+            return Constant.WHERE_DEFAULTUN;
+        }
+        List<String> authorIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getId()).collect(Collectors.toList());
+        List<MasterAuthorDetail> masterAuthorDetails = authorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().in(Constant.PARENT_ID, authorIds));
+        if (masterAuthorDetails.isEmpty()) {
+            return Constant.WHERE_DEFAULTUN;
+        }
+        HashMap<String, List<String>> segmentMap = new HashMap<>();
+        HashMap<String, Boolean> segmentAllMap = new HashMap<>();
+
+        for (MasterAuthorDetail detail : masterAuthorDetails) {
+            String field = detail.getField();
+            Boolean all = detail.getAll();
+            if (!(segmentAllMap.containsKey(field) && segmentAllMap.get(field))) {
+                segmentAllMap.put(field, all);
+            }
+
+            Boolean preAll = segmentAllMap.get(field);
+            if (preAll && segmentMap.containsKey(field)) {
+                segmentMap.remove(field);
+            }
+
+            String val = detail.getVal();
+            List<String> split = DbUtils.split(val);
+            segmentMap.put(field,split);
+        }
+        ContentBuilder builder = new ContentBuilder(Constant.AND);
+        Set<String> keySet = segmentMap.keySet();
+        for (String code : keySet) {
+            List<String> vals = segmentMap.get(code);
+            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);
+            builder.append(format);
+        }
+        String filter = builder.toString();
+        return filter;
     }
 
     private MasterAuthor merage(MasterAuthor preMerageMasterAuthor, MasterAuthor masterAuthor) {

--
Gitblit v1.8.0