| | |
| | | |
| | | 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.checkplan.vo.MesDvCheckPlanImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.MesDvCheckPlanImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.enums.dv.MesDvCheckPlanTypeEnum; |
| | | 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 checkPlanMapper.selectByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesDvCheckPlanImportRespVO importCheckPlanList(List<MesDvCheckPlanImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(DV_CHECK_PLAN_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesDvCheckPlanImportRespVO respVO = MesDvCheckPlanImportRespVO.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 { |
| | | MesDvCheckPlanSaveReqVO saveReqVO = BeanUtils.toBean(importItem, MesDvCheckPlanSaveReqVO.class); |
| | | saveReqVO.setType(ObjUtil.defaultIfNull(importItem.getType(), MesDvCheckPlanTypeEnum.CHECK.getType())); |
| | | saveReqVO.setCycleType(ObjUtil.defaultIfNull(importItem.getCycleType(), 1)); |
| | | saveReqVO.setCycleCount(ObjUtil.defaultIfNull(importItem.getCycleCount(), 1)); |
| | | MesDvCheckPlanDO exist = checkPlanMapper.selectByCode(importItem.getCode()); |
| | | if (exist == null) { |
| | | createCheckPlan(saveReqVO); |
| | | respVO.getCreateCodes().add(saveReqVO.getCode()); |
| | | } else if (updateSupport) { |
| | | if (ObjUtil.notEqual(MesDvCheckPlanStatusEnum.PREPARE.getStatus(), exist.getStatus())) { |
| | | respVO.getFailureCodes().put(key, "方案已启用,不能更新:" + importItem.getCode()); |
| | | return; |
| | | } |
| | | saveReqVO.setId(exist.getId()); |
| | | updateCheckPlan(saveReqVO); |
| | | respVO.getUpdateCodes().add(saveReqVO.getCode()); |
| | | } else { |
| | | respVO.getFailureCodes().put(key, "方案编码已存在:" + importItem.getCode()); |
| | | } |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | } |