| | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.pro.packaged.Q; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.DataBaseConstant; |
| | |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.*; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.EamEquipmentMapper; |
| | | import org.jeecg.modules.eam.mapper.EamMaintenanceStandardMapper; |
| | | import org.jeecg.modules.eam.mapper.EamSecondMaintenanceOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamSecondMaintenanceQuery; |
| | | import org.jeecg.modules.eam.request.EamSecondMaintenanceRequest; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil; |
| | | import org.jeecg.modules.eam.vo.EamEquipmentTree; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.mapper.BaseFactoryMapper; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private IEamBaseHFCodeService hfCodeService; |
| | | @Autowired |
| | | private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; |
| | | @Autowired |
| | | private EamMaintenanceStandardMapper eamMaintenanceStandardMapper; |
| | | @Resource |
| | | private BaseFactoryMapper baseFactoryMapper; |
| | | |
| | | @Override |
| | | public IPage<EamSecondMaintenanceOrder> queryPageList(Page<EamSecondMaintenanceOrder> page, EamSecondMaintenanceQuery query) { |
| | | QueryWrapper<EamSecondMaintenanceOrder> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("wmo.del_flag",CommonConstant.DEL_FLAG_0.toString()); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | |
| | | } |
| | | |
| | | return eamSecondMaintenanceOrderMapper.queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 批量新增树结构 |
| | | */ |
| | | @Override |
| | | public List<EamEquipmentTree> getTree(){ |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) return Collections.emptyList(); |
| | | |
| | | // 构建通用查询条件 |
| | | QueryWrapper<EamMaintenanceStandard> baseQuery = new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("ems.maintenance_category", "SECOND_MAINTENANCE") |
| | | .eq("ems.standard_status", MaintenanceStandardStatusEnum.START.name()) |
| | | .eq("ems.del_flag", CommonConstant.DEL_FLAG_0.toString()); |
| | | |
| | | // 应用数据权限过滤 |
| | | applyDataPermissionFilter(sysUser, baseQuery); |
| | | |
| | | // 单次查询设备列表 |
| | | List<EamEquipment> equipmentList = eamMaintenanceStandardMapper.queryList(baseQuery); |
| | | if (CollectionUtils.isEmpty(equipmentList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 获取关联的工厂代码 |
| | | Set<String> factoryOrgCodes = equipmentList.stream() |
| | | .map(EamEquipment::getFactoryOrgCode) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 单次查询所有工厂数据(包含完整树结构) |
| | | List<BaseFactory> allFactories = baseFactoryService.list( |
| | | new LambdaQueryWrapper<BaseFactory>() |
| | | .eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()) |
| | | .orderByAsc(BaseFactory::getSorter)); |
| | | |
| | | // 提取权限关联的工厂节点ID(包含所有父节点) |
| | | Set<String> authorizedFactoryIds = extractAuthorizedFactoryIds( |
| | | allFactories, factoryOrgCodes); |
| | | |
| | | // 过滤出有效工厂结构 |
| | | List<BaseFactory> validFactories = allFactories.stream() |
| | | .filter(f -> authorizedFactoryIds.contains(f.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // ===构建设备树 === |
| | | Map<String, List<EamEquipment>> equipmentMap = equipmentList.stream() |
| | | .collect(Collectors.groupingBy(EamEquipment::getFactoryOrgCode)); |
| | | |
| | | // 构建基础树 |
| | | List<EamEquipmentTree> treeList = FindsEquipmentEamCenterUtil.wrapEquipmentBaseFactoryTreeList(validFactories); |
| | | |
| | | // 填充设备数据 |
| | | populateEquipmentNodes(treeList, equipmentMap); |
| | | return treeList; |
| | | } |
| | | |
| | | // 应用数据权限条件(共用方法) |
| | | private void applyDataPermissionFilter(LoginUser user, QueryWrapper<EamMaintenanceStandard> query) { |
| | | if (StringUtils.isNotBlank(user.getEamEquipmentIds())) { |
| | | List<String> equipmentIds = Arrays.asList(user.getEamEquipmentIds().split(",")); |
| | | query.in("e.equipment_code", equipmentIds); |
| | | } else { |
| | | List<BaseFactoryUser> factoryUsers = baseFactoryUserService.list( |
| | | new LambdaQueryWrapper<BaseFactoryUser>() |
| | | .eq(BaseFactoryUser::getUserId, user.getId())); |
| | | |
| | | if (CollectionUtils.isNotEmpty(factoryUsers)) { |
| | | Set<String> factoryIds = factoryUsers.stream() |
| | | .map(BaseFactoryUser::getFactoryId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | Set<String> factoryCodes = baseFactoryService.listByIds(factoryIds).stream() |
| | | .map(BaseFactory::getOrgCode) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | query.in("e.factory_org_code", factoryCodes); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 提取授权工厂ID |
| | | private Set<String> extractAuthorizedFactoryIds(List<BaseFactory> allFactories, Set<String> authOrgCodes) { |
| | | Set<String> result = new HashSet<>(); |
| | | // 构建ID->工厂的映射 |
| | | Map<String, BaseFactory> factoryMap = allFactories.stream() |
| | | .collect(Collectors.toMap(BaseFactory::getId, Function.identity())); |
| | | |
| | | // 逆向查找父节点链 |
| | | for (BaseFactory factory : allFactories) { |
| | | if (authOrgCodes.contains(factory.getOrgCode())) { |
| | | collectParentIds(factoryMap, factory.getId(), result); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // 递归收集父节点ID |
| | | private void collectParentIds(Map<String, BaseFactory> factoryMap, String currentId, Set<String> idSet) { |
| | | if (StringUtils.isEmpty(currentId) || idSet.contains(currentId)) return; |
| | | |
| | | idSet.add(currentId); |
| | | BaseFactory factory = factoryMap.get(currentId); |
| | | if (factory != null && StringUtils.isNotBlank(factory.getParentId())) { |
| | | collectParentIds(factoryMap, factory.getParentId(), idSet); |
| | | } |
| | | } |
| | | |
| | | // 填充设备节点(非递归) |
| | | private void populateEquipmentNodes(List<EamEquipmentTree> treeList, |
| | | Map<String, List<EamEquipment>> equipmentMap) { |
| | | for (EamEquipmentTree node : treeList) { |
| | | |
| | | String orgCode = resolveOrgCodeFromTree(node); // 需实现该逻辑 |
| | | |
| | | // 关联设备数据 |
| | | List<EamEquipment> devices = equipmentMap.getOrDefault(orgCode, Collections.emptyList()); |
| | | if (!CollectionUtils.isEmpty(devices)) { |
| | | for (EamEquipment device : devices) { |
| | | EamEquipmentTree deviceNode = new EamEquipmentTree().convert(device); |
| | | deviceNode.setParentId(node.getKey()); |
| | | deviceNode.setType(2); |
| | | deviceNode.setLeaf(true); // 明确标记为叶子节点 |
| | | node.getChildren().add(deviceNode); |
| | | } |
| | | // 只有当存在设备时才标记为非叶子 |
| | | node.setLeaf(false); |
| | | } |
| | | |
| | | // 继续处理子节点(工厂层级) |
| | | if (!CollectionUtils.isEmpty(node.getChildren())) { |
| | | populateEquipmentNodes(node.getChildren(), equipmentMap); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 解析方法 |
| | | private String resolveOrgCodeFromTree(EamEquipmentTree node) { |
| | | BaseFactory factory =baseFactoryMapper.selectById(node.getKey()); |
| | | return factory != null ? factory.getOrgCode() : null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | }else{ |
| | | userApprovalList= userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", entity.getId()); |
| | | if (StrUtil.isEmpty(request.getManageUserResult())){ |
| | | request.setManageUserResult(""); |
| | | if (StrUtil.isEmpty(request.getDealDescription())){ |
| | | request.setDealDescription(""); |
| | | } |
| | | values.put("organization",request.getDealDescription()); |
| | | values.put("comment", request.getManageUserResult()); |
| | | values.put("comment", request.getDealDescription()); |
| | | values.put("manageUserResult",request.getManageUserResult()); |
| | | request.setComment(request.getDealDescription()); |
| | | if (request.getManageUserResult().equals("2")){ |
| | |
| | | entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_ADMIN_CONFIRM.name()); |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0004); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未存在管理员,无法进入下级审批!"); |
| | | throw new JeecgBootException("设备未存在车间设备管理员,无法进入驳回审批!"); |
| | | }else{ |
| | | userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("NextAssignee", userApprovalList); |