| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package com.ydtech.modules.admin.service.impl;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.modules.admin.dao.SysDeptInternalAgentMapper;
- import com.ydtech.modules.admin.model.dto.SysDeptInternalAgentDto;
- import com.ydtech.modules.admin.model.po.SysDeptInternalAgent;
- import com.ydtech.modules.admin.model.vo.SysDeptInternalAgentAddVo;
- import com.ydtech.modules.admin.model.vo.SysUserLinkAreaVo;
- import com.ydtech.modules.admin.service.SysDeptInternalAgentService;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.utils.HeadUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- /**
- * @author Administrator
- * @description 针对表【sys_dept_internal_agent(内部机构管理)】的数据库操作Service实现
- * @createDate 2024-06-26 17:28:34
- */
- @Service
- public class SysDeptInternalAgentServiceImpl extends ServiceImpl<SysDeptInternalAgentMapper, SysDeptInternalAgent>
- implements SysDeptInternalAgentService {
- @Autowired
- private SysDeptInternalAgentMapper sysDeptInternalAgentMapper;
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/26 18:53
- * @Description: 分页
- */
- @Override
- public BasePageResult<SysDeptInternalAgentDto> queryPage(SysUserLinkAreaVo sysUserLinkAreaVo) {
- return null;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/26 18:53
- * @Description: 添加或修改
- */
- @Override
- public void addOrUpdate(SysDeptInternalAgentAddVo sysDeptInternalAgentAddVo) {
- String parentId = sysDeptInternalAgentAddVo.getParentId();
- String id = sysDeptInternalAgentAddVo.getId();
- SysDeptInternalAgent sysDept = new SysDeptInternalAgent();
- BeanUtils.copyProperties(sysDeptInternalAgentAddVo, sysDept);
- String uuid = HeadUtils.get16UUID();
- SysDeptInternalAgent sysDeptInternalAgentParent = sysDeptInternalAgentMapper.selectById(parentId);
- if(StringUtils.isNotBlank(id)){
- //更新操作
- sysDeptInternalAgentMapper.updateById(sysDept);
- }else{
- //插入操作
- sysDept.setId(uuid);
- sysDept.setParentName(sysDeptInternalAgentParent.getName());
- sysDept.setParentIds(sysDeptInternalAgentParent.getParentIds()+","+uuid);
- sysDept.setComlevel(sysDeptInternalAgentParent.getComlevel()+1);
- sysDeptInternalAgentMapper.insert(sysDept);
- }
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/26 18:53
- * @Description: 删除
- */
- @Override
- public void deleteByIds(List<String> ids) {
- sysDeptInternalAgentMapper.deleteBatchIds(ids);
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/26 18:54
- * @Description: 查询对象
- */
- @Override
- public SysDeptInternalAgent findSysDeptInternalAgentById(String id) {
- return sysDeptInternalAgentMapper.selectById(id);
- }
- @Override
- public List<SysDeptInternalAgent> findTree(String deptId, String comtype) {
- String parentIds =null;
- if(StringUtils.isNotBlank(deptId)){
- SysDeptInternalAgent sysDeptInternalAgent = sysDeptInternalAgentMapper.selectById(deptId);
- parentIds=sysDeptInternalAgent.getParentIds();
- }
- List<SysDeptInternalAgent> sysDeptAll =sysDeptInternalAgentMapper.queryDeptList(parentIds,comtype);
- List<SysDeptInternalAgent> resultList =new ArrayList<SysDeptInternalAgent>();
- List<SysDeptInternalAgent> sysDeptTop = getTopDeptList(sysDeptAll);
- for (SysDeptInternalAgent dept : sysDeptTop) {
- if(StringUtils.isNotBlank(comtype)){
- resultList.add(buildDeptTree(dept,sysDeptAll));
- }else{
- resultList.add(buildDeptTreeOne(dept,sysDeptAll));
- }
- }
- return resultList;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/28 19:19
- * @Description: 处理上下级关系
- */
- private SysDeptInternalAgent buildDeptTreeOne(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
- for (SysDeptInternalAgent d : deptList) {
- if (dept.getId().equals(d.getParentId())) {
- if (null == dept.getChildren()) {
- dept.setChildren(new ArrayList<SysDeptInternalAgent>());
- }
- //递归调用
- dept.getChildren().add(buildDeptTreeOne(d, deptList));
- }
- }
- return dept;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/28 18:17
- * @Description: 获取顶级机构
- */
- private static List<SysDeptInternalAgent> getTopDeptList(List<SysDeptInternalAgent> sysDeptAll) {
- Integer min;
- List<Integer> levelList =new ArrayList<>();
- List<SysDeptInternalAgent> sysDeptTop=new ArrayList<>();
- if(sysDeptAll !=null && sysDeptAll.size()>0){
- for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
- levelList.add(Integer.parseInt(sysDeptInternalAgent.getComlevel()));
- }
- min = Collections.min(levelList);
- for(SysDeptInternalAgent sysDeptInternalAgent: sysDeptAll){
- if(Integer.parseInt(sysDeptInternalAgent.getComlevel())==min){
- sysDeptTop.add(sysDeptInternalAgent);
- }
- }
- }
- return sysDeptTop;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/27 8:42
- * @Description: 处理爷孙关系
- */
- private SysDeptInternalAgent buildDeptTree(SysDeptInternalAgent dept, List<SysDeptInternalAgent> deptList){
- for (SysDeptInternalAgent d : deptList) {
- if (d.getParentIds().contains(dept.getParentIds()) && !d.getParentIds().equals(dept.getParentIds()) ) {
- if (null == dept.getChildren()) {
- dept.setChildren(new ArrayList<SysDeptInternalAgent>());
- }
- //递归调用
- dept.getChildren().add(buildDeptTree(d, deptList));
- }
- }
- return dept;
- }
- }
|