| | |
| | | import org.jeecg.common.util.FillRuleUtil; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.base.entity.EamBaseRepairDepart; |
| | | import org.jeecg.modules.eam.base.entity.EamBaseRepairDepartUser; |
| | | import org.jeecg.modules.eam.base.mapper.EamBaseRepairDepartUserMapper; |
| | | import org.jeecg.modules.eam.base.service.IEamBaseRepairDepartService; |
| | | import org.jeecg.modules.eam.base.mapper.EamBaseRepairDepartMapper; |
| | | import org.jeecg.modules.eam.base.model.EamBaseRepairDepartTreeModel; |
| | | import org.jeecg.modules.eam.base.model.RepairDepartIdModel; |
| | | import org.jeecg.modules.eam.base.util.FindsRepairDepartsChildrenUtil; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.mapper.SysUserMapper; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author: Lius |
| | |
| | | @Resource |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Resource |
| | | private EamBaseRepairDepartUserMapper repairDepartUserMapper; |
| | | |
| | | /** |
| | | * queryTreeList 对应 queryTreeList 查询所有的维修部门班组数据,以树结构形式响应给前端 |
| | | */ |
| | |
| | | query.orderByAsc(EamBaseRepairDepart::getDepartOrder); |
| | | List<EamBaseRepairDepart> list = this.list(query); |
| | | //设置用户id,让前台显示 |
| | | // this.setUserIdsByProList(list); |
| | | this.setUserIdsByProList(list); |
| | | //调用wrapTreeDataToTreeList方法生成树状数据 |
| | | return FindsRepairDepartsChildrenUtil.wrapTreeDataToTreeList(list); |
| | | } |
| | |
| | | this.checkChildrenExists(id, idList); |
| | | boolean result = this.removeByIds(idList); |
| | | //根据维修部门班组id删除用户与维修部门班组关系 |
| | | // repairDepartUserMapper.delete(new LambdaQueryWrapper<EamBaseRepairDepartUser>().in(EamBaseRepairDepartUser::getDepartId, idList)); |
| | | repairDepartUserMapper.delete(new LambdaQueryWrapper<EamBaseRepairDepartUser>().in(EamBaseRepairDepartUser::getDepartId, idList)); |
| | | //根据维修部门班组id删除维修部门班组与设备关系 |
| | | // repairDepartEquipmentMapper.delete(new LambdaQueryWrapper<SysMaintainDepartEquipment>().in(SysMaintainDepartEquipment::getMaintainDepartId, idList)); |
| | | return result; |
| | |
| | | } |
| | | this.removeByIds(idList); |
| | | //根据维修部门班组id删除用户与维修部门班组关系 |
| | | // repairDepartUserMapper.delete(new LambdaQueryWrapper<EamBaseRepairDepartUser>().in(EamBaseRepairDepartUser::getDepartId, idList)); |
| | | repairDepartUserMapper.delete(new LambdaQueryWrapper<EamBaseRepairDepartUser>().in(EamBaseRepairDepartUser::getDepartId, idList)); |
| | | //根据维修部门班组id删除维修部门班组与设备关系 |
| | | // repairDepartEquipmentMapper.delete(new LambdaQueryWrapper<SysMaintainDepartEquipment>().in(SysMaintainDepartEquipment::getMaintainDepartId, idList)); |
| | | } |
| | |
| | | // return this.baseMapper.queryRepDepByPid(pid); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 根据用户id获取维修部门班组下拉树选项 |
| | | // */ |
| | | // @Override |
| | | // public List<RepairDepartIdModel> loadMaintainDepartTreeOptions(String userId) { |
| | | // //获取所有维修部门班组数据 |
| | | // List<EamBaseRepairDepart> repairDepartList = this.baseMapper.selectList(new LambdaQueryWrapper<EamBaseRepairDepart>().eq(EamBaseRepairDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(EamBaseRepairDepart::getDepartOrder)); |
| | | // //根据用户id获取拥有的维修部门班组信息集合 |
| | | // List<String> repairDepartIds = repairDepartUserMapper.queryRepairDepartIdsByUserId(userId); |
| | | // List<String> allMaintainDepartIds = new ArrayList<>(); |
| | | // //找到所有维修部门班组id的上级id |
| | | // if (repairDepartIds != null && !repairDepartIds.isEmpty()) { |
| | | // for (String repairDepartId : repairDepartIds) { |
| | | // this.getAllMaintainDepartIds(repairDepartList, repairDepartId, allMaintainDepartIds); |
| | | // } |
| | | // } |
| | | // //过滤维修部门班组数据 |
| | | // List<EamBaseRepairDepart> list = repairDepartList.stream().filter((EamBaseRepairDepart eamBaseRepairDepart) -> allMaintainDepartIds.contains(eamBaseRepairDepart.getId())).collect(Collectors.toList()); |
| | | // return FindsRepairDepartsChildrenUtil.wrapTreeDataToMaintainDepartIdTreeList(list); |
| | | // } |
| | | /** |
| | | * 根据用户id获取维修部门班组下拉树选项 |
| | | */ |
| | | @Override |
| | | public List<RepairDepartIdModel> loadMaintainDepartTreeOptions(String userId) { |
| | | //获取所有维修部门班组数据 |
| | | List<EamBaseRepairDepart> repairDepartList = this.baseMapper.selectList(new LambdaQueryWrapper<EamBaseRepairDepart>().eq(EamBaseRepairDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(EamBaseRepairDepart::getDepartOrder)); |
| | | //根据用户id获取拥有的维修部门班组信息集合 |
| | | List<String> repairDepartIds = repairDepartUserMapper.queryRepairDepartIdsByUserId(userId); |
| | | List<String> allMaintainDepartIds = new ArrayList<>(); |
| | | //找到所有维修部门班组id的上级id |
| | | if (repairDepartIds != null && !repairDepartIds.isEmpty()) { |
| | | for (String repairDepartId : repairDepartIds) { |
| | | this.getAllMaintainDepartIds(repairDepartList, repairDepartId, allMaintainDepartIds); |
| | | } |
| | | } |
| | | //过滤维修部门班组数据 |
| | | List<EamBaseRepairDepart> list = repairDepartList.stream().filter((EamBaseRepairDepart eamBaseRepairDepart) -> allMaintainDepartIds.contains(eamBaseRepairDepart.getId())).collect(Collectors.toList()); |
| | | return FindsRepairDepartsChildrenUtil.wrapTreeDataToMaintainDepartIdTreeList(list); |
| | | } |
| | | // |
| | | // /** |
| | | // * 递归查询所有子节点id |
| | |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 获取所有的维修部门班组id(包含所有上级) |
| | | // */ |
| | | // private void getAllMaintainDepartIds(List<EamBaseRepairDepart> repairDepartList, String repairDepartId, List<String> allMaintainDepartIds) { |
| | | // if (!allMaintainDepartIds.contains(repairDepartId)) { |
| | | // allMaintainDepartIds.add(repairDepartId); |
| | | // } |
| | | // for (EamBaseRepairDepart eamBaseRepairDepart : repairDepartList) { |
| | | // if (StringUtils.isEmpty(eamBaseRepairDepart.getParentId())) { |
| | | // continue; |
| | | // } |
| | | // if (repairDepartId.equals(eamBaseRepairDepart.getId())) { |
| | | // if (!allMaintainDepartIds.contains(eamBaseRepairDepart.getParentId())) { |
| | | // allMaintainDepartIds.add(eamBaseRepairDepart.getParentId()); |
| | | // getAllMaintainDepartIds(repairDepartList, eamBaseRepairDepart.getParentId(), allMaintainDepartIds); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // /** |
| | | // * 通过维修部门班组集合为维修部门班组设置用户id,用于前台展示 |
| | | // */ |
| | | // private void setUserIdsByProList(List<EamBaseRepairDepart> repairDepartList) { |
| | | // //查询负责部门不为空的情况 |
| | | // LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>(); |
| | | // query.isNotNull(SysUser::getDepartIds); |
| | | // List<SysUser> users = sysUserMapper.selectList(query); |
| | | // Map<String, Object> map = new HashMap(5); |
| | | // //先循环一遍找到不同的负责维修部门班组id |
| | | // for (SysUser user : users) { |
| | | // String repairDepartIds = user.getRepairDepartIds(); |
| | | // if (StringUtils.isNotBlank(repairDepartIds)) { |
| | | // String[] repairDepartIdArray = repairDepartIds.split(","); |
| | | // for (String repairDepartId : repairDepartIdArray) { |
| | | // if (map.containsKey(repairDepartId)) { |
| | | // String userIds = map.get(repairDepartId) + "," + user.getId(); |
| | | // map.put(repairDepartId, userIds); |
| | | // } else { |
| | | // map.put(repairDepartId, user.getId()); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // //循环维修部门班组集合找到维修部门班组id对应的负责用户 |
| | | // for (EamBaseRepairDepart eamBaseRepairDepart : repairDepartList) { |
| | | // if (map.containsKey(eamBaseRepairDepart.getId())) { |
| | | // eamBaseRepairDepart.setDirectorUserIds(map.get(eamBaseRepairDepart.getId()).toString()); |
| | | // } |
| | | // } |
| | | // } |
| | | /** |
| | | * 获取所有的维修部门班组id(包含所有上级) |
| | | */ |
| | | private void getAllMaintainDepartIds(List<EamBaseRepairDepart> repairDepartList, String repairDepartId, List<String> allMaintainDepartIds) { |
| | | if (!allMaintainDepartIds.contains(repairDepartId)) { |
| | | allMaintainDepartIds.add(repairDepartId); |
| | | } |
| | | for (EamBaseRepairDepart eamBaseRepairDepart : repairDepartList) { |
| | | if (StringUtils.isEmpty(eamBaseRepairDepart.getParentId())) { |
| | | continue; |
| | | } |
| | | if (repairDepartId.equals(eamBaseRepairDepart.getId())) { |
| | | if (!allMaintainDepartIds.contains(eamBaseRepairDepart.getParentId())) { |
| | | allMaintainDepartIds.add(eamBaseRepairDepart.getParentId()); |
| | | getAllMaintainDepartIds(repairDepartList, eamBaseRepairDepart.getParentId(), allMaintainDepartIds); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过维修部门班组集合为维修部门班组设置用户id,用于前台展示 |
| | | */ |
| | | private void setUserIdsByProList(List<EamBaseRepairDepart> repairDepartList) { |
| | | //查询负责部门不为空的情况 |
| | | LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>(); |
| | | query.isNotNull(SysUser::getDepartIds); |
| | | List<SysUser> users = sysUserMapper.selectList(query); |
| | | Map<String, Object> map = new HashMap(5); |
| | | //先循环一遍找到不同的负责维修部门班组id |
| | | for (SysUser user : users) { |
| | | String repairDepartIds = user.getRepairDepartIds(); |
| | | if (StringUtils.isNotBlank(repairDepartIds)) { |
| | | String[] repairDepartIdArray = repairDepartIds.split(","); |
| | | for (String repairDepartId : repairDepartIdArray) { |
| | | if (map.containsKey(repairDepartId)) { |
| | | String userIds = map.get(repairDepartId) + "," + user.getId(); |
| | | map.put(repairDepartId, userIds); |
| | | } else { |
| | | map.put(repairDepartId, user.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //循环维修部门班组集合找到维修部门班组id对应的负责用户 |
| | | for (EamBaseRepairDepart eamBaseRepairDepart : repairDepartList) { |
| | | if (map.containsKey(eamBaseRepairDepart.getId())) { |
| | | eamBaseRepairDepart.setDirectorUserIds(map.get(eamBaseRepairDepart.getId()).toString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |