| | |
| | | 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.core.toolkit.CollectionUtils; |
| | | 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.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.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | |
| | | @Autowired |
| | | private IBaseFactoryUserService baseFactoryUserService; |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | |
| | | private IEamReportRepairService eamReportRepairService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService eamEquipmentExtendService; |
| | | @Autowired |
| | | private IEamBaseHFCodeService hfCodeService; |
| | | @Autowired |
| | | private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; |
| | | |
| | | @Override |
| | | public IPage<EamSecondMaintenanceOrder> queryPageList(Page<EamSecondMaintenanceOrder> page, EamSecondMaintenanceQuery query) { |
| | |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据车间过滤设备 |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); |
| | | //没有选择设备,根据中心过滤设备 |
| | | List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId())); |
| | | if(!CollectionUtils.isEmpty(baseFactoryUserList)){ |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | } else { |
| | | return page; |
| | | } |
| | | } |
| | | //查询条件过滤 |
| | | if (query != null) { |
| | |
| | | order.setStandardId(request.getStandardId()); |
| | | order.setMaintenanceDate(request.getMaintenanceDate()); |
| | | order.setOperator(request.getOperator()); |
| | | //技术状态鉴定表 |
| | | EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.SECOND_MAINTENANCE.name()); |
| | | if(eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置技术状态鉴定表的HF编码,添加失败!"); |
| | | } |
| | | order.setHfCode(eamBaseHFCode.getHfCode()); |
| | | order.setRemark(request.getRemark()); |
| | | //状态初始化 |
| | | order.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_MAINTENANCE.name()); |
| | |
| | | order.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | eamSecondMaintenanceOrderMapper.insert(order); |
| | | //处理明细数据 |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setOrderId(order.getId()); |
| | | List<EamMaintenanceStandardDetail> eamMaintenanceStandardDetailList= eamMaintenanceStandardDetailService.selectByStandardId(order.getStandardId()); |
| | | List<EamSecondMaintenanceOrderDetail> requestTableDetailList = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(eamMaintenanceStandardDetailList)) { |
| | | eamMaintenanceStandardDetailList.forEach(item -> { |
| | | EamSecondMaintenanceOrderDetail detail = new EamSecondMaintenanceOrderDetail(); |
| | | BeanUtils.copyProperties(item, detail); |
| | | detail.setOrderId(order.getId()); |
| | | requestTableDetailList.add(detail); |
| | | }); |
| | | secondMaintenanceOrderDetailService.saveBatch(request.getTableDetailList()); |
| | | secondMaintenanceOrderDetailService.saveBatch(requestTableDetailList); |
| | | } |
| | | //判断是否存在保养人 如果存在则启动流程 |
| | | if (StringUtils.isNotBlank(order.getOperator())) { |
| | | //启动流程 |
| | | flowCommonService.initActBusiness("工单号: " + order.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(), |
| | | order.getId(), "IEamSecondMaintenanceOrderService", "second_maintenance_process", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", order.getId()); |
| | | if (StrUtil.isEmpty(order.getRemark())) { |
| | | variables.put("organization", "新增二保工单默认启动流程"); |
| | | variables.put("comment", "新增二保工单默认启动流程"); |
| | | } else { |
| | | variables.put("organization", order.getRemark()); |
| | | variables.put("comment", order.getRemark()); |
| | | } |
| | | variables.put("proofreading", true); |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(order.getOperator()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("second_maintenance_process", variables); |
| | | if (result != null) { |
| | | //更新周保状态 |
| | | order.setMaintenanceStatus(SecondMaintenanceStatusEnum.UNDER_MAINTENANCE.name()); |
| | | order.setActualStartTime(new Date()); |
| | | eamSecondMaintenanceOrderMapper.updateById(order); |
| | | //更新设备保养状态 |
| | | eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_SECOND_MAINTENANCE.name()); |
| | | return result.isSuccess(); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | throw new JeecgBootException("只有待保养状态的数据才可编辑!"); |
| | | } |
| | | entity.setMaintenanceDate(request.getMaintenanceDate()); |
| | | entity.setOperator(request.getOperator()); |
| | | entity.setRemark(request.getRemark()); |
| | | |
| | | eamSecondMaintenanceOrderMapper.updateById(entity); |
| | | //处理详情 |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | List<EamSecondMaintenanceOrderDetail> addList = new ArrayList<>(); |
| | | List<EamSecondMaintenanceOrderDetail> updateList = new ArrayList<>(); |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setOrderId(entity.getId()); |
| | | if (tableDetail.getId() == null) { |
| | | addList.add(tableDetail); |
| | | } else { |
| | | updateList.add(tableDetail); |
| | | } |
| | | }); |
| | | if (CollectionUtil.isNotEmpty(addList)) { |
| | | secondMaintenanceOrderDetailService.saveBatch(addList); |
| | | } |
| | | if (CollectionUtil.isNotEmpty(updateList)) { |
| | | secondMaintenanceOrderDetailService.updateBatchById(updateList); |
| | | } |
| | | } |
| | | if (CollectionUtil.isNotEmpty(request.getRemoveDetailList())) { |
| | | List<String> ids = request.getRemoveDetailList().stream().map(EamSecondMaintenanceOrderDetail::getId).collect(Collectors.toList()); |
| | | secondMaintenanceOrderDetailService.removeBatchByIds(ids); |
| | | } |
| | | //判断是否存在保养人 如果存在则启动流程 |
| | | if (StringUtils.isNotBlank(entity.getOperator())) { |
| | | //启动流程 |
| | |
| | | case UNDER_MAINTENANCE: |
| | | //执行完成 |
| | | //设备管理员确认 |
| | | String equipmentManager = equipment.getEquipmentManager(); |
| | | if(StringUtils.isBlank(equipmentManager)) { |
| | | throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!"); |
| | | } |
| | | userApprovalList = Collections.singletonList(equipmentManager); |
| | | // String equipmentManager = equipment.getEquipmentManager(); |
| | | // if(StringUtils.isBlank(equipmentManager)) { |
| | | // throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!"); |
| | | // } |
| | | // userApprovalList = Collections.singletonList(equipmentManager); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", "二保执行结束"); |
| | | values.put("comment", "二保执行结束"); |
| | | values.put("NextAssignee", userApprovalList); |
| | | // values.put("NextAssignee", userApprovalList); |
| | | request.setComment("二保执行结束"); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.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())) { |
| | | secondMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList()); |
| | | } |
| | | //更新设备保养状态 |
| | | eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.SECOND_MAINTENANCE_WAIT_CONFIRM.name()); |
| | | break; |
| | | case WAIT_CONFIRM: |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0003); |
| | | userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(),null, BusinessCodeConst.PCR0003); |
| | | 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.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | values.put("confirmation", request.getConfirmDealType()); |
| | | request.setComment(request.getConfirmComment()); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_LEADER_CONFIRM.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<EamSecondMaintenanceOrderDetail> collect = request.getTableDetailList().stream().filter((detail) -> CommonConstant.DEFAULT_1.equals(detail.getReportFlag())).collect(Collectors.toList()); |
| | | if (CollectionUtil.isNotEmpty(collect)) { |
| | | eamReportRepairService.reportRepairFromSecondMaintenance(equipment.getId(), entity.getOperator(), collect); |
| | | } |
| | | break; |
| | | case WAIT_LEADER_CONFIRM: |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getLeaderConfirmComment()); |
| | | values.put("comment", request.getLeaderConfirmComment()); |
| | | request.setComment(request.getLeaderConfirmComment()); |
| | | //设置entity |
| | | entity.setMaintenanceStatus(SecondMaintenanceStatusEnum.COMPLETE.name()); |
| | | entity.setConfirmLeader(user.getUsername()); |
| | | entity.setLeaderConfirmComment(request.getLeaderConfirmComment()); |
| | | entity.setLeaderConfirmTime(new Date()); |
| | | //更新设备保养状态 |
| | | eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name()); |
| | | break; |