| | |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CODE_DUPLICATE; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_HAS_CHECK_RECORD; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_IMPORT_LIST_IS_EMPTY; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.enums.dv.MesDvMeteringStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 计量器具 Service 实现类 |
| | |
| | | return meteringMapper.selectByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesDvMeteringImportRespVO importMeteringList(List<MesDvMeteringImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(DV_METERING_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesDvMeteringImportRespVO respVO = MesDvMeteringImportRespVO.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.getCode(), "第 " + currentIndex + " 行"); |
| | | if (StrUtil.isBlank(importItem.getCode())) { |
| | | respVO.getFailureCodes().put(key, "计量器具编码不能为空"); |
| | | return; |
| | | } |
| | | try { |
| | | MesDvMeteringSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvMeteringSaveReqVO.class); |
| | | saveReqVO.setCategory(ObjUtil.defaultIfNull(importItem.getCategory(), 1)); |
| | | saveReqVO.setCheckCycleCount(ObjUtil.defaultIfNull(importItem.getCheckCycleCount(), 12)); |
| | | saveReqVO.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), MesDvMeteringStatusEnum.IN_USE.getStatus())); |
| | | MesDvMeteringDO exist = meteringMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | createMetering(saveReqVO); |
| | | respVO.getCreateCodes().add(saveReqVO.getCode()); |
| | | } else if (updateSupport) { |
| | | saveReqVO.setId(exist.getId()); |
| | | updateMetering(saveReqVO); |
| | | respVO.getUpdateCodes().add(saveReqVO.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "计量器具编码已存在:" + importItem.getCode()); |
| | | } |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |