| | |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandardDetail; |
| | | import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationStandardMapper; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest; |
| | | import org.jeecg.modules.eam.request.ImportException; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardDetailService; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService; |
| | |
| | | builder.append(paragraph.getText().trim()); |
| | | } |
| | | }); |
| | | if (!checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) { |
| | | if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) { |
| | | return Result.error(fileName + ":此文件不符合安全装置检查模板规范,请检查!"); |
| | | } |
| | | //获取设备信息 |
| | |
| | | //查看是否有此设备启用的规范信息 |
| | | EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); |
| | | if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { |
| | | return Result.error(fileName + ":此设备的安全装置检查项已添加,请进行编辑或升版!"); |
| | | return Result.error(fileName + ":此设备已存在启用的规范,请进行编辑或升版!"); |
| | | } |
| | | //获取检查项信息 |
| | | List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractSafetyEquipmentCheckItems(tables); |
| | |
| | | detailList.forEach(standardDetail -> { |
| | | standardDetail.setStandardId(originalStandard.getId()); |
| | | }); |
| | | //先删除,后添加 |
| | | standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name()); |
| | | //重新添加 |
| | | standardDetailService.saveBatch(detailList); |
| | | }else { |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); |
| | |
| | | request.setTableDetailList(detailList); |
| | | this.addEamTechnicalStatusEvaluationStandard(request); |
| | | } |
| | | } catch (ImportException e) { |
| | | log.error(e.getMessage(), e); |
| | | return Result.error(fileName + ":" + e.getMessage() + "!"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | return Result.error(fileName + ":系统错误-" + e.getMessage() + "!"); |
| | | return Result.error(fileName + ":" + e.getMessage() + "!"); |
| | | } |
| | | } else { |
| | | return Result.error(fileName + ":文件格式错误,无法解析!"); |
| | |
| | | return Result.OK(fileName + ":导入成功!"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> importPrecisionCheck(MultipartFile file) { |
| | | String fileName = file.getOriginalFilename(); |
| | | if (StringUtils.isBlank(fileName)) { |
| | | return Result.error(fileName + ":文件格式错误,无法解析!"); |
| | | } |
| | | String fileSuffix = FileUtil.getFileSuffix(fileName); |
| | | //只支持 .docx 的word文档 |
| | | if ("docx".equals(fileSuffix)) { |
| | | try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { |
| | | List<XWPFParagraph> paragraphs = doc.getParagraphs(); |
| | | List<XWPFTable> tables = doc.getTables(); |
| | | if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) { |
| | | return Result.error(fileName + ":此文件不符合设备精度检查模板规范,请检查!"); |
| | | } |
| | | //获取文件标题 |
| | | StringBuilder builder = new StringBuilder(); |
| | | paragraphs.forEach(paragraph -> { |
| | | if (StringUtils.isNotBlank(paragraph.getText())) { |
| | | builder.append(paragraph.getText().trim()); |
| | | } |
| | | }); |
| | | if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK)) { |
| | | return Result.error(fileName + ":此文件不符合设备精度检查模板规范,请检查!"); |
| | | } |
| | | //获取设备信息 |
| | | EamEquipment equipment = extractEquipmentInfo(tables.get(0)); |
| | | //查看是否有此设备启用的规范信息 |
| | | EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); |
| | | if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { |
| | | return Result.error(fileName + ":此设备已存在启用的规范,请进行编辑或升版!"); |
| | | } |
| | | //获取检查项信息 |
| | | List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractPrecisionCheckItems(tables); |
| | | if(CollectionUtil.isEmpty(detailList)){ |
| | | return Result.error(fileName + ":未解析到检查项内容,请检查!"); |
| | | } |
| | | if(originalStandard != null) { |
| | | //已存在技术状态鉴定规范,且规范状态为已提交 |
| | | originalStandard.setHasPrecisionCheck(CommonConstant.STATUS_1); |
| | | originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name()); |
| | | super.getBaseMapper().updateById(originalStandard); |
| | | detailList.forEach(standardDetail -> { |
| | | standardDetail.setStandardId(originalStandard.getId()); |
| | | }); |
| | | //先删除,后添加 |
| | | standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name()); |
| | | //重新添加 |
| | | standardDetailService.saveBatch(detailList); |
| | | }else { |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); |
| | | //新增技术状态鉴定规范 |
| | | EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest(); |
| | | request.setEquipmentId(equipment.getId()); |
| | | request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0); |
| | | request.setHasOtherCheck(CommonConstant.STATUS_0); |
| | | request.setHasPrecisionCheck(CommonConstant.STATUS_1); |
| | | request.setStandardCode(codeSeq); |
| | | request.setStandardName(equipment.getEquipmentName() + "技术状态鉴定规范"); |
| | | request.setTableDetailList(detailList); |
| | | this.addEamTechnicalStatusEvaluationStandard(request); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | return Result.error(fileName + ":" + e.getMessage() + "!"); |
| | | } |
| | | } else { |
| | | return Result.error(fileName + ":文件格式错误,无法解析!"); |
| | | } |
| | | |
| | | return Result.OK(fileName + ":导入成功!"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> importOtherCheck(MultipartFile file) { |
| | | String fileName = file.getOriginalFilename(); |
| | | if (StringUtils.isBlank(fileName)) { |
| | | return Result.error(fileName + ":文件格式错误,无法解析!"); |
| | | } |
| | | String fileSuffix = FileUtil.getFileSuffix(fileName); |
| | | //只支持 .docx 的word文档 |
| | | if ("docx".equals(fileSuffix)) { |
| | | try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { |
| | | List<XWPFParagraph> paragraphs = doc.getParagraphs(); |
| | | List<XWPFTable> tables = doc.getTables(); |
| | | if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) { |
| | | return Result.error(fileName + ":此文件不符合安全装置检查模板规范,请检查!"); |
| | | } |
| | | //获取文件标题 |
| | | StringBuilder builder = new StringBuilder(); |
| | | paragraphs.forEach(paragraph -> { |
| | | if (StringUtils.isNotBlank(paragraph.getText())) { |
| | | builder.append(paragraph.getText().trim()); |
| | | } |
| | | }); |
| | | if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK)) { |
| | | return Result.error(fileName + ":此文件不符合其他检查模板规范,请检查!"); |
| | | } |
| | | //获取设备信息 |
| | | EamEquipment equipment = extractEquipmentInfo(tables.get(0)); |
| | | //查看是否有此设备启用的规范信息 |
| | | EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); |
| | | if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { |
| | | return Result.error(fileName + ":此设备已存在启用的规范,请进行编辑或升版!"); |
| | | } |
| | | //获取检查项信息 |
| | | List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractOtherCheckItems(tables); |
| | | if(CollectionUtil.isEmpty(detailList)){ |
| | | return Result.error(fileName + ":未解析到检查项内容,请检查!"); |
| | | } |
| | | if(originalStandard != null) { |
| | | //已存在技术状态鉴定规范,且规范状态为已提交 |
| | | originalStandard.setHasOtherCheck(CommonConstant.STATUS_1); |
| | | originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name()); |
| | | super.getBaseMapper().updateById(originalStandard); |
| | | detailList.forEach(standardDetail -> { |
| | | standardDetail.setStandardId(originalStandard.getId()); |
| | | }); |
| | | //先删除,后添加 |
| | | standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name()); |
| | | //重新添加 |
| | | standardDetailService.saveBatch(detailList); |
| | | }else { |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); |
| | | //新增技术状态鉴定规范 |
| | | EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest(); |
| | | request.setEquipmentId(equipment.getId()); |
| | | request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0); |
| | | request.setHasOtherCheck(CommonConstant.STATUS_1); |
| | | request.setHasPrecisionCheck(CommonConstant.STATUS_0); |
| | | request.setStandardCode(codeSeq); |
| | | request.setStandardName(equipment.getEquipmentName() + "技术状态鉴定规范"); |
| | | request.setTableDetailList(detailList); |
| | | this.addEamTechnicalStatusEvaluationStandard(request); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | return Result.error(fileName + ":" + e.getMessage() + "!"); |
| | | } |
| | | } else { |
| | | return Result.error(fileName + ":文件格式错误,无法解析!"); |
| | | } |
| | | |
| | | return Result.OK(fileName + ":导入成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 检查导入文件分类是否匹配 |
| | | * @param title 标题段落字符串 |
| | | * @param category 分类 |
| | | * @return true 不匹配, false 匹配 |
| | | */ |
| | | private boolean checkImportCategory(String title, TechnicalStatusEvaluationCheckCategoryEnum category) { |
| | | switch (category) { |
| | | case SAFETY_EQUIPMENT_CHECK: |
| | | return title.contains("安全装置检查"); |
| | | return !title.contains("安全装置检查"); |
| | | case PRECISION_CHECK: |
| | | return title.contains("精度检查单"); |
| | | return !title.contains("精度检查单"); |
| | | case OTHER_CHECK: |
| | | return title.contains("其他检查"); |
| | | return !title.contains("其他检查"); |
| | | } |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | |
| | | * 提取安全装置检查明细 |
| | | */ |
| | | private List<EamTechnicalStatusEvaluationStandardDetail> extractSafetyEquipmentCheckItems(List<XWPFTable> tableList) { |
| | | |
| | | List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); |
| | | EamTechnicalStatusEvaluationStandardDetail item = null; |
| | | //解析第一个表格,带设备信息 |
| | |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | /** |
| | | * 提取其他检查项明细内容 |
| | | * @param tables |
| | | * @return |
| | | */ |
| | | private List<EamTechnicalStatusEvaluationStandardDetail> extractOtherCheckItems(List<XWPFTable> tables) { |
| | | List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); |
| | | EamTechnicalStatusEvaluationStandardDetail item = null; |
| | | //解析第一个表格,带设备信息 |
| | | XWPFTable table = tables.get(0); |
| | | for (int i = 0; i < table.getNumberOfRows(); i++) { |
| | | XWPFTableRow row = table.getRow(i); |
| | | if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) { |
| | | //读取到空row值 |
| | | continue; |
| | | } |
| | | //检查是否到检查项序号 |
| | | String firstCell = row.getCell(0).getText().trim(); |
| | | Integer itemCode = null; |
| | | try { |
| | | itemCode = Integer.parseInt(firstCell); |
| | | } catch (NumberFormatException e) { |
| | | //不是检查项内容,跳过此行 |
| | | continue; |
| | | } |
| | | //获取第二个单元格 |
| | | String secondCell = row.getCell(1).getText().trim(); |
| | | //如果这一行为序号则解析整行 |
| | | if (StringUtils.isNotBlank(secondCell)) { |
| | | item = new EamTechnicalStatusEvaluationStandardDetail(); |
| | | item.setItemCode(itemCode); |
| | | item.setItemName(secondCell); |
| | | item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name()); |
| | | items.add(item); |
| | | } |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | private List<EamTechnicalStatusEvaluationStandardDetail> extractPrecisionCheckItems(List<XWPFTable> tables) { |
| | | List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); |
| | | EamTechnicalStatusEvaluationStandardDetail item = null; |
| | | //解析第一个表格,带设备信息 |
| | | XWPFTable table = tables.get(0); |
| | | for (int i = 0; i < table.getNumberOfRows(); i++) { |
| | | XWPFTableRow row = table.getRow(i); |
| | | if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) { |
| | | //读取到空row值 |
| | | continue; |
| | | } |
| | | //检查是否到检查项序号 |
| | | String firstCell = row.getCell(0).getText().trim(); |
| | | Integer itemCode = null; |
| | | try { |
| | | itemCode = Integer.parseInt(firstCell); |
| | | } catch (NumberFormatException e) { |
| | | //不是检查项内容,跳过此行 |
| | | if(item == null) { |
| | | continue; |
| | | }else { |
| | | itemCode = item.getItemCode(); |
| | | } |
| | | } |
| | | //获取第二个单元格 |
| | | String itemName = row.getCell(1).getText().trim(); |
| | | if(StringUtils.isBlank(itemName)) { |
| | | if(item != null) { |
| | | itemName = item.getItemName(); |
| | | }else { |
| | | continue; |
| | | } |
| | | } |
| | | String subItemName = null; |
| | | String toleranceValue = null; |
| | | if(row.getTableCells().size() == 4) { |
| | | toleranceValue = row.getCell(2).getText().trim(); |
| | | }else if(row.getTableCells().size() == 5) { |
| | | subItemName = row.getCell(2).getText().trim(); |
| | | toleranceValue = row.getCell(3).getText().trim(); |
| | | }else { |
| | | continue; |
| | | } |
| | | if(StringUtils.isBlank(toleranceValue)) { |
| | | //允差值不存在,跳过 |
| | | if(item != null) { |
| | | toleranceValue = item.getToleranceValue(); |
| | | }else { |
| | | continue; |
| | | } |
| | | } |
| | | //拼装明细数据 |
| | | item = new EamTechnicalStatusEvaluationStandardDetail(); |
| | | item.setItemCode(itemCode); |
| | | item.setItemName(itemName); |
| | | item.setSubItemName(subItemName); |
| | | item.setToleranceValue(toleranceValue); |
| | | item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name()); |
| | | items.add(item); |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | } |