| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.meteringcheck; |
| | | import java.util.List; |
| | | |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CHECK_CODE_DUPLICATE; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CHECK_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CHECK_IMPORT_LIST_IS_EMPTY; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.metering.MesDvMeteringMapper; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 计量检测记录 Service 实现类 |
| | |
| | | @Service |
| | | @Validated |
| | | public class MesDvMeteringCheckServiceImpl implements MesDvMeteringCheckService { |
| | | |
| | | @Resource |
| | | private MesDvMeteringMapper meteringMapper; |
| | | |
| | | @Resource |
| | | private MesDvMeteringCheckMapper meteringCheckMapper; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesDvMeteringCheckImportRespVO importMeteringCheckList(List<MesDvMeteringCheckImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(DV_METERING_CHECK_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesDvMeteringCheckImportRespVO respVO = MesDvMeteringCheckImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String key = StrUtil.blankToDefault(importItem.getCheckCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getCheckCode())) { |
| | | respVO.getFailureCodes().put(key, "检测编号不能为空"); |
| | | return; |
| | | } |
| | | if (StrUtil.isBlank(importItem.getMeteringCode())) { |
| | | respVO.getFailureCodes().put(key, "计量器具编码不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getCheckDate() == null) { |
| | | respVO.getFailureCodes().put(key, "检测日期不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getCheckResult() == null) { |
| | | respVO.getFailureCodes().put(key, "检测结论不能为空"); |
| | | return; |
| | | } |
| | | MesDvMeteringDO metering = meteringMapper.selectByCode(importItem.getMeteringCode()); |
| | | if (metering == null) { |
| | | respVO.getFailureCodes().put(key, "计量器具不存在:" + importItem.getMeteringCode()); |
| | | return; |
| | | } |
| | | try { |
| | | MesDvMeteringCheckSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvMeteringCheckSaveReqVO.class); |
| | | saveReqVO.setMeteringId(metering.getId()); |
| | | createMeteringCheck(saveReqVO); |
| | | respVO.getCreateCodes().add(saveReqVO.getCheckCode()); |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |