| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | .or() |
| | | .like("e.equipment_code", eamMaintenanceStandard.getKeyword())); |
| | | } |
| | | //id |
| | | if(StringUtils.isNotBlank(eamMaintenanceStandard.getId())) { |
| | | queryWrapper.eq("ems.id", eamMaintenanceStandard.getId()); |
| | | } |
| | | } |
| | | queryWrapper.orderByDesc("ems.create_time"); |
| | | return eamMaintenanceStandardMapper.queryPageList(page, queryWrapper); |
| | |
| | | BeanUtils.copyProperties(standardRequest, entity); |
| | | entity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | //版本递增 |
| | | entity.setStandardVersion(CommonConstant.OPERATE_TYPE_1); |
| | | entity.setStandardVersion("v"+CommonConstant.OPERATE_TYPE_1); |
| | | //设备处理 |
| | | entity.setEquipmentId(standardRequest.getEquipmentId()); |
| | | //删除标记 |
| | |
| | | if(entity == null){ |
| | | throw new JeecgBootException("编辑的数据已删除,请刷新重试!"); |
| | | } |
| | | entity.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | //原来的作废 |
| | | eamMaintenanceStandardMapper.updateById(entity); |
| | | |
| | | //新增一个版本 |
| | | EamMaintenanceStandard newEntity = new EamMaintenanceStandard(); |
| | |
| | | newEntity.setInitialDate(standardRequest.getInitialDate()); |
| | | newEntity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | //版本递增 |
| | | newEntity.setStandardVersion(entity.getStandardVersion() + 1); |
| | | //获取数字 |
| | | Pattern pattern = Pattern.compile("(\\d+)(?:\\.\\d+)*$"); |
| | | Matcher matcher = pattern.matcher(entity.getStandardVersion()); |
| | | if (matcher.find()) { |
| | | try { |
| | | int mainVersion = Integer.parseInt(matcher.group(1)); |
| | | newEntity.setStandardVersion("v"+(mainVersion+1)); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | //设备处理 |
| | | newEntity.setEquipmentId(standardRequest.getEquipmentId()); |
| | | //删除标记 |
| | |
| | | // 设置流程变量 |
| | | Map<String, Object> values = setProcessVariables(eamMaintenanceStandard, userId, eamMaintenanceStandardVo); |
| | | eamMaintenanceStandardVo.setValues(values); |
| | | |
| | | eamMaintenanceStandardVo.setComment(values.get("comment").toString()); |
| | | // 完成流程任务 |
| | | Result result = flowTaskService.complete(eamMaintenanceStandardVo); |
| | | if (result.isSuccess()) { |
| | | if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) { |
| | | if (eamMaintenanceStandardVo.getRepairManagerApproveResult().equals("1")){ |
| | | List<FlowMyBusiness> newbusinessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("process_instance_id", eamMaintenanceStandardVo.getInstanceId())); |
| | | FlowMyBusiness newflowMyBusiness = newbusinessList.get(0); |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name()); |
| | | //获取flow的流程实例id,设置下一步的处理人员 |
| | | EamMaintenanceStandard maintenanceStandard=this.getById(eamMaintenanceStandardVo.getDataId()); |
| | | EamEquipment eamEquipment=eamEquipmentService.getById(maintenanceStandard.getEquipmentId()); |
| | | BaseFactory baseFactory=baseFactoryService.getOne(new QueryWrapper<BaseFactory>().eq("org_code", eamEquipment.getFactoryOrgCode())); |
| | | List<UserSelector> userSelectorList=sysUserService.selectOperatorFactoryList(eamEquipment.getEquipmentCode(),baseFactory.getId(), BusinessCodeConst.PCR0008); |
| | | if (!CollectionUtils.isEmpty(userSelectorList)) { |
| | | List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | newflowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); |
| | | flowMyBusinessService.updateById(newflowMyBusiness); |
| | | } |
| | | }else { |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | } |
| | |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) { |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")){ |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); |
| | | //判断是否进行升版,通过设备编号、保养分类、状态进行筛选 |
| | | EamMaintenanceStandard maintenanceStandard=this.getById(eamMaintenanceStandardVo.getDataId()); |
| | | QueryWrapper<EamMaintenanceStandard> queryWrapper=new QueryWrapper<>(); |
| | | 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); |
| | | } |
| | | } |
| | | }else { |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | } |
| | |
| | | } else { |
| | | return result; |
| | | } |
| | | |
| | | return Result.OK("操作成功"); |
| | | } catch (Exception e) { |
| | | return Result.error("操作失败:" + e.getMessage()); |
| | |
| | | Map<String, Object> values = new HashMap<>(); |
| | | values.put("dataId", eamMaintenanceStandard.getId()); |
| | | values.put("assignee", userId); |
| | | values.put("organization", eamMaintenanceStandardVo.getComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getComment()); |
| | | if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) { |
| | | values.put("repairManagerApproveResult", eamMaintenanceStandardVo.getRepairManagerApproveResult()); |
| | | values.put("organization", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | } |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) { |
| | | values.put("technicalManagerApproveResult", eamMaintenanceStandardVo.getTechnicalManagerApproveResult()); |
| | | values.put("organization", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | } |
| | | return values; |
| | | } |
| | |
| | | } |
| | | |
| | | /*流程业务代码--------------------------结束*/ |
| | | |
| | | |
| | | /*导入文件--------------------------开始*/ |
| | | /** |
| | | * 导入点检表数据 |
| | | * @param file Excel文件 |
| | | * @return 导入结果 |
| | | */ |
| | | // public Result<?> importInspectionData(MultipartFile file) { |
| | | // int successCount = 0; |
| | | // |
| | | // try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { |
| | | // Sheet sheet = workbook.getSheetAt(0); |
| | | // // 1. 解析表头信息 |
| | | // Map<String, String> header = parseHeader(sheet, errors); |
| | | // |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // |
| | | // return new ImportResult(successCount, errors); |
| | | // } |
| | | |
| | | /** |
| | | * 解析表头信息 |
| | | */ |
| | | // private Map<String, String> parseHeader(Sheet sheet, List<ImportError> errors) { |
| | | // Map<String, String> header = new HashMap<>(); |
| | | // try { |
| | | // Row headerRow = sheet.getRow(0); |
| | | // // 示例:第一行:设备名称:割炬 型号:gta001 统一编号:xc001 |
| | | // String cellValue = getCellStringValue(headerRow.getCell(0)); |
| | | // |
| | | // // 使用正则表达式解析关键信息 |
| | | // Pattern pattern = Pattern.compile("设备名称[::](\\S+)\\s+型号[::](\\S+)\\s+统一编号[::](\\S+)\\s+日期[::](\\S+)\\s+单位[::](\\S+)"); |
| | | // Matcher matcher = pattern.matcher(cellValue); |
| | | // |
| | | // if (matcher.find()) { |
| | | // header.put("deviceName", matcher.group(1)); |
| | | // header.put("deviceModel", matcher.group(2)); |
| | | // header.put("deviceCode", matcher.group(3)); |
| | | // header.put("inspectionMonth", matcher.group(4)); |
| | | // header.put("unit", matcher.group(5)); |
| | | // } else { |
| | | // errors.add(new ImportError("表头格式错误", cellValue, 1)); |
| | | // } |
| | | // } catch (Exception e) { |
| | | // errors.add(new ImportError("解析表头异常", e.getMessage(), 1)); |
| | | // } |
| | | // return header; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 解析每日点检项目 |
| | | // */ |
| | | // private List<InspectionItem> parseDailyItems(Sheet sheet, List<ImportError> errors) { |
| | | // List<InspectionItem> items = new ArrayList<>(); |
| | | // |
| | | // // 点检项目从第3行开始(序号从1开始) |
| | | // int startRow = 2; |
| | | // int rowNum = startRow; |
| | | // |
| | | // try { |
| | | // // 找到每日点检表的结束位置(维护责任人签字) |
| | | // while (rowNum <= sheet.getLastRowNum()) { |
| | | // Row row = sheet.getRow(rowNum); |
| | | // if (row == null) { |
| | | // rowNum++; |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 判断是否到达结束位置 |
| | | // String sequenceValue = getCellStringValue(row.getCell(0)); |
| | | // if ("9".equals(sequenceValue) || "维护责任人签字".contains(sequenceValue)) { |
| | | // break; |
| | | // } |
| | | // |
| | | // // 解析项目行 |
| | | // InspectionItem item = new InspectionItem(); |
| | | // item.setSequence(Integer.parseInt(sequenceValue)); |
| | | // item.setProjectName(getCellStringValue(row.getCell(1))); |
| | | // item.setRequirement(getCellStringValue(row.getCell(2))); |
| | | // |
| | | // items.add(item); |
| | | // rowNum++; |
| | | // } |
| | | // } catch (Exception e) { |
| | | // errors.add(new ImportError("解析每日项目异常", e.getMessage(), rowNum + 1)); |
| | | // } |
| | | // |
| | | // return items; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 解析周保养项目 |
| | | // */ |
| | | // private List<InspectionItem> parseWeeklyItems(Sheet sheet, List<ImportError> errors) { |
| | | // List<InspectionItem> items = new ArrayList<>(); |
| | | // |
| | | // try { |
| | | // // 定位周保养标题行(行号11) |
| | | // int startRow = 10; |
| | | // |
| | | // // 从第12行开始是周保养项目 |
| | | // for (int rowNum = startRow + 1; rowNum <= sheet.getLastRowNum(); rowNum++) { |
| | | // Row row = sheet.getRow(rowNum); |
| | | // if (row == null) continue; |
| | | // |
| | | // String sequenceValue = getCellStringValue(row.getCell(0)); |
| | | // |
| | | // // 遇到结束标志则停止解析 |
| | | // if ("周保养操作者执行".contains(sequenceValue)) break; |
| | | // |
| | | // try { |
| | | // InspectionItem item = new InspectionItem(); |
| | | // item.setSequence(Integer.parseInt(sequenceValue)); |
| | | // item.setProjectName(getCellStringValue(row.getCell(1))); |
| | | // item.setStandard(getCellStringValue(row.getCell(2))); |
| | | // item.setRequirement(getCellStringValue(row.getCell(3))); // 执行记录 |
| | | // |
| | | // items.add(item); |
| | | // } catch (Exception e) { |
| | | // errors.add(new ImportError("解析周保养项目异常", e.getMessage(), rowNum + 1)); |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // errors.add(new ImportError("定位周保养项目异常", e.getMessage(), 0)); |
| | | // } |
| | | // |
| | | // return items; |
| | | // } |
| | | /*导入文件--------------------------结束*/ |
| | | } |