| | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | 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.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.OrderCreationMethodEnum; |
| | | import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrder; |
| | | import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrderDetail; |
| | | import org.jeecg.modules.eam.mapper.EamWeekMaintenanceOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamWeekMaintenanceQuery; |
| | | import org.jeecg.modules.eam.request.EamWeekMaintenanceRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamReportRepairService; |
| | | import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderDetailService; |
| | | import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderService; |
| | | 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.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | /** |
| | | * @Description: 周保工单 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-04-02 |
| | | * @Date: 2025-04-02 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service("IEamWeekMaintenanceOrderService") |
| | |
| | | @Autowired |
| | | private IEamWeekMaintenanceOrderDetailService eamWeekMaintenanceOrderDetailService; |
| | | |
| | | @Resource |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Resource |
| | | @Autowired |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | @Autowired |
| | | private IEamReportRepairService eamReportRepairService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | order.setRemark(request.getRemark()); |
| | | //状态初始化 |
| | | order.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name()); |
| | | order.setCreationMethod(OrderCreationMethodEnum.MANUAL.name()); |
| | | order.setCreationMethod(request.getCreationMethod()); |
| | | //删除标记 |
| | | order.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | eamWeekMaintenanceOrderMapper.insert(order); |
| | | //处理明细数据 |
| | | if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setOrderId(order.getId()); |
| | |
| | | eamWeekMaintenanceOrderDetailService.saveBatch(request.getTableDetailList()); |
| | | } |
| | | //判断是否存在保养人 如果存在则启动流程 |
| | | if(StringUtils.isNotBlank(order.getOperator())) { |
| | | if (StringUtils.isNotBlank(order.getOperator())) { |
| | | //启动流程 |
| | | flowCommonService.initActBusiness("工单号:" + order.getOrderNum() + ";开始进行设备周保", |
| | | order.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null); |
| | |
| | | usernames.add(order.getOperator()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables); |
| | | if(result != null){ |
| | | if (result != null) { |
| | | //更新周保状态 |
| | | order.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); |
| | | order.setActualStartTime(new Date()); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editWeekMaintenance(EamWeekMaintenanceRequest request) { |
| | | EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId()); |
| | | if(entity == null){ |
| | | if (entity == null) { |
| | | throw new JeecgBootException("编辑的数据已删除,请刷新重试!"); |
| | | } |
| | | if(!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())){ |
| | | if (!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) { |
| | | throw new JeecgBootException("只有待保养状态的数据才可编辑!"); |
| | | } |
| | | entity.setMaintenanceDate(request.getMaintenanceDate()); |
| | |
| | | |
| | | eamWeekMaintenanceOrderMapper.updateById(entity); |
| | | //处理详情 |
| | | if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | List<EamWeekMaintenanceOrderDetail> addList = new ArrayList<>(); |
| | | List<EamWeekMaintenanceOrderDetail> updateList = new ArrayList<>(); |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setOrderId(entity.getId()); |
| | | if(tableDetail.getId() == null){ |
| | | if (tableDetail.getId() == null) { |
| | | addList.add(tableDetail); |
| | | }else { |
| | | } else { |
| | | updateList.add(tableDetail); |
| | | } |
| | | }); |
| | | if(CollectionUtil.isNotEmpty(addList)){ |
| | | if (CollectionUtil.isNotEmpty(addList)) { |
| | | eamWeekMaintenanceOrderDetailService.saveBatch(addList); |
| | | } |
| | | if(CollectionUtil.isNotEmpty(updateList)){ |
| | | if (CollectionUtil.isNotEmpty(updateList)) { |
| | | eamWeekMaintenanceOrderDetailService.updateBatchById(updateList); |
| | | } |
| | | } |
| | | if(CollectionUtil.isNotEmpty(request.getRemoveDetailList())) { |
| | | if (CollectionUtil.isNotEmpty(request.getRemoveDetailList())) { |
| | | List<String> ids = request.getRemoveDetailList().stream().map(EamWeekMaintenanceOrderDetail::getId).collect(Collectors.toList()); |
| | | eamWeekMaintenanceOrderDetailService.removeBatchByIds(ids); |
| | | } |
| | | //判断是否存在保养人 如果存在则启动流程 |
| | | if(StringUtils.isNotBlank(entity.getOperator())) { |
| | | if (StringUtils.isNotBlank(entity.getOperator())) { |
| | | //启动流程 |
| | | flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";开始进行设备周保", |
| | | entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null); |
| | |
| | | usernames.add(entity.getOperator()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables); |
| | | if(result != null){ |
| | | if (result != null) { |
| | | //更新周保状态 |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); |
| | | entity.setActualStartTime(new Date()); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean collect(String id) { |
| | | EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(id); |
| | | if(entity == null) { |
| | | if (entity == null) { |
| | | throw new JeecgBootException("要领取的工单不存在,请刷新重试!"); |
| | | } |
| | | if(!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) { |
| | | if (!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) { |
| | | throw new JeecgBootException("该工单已进行过领取!"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | |
| | | usernames.add(entity.getOperator()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables); |
| | | if(result != null){ |
| | | if (result != null) { |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean approval(EamWeekMaintenanceRequest request) { |
| | | EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("审批的数据已删除,请刷新重试!"); |
| | | } |
| | | // 获取当前登录用户 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("未获取到登录用户,请重新登录后再试!"); |
| | | } |
| | | request.setAssignee(user.getUsername()); |
| | | // 获取流程业务记录 |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("流程实例不存在,请刷新后重试!"); |
| | | } |
| | | |
| | | boolean userAuthorized = isUserAuthorized(flowMyBusiness, user); |
| | | if (!userAuthorized) { |
| | | throw new JeecgBootException("用户无权操作此任务,请刷新后重试!"); |
| | | } |
| | | // 认领任务 |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("任务不存在、已完成或已被他人认领!"); |
| | | } |
| | | |
| | | EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设备不存在,请检查!"); |
| | | } |
| | | |
| | | WeekMaintenanceStatusEnum status = WeekMaintenanceStatusEnum.getInstance(entity.getMaintenanceStatus()); |
| | | if (status == null) { |
| | | return false; |
| | | } |
| | | //流程变量 |
| | | Map<String, Object> values = new HashMap<>(); |
| | | switch (status) { |
| | | case UNDER_MAINTENANCE: |
| | | //执行完成 |
| | | List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0003); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未分配给班组长,无法进入下级审批!"); |
| | | } |
| | | List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", "周保执行结束"); |
| | | values.put("comment", "周保执行结束"); |
| | | values.put("NextAssignee", userApprovalList); |
| | | request.setComment("周保执行结束"); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_CONFIRM.name()); |
| | | entity.setActualEndTime(new Date()); |
| | | //处理附件 |
| | | if (CollectionUtil.isNotEmpty(request.getImageFilesResult())) { |
| | | List<FileUploadResult> fileUploadResultList = request.getImageFilesResult(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResultList); |
| | | entity.setImageFiles(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | //处理详情 |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | eamWeekMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList()); |
| | | } |
| | | break; |
| | | case WAIT_CONFIRM: |
| | | if(StringUtils.isBlank(equipment.getEquipmentManager())) { |
| | | throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!"); |
| | | } |
| | | //班组长确认 |
| | | userApprovalList = new ArrayList<>(); |
| | | userApprovalList.add(equipment.getEquipmentManager()); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | values.put("confirmation", request.getConfirmDealType()); |
| | | request.setComment(request.getConfirmComment()); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_INITIAL_ACCEPTANCE.name()); |
| | | entity.setConfirmUser(user.getUsername()); |
| | | entity.setConfirmComment(request.getConfirmComment()); |
| | | entity.setConfirmTime(new Date()); |
| | | entity.setConfirmDealType(request.getConfirmDealType()); |
| | | if (CommonConstant.HAS_CANCLE.equals(request.getConfirmDealType())) { |
| | | //驳回 |
| | | userApprovalList = new ArrayList<>(); |
| | | userApprovalList.add(entity.getOperator()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); |
| | | } |
| | | //处理报修 |
| | | List<EamWeekMaintenanceOrderDetail> collect = request.getTableDetailList().stream().filter((detail) -> CommonConstant.DEFAULT_1.equals(detail.getReportFlag())).collect(Collectors.toList()); |
| | | if (CollectionUtil.isNotEmpty(collect)) { |
| | | eamReportRepairService.reportRepairFromMaintenance(equipment.getId(), entity.getOperator(), collect); |
| | | } |
| | | break; |
| | | case WAIT_INITIAL_ACCEPTANCE: |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0005); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未分配给设能部管理员,无法进入下级审批!"); |
| | | } |
| | | userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getInitialAcceptanceComment()); |
| | | values.put("comment", request.getInitialAcceptanceComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | request.setComment(request.getInitialAcceptanceComment()); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_FINAL_ACCEPTANCE.name()); |
| | | entity.setInitialAcceptanceUser(user.getUsername()); |
| | | entity.setInitialAcceptanceComment(request.getInitialAcceptanceComment()); |
| | | entity.setInitialAcceptanceTime(new Date()); |
| | | //处理附件 |
| | | if (CollectionUtil.isNotEmpty(request.getInitialAcceptanceFilesResult())) { |
| | | List<FileUploadResult> fileUploadResultList = request.getInitialAcceptanceFilesResult(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResultList); |
| | | entity.setInitialAcceptanceFiles(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | break; |
| | | case WAIT_FINAL_ACCEPTANCE: |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getInitialAcceptanceComment()); |
| | | values.put("comment", request.getInitialAcceptanceComment()); |
| | | request.setComment(request.getInitialAcceptanceComment()); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.COMPLETE.name()); |
| | | entity.setFinalAcceptanceUser(user.getUsername()); |
| | | entity.setFinalAcceptanceComment(request.getFinalAcceptanceComment()); |
| | | entity.setFinalAcceptanceTime(new Date()); |
| | | //处理附件 |
| | | if (CollectionUtil.isNotEmpty(request.getFinalAcceptanceFilesResult())) { |
| | | List<FileUploadResult> fileUploadResultList = request.getFinalAcceptanceFilesResult(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | try { |
| | | String referenceFile = mapper.writeValueAsString(fileUploadResultList); |
| | | entity.setFinalAcceptanceFiles(referenceFile); |
| | | } catch (JsonProcessingException e) { |
| | | log.error("JSON转换失败:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | request.setValues(values); |
| | | |
| | | // 完成流程任务 |
| | | Result result = flowTaskService.complete(request); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审批失败,请刷新查看!"); |
| | | } |
| | | //保存工单 |
| | | eamWeekMaintenanceOrderMapper.updateById(entity); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public List<EamWeekMaintenanceOrder> selectUnCompleteOrder(String expiredDate) { |
| | | LambdaQueryWrapper<EamWeekMaintenanceOrder> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.lt(EamWeekMaintenanceOrder::getMaintenanceDate, expiredDate); |
| | | List<String> unCompleteStatus = new ArrayList<>(); |
| | | unCompleteStatus.add(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name()); |
| | | unCompleteStatus.add(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); |
| | | queryWrapper.in(EamWeekMaintenanceOrder::getMaintenanceStatus, unCompleteStatus); |
| | | queryWrapper.orderByAsc(EamWeekMaintenanceOrder::getMaintenanceDate); |
| | | return eamWeekMaintenanceOrderMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | //业务是否干预流程,业务干预,流程干预,指定人员进行处理 |
| | | //获取下一步处理人 |
| | | Object object=values.get("NextAssignee"); |
| | | Object object = values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | } |