From 3990ae574c221e3764ce9cbc2e4e3eb71b7b1b52 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期六, 24 十月 2026 23:41:23 +0800
Subject: [PATCH] fix(mes): 修复批次正反向追溯链路
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java | 72 +++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 1 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java
index 1b0451e..df5b27b 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java
@@ -1,8 +1,12 @@
package cn.iocoder.yudao.module.mes.service.cal.plan;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanImportExcelVO;
+import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO;
@@ -10,16 +14,18 @@
import cn.iocoder.yudao.module.mes.enums.cal.MesCalPlanStatusEnum;
import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum;
import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService;
-import cn.hutool.core.util.ObjUtil;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
@@ -132,6 +138,70 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
+ public MesCalPlanImportRespVO importPlanList(List<MesCalPlanImportExcelVO> importList,
+ boolean updateSupport) {
+ // 1. 鏍¢獙闈炵┖
+ if (CollUtil.isEmpty(importList)) {
+ throw exception(CAL_PLAN_IMPORT_LIST_IS_EMPTY);
+ }
+
+ // 2. 閫愯澶勭悊
+ MesCalPlanImportRespVO respVO = MesCalPlanImportRespVO.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;
+ }
+ if (StrUtil.isBlank(importItem.getName())) {
+ respVO.getFailureCodes().put(key, "璁″垝鍚嶇О涓嶈兘涓虹┖");
+ return;
+ }
+ if (importItem.getCalendarType() == null) {
+ respVO.getFailureCodes().put(key, "鐝粍绫诲瀷涓嶈兘涓虹┖");
+ return;
+ }
+ if (importItem.getStartDate() == null || importItem.getEndDate() == null) {
+ respVO.getFailureCodes().put(key, "寮�濮嬫棩鏈熴�佺粨鏉熸棩鏈熶笉鑳戒负绌�");
+ return;
+ }
+ if (importItem.getShiftType() == null) {
+ respVO.getFailureCodes().put(key, "杞彮鏂瑰紡涓嶈兘涓虹┖");
+ return;
+ }
+ // 2.1 鍒ゆ柇锛氬垱寤� or 鏇存柊
+ MesCalPlanDO existPlan = planMapper.selectByCode(importItem.getCode());
+ if (existPlan == null) {
+ // 2.1.1 鏂板
+ MesCalPlanDO plan = BeanUtils.toBean(importItem, MesCalPlanDO.class);
+ plan.setId(null);
+ plan.setStatus(MesCalPlanStatusEnum.PREPARE.getStatus());
+ planMapper.insert(plan);
+ // 鑷姩鐢熸垚榛樿鐝
+ if (plan.getShiftType() != null) {
+ planShiftService.addDefaultPlanShift(plan.getId(), plan.getShiftType());
+ }
+ respVO.getCreateCodes().add(importItem.getCode());
+ } else if (updateSupport) {
+ // 2.1.2 鏇存柊锛堜笉鍏佽閫氳繃 import 淇敼鐘舵�侊級
+ MesCalPlanDO updateObj = BeanUtils.toBean(importItem, MesCalPlanDO.class);
+ updateObj.setId(existPlan.getId());
+ updateObj.setStatus(null);
+ planMapper.updateById(updateObj);
+ respVO.getUpdateCodes().add(importItem.getCode());
+ } else {
+ respVO.getFailureCodes().put(key, "璁″垝缂栫爜宸插瓨鍦�");
+ }
+ });
+ return respVO;
+ }
+
+ @Override
public MesCalPlanDO validatePlanPrepare(Long planId) {
MesCalPlanDO plan = validatePlanExists(planId);
if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) {
--
Gitblit v1.9.3