| | |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.type.MesDvMachineryTypeImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.type.MesDvMachineryTypeImportRespVO; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 设备类型 Service 实现类 |
| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesDvMachineryTypeImportRespVO importMachineryTypeList(List<MesDvMachineryTypeImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(DV_MACHINERY_TYPE_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesDvMachineryTypeImportRespVO respVO = MesDvMachineryTypeImportRespVO.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; |
| | | } |
| | | Long parentId = MesDvMachineryTypeDO.PARENT_ID_ROOT; |
| | | if (StrUtil.isNotBlank(importItem.getParentCode())) { |
| | | MesDvMachineryTypeDO parent = machineryTypeMapper.selectByCode(importItem.getParentCode()); |
| | | if (parent == null) { |
| | | respVO.getFailureCodes().put(key, "父类型不存在:" + importItem.getParentCode()); |
| | | return; |
| | | } |
| | | parentId = parent.getId(); |
| | | } |
| | | try { |
| | | MesDvMachineryTypeSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvMachineryTypeSaveReqVO.class); |
| | | saveReqVO.setParentId(parentId); |
| | | saveReqVO.setStatus(ObjUtil.defaultIfNull(importItem.getStatus(), CommonStatusEnum.ENABLE.getStatus())); |
| | | saveReqVO.setSort(ObjUtil.defaultIfNull(importItem.getSort(), 0)); |
| | | MesDvMachineryTypeDO exist = machineryTypeMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | createMachineryType(saveReqVO); |
| | | respVO.getCreateCodes().add(saveReqVO.getCode()); |
| | | } else if (updateSupport) { |
| | | saveReqVO.setId(exist.getId()); |
| | | updateMachineryType(saveReqVO); |
| | | respVO.getUpdateCodes().add(saveReqVO.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "类型编码已存在:" + importItem.getCode()); |
| | | } |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |