package com.ydtech.modules.admin.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ydtech.modules.admin.dao.SysDeptMapper; import com.ydtech.modules.admin.dao.SysUserLinkFrontLineDeptMapper; import com.ydtech.modules.admin.model.SysDept; import com.ydtech.modules.admin.model.dto.SysUserDto; import com.ydtech.modules.admin.model.dto.SysUserLinkDeptInternalAgentDto; import com.ydtech.modules.admin.model.dto.SysUserLinkFrontLineDeptDto; import com.ydtech.modules.admin.model.po.SysUserLinkFrontLineDept; import com.ydtech.modules.admin.model.vo.*; import com.ydtech.modules.admin.service.SysUserLinkFrontLineDeptService; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.order.entity.BasePageResult; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * @author Administrator * @description 针对表【sys_user_link_front_line_dept(后线人员配置内部机构表)】的数据库操作Service实现 * @createDate 2024-06-26 17:28:18 */ @Service public class SysUserLinkFrontLineDeptServiceImpl extends ServiceImpl implements SysUserLinkFrontLineDeptService { @Autowired private SysUserLinkFrontLineDeptMapper sysUserLinkFrontLineDeptMapper; @Autowired private SysDeptMapper sysDeptMapper; /** * @version * @author: hxl * @Date: 2024/6/26 18:55 * @Description: 查看前线机构数据 */ @Override public List queryQxOrgTree(String userId) { List sysDeptAll =new ArrayList(); if(StringUtils.isNotBlank(userId)){ //通过用户查询机构树 sysDeptAll=sysUserLinkFrontLineDeptMapper.findDeptListByUserId(userId); }else{ //查询所有的数据 机构等级 =3 或者 机构等级>2 且机构id 包含M 和D 的机构 sysDeptAll = sysDeptMapper.queryListByQXDept(); } List resultList =new ArrayList(); List sysDeptTop = sysDeptAll.stream().filter(item ->"3".equals(item.getComlevel())).collect(Collectors.toList()); for (SysDept dept : sysDeptTop) { resultList.add(buildDeptTree(dept,sysDeptAll)); } return resultList; } /** * @version * @author: hxl * @Date: 2024/6/27 8:42 * @Description: 获取顶级机构的数据 */ /** * 递归构建树形结构 */ private SysDept buildDeptTree(SysDept dept, List deptList){ for (SysDept d : deptList) { if (dept.getId().equals(d.getParentId())) { if (null == dept.getChildren()) { dept.setChildren(new ArrayList()); } //递归调用 dept.getChildren().add(buildDeptTree(d, deptList)); } } return dept; } /** * @version * @author: hxl * @Date: 2024/6/26 18:55 * @Description: 添加或修改 */ @Override public void addOrUpdate(SysUserLinkFrontLineDeptAddVo sysUserLinkFrontLineDeptAddVo) { String userId = sysUserLinkFrontLineDeptAddVo.getUserId(); List deptIds = sysUserLinkFrontLineDeptAddVo.getDeptIds(); //删除数据重新添加 sysUserLinkFrontLineDeptMapper.deleteByUserId(userId); List addList= new ArrayList<>(); //重新添加 if(deptIds!=null && deptIds.size()>0){ for (String deptId : deptIds) { SysUserLinkFrontLineDept add=new SysUserLinkFrontLineDept(userId,deptId,new Date(), new BaseController().getUser().getId(),new Date(),new BaseController().getUser().getId()); addList.add(add); } } this.saveBatch(addList); } /** * @version * @author: hxl * @Date: 2024/6/26 18:56 * @Description: 删除 */ @Override public void deleteByIds(List ids) { sysUserLinkFrontLineDeptMapper.deleteBatchIds(ids); } /** * @version * @author: hxl * @Date: 2024/6/26 18:56 * @Description: 查询对象 */ @Override public List findSysUserLinkFrontLineDeptById(String id) { return null; } /** * @version * @author: hxl * @Date: 2024/6/26 18:56 * @Description: 分页 */ @Override public BasePageResult queryPage(SysUserLinkFrontLineDeptQueryVo sysUserLinkFrontLineDeptQueryVo) { Page page = new Page<>(sysUserLinkFrontLineDeptQueryVo.getPageNum(), sysUserLinkFrontLineDeptQueryVo.getPageSize()); Page pageResult = sysUserLinkFrontLineDeptMapper.queryPage(page, sysUserLinkFrontLineDeptQueryVo); return new BasePageResult<>(sysUserLinkFrontLineDeptQueryVo.getPageNum(), page.getSize(), pageResult.getTotal(), page.getPages(), pageResult.getRecords()); } @Override public BasePageResult findUserListByPage(SysUserDto sysUserDto) { Page page = new Page<>(sysUserDto.getPageNum(), sysUserDto.getPageSize()); Page userPageResult = sysUserLinkFrontLineDeptMapper.findUserListByDeptPage(page, sysUserDto); return new BasePageResult<>(sysUserDto.getPageNum(), page.getSize(), userPageResult.getTotal(), page.getPages(), userPageResult.getRecords()); } @Override public BasePageResult queryUserPage(SysUserLinkDeptInternalAgentQueryVo sysUserLinkDeptInternalAgentQueryVo) { return null; } }