| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.impl.el.DateUtil; |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.variable.api.persistence.entity.VariableInstance; |
| | | import org.jeecg.common.api.vo.FileUploadResult; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | |
| | | import org.jeecg.modules.eam.request.EamInspectionOrderRequest; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.eam.vo.EquipmentInspectionStatistics; |
| | | import org.jeecg.modules.eam.vo.EquipmentRepairStatistics; |
| | | 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; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.domain.vo.FlowTaskVo; |
| | | import org.jeecg.modules.flowable.domain.vo.WorkTaskDataVo; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.qywx.message.vo.TemplateCard; |
| | | import org.jeecg.modules.qywx.message.vo.TemplateCardEntity; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.IMdcUserProductionService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.service.IThirdAppService; |
| | | import org.jeecg.modules.system.service.impl.ThirdAppWechatEnterpriseServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private IEamEquipmentExtendService eamEquipmentExtendService; |
| | | @Autowired |
| | | private IMdcProductionService mdcProductionService; |
| | | @Autowired |
| | | private ThirdAppWechatEnterpriseServiceImpl wechatEnterpriseService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | | private HistoryService historyService; |
| | | |
| | | @Value("${wechatEnterprise.cardActionUrl}") |
| | | private String cardActionUrl; |
| | | |
| | | @Override |
| | | public IPage<EamInspectionOrder> queryPageList(Page<EamInspectionOrder> page, EamInspectionOrderQuery query) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<EamInspectionOrder> selectUnReceivedInspectionOrder() { |
| | | return this.baseMapper.selectUnReceivedInspectionOrder(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addInspectionOrder(EamInspectionOrderRequest eamInspectionOrderRequest) { |
| | | EamInspectionOrder eamInspectionOrder = new EamInspectionOrder(); |
| | |
| | | triggerProcess(eamInspectionOrder); |
| | | //更新设备保养状态 |
| | | eamEquipmentExtendService.updateEquipmentInspectionStatus(eamInspectionOrder.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_INSPECTION.name()); |
| | | //推送企业微信消息 |
| | | sendQywxTemplateCardMessage(eamInspectionOrder, null); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private void sendQywxTemplateCardMessage(EamInspectionOrder eamInspectionOrder, EamInspectionOrderRequest request) { |
| | | TemplateCard templateCard = new TemplateCard(); |
| | | String inspectionStatus = eamInspectionOrder.getInspectionStatus(); |
| | | EamEquipment equipment = eamEquipmentService.getById(eamInspectionOrder.getEquipmentId()); |
| | | eamInspectionOrder.setEquipmentCode(equipment.getEquipmentCode()); |
| | | //todo 目前确认,待领取工单不推送 |
| | | //if (InspectionStatus.WAIT_INSPECTION.name().equals(inspectionStatus)) { |
| | | // //工单待领取,推送消息给所有操作工 |
| | | // String orgId = Optional.ofNullable(eamEquipmentService.getById(eamInspectionOrder.getEquipmentId())) |
| | | // .map(EamEquipment::getOrgId) |
| | | // .orElse(null); |
| | | // if (orgId == null) { |
| | | // throw new IllegalArgumentException("未找到设备的组织 ID"); |
| | | // } |
| | | // //查询该设备所属产线的所有操作工 |
| | | // List<SysUser> sysUserList = mdcUserProductionService.queryByPostAndProId("PCR0001", orgId); |
| | | // List<String> usernameList = sysUserList.stream().map(SysUser::getUsername).collect(Collectors.toList()); |
| | | // if (usernameList.isEmpty()) { |
| | | // throw new IllegalArgumentException("未找到该设备所属产线的操作工,请联系管理员处理"); |
| | | // } |
| | | // String nextAssigneeStr = usernameList.stream() |
| | | // .filter(Objects::nonNull) // 可选:过滤 null 值 |
| | | // .collect(Collectors.joining(",")); |
| | | // String touser = wechatEnterpriseService.getTouser(nextAssigneeStr, false); |
| | | // templateCard.setTouser(touser); |
| | | //} |
| | | if (InspectionStatus.UNDER_INSPECTION.name().equals(inspectionStatus)) { |
| | | //工单已开始点检,推送消息给具体操作工(新增工单时指定、领取工单的操作工) |
| | | String operator = eamInspectionOrder.getOperator(); |
| | | if (StrUtil.isNotBlank(operator)) { |
| | | //新增工单时、工单领取时已指定点检人 |
| | | String touser = wechatEnterpriseService.getTouser(operator, false); |
| | | templateCard.setTouser(touser); |
| | | } |
| | | } |
| | | if (InspectionStatus.WAIT_CONFIRM.name().equals(inspectionStatus)) { |
| | | //工单已点检完成,推送消息给班组长确认 |
| | | List<String> nextAssignee = (List<String>) request.getValues().get("NextAssignee"); |
| | | String nextAssigneeStr = nextAssignee.stream() |
| | | .filter(Objects::nonNull) // 可选:过滤 null 值 |
| | | .collect(Collectors.joining(",")); |
| | | String touser = wechatEnterpriseService.getTouser(nextAssigneeStr, false); |
| | | templateCard.setTouser(touser); |
| | | } |
| | | //todo 工单完成,不推送消息 |
| | | //if (InspectionStatus.COMPLETE.name().equals(inspectionStatus)) { |
| | | // //工单已确认完成,推送消息给点检人 |
| | | // String touser = wechatEnterpriseService.getTouser(eamInspectionOrder.getOperator(), false); |
| | | // templateCard.setTouser(touser); |
| | | //} |
| | | |
| | | TemplateCardEntity templateCardEntity = new TemplateCardEntity(); |
| | | templateCard.setTemplate_card(templateCardEntity); |
| | | templateCardEntity.setTask_id(eamInspectionOrder.getId()); |
| | | TemplateCardEntity.MainTitle mainTitle = new TemplateCardEntity.MainTitle(); |
| | | mainTitle.setTitle("设备点检"); |
| | | templateCardEntity.setMain_title(mainTitle); |
| | | |
| | | //if (InspectionStatus.WAIT_INSPECTION.name().equals(inspectionStatus)) { |
| | | // templateCardEntity.setSub_title_text("新增设备点检工单: " + eamInspectionOrder.getOrderNum() + " ,请进入系统领取"); |
| | | //} |
| | | if (InspectionStatus.UNDER_INSPECTION.name().equals(inspectionStatus)) { |
| | | if (Objects.nonNull(request) && StrUtil.isNotBlank(request.getConfirmDealType())) { |
| | | //是驳回的单子 |
| | | templateCardEntity.setSub_title_text("工单: " + eamInspectionOrder.getOrderNum() + " 被驳回,请重新进行设备点检"); |
| | | } else { |
| | | templateCardEntity.setSub_title_text("已领取工单: " + eamInspectionOrder.getOrderNum() + ",开始进行设备点检"); |
| | | } |
| | | } |
| | | if (InspectionStatus.WAIT_CONFIRM.name().equals(inspectionStatus)) { |
| | | templateCardEntity.setSub_title_text("工单: " + eamInspectionOrder.getOrderNum() + " 已完成设备点检,请进入系统确认"); |
| | | } |
| | | //if (InspectionStatus.COMPLETE.name().equals(inspectionStatus)) { |
| | | // templateCardEntity.setSub_title_text("工单: " + eamInspectionOrder.getOrderNum() + " 已完成点检后确认"); |
| | | //} |
| | | |
| | | List<TemplateCardEntity.HorizontalContent> horizontalContentList = CollectionUtil.newArrayList(); |
| | | TemplateCardEntity.HorizontalContent content1 = new TemplateCardEntity.HorizontalContent(); |
| | | content1.setKeyname("工单号"); |
| | | content1.setValue(eamInspectionOrder.getOrderNum()); |
| | | horizontalContentList.add(content1); |
| | | TemplateCardEntity.HorizontalContent content2 = new TemplateCardEntity.HorizontalContent(); |
| | | content2.setKeyname("设备编号"); |
| | | content2.setValue(eamInspectionOrder.getEquipmentCode()); |
| | | horizontalContentList.add(content2); |
| | | |
| | | //如果工单状态为待点检(没指定点检人的未领取状态),流程是没有启动的,无法获取节点信息 |
| | | if (!InspectionStatus.WAIT_INSPECTION.name().equals(inspectionStatus)) { |
| | | WorkTaskDataVo previousFlowInfo = flowTaskService.getPreviousFlowInfo(eamInspectionOrder.getId()); |
| | | TemplateCardEntity.HorizontalContent content3 = new TemplateCardEntity.HorizontalContent(); |
| | | content3.setKeyname("前驱节点"); |
| | | content3.setValue(previousFlowInfo.getPreNode()); |
| | | horizontalContentList.add(content3); |
| | | TemplateCardEntity.HorizontalContent content4 = new TemplateCardEntity.HorizontalContent(); |
| | | content4.setKeyname("当前节点"); |
| | | if (InspectionStatus.COMPLETE.name().equals(inspectionStatus)) { |
| | | content4.setValue("已完成"); |
| | | } else { |
| | | content4.setValue(previousFlowInfo.getName()); |
| | | } |
| | | horizontalContentList.add(content4); |
| | | } |
| | | |
| | | //if (InspectionStatus.WAIT_INSPECTION.name().equals(inspectionStatus)) { |
| | | // TemplateCardEntity.HorizontalContent content3 = new TemplateCardEntity.HorizontalContent(); |
| | | // content3.setKeyname("发起人"); |
| | | // SysUser sysUser = sysUserService.getUserByName(eamInspectionOrder.getCreateBy()); |
| | | // content3.setValue(sysUser.getRealname()); |
| | | // horizontalContentList.add(content3); |
| | | //} |
| | | if (InspectionStatus.UNDER_INSPECTION.name().equals(inspectionStatus)) { |
| | | if (Objects.isNull(request)) { |
| | | TemplateCardEntity.HorizontalContent content = new TemplateCardEntity.HorizontalContent(); |
| | | content.setKeyname("领取人"); |
| | | SysUser sysUser = sysUserService.getUserByName(eamInspectionOrder.getOperator()); |
| | | content.setValue(sysUser.getRealname()); |
| | | horizontalContentList.add(content); |
| | | } else { |
| | | TemplateCardEntity.HorizontalContent content3 = new TemplateCardEntity.HorizontalContent(); |
| | | TemplateCardEntity.HorizontalContent content4 = new TemplateCardEntity.HorizontalContent(); |
| | | content3.setKeyname("确认人"); |
| | | String confirmAssignee = request.getAssignee(); |
| | | SysUser confirmUser = sysUserService.getUserByName(confirmAssignee); |
| | | content3.setValue(confirmUser.getRealname()); |
| | | horizontalContentList.add(content3); |
| | | content4.setKeyname("确认意见"); |
| | | content4.setValue("驳回"); |
| | | horizontalContentList.add(content4); |
| | | } |
| | | } |
| | | if (InspectionStatus.WAIT_CONFIRM.name().equals(inspectionStatus)) { |
| | | TemplateCardEntity.HorizontalContent content3 = new TemplateCardEntity.HorizontalContent(); |
| | | content3.setKeyname("点检人"); |
| | | SysUser sysUser = sysUserService.getUserByName(eamInspectionOrder.getOperator()); |
| | | content3.setValue(sysUser.getRealname()); |
| | | horizontalContentList.add(content3); |
| | | } |
| | | //if ((InspectionStatus.COMPLETE.name().equals(inspectionStatus))) { |
| | | // TemplateCardEntity.HorizontalContent content3 = new TemplateCardEntity.HorizontalContent(); |
| | | // TemplateCardEntity.HorizontalContent content4 = new TemplateCardEntity.HorizontalContent(); |
| | | // content3.setKeyname("确认人"); |
| | | // SysUser sysUser = sysUserService.getUserByName(eamInspectionOrder.getCreateBy()); |
| | | // content3.setValue(sysUser.getRealname()); |
| | | // horizontalContentList.add(content3); |
| | | // content4.setKeyname("确认意见"); |
| | | // content4.setValue("通过"); |
| | | // horizontalContentList.add(content4); |
| | | //} |
| | | |
| | | templateCardEntity.setHorizontal_content_list(horizontalContentList); |
| | | |
| | | TemplateCardEntity.CardAction cardAction = new TemplateCardEntity.CardAction(); |
| | | cardAction.setType(1); |
| | | cardAction.setUrl(cardActionUrl); |
| | | templateCardEntity.setCard_action(cardAction); |
| | | |
| | | wechatEnterpriseService.sendTemplateCardMsg(templateCard, true); |
| | | } |
| | | |
| | | /** |
| | |
| | | eamInspectionOrder.setEquipmentCode(equipment.getEquipmentCode()); |
| | | } |
| | | System.out.println("设备点检:" + eamInspectionOrder.getId()); |
| | | flowCommonService.initActBusiness("工单号:" + eamInspectionOrder.getOrderNum() + "设备编号" + eamInspectionOrder.getEquipmentCode() + "进行设备点检", |
| | | flowCommonService.initActBusiness("工单号: " + eamInspectionOrder.getOrderNum() + ";设备编号: " + eamInspectionOrder.getEquipmentCode() + ";安装位置: " + equipment.getInstallationPosition(), |
| | | eamInspectionOrder.getId(), "IEamInspectionOrderService", "eam_inspection", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", eamInspectionOrder.getId()); |
| | |
| | | this.updateById(eamInspectionOrder); |
| | | //更新设备保养状态 |
| | | eamEquipmentExtendService.updateEquipmentInspectionStatus(eamInspectionOrder.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_INSPECTION.name()); |
| | | //推送企业微信消息 |
| | | sendQywxTemplateCardMessage(eamInspectionOrder, null); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | // 更新工单信息 |
| | | updateEamInspectionOrder(eamInspectionOrder); |
| | | |
| | | //微信消息推送(工单完成不推送) |
| | | if (!InspectionStatus.COMPLETE.name().equals(eamInspectionOrder.getInspectionStatus())) { |
| | | sendQywxTemplateCardMessage(eamInspectionOrder, eamInspectionOrderRequest); |
| | | } |
| | | |
| | | //查询数据,进行设备维修处理 |
| | | if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) { |
| | | updateEamInspectionOrderDetail(eamInspectionOrder); |