SysUserLinkFrontLineDeptServiceImpl.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.ydtech.modules.admin.service.impl;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.ydtech.modules.admin.dao.SysDeptMapper;
  5. import com.ydtech.modules.admin.dao.SysUserLinkFrontLineDeptMapper;
  6. import com.ydtech.modules.admin.model.SysDept;
  7. import com.ydtech.modules.admin.model.dto.SysUserDto;
  8. import com.ydtech.modules.admin.model.dto.SysUserLinkDeptInternalAgentDto;
  9. import com.ydtech.modules.admin.model.dto.SysUserLinkFrontLineDeptDto;
  10. import com.ydtech.modules.admin.model.po.SysUserLinkFrontLineDept;
  11. import com.ydtech.modules.admin.model.vo.*;
  12. import com.ydtech.modules.admin.service.SysUserLinkFrontLineDeptService;
  13. import com.ydtech.modules.base.controller.BaseController;
  14. import com.ydtech.modules.order.entity.BasePageResult;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.stream.Collectors;
  22. /**
  23. * @author Administrator
  24. * @description 针对表【sys_user_link_front_line_dept(后线人员配置内部机构表)】的数据库操作Service实现
  25. * @createDate 2024-06-26 17:28:18
  26. */
  27. @Service
  28. public class SysUserLinkFrontLineDeptServiceImpl extends ServiceImpl<SysUserLinkFrontLineDeptMapper, SysUserLinkFrontLineDept>
  29. implements SysUserLinkFrontLineDeptService {
  30. @Autowired
  31. private SysUserLinkFrontLineDeptMapper sysUserLinkFrontLineDeptMapper;
  32. @Autowired
  33. private SysDeptMapper sysDeptMapper;
  34. /**
  35. * @version
  36. * @author: hxl
  37. * @Date: 2024/6/26 18:55
  38. * @Description: 查看前线机构数据
  39. */
  40. @Override
  41. public List<SysDept> queryQxOrgTree(String userId) {
  42. List<SysDept> sysDeptAll =new ArrayList<SysDept>();
  43. if(StringUtils.isNotBlank(userId)){
  44. //通过用户查询机构树
  45. sysDeptAll=sysUserLinkFrontLineDeptMapper.findDeptListByUserId(userId);
  46. }else{
  47. //查询所有的数据 机构等级 =3 或者 机构等级>2 且机构id 包含M 和D 的机构
  48. sysDeptAll = sysDeptMapper.queryListByQXDept();
  49. }
  50. List<SysDept> resultList =new ArrayList<SysDept>();
  51. List<SysDept> sysDeptTop = sysDeptAll.stream().filter(item ->"3".equals(item.getComlevel())).collect(Collectors.toList());
  52. for (SysDept dept : sysDeptTop) {
  53. resultList.add(buildDeptTree(dept,sysDeptAll));
  54. }
  55. return resultList;
  56. }
  57. /**
  58. * @version
  59. * @author: hxl
  60. * @Date: 2024/6/27 8:42
  61. * @Description: 获取顶级机构的数据
  62. */
  63. /**
  64. * 递归构建树形结构
  65. */
  66. private SysDept buildDeptTree(SysDept dept, List<SysDept> deptList){
  67. for (SysDept d : deptList) {
  68. if (dept.getId().equals(d.getParentId())) {
  69. if (null == dept.getChildren()) {
  70. dept.setChildren(new ArrayList<SysDept>());
  71. }
  72. //递归调用
  73. dept.getChildren().add(buildDeptTree(d, deptList));
  74. }
  75. }
  76. return dept;
  77. }
  78. /**
  79. * @version
  80. * @author: hxl
  81. * @Date: 2024/6/26 18:55
  82. * @Description: 添加或修改
  83. */
  84. @Override
  85. public void addOrUpdate(SysUserLinkFrontLineDeptAddVo sysUserLinkFrontLineDeptAddVo) {
  86. String userId = sysUserLinkFrontLineDeptAddVo.getUserId();
  87. List<String> deptIds = sysUserLinkFrontLineDeptAddVo.getDeptIds();
  88. //删除数据重新添加
  89. sysUserLinkFrontLineDeptMapper.deleteByUserId(userId);
  90. List<SysUserLinkFrontLineDept> addList= new ArrayList<>();
  91. //重新添加
  92. if(deptIds!=null && deptIds.size()>0){
  93. for (String deptId : deptIds) {
  94. SysUserLinkFrontLineDept add=new SysUserLinkFrontLineDept(userId,deptId,new Date(),
  95. new BaseController().getUser().getId(),new Date(),new BaseController().getUser().getId());
  96. addList.add(add);
  97. }
  98. }
  99. this.saveBatch(addList);
  100. }
  101. /**
  102. * @version
  103. * @author: hxl
  104. * @Date: 2024/6/26 18:56
  105. * @Description: 删除
  106. */
  107. @Override
  108. public void deleteByIds(List<String> ids) {
  109. sysUserLinkFrontLineDeptMapper.deleteBatchIds(ids);
  110. }
  111. /**
  112. * @version
  113. * @author: hxl
  114. * @Date: 2024/6/26 18:56
  115. * @Description: 查询对象
  116. */
  117. @Override
  118. public List<SysAreaVo> findSysUserLinkFrontLineDeptById(String id) {
  119. return null;
  120. }
  121. /**
  122. * @version
  123. * @author: hxl
  124. * @Date: 2024/6/26 18:56
  125. * @Description: 分页
  126. */
  127. @Override
  128. public BasePageResult<SysUserLinkFrontLineDeptDto> queryPage(SysUserLinkFrontLineDeptQueryVo sysUserLinkFrontLineDeptQueryVo) {
  129. Page<SysUserLinkFrontLineDeptDto> page = new Page<>(sysUserLinkFrontLineDeptQueryVo.getPageNum(),
  130. sysUserLinkFrontLineDeptQueryVo.getPageSize());
  131. Page<SysUserLinkFrontLineDeptDto> pageResult = sysUserLinkFrontLineDeptMapper.queryPage(page, sysUserLinkFrontLineDeptQueryVo);
  132. return new BasePageResult<>(sysUserLinkFrontLineDeptQueryVo.getPageNum(), page.getSize(), pageResult.getTotal(), page.getPages(),
  133. pageResult.getRecords());
  134. }
  135. @Override
  136. public BasePageResult<SysUserBaseVO> findUserListByPage(SysUserDto sysUserDto) {
  137. Page<SysUserBaseVO> page = new Page<>(sysUserDto.getPageNum(),
  138. sysUserDto.getPageSize());
  139. Page<SysUserBaseVO> userPageResult = sysUserLinkFrontLineDeptMapper.findUserListByDeptPage(page, sysUserDto);
  140. return new BasePageResult<>(sysUserDto.getPageNum(), page.getSize(), userPageResult.getTotal(), page.getPages(),
  141. userPageResult.getRecords());
  142. }
  143. @Override
  144. public BasePageResult<SysUserLinkDeptInternalAgentDto> queryUserPage(SysUserLinkDeptInternalAgentQueryVo sysUserLinkDeptInternalAgentQueryVo) {
  145. return null;
  146. }
  147. }