diff --git a/src/main/java/com/lz/modules/app/controller/FlowManagerController.java b/src/main/java/com/lz/modules/app/controller/FlowManagerController.java index 9f774d26..24abe7bd 100644 --- a/src/main/java/com/lz/modules/app/controller/FlowManagerController.java +++ b/src/main/java/com/lz/modules/app/controller/FlowManagerController.java @@ -1,11 +1,13 @@ package com.lz.modules.app.controller; import java.util.Arrays; +import java.util.List; import java.util.Map; import com.lz.common.utils.PageUtils; import com.lz.common.utils.R; import com.lz.modules.flow.entity.FlowManager; +import com.lz.modules.flow.model.FlowDto; import com.lz.modules.flow.service.FlowManagerService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -40,6 +42,11 @@ public class FlowManagerController { return R.ok().put("page", page); } + @RequestMapping("/menu/list") + public List menuList(){ + List flowDtoList = flowManagerService.getFowList(); + return flowDtoList; + } /** * 信息 diff --git a/src/main/java/com/lz/modules/flow/model/FlowDto.java b/src/main/java/com/lz/modules/flow/model/FlowDto.java new file mode 100644 index 00000000..e3ddba70 --- /dev/null +++ b/src/main/java/com/lz/modules/flow/model/FlowDto.java @@ -0,0 +1,30 @@ +package com.lz.modules.flow.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class FlowDto { + private static final long serialVersionUID = 1L; + + /** + * 飞书部门id + */ + private String departmentId; + /** + * 飞书上级部门id + */ + private String departmentParentId; + /** + * 飞书显示部门人数 + */ + private String realName; + /** + * 组织架构名称/部门名称 + */ + private String departmentName; + + private List list; + +} diff --git a/src/main/java/com/lz/modules/flow/model/FlowInfo.java b/src/main/java/com/lz/modules/flow/model/FlowInfo.java new file mode 100644 index 00000000..942bb33c --- /dev/null +++ b/src/main/java/com/lz/modules/flow/model/FlowInfo.java @@ -0,0 +1,14 @@ +package com.lz.modules.flow.model; + +import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; +import lombok.Data; + +import java.util.List; + +@Data +public class FlowInfo { + private DepartmentsStaffRelateEntity parentDepartmentRelate; + + private List list; + +} diff --git a/src/main/java/com/lz/modules/flow/service/FlowManagerService.java b/src/main/java/com/lz/modules/flow/service/FlowManagerService.java index 58401241..56f3cbef 100644 --- a/src/main/java/com/lz/modules/flow/service/FlowManagerService.java +++ b/src/main/java/com/lz/modules/flow/service/FlowManagerService.java @@ -3,6 +3,7 @@ package com.lz.modules.flow.service; import com.baomidou.mybatisplus.extension.service.IService; import com.lz.common.utils.PageUtils; import com.lz.modules.flow.entity.FlowManager; +import com.lz.modules.flow.model.FlowDto; import java.util.List; import java.util.Map; @@ -37,4 +38,6 @@ public interface FlowManagerService extends IService { PageUtils queryPage(Map params); void deleteBatchIds(List asList); + + List getFowList(); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/flow/service/impl/FlowManagerServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/FlowManagerServiceImpl.java index 7a0a5692..9dde4f6d 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/FlowManagerServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/FlowManagerServiceImpl.java @@ -3,14 +3,27 @@ package com.lz.modules.flow.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lz.common.utils.NumberUtil; import com.lz.common.utils.PageUtils; +import com.lz.modules.app.dao.DepartmentsDao; +import com.lz.modules.app.dao.StaffDao; +import com.lz.modules.app.entity.DepartmentsEntity; +import com.lz.modules.app.entity.DepartmentsStaffRelateEntity; +import com.lz.modules.app.entity.StaffEntity; +import com.lz.modules.app.service.DepartmentsStaffRelateService; import com.lz.modules.flow.dao.FlowManagerMapper; import com.lz.modules.flow.entity.FlowManager; +import com.lz.modules.flow.model.FlowDto; +import com.lz.modules.flow.model.FlowInfo; import com.lz.modules.flow.service.FlowManagerService; +import com.lz.modules.flow.service.RecordRoleService; +import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** *

@@ -28,6 +41,18 @@ public class FlowManagerServiceImpl extends ServiceImpl getFowList() { + List tDepartments = departmentsDao.selectAll(); + List parentDepartments = tDepartments.stream() + //根据两个属性进行过滤 + .filter(s -> s.getDepartmentParentId().equals("1")) + .collect(Collectors.toList()); + List departmentsStaffRelateEntities = departmentsStaffRelateService.selectAll(); + Map departmentsStaffRelateEntityMap = new HashMap<>(); + Map singleRelateMap = new HashMap<>(); + + for(DepartmentsStaffRelateEntity d : departmentsStaffRelateEntities){ + singleRelateMap.put(d.getDepartmentId(),d); + if(new Integer(1).equals(d.getIsLeader())){ + FlowInfo flowInfo = new FlowInfo(); + flowInfo.setParentDepartmentRelate(d); + List list = new ArrayList<>(); + for(DepartmentsStaffRelateEntity d2 : departmentsStaffRelateEntities){ + if(d2.getDepartmentId().equals(d.getDepartmentId()) && new Integer(0).equals(d2.getIsLeader())){ + list.add(d2); + } + } + flowInfo.setList(list); + departmentsStaffRelateEntityMap.put(d.getDepartmentId(),flowInfo); + } + } + + List staffEntities = staffDao.selectAll(); + Map staffMap = new HashMap<>(); + for(StaffEntity staffEntity : staffEntities){ + staffMap.put(staffEntity.getId(),staffEntity); + } + List list = new ArrayList<>(); + for (DepartmentsEntity d : parentDepartments) { + String realName = getRealName(departmentsStaffRelateEntityMap,staffMap,d.getDepartmentId(),singleRelateMap); + FlowDto entity = buildMenuEntity(d.getDepartmentId(),d.getDepartmentName() , "1", realName); + List childList = getMenuList(tDepartments, entity,departmentsStaffRelateEntityMap,staffMap,singleRelateMap); + entity.setList(childList); + list.add(entity); + } + return list; + } + + + public FlowDto buildMenuEntity(String departmentId, String departmentName, String parentId, String realName) { + FlowDto flowDto = new FlowDto(); + flowDto.setDepartmentId(departmentId); + flowDto.setDepartmentName(departmentName); + flowDto.setDepartmentParentId(parentId); + flowDto.setRealName(realName); + return flowDto; + } + + + public String getRealName(Map departmentsStaffRelateEntityMap, Map staffMap, String departmentId + , Map singleRelateMap) { + FlowInfo flowInfo = departmentsStaffRelateEntityMap.get(departmentId); + if (flowInfo != null) { + return doGetRealName(flowInfo.getParentDepartmentRelate(), staffMap); + } else { + return doGetRealName(singleRelateMap.get(departmentId), staffMap); + } + } + + public String doGetRealName(DepartmentsStaffRelateEntity departmentsStaffRelateEntity, Map staffMap) { + if (departmentsStaffRelateEntity != null) { + StaffEntity staffEntity = staffMap.get(departmentsStaffRelateEntity.getStaffId()); + if (staffEntity != null) { + return staffEntity.getName(); + } + } + return ""; + } + + public List getMenuList(List tDepartments,FlowDto flowDto, + Map departmentsStaffRelateEntityMap, Map staffMap + ,Map singleRelateMap) { + List flowDtos = new ArrayList<>(); + for(DepartmentsEntity child : tDepartments) { + if (child.getDepartmentParentId().equals(flowDto.getDepartmentId())) { + FlowDto entity = buildMenuEntity(child.getDepartmentId(), + child.getDepartmentName(), flowDto.getDepartmentId(), + getRealName(departmentsStaffRelateEntityMap, staffMap, child.getDepartmentId(),singleRelateMap)); + List list = getMenuList(tDepartments, entity, departmentsStaffRelateEntityMap, staffMap,singleRelateMap); + if (CollectionUtils.isEmpty(list) || list.size() == 0) { + FlowInfo flowInfo = departmentsStaffRelateEntityMap.get(child.getDepartmentId()); + if (flowInfo != null && CollectionUtils.isNotEmpty(flowInfo.getList()) && flowInfo.getList().size() > 0) { + list = new ArrayList<>(); + for (DepartmentsStaffRelateEntity dr : flowInfo.getList()) { + StaffEntity staffEntity = staffMap.get(dr.getStaffId()); + FlowDto childEntiry = buildMenuEntity(dr.getDepartmentId() + "_" + dr.getStaffId(), + staffEntity != null ? staffEntity.getName() : "", + entity.getDepartmentId(), + ""); + list.add(childEntiry); + } + } + } + entity.setList(list); + flowDtos.add(entity); + } + } + return flowDtos; + } + }