From 457fa2cb4cc7c78f1caace6ef34207ff785144f9 Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期四, 17 七月 2025 17:14:00 +0800 Subject: [PATCH] art: 技术状态鉴定申请-工单生成 --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java | 558 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 513 insertions(+), 45 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java index 2f52af9..f6932c1 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java @@ -7,31 +7,42 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableRow; import org.apache.shiro.SecurityUtils; +import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.FileUtil; import org.jeecg.common.util.SimpleVersionGenerateUtil; -import org.jeecg.modules.system.entity.BaseFactory; -import org.jeecg.modules.system.entity.BaseFactoryUser; -import org.jeecg.modules.system.service.IBaseFactoryService; -import org.jeecg.modules.system.service.IBaseFactoryUserService; +import org.jeecg.modules.eam.constant.BusinessCodeConst; import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationCheckCategoryEnum; -import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationStandardEnum; +import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationStandardStatusEnum; +import org.jeecg.modules.eam.entity.EamEquipment; import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard; import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandardDetail; import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationStandardMapper; import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest; +import org.jeecg.modules.eam.service.IEamEquipmentService; import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardDetailService; import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService; +import org.jeecg.modules.system.entity.BaseFactory; +import org.jeecg.modules.system.entity.BaseFactoryUser; +import org.jeecg.modules.system.service.IBaseFactoryService; +import org.jeecg.modules.system.service.IBaseFactoryUserService; +import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -41,6 +52,7 @@ * @Version: V1.0 */ @Service +@Slf4j public class EamTechnicalStatusEvaluationStandardServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationStandardMapper, EamTechnicalStatusEvaluationStandard> implements IEamTechnicalStatusEvaluationStandardService { @Autowired @@ -49,6 +61,10 @@ private IBaseFactoryService baseFactoryService; @Autowired private IEamTechnicalStatusEvaluationStandardDetailService standardDetailService; + @Autowired + private IEamEquipmentService equipmentService; + @Autowired + private ISysBusinessCodeRuleService businessCodeRuleService; @Override public IPage<EamTechnicalStatusEvaluationStandard> queryPageList(Page<EamTechnicalStatusEvaluationStandard> page, EamTechnicalStatusEvaluationStandard query) { @@ -68,9 +84,9 @@ 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_org_code", factoryCode); + Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); + Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); + queryWrapper.in("e.factory_org_code", factoryCodeList); } else { return page; } @@ -89,9 +105,16 @@ queryWrapper.eq("ems.equipment_id", query.getEquipmentId()); } - //淇濆吇鍒嗙被 + //瑙勮寖鐘舵�� if (StringUtils.isNotBlank(query.getStandardStatus())) { queryWrapper.eq("ems.standard_status", query.getStandardStatus()); + } + + //璁惧缂栫爜 + if (StringUtils.isNotBlank(query.getKeyword())) { + queryWrapper.and(wrapper -> wrapper.like("e.equipment_name", query.getKeyword()) + .or() + .like("e.equipment_code", query.getKeyword())); } } queryWrapper.orderByDesc("ems.create_time"); @@ -101,13 +124,13 @@ @Override @Transactional(rollbackFor = Exception.class) public boolean addEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) { - if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { + if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫� throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒"); } EamTechnicalStatusEvaluationStandard entity = new EamTechnicalStatusEvaluationStandard(); BeanUtils.copyProperties(request, entity); - entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name()); + entity.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.WAIT_SUBMIT.name()); //鐗堟湰閫掑 entity.setStandardVersion(SimpleVersionGenerateUtil.getInitVersion()); //璁惧澶勭悊 @@ -116,36 +139,36 @@ entity.setDelFlag(CommonConstant.DEL_FLAG_0); //閲嶅鎬ф牎楠� EamTechnicalStatusEvaluationStandard exist = checkDuplicate(entity.getEquipmentId(), null); - if(exist != null){ + if (exist != null) { throw new JeecgBootException("瑙勮寖宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�"); } this.getBaseMapper().insert(entity); //澶勭悊鏄庣粏鏁版嵁 - if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { + if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { request.getTableDetailList().forEach(tableDetail -> { tableDetail.setStandardId(entity.getId()); }); //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨 - if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { //淇濆瓨鍏朵粬鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { //淇濆瓨瀹夊叏瑁呯疆鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { //淇濆瓨绮惧害妫�楠屽垎绫� List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); @@ -160,13 +183,13 @@ queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getEquipmentId, equipmentId); queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getDelFlag, CommonConstant.DEL_FLAG_0); //寰呮彁浜ゃ�佸惎鐢ㄧ姸鎬� - queryWrapper.in(EamTechnicalStatusEvaluationStandard::getStandardStatus, Arrays.asList(TechnicalStatusEvaluationStandardEnum.ENABLE.name(), TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name())); + queryWrapper.in(EamTechnicalStatusEvaluationStandard::getStandardStatus, Arrays.asList(TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name(), TechnicalStatusEvaluationStandardStatusEnum.WAIT_SUBMIT.name())); queryWrapper.orderByDesc(EamTechnicalStatusEvaluationStandard::getStandardVersion); - if(StringUtils.isNotBlank(id)){ + if (StringUtils.isNotBlank(id)) { queryWrapper.ne(EamTechnicalStatusEvaluationStandard::getId, id); } List<EamTechnicalStatusEvaluationStandard> list = this.getBaseMapper().selectList(queryWrapper); - if(CollectionUtil.isEmpty(list)) { + if (CollectionUtil.isEmpty(list)) { return null; } return list.get(0); @@ -175,12 +198,12 @@ @Override @Transactional(rollbackFor = Exception.class) public boolean editEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) { - if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { + if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫� throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒"); } EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId()); - if(entity == null){ + if (entity == null) { throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�"); } entity.setStandardName(request.getStandardName()); @@ -191,33 +214,33 @@ entity.setRemark(request.getRemark()); this.getBaseMapper().updateById(entity); //澶勭悊璇︽儏 - if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { + if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { //鍏堝垹闄ゆ鏌ラ」 standardDetailService.removeByStandardId(entity.getId()); request.getTableDetailList().forEach(tableDetail -> { tableDetail.setStandardId(entity.getId()); }); //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨 - if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { //淇濆瓨鍏朵粬鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { //淇濆瓨瀹夊叏瑁呯疆鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { //淇濆瓨绮惧害妫�楠屽垎绫� List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); @@ -229,12 +252,12 @@ @Override @Transactional(rollbackFor = Exception.class) public boolean upgrade(EamTechnicalStatusEvaluationStandardRequest request) { - if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { + if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) { //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫� throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒"); } EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId()); - if(entity == null){ + if (entity == null) { throw new JeecgBootException("鍗囩増鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�"); } @@ -243,7 +266,7 @@ newEntity.setStandardCode(request.getStandardCode()); newEntity.setStandardName(request.getStandardName()); newEntity.setEvaluationPeriod(request.getEvaluationPeriod()); - newEntity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.ENABLE.name()); + newEntity.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name()); //鐗堟湰閫掑 newEntity.setStandardVersion(SimpleVersionGenerateUtil.addVersion(entity.getStandardVersion())); //璁惧澶勭悊 @@ -256,12 +279,12 @@ newEntity.setRemark(request.getRemark()); //閲嶅鎬ф牎楠� EamTechnicalStatusEvaluationStandard exist = checkDuplicate(newEntity.getEquipmentId(), entity.getId()); - if(exist != null){ + if (exist != null) { throw new JeecgBootException("閴村畾瑙勮寖宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�"); } this.getBaseMapper().insert(newEntity); //澶勭悊鏄庣粏鏁版嵁 - if(CollectionUtil.isNotEmpty(request.getTableDetailList())) { + if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { request.getTableDetailList().forEach(tableDetail -> { tableDetail.setId(null); tableDetail.setCreateBy(null); @@ -271,34 +294,479 @@ tableDetail.setStandardId(newEntity.getId()); }); //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨 - if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) { //淇濆瓨鍏朵粬鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) { //淇濆瓨瀹夊叏瑁呯疆鍒嗙被 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } - if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { + if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) { //淇濆瓨绮惧害妫�楠屽垎绫� List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(collect)) { + if (CollectionUtils.isEmpty(collect)) { throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒"); } standardDetailService.saveBatch(collect); } } //绂佺敤鍘熸潵鐨勭増鏈� - entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.DISABLE.name()); + entity.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.DISABLE.name()); this.getBaseMapper().updateById(entity); return true; } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> importSafetyEquipmentCheck(MultipartFile file) { + String fileName = file.getOriginalFilename(); + if (StringUtils.isBlank(fileName)) { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + String fileSuffix = FileUtil.getFileSuffix(fileName); + //鍙敮鎸� .docx 鐨剋ord鏂囨。 + if ("docx".equals(fileSuffix)) { + try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { + List<XWPFParagraph> paragraphs = doc.getParagraphs(); + List<XWPFTable> tables = doc.getTables(); + if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇鏂囦欢鏍囬 + StringBuilder builder = new StringBuilder(); + paragraphs.forEach(paragraph -> { + if (StringUtils.isNotBlank(paragraph.getText())) { + builder.append(paragraph.getText().trim()); + } + }); + if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇璁惧淇℃伅 + EamEquipment equipment = extractEquipmentInfo(tables.get(0)); + //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭� + EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); + if (originalStandard != null && TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { + return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�"); + } + //鑾峰彇妫�鏌ラ」淇℃伅 + List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractSafetyEquipmentCheckItems(tables); + if(CollectionUtil.isEmpty(detailList)){ + return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒"); + } + if(originalStandard != null) { + //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜� + originalStandard.setHasSafetyEquipmentCheck(CommonConstant.STATUS_1); + originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.WAIT_SUBMIT.name()); + super.getBaseMapper().updateById(originalStandard); + detailList.forEach(standardDetail -> { + standardDetail.setStandardId(originalStandard.getId()); + }); + //鍏堝垹闄わ紝鍚庢坊鍔� + standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name()); + //閲嶆柊娣诲姞 + standardDetailService.saveBatch(detailList); + }else { + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); + //鏂板鎶�鏈姸鎬侀壌瀹氳鑼� + EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest(); + request.setEquipmentId(equipment.getId()); + request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_1); + request.setHasOtherCheck(CommonConstant.STATUS_0); + request.setHasPrecisionCheck(CommonConstant.STATUS_0); + request.setStandardCode(codeSeq); + request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�"); + request.setTableDetailList(detailList); + this.addEamTechnicalStatusEvaluationStandard(request); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return Result.error(fileName + ":" + e.getMessage() + "锛�"); + } + } else { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + + return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�"); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> importPrecisionCheck(MultipartFile file) { + String fileName = file.getOriginalFilename(); + if (StringUtils.isBlank(fileName)) { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + String fileSuffix = FileUtil.getFileSuffix(fileName); + //鍙敮鎸� .docx 鐨剋ord鏂囨。 + if ("docx".equals(fileSuffix)) { + try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { + List<XWPFParagraph> paragraphs = doc.getParagraphs(); + List<XWPFTable> tables = doc.getTables(); + if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎璁惧绮惧害妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇鏂囦欢鏍囬 + StringBuilder builder = new StringBuilder(); + paragraphs.forEach(paragraph -> { + if (StringUtils.isNotBlank(paragraph.getText())) { + builder.append(paragraph.getText().trim()); + } + }); + if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎璁惧绮惧害妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇璁惧淇℃伅 + EamEquipment equipment = extractEquipmentInfo(tables.get(0)); + //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭� + EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); + if (originalStandard != null && TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { + return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�"); + } + //鑾峰彇妫�鏌ラ」淇℃伅 + List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractPrecisionCheckItems(tables); + if(CollectionUtil.isEmpty(detailList)){ + return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒"); + } + if(originalStandard != null) { + //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜� + originalStandard.setHasPrecisionCheck(CommonConstant.STATUS_1); + originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.WAIT_SUBMIT.name()); + super.getBaseMapper().updateById(originalStandard); + detailList.forEach(standardDetail -> { + standardDetail.setStandardId(originalStandard.getId()); + }); + //鍏堝垹闄わ紝鍚庢坊鍔� + standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name()); + //閲嶆柊娣诲姞 + standardDetailService.saveBatch(detailList); + }else { + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); + //鏂板鎶�鏈姸鎬侀壌瀹氳鑼� + EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest(); + request.setEquipmentId(equipment.getId()); + request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0); + request.setHasOtherCheck(CommonConstant.STATUS_0); + request.setHasPrecisionCheck(CommonConstant.STATUS_1); + request.setStandardCode(codeSeq); + request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�"); + request.setTableDetailList(detailList); + this.addEamTechnicalStatusEvaluationStandard(request); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return Result.error(fileName + ":" + e.getMessage() + "锛�"); + } + } else { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + + return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�"); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> importOtherCheck(MultipartFile file) { + String fileName = file.getOriginalFilename(); + if (StringUtils.isBlank(fileName)) { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + String fileSuffix = FileUtil.getFileSuffix(fileName); + //鍙敮鎸� .docx 鐨剋ord鏂囨。 + if ("docx".equals(fileSuffix)) { + try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) { + List<XWPFParagraph> paragraphs = doc.getParagraphs(); + List<XWPFTable> tables = doc.getTables(); + if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇鏂囦欢鏍囬 + StringBuilder builder = new StringBuilder(); + paragraphs.forEach(paragraph -> { + if (StringUtils.isNotBlank(paragraph.getText())) { + builder.append(paragraph.getText().trim()); + } + }); + if (checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK)) { + return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎鍏朵粬妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒"); + } + //鑾峰彇璁惧淇℃伅 + EamEquipment equipment = extractEquipmentInfo(tables.get(0)); + //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭� + EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null); + if (originalStandard != null && TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) { + return Result.error(fileName + ":姝よ澶囧凡瀛樺湪鍚敤鐨勮鑼冿紝璇疯繘琛岀紪杈戞垨鍗囩増锛�"); + } + //鑾峰彇妫�鏌ラ」淇℃伅 + List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractOtherCheckItems(tables); + if(CollectionUtil.isEmpty(detailList)){ + return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒"); + } + if(originalStandard != null) { + //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜� + originalStandard.setHasOtherCheck(CommonConstant.STATUS_1); + originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.WAIT_SUBMIT.name()); + super.getBaseMapper().updateById(originalStandard); + detailList.forEach(standardDetail -> { + standardDetail.setStandardId(originalStandard.getId()); + }); + //鍏堝垹闄わ紝鍚庢坊鍔� + standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name()); + //閲嶆柊娣诲姞 + standardDetailService.saveBatch(detailList); + }else { + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE); + //鏂板鎶�鏈姸鎬侀壌瀹氳鑼� + EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest(); + request.setEquipmentId(equipment.getId()); + request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_0); + request.setHasOtherCheck(CommonConstant.STATUS_1); + request.setHasPrecisionCheck(CommonConstant.STATUS_0); + request.setStandardCode(codeSeq); + request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�"); + request.setTableDetailList(detailList); + this.addEamTechnicalStatusEvaluationStandard(request); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return Result.error(fileName + ":" + e.getMessage() + "锛�"); + } + } else { + return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�"); + } + + return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�"); + } + + @Override + public List<EamTechnicalStatusEvaluationStandard> queryListByKeyword(String keyword, String equipmentId, Integer pageSize) { + Page<EamTechnicalStatusEvaluationStandard> page = new Page<>(1, pageSize); + EamTechnicalStatusEvaluationStandard query = new EamTechnicalStatusEvaluationStandard(); + query.setEquipmentId(equipmentId); + query.setKeyword(keyword); + query.setStandardStatus(TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name()); + IPage<EamTechnicalStatusEvaluationStandard> pageData = this.queryPageList(page, query); + return pageData.getRecords(); + } + + @Override + public EamTechnicalStatusEvaluationStandard queryEnableStandard(String equipmentId) { + LambdaQueryWrapper<EamTechnicalStatusEvaluationStandard> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getEquipmentId, equipmentId); + queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getDelFlag, CommonConstant.DEL_FLAG_0); + //鍚敤鐘舵�� + queryWrapper.eq(EamTechnicalStatusEvaluationStandard::getStandardStatus, TechnicalStatusEvaluationStandardStatusEnum.ENABLE.name()); + queryWrapper.orderByDesc(EamTechnicalStatusEvaluationStandard::getStandardVersion); + List<EamTechnicalStatusEvaluationStandard> list = this.getBaseMapper().selectList(queryWrapper); + if (CollectionUtil.isEmpty(list)) { + return null; + } + return list.get(0); + } + + /** + * 妫�鏌ュ鍏ユ枃浠跺垎绫绘槸鍚﹀尮閰� + * @param title 鏍囬娈佃惤瀛楃涓� + * @param category 鍒嗙被 + * @return true 涓嶅尮閰嶏紝 false 鍖归厤 + */ + private boolean checkImportCategory(String title, TechnicalStatusEvaluationCheckCategoryEnum category) { + switch (category) { + case SAFETY_EQUIPMENT_CHECK: + return !title.contains("瀹夊叏瑁呯疆妫�鏌�"); + case PRECISION_CHECK: + return !title.contains("绮惧害妫�鏌ュ崟"); + case OTHER_CHECK: + return !title.contains("鍏朵粬妫�鏌�"); + } + return true; + } + + + /** + * 鎻愬彇璁惧鍩烘湰淇℃伅 + */ + private EamEquipment extractEquipmentInfo(XWPFTable table) { + if (table.getNumberOfRows() < 4) { + //濡傛灉 table 灏忎簬4琛� 浠h〃涓嶇鍚堟ā鏉胯鑼冿紝瀵煎叆澶辫触 + throw new JeecgBootException("姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌�"); + } + // 鎻愬彇绗簩琛屾暟鎹� + Map<String, String> row2Data = extractHeadRowData(table.getRow(1)); + //鑾峰彇璁惧缁熶竴缂栫爜 + String equipmentCode = row2Data.get("缁熶竴缂栧彿") == null ? null : row2Data.get("缁熶竴缂栧彿").trim(); + EamEquipment eamEquipment = equipmentService.selectByEquipmentCode(equipmentCode); + if (eamEquipment == null) { + throw new JeecgBootException("鏈壘鍒拌澶囦俊鎭紝璇锋煡鐪嬭澶囧彴璐︽槸鍚︽湁姝よ澶�"); + } + return eamEquipment; + } + + /** + * 琛ㄦ牸琛ㄥご鏁版嵁瑙f瀽 + */ + private Map<String, String> extractHeadRowData(XWPFTableRow row) { + Map<String, String> data = new HashMap<>(); + if(CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() != 4) { + throw new JeecgBootException("姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌�"); + } + int cellCount = row.getTableCells().size(); + for (int i = 0; i < cellCount; i += 2) { + String key = row.getCell(i).getText().trim(); + String value = row.getCell(i + 1).getText().trim(); + if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) { + data.put(key, value); + } + } + return data; + } + + /** + * 鎻愬彇瀹夊叏瑁呯疆妫�鏌ユ槑缁� + */ + private List<EamTechnicalStatusEvaluationStandardDetail> extractSafetyEquipmentCheckItems(List<XWPFTable> tableList) { + List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); + EamTechnicalStatusEvaluationStandardDetail item = null; + //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭� + XWPFTable table = tableList.get(0); + for (int i = 0; i < table.getNumberOfRows(); i++) { + XWPFTableRow row = table.getRow(i); + if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) { + //璇诲彇鍒扮┖row鍊� + continue; + } + //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿 + String firstCell = row.getCell(0).getText().trim(); + Integer itemCode = null; + try { + itemCode = Integer.parseInt(firstCell); + } catch (NumberFormatException e) { + //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛� + continue; + } + //鑾峰彇绗簩涓崟鍏冩牸 + String secondCell = row.getCell(1).getText().trim(); + //濡傛灉杩欎竴琛屼负搴忓彿鍒欒В鏋愭暣琛� + if (StringUtils.isNotBlank(secondCell)) { + item = new EamTechnicalStatusEvaluationStandardDetail(); + item.setItemCode(itemCode); + item.setItemName(secondCell); + item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name()); + items.add(item); + } + } + return items; + } + + /** + * 鎻愬彇鍏朵粬妫�鏌ラ」鏄庣粏鍐呭 + * @param tables + * @return + */ + private List<EamTechnicalStatusEvaluationStandardDetail> extractOtherCheckItems(List<XWPFTable> tables) { + List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); + EamTechnicalStatusEvaluationStandardDetail item = null; + //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭� + XWPFTable table = tables.get(0); + for (int i = 0; i < table.getNumberOfRows(); i++) { + XWPFTableRow row = table.getRow(i); + if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) { + //璇诲彇鍒扮┖row鍊� + continue; + } + //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿 + String firstCell = row.getCell(0).getText().trim(); + Integer itemCode = null; + try { + itemCode = Integer.parseInt(firstCell); + } catch (NumberFormatException e) { + //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛� + continue; + } + //鑾峰彇绗簩涓崟鍏冩牸 + String secondCell = row.getCell(1).getText().trim(); + //濡傛灉杩欎竴琛屼负搴忓彿鍒欒В鏋愭暣琛� + if (StringUtils.isNotBlank(secondCell)) { + item = new EamTechnicalStatusEvaluationStandardDetail(); + item.setItemCode(itemCode); + item.setItemName(secondCell); + item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name()); + items.add(item); + } + } + return items; + } + + private List<EamTechnicalStatusEvaluationStandardDetail> extractPrecisionCheckItems(List<XWPFTable> tables) { + List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>(); + EamTechnicalStatusEvaluationStandardDetail item = null; + //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭� + XWPFTable table = tables.get(0); + for (int i = 0; i < table.getNumberOfRows(); i++) { + XWPFTableRow row = table.getRow(i); + if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) { + //璇诲彇鍒扮┖row鍊� + continue; + } + //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿 + String firstCell = row.getCell(0).getText().trim(); + Integer itemCode = null; + try { + itemCode = Integer.parseInt(firstCell); + } catch (NumberFormatException e) { + //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛� + if(item == null) { + continue; + }else { + itemCode = item.getItemCode(); + } + } + //鑾峰彇绗簩涓崟鍏冩牸 + String itemName = row.getCell(1).getText().trim(); + if(StringUtils.isBlank(itemName)) { + if(item != null) { + itemName = item.getItemName(); + }else { + continue; + } + } + String subItemName = null; + String toleranceValue = null; + if(row.getTableCells().size() == 4) { + toleranceValue = row.getCell(2).getText().trim(); + }else if(row.getTableCells().size() == 5) { + subItemName = row.getCell(2).getText().trim(); + toleranceValue = row.getCell(3).getText().trim(); + }else { + continue; + } + if(StringUtils.isBlank(toleranceValue)) { + //鍏佸樊鍊间笉瀛樺湪锛岃烦杩� + if(item != null) { + toleranceValue = item.getToleranceValue(); + }else { + continue; + } + } + //鎷艰鏄庣粏鏁版嵁 + item = new EamTechnicalStatusEvaluationStandardDetail(); + item.setItemCode(itemCode); + item.setItemName(itemName); + item.setSubItemName(subItemName); + item.setToleranceValue(toleranceValue); + item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name()); + items.add(item); + } + return items; + } + } -- Gitblit v1.9.3