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