From 6722e123b7a54dcc6c6937bc4324c67293f233db Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期五, 18 七月 2025 11:50:04 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java | 1223 +++++++++++++++++++++++++++++++++------------------------ 1 files changed, 701 insertions(+), 522 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java index 2f1b8f8..8dbc946 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java @@ -10,12 +10,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jeecg.weibo.exception.BusinessException; -import liquibase.pro.packaged.R; -import liquibase.pro.packaged.S; -import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xwpf.usermodel.*; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; @@ -24,10 +20,6 @@ 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.eam.constant.BusinessCodeConst; import org.jeecg.modules.eam.constant.EamMaintenanceStandardDetailCategory; import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; @@ -42,15 +34,17 @@ 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.eam.vo.*; +import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo; import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; 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.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.entity.BaseFactory; +import org.jeecg.modules.system.entity.BaseFactoryUser; +import org.jeecg.modules.system.entity.SysParams; +import org.jeecg.modules.system.service.*; import org.jeecg.modules.system.vo.UserSelector; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -69,11 +63,11 @@ /** * @Description: 淇濆吇鏍囧噯 * @Author: jeecg-boot - * @Date: 2025-03-26 + * @Date: 2025-03-26 * @Version: V1.0 */ @Service("IEamMaintenanceStandardService") -public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService , FlowCallBackServiceI { +public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService, FlowCallBackServiceI { @Resource private EamMaintenanceStandardMapper eamMaintenanceStandardMapper; @@ -101,6 +95,8 @@ private IEamEquipmentExtendService eamEquipmentExtendService; @Autowired private ISysBusinessCodeRuleService businessCodeRuleService; + @Autowired + private ISysParamsService sysParamsService; // 甯搁噺瀹氫箟 private static final String REPAIR_TITLE = "缁翠慨浜哄憳淇濆吇鍐呭"; @@ -128,43 +124,45 @@ queryWrapper.in("e.equipment_code", equipArr); } else { //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶� - List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService. - list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId())); - if(!CollectionUtils.isEmpty(baseFactoryUserList)){ - List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList()); - List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList()); - queryWrapper.in("e.factory_code", factoryCode); + List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. + list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); + if (!CollectionUtils.isEmpty(baseFactoryUserList)) { + Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); + Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); + queryWrapper.in("e.factory_org_code", factoryCode); + } else { + return page; } } - if(eamMaintenanceStandard != null) { + if (eamMaintenanceStandard != null) { //缂栫爜 妯$硦鏌ヨ - if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) { queryWrapper.like("ems.standard_code", eamMaintenanceStandard.getStandardCode()); } //鍚嶇О 妯$硦鏌ヨ - if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) { queryWrapper.like("ems.standard_name", eamMaintenanceStandard.getStandardName()); } //璁惧 - if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) { queryWrapper.eq("ems.equipment_id", eamMaintenanceStandard.getEquipmentId()); } //淇濆吇鍒嗙被 - if(StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) { queryWrapper.eq("ems.maintenance_category", eamMaintenanceStandard.getMaintenanceCategory()); } //淇濆吇鍒嗙被 - if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) { queryWrapper.eq("ems.standard_status", eamMaintenanceStandard.getStandardStatus()); } //璁惧缂栫爜 - if(StringUtils.isNotBlank(eamMaintenanceStandard.getKeyword())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getKeyword())) { queryWrapper.and(wrapper -> wrapper.like("e.equipment_name", eamMaintenanceStandard.getKeyword()) .or() .like("e.equipment_code", eamMaintenanceStandard.getKeyword())); } //id - if(StringUtils.isNotBlank(eamMaintenanceStandard.getId())) { + if (StringUtils.isNotBlank(eamMaintenanceStandard.getId())) { queryWrapper.eq("ems.id", eamMaintenanceStandard.getId()); } } @@ -179,19 +177,19 @@ BeanUtils.copyProperties(standardRequest, entity); entity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); //鐗堟湰閫掑 - entity.setStandardVersion("v"+CommonConstant.OPERATE_TYPE_1); + entity.setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1); //璁惧澶勭悊 entity.setEquipmentId(standardRequest.getEquipmentId()); //鍒犻櫎鏍囪 entity.setDelFlag(CommonConstant.DEL_FLAG_0); //閲嶅鎬ф牎楠� - EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory()); - if(exist != null){ + EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); + if (exist != null) { throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�"); } eamMaintenanceStandardMapper.insert(entity); //澶勭悊鏄庣粏鏁版嵁 - if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { + if (CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { standardRequest.getTableDetailList().forEach(tableDetail -> { tableDetail.setStandardId(entity.getId()); }); @@ -204,7 +202,7 @@ @Transactional(rollbackFor = Exception.class) public boolean editMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId()); - if(entity == null){ + if (entity == null) { throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�"); } entity.setStandardName(standardRequest.getStandardName()); @@ -213,25 +211,17 @@ //澶勭悊璇︽儏 if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { List<EamMaintenanceStandardDetail> addList = new ArrayList<>(); - List<EamMaintenanceStandardDetail> updateList = new ArrayList<>(); + //鍏堝垹闄ゅ師鏈� + LambdaQueryWrapper<EamMaintenanceStandardDetail> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(EamMaintenanceStandardDetail::getStandardId, standardRequest.getId()); + eamMaintenanceStandardDetailService.remove(queryWrapper); standardRequest.getTableDetailList().forEach(tableDetail -> { - tableDetail.setStandardId(entity.getId()); - if(tableDetail.getId() == null){ - addList.add(tableDetail); - }else { - updateList.add(tableDetail); - } + EamMaintenanceStandardDetail eamMaintenanceStandardDetail=new EamMaintenanceStandardDetail(); + BeanUtils.copyProperties(tableDetail, eamMaintenanceStandardDetail); + eamMaintenanceStandardDetail.setStandardId(entity.getId()); + addList.add(eamMaintenanceStandardDetail); }); - if(CollectionUtil.isNotEmpty(addList)){ - eamMaintenanceStandardDetailService.saveBatch(addList); - } - if(CollectionUtil.isNotEmpty(updateList)){ - eamMaintenanceStandardDetailService.updateBatchById(updateList); - } - } - if(CollectionUtil.isNotEmpty(standardRequest.getRemoveDetailList())) { - List<String> ids = standardRequest.getRemoveDetailList().stream().map(EamMaintenanceStandardDetail::getId).collect(Collectors.toList()); - eamMaintenanceStandardDetailService.removeBatchByIds(ids); + eamMaintenanceStandardDetailService.saveBatch(addList); } return true; } @@ -240,7 +230,7 @@ @Transactional(rollbackFor = Exception.class) public boolean upgradeMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) { EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId()); - if(entity == null){ + if (entity == null) { throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�"); } @@ -251,6 +241,7 @@ newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory()); newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod()); newEntity.setInitialDate(standardRequest.getInitialDate()); + newEntity.setPeriodUnit(standardRequest.getPeriodUnit()); newEntity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); //鐗堟湰閫掑 //鑾峰彇鏁板瓧 @@ -259,7 +250,7 @@ if (matcher.find()) { try { int mainVersion = Integer.parseInt(matcher.group(1)); - newEntity.setStandardVersion("v"+(mainVersion+1)); + newEntity.setStandardVersion("v" + (mainVersion + 1)); } catch (NumberFormatException ignored) { } } @@ -268,13 +259,13 @@ //鍒犻櫎鏍囪 newEntity.setDelFlag(CommonConstant.DEL_FLAG_0); //閲嶅鎬ф牎楠� - EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory()); - if(exist != null){ + EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); + if (exist != null) { throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�"); } eamMaintenanceStandardMapper.insert(newEntity); //澶勭悊鏄庣粏鏁版嵁 - if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { + if (CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) { standardRequest.getTableDetailList().forEach(tableDetail -> { tableDetail.setId(null); tableDetail.setCreateBy(null); @@ -289,16 +280,16 @@ } @Override - public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory) { + public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory, String standardStatus) { LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId); queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory); queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); - queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); + queryWrapper.ne(EamMaintenanceStandard::getStandardStatus, standardStatus); queryWrapper.orderByDesc(EamMaintenanceStandard::getStandardVersion); List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper); - if(CollectionUtil.isEmpty(list)) { + if (CollectionUtil.isEmpty(list)) { return null; } return list.get(0); @@ -306,12 +297,13 @@ /** * 鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯 - * @param keyword 璁惧缂栧彿 + * + * @param keyword 璁惧缂栧彿 * @param maintenanceCategory 淇濆吇绫诲瀷 * @return */ @Override - public List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory){ + public List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory) { Page<EamMaintenanceStandard> page = new Page<EamMaintenanceStandard>(1, pageSize); EamMaintenanceStandard query = new EamMaintenanceStandard(); query.setEquipmentId(equipmentId); @@ -336,28 +328,29 @@ /** * 娴佺▼鍚姩,淇濆瓨瀵瑰簲鐨勬暟鎹� + * * @param id * @return */ @Override - public Result<?> saveEamMaintenanceStandardProcess(String id){ + public Result<?> saveEamMaintenanceStandardProcess(String id) { LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - EamMaintenanceStandard maintenanceStandard=this.getById(id); - if (maintenanceStandard==null){ + EamMaintenanceStandard maintenanceStandard = this.getById(id); + if (maintenanceStandard == null) { return Result.error("鏈壘鍒板搴斾繚鍏绘爣鍑�"); } System.out.println("淇濆吇瑙勮寖娴佺▼锛�" + maintenanceStandard.getId()); - flowCommonService.initActBusiness(maintenanceStandard.getStandardName()+"瑙勮寖杩涜娴佺▼瀹℃牳", + 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); + variables.put("proofreading", true); + Result result = flowDefinitionService.startProcessInstanceByKey("eam_maintenance_standard", variables); if (!result.isSuccess()) { super.removeById(maintenanceStandard.getId()); - }else { + } else { maintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name()); maintenanceStandard.setDesigner(user.getUsername()); maintenanceStandard.setDesignTime(new Date()); @@ -371,11 +364,10 @@ return Result.error("娴佺▼璁板綍涓嶅瓨鍦�"); } 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); + 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()); + List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList()); flowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); flowMyBusinessService.updateById(flowMyBusiness); } @@ -385,11 +377,13 @@ /** * 瀹℃壒鎿嶄綔 + * * @param eamMaintenanceStandardVo * @return */ @Override - public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo){ + @Transactional(rollbackFor = Exception.class) + public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo) { try { // 鍙傛暟鏍¢獙 if (StrUtil.isEmpty(eamMaintenanceStandardVo.getTaskId()) || StrUtil.isEmpty(eamMaintenanceStandardVo.getDataId())) { @@ -443,23 +437,22 @@ Result result = flowTaskService.complete(eamMaintenanceStandardVo); if (result.isSuccess()) { if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) { - if (eamMaintenanceStandardVo.getRepairManagerApproveResult().equals("1")){ + 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鐨勬祦绋嬪疄渚媔d,璁剧疆涓嬩竴姝ョ殑澶勭悊浜哄憳 - 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); + 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()); + List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList()); newflowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList)); flowMyBusinessService.updateById(newflowMyBusiness); } - }else { + } else { eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); } eamMaintenanceStandard.setRepairManager(user.getUsername()); @@ -468,15 +461,15 @@ eamMaintenanceStandard.setRepairManagerApproveComment(eamMaintenanceStandardVo.getComment()); } if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) { - if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")){ + if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")) { eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); //鍒ゆ柇鏄惁杩涜鍗囩増锛岄�氳繃璁惧缂栧彿銆佷繚鍏诲垎绫汇�佺姸鎬佽繘琛岀瓫閫� - EamMaintenanceStandard maintenanceStandard=this.getById(eamMaintenanceStandardVo.getDataId()); - QueryWrapper<EamMaintenanceStandard> queryWrapper=new QueryWrapper<>(); + 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); + List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper); if (!CollectionUtils.isEmpty(list)) { //浣滃簾鍘熸湁 for (EamMaintenanceStandard eamMaintenanceStandard1 : list) { @@ -484,7 +477,7 @@ this.updateById(eamMaintenanceStandard1); } } - }else { + } else { eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); } eamMaintenanceStandard.setTechnicalManager(user.getUsername()); @@ -547,9 +540,10 @@ /*瀵煎叆鐐规鏂囦欢Excel--------------------------寮�濮�*/ + /** - * 鐐规琛ㄥ鍏ュ叆鍙� - */ + * 鐐规琛ㄥ鍏ュ叆鍙� + */ @Override @Transactional(rollbackFor = Exception.class) public Result<?> importPointInspectionExcel(MultipartFile file) { @@ -561,22 +555,32 @@ // 1. 鎻愬彇璁惧淇℃伅 EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet); - if (eamMaintenanceStandard == null) { + if (eamMaintenanceStandard == null || eamMaintenanceStandard.getEquipmentId() == null) { return Result.error("璁惧淇℃伅鎻愬彇澶辫触"); } eamMaintenanceStandard.setStandardName(name); + + // 妫�鏌ラ噸澶� + EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), + eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); + if (exist != null) { + return Result.error(name + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞"); + } + eamMaintenanceStandard.setInitialDate(new Date()); eamMaintenanceStandardMapper.insert(eamMaintenanceStandard); - // 2. 鎻愬彇姣忔棩鐐规椤圭洰 - List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard); - if(dailyDetails.isEmpty()){ + Map<Integer, String> rowErrors = new HashMap<>(); + + // 2. 鎻愬彇姣忔棩鐐规椤圭洰锛堜紭鍖栫┖琛屽拰缁撴潫鏍囪澶勭悊锛� + List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard, rowErrors); + if (dailyDetails.isEmpty()) { return Result.error("鏈壘鍒版瘡鏃ョ偣妫�椤圭洰"); } // 3. 鎻愬彇鍛ㄤ繚鍏婚」鐩� - List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard); - if(weeklyDetails.isEmpty()){ + List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard, rowErrors); + if (weeklyDetails.isEmpty()) { return Result.error("鏈壘鍒板懆淇濆吇椤圭洰"); } @@ -589,6 +593,17 @@ eamMaintenanceStandardDetailService.saveBatch(allDetails); } + // 瑙﹀彂淇濆吇娴佺▼ + SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type"); + if (sysParams != null) { + if (sysParams.getSettingValue().equals("1")){ + eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); + eamMaintenanceStandardMapper.updateById(eamMaintenanceStandard); + } + } else { + return Result.error("鏈壘鍒颁繚鍏绘祦绋嬪鍏ョ浉鍏抽厤缃�,璇疯仈绯荤鐞嗗憳"); + } + return Result.OK("鐐规琛ㄥ鍏ユ垚鍔�"); } catch (Exception e) { @@ -597,8 +612,8 @@ } /** - * 鎻愬彇鐐规琛ㄦ爣棰� - */ + * 鎻愬彇鐐规琛ㄦ爣棰� + */ private String extractInspectionTitle(MultipartFile file) { try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { Sheet sheet = workbook.getSheetAt(0); @@ -622,7 +637,7 @@ } /** - * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧 + * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧 */ private String extractTextBeforeInspection(String title) { if (StringUtils.isBlank(title)) { @@ -634,8 +649,8 @@ } /** - * 鎻愬彇璁惧淇℃伅 - */ + * 鎻愬彇璁惧淇℃伅 + */ private EamMaintenanceStandard extractDeviceInfo(Sheet sheet) { Row headerRow = sheet.getRow(0); if (headerRow == null) { @@ -649,7 +664,7 @@ EamMaintenanceStandard standard = new EamMaintenanceStandard(); standard.setEquipmentName(extractField(headerText, "璁惧鍚嶇О[:锛歖\\s*(\\S+)")); - standard.setEquipmentId(extractField(headerText, "璁惧鍨嬪彿[:锛歖\\s*(\\S+)")); + standard.setEquipmentCode(extractField(headerText, "缁熶竴缂栧彿[:锛歖\\s*(\\S+)")); // 鏃ユ湡澶勭悊 @@ -666,22 +681,14 @@ } // 鍏宠仈璁惧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 { + if (StrUtil.isNotEmpty(standard.getEquipmentCode())) { + EamEquipment equipments = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode()); + if (equipments == null) { return null; + } else { + standard.setEquipmentId(equipments.getId()); } } - String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); standard.setStandardCode(codeSeq); standard.setMaintenanceCategory("POINT_INSPECTION"); @@ -695,7 +702,7 @@ } /** - * 瑙f瀽鏃ユ湡瀛楃涓� + * 瑙f瀽鏃ユ湡瀛楃涓� */ private Date parseDate(String dateStr) throws ParseException { // 灏濊瘯澶氱鏃ユ湡鏍煎紡 @@ -721,172 +728,8 @@ } /** - * 鎻愬彇姣忔棩鐐规椤圭洰 - */ - private List<EamMaintenanceStandardDetail> extractDailyItems(Sheet sheet, EamMaintenanceStandard standard) { - return extractItems(sheet, standard, "鐐规椤圭洰", "瀹屾垚鏁版嵁/瑕佹眰", "DAY_INSPECTION"); - } - - /** - * 鎻愬彇鍛ㄤ繚鍏婚」鐩� - */ - private List<EamMaintenanceStandardDetail> extractWeeklyItems(Sheet sheet, EamMaintenanceStandard standard) { - return extractItems(sheet, standard, "鍛ㄤ繚鍏婚」鐩�", "妫�鏌ユ爣鍑�", "WEEK_INSPECTION"); - } - - /** - * 閫氱敤椤圭洰鎻愬彇鏂规硶 - */ - private List<EamMaintenanceStandardDetail> extractItems(Sheet sheet, EamMaintenanceStandard standard, - String primaryHeader, String secondaryHeader, - String itemCategory) { - int[] section = findTableSection(sheet, primaryHeader, secondaryHeader); - if (section == null) { - return Collections.emptyList(); - } - - List<EamMaintenanceStandardDetail> details = new ArrayList<>(); - for (int rowIdx = section[0]; rowIdx <= section[1]; rowIdx++) { - Row row = sheet.getRow(rowIdx); - if (row == null || isEmptyRow(row)) { - continue; - } - - // 纭繚绗竴鍒楁槸搴忓彿锛堟暟瀛楋級 - Cell seqCell = row.getCell(0); - if (seqCell == null || seqCell.getCellType() != CellType.NUMERIC) { - continue; - } - - // 鍒涘缓椤圭洰璇︽儏 - EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail(); - detail.setStandardId(standard.getId()); - detail.setItemName(getCellStringValue(row.getCell(1))); - detail.setItemCategory(itemCategory); - - // 鏍规嵁椤圭洰绫诲瀷璁剧疆闇�姹傚瓧娈� - if ("DAY_INSPECTION".equals(itemCategory)) { - detail.setItemDemand(getCellStringValue(row.getCell(2))); - } else if ("WEEK_INSPECTION".equals(itemCategory)) { - detail.setItemDemand(getCellStringValue(row.getCell(2))); - } - - details.add(detail); - } - - return details; - } - - /** - * 鏌ユ壘琛ㄦ牸鍖哄煙 + * 浣跨敤姝e垯鎻愬彇瀛楁 */ - private int[] findTableSection(Sheet sheet, String primaryHeader, String secondaryHeader) { - for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) { - Row row = sheet.getRow(rowIdx); - if (row == null) continue; - - if (isHeaderRow(row, primaryHeader, secondaryHeader)) { - int startRow = rowIdx + 1; - int endRow = findDataEnd(sheet, startRow); - return new int[]{startRow, endRow}; - } - } - return null; - } - - /** - * 妫�鏌ユ槸鍚︿负琛ㄥご琛� - */ - private boolean isHeaderRow(Row row, String header1, String header2) { - boolean foundHeader1 = false; - boolean foundHeader2 = false; - - for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { - Cell cell = row.getCell(colIdx); - if (cell == null) continue; - - String cellValue = getCellStringValue(cell); - if (cellValue.contains(header1)) foundHeader1 = true; - if (cellValue.contains(header2)) foundHeader2 = true; - } - - return foundHeader1 && foundHeader2; - } - - /** - * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆 - */ - private int findDataEnd(Sheet sheet, int startRow) { - for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { - Row row = sheet.getRow(rowIdx); - if (row == null) return rowIdx - 1; - - // 妫�鏌ユ槸鍚︾粨鏉熸爣蹇楄锛堝绛惧瓧琛岋級 - if (isSignatureRow(row)) { - return rowIdx - 1; - } - - // 妫�鏌ユ槸鍚︽柊鐨勮〃澶村紑濮� - if (isNewHeaderStart(row)) { - return rowIdx - 1; - } - } - return sheet.getLastRowNum(); - } - - /** - * 璇嗗埆绛惧瓧琛岀壒寰� - */ - private boolean isSignatureRow(Row row) { - for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { - Cell cell = row.getCell(colIdx); - if (cell == null) continue; - - String value = getCellStringValue(cell); - if (value.contains("绛惧瓧") || value.contains("璐d换浜�") || - value.contains("鎵ц") || value.contains("纭")) { - return true; - } - } - return false; - } - - /** - * 璇嗗埆鏂拌〃澶村紑濮� - */ - private boolean isNewHeaderStart(Row row) { - for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { - Cell cell = row.getCell(colIdx); - if (cell == null) continue; - - String value = getCellStringValue(cell); - if ("搴忓彿".equals(value) || "鐐规椤圭洰".equals(value) || "鍛ㄤ繚鍏婚」鐩�".equals(value)) { - return true; - } - } - return false; - } - - /** - * 妫�鏌ヨ鏄惁涓虹┖ - */ - private boolean isEmptyRow(Row row) { - if (row == null) return true; - for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { - Cell cell = row.getCell(colIdx); - if (cell != null && cell.getCellType() != CellType.BLANK) { - String value = getCellStringValue(cell); - if (StringUtils.isNotBlank(value)) { - return false; - } - } - } - return true; - } - - /** - * 浣跨敤姝e垯鎻愬彇瀛楁 - */ private String extractField(String text, String regex) { if (StringUtils.isBlank(text)) return ""; Pattern pattern = Pattern.compile(regex); @@ -895,10 +738,139 @@ } /** - * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊� + * 鎻愬彇姣忔棩鐐规椤圭洰 + */ + private List<EamMaintenanceStandardDetail> extractDailyItems(Sheet sheet, EamMaintenanceStandard standard, Map<Integer, String> rowErrors) { + // 浣跨敤澶氬叧閿瘝鍖归厤 + String[] primaryHeaders = {"鐐规椤圭洰", "鏃ュ父鐐规", "姣忔棩妫�鏌�"}; + String[] secondaryHeaders = {"瀹屾垚鏁版嵁/瑕佹眰", "妫�鏌ユ爣鍑�", "瑕佹眰"}; + return extractItems(sheet, standard, primaryHeaders, secondaryHeaders, "DAY_INSPECTION", rowErrors); + } + + /** + * 鎻愬彇鍛ㄤ繚鍏婚」鐩� + */ + private List<EamMaintenanceStandardDetail> extractWeeklyItems(Sheet sheet, EamMaintenanceStandard standard, Map<Integer, String> rowErrors) { + // 浣跨敤澶氬叧閿瘝鍖归厤 + String[] primaryHeaders = {"鍛ㄤ繚鍏婚」鐩�", "鍛ㄤ繚鍏�", "姣忓懆淇濆吇"}; + String[] secondaryHeaders = {"妫�鏌ユ爣鍑�", "淇濆吇瑕佹眰", "鏍囧噯"}; + return extractItems(sheet, standard, primaryHeaders, secondaryHeaders, "WEEK_INSPECTION", rowErrors); + } + + /** + * 鏍稿績鏀硅繘锛氫紭鍖栬〃鏍煎尯鍩熻瘑鍒拰鏁版嵁鎻愬彇 */ + private List<EamMaintenanceStandardDetail> extractItems(Sheet sheet, + EamMaintenanceStandard standard, + String[] primaryHeaders, + String[] secondaryHeaders, + String itemCategory, + Map<Integer, String> rowErrors) { + + // 1. 瀹氫綅琛ㄦ牸鍖哄煙锛堢簿纭尮閰嶈〃澶达級 + int startRow = findHeaderRow(sheet, primaryHeaders, secondaryHeaders); + if (startRow == -1) { + rowErrors.put(-1, "鏈壘鍒�" + Arrays.toString(primaryHeaders) + "琛ㄥご鍖哄煙"); + return Collections.emptyList(); + } + + int endRow = findDataEnd(sheet, startRow + 1, "鍛ㄤ繚鍏婚」鐩�"); + + // 鎻愬彇鏃ュ織锛堝疄闄呬娇鐢ㄦ椂鍙互鍘绘帀锛� + System.out.println("鎻愬彇鍖哄煙: " + (startRow + 1) + "琛屽埌" + (endRow + 1) + "琛�"); + + // 2. 鎻愬彇鏁版嵁琛� + List<EamMaintenanceStandardDetail> details = new ArrayList<>(); + for (int rowIdx = startRow + 1; rowIdx <= endRow; rowIdx++) { + Row row = sheet.getRow(rowIdx); + if (row == null) continue; + + try { + // 搴忓彿鍒楀鐞� + Cell seqCell = row.getCell(0); + if (seqCell == null || seqCell.getCellType() == CellType.BLANK) { + continue; + } + + // 鑾峰彇搴忓彿鍊硷紙鏀寔鏁板瓧鍜屾枃鏈牸寮忥級 + int seqValue = 0; + try { + if (seqCell.getCellType() == CellType.NUMERIC) { + seqValue = (int) seqCell.getNumericCellValue(); + } else if (seqCell.getCellType() == CellType.STRING) { + seqValue = Integer.parseInt(seqCell.getStringCellValue().trim()); + } + } catch (NumberFormatException e) { + rowErrors.put(rowIdx + 1, "搴忓彿鏍煎紡閿欒"); + continue; + } + + // 椤圭洰鍚嶇О鍒楋紙绗簩鍒楋級 + Cell nameCell = row.getCell(1); + if (nameCell == null || nameCell.getCellType() == CellType.BLANK) { + continue; + } + String itemName = getCellStringValue(nameCell).trim(); + + // 瑕佹眰/鏍囧噯鍒楋紙绗笁鍒楋級 + String demand = ""; + if (row.getLastCellNum() >= 3) { + Cell demandCell = row.getCell(2); + if (demandCell != null) { + demand = getCellStringValue(demandCell).trim(); + } + } + + // 鍒涘缓璇︽儏瀵硅薄 + EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail(); + detail.setStandardId(standard.getId()); + detail.setItemCode(seqValue); + detail.setItemName(itemName); + detail.setItemDemand(demand); + detail.setItemCategory(itemCategory); + details.add(detail); + + } catch (Exception e) { + rowErrors.put(rowIdx + 1, "瑙f瀽閿欒: " + e.getMessage()); + } + } + return details; + } + + /** + * 鑾峰彇琛屼腑鎵�鏈夊崟鍏冩牸鐨勫瓧绗︿覆鍊� + */ + private List<String> getRowStringValues(Row row) { + List<String> values = new ArrayList<>(); + if (row == null) return values; + + for (int cellIdx = 0; cellIdx < row.getLastCellNum(); cellIdx++) { + Cell cell = row.getCell(cellIdx); + if (cell != null) { + values.add(getCellStringValue(cell)); + } else { + values.add(""); // 瀵逛簬绌哄崟鍏冩牸娣诲姞绌哄瓧绗︿覆 + } + } + return values; + } + + /** + * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊硷紙澧炲己鍏紡澶勭悊锛� + */ private String getCellStringValue(Cell cell) { - if (cell == null) return ""; + if (cell == null) { + return ""; + } + // 淇濇寔涓嶅彉锛屼絾娣诲姞鏁板瓧绫诲瀷澶勭悊 + if (cell.getCellType() == CellType.NUMERIC) { + // 鏁存暟澶勭悊 + double num = cell.getNumericCellValue(); + if (num == (int) num) { + return String.valueOf((int) num); + } + return String.valueOf(num); + } switch (cell.getCellType()) { case STRING: return cell.getStringCellValue().trim(); @@ -910,37 +882,196 @@ case BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case FORMULA: - return handleFormulaCell(cell); + return getFormulaCellValue(cell); default: return ""; } } /** - * 澶勭悊鍏紡鍗曞厓鏍� + * 绮剧‘鏌ユ壘琛ㄥご琛� */ - private String handleFormulaCell(Cell cell) { + private int findHeaderRow(Sheet sheet, String[] primaryHeaders, String[] secondaryHeaders) { + for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) { + Row row = sheet.getRow(rowIdx); + if (row == null) continue; + + String rowText = getRowStringValues(row).stream().collect(Collectors.joining()); + + // 妫�鏌ヤ富鏍囬鍜屽壇鏍囬 + boolean hasPrimary = false; + boolean hasSecondary = false; + + for (String header : primaryHeaders) { + if (rowText.contains(header)) { + hasPrimary = true; + break; + } + } + + for (String header : secondaryHeaders) { + if (rowText.contains(header)) { + hasSecondary = true; + break; + } + } + + if (hasPrimary && hasSecondary) { + return rowIdx; + } + } + return -1; + } + + /** + * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆锛堟牴鎹偍鐨凟xcel缁撴瀯浼樺寲锛� + */ + private int findDataEnd(Sheet sheet, int startRow, String nextSectionKeyword) { + int consecutiveEmptyRows = 0; + final int MAX_EMPTY_ROWS = 3; + + for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { + Row row = sheet.getRow(rowIdx); + + // 鍏抽敭鏀硅繘1锛氱┖琛屽鐞� + if (isEssentiallyEmpty(row)) { + consecutiveEmptyRows++; + if (consecutiveEmptyRows >= MAX_EMPTY_ROWS) { + return rowIdx - consecutiveEmptyRows; + } + continue; + } else { + consecutiveEmptyRows = 0; + } + + // 鍏抽敭鏀硅繘2锛氱粨鏉熸爣璁版娴� + String rowText = getRowStringValues(row).stream().collect(Collectors.joining()); + + // 鏍规嵁鎮ㄧ殑Excel缁撴瀯锛岀瀛楄鏈夌壒瀹氭牸寮� + if (rowText.contains("缁存姢璐d换浜虹瀛�")) { + return rowIdx - 1; + } + + // 妫�娴嬩笅涓�涓尯鍩熺殑寮�濮嬶紙濡傚懆淇濆吇椤圭洰锛� + if (StringUtils.isNotBlank(nextSectionKeyword) && + rowText.contains(nextSectionKeyword)) { + return rowIdx - 1; + } + } + return sheet.getLastRowNum(); + } + + /** + * 鍒ゆ柇鏉′欢锛氬墠涓ゅ垪涓虹┖鍗宠涓虹┖琛� + */ + private boolean isEssentiallyEmpty(Row row) { + if (row == null) return true; + + // 妫�鏌ュ簭鍙峰垪 + Cell indexCell = row.getCell(0); + if (indexCell != null && indexCell.getCellType() != CellType.BLANK) { + return false; + } + + // 妫�鏌ラ」鐩悕绉板垪 + Cell nameCell = row.getCell(1); + if (nameCell != null && nameCell.getCellType() != CellType.BLANK) { + return false; + } + + return true; + } + + /** + * 鑾峰彇鍏紡鍗曞厓鏍煎�� + */ + private String getFormulaCellValue(Cell cell) { try { - FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + Workbook workbook = cell.getSheet().getWorkbook(); + FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); CellValue cellValue = evaluator.evaluate(cell); - - if (cellValue == null) return ""; - + if (cellValue == null) { + return ""; + } switch (cellValue.getCellType()) { - case STRING: return cellValue.getStringValue(); - case NUMERIC: return String.valueOf((int) cellValue.getNumberValue()); - case BOOLEAN: return String.valueOf(cellValue.getBooleanValue()); - default: return ""; + case STRING: + return cellValue.getStringValue(); + case NUMERIC: + return String.valueOf((int) cellValue.getNumberValue()); + case BOOLEAN: + return String.valueOf(cellValue.getBooleanValue()); + default: + return ""; } } catch (Exception e) { + log.warn("瑙f瀽鍏紡鍗曞厓鏍煎け璐�"); return ""; } + } + + + private int findDataEnd(Sheet sheet, int startRow) { + int consecutiveEmptyRows = 0; + final int MAX_EMPTY_ROWS = 2; + boolean foundData = false; + + for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { + Row row = sheet.getRow(rowIdx); + + // 鍏抽敭浼樺寲1锛氬厛妫�鏌ユ槸鍚︿负绌鸿 + if (isEmptyRow(row)) { + consecutiveEmptyRows++; + if (consecutiveEmptyRows >= MAX_EMPTY_ROWS) { + return foundData ? rowIdx - consecutiveEmptyRows : startRow; + } + continue; + } else { + consecutiveEmptyRows = 0; + } + + // 鍏抽敭浼樺寲2锛氫弗鏍奸檺瀹氱粨鏉熸爣璁扮殑璇嗗埆鏉′欢 + if (isStrongEndMarker(row)) { + return foundData ? rowIdx - 1 : startRow; + } + + // 鍏抽敭浼樺寲3锛氭爣璁板凡鎵惧埌鏈夋晥鏁版嵁 + foundData = true; + } + return sheet.getLastRowNum(); + } + + // 澧炲己鐗堢粨鏉熸爣璁拌瘑鍒� + private boolean isStrongEndMarker(Row row) { + String rowText = String.join("", getRowStringValues(row)).toLowerCase(); + + return + // 绮剧‘鍖归厤绛惧瓧鐗瑰緛锛堝嚭鐜板湪琛岄锛� + (rowText.startsWith("缁存姢璐d换浜虹瀛�") || + rowText.startsWith("鎵ц浜虹瀛�")) || + // 绮剧‘鍖归厤鏂版澘鍧楁爣棰� + rowText.matches("^\\s*鍛ㄤ繚鍏婚」鐩甛\s*$") || + rowText.contains("骞村害淇濆吇椤圭洰"); + } + + // 绌鸿妫�娴嬩紭鍖栵紙鍏佽閮ㄥ垎鍒椾负绌猴級 + private boolean isEmptyRow(Row row) { + if (row == null) return true; + // 鍙鏌ュ墠3鍒楋紙搴忓彿鍒�+椤圭洰鍚�+瑕佹眰锛� + for (int cellIdx = 0; cellIdx < Math.min(3, row.getLastCellNum()); cellIdx++) { + Cell cell = row.getCell(cellIdx); + if (cell != null && cell.getCellType() != CellType.BLANK) { + return false; + } + } + return true; } /*瀵煎叆鐐规鏂囦欢Excel--------------------------缁撴潫*/ /*瀵煎叆浜屼繚涓変繚鏂囦欢Excel--------------------------寮�濮�*/ + /** * 缁熶竴淇濆吇瑙勮寖瀵煎叆鍏ュ彛 + * * @param file 涓婁紶鏂囦欢 * @param type 淇濆吇绫诲瀷 (SECOND/THIRD) * @return 瀵煎叆缁撴灉锛堝寘鍚垚鍔�/澶辫触淇℃伅锛� @@ -951,46 +1082,102 @@ 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 + ": 鏂囨。涓湭鎵惧埌琛ㄦ牸"); } - XWPFTable table = doc.getTables().get(0); - - // 鏂囨。绫诲瀷鏍¢獙 - 闃叉浜屼繚浼犲叆涓変繚鎴栧弽涔� - if (isWrongDocumentType(table, type)) { - return Result.error(fileName + ": 鏂囨。绫诲瀷涓嶅尮閰� - " + - ("SECOND".equals(type) ? "璇峰鍏ヤ簩绾т繚鍏绘枃妗�" : "璇峰鍏ヤ笁绾т繚鍏绘枃妗�")); + // 鍩虹楠岃瘉 + if (doc.getTables().isEmpty()) { + return Result.error(fileName + ": 鏂囨。涓湭鎵惧埌琛ㄦ牸"); } - EamMaintenanceStandard standard = extractDeviceInfo(table); + List<XWPFTable> tables = doc.getTables(); + EamMaintenanceStandard standard = null; + List<EamMaintenanceStandardDetail> items = new ArrayList<>(); + String standardId = null; + + // 1. 澶勭悊鎵�鏈夎〃鏍� + for (int i = 0; i < tables.size(); i++) { + XWPFTable table = tables.get(i); + + if (i == 0) { // 绗竴椤佃〃鏍� + // 楠岃瘉璁惧淇℃伅琛ㄦ牸 + if (isWrongDocumentType(table, type)) { + return Result.error(fileName + ": 鏂囨。绫诲瀷涓嶅尮閰� - " + + ("SECOND".equals(type) ? "璇峰鍏ヤ簩绾т繚鍏绘枃妗�" : "璇峰鍏ヤ笁绾т繚鍏绘枃妗�")); + } + + // 鎻愬彇璁惧淇℃伅 + standard = extractDeviceInfo(table, type); + if (standard == null) { + return Result.error(fileName + ": 璁惧淇℃伅鎻愬彇澶辫触"); + } + + // 閰嶇疆绫诲瀷鐩稿叧鍙傛暟 + configureStandard(standard, type, file); + EamMaintenanceStandard exist = checkDuplicate(standard.getEquipmentId(), standard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.ABOLISH.name()); + if (exist != null) { + return Result.error(fileName + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞"); + } + standard.setStandardName(documentTitle); + eamMaintenanceStandardMapper.insert(standard); + standardId = standard.getId(); + + // 鎻愬彇绗竴椤电殑淇濆吇椤圭洰 + if ("SECOND".equals(type)) { + items.addAll(extractSecondMaintenanceItems(table, standardId, true)); + } else if ("THIRD".equals(type)) { + items.addAll(extractThirdMaintenanceItems(table, standardId, true)); + } + + } else { // 鍚庣画椤甸潰 + // 鎻愬彇鍚庣画椤甸潰鐨勪繚鍏婚」鐩� + if ("SECOND".equals(type)) { + items.addAll(extractSecondMaintenanceItems(table, standardId, false)); + } else if ("THIRD".equals(type)) { + items.addAll(extractThirdMaintenanceItems(table, standardId, false)); + } + } + } + + // 楠岃瘉璁惧淇℃伅鎻愬彇 if (standard == null) { return Result.error(fileName + ": 璁惧淇℃伅鎻愬彇澶辫触"); } - // 閰嶇疆绫诲瀷鐩稿叧鍙傛暟 - configureStandard(standard, type, file); - eamMaintenanceStandardMapper.insert(standard); - String standardId = standard.getId(); + // 2. 鍚庡鐞嗭細鏍规嵁涓嶅悓绫诲瀷杩涜澶勭悊 + processItemsAfterExtraction(items, type); - // 鎻愬彇淇濆吇椤圭洰 - 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); - } - - // 椤圭洰楠岃瘉 + // 3. 椤圭洰楠岃瘉 if (items.isEmpty()) { return Result.error(fileName + ": 鏈彁鍙栧埌浠讳綍淇濆吇椤圭洰"); } - // 淇濆瓨椤圭洰 + // 4. 淇濆瓨椤圭洰 eamMaintenanceStandardDetailService.saveBatch(items); + + + SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type"); + + if (sysParams != null) { + if (sysParams.getSettingValue().equals("1")) { + standard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); + eamMaintenanceStandardMapper.updateById(standard); + } + } else { + return Result.error("鏈壘鍒颁繚鍏绘祦绋嬪鍏ョ浉鍏抽厤缃�,璇疯仈绯荤鐞嗗憳"); + } return Result.ok(fileName + ": 瀵煎叆鎴愬姛, 椤圭洰鏁�: " + items.size()); @@ -1002,8 +1189,198 @@ } /** + * 鍚庡鐞嗘柟娉曪細鏍规嵁涓嶅悓绫诲瀷杩涜澶勭悊 + */ + 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++; + } + } + } + + /** + * 鎻愬彇浜岀骇淇濆吇椤圭洰锛堝尯鍒嗙涓�椤靛拰鍚庣画椤甸潰锛� + */ + private List<EamMaintenanceStandardDetail> extractSecondMaintenanceItems( + XWPFTable table, String standardId, boolean isFirstTable) { + + List<EamMaintenanceStandardDetail> items = new ArrayList<>(); + String currentCategory = null; + int startRow = 0; + + // 瀵逛簬绗竴椤佃〃鏍硷紝璺宠繃鍓嶄袱琛岋紙璁惧淇℃伅琛岋級 + if (isFirstTable && table.getNumberOfRows() > 2) { + startRow = 2; // 浠庣涓夎寮�濮嬫槸淇濆吇鍐呭 + } + + for (int i = startRow; i < table.getNumberOfRows(); i++) { + XWPFTableRow row = table.getRow(i); + if (row == null) continue; + + // 妫�鏌ユ槸鍚︽槸鏍囬琛岋紙缁翠慨浜哄憳淇濆吇鍐呭鎴栨搷浣滀汉鍛樹繚鍏诲唴瀹癸級 + String firstCell = getCellText(row.getCell(0)); + // 澶勭悊绌鸿鍚庣殑閮ㄤ綅缁ф壙 + if (firstCell.contains(REPAIR_TITLE)) { + currentCategory = "REPAIRER_MAINTENANCE"; + } else if (firstCell.contains(OPERATOR_TITLE)) { + currentCategory = "OPERATOR_MAINTENANCE"; + } + + // 澶勭悊鏅�氶」鐩 + if (currentCategory != null && isValidItemRow(row)) { + EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail(); + item.setItemCategory(currentCategory); + item.setStandardId(standardId); + + // 鎻愬彇搴忓彿锛堢浜屽垪锛� + if (row.getTableCells().size() > 1) { + String seqText = getCellText(row.getCell(1)); + try { + if (!seqText.equals("搴忓彿")) { + item.setItemCode(Integer.parseInt(seqText.trim())); + } + } catch (NumberFormatException e) { + // 蹇界暐搴忓彿瑙f瀽閿欒 + } + } + + // 鎻愬彇鍐呭锛堢涓夊垪锛� + if (row.getTableCells().size() > 2) { + String seqText = getCellText(row.getCell(2)); + item.setItemName(seqText); + } + + items.add(item); + } + } + return items; + } + + /** + * 鎻愬彇涓夌骇淇濆吇椤圭洰锛堣В鍐宠法椤电┖琛岄棶棰橈級 + */ + private List<EamMaintenanceStandardDetail> extractThirdMaintenanceItems( + XWPFTable table, String standardId, boolean isFirstTable) { + + List<EamMaintenanceStandardDetail> items = new ArrayList<>(); + String currentPart = ""; + int startRow = 0; + + // 瀵逛簬绗竴椤佃〃鏍硷紝璺宠繃鍓嶄袱琛岋紙璁惧淇℃伅琛岋級 + if (isFirstTable && table.getNumberOfRows() > 2) { + startRow = 2; // 浠庣涓夎寮�濮嬫槸淇濆吇鍐呭 + } + + for (int i = startRow; i < table.getNumberOfRows(); i++) { + XWPFTableRow row = table.getRow(i); + if (row == null) continue; // 纭繚琛屽璞′笉涓虹┖ + + // 妫�鏌ユ槸鍚︽槸绌鸿锛堝寘鍚墍鏈夊崟鍏冩牸閮戒负绌虹殑鎯呭喌锛� + if (isRowEmpty(row)) { + // 绌鸿澶勭悊锛氫繚鐣欏綋鍓嶄綅缃絾涓嶅垱寤洪」鐩� + continue; + } + + // 鍒涘缓淇濆吇椤圭洰 + EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail(); + item.setStandardId(standardId); + int colCount = row.getTableCells().size(); + + // 澶勭悊閮ㄤ綅鍒楋紙绗竴鍒楋級 + if (colCount > 0) { + String firstCell = getCellText(row.getCell(0)).trim(); + + // 鍏抽敭鏀硅繘锛氭纭鐞嗙┖琛屽悗鐨勯儴浣嶇户鎵� + if (!firstCell.isEmpty() && !firstCell.equals("淇濆吇閮ㄤ綅")) { + // 鏇存柊褰撳墠閮ㄤ綅 + currentPart = firstCell; + } + item.setItemPart(currentPart); + } else { + // 濡傛灉娌℃湁鍗曞厓鏍硷紝浣跨敤褰撳墠閮ㄤ綅 + item.setItemPart(currentPart); + } + + // 鏍规嵁鍒楁暟鎻愬彇鍐呭锛堣�冭檻鍚堝苟鍗曞厓鏍兼儏鍐碉級 + List<String> cellContents = new ArrayList<>(); + for (int j = 0; j < colCount; j++) { + XWPFTableCell cell = row.getCell(j); + String text = getCellText(cell).trim(); + + // 鐗规畩澶勭悊锛氱浜岄〉绗竴琛屽彲鑳芥槸绌鸿鍚庣殑鍐呭 + if (j == 0 && !text.isEmpty() && !text.equals(currentPart)) { + // 濡傛灉涓嶆槸閮ㄤ綅鍒楋紝鍒欐坊鍔犱负鍐呭 + cellContents.add(text); + } else if (j > 0) { + // 鍏朵粬鍒椾綔涓哄唴瀹� + cellContents.add(text); + } + } + + // 鏅鸿兘瑙f瀽鍗曞厓鏍煎唴瀹� + if (cellContents.size() >= 2) { + // 榛樿澶勭悊鏂瑰紡锛氭渶鍚庝袱涓綔涓哄唴瀹瑰拰鏍囧噯 + item.setItemName(cellContents.get(cellContents.size() - 2)); + item.setItemDemand(cellContents.get(cellContents.size() - 1)); + } else if (cellContents.size() == 1) { + // 鍗曞垪妯″紡锛氳涓哄唴瀹� + item.setItemName(cellContents.get(0)); + } else if (!isRowEmpty(row)) { + // 鐗规畩澶勭悊锛氳闈炵┖浣嗘病鏈夋彁鍙栧埌鍐呭锛堝彲鑳芥槸澶嶆潅鍚堝苟鍗曞厓鏍硷級 + // 灏濊瘯鎻愬彇鏁磋鏂囨湰浣滀负鍐呭 + StringBuilder content = new StringBuilder(); + for (XWPFTableCell cell : row.getTableCells()) { + content.append(getCellText(cell).trim()).append(" "); + } + item.setItemName(content.toString().trim()); + } + + items.add(item); + } + return items; + } + + /** + * 浼樺寲鍚庣殑绌鸿妫�娴嬶紙瑙e喅璺ㄩ〉绌鸿闂锛� + */ + 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) { boolean hasRepairTitle = false; boolean hasOperatorTitle = false; @@ -1050,7 +1427,7 @@ /** * 鎻愬彇璁惧鍩烘湰淇℃伅 */ - private EamMaintenanceStandard extractDeviceInfo(XWPFTable table) { + private EamMaintenanceStandard extractDeviceInfo(XWPFTable table, String type) { if (table.getNumberOfRows() < 2) return null; // 鎻愬彇鍓嶄袱琛屾暟鎹� @@ -1065,29 +1442,22 @@ 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 { + 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 boolean isNotBlank(String str) { - return str != null && !str.trim().isEmpty(); - } /** * 琛ㄦ牸琛屾暟鎹В鏋� @@ -1145,7 +1515,7 @@ standard.setStandardName(filename) .setInitialDate(new Date()) .setStandardStatus(MaintenanceStandardStatusEnum.START.name()) - .setStandardVersion("v1.0") + .setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1) .setDelFlag(0) .setStandardCode(businessCodeRuleService.generateBusinessCodeSeq( BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE @@ -1171,161 +1541,6 @@ } /** - * 鎻愬彇浜岀骇淇濆吇椤圭洰 - */ - 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) { - // 蹇界暐搴忓彿瑙f瀽閿欒 - } - } - - 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(); - // 涓夌骇淇濆吇涓嶉渶瑕佺被鍨嬶紝涓嶈缃甶temCategory - 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) { @@ -1348,48 +1563,12 @@ } /** - * 鍐呭娓呯悊 - */ - 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--------------------------缁撴潫*/ -- Gitblit v1.9.3