| | |
| | | import com.jeecg.weibo.exception.BusinessException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactory; |
| | | import org.jeecg.modules.eam.base.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryService; |
| | | import org.jeecg.modules.eam.base.service.IBaseFactoryUserService; |
| | | 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.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.EamMaintenanceStandardDetailCategory; |
| | | import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.entity.EamMaintenanceStandard; |
| | | import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail; |
| | | import org.jeecg.modules.eam.mapper.EamMaintenanceStandardMapper; |
| | | import org.jeecg.modules.eam.request.EamMaintenanceStandardRequest; |
| | | import org.jeecg.modules.eam.request.ImportException; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardDetailService; |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardService; |
| | |
| | | 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.service.ISysBusinessCodeRuleService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService eamEquipmentExtendService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | |
| | | // 常量定义 |
| | | private static final String REPAIR_TITLE = "维修人员保养内容"; |
| | | private static final String OPERATOR_TITLE = "操作人员保养内容"; |
| | | private static final Map<String, EamMaintenanceStandardDetailCategory> SECOND_CATEGORY_MAPPING = new HashMap<>(); |
| | | |
| | | // 枚举映射初始化 |
| | | static { |
| | | SECOND_CATEGORY_MAPPING.put(REPAIR_TITLE, EamMaintenanceStandardDetailCategory.REPAIRER_MAINTENANCE); |
| | | SECOND_CATEGORY_MAPPING.put(OPERATOR_TITLE, EamMaintenanceStandardDetailCategory.OPERATOR_MAINTENANCE); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<EamMaintenanceStandard> queryPageList(Page<EamMaintenanceStandard> page, EamMaintenanceStandard eamMaintenanceStandard) { |
| | | QueryWrapper<EamMaintenanceStandard> queryWrapper = new QueryWrapper<>(); |
| | |
| | | newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory()); |
| | | newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod()); |
| | | newEntity.setInitialDate(standardRequest.getInitialDate()); |
| | | newEntity.setPeriodUnit(standardRequest.getPeriodUnit()); |
| | | newEntity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | //版本递增 |
| | | //获取数字 |
| | |
| | | LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory); |
| | | queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.START.name()); |
| | | return eamMaintenanceStandardMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | 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.PCR0007); |
| | | 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()); |
| | | flowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); |
| | |
| | | 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); |
| | | List<UserSelector> userSelectorList=sysUserService.selectOperatorFactoryList(eamEquipment.getEquipmentCode(),baseFactory.getId(), BusinessCodeConst.PCR0009); |
| | | if (!CollectionUtils.isEmpty(userSelectorList)) { |
| | | List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | newflowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); |
| | |
| | | /*流程业务代码--------------------------结束*/ |
| | | |
| | | |
| | | /*导入文件--------------------------开始*/ |
| | | /*导入点检文件Excel--------------------------开始*/ |
| | | /** |
| | | * 点检表导入入口 |
| | | */ |
| | |
| | | // 1. 提取设备信息 |
| | | EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet); |
| | | if (eamMaintenanceStandard == null) { |
| | | throw new BusinessException("设备信息提取失败"); |
| | | return Result.error("设备信息提取失败"); |
| | | }else { |
| | | if (eamMaintenanceStandard.getEquipmentId() == null) { |
| | | return Result.error("设备信息提取失败"); |
| | | } |
| | | } |
| | | |
| | | eamMaintenanceStandard.setStandardName(name); |
| | |
| | | |
| | | // 2. 提取每日点检项目 |
| | | List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard); |
| | | if(dailyDetails.isEmpty()){ |
| | | return Result.error("未找到每日点检项目"); |
| | | } |
| | | |
| | | // 3. 提取周保养项目 |
| | | List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard); |
| | | if(weeklyDetails.isEmpty()){ |
| | | return Result.error("未找到周保养项目"); |
| | | } |
| | | |
| | | // 合并并保存所有项目 |
| | | List<EamMaintenanceStandardDetail> allDetails = new ArrayList<>(); |
| | |
| | | |
| | | EamMaintenanceStandard standard = new EamMaintenanceStandard(); |
| | | standard.setEquipmentName(extractField(headerText, "设备名称[::]\\s*(\\S+)")); |
| | | standard.setEquipmentId(extractField(headerText, "设备型号[::]\\s*(\\S+)")); |
| | | standard.setStandardCode(extractField(headerText, "统一编号[::]\\s*(\\S+)")); |
| | | standard.setEquipmentCode(extractField(headerText, "统一编号[::]\\s*(\\S+)")); |
| | | |
| | | |
| | | // 日期处理 |
| | | String dateStr = extractField(headerText, "日期[::]\\s*(\\S+)"); |
| | |
| | | } |
| | | } |
| | | |
| | | // 关联设备ID |
| | | if (isNotBlank(standard.getEquipmentCode()) && |
| | | isNotBlank(standard.getEquipmentName())) { |
| | | |
| | | List<EamEquipment> equipments = eamEquipmentService.list( |
| | | new QueryWrapper<EamEquipment>() |
| | | .eq("equipment_code", standard.getEquipmentCode()) |
| | | .eq("equipment_name", standard.getEquipmentName()) |
| | | ); |
| | | |
| | | if (!equipments.isEmpty()) { |
| | | standard.setEquipmentId(equipments.get(0).getId()); |
| | | }else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); |
| | | standard.setStandardCode(codeSeq); |
| | | standard.setMaintenanceCategory("POINT_INSPECTION"); |
| | | standard.setPeriodUnit("天"); |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); |
| | | standard.setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1); |
| | | standard.setDelFlag(0); |
| | | standard.setMaintenancePeriod(1); |
| | | |
| | | return standard; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 识别新表头开始 |
| | | * 识别新表头开始 |
| | | */ |
| | | private boolean isNewHeaderStart(Row row) { |
| | | for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { |
| | |
| | | */ |
| | | private String extractField(String text, String regex) { |
| | | if (StringUtils.isBlank(text)) return ""; |
| | | |
| | | Pattern pattern = Pattern.compile(regex); |
| | | Matcher matcher = pattern.matcher(text); |
| | | return matcher.find() ? matcher.group(1) : ""; |
| | |
| | | */ |
| | | private String getCellStringValue(Cell cell) { |
| | | if (cell == null) return ""; |
| | | |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | return cell.getStringCellValue().trim(); |
| | |
| | | return ""; |
| | | } |
| | | } |
| | | /*导入文件--------------------------结束*/ |
| | | /*导入点检文件Excel--------------------------结束*/ |
| | | |
| | | /*导入二保三保文件Excel--------------------------开始*/ |
| | | /** |
| | | * 统一保养规范导入入口 |
| | | * @param file 上传文件 |
| | | * @param type 保养类型 (SECOND/THIRD) |
| | | * @return 导入结果(包含成功/失败信息) |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result<?> importMaintenanceStandard(MultipartFile file, String type) { |
| | | String fileName = file.getOriginalFilename(); |
| | | |
| | | try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { |
| | | // 基础验证 |
| | | if (doc.getTables().isEmpty()) { |
| | | return Result.error(fileName + ": 文档中未找到表格"); |
| | | } |
| | | |
| | | XWPFTable table = doc.getTables().get(0); |
| | | |
| | | // 文档类型校验 - 防止二保传入三保或反之 |
| | | if (isWrongDocumentType(table, type)) { |
| | | return Result.error(fileName + ": 文档类型不匹配 - " + |
| | | ("SECOND".equals(type) ? "请导入二级保养文档" : "请导入三级保养文档")); |
| | | } |
| | | |
| | | EamMaintenanceStandard standard = extractDeviceInfo(table); |
| | | if (standard == null) { |
| | | return Result.error(fileName + ": 设备信息提取失败"); |
| | | } |
| | | |
| | | // 配置类型相关参数 |
| | | configureStandard(standard, type, file); |
| | | eamMaintenanceStandardMapper.insert(standard); |
| | | String standardId = standard.getId(); |
| | | |
| | | // 提取保养项目 |
| | | List<EamMaintenanceStandardDetail> items; |
| | | if ("SECOND".equals(type)) { |
| | | items = extractSecondMaintenanceItems(table, standardId); |
| | | } else if ("THIRD".equals(type)) { |
| | | items = extractThirdMaintenanceItems(table, standardId); |
| | | } else { |
| | | return Result.error(fileName + ": 不支持的保养类型: " + type); |
| | | } |
| | | |
| | | // 项目验证 |
| | | if (items.isEmpty()) { |
| | | return Result.error(fileName + ": 未提取到任何保养项目"); |
| | | } |
| | | |
| | | // 保存项目 |
| | | eamMaintenanceStandardDetailService.saveBatch(items); |
| | | |
| | | return Result.ok(fileName + ": 导入成功, 项目数: " + items.size()); |
| | | |
| | | } catch (ImportException e) { |
| | | return Result.error(e.getMessage()); |
| | | } catch (Exception e) { |
| | | return Result.error(fileName + ": 系统错误 - " + e.getClass().getSimpleName()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文档类型校验 - 防止二保传入三保或反之 |
| | | */ |
| | | private boolean isWrongDocumentType(XWPFTable table, String requestedType) { |
| | | boolean hasRepairTitle = false; |
| | | boolean hasOperatorTitle = false; |
| | | boolean hasMaintenancePart = false; |
| | | |
| | | // 只检查前10行(通常标题在前几行) |
| | | int maxRows = Math.min(table.getNumberOfRows(), 10); |
| | | |
| | | for (int i = 0; i < maxRows; i++) { |
| | | XWPFTableRow row = table.getRow(i); |
| | | if (row == null) continue; |
| | | |
| | | // 检查所有单元格内容 |
| | | for (int j = 0; j < row.getTableCells().size(); j++) { |
| | | String cellText = getCellText(row.getCell(j)); |
| | | |
| | | // 检查二级保养特征 |
| | | if (cellText.contains(REPAIR_TITLE)) { |
| | | hasRepairTitle = true; |
| | | } |
| | | if (cellText.contains(OPERATOR_TITLE)) { |
| | | hasOperatorTitle = true; |
| | | } |
| | | |
| | | // 检查三级保养特征 |
| | | if (cellText.contains("保养部位")) { |
| | | hasMaintenancePart = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 逻辑判断 |
| | | if ("SECOND".equals(requestedType)) { |
| | | // 如果请求导入二级保养,但文档中有三级保养特征 |
| | | return !(hasRepairTitle || hasOperatorTitle) || hasMaintenancePart; |
| | | } else if ("THIRD".equals(requestedType)) { |
| | | // 如果请求导入三级保养,但文档中有二级保养特征 |
| | | return !hasMaintenancePart || (hasRepairTitle || hasOperatorTitle); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 提取设备基本信息 |
| | | */ |
| | | private EamMaintenanceStandard extractDeviceInfo(XWPFTable table) { |
| | | if (table.getNumberOfRows() < 2) return null; |
| | | |
| | | // 提取前两行数据 |
| | | Map<String, String> row1Data = extractRowData(table.getRow(0)); |
| | | Map<String, String> row2Data = extractRowData(table.getRow(1)); |
| | | |
| | | // 创建设备标准对象 |
| | | EamMaintenanceStandard standard = new EamMaintenanceStandard(); |
| | | standard.setEquipmentText(row1Data.get("设备类别")); |
| | | standard.setEquipmentCode(row1Data.get("设备编号")); |
| | | standard.setEquipmentName(row2Data.get("设备名称")); |
| | | standard.setEquipmentModel(row2Data.get("设备型号")); |
| | | |
| | | // 关联设备ID |
| | | if (isNotBlank(standard.getEquipmentCode()) && |
| | | isNotBlank(standard.getEquipmentName())) { |
| | | |
| | | List<EamEquipment> equipments = eamEquipmentService.list( |
| | | new QueryWrapper<EamEquipment>() |
| | | .eq("equipment_code", standard.getEquipmentCode()) |
| | | .eq("equipment_name", standard.getEquipmentName()) |
| | | ); |
| | | |
| | | if (!equipments.isEmpty()) { |
| | | standard.setEquipmentId(equipments.get(0).getId()); |
| | | }else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | return standard; |
| | | } |
| | | |
| | | // 简易版字符串非空判断 |
| | | private boolean isNotBlank(String str) { |
| | | return str != null && !str.trim().isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * 表格行数据解析 |
| | | */ |
| | | private Map<String, String> extractRowData(XWPFTableRow row) { |
| | | Map<String, String> data = new HashMap<>(); |
| | | int cellCount = row.getTableCells().size(); |
| | | |
| | | try { |
| | | // 键值对模式 (标签|值|标签|值) |
| | | if (cellCount >= 4 && cellCount % 2 == 0) { |
| | | for (int i = 0; i < cellCount; i += 2) { |
| | | String key = cleanKey(getCellText(row.getCell(i))); |
| | | String value = getCellText(row.getCell(i + 1)); |
| | | if (!key.isEmpty()) data.put(key, value); |
| | | } |
| | | } |
| | | // 连续单元格模式 |
| | | else { |
| | | for (int i = 0; i < cellCount; i++) { |
| | | String text = getCellText(row.getCell(i)); |
| | | int colonIndex = text.indexOf(':'); |
| | | if (colonIndex > 0) { |
| | | String key = cleanKey(text.substring(0, colonIndex)); |
| | | String value = text.substring(colonIndex + 1); |
| | | data.put(key, value); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("行数据解析异常", e); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * 键名标准化处理 |
| | | */ |
| | | private String cleanKey(String key) { |
| | | if (key == null) return ""; |
| | | // 移除空格和中文冒号 |
| | | return key.replaceAll("\\s", "").replace(":", ""); |
| | | } |
| | | |
| | | /** |
| | | * 配置保养标准参数 |
| | | */ |
| | | private void configureStandard(EamMaintenanceStandard standard, String type, MultipartFile file) { |
| | | // 基础参数 |
| | | String filename = file.getOriginalFilename(); |
| | | if (filename != null && filename.contains(".")) { |
| | | filename = filename.substring(0, filename.lastIndexOf('.')); |
| | | } |
| | | |
| | | standard.setStandardName(filename) |
| | | .setInitialDate(new Date()) |
| | | .setStandardStatus(MaintenanceStandardStatusEnum.START.name()) |
| | | .setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1) |
| | | .setDelFlag(0) |
| | | .setStandardCode(businessCodeRuleService.generateBusinessCodeSeq( |
| | | BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE |
| | | )); |
| | | |
| | | // 类型特定参数 |
| | | if ("SECOND".equals(type)) { |
| | | standard.setMaintenanceCategory("SECOND_MAINTENANCE") |
| | | .setMaintenancePeriod(6) |
| | | .setPeriodUnit("月"); |
| | | } else { |
| | | standard.setMaintenanceCategory("THIRD_MAINTENANCE") |
| | | .setPeriodUnit("年"); |
| | | |
| | | // 获取三级保养周期 |
| | | if (standard.getEquipmentId() != null) { |
| | | EamEquipmentExtend extend = eamEquipmentExtendService.getById(standard.getEquipmentId()); |
| | | if (extend != null) { |
| | | standard.setMaintenancePeriod(extend.getThirdMaintenancePeriod()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 提取二级保养项目 |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractSecondMaintenanceItems( |
| | | XWPFTable table, String standardId) { |
| | | |
| | | List<EamMaintenanceStandardDetail> items = new ArrayList<>(); |
| | | EamMaintenanceStandardDetailCategory currentCategory = null; |
| | | |
| | | for (int i = 0; i < table.getNumberOfRows(); i++) { |
| | | XWPFTableRow row = table.getRow(i); |
| | | if (row == null) continue; |
| | | |
| | | // 检查是否是标题行(维修人员保养内容或操作人员保养内容) |
| | | String firstCell = getCellText(row.getCell(0)); |
| | | if (firstCell != null) { |
| | | for (String title : SECOND_CATEGORY_MAPPING.keySet()) { |
| | | if (firstCell.contains(title)) { |
| | | currentCategory = SECOND_CATEGORY_MAPPING.get(title); |
| | | |
| | | // 检查第二列和第三列是否是"序号"和"保养内容" |
| | | if (row.getTableCells().size() > 2) { |
| | | String secondCell = getCellText(row.getCell(1)); |
| | | String thirdCell = getCellText(row.getCell(2)); |
| | | |
| | | // 明确跳过标题行 |
| | | if ("序号".equals(secondCell) && "保养内容".equals(thirdCell)) { |
| | | continue; // 跳过这一行 |
| | | } |
| | | } |
| | | |
| | | // 尝试提取标题行中的项目(如果存在) |
| | | if (row.getTableCells().size() > 2) { |
| | | String content = getCellText(row.getCell(2)); |
| | | if (content != null && !content.trim().isEmpty() && |
| | | !"保养内容".equals(content.trim())) { // 过滤无效内容 |
| | | items.add(createItem(currentCategory, content.trim(), standardId)); |
| | | } |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理普通项目行 |
| | | if (currentCategory != null && isValidItemRow(row)) { |
| | | // 获取内容 |
| | | String content = row.getTableCells().size() > 2 ? |
| | | getCellText(row.getCell(2)) : ""; |
| | | |
| | | // 排除标题内容 |
| | | if ("保养内容".equals(content) || |
| | | "序号".equals(content) || |
| | | content.contains("维修人员保养内容") || |
| | | content.contains("操作人员保养内容")) { |
| | | continue; |
| | | } |
| | | |
| | | EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail(); |
| | | item.setItemCategory(String.valueOf(currentCategory)); |
| | | item.setStandardId(standardId); |
| | | item.setItemName(cleanContent(content)); |
| | | |
| | | // 处理序号(第二列) |
| | | if (row.getTableCells().size() > 1) { |
| | | String seqText = getCellText(row.getCell(1)); |
| | | try { |
| | | if (seqText != null && !seqText.trim().isEmpty()) { |
| | | item.setItemCode(Integer.parseInt(seqText.trim())); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | // 忽略序号解析错误 |
| | | } |
| | | } |
| | | |
| | | items.add(item); |
| | | } |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | /** |
| | | * 创建保养项目 |
| | | */ |
| | | private EamMaintenanceStandardDetail createItem( |
| | | EamMaintenanceStandardDetailCategory category, |
| | | String content, |
| | | String standardId) { |
| | | |
| | | EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail(); |
| | | item.setItemCategory(category.name()); |
| | | item.setStandardId(standardId); |
| | | item.setItemName(cleanContent(content)); |
| | | return item; |
| | | } |
| | | |
| | | /** |
| | | * 提取三级保养项目(无类型) |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractThirdMaintenanceItems( |
| | | XWPFTable table, String standardId) { |
| | | |
| | | List<EamMaintenanceStandardDetail> items = new ArrayList<>(); |
| | | String currentPart = ""; |
| | | int itemCount = 1; |
| | | |
| | | // 从第三行开始(跳过表头和设备信息) |
| | | for (int i = 2; i < table.getNumberOfRows(); i++) { |
| | | XWPFTableRow row = table.getRow(i); |
| | | if (row == null || isRowEmpty(row)) continue; |
| | | |
| | | // 跳过"保养部位"标题行 |
| | | String firstCell = getCellText(row.getCell(0)); |
| | | if ("保养部位".equals(firstCell)) { |
| | | continue; |
| | | } |
| | | |
| | | EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail(); |
| | | // 三级保养不需要类型,不设置itemCategory |
| | | item.setStandardId(standardId); |
| | | item.setItemCode(itemCount++); |
| | | |
| | | // 处理部位列 |
| | | if (!row.getTableCells().isEmpty()) { |
| | | String partCell = getCellText(row.getCell(0)); |
| | | if (!partCell.trim().isEmpty()) { |
| | | currentPart = partCell.trim(); |
| | | } |
| | | } |
| | | item.setItemPart(currentPart); |
| | | |
| | | // 根据列数确定内容和标准的位置 |
| | | int cellCount = row.getTableCells().size(); |
| | | if (cellCount == 3) { // 部位|内容|标准 |
| | | item.setItemName(getCellText(row.getCell(1))); |
| | | item.setItemDemand(getCellText(row.getCell(2))); |
| | | } |
| | | else if (cellCount == 2) { // 内容|标准 |
| | | item.setItemName(getCellText(row.getCell(0))); |
| | | item.setItemDemand(getCellText(row.getCell(1))); |
| | | } |
| | | else if (cellCount == 1) { // 单列内容 |
| | | item.setItemName(getCellText(row.getCell(0))); |
| | | } |
| | | else if (cellCount > 3) { // 多列处理 |
| | | // 取第2列作为内容,最后一列作为标准 |
| | | item.setItemName(getCellText(row.getCell(1))); |
| | | item.setItemDemand(getCellText(row.getCell(cellCount - 1))); |
| | | } |
| | | |
| | | items.add(item); |
| | | } |
| | | return items; |
| | | } |
| | | |
| | | /** |
| | | * 兼容版单元格文本提取 |
| | | */ |
| | | private String getCellText(XWPFTableCell cell) { |
| | | if (cell == null) return ""; |
| | | |
| | | StringBuilder text = new StringBuilder(); |
| | | for (XWPFParagraph para : cell.getParagraphs()) { |
| | | if (para != null) { |
| | | for (XWPFRun run : para.getRuns()) { |
| | | if (run != null) { |
| | | String runText = run.getText(0); |
| | | if (runText != null) { |
| | | text.append(runText); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return text.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 内容清理 |
| | | */ |
| | | private String cleanContent(String text) { |
| | | if (text == null) return ""; |
| | | |
| | | // 替换特殊空格和合并连续空格 |
| | | text = text.replace('\u00A0', ' ') |
| | | .replace('\u2007', ' ') |
| | | .replace('\u202F', ' ') |
| | | .replaceAll("\\s+", " "); |
| | | |
| | | // 规范标点符号 |
| | | return text.replace(',', '、') |
| | | .replace(',', '、') |
| | | .replace(';', ';') |
| | | .replace(';', ';') |
| | | .replace(':', ':') |
| | | .replace(':', ':') |
| | | .trim(); |
| | | } |
| | | |
| | | /** |
| | | * 验证有效项目行 |
| | | */ |
| | | private boolean isValidItemRow(XWPFTableRow row) { |
| | | return row != null && |
| | | row.getTableCells().size() >= 2 && |
| | | !getCellText(row.getCell(1)).trim().isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * 空行检测 |
| | | */ |
| | | private boolean isRowEmpty(XWPFTableRow row) { |
| | | if (row == null) return true; |
| | | for (XWPFTableCell cell : row.getTableCells()) { |
| | | String text = getCellText(cell); |
| | | if (text != null && !text.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /*导入二保三保文件Excel--------------------------结束*/ |
| | | |
| | | } |