夏文涛 hai 1 ano
pai
achega
3394a30692

+ 0 - 4
src/main/java/com/template/controller/SmartAskForLeaveConfigController.java

@@ -1,7 +1,5 @@
 package com.template.controller;
 
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.template.annotation.DESRespondSecret;
 import com.template.api.SmartAskForLeaveConfigControllerAPI;
@@ -12,8 +10,6 @@ import com.template.services.SmartAskForLeaveConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.List;
-
 /**
  * <p>
  *  前端控制器

+ 1 - 0
src/main/java/com/template/model/pojo/SmartAuthorGroupManager.java

@@ -21,6 +21,7 @@ public class SmartAuthorGroupManager {
     public String userName;
     public String departmentManage;
     public String departmentView;
+    public String departments;
     public List<JSONObject> departmentManageJson;
     public List<JSONObject> departmentViewJson;
 

+ 40 - 35
src/main/java/com/template/services/impl/SmartAuthorGroupServiceImpl.java

@@ -12,18 +12,19 @@ import com.template.model.result.PageUtils;
 import com.template.model.weixin.AuthorListGroup;
 import com.template.services.SmartAuthorGroupService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author ceshi
@@ -59,7 +60,7 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
         Page<SmartAuthorGroup> page = new Page<>(currentPage, pageCount);
         QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
         //queryWrapper.like(StringUtils.hasText(name), "name", name);
-        IPage<SmartAuthorGroup> result = smartAuthorGroupMapper.selectPage(page,queryWrapper);
+        IPage<SmartAuthorGroup> result = smartAuthorGroupMapper.selectPage(page, queryWrapper);
         return new PageUtils<>(result);
     }
 
@@ -97,13 +98,13 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
 
 
     @Override
-    public List<SmartAuthorGroup> smartAuthorGroup(Integer userId){
+    public List<SmartAuthorGroup> smartAuthorGroup(Integer userId) {
         List<SmartAuthorGroup> result = smartAuthorGroupMapper.smartAuthorGroup(userId);
         return result;
     }
 
     @Override
-    public List<SmartAuthorGroup> smartAuthorGroupSuperAdmins(Integer userId){
+    public List<SmartAuthorGroup> smartAuthorGroupSuperAdmins(Integer userId) {
         List<SmartAuthorGroup> result = smartAuthorGroupMapper.smartAuthorGroupSuperAdmin(userId);
         return result;
     }
@@ -151,44 +152,48 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
     }
 
     @Override
-    public List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId){
+    public List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId) {
         List<SmartAuthorGroupManager> list = smartAuthorGroupMapper.getSmartAuthorGroupManager(groupId);
-        if (list.size()>0){
-            for (int i = 0; i < list.size(); i++) {
-                SmartAuthorGroupManager smartAuthorGroupManager = list.get(i);
-                if (smartAuthorGroupManager.getDepartmentManage()!=null && !smartAuthorGroupManager.getDepartmentManage().equals("")){
-                    String[] manageId = smartAuthorGroupManager.getDepartmentManage().split(",");
-                    QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
-                    queryWrapper1.eq("deleted", 0);
-                    queryWrapper1.in("id", Arrays.asList(manageId));
-                    List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
+        if (list != null && list.size() > 0) {
+            List<String> departmentStrs = list.stream().map(SmartAuthorGroupManager::getDepartments).collect(Collectors.toList());
+            List<String> departmentIds = Arrays.asList(StringUtils.join(departmentStrs, ',').split(",")).stream().distinct().collect(Collectors.toList());
+            QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
+            queryWrapper1.eq("deleted", 0);
+            queryWrapper1.in("id", departmentIds);
+            List<SmartDepartment> departmentDatas = smartDepartmentMapper.selectList(queryWrapper1);
+
+            for (SmartAuthorGroupManager smartAuthorGroupManager : list) {
+                if (smartAuthorGroupManager.getDepartmentManage() != null && !smartAuthorGroupManager.getDepartmentManage().equals("")) {
+                    List<String> manageIds = Arrays.asList(smartAuthorGroupManager.getDepartmentManage().split(","));
                     List<JSONObject> departmentManageJson = new ArrayList<>();
-                    if (list1.size()>0){
-                        for (int j = 0; j < list1.size(); j++) {
-                            JSONObject jsonObject1 = new JSONObject();
-                            jsonObject1.put("id", list1.get(j).getId());
-                            jsonObject1.put("name", list1.get(j).getName());
-                            departmentManageJson.add(jsonObject1);
+                    for (String manageId : manageIds) {
+                        if (departmentDatas != null && departmentDatas.size() > 0) {
+                            Optional<SmartDepartment> oDepartment = departmentDatas.stream().filter(e -> String.valueOf(e.getId()).equals(manageId)).findFirst();
+                            if(oDepartment != null && oDepartment.isPresent()){
+                                JSONObject jsonObject1 = new JSONObject();
+                                jsonObject1.put("id", oDepartment.get().getId());
+                                jsonObject1.put("name", oDepartment.get().getName());
+                                departmentManageJson.add(jsonObject1);
+                            }
                         }
                     }
-                    list.get(i).setDepartmentManageJson(departmentManageJson);
+                    smartAuthorGroupManager.setDepartmentManageJson(departmentManageJson);
                 }
-                if (smartAuthorGroupManager.getDepartmentView()!=null && !smartAuthorGroupManager.getDepartmentView().equals("")){
-                    String[] viewId = smartAuthorGroupManager.getDepartmentView().split(",");
-                    QueryWrapper<SmartDepartment> queryWrapper1 = new QueryWrapper<>();
-                    queryWrapper1.eq("deleted", 0);
-                    queryWrapper1.in("id", Arrays.asList(viewId));
-                    List<SmartDepartment> list1 = smartDepartmentMapper.selectList(queryWrapper1);
+                if (smartAuthorGroupManager.getDepartmentView() != null && !smartAuthorGroupManager.getDepartmentView().equals("")) {
+                    List<String> viewIds = Arrays.asList(smartAuthorGroupManager.getDepartmentView().split(","));
                     List<JSONObject> departmentViewJson = new ArrayList<>();
-                    if (list1.size()>0){
-                        for (int j = 0; j < list1.size(); j++) {
-                            JSONObject jsonObject1 = new JSONObject();
-                            jsonObject1.put("id", list1.get(j).getId());
-                            jsonObject1.put("name", list1.get(j).getName());
-                            departmentViewJson.add(jsonObject1);
+                    for (String viewId : viewIds) {
+                        if (departmentDatas != null && departmentDatas.size() > 0) {
+                            Optional<SmartDepartment> oDepartment = departmentDatas.stream().filter(e -> String.valueOf(e.getId()).equals(viewId)).findFirst();
+                            if(oDepartment != null && oDepartment.isPresent()){
+                                JSONObject jsonObject1 = new JSONObject();
+                                jsonObject1.put("id", oDepartment.get().getId());
+                                jsonObject1.put("name", oDepartment.get().getName());
+                                departmentViewJson.add(jsonObject1);
+                            }
                         }
                     }
-                    list.get(i).setDepartmentViewJson(departmentViewJson);
+                    smartAuthorGroupManager.setDepartmentViewJson(departmentViewJson);
                 }
             }
         }

+ 1 - 1
src/main/resources/mapper/template/SmartAuthorGroupMapper.xml

@@ -36,7 +36,7 @@
 
 
     <select id="getSmartAuthorGroupManager" resultType="com.template.model.pojo.SmartAuthorGroupManager" resultMap="smartAuthorGroupManager">
-        select a.`id`,a.`group_id`,a.`user_id`,b.card_no,b.`name` as user_name,a.`department_manage`,a.`department_view`
+        select a.`id`,a.`group_id`,a.`user_id`,b.card_no,b.`name` as user_name,a.`department_manage`,a.`department_view`,CONCAT(a.`department_manage`,',',a.`department_view`) as departments
             from `smart_authority` a left join `smart_user` b on a.`user_id`=b.id
             where group_id=#{groupId} and a.deleted=0 and b.deleted=0
     </select>