| | |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.constant.InspectionStatus; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrder; |
| | | import org.jeecg.modules.eam.entity.EamInspectionOrderDetail; |
| | | import org.jeecg.modules.eam.constant.ReportRepairEnum; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.EamInspectionOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamInspectionOrderRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamInspectionOrderDetailService; |
| | | import org.jeecg.modules.eam.service.IEamInspectionOrderService; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.impl.FlowMyBusinessServiceImpl; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | |
| | | private IEamEquipmentService iEamEquipmentService; |
| | | @Autowired |
| | | private IMdcUserProductionService mdcUserProductionService; |
| | | @Autowired |
| | | private IEamReportRepairService eamReportRepairService; |
| | | @Autowired |
| | | private IEamEquipmentFaultReasonService eamEquipmentFaultReasonService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | |
| | | public boolean editInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | | EamInspectionOrder eamInspectionOrder = new EamInspectionOrder(); |
| | | BeanUtils.copyProperties(eamInspectionOrderRequest, eamInspectionOrder); |
| | | if (StrUtil.isNotEmpty(eamInspectionOrder.getOperator())){ |
| | | eamInspectionOrder.setInspectionStatus(InspectionStatus.IN_PROGRESS.getCode()); |
| | | } |
| | | updateById(eamInspectionOrder); |
| | | //处理明细数据 |
| | | if (CollectionUtil.isNotEmpty(eamInspectionOrderRequest.getTableDetailList())) { |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result<?> inspectionProcess(EamInspectionOrderRequest eamInspectionOrderRequest){ |
| | | public Result<?> inspectionProcess(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | | try { |
| | | // 参数校验 |
| | | if (!StrUtil.isNotBlank(eamInspectionOrderRequest.getTaskId()) || !StrUtil.isNotBlank(eamInspectionOrderRequest.getDataId())) { |
| | | // 检查请求参数 |
| | | if (!isValidRequest(eamInspectionOrderRequest)) { |
| | | return Result.error("非法参数"); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | eamInspectionOrderRequest.setAssignee(user.getUsername()); |
| | | if (!StrUtil.isNotBlank(userId)) { |
| | | |
| | | // 获取当前登录用户 |
| | | LoginUser user = getCurrentUser(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | return Result.error("账号不存在"); |
| | | } |
| | | eamInspectionOrderRequest.setAssignee(user.getUsername()); |
| | | |
| | | // 数据查询 |
| | | EamInspectionOrder eamInspectionOrder = this.getById(eamInspectionOrderRequest.getDataId()); |
| | | // 获取点检工单信息 |
| | | EamInspectionOrder eamInspectionOrder = getEamInspectionOrder(eamInspectionOrderRequest.getDataId()); |
| | | if (eamInspectionOrder == null) { |
| | | return Result.error("未找到对应数据"); |
| | | } |
| | | |
| | | // 2. 查询流程业务记录(处理空结果) |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("process_instance_id", eamInspectionOrderRequest.getInstanceId()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | // 获取流程业务记录 |
| | | FlowMyBusiness flowMyBusiness = getFlowMyBusiness(eamInspectionOrderRequest.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | return Result.error("流程记录不存在"); |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | |
| | | // 3. 校验用户是否为候选处理人 |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | // 检查用户是否有权限操作任务 |
| | | if (!isUserAuthorized(flowMyBusiness, user)) { |
| | | return Result.error("用户无权操作此任务"); |
| | | } |
| | | |
| | | // 4. 认领任务(处理已被认领的情况) |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return Result.error("任务不存在或已完成"); |
| | | // 认领任务 |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | return Result.error("任务不存在、已完成或已被他人认领"); |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return Result.error("任务已被他人认领"); |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | Map<String, Object> values = new HashMap<>(); |
| | | if ((InspectionStatus.IN_PROGRESS.getCode()).equals(eamInspectionOrder.getInspectionStatus())) { |
| | | //点检人点检结束 |
| | | //查询对应班组长,作为下一节点处理人,存在多个处理人 |
| | | String orgId=iEamEquipmentService.getById(eamInspectionOrder.getEquipmentId()).getOrgId(); |
| | | //筛选出班组长岗位,post为PCR0003 |
| | | List<SysUser> sysUserList= mdcUserProductionService.queryByPostAndProId("PCR0003",orgId); |
| | | List<String> usernameList; |
| | | if (sysUserList.isEmpty()){ |
| | | return Result.error("未找到该设备对应车间的班组长,请联系管理员处理"); |
| | | }else { |
| | | usernameList = sysUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); |
| | | } |
| | | // 设置流程变量 |
| | | |
| | | values.put("dataId", eamInspectionOrder.getId()); |
| | | values.put("organization", "点检人点检结束"); |
| | | values.put("comment","点检人点检结束" ); |
| | | values.put("NextAssignee", usernameList); |
| | | eamInspectionOrderRequest.setComment("点检人点检结束"); |
| | | }else { |
| | | //班组长确认 |
| | | values.put("dataId", eamInspectionOrder.getId()); |
| | | values.put("organization", "班组长确认"); |
| | | values.put("comment","班组长确认" ); |
| | | eamInspectionOrderRequest.setComment("班组长确认"); |
| | | } |
| | | eamInspectionOrderRequest.setValues(values); |
| | | // 设置流程变量 |
| | | setupProcessVariables(eamInspectionOrderRequest, eamInspectionOrder, user); |
| | | |
| | | // 完成流程任务 |
| | | Result result = flowTaskService.complete(eamInspectionOrderRequest); |
| | | if (result.isSuccess()) { |
| | | // 更新状态 |
| | | if ((InspectionStatus.IN_PROGRESS.getCode()).equals(eamInspectionOrder.getInspectionStatus())) { |
| | | //点检完成 |
| | | eamInspectionOrder.setInspectionStatus("3"); |
| | | eamInspectionOrder.setInspectionDate(new Date()); |
| | | eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", eamInspectionOrder.getId())); |
| | | eamInspectionOrderDetailService.saveBatch(eamInspectionOrderRequest.getTableDetailList()); |
| | | this.updateById(eamInspectionOrder); |
| | | } |
| | | } else if ((InspectionStatus.COMPLETED.getCode()).equals(eamInspectionOrder.getInspectionStatus())){ |
| | | // 班组长确认任务 |
| | | eamInspectionOrder.setInspectionStatus("4"); |
| | | eamInspectionOrder.setConfirmUser(user.getUsername()); |
| | | eamInspectionOrder.setConfirmTime(new Date()); |
| | | this.updateById(eamInspectionOrder); |
| | | //处理异常数据进入维修单 |
| | | return result; |
| | | |
| | | // 根据任务完成结果更新工单状态 |
| | | updateOrderStatus(result, eamInspectionOrderRequest, eamInspectionOrder, user); |
| | | |
| | | // 更新工单信息 |
| | | updateEamInspectionOrder(eamInspectionOrder); |
| | | |
| | | //查询数据,进行设备维修处理 |
| | | if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.CONFIRMED.getCode())){ |
| | | updateEamInspectionOrderDetail(eamInspectionOrder); |
| | | } |
| | | |
| | | return Result.OK("操作成功"); |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean isValidRequest(EamInspectionOrderRequest request) { |
| | | return StrUtil.isNotBlank(request.getTaskId()) && StrUtil.isNotBlank(request.getDataId()); |
| | | } |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | try { |
| | | return (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private EamInspectionOrder getEamInspectionOrder(String dataId) { |
| | | return this.getById(dataId); |
| | | } |
| | | |
| | | private FlowMyBusiness getFlowMyBusiness(String instanceId) { |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>().eq("process_instance_id", instanceId)); |
| | | return businessList.isEmpty() ? null : businessList.get(0); |
| | | } |
| | | |
| | | private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | return todoUsers != null && todoUsers.contains(user.getUsername()); |
| | | } |
| | | |
| | | private boolean claimTask(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return false; |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return false; |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | return true; |
| | | } |
| | | |
| | | private void setupProcessVariables(EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user) { |
| | | Map<String, Object> values = new HashMap<>(); |
| | | if (InspectionStatus.IN_PROGRESS.getCode().equals(order.getInspectionStatus()) && user.getUsername().equals(order.getOperator())) { |
| | | // 点检人点检结束 |
| | | String orgId = Optional.ofNullable(iEamEquipmentService.getById(order.getEquipmentId())) |
| | | .map(equipment -> equipment.getOrgId()) |
| | | .orElse(null); |
| | | if (orgId == null) { |
| | | throw new IllegalArgumentException("未找到设备的组织 ID"); |
| | | } |
| | | List<SysUser> sysUserList = mdcUserProductionService.queryByPostAndProId("PCR0003", orgId); |
| | | List<String> usernameList = sysUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); |
| | | if (usernameList.isEmpty()) { |
| | | throw new IllegalArgumentException("未找到该设备对应车间的班组长,请联系管理员处理"); |
| | | } |
| | | values.put("dataId", order.getId()); |
| | | values.put("organization", "点检人点检结束"); |
| | | values.put("comment", "点检人点检结束"); |
| | | values.put("NextAssignee", usernameList); |
| | | request.setComment("点检人点检结束"); |
| | | } else { |
| | | // 班组长确认 |
| | | values.put("dataId", order.getId()); |
| | | values.put("organization", request.getDealSuggestion()); |
| | | values.put("comment", request.getDealSuggestion()); |
| | | values.put("confirmation", request.getDealType()); |
| | | request.setComment(request.getDealSuggestion()); |
| | | if ("2".equals(request.getDealType())) { |
| | | // 班组长驳回 |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(order.getOperator()); |
| | | order.setInspectionStatus("2"); |
| | | values.put("NextAssignee", usernames); |
| | | } |
| | | } |
| | | request.setValues(values); |
| | | } |
| | | |
| | | private void updateOrderStatus(Result result, EamInspectionOrderRequest request, EamInspectionOrder order, LoginUser user) { |
| | | if (result.isSuccess()) { |
| | | if (InspectionStatus.IN_PROGRESS.getCode().equals(order.getInspectionStatus()) && StrUtil.isEmpty(request.getDealType())) { |
| | | // 点检完成 |
| | | order.setInspectionStatus("3"); |
| | | order.setOperateTime(new Date()); |
| | | eamInspectionOrderDetailService.remove(new QueryWrapper<EamInspectionOrderDetail>().eq("order_id", order.getId())); |
| | | eamInspectionOrderDetailService.saveBatch(request.getTableDetailList()); |
| | | } else if (InspectionStatus.COMPLETED.getCode().equals(order.getInspectionStatus()) && StrUtil.isNotEmpty(request.getDealType())) { |
| | | // 班组长确认任务 |
| | | order.setInspectionStatus("4"); |
| | | order.setConfirmUser(user.getUsername()); |
| | | order.setConfirmTime(new Date()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void updateEamInspectionOrder(EamInspectionOrder eamInspectionOrder) { |
| | | this.updateById(eamInspectionOrder); |
| | | } |
| | | |
| | | /** |
| | | * 设备是否存在异常,并进行设备维修 |
| | | * @param eamInspectionOrder |
| | | */ |
| | | private void updateEamInspectionOrderDetail(EamInspectionOrder eamInspectionOrder) { |
| | | EamEquipmentFaultReason eamEquipmentFaultReason=eamEquipmentFaultReasonService. |
| | | getOne(new QueryWrapper<EamEquipmentFaultReason>().eq("fault_code","EFR20250003")); |
| | | List<EamInspectionOrderDetail> eamInspectionOrderDetails = eamInspectionOrderDetailService |
| | | .list(new QueryWrapper<EamInspectionOrderDetail>() |
| | | .eq("order_id", eamInspectionOrder.getId()).eq("report_flag","1")); |
| | | List<EamReportRepair> eamReportRepairs = new ArrayList<>(); |
| | | if (!eamInspectionOrderDetails.isEmpty()) { |
| | | eamInspectionOrderDetails.forEach(item->{ |
| | | EamReportRepair eamReportRepair=new EamReportRepair(); |
| | | eamReportRepair.setEquipmentId(eamInspectionOrder.getEquipmentId()); |
| | | eamReportRepair.setFaultName(eamEquipmentFaultReason.getFaultName()); |
| | | eamReportRepair.setFaultType(eamEquipmentFaultReason.getFaultCategory()); |
| | | eamReportRepair.setFaultDescription(eamEquipmentFaultReason.getFaultDescription()); |
| | | eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name()); |
| | | eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | eamReportRepair.setFaultStartTime(new Date()); |
| | | eamReportRepair.setRemark(item.getExceptionDescription()); |
| | | eamReportRepairs.add(eamReportRepair); |
| | | }); |
| | | } |
| | | if (!eamReportRepairs.isEmpty()) { |
| | | eamReportRepairService.saveBatch(eamReportRepairs); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 批量作废与领取 |
| | | * @param ids |