| | |
| | | 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.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | 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.domain.vo.FlowTaskVo; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | |
| | | |
| | | /*流程业务代码--------------------------开始*/ |
| | | |
| | | /** |
| | | * 流程启动,保存对应的数据 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> saveEamMaintenanceStandardProcess(String id) { |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | EamMaintenanceStandard maintenanceStandard = this.getById(id); |
| | | if (maintenanceStandard == null) { |
| | | return Result.error("未找到对应保养标准"); |
| | | // 获取当前登录用户 |
| | | LoginUser currentUser = getCurrentUser(); |
| | | |
| | | // 校验保养标准是否存在 |
| | | EamMaintenanceStandard maintenanceStandard = validateStandardExistence(id); |
| | | |
| | | // 校验关联设备是否存在 |
| | | EamEquipment equipment = validateEquipmentExistence(maintenanceStandard.getEquipmentId()); |
| | | |
| | | // 检查是否是驳回后重新提交的流程 |
| | | FlowMyBusiness flowBusiness = flowMyBusinessService.selectByDataId(maintenanceStandard.getId()); |
| | | |
| | | if (isReSubmitScenario(flowBusiness)) { |
| | | return handleReSubmitScenario(maintenanceStandard, equipment, currentUser, flowBusiness); |
| | | } |
| | | System.out.println("保养规范流程:" + maintenanceStandard.getId()); |
| | | flowCommonService.initActBusiness(maintenanceStandard.getStandardName() + "规范进行流程审核", |
| | | maintenanceStandard.getId(), "IEamMaintenanceStandardService", "eam_maintenance_standard", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", maintenanceStandard.getId()); |
| | | variables.put("organization", "保养规范启动流程"); |
| | | variables.put("comment", "保养规范启动流程"); |
| | | variables.put("proofreading", true); |
| | | EamEquipment eamEquipment = eamEquipmentService.getById(maintenanceStandard.getEquipmentId()); |
| | | List<UserSelector> userSelectorList = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008); |
| | | if (!CollectionUtils.isEmpty(userSelectorList)) { |
| | | List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(usernameList)) { |
| | | variables.put("NextAssignee", usernameList); |
| | | }else { |
| | | throw new JeecgBootException("设备未存在维修室主任,无法进入下级审批!"); |
| | | |
| | | // 处理首次启动流程 |
| | | return handleFirstSubmitScenario(maintenanceStandard, equipment, currentUser); |
| | | } |
| | | |
| | | /** |
| | | * 判断是否是驳回后重新提交的场景 |
| | | */ |
| | | private boolean isReSubmitScenario(FlowMyBusiness flowBusiness) { |
| | | return flowBusiness != null && |
| | | MaintenanceStandardStatusEnum.WAIT_SUBMIT.name().equals(flowBusiness.getTaskNameId()); |
| | | } |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("eam_maintenance_standard", variables); |
| | | if (!result.isSuccess()) { |
| | | super.removeById(maintenanceStandard.getId()); |
| | | } else { |
| | | maintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name()); |
| | | maintenanceStandard.setDesigner(user.getUsername()); |
| | | maintenanceStandard.setDesignTime(new Date()); |
| | | eamMaintenanceStandardMapper.updateById(maintenanceStandard); |
| | | //获取flow的流程实例id,设置下一步的处理人员 |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("data_id", maintenanceStandard.getId()) |
| | | |
| | | /** |
| | | * 处理驳回后重新提交的流程 |
| | | */ |
| | | private Result<?> handleReSubmitScenario(EamMaintenanceStandard maintenanceStandard, |
| | | EamEquipment equipment, |
| | | LoginUser currentUser, |
| | | FlowMyBusiness flowBusiness) { |
| | | // 更新待办维修工 |
| | | updateTodoMaintenanceWorkers(flowBusiness, equipment); |
| | | |
| | | // 认领任务 |
| | | claimTaskOrFail(flowBusiness.getTaskId(), currentUser); |
| | | |
| | | // 构建流程变量 |
| | | Map<String, Object> variables = buildProcessVariables(maintenanceStandard.getId(), "保养规范再次启动流程"); |
| | | |
| | | // 设置下一级审批人(维修室主任) |
| | | setNextApprover(variables, equipment, BusinessCodeConst.PCR0008, "维修室主任"); |
| | | |
| | | // 完成当前任务,推进流程 |
| | | FlowTaskVo taskVo = buildFlowTaskVo(flowBusiness, maintenanceStandard, variables, "保养规范再次启动流程"); |
| | | Result result = flowTaskService.complete(taskVo); |
| | | |
| | | // 更新保养标准状态 |
| | | if (result.isSuccess()) { |
| | | updateMaintenanceStandardStatus(maintenanceStandard, currentUser, MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR); |
| | | return Result.ok("保养规范流程重启成功"); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 处理首次提交的流程 |
| | | */ |
| | | private Result<?> handleFirstSubmitScenario(EamMaintenanceStandard maintenanceStandard, |
| | | EamEquipment equipment, |
| | | LoginUser currentUser) { |
| | | // 初始化流程业务信息 |
| | | flowCommonService.initActBusiness( |
| | | maintenanceStandard.getStandardName() + "规范进行流程审核", |
| | | maintenanceStandard.getId(), |
| | | "IEamMaintenanceStandardService", |
| | | "eam_maintenance_standard", |
| | | null |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return Result.error("流程记录不存在"); |
| | | |
| | | // 构建流程变量 |
| | | Map<String, Object> variables = buildProcessVariables(maintenanceStandard.getId(), "保养规范启动流程"); |
| | | |
| | | // 设置下一级审批人(维修室主任) |
| | | setNextApprover(variables, equipment, BusinessCodeConst.PCR0008, "维修室主任"); |
| | | |
| | | // 启动流程实例 |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("eam_maintenance_standard", variables); |
| | | |
| | | // 处理流程启动结果 |
| | | if (result.isSuccess()) { |
| | | updateMaintenanceStandardStatus(maintenanceStandard, currentUser, MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR); |
| | | validateFlowBusinessRecord(maintenanceStandard.getId()); |
| | | } else { |
| | | this.removeById(maintenanceStandard.getId()); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 审批操作 |
| | | * |
| | | * @param eamMaintenanceStandardVo |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo) { |
| | | EamMaintenanceStandard eamMaintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId()); |
| | | if (eamMaintenanceStandard == null) { |
| | | return Result.error("未找到对应保养标准"); |
| | | } |
| | | // 获取当前登录用户 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("未获取到登录用户,请重新登录后再试!"); |
| | | } |
| | | eamMaintenanceStandardVo.setAssignee(user.getUsername()); |
| | | // 获取流程业务记录 |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(eamMaintenanceStandardVo.getInstanceId(), eamMaintenanceStandardVo.getTaskId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("流程实例不存在,请刷新后重试!"); |
| | | } |
| | | public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo vo) { |
| | | // 基础校验 |
| | | EamMaintenanceStandard standard = validateStandardExistence(vo.getDataId()); |
| | | LoginUser user = getCurrentUser(); |
| | | FlowMyBusiness business = validateFlowBusiness(vo); |
| | | validateUserAuthorization(business, user); |
| | | claimTaskOrFail(business.getTaskId(), user); |
| | | |
| | | boolean userAuthorized = isUserAuthorized(flowMyBusiness, user); |
| | | if (!userAuthorized) { |
| | | throw new JeecgBootException("用户无权操作此任务,请刷新后重试!"); |
| | | } |
| | | // 认领任务 |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("任务不存在、已完成或已被他人认领!"); |
| | | } |
| | | // 准备审批所需数据 |
| | | EamEquipment equipment = validateEquipmentExistence(standard.getEquipmentId()); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | |
| | | EamEquipment eamEquipment = eamEquipmentService.getById(eamMaintenanceStandard.getEquipmentId()); |
| | | if (eamEquipment == null) { |
| | | throw new JeecgBootException("设备不存在,请检查!"); |
| | | } |
| | | |
| | | MaintenanceStandardStatusEnum status = MaintenanceStandardStatusEnum.getInstance(eamMaintenanceStandard.getStandardStatus()); |
| | | // 根据当前状态处理审批 |
| | | MaintenanceStandardStatusEnum status = MaintenanceStandardStatusEnum.getInstance(standard.getStandardStatus()); |
| | | if (status == null) { |
| | | return null; |
| | | throw new JeecgBootException("无效的保养标准状态"); |
| | | } |
| | | //流程变量 |
| | | Map<String, Object> values = new HashMap<>(); |
| | | List<String> userApprovalList; |
| | | List<UserSelector> userSelectors; |
| | | |
| | | switch (status){ |
| | | case WAIT_REPAIR_DIRECTOR: |
| | | //维修主任审核 |
| | | userSelectors = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0009); |
| | | if (CollectionUtils.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未存在生产设备技术主管,无法进入下级审批!"); |
| | | }else { |
| | | userApprovalList= userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("dataId", eamMaintenanceStandard.getId()); |
| | | values.put("repairManagerApproveResult", eamMaintenanceStandardVo.getRepairManagerApproveResult()); |
| | | if (StrUtil.isEmpty(eamMaintenanceStandardVo.getRepairManagerApproveComment())){ |
| | | eamMaintenanceStandardVo.setRepairManagerApproveComment(""); |
| | | } |
| | | values.put("organization", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | eamMaintenanceStandardVo.setComment(eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | if (eamMaintenanceStandardVo.getRepairManagerApproveResult().equals("2")){ |
| | | eamMaintenanceStandard.setStandardStatus(SecondMaintenanceStatusEnum.ABOLISH.name()); |
| | | }else { |
| | | values.put("NextAssignee", userApprovalList); |
| | | eamMaintenanceStandard.setRepairManager(user.getUsername()); |
| | | eamMaintenanceStandard.setRepairManagerApproveResult(eamMaintenanceStandardVo.getRepairManagerApproveResult()); |
| | | eamMaintenanceStandard.setRepairManagerApproveTime(new Date()); |
| | | eamMaintenanceStandard.setRepairManagerApproveComment(eamMaintenanceStandardVo.getComment()); |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name()); |
| | | } |
| | | } |
| | | handleRepairDirectorApproval(vo, standard, equipment, variables); |
| | | break; |
| | | case WAIT_TECHNICAL_DIRECTOR: |
| | | //待技术主管审批 |
| | | if (StrUtil.isEmpty(eamMaintenanceStandardVo.getTechnicalManagerApproveComment())){ |
| | | eamMaintenanceStandardVo.setTechnicalManagerApproveComment(""); |
| | | } |
| | | values.put("dataId", eamMaintenanceStandard.getId()); |
| | | values.put("organization", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | values.put("technicalManagerApproveResult", eamMaintenanceStandardVo.getTechnicalManagerApproveResult()); |
| | | eamMaintenanceStandardVo.setComment(eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("2")){ |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name()); |
| | | userSelectors = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未存在维修室主任,无法进入驳回审批!"); |
| | | }else{ |
| | | userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | } |
| | | }else { |
| | | eamMaintenanceStandard.setTechnicalManager(user.getUsername()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveResult(eamMaintenanceStandardVo.getTechnicalManagerApproveResult()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveTime(new Date()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveComment(eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); |
| | | } |
| | | handleTechnicalDirectorApproval(vo, standard, equipment, variables); |
| | | break; |
| | | default: |
| | | throw new JeecgBootException("审批失败"); |
| | | throw new JeecgBootException("当前状态不支持审批操作"); |
| | | } |
| | | |
| | | } |
| | | eamMaintenanceStandardVo.setValues(values); |
| | | // 完成流程任务 |
| | | Result result = flowTaskService.complete(eamMaintenanceStandardVo); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审批失败,请刷新查看!"); |
| | | } |
| | | this.updateById(eamMaintenanceStandard); |
| | | if (StrUtil.isNotEmpty(eamMaintenanceStandardVo.getTechnicalManagerApproveResult())){ |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")) { |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); |
| | | //判断是否进行升版,通过设备编号、保养分类、状态进行筛选 |
| | | EamMaintenanceStandard maintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId()); |
| | | QueryWrapper<EamMaintenanceStandard> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.ne("id", eamMaintenanceStandardVo.getDataId()); |
| | | queryWrapper.eq("equipment_id", maintenanceStandard.getEquipmentId()); |
| | | queryWrapper.eq("maintenance_category", maintenanceStandard.getMaintenanceCategory()); |
| | | queryWrapper.eq("standard_status", MaintenanceStandardStatusEnum.START.name()); |
| | | List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper); |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | //作废原有 |
| | | for (EamMaintenanceStandard eamMaintenanceStandard1 : list) { |
| | | eamMaintenanceStandard1.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | this.updateById(eamMaintenanceStandard1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 提交审批结果 |
| | | submitApprovalResult(vo, standard, variables); |
| | | return Result.OK("操作成功"); |
| | | } |
| | | |
| | | |
| | | private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | return todoUsers != null && todoUsers.contains(user.getUsername()); |
| | | private LoginUser getCurrentUser() { |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null) { |
| | | throw new JeecgBootException("未获取到登录用户,请重新登录后再试!"); |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | private boolean claimTask(String taskId, LoginUser user) { |
| | | private EamMaintenanceStandard validateStandardExistence(String id) { |
| | | EamMaintenanceStandard standard = this.getById(id); |
| | | if (standard == null) { |
| | | throw new JeecgBootException("未找到对应保养标准"); |
| | | } |
| | | return standard; |
| | | } |
| | | |
| | | private EamEquipment validateEquipmentExistence(String equipmentId) { |
| | | EamEquipment equipment = eamEquipmentService.getById(equipmentId); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("关联设备不存在"); |
| | | } |
| | | return equipment; |
| | | } |
| | | |
| | | private FlowMyBusiness validateFlowBusiness(EamMaintenanceStandardVo vo) { |
| | | FlowMyBusiness business = flowMyBusinessService.getFlowMyBusiness(vo.getInstanceId(), vo.getTaskId()); |
| | | if (business == null) { |
| | | throw new JeecgBootException("流程实例不存在,请刷新重试"); |
| | | } |
| | | return business; |
| | | } |
| | | |
| | | private void validateUserAuthorization(FlowMyBusiness business, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(business.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | throw new JeecgBootException("用户无权操作此任务"); |
| | | } |
| | | } |
| | | |
| | | private void claimTaskOrFail(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return false; |
| | | throw new JeecgBootException("任务不存在或已完成"); |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return false; |
| | | throw new JeecgBootException("任务已被他人认领"); |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | return true; |
| | | } |
| | | |
| | | private Map<String, Object> buildProcessVariables(String dataId, String comment) { |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | vars.put("dataId", dataId); |
| | | vars.put("organization", comment); |
| | | vars.put("comment", comment); |
| | | vars.put("proofreading", true); |
| | | return vars; |
| | | } |
| | | |
| | | private void setNextApprover(Map<String, Object> variables, EamEquipment equipment, |
| | | String businessCode, String roleName) { |
| | | List<UserSelector> approvers = sysUserService.selectOperatorList( |
| | | equipment.getEquipmentCode(), |
| | | equipment.getFactoryOrgCode(), |
| | | businessCode |
| | | ); |
| | | if (CollectionUtils.isEmpty(approvers)) { |
| | | throw new JeecgBootException("设备未配置" + roleName); |
| | | } |
| | | variables.put("NextAssignee", approvers.stream() |
| | | .map(UserSelector::getUsername) |
| | | .collect(Collectors.toList())); |
| | | } |
| | | |
| | | private void updateTodoMaintenanceWorkers(FlowMyBusiness business, EamEquipment equipment) { |
| | | List<UserSelector> maintenanceWorkers = sysUserService.selectOperatorList( |
| | | equipment.getEquipmentCode(), |
| | | equipment.getFactoryOrgCode(), |
| | | BusinessCodeConst.PCR0002 |
| | | ); |
| | | if (CollectionUtils.isEmpty(maintenanceWorkers)) { |
| | | throw new JeecgBootException("设备未配置维修工"); |
| | | } |
| | | business.setTodoUsers(JSON.toJSONString( |
| | | maintenanceWorkers.stream() |
| | | .map(UserSelector::getUsername) |
| | | .collect(Collectors.toList()) |
| | | )); |
| | | flowMyBusinessService.updateById(business); |
| | | } |
| | | |
| | | private FlowTaskVo buildFlowTaskVo(FlowMyBusiness business, EamMaintenanceStandard standard, |
| | | Map<String, Object> variables, String comment) { |
| | | FlowTaskVo taskVo = new FlowTaskVo(); |
| | | taskVo.setTaskId(business.getTaskId()); |
| | | taskVo.setComment(comment); |
| | | taskVo.setInstanceId(business.getProcessInstanceId()); |
| | | taskVo.setDataId(standard.getId()); |
| | | taskVo.setValues(variables); |
| | | return taskVo; |
| | | } |
| | | |
| | | private void updateMaintenanceStandardStatus(EamMaintenanceStandard standard, |
| | | LoginUser user, |
| | | MaintenanceStandardStatusEnum status) { |
| | | standard.setStandardStatus(status.name()); |
| | | if (MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.equals(status)) { |
| | | standard.setDesigner(user.getUsername()); |
| | | standard.setDesignTime(new Date()); |
| | | } |
| | | this.updateById(standard); |
| | | } |
| | | |
| | | private void validateFlowBusinessRecord(String standardId) { |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>().eq("data_id", standardId) |
| | | ); |
| | | if (CollectionUtils.isEmpty(businessList)) { |
| | | throw new JeecgBootException("流程记录不存在"); |
| | | } |
| | | } |
| | | |
| | | private void handleRepairDirectorApproval(EamMaintenanceStandardVo vo, |
| | | EamMaintenanceStandard standard, |
| | | EamEquipment equipment, |
| | | Map<String, Object> variables) { |
| | | // 设置基础流程变量 |
| | | variables.putAll(buildProcessVariables(standard.getId(), |
| | | StrUtil.blankToDefault(vo.getRepairManagerApproveComment(), ""))); |
| | | variables.put("repairManagerApproveResult", vo.getRepairManagerApproveResult()); |
| | | |
| | | LoginUser user = getCurrentUser(); |
| | | vo.setAssignee(user.getUsername()); |
| | | vo.setComment(vo.getRepairManagerApproveComment()); |
| | | if ("2".equals(vo.getRepairManagerApproveResult())) { |
| | | // 驳回 |
| | | UpdateWrapper<EamMaintenanceStandard> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", standard.getId()); |
| | | updateWrapper.set("standard_status", MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | updateWrapper.set("designer", null); |
| | | updateWrapper.set("design_time", null); |
| | | this.update(updateWrapper); |
| | | } else { |
| | | // 通过 |
| | | setNextApprover(variables, equipment, BusinessCodeConst.PCR0009, "生产设备技术主管"); |
| | | standard.setRepairManager(user.getUsername()); |
| | | standard.setRepairManagerApproveResult(vo.getRepairManagerApproveResult()); |
| | | standard.setRepairManagerApproveTime(new Date()); |
| | | standard.setRepairManagerApproveComment(vo.getRepairManagerApproveComment()); |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name()); |
| | | } |
| | | } |
| | | |
| | | private void handleTechnicalDirectorApproval(EamMaintenanceStandardVo vo, |
| | | EamMaintenanceStandard standard, |
| | | EamEquipment equipment, |
| | | Map<String, Object> variables) { |
| | | // 设置基础流程变量 |
| | | variables.putAll(buildProcessVariables(standard.getId(), |
| | | StrUtil.blankToDefault(vo.getTechnicalManagerApproveComment(), ""))); |
| | | variables.put("technicalManagerApproveResult", vo.getTechnicalManagerApproveResult()); |
| | | |
| | | LoginUser user = getCurrentUser(); |
| | | vo.setAssignee(user.getUsername()); |
| | | vo.setComment(vo.getTechnicalManagerApproveComment()); |
| | | if ("2".equals(vo.getTechnicalManagerApproveResult())) { |
| | | // 驳回 |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name()); |
| | | standard.setRepairManager(null); |
| | | standard.setRepairManagerApproveResult(null); |
| | | standard.setRepairManagerApproveTime(null); |
| | | standard.setRepairManagerApproveComment(null); |
| | | setNextApprover(variables, equipment, BusinessCodeConst.PCR0008, "维修室主任"); |
| | | } else { |
| | | // 通过 |
| | | standard.setTechnicalManager(user.getUsername()); |
| | | standard.setTechnicalManagerApproveResult(vo.getTechnicalManagerApproveResult()); |
| | | standard.setTechnicalManagerApproveTime(new Date()); |
| | | standard.setTechnicalManagerApproveComment(vo.getTechnicalManagerApproveComment()); |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); |
| | | } |
| | | } |
| | | |
| | | private void submitApprovalResult(EamMaintenanceStandardVo vo, |
| | | EamMaintenanceStandard standard, |
| | | Map<String, Object> variables) { |
| | | vo.setValues(variables); |
| | | Result result = flowTaskService.complete(vo); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审批流程提交失败: " + result.getMessage()); |
| | | } |
| | | |
| | | // 更新保养标准 |
| | | this.updateById(standard); |
| | | |
| | | // 技术主管审批通过后,作废旧版本 |
| | | if (MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name().equals(standard.getStandardStatus()) |
| | | && "1".equals(vo.getTechnicalManagerApproveResult())) { |
| | | abolishPreviousStandards(standard); |
| | | } |
| | | } |
| | | |
| | | private void abolishPreviousStandards(EamMaintenanceStandard current) { |
| | | List<EamMaintenanceStandard> previous = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .ne("id", current.getId()) |
| | | .eq("equipment_id", current.getEquipmentId()) |
| | | .eq("maintenance_category", current.getMaintenanceCategory()) |
| | | .eq("standard_status", MaintenanceStandardStatusEnum.START.name()) |
| | | ); |
| | | |
| | | if (!CollectionUtils.isEmpty(previous)) { |
| | | previous.forEach(standard -> { |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | }); |
| | | this.updateBatchById(previous); |
| | | } |
| | | } |
| | | |
| | | |