| | |
| | | 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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.jeecg.weibo.exception.BusinessException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | |
| | | 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; |
| | |
| | | import org.jeecg.modules.system.entity.SysParams; |
| | | import org.jeecg.modules.system.service.*; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service("IEamMaintenanceStandardService") |
| | | @Slf4j |
| | | public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService, FlowCallBackServiceI { |
| | | |
| | | @Resource |
| | |
| | | queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory); |
| | | queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.ne(EamMaintenanceStandard::getStandardStatus, standardStatus); |
| | | queryWrapper.ne(EamMaintenanceStandard::getStandardStatus,MaintenanceStandardStatusEnum.START.name()); |
| | | queryWrapper.orderByDesc(EamMaintenanceStandard::getStandardVersion); |
| | | |
| | | List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper); |
| | |
| | | return eamMaintenanceStandardMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public EamMaintenanceStandard queryByEquipmentIdAndCategory(String equipmentId, String maintenanceCategory) { |
| | | LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); |
| | | queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory); |
| | | queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.START.name()); |
| | | queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId); |
| | | return eamMaintenanceStandardMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | | |
| | | /*流程业务代码--------------------------开始*/ |
| | | |
| | | /** |
| | | * 流程启动,保存对应的数据 |
| | | * |
| | | * @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); |
| | | 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()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return Result.error("流程记录不存在"); |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | 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()); |
| | | flowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); |
| | | flowMyBusinessService.updateById(flowMyBusiness); |
| | | } |
| | | |
| | | // 处理首次启动流程 |
| | | return handleFirstSubmitScenario(maintenanceStandard, equipment, currentUser); |
| | | } |
| | | |
| | | /** |
| | | * 判断是否是驳回后重新提交的场景 |
| | | */ |
| | | private boolean isReSubmitScenario(FlowMyBusiness flowBusiness) { |
| | | return flowBusiness != null && |
| | | MaintenanceStandardStatusEnum.WAIT_SUBMIT.name().equals(flowBusiness.getTaskNameId()); |
| | | } |
| | | |
| | | /** |
| | | * 处理驳回后重新提交的流程 |
| | | */ |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 审批操作 |
| | | * |
| | | * @param eamMaintenanceStandardVo |
| | | * @return |
| | | * 处理首次提交的流程 |
| | | */ |
| | | private Result<?> handleFirstSubmitScenario(EamMaintenanceStandard maintenanceStandard, |
| | | EamEquipment equipment, |
| | | LoginUser currentUser) { |
| | | // 初始化流程业务信息 |
| | | flowCommonService.initActBusiness( |
| | | maintenanceStandard.getStandardName() + "规范进行流程审核", |
| | | maintenanceStandard.getId(), |
| | | "IEamMaintenanceStandardService", |
| | | "eam_maintenance_standard", |
| | | null |
| | | ); |
| | | |
| | | // 构建流程变量 |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 审批操作 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo) { |
| | | try { |
| | | // 参数校验 |
| | | if (StrUtil.isEmpty(eamMaintenanceStandardVo.getTaskId()) || StrUtil.isEmpty(eamMaintenanceStandardVo.getDataId())) { |
| | | return Result.error("参数错误"); |
| | | } |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | String userId = user.getId(); |
| | | eamMaintenanceStandardVo.setAssignee(user.getUsername()); |
| | | if (StrUtil.isEmpty(userId)) { |
| | | return Result.error("未找到对应用户"); |
| | | } |
| | | public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo vo) { |
| | | // 基础校验 |
| | | EamMaintenanceStandard standard = validateStandardExistence(vo.getDataId()); |
| | | LoginUser user = getCurrentUser(); |
| | | FlowMyBusiness business = validateFlowBusiness(vo); |
| | | validateUserAuthorization(business, user); |
| | | claimTaskOrFail(business.getTaskId(), user); |
| | | |
| | | // 数据查询 |
| | | EamMaintenanceStandard eamMaintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId()); |
| | | if (eamMaintenanceStandard == null) { |
| | | return Result.error("未找到对应保养标准"); |
| | | } |
| | | // 准备审批所需数据 |
| | | EamEquipment equipment = validateEquipmentExistence(standard.getEquipmentId()); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | |
| | | // 2. 查询流程业务记录(处理空结果) |
| | | List<FlowMyBusiness> businessList = flowMyBusinessService.list( |
| | | new QueryWrapper<FlowMyBusiness>() |
| | | .eq("process_instance_id", eamMaintenanceStandardVo.getInstanceId()) |
| | | ); |
| | | if (businessList.isEmpty()) { |
| | | return Result.error("流程记录不存在"); |
| | | } |
| | | FlowMyBusiness flowMyBusiness = businessList.get(0); |
| | | // 根据当前状态处理审批 |
| | | MaintenanceStandardStatusEnum status = MaintenanceStandardStatusEnum.getInstance(standard.getStandardStatus()); |
| | | if (status == null) { |
| | | throw new JeecgBootException("无效的保养标准状态"); |
| | | } |
| | | |
| | | // 3. 校验用户是否为候选处理人 |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | if (todoUsers == null || !todoUsers.contains(user.getUsername())) { |
| | | return Result.error("用户无权操作此任务"); |
| | | } |
| | | switch (status) { |
| | | case WAIT_REPAIR_DIRECTOR: |
| | | handleRepairDirectorApproval(vo, standard, equipment, variables); |
| | | break; |
| | | case WAIT_TECHNICAL_DIRECTOR: |
| | | handleTechnicalDirectorApproval(vo, standard, equipment, variables); |
| | | break; |
| | | default: |
| | | throw new JeecgBootException("当前状态不支持审批操作"); |
| | | } |
| | | |
| | | // 4. 认领任务(处理已被认领的情况) |
| | | String taskId = flowMyBusiness.getTaskId(); |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return Result.error("任务不存在或已完成"); |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return Result.error("任务已被他人认领"); |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | // 提交审批结果 |
| | | submitApprovalResult(vo, standard, variables); |
| | | return Result.OK("操作成功"); |
| | | } |
| | | |
| | | // 设置流程变量 |
| | | 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()); |
| | | List<UserSelector> userSelectorList = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0009); |
| | | 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()); |
| | | } |
| | | eamMaintenanceStandard.setRepairManager(user.getUsername()); |
| | | eamMaintenanceStandard.setRepairManagerApproveResult(eamMaintenanceStandardVo.getRepairManagerApproveResult()); |
| | | eamMaintenanceStandard.setRepairManagerApproveTime(new Date()); |
| | | eamMaintenanceStandard.setRepairManagerApproveComment(eamMaintenanceStandardVo.getComment()); |
| | | } |
| | | 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()); |
| | | } |
| | | eamMaintenanceStandard.setTechnicalManager(user.getUsername()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveResult(eamMaintenanceStandardVo.getTechnicalManagerApproveResult()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveTime(new Date()); |
| | | eamMaintenanceStandard.setTechnicalManagerApproveComment(eamMaintenanceStandardVo.getComment()); |
| | | } |
| | | this.updateById(eamMaintenanceStandard); |
| | | } else { |
| | | return result; |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } catch (Exception e) { |
| | | return Result.error("操作失败:" + e.getMessage()); |
| | | |
| | | private LoginUser getCurrentUser() { |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null) { |
| | | throw new JeecgBootException("未获取到登录用户,请重新登录后再试!"); |
| | | } |
| | | return 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 Map<String, Object> setProcessVariables(EamMaintenanceStandard eamMaintenanceStandard, String userId, EamMaintenanceStandardVo eamMaintenanceStandardVo) { |
| | | Map<String, Object> values = new HashMap<>(); |
| | | values.put("dataId", eamMaintenanceStandard.getId()); |
| | | values.put("assignee", userId); |
| | | if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) { |
| | | values.put("repairManagerApproveResult", eamMaintenanceStandardVo.getRepairManagerApproveResult()); |
| | | values.put("organization", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getRepairManagerApproveComment()); |
| | | private void claimTaskOrFail(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | throw new JeecgBootException("任务不存在或已完成"); |
| | | } |
| | | if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) { |
| | | values.put("technicalManagerApproveResult", eamMaintenanceStandardVo.getTechnicalManagerApproveResult()); |
| | | values.put("organization", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | values.put("comment", eamMaintenanceStandardVo.getTechnicalManagerApproveComment()); |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | throw new JeecgBootException("任务已被他人认领"); |
| | | } |
| | | return values; |
| | | taskService.claim(taskId, user.getUsername()); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | //业务是否干预流程,业务干预,流程干预,指定人员进行处理 |
| | | return null; |
| | | //获取下一步处理人 |
| | | Object object = values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | |
| | | /*流程业务代码--------------------------结束*/ |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> importPointInspectionExcel(MultipartFile file) { |
| | | public Result<?> importPointInspectionExcel(MultipartFile file,String id) { |
| | | EamMaintenanceStandard eamMaintenanceStandardOld=new EamMaintenanceStandard(); |
| | | if (StrUtil.isNotEmpty(id)){ |
| | | eamMaintenanceStandardOld=eamMaintenanceStandardMapper.selectById(id); |
| | | } |
| | | try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | |
| | |
| | | |
| | | eamMaintenanceStandard.setStandardName(name); |
| | | |
| | | // 检查重复 |
| | | EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), |
| | | eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | if (exist != null) { |
| | | return Result.error(name + ": 设备标准已存在,不能重复添加"); |
| | | // 检查重复,只导入校验,升版不校验 |
| | | if (StrUtil.isEmpty(id)){ |
| | | EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), |
| | | eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | if (exist != null) { |
| | | return Result.error(name + ": 设备标准已存在,不能重复添加"); |
| | | } |
| | | } |
| | | if (StrUtil.isNotEmpty(id)){ |
| | | if (eamMaintenanceStandardOld.getEquipmentId().equals(eamMaintenanceStandard.getEquipmentId()) |
| | | &&eamMaintenanceStandardOld.getMaintenanceCategory().equals(eamMaintenanceStandard.getMaintenanceCategory())) { |
| | | //判断是否现有待提交数据 |
| | | EamMaintenanceStandard maintenanceStandard=eamMaintenanceStandardMapper.selectOne( |
| | | new QueryWrapper<EamMaintenanceStandard>().eq("equipment_id",eamMaintenanceStandard.getEquipmentId()) |
| | | .eq("maintenance_category",eamMaintenanceStandard.getMaintenanceCategory()) |
| | | .eq("standard_status",MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0)); |
| | | if (maintenanceStandard != null) { |
| | | //删除原有待提交 |
| | | eamMaintenanceStandardMapper.deleteById(maintenanceStandard.getId()); |
| | | } |
| | | //查询在流程中的数据 |
| | | List<EamMaintenanceStandard> eamMaintenanceStandardList=eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>().eq("equipment_id",eamMaintenanceStandard.getEquipmentId()) |
| | | .eq("maintenance_category",eamMaintenanceStandard.getMaintenanceCategory()) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | .and(i->i. |
| | | eq("standard_status",MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name()) |
| | | .or() |
| | | .eq("standard_status",MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name()) |
| | | )); |
| | | if (!eamMaintenanceStandardList.isEmpty()) { |
| | | return Result.error("已存在处于审批流程的数据,请删除或结束后进行升版导入操作"); |
| | | } |
| | | //升版操作,作废原有 |
| | | eamMaintenanceStandardOld.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | eamMaintenanceStandardMapper.updateById(eamMaintenanceStandardOld); |
| | | //版本递增获取数字 |
| | | Pattern pattern = Pattern.compile("(\\d+)(?:\\.\\d+)*$"); |
| | | Matcher matcher = pattern.matcher(eamMaintenanceStandardOld.getStandardVersion()); |
| | | if (matcher.find()) { |
| | | try { |
| | | int mainVersion = Integer.parseInt(matcher.group(1)); |
| | | eamMaintenanceStandard.setStandardVersion("v" + (mainVersion + 1)); |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | } |
| | | }else { |
| | | return Result.error("升版导入的文件与原有数据的设备编号不一致,请重新编辑导入文件"); |
| | | } |
| | | } |
| | | eamMaintenanceStandard.setInitialDate(new Date()); |
| | | eamMaintenanceStandardMapper.insert(eamMaintenanceStandard); |
| | |
| | | } |
| | | /*导入点检文件Excel--------------------------结束*/ |
| | | |
| | | /*导入二保三保文件Excel--------------------------开始*/ |
| | | |
| | | /*导入二保三保文件Word--------------------------开始*/ |
| | | /** |
| | | * 统一保养规范导入入口 |
| | | * |
| | | * @param file 上传文件 |
| | | * @param type 保养类型 (SECOND/THIRD) |
| | | * @return 导入结果(包含成功/失败信息) |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result<?> importMaintenanceStandard(MultipartFile file, String type) { |
| | | public Result<?> importMaintenanceStandard(MultipartFile file, String type, String id) { |
| | | String fileName = file.getOriginalFilename(); |
| | | |
| | | try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { |
| | | // 获取文档标题(第一个非空段落) |
| | | String documentTitle = null; |
| | | for (XWPFParagraph p : doc.getParagraphs()) { |
| | | String text = p.getText(); |
| | | if (text != null && !text.trim().isEmpty()) { |
| | | documentTitle = text.trim(); |
| | | break; // 找到第一个非空段落即退出 |
| | | } |
| | | } |
| | | |
| | | // 基础验证 |
| | | if (doc.getTables().isEmpty()) { |
| | | return Result.error(fileName + ": 文档中未找到表格"); |
| | | } |
| | | |
| | | // 基础验证 |
| | | if (doc.getTables().isEmpty()) { |
| | | return Result.error(fileName + ": 文档中未找到表格"); |
| | | } |
| | | |
| | | List<XWPFTable> tables = doc.getTables(); |
| | | EamMaintenanceStandard standard = null; |
| | | List<EamMaintenanceStandardDetail> items = new ArrayList<>(); |
| | | String standardId = null; |
| | | List<EamMaintenanceStandard> standards = new ArrayList<>(); |
| | | List<EamMaintenanceStandardDetail> allItems = new ArrayList<>(); |
| | | int deviceCount = 0; |
| | | boolean isRevision = StrUtil.isNotEmpty(id); |
| | | EamMaintenanceStandard oldStandardForRevision = null; |
| | | Map<String, Integer> deviceVersionMap = new HashMap<>(); |
| | | Map<String, Integer> compositeVersionMap = new HashMap<>(); |
| | | |
| | | // 1. 处理所有表格 |
| | | for (int i = 0; i < tables.size(); i++) { |
| | | // 获取文档中的所有段落 |
| | | List<XWPFParagraph> paragraphs = doc.getParagraphs(); |
| | | |
| | | // 如果是升版导入,获取原有标准 |
| | | if (isRevision) { |
| | | oldStandardForRevision = eamMaintenanceStandardMapper.selectById(id); |
| | | if (oldStandardForRevision == null) { |
| | | return Result.error("升版导入失败:未找到ID为" + id + "的设备标准"); |
| | | } |
| | | // 预加载设备版本信息(使用复合键) |
| | | loadDeviceMaxVersions(oldStandardForRevision.getEquipmentId(), compositeVersionMap); |
| | | } else { |
| | | // 非升版导入时,预加载所有设备的最大版本(使用复合键) |
| | | loadAllDeviceMaxVersions(compositeVersionMap); |
| | | } |
| | | |
| | | // 多设备处理主循环 |
| | | for (int i = 0; i < tables.size(); ) { |
| | | XWPFTable table = tables.get(i); |
| | | |
| | | if (i == 0) { // 第一页表格 |
| | | // 验证设备信息表格 |
| | | if (isWrongDocumentType(table, type)) { |
| | | return Result.error(fileName + ": 文档类型不匹配 - " + |
| | | ("SECOND".equals(type) ? "请导入二级保养文档" : "请导入三级保养文档")); |
| | | // 识别设备信息表格 |
| | | if (isDeviceInfoTable(table)) { |
| | | deviceCount++; |
| | | |
| | | // 升版导入只能处理单设备 |
| | | if (isRevision && deviceCount > 1) { |
| | | throw new ImportException("升版导入仅支持单设备文档"); |
| | | } |
| | | |
| | | // 提取设备信息 |
| | | standard = extractDeviceInfo(table, type); |
| | | EamMaintenanceStandard standard = extractDeviceInfo(table, type); |
| | | if (standard == null) { |
| | | return Result.error(fileName + ": 设备信息提取失败"); |
| | | throw new ImportException("表格" + (i+1) + ":设备信息提取失败"); |
| | | } |
| | | |
| | | // 配置类型相关参数 |
| | | configureStandard(standard, type, file); |
| | | EamMaintenanceStandard exist = checkDuplicate(standard.getEquipmentId(), standard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | if (exist != null) { |
| | | return Result.error(fileName + ": 设备标准已存在,不能重复添加"); |
| | | // 从文档中获取标题(表格前的段落) |
| | | String title = extractTitleBeforeTable(table, paragraphs); |
| | | if (title != null) { |
| | | standard.setStandardName(title); |
| | | } |
| | | standard.setStandardName(documentTitle); |
| | | |
| | | // 处理重复和升版逻辑 |
| | | processStandard(standard, type, file, id, oldStandardForRevision, compositeVersionMap); |
| | | |
| | | // 保存设备标准 |
| | | eamMaintenanceStandardMapper.insert(standard); |
| | | standardId = standard.getId(); |
| | | standards.add(standard); |
| | | |
| | | // 提取第一页的保养项目 |
| | | // 更新设备版本映射 |
| | | updateDeviceVersionMap(deviceVersionMap, standard); |
| | | |
| | | // 提取当前设备信息表格中的保养项目 |
| | | List<EamMaintenanceStandardDetail> items = new ArrayList<>(); |
| | | if ("SECOND".equals(type)) { |
| | | items.addAll(extractSecondMaintenanceItems(table, standardId, true)); |
| | | } else if ("THIRD".equals(type)) { |
| | | items.addAll(extractThirdMaintenanceItems(table, standardId, true)); |
| | | items.addAll(extractSecondMaintenanceItems(table, standard.getId(), true)); |
| | | } else { |
| | | items.addAll(extractThirdMaintenanceItems(table, standard.getId(), true)); |
| | | } |
| | | |
| | | } else { // 后续页面 |
| | | // 提取后续页面的保养项目 |
| | | if ("SECOND".equals(type)) { |
| | | items.addAll(extractSecondMaintenanceItems(table, standardId, false)); |
| | | } else if ("THIRD".equals(type)) { |
| | | items.addAll(extractThirdMaintenanceItems(table, standardId, false)); |
| | | // 提取后续关联的保养项目表格 |
| | | i++; // 移动到下一个表格 |
| | | while (i < tables.size() && !isDeviceInfoTable(tables.get(i))) { |
| | | XWPFTable itemTable = tables.get(i); |
| | | if ("SECOND".equals(type)) { |
| | | items.addAll(extractSecondMaintenanceItems(itemTable, standard.getId(), false)); |
| | | } else { |
| | | items.addAll(extractThirdMaintenanceItems(itemTable, standard.getId(), false)); |
| | | } |
| | | i++; |
| | | } |
| | | |
| | | // 项目后处理 |
| | | processItemsAfterExtraction(items, type); |
| | | allItems.addAll(items); |
| | | |
| | | // 如果是最后一个表格,需要退出循环 |
| | | if (i >= tables.size()) break; |
| | | } else { |
| | | i++; // 如果不是设备信息表格,继续下一个 |
| | | } |
| | | } |
| | | |
| | | // 验证设备信息提取 |
| | | if (standard == null) { |
| | | return Result.error(fileName + ": 设备信息提取失败"); |
| | | // 校验设备数量 |
| | | if (standards.isEmpty()) { |
| | | return Result.error(fileName + ":未找到有效的设备信息表格"); |
| | | } |
| | | |
| | | // 2. 后处理:根据不同类型进行处理 |
| | | processItemsAfterExtraction(items, type); |
| | | |
| | | // 3. 项目验证 |
| | | if (items.isEmpty()) { |
| | | return Result.error(fileName + ": 未提取到任何保养项目"); |
| | | // 批量保存保养项目 |
| | | if (!allItems.isEmpty()) { |
| | | eamMaintenanceStandardDetailService.saveBatch(allItems); |
| | | } |
| | | |
| | | // 4. 保存项目 |
| | | eamMaintenanceStandardDetailService.saveBatch(items); |
| | | |
| | | |
| | | // 更新流程状态 |
| | | SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type"); |
| | | |
| | | if (sysParams != null) { |
| | | if (sysParams.getSettingValue().equals("1")) { |
| | | if (sysParams != null && "1".equals(sysParams.getSettingValue())) { |
| | | for (EamMaintenanceStandard standard : standards) { |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | eamMaintenanceStandardMapper.updateById(standard); |
| | | } |
| | | } else { |
| | | return Result.error("未找到保养流程导入相关配置,请联系管理员"); |
| | | } else if (sysParams == null) { |
| | | throw new ImportException("未配置保养流程导入参数"); |
| | | } |
| | | |
| | | return Result.ok(fileName + ": 导入成功, 项目数: " + items.size()); |
| | | // 作废旧版本(保留最新版本) |
| | | obsoleteOldVersionsByCompositeKey(deviceVersionMap); |
| | | |
| | | return Result.ok(fileName + "导入成功,设备数:" + standards.size() + ",项目数:" + allItems.size()); |
| | | |
| | | } catch (ImportException e) { |
| | | return Result.error(e.getMessage()); |
| | | return Result.error(fileName + ":" + e.getMessage()); |
| | | } catch (Exception e) { |
| | | return Result.error(fileName + ": 系统错误 - " + e.getClass().getSimpleName()); |
| | | log.error("导入保养规范失败", e); |
| | | return Result.error(fileName + ":系统错误 - " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // 设备信息表格识别方法 |
| | | private boolean isDeviceInfoTable(XWPFTable table) { |
| | | if (table.getNumberOfRows() < 2) return false; |
| | | |
| | | // 检查前两行是否包含设备信息特征 |
| | | String row1 = getRowText(table.getRow(0)); |
| | | String row2 = getRowText(table.getRow(1)); |
| | | List<String> keywords = Arrays.asList("设备类别", "设备编号", "设备名称", "设备型号"); |
| | | int matchCount = 0; |
| | | |
| | | for (String keyword : keywords) { |
| | | if (row1.contains(keyword) || row2.contains(keyword)) { |
| | | matchCount++; |
| | | } |
| | | } |
| | | return matchCount >= 2; // 至少匹配两个关键词 |
| | | } |
| | | |
| | | // 获取表格行的文本内容 |
| | | private String getRowText(XWPFTableRow row) { |
| | | if (row == null) return ""; |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (XWPFTableCell cell : row.getTableCells()) { |
| | | sb.append(getCellText(cell)); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 后处理方法:根据不同类型进行处理 |
| | | * 从表格前的段落中提取标题(修复版) |
| | | */ |
| | | private void processItemsAfterExtraction(List<EamMaintenanceStandardDetail> items, String type) { |
| | | if ("SECOND".equals(type)) { |
| | | // 二级保养: 删除没有序号的数据 |
| | | items.removeIf(item -> item.getItemCode() == null); |
| | | } else { |
| | | // 三级保养: |
| | | // 1. 删除第一条数据(通常是标题行) |
| | | if (!items.isEmpty()) { |
| | | items.remove(0); |
| | | } |
| | | // 2. 为缺失部位的数据填充前一条的保养部位 |
| | | String lastPart = ""; |
| | | int i = 1; |
| | | for (EamMaintenanceStandardDetail item : items) { |
| | | item.setItemCode(i); |
| | | if (item.getItemPart() != null && !item.getItemPart().isEmpty()) { |
| | | lastPart = item.getItemPart(); |
| | | } else if (!lastPart.isEmpty()) { |
| | | item.setItemPart(lastPart); |
| | | private String extractTitleBeforeTable(XWPFTable table, List<XWPFParagraph> paragraphs) { |
| | | try { |
| | | // 获取表格的CTTbl对象 |
| | | CTTbl ctTbl = table.getCTTbl(); |
| | | |
| | | // 获取表格所在的body |
| | | IBody body = table.getBody(); |
| | | |
| | | // 获取body的所有元素(段落和表格) |
| | | List<IBodyElement> bodyElements = body.getBodyElements(); |
| | | |
| | | // 找到当前表格在body中的位置 |
| | | int tableIndex = -1; |
| | | for (int i = 0; i < bodyElements.size(); i++) { |
| | | IBodyElement element = bodyElements.get(i); |
| | | if (element instanceof XWPFTable && element.equals(table)) { |
| | | tableIndex = i; |
| | | break; |
| | | } |
| | | i++; |
| | | } |
| | | |
| | | // 如果找到表格位置,向前查找段落 |
| | | if (tableIndex > 0) { |
| | | for (int i = tableIndex - 1; i >= 0; i--) { |
| | | IBodyElement element = bodyElements.get(i); |
| | | if (element instanceof XWPFParagraph) { |
| | | XWPFParagraph paragraph = (XWPFParagraph) element; |
| | | String text = paragraph.getText(); |
| | | if (text != null && !text.trim().isEmpty() && text.contains("保养规范")) { |
| | | return text.trim(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果上方没有找到标题,尝试从表格内部提取 |
| | | if (table.getNumberOfRows() > 0) { |
| | | XWPFTableRow firstRow = table.getRow(0); |
| | | for (XWPFTableCell cell : firstRow.getTableCells()) { |
| | | String text = getCellText(cell); |
| | | if (text != null && text.contains("保养规范")) { |
| | | return text.trim(); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("提取标题失败", e); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 处理设备标准的重复校验和升版逻辑 |
| | | */ |
| | | private void processStandard(EamMaintenanceStandard standard, String type, MultipartFile file, |
| | | String id, EamMaintenanceStandard oldStandard, |
| | | Map<String, Integer> versionMap) throws ImportException { |
| | | // 如果标题为空,使用设备名称生成默认标题 |
| | | if (StrUtil.isEmpty(standard.getStandardName())) { |
| | | String defaultTitle = standard.getEquipmentName() + "生产设备" + |
| | | ("SECOND".equals(type) ? "二级" : "三级") + "保养规范"; |
| | | standard.setStandardName(defaultTitle); |
| | | } |
| | | |
| | | // 配置基础属性 |
| | | configureStandard(standard, type, file); |
| | | |
| | | if (StrUtil.isNotEmpty(id)) { |
| | | // 升版导入处理 |
| | | if (oldStandard == null) { |
| | | throw new ImportException("未找到要升版的标准记录"); |
| | | } |
| | | |
| | | // 验证设备一致性(设备ID和保养类别必须一致) |
| | | if (!oldStandard.getEquipmentId().equals(standard.getEquipmentId()) || |
| | | !oldStandard.getMaintenanceCategory().equals(standard.getMaintenanceCategory())) { |
| | | throw new ImportException("升版设备信息或保养类别不一致"); |
| | | } |
| | | |
| | | // 检查待办流程 |
| | | List<EamMaintenanceStandard> pendingList = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("equipment_id", standard.getEquipmentId()) |
| | | .eq("maintenance_category", standard.getMaintenanceCategory()) |
| | | .in("standard_status", |
| | | MaintenanceStandardStatusEnum.WAIT_SUBMIT.name(), |
| | | MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name(), |
| | | MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name()) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | ); |
| | | |
| | | if (!pendingList.isEmpty()) { |
| | | throw new ImportException("存在待审批流程,请结束后再操作"); |
| | | } |
| | | |
| | | // 作废旧标准 |
| | | oldStandard.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | eamMaintenanceStandardMapper.updateById(oldStandard); |
| | | |
| | | // 版本升级 |
| | | String newVersion = incrementVersion(oldStandard.getStandardVersion()); |
| | | standard.setStandardVersion(newVersion); |
| | | |
| | | // 更新版本映射 |
| | | String compositeKey = generateCompositeKey( |
| | | standard.getEquipmentId(), |
| | | standard.getMaintenanceCategory() |
| | | ); |
| | | int newVersionNum = extractVersionNumber(newVersion); |
| | | versionMap.put(compositeKey, newVersionNum); |
| | | |
| | | } else { |
| | | // 查询所有匹配的设备+保养类别标准 |
| | | List<EamMaintenanceStandard> existingStandards = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("equipment_id", standard.getEquipmentId()) |
| | | .eq("maintenance_category", standard.getMaintenanceCategory()) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | ); |
| | | |
| | | // 如果存在匹配记录,找出最大版本号 |
| | | if (!existingStandards.isEmpty()) { |
| | | // 找出最大版本号 |
| | | int maxVersion = existingStandards.stream() |
| | | .mapToInt(s -> extractVersionNumber(s.getStandardVersion())) |
| | | .max() |
| | | .orElse(0); |
| | | |
| | | // 设置新版本号为最大版本+1 |
| | | standard.setStandardVersion("v" + (maxVersion + 1)); |
| | | |
| | | // 更新版本映射 |
| | | String compositeKey = generateCompositeKey( |
| | | standard.getEquipmentId(), |
| | | standard.getMaintenanceCategory() |
| | | ); |
| | | versionMap.put(compositeKey, maxVersion + 1); |
| | | } else { |
| | | // 没有匹配记录,初始化为v1 |
| | | standard.setStandardVersion("v1"); |
| | | |
| | | // 更新版本映射 |
| | | String compositeKey = generateCompositeKey( |
| | | standard.getEquipmentId(), |
| | | standard.getMaintenanceCategory() |
| | | ); |
| | | versionMap.put(compositeKey, 1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 提取二级保养项目(区分第一页和后续页面) |
| | | * 配置保养标准参数 |
| | | */ |
| | | private void configureStandard(EamMaintenanceStandard standard, String type, MultipartFile file) { |
| | | // 基础参数 |
| | | standard.setInitialDate(new Date()) |
| | | .setStandardStatus(MaintenanceStandardStatusEnum.START.name()) |
| | | .setDelFlag(CommonConstant.DEL_FLAG_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 && extend.getThirdMaintenancePeriod() != null) { |
| | | standard.setMaintenancePeriod(extend.getThirdMaintenancePeriod()); |
| | | } |
| | | } |
| | | |
| | | // 默认三级保养周期 |
| | | if (standard.getMaintenancePeriod() == null) { |
| | | standard.setMaintenancePeriod(1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载指定设备的最大版本号 |
| | | */ |
| | | private void loadDeviceMaxVersions(String equipmentId, Map<String, Integer> compositeVersionMap) { |
| | | if (StrUtil.isBlank(equipmentId)) return; |
| | | |
| | | // 查询该设备的所有标准 |
| | | List<EamMaintenanceStandard> standards = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("equipment_id", equipmentId) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | ); |
| | | |
| | | // 按保养分类分组 |
| | | Map<String, List<EamMaintenanceStandard>> standardsByCategory = standards.stream() |
| | | .collect(Collectors.groupingBy(EamMaintenanceStandard::getMaintenanceCategory)); |
| | | |
| | | // 解析每个保养分类的最大版本号 |
| | | for (Map.Entry<String, List<EamMaintenanceStandard>> entry : standardsByCategory.entrySet()) { |
| | | String maintenanceCategory = entry.getKey(); |
| | | int maxVersion = entry.getValue().stream() |
| | | .mapToInt(s -> extractVersionNumber(s.getStandardVersion())) |
| | | .max() |
| | | .orElse(0); |
| | | |
| | | String compositeKey = generateCompositeKey(equipmentId, maintenanceCategory); |
| | | compositeVersionMap.put(compositeKey, maxVersion); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载所有设备的最大版本号 |
| | | */ |
| | | private void loadAllDeviceMaxVersions(Map<String, Integer> deviceVersionMap) { |
| | | // 查询所有设备的标准 |
| | | List<EamMaintenanceStandard> allStandards = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | ); |
| | | |
| | | // 创建复合键分组:设备ID + 保养分类 |
| | | Map<String, List<EamMaintenanceStandard>> standardsByCompositeKey = new HashMap<>(); |
| | | |
| | | for (EamMaintenanceStandard standard : allStandards) { |
| | | String compositeKey = generateCompositeKey( |
| | | standard.getEquipmentId(), |
| | | standard.getMaintenanceCategory() |
| | | ); |
| | | |
| | | standardsByCompositeKey |
| | | .computeIfAbsent(compositeKey, k -> new ArrayList<>()) |
| | | .add(standard); |
| | | } |
| | | |
| | | // 计算每个复合键的最大版本号 |
| | | for (Map.Entry<String, List<EamMaintenanceStandard>> entry : standardsByCompositeKey.entrySet()) { |
| | | String compositeKey = entry.getKey(); |
| | | int maxVersion = entry.getValue().stream() |
| | | .mapToInt(s -> extractVersionNumber(s.getStandardVersion())) |
| | | .max() |
| | | .orElse(0); |
| | | |
| | | deviceVersionMap.put(compositeKey, maxVersion); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新设备版本映射表 |
| | | */ |
| | | private void updateDeviceVersionMap(Map<String, Integer> compositeVersionMap, |
| | | EamMaintenanceStandard newStandard) { |
| | | String compositeKey = generateCompositeKey( |
| | | newStandard.getEquipmentId(), |
| | | newStandard.getMaintenanceCategory() |
| | | ); |
| | | |
| | | int newVersion = extractVersionNumber(newStandard.getStandardVersion()); |
| | | |
| | | // 如果复合键已存在,比较版本号 |
| | | if (compositeVersionMap.containsKey(compositeKey)) { |
| | | int currentMax = compositeVersionMap.get(compositeKey); |
| | | if (newVersion > currentMax) { |
| | | compositeVersionMap.put(compositeKey, newVersion); |
| | | } |
| | | } else { |
| | | compositeVersionMap.put(compositeKey, newVersion); |
| | | } |
| | | } |
| | | /** |
| | | * 作废旧版本 |
| | | */ |
| | | private void obsoleteOldVersionsByCompositeKey(Map<String, Integer> compositeVersionMap) { |
| | | for (Map.Entry<String, Integer> entry : compositeVersionMap.entrySet()) { |
| | | String compositeKey = entry.getKey(); |
| | | String[] parts = compositeKey.split("\\|"); |
| | | if (parts.length != 2) continue; |
| | | |
| | | String equipmentId = parts[0]; |
| | | String maintenanceCategory = parts[1]; |
| | | int maxVersion = entry.getValue(); |
| | | |
| | | // 作废所有不是最新版本的标准(相同设备+相同保养分类) |
| | | List<EamMaintenanceStandard> oldStandards = eamMaintenanceStandardMapper.selectList( |
| | | new QueryWrapper<EamMaintenanceStandard>() |
| | | .eq("equipment_id", equipmentId) |
| | | .eq("maintenance_category", maintenanceCategory) |
| | | .eq("del_flag", CommonConstant.DEL_FLAG_0) |
| | | ); |
| | | |
| | | for (EamMaintenanceStandard standard : oldStandards) { |
| | | int version = extractVersionNumber(standard.getStandardVersion()); |
| | | if (version < maxVersion) { |
| | | // 检查是否在审批流程中 |
| | | if (isPendingApproval(standard)) { |
| | | log.warn("跳过作废:设备{}的{}标准{}处于审批流程中", |
| | | equipmentId, maintenanceCategory, standard.getId()); |
| | | continue; |
| | | } |
| | | |
| | | standard.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); |
| | | eamMaintenanceStandardMapper.updateById(standard); |
| | | |
| | | log.info("设备{}的{}旧标准已作废:{} (v{})", |
| | | equipmentId, maintenanceCategory, standard.getId(), version); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断标准是否处于审批流程中 |
| | | */ |
| | | private boolean isPendingApproval(EamMaintenanceStandard standard) { |
| | | return MaintenanceStandardStatusEnum.WAIT_SUBMIT.name().equals(standard.getStandardStatus()) || |
| | | MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name().equals(standard.getStandardStatus()) || |
| | | MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name().equals(standard.getStandardStatus()); |
| | | } |
| | | |
| | | /** |
| | | * 从版本字符串中提取数字 |
| | | */ |
| | | private int extractVersionNumber(String versionStr) { |
| | | if (StrUtil.isBlank(versionStr)) return 0; |
| | | |
| | | Pattern pattern = Pattern.compile("v?(\\d+)"); |
| | | Matcher matcher = pattern.matcher(versionStr); |
| | | if (matcher.find()) { |
| | | try { |
| | | return Integer.parseInt(matcher.group(1)); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("版本号解析失败: {}", versionStr); |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | /** |
| | | * 生成设备+保养类别的复合键 |
| | | */ |
| | | private String generateCompositeKey(String equipmentId, String maintenanceCategory) { |
| | | return equipmentId + "|" + maintenanceCategory; |
| | | } |
| | | |
| | | /** |
| | | * 版本号递增逻辑 |
| | | */ |
| | | private String incrementVersion(String oldVersion) { |
| | | if (StrUtil.isBlank(oldVersion)) { |
| | | return "v1"; |
| | | } |
| | | |
| | | // 尝试匹配 vX 格式 |
| | | Pattern pattern = Pattern.compile("v?(\\d+)"); |
| | | Matcher matcher = pattern.matcher(oldVersion); |
| | | if (matcher.find()) { |
| | | try { |
| | | int verNum = Integer.parseInt(matcher.group(1)) + 1; |
| | | return "v" + verNum; |
| | | } catch (NumberFormatException e) { |
| | | // 格式错误,使用默认 |
| | | } |
| | | } |
| | | return "v1"; |
| | | } |
| | | |
| | | /** |
| | | * 提取设备基本信息 |
| | | */ |
| | | private EamMaintenanceStandard extractDeviceInfo(XWPFTable table, String type) { |
| | | 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 (StrUtil.isNotEmpty(standard.getEquipmentCode())) { |
| | | EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode()); |
| | | if (equipment == null) { |
| | | log.warn("设备编码未找到: {}", standard.getEquipmentCode()); |
| | | return null; |
| | | } else { |
| | | standard.setEquipmentId(equipment.getId()); |
| | | } |
| | | } |
| | | |
| | | return standard; |
| | | } |
| | | |
| | | /** |
| | | * 提取二级保养项目 |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractSecondMaintenanceItems( |
| | | XWPFTable table, String standardId, boolean isFirstTable) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 优化后的空行检测(解决跨页空行问题) |
| | | */ |
| | | private boolean isRowEmpty(XWPFTableRow row) { |
| | | if (row == null || row.getTableCells().isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | boolean allCellsEmpty = true; |
| | | for (XWPFTableCell cell : row.getTableCells()) { |
| | | String text = getCellText(cell).trim(); |
| | | // 保留包含换行符等的单元格作为非空行 |
| | | if (!text.isEmpty() && !text.replaceAll("\\s+", "").isEmpty()) { |
| | | allCellsEmpty = false; |
| | | break; |
| | | } |
| | | } |
| | | return allCellsEmpty; |
| | | } |
| | | |
| | | /** |
| | | * 文档类型校验 - 防止二保传入三保或反之 |
| | | */ |
| | | private boolean isWrongDocumentType(XWPFTable table, String requestedType) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 提取设备基本信息 |
| | | */ |
| | | private EamMaintenanceStandard extractDeviceInfo(XWPFTable table, String type) { |
| | | 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 (StrUtil.isNotEmpty(standard.getEquipmentCode())) { |
| | | EamEquipment equipments = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode()); |
| | | if (equipments == null) { |
| | | return null; |
| | | } else { |
| | | standard.setEquipmentId(equipments.getId()); |
| | | } |
| | | if (type.equals("THIRD")) { |
| | | EamEquipmentExtend eamEquipmentExtend = eamEquipmentExtendService.getById(standard.getEquipmentId()); |
| | | standard.setMaintenancePeriod(eamEquipmentExtend.getThirdMaintenancePeriod()); |
| | | } |
| | | } |
| | | |
| | | return standard; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 表格行数据解析 |
| | | */ |
| | | private Map<String, String> extractRowData(XWPFTableRow row) { |
| | |
| | | else { |
| | | for (int i = 0; i < cellCount; i++) { |
| | | String text = getCellText(row.getCell(i)); |
| | | // 支持中文冒号和英文冒号 |
| | | int colonIndex = text.indexOf(':'); |
| | | if (colonIndex < 0) colonIndex = text.indexOf(':'); |
| | | |
| | | if (colonIndex > 0) { |
| | | String key = cleanKey(text.substring(0, colonIndex)); |
| | | String value = text.substring(colonIndex + 1); |
| | |
| | | |
| | | /** |
| | | * 键名标准化处理 |
| | | */ |
| | | */ |
| | | private String cleanKey(String key) { |
| | | if (key == null) return ""; |
| | | // 移除空格和中文冒号 |
| | | return key.replaceAll("\\s", "").replace(":", ""); |
| | | return key.replaceAll("\\s", "").replace(":", "").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('.')); |
| | | private boolean isRowEmpty(XWPFTableRow row) { |
| | | if (row == null || row.getTableCells().isEmpty()) { |
| | | return true; |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | boolean allCellsEmpty = true; |
| | | for (XWPFTableCell cell : row.getTableCells()) { |
| | | String text = getCellText(cell).trim(); |
| | | // 保留包含换行符等的单元格作为非空行 |
| | | if (!text.isEmpty() && !text.replaceAll("\\s+", "").isEmpty()) { |
| | | allCellsEmpty = false; |
| | | break; |
| | | } |
| | | } |
| | | return allCellsEmpty; |
| | | } |
| | | |
| | | /** |
| | |
| | | !getCellText(row.getCell(1)).trim().isEmpty(); |
| | | } |
| | | |
| | | /*导入二保三保文件Excel--------------------------结束*/ |
| | | /** |
| | | * 后处理方法:根据不同类型进行处理 |
| | | */ |
| | | private void processItemsAfterExtraction(List<EamMaintenanceStandardDetail> items, String type) { |
| | | if ("SECOND".equals(type)) { |
| | | // 二级保养: 删除没有序号的数据 |
| | | items.removeIf(item -> item.getItemCode() == null); |
| | | } else { |
| | | // 三级保养: |
| | | // 1. 删除第一条数据(通常是标题行) |
| | | if (!items.isEmpty()) { |
| | | items.remove(0); |
| | | } |
| | | // 2. 为缺失部位的数据填充前一条的保养部位 |
| | | String lastPart = ""; |
| | | int i = 1; |
| | | for (EamMaintenanceStandardDetail item : items) { |
| | | item.setItemCode(i); |
| | | if (item.getItemPart() != null && !item.getItemPart().isEmpty()) { |
| | | lastPart = item.getItemPart(); |
| | | } else if (!lastPart.isEmpty()) { |
| | | item.setItemPart(lastPart); |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /*导入二保三保文件Word--------------------------结束*/ |
| | | } |