qiangxuan 7 hónapja
szülő
commit
74df9fb2cf

+ 4 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsend/service/impl/BilletHotsendBaseServiceImpl.java

@@ -55,6 +55,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -133,6 +134,7 @@ public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseM
 			List<RollClubCommon> groupRollClubCommonList = entry.getValue();
 			JSONObject jsonObject = handleBilletHotsenAndDetails(billetHotsend, billetHotsendDetailsVo, billetHotsendTypeConfig, rollClubOneOrHeightStorageBillId, storageBill, groupRollClubCommonList);
 			if (jsonObject.containsKey("fail")){
+				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 				return jsonObject;
 			}
 		}
@@ -215,6 +217,7 @@ public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseM
 			List<RollClubCommon> groupRollClubCommonList = entry.getValue();
 			JSONObject jsonObject = handleBilletHotsenAndDetails(billetHotsend, billetHotsendDetailsVo, billetHotsendTypeConfig, rollClubOneOrHeightStorageBillId, storageBill, groupRollClubCommonList);
 			if (jsonObject.containsKey("fail")){
+				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 				return jsonObject;
 			}
 		}
@@ -283,6 +286,7 @@ public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseM
 		}
 		// 更新装运单 车次总序号、本车车次
 		if (oConvertUtils.isEmpty(billetHotsendDetailsVo.getStorageBill()) || billetHotsendDetailsVo.getStorageBill() == null){
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 			result.put("fail", "钢坯装运单不存在,棒线发车失败!");
 			return result;
 		}

+ 2 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -101,8 +101,8 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 			}
 		}
 		//更新班组班别缓存
-		String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getShiftGroup());
-		String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getShift());
+		String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
+		String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
 		redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
 		redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
 		// 生成新的交班记录 初始化并保存入库

+ 27 - 14
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/stackingAndLoadingVehicles/controller/StackingAndLoadingVehiclesController.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.billet.stackingAndLoadingVehicles.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -280,8 +281,11 @@ public class StackingAndLoadingVehiclesController extends JeecgController<Stacki
 	 @ApiOperation(value="钢坯-新增堆垛", notes="钢坯-新增堆垛")
 	 @PostMapping(value = "/addStacking")
 	 public Result<?> addStackInfo(@RequestBody LoadingParams loadingParams){
-		 stackingAndLoadingVehiclesService.addStackInfo(loadingParams);
-		 return Result.OK("新增堆垛操作成功");
+		 JSONObject jsonObject = stackingAndLoadingVehiclesService.addStackInfo(loadingParams);
+		 if (jsonObject.containsKey("fail")){
+			 return Result.OK((String) jsonObject.get("fail"));
+		 }
+		 return Result.OK((String) jsonObject.get("success"));
 	 }
 
      @ApiOperation(value="钢坯-垛位装车", notes="钢坯-垛位装车")
@@ -290,17 +294,20 @@ public class StackingAndLoadingVehiclesController extends JeecgController<Stacki
     	 if(oConvertUtils.listIsEmpty(loadingParams.getStackingAndLoadingVehiclesList())){
     		return Result.OK("请装入钢坯!");
 		 }
-		 Set<String> heats = new HashSet<>();
-		 for (StackingAndLoadingVehicles stackingAndLoadingVehicles : loadingParams.getStackingAndLoadingVehiclesList()) {
-			 heats.add(stackingAndLoadingVehicles.getHeatNo());
-		 }
-		 if(heats.size()>3)return Result.error("一次只能选择三种炉次的钢坯");
+//		 Set<String> heats = new HashSet<>();
+//		 for (StackingAndLoadingVehicles stackingAndLoadingVehicles : loadingParams.getStackingAndLoadingVehiclesList()) {
+//			 heats.add(stackingAndLoadingVehicles.getHeatNo());
+//		 }
+//		 if(heats.size() > 3)return Result.error("一次只能选择三种炉次的钢坯");
 		 StorageBill storageBill = loadingParams.getStorageBill();
 		 if (oConvertUtils.isEmpty(storageBill)){
-			 return Result.OK("钢坯装运单不存在,垛位装车失败!");
+			 return Result.error("钢坯装运单不存在,垛位装车失败!");
 		 }
-    	 stackingAndLoadingVehiclesService.loadingHandle(loadingParams);
-		return Result.OK("垛位装车操作成功");
+		 JSONObject jsonObject = stackingAndLoadingVehiclesService.loadingHandle(loadingParams);
+		 if (jsonObject.containsKey("fail")){
+			 return Result.error((String) jsonObject.get("fail"));
+		 }
+		 return Result.OK("垛位装车操作成功");
      }
 
 
@@ -310,11 +317,17 @@ public class StackingAndLoadingVehiclesController extends JeecgController<Stacki
 
 		 StorageBill storageBill = loadingParams.getStorageBill();
 		 if (oConvertUtils.isEmpty(storageBill)){
-			 return Result.OK("钢坯装运单不存在,垛位发车失败!");
+			 return Result.error("钢坯装运单不存在,垛位发车失败!");
+		 }
+		 List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
+		 if (oConvertUtils.listIsEmpty(stackingAndLoadingVehiclesList)){
+			 return Result.error("钢坯信息为空,垛位发车失败!");
+		 }
+		 JSONObject jsonObject = stackingAndLoadingVehiclesService.stackDepartHandle(loadingParams);
+		 if (jsonObject.containsKey("fail")){
+			 return Result.error((String) jsonObject.get("fail"));
 		 }
-		 stackingAndLoadingVehiclesService.stackDepartHandle(loadingParams);
-//		 operateLogService.add(billetHotsend,null,BilletHotsend.class);
-		 return Result.OK("垛位发车操作成功");
+		 return Result.OK((String) jsonObject.get("success"));
 	 }
 
      @ApiOperation(value="堆垛-发车", notes="堆垛-发车")

+ 4 - 3
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/stackingAndLoadingVehicles/service/IStackingAndLoadingVehiclesService.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.billet.stackingAndLoadingVehicles.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -38,11 +39,11 @@ public interface IStackingAndLoadingVehiclesService extends IService<StackingAnd
 
     List<StackingAndLoadingVehicles> getListByTypeConfigId(String typeConfigId);
 
-    void loadingHandle(LoadingParams loadingParams);
+    JSONObject loadingHandle(LoadingParams loadingParams);
 
-    void stackDepartHandle(LoadingParams loadingParams);
+    JSONObject stackDepartHandle(LoadingParams loadingParams);
 
-    void addStackInfo(LoadingParams loadingParams);
+    JSONObject addStackInfo(LoadingParams loadingParams);
 
     String judgeDiscardHandle(LoadingParams loadingParams);
 }

+ 246 - 220
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/stackingAndLoadingVehicles/service/impl/StackingAndLoadingVehiclesServiceImpl.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.billet.stackingAndLoadingVehicles.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -10,9 +11,8 @@ import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
 import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
-import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
-import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
+import org.jeecg.modules.billet.billetHotsend.entity.RollClubCommon;
 import org.jeecg.modules.billet.billetHotsend.entity.RulerDefaultConfig;
 import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
 import org.jeecg.modules.billet.billetHotsend.service.IRulerDefaultConfigService;
@@ -46,8 +46,10 @@ import org.jeecg.modules.billet.storageCarLog.entity.StorageCarLog;
 import org.jeecg.modules.billet.storageCarLog.service.IStorageCarLogService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -87,8 +89,6 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
     @Autowired
     private StackingAndLoadingVehiclesMapper stackingAndLoadingVehiclesMapper;
     @Autowired
-    private IHeatsActualsService heatsActualsService;
-    @Autowired
     private IRollOutShippDetailsService rollOutShippDetailsService;
     @Autowired
     private IRollClubThreeDetailsService rollClubThreeDetailsService;
@@ -98,6 +98,9 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
     private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
     @Autowired
     private IBilletHotsendAbandonsService billetHotsendAbandonsService;
+    @Autowired
+    public RedisTemplate redisTemplate;
+
     @Override
     public List<List<StackingAndLoadingVehicles>> getListBySatck(String typeConfigId) {
         LambdaQueryWrapper<StackingAndLoadingVehicles> wrapper = new LambdaQueryWrapper<>();
@@ -475,120 +478,14 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
 
     @Override
     @Transactional
-    public void loadingHandle(LoadingParams loadingParams) {
+    public JSONObject loadingHandle(LoadingParams loadingParams) {
+        JSONObject result = new JSONObject();
         // 根据billetHotsendTypeConfigId 查询基础垛位信息
         BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getById(loadingParams.getBilletHotsendTypeConfigId());
+
+        BilletHotsend billetHotsend = loadingParams.getBilletHotsend();
+
         List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
-        BilletHotsend billetHotsend = new BilletHotsend();
-        BeanUtils.copyProperties(loadingParams.getBilletHotsend(), billetHotsend);
-        String cacheShint = loadingParams.getBilletHotsend().getShift();
-        String cacheShintGroup = loadingParams.getBilletHotsend().getShiftGroup();
-        //1 新保存 钢坯热送基础信息
-        HeatsActuals heatsActuals = heatsActualsService.getOne(new LambdaQueryWrapper<HeatsActuals>().eq(HeatsActuals::getCasterCode, billetHotsend.getCcmNo()).eq(HeatsActuals::getHeatsCode, billetHotsend.getHeatNo()));
-        if (heatsActuals != null) {
-            cacheShint = heatsActuals.getShift();
-            cacheShintGroup = heatsActuals.getShiftGroup();
-        }
-        if (oConvertUtils.listIsEmpty(stackingAndLoadingVehiclesList)){
-            return;
-        }
-        // 根据铸机号、位置、层数、类型配置ID更新 初始化容器中的垛位信息
-        stackingAndLoadingVehiclesList.forEach(x ->{
-            LambdaUpdateWrapper<StackingAndLoadingVehicles> updateWrapper = new LambdaUpdateWrapper();
-            updateWrapper.eq(StackingAndLoadingVehicles::getId, x.getId())
-                    .set(StackingAndLoadingVehicles::getBilletNos, null)
-                    .set(StackingAndLoadingVehicles::getSpec, null)
-                    .set(StackingAndLoadingVehicles::getSteel, null)
-                    .set(StackingAndLoadingVehicles::getSize, null)
-                    .set(StackingAndLoadingVehicles::getShift, null)
-                    .set(StackingAndLoadingVehicles::getHeatNo, null)
-                    .set(StackingAndLoadingVehicles::getCreateDate, null)
-                    .set(StackingAndLoadingVehicles::getShiftGroup, null);
-            StackingAndLoadingVehicles stackingAndLoadingVehicles = new StackingAndLoadingVehicles();
-            BeanUtils.copyProperties(x, stackingAndLoadingVehicles);
-            stackingAndLoadingVehiclesMapper.update(stackingAndLoadingVehicles, updateWrapper);
-            // 先根据垛位容器中的铸机号和炉号 查询钢坯热送基础信息
-            LambdaQueryWrapper<BilletHotsend> queryWrapper1 = new LambdaQueryWrapper<>();
-            queryWrapper1.eq(BilletHotsend::getCcmNo, x.getCcmNo())
-                    .eq(BilletHotsend::getHeatNo, x.getHeatNo());
-            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper1);
-            idExistBh.setStackNum(idExistBh.getStackNum() - 4);
-            if ("roll_club_two".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRollclubtwoNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubtwoNum()) ? idExistBh.getRollclubtwoNum() + 4 : 4);
-            }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRollclubthreeNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubthreeNum()) ? idExistBh.getRollclubthreeNum() + 4 : 4);
-            }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRolloutshippNum(oConvertUtils.isNotEmpty(idExistBh.getRolloutshippNum()) ? idExistBh.getRolloutshippNum() + 4 : 4);
-            }
-            billetHotsendBaseService.updateById(idExistBh);
-        });
-        String finalCacheShint1 = cacheShint;
-        String finalCacheShintGroup1 = cacheShintGroup;
-        // 3 保存 下垛日志    stacking_up_log
-        List<StackingDownLog> stackingDownLogList = new ArrayList<>();
-        List<RollClubTwoDetails> addRollClubTwoDetailsList = new ArrayList<>();
-        List<RollClubThreeDetails> addRollClubThreeDetailsList = new ArrayList<>();
-        List<RollOutShippDetails> addRollOutShippDetailsList = new ArrayList<>();
-        stackingAndLoadingVehiclesList.forEach(x ->{
-            StackingDownLog stackingDownLog = new StackingDownLog();
-            BeanUtils.copyProperties(x, stackingDownLog);
-            stackingDownLog.setId(String.valueOf(IdWorker.getId()));
-            stackingDownLog.setBilletNo(x.getBilletNos());
-            stackingDownLog.setStorageBillId(loadingParams.getStorageBill().getId());
-            stackingDownLog.setStackStorey(x.getLayer());// 堆垛层号(1-20)
-            stackingDownLog.setStackNum(x.getAddress());// 堆垛编号(1-9)
-            stackingDownLog.setStackAddr(billetHotsendTypeConfig.getTypeName());
-            stackingDownLog.setShift(finalCacheShint1);
-            stackingDownLog.setShiftGroup(finalCacheShintGroup1);
-//            stackingUpLog.setFromStackingId(stackingAndLoadingVehicles.getId());
-            stackingDownLogList.add(stackingDownLog);
-            if ("roll_club_two".equals(loadingParams.getDestinationTable())){
-                RollClubTwoDetails rollClubTwoDetails = new RollClubTwoDetails();
-                BeanUtils.copyProperties(x, rollClubTwoDetails);
-                rollClubTwoDetails.setBilletNo(x.getBilletNos());
-                rollClubTwoDetails.setStorageBillId(loadingParams.getStorageBill().getId());
-                rollClubTwoDetails.setStackStorey(x.getLayer());
-                rollClubTwoDetails.setStackNum(x.getAddress());
-                rollClubTwoDetails.setLicensePlate(loadingParams.getStorageBill().getLicensePlate());
-                rollClubTwoDetails.setCreateTime(new Date());
-                rollClubTwoDetails.setUpdateTime(new Date());
-                rollClubTwoDetails.setId(String.valueOf(IdWorker.getId()));
-                addRollClubTwoDetailsList.add(rollClubTwoDetails);
-            }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
-                RollClubThreeDetails rollClubThreeDetails = new RollClubThreeDetails();
-                BeanUtils.copyProperties(x, rollClubThreeDetails);
-                rollClubThreeDetails.setBilletNo(x.getBilletNos());
-                rollClubThreeDetails.setStorageBillId(loadingParams.getStorageBill().getId());
-                rollClubThreeDetails.setStackStorey(x.getLayer());
-                rollClubThreeDetails.setStackNum(x.getAddress());
-                rollClubThreeDetails.setLicensePlate(loadingParams.getStorageBill().getLicensePlate());
-                rollClubThreeDetails.setCreateTime(new Date());
-                rollClubThreeDetails.setUpdateTime(new Date());
-                rollClubThreeDetails.setId(String.valueOf(IdWorker.getId()));
-                addRollClubThreeDetailsList.add(rollClubThreeDetails);
-            }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
-                RollOutShippDetails rollOutShippDetails = new RollOutShippDetails();
-                BeanUtils.copyProperties(x, rollOutShippDetails);
-                rollOutShippDetails.setBilletNo(x.getBilletNos());
-                rollOutShippDetails.setStorageBillId(loadingParams.getStorageBill().getId());
-                rollOutShippDetails.setStackStorey(x.getLayer());
-                rollOutShippDetails.setStackNum(x.getAddress());
-                rollOutShippDetails.setLicensePlate(loadingParams.getStorageBill().getLicensePlate());
-                rollOutShippDetails.setId(String.valueOf(IdWorker.getId()));
-                rollOutShippDetails.setCreateTime(new Date());
-                rollOutShippDetails.setUpdateTime(new Date());
-                addRollOutShippDetailsList.add(rollOutShippDetails);
-            }
-        });
-        stackingDownLogService.saveBatch(stackingDownLogList);
-        // 根据所去的目的地 保存到对应的明细表
-        if ("roll_club_two".equals(loadingParams.getDestinationTable())){
-            rollClubTwoDetailsService.saveBatch(addRollClubTwoDetailsList);
-        }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
-            rollClubThreeDetailsService.saveBatch(addRollClubThreeDetailsList);
-        }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
-            rollOutShippDetailsService.saveBatch(addRollOutShippDetailsList);
-        }
         // 获取所有的坯号集合
         List<String> billetNosList = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getBilletNos)
                 .flatMap(billetNos -> {
@@ -598,45 +495,84 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
                         return java.util.stream.Stream.empty();
                     }
                 }).collect(Collectors.toList());
-
-        //5 查询并批量更新钢坯基础信息 belongTable
         LambdaQueryWrapper<BilletBasicInfo> queryWrapperBB = new LambdaQueryWrapper<BilletBasicInfo>()
                 .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(billetHotsend.getCcmNo()))
                 .in(BilletBasicInfo::getBilletNo, billetNosList);
         List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapperBB);
+        List<RollClubCommon> rollClubCommonList= new ArrayList<>();
+        billetBasicInfoList.forEach(x ->{
+            RollClubCommon rollClubCommon = new RollClubCommon();
+            BeanUtils.copyProperties(x, rollClubCommon);
+            rollClubCommon.setCcmNo(x.getCcmNo().toString());
+            rollClubCommonList.add(rollClubCommon);
+        });
+
+        StorageBill storageBill =loadingParams.getStorageBill();
+
+        handleStackDepartCommon(billetHotsend, stackingAndLoadingVehiclesList, loadingParams, billetHotsendTypeConfig, storageBill);
+
+        // 先根据垛位容器中的铸机号和炉号 查询钢坯热送基础信息
+        Map<String, List<RollClubCommon>> rollClubCommonListttt = groupByShiftAttributes(rollClubCommonList);
+        for (Map.Entry<String, List<RollClubCommon>> entry : rollClubCommonListttt.entrySet()) {
+            String[] parts = entry.getKey().split(",");
+            billetHotsend.setHeatNo(parts[0]);// 炉号
+            billetHotsend.setShiftGroup(parts[1]);// 班组
+            billetHotsend.setShift(parts[2]);// 班别
+            List<RollClubCommon> groupRollClubCommonList = entry.getValue();
+            LambdaQueryWrapper<BilletHotsend> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsend::getCcmNo, billetHotsend.getCcmNo())
+                    .eq(BilletHotsend::getHeatNo, billetHotsend.getHeatNo())
+                    .eq(BilletHotsend::getShift,  billetHotsend.getShift())
+                    .eq(BilletHotsend::getShiftGroup, billetHotsend.getShiftGroup());
+            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper);
+            if (oConvertUtils.isEmpty(idExistBh)){
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                result.put("fail", "钢坯热送单为空,垛位装车保存失败");
+                return result;
+            }
+            billetHotsend.setId(idExistBh.getId());
+            billetHotsend.setStackNum(idExistBh.getStackNum() - groupRollClubCommonList.size());
+            // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
+            if ("roll_club_two".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRollclubtwoNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubtwoNum()) ? idExistBh.getRollclubtwoNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRollclubthreeNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubthreeNum()) ? idExistBh.getRollclubthreeNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRolloutshippNum(oConvertUtils.isNotEmpty(idExistBh.getRolloutshippNum()) ? idExistBh.getRolloutshippNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }
+            billetHotsend.setUpdateTime(new Date());
+            billetHotsendBaseService.updateById(billetHotsend);
+        }
+
+        //5 查询并批量更新钢坯基础信息 belongTable
         billetBasicInfoList.forEach(x ->{
             x.setBelongTable(loadingParams.getDestinationTable());
             x.setBhtcId(loadingParams.getDestinationId());
             x.setUpdateTime(new Date());
         });
         billetBasicInfoService.saveOrUpdateBatch(billetBasicInfoList);
-        StorageBill storageBill = loadingParams.getStorageBill();
-        storageBill.setAmountTotal(stackingAndLoadingVehiclesList.size() * 4);
+        storageBill.setAmountTotal((oConvertUtils.isNotEmpty(storageBill.getAmountTotal()) ? storageBill.getAmountTotal() : 0) + stackingAndLoadingVehiclesList.size() * 4);
         storageBill.setDestination(loadingParams.getDestination());
         storageBill.setTypeConfigId(loadingParams.getDestinationId());
         storageBillService.updateById(storageBill);
+        result.put("success", "堆垛保存操作成功");
+        return result;
     }
 
-    @Override
-    @Transactional
-    public void stackDepartHandle(LoadingParams loadingParams) {
-        // 根据billetHotsendTypeConfigId 查询基础垛位信息
-        BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getById(loadingParams.getBilletHotsendTypeConfigId());
-        List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
-        BilletHotsend billetHotsend = new BilletHotsend();
-        BeanUtils.copyProperties(loadingParams.getBilletHotsend(), billetHotsend);
-        String cacheShint = loadingParams.getBilletHotsend().getShift();
-        String cacheShintGroup = loadingParams.getBilletHotsend().getShiftGroup();
-        //1 新保存 钢坯热送基础信息
-        HeatsActuals heatsActuals = heatsActualsService.getOne(new LambdaQueryWrapper<HeatsActuals>().eq(HeatsActuals::getCasterCode, billetHotsend.getCcmNo()).eq(HeatsActuals::getHeatsCode, billetHotsend.getHeatNo()));
-        if (heatsActuals != null) {
-            cacheShint = heatsActuals.getShift();
-            cacheShintGroup = heatsActuals.getShiftGroup();
-        }
-        if (oConvertUtils.listIsEmpty(stackingAndLoadingVehiclesList)){
-            return;
-        }
-        // 2 发车后,动态更新容器中的垛位信息 初始化
+    /**
+     * 堆垛保存、堆垛发车公共处理
+     * @param billetHotsend
+     * @param stackingAndLoadingVehiclesList
+     * @param loadingParams
+     * @param billetHotsendTypeConfig
+     * @param storageBill
+     */
+    private void handleStackDepartCommon(BilletHotsend billetHotsend, List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList, LoadingParams loadingParams, BilletHotsendTypeConfig billetHotsendTypeConfig, StorageBill storageBill){
+        String keyShiftGroup = String.format("class:shift:group:%s", billetHotsend.getCcmNo());
+        String keyShift = String.format("class:shift:%s", billetHotsend.getCcmNo());
+        String finalCacheShintGroup = redisTemplate.opsForValue().get(keyShiftGroup).toString();
+        String finalCacheShint = redisTemplate.opsForValue().get(keyShift).toString();
+        // 根据铸机号、位置、层数、类型配置ID更新 初始化容器中的垛位信息
         stackingAndLoadingVehiclesList.forEach(x ->{
             LambdaUpdateWrapper<StackingAndLoadingVehicles> updateWrapper = new LambdaUpdateWrapper();
             updateWrapper.eq(StackingAndLoadingVehicles::getId, x.getId())
@@ -651,25 +587,8 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
             StackingAndLoadingVehicles stackingAndLoadingVehicles = new StackingAndLoadingVehicles();
             BeanUtils.copyProperties(x, stackingAndLoadingVehicles);
             stackingAndLoadingVehiclesMapper.update(stackingAndLoadingVehicles, updateWrapper);
-            // 先根据垛位容器中的铸机号和炉号 查询钢坯热送基础信息
-            LambdaQueryWrapper<BilletHotsend> queryWrapper1 = new LambdaQueryWrapper<>();
-            queryWrapper1.eq(BilletHotsend::getCcmNo, x.getCcmNo())
-                    .eq(BilletHotsend::getHeatNo, x.getHeatNo());
-            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper1);
-            idExistBh.setStackNum(idExistBh.getStackNum() - 4);
-            if ("roll_club_two".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRollclubtwoNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubtwoNum()) ? idExistBh.getRollclubtwoNum() + 4 : 4);
-            }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRollclubthreeNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubthreeNum()) ? idExistBh.getRollclubthreeNum() + 4 : 4);
-            }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
-                idExistBh.setRolloutshippNum(oConvertUtils.isNotEmpty(idExistBh.getRolloutshippNum()) ? idExistBh.getRolloutshippNum() + 4 : 4);
-            }
-            billetHotsendBaseService.updateById(idExistBh);
         });
-        StorageBill storageBill = loadingParams.getStorageBill();
-        // 4 保存 下垛日志    stacking_down_log
-        String finalCacheShint1 = cacheShint;
-        String finalCacheShintGroup1 = cacheShintGroup;
+        // 3 保存 下垛日志    stacking_up_log
         List<StackingDownLog> stackingDownLogList = new ArrayList<>();
         List<RollClubTwoDetails> addRollClubTwoDetailsList = new ArrayList<>();
         List<RollClubThreeDetails> addRollClubThreeDetailsList = new ArrayList<>();
@@ -678,30 +597,46 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
             StackingDownLog stackingDownLog = new StackingDownLog();
             BeanUtils.copyProperties(x, stackingDownLog);
             stackingDownLog.setId(String.valueOf(IdWorker.getId()));
+            // 根据坯号查询 对应的钢坯基础信息,获取到炉号
+            String[] parts = x.getBilletNos().split(",");
+            //4 获取所有的坯号集合
+            LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.in(BilletBasicInfo::getBilletNo, Arrays.asList(parts));
+            List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
+            BilletBasicInfo billetBasicInfo = billetBasicInfoList.stream().findFirst().orElse(null);
+            List<String> heatNos = billetBasicInfoList.stream().map(BilletBasicInfo::getHeatNo).distinct().collect(Collectors.toList());
+            stackingDownLog.setHeatNo(String.join(",", heatNos));
             stackingDownLog.setBilletNo(x.getBilletNos());
-            stackingDownLog.setStorageBillId(loadingParams.getStorageBill().getId());// 装运单ID
-            stackingDownLog.setStackStorey(x.getLayer());
-            stackingDownLog.setStackNum(x.getAddress());
-            stackingDownLog.setShift(finalCacheShint1);
-            stackingDownLog.setShiftGroup(finalCacheShintGroup1);
-            stackingDownLog.setCreateTime(new Date());
+            stackingDownLog.setStorageBillId(storageBill.getId());
+            stackingDownLog.setStackStorey(x.getLayer());// 堆垛层号(1-20)
+            stackingDownLog.setStackNum(x.getAddress());// 堆垛编号(1-9)
+            stackingDownLog.setStackAddr(billetHotsendTypeConfig.getTypeName());
+            stackingDownLog.setShift(finalCacheShint);
+            stackingDownLog.setShiftGroup(finalCacheShintGroup);
+//            stackingUpLog.setFromStackingId(stackingAndLoadingVehicles.getId());
             stackingDownLogList.add(stackingDownLog);
             if ("roll_club_two".equals(loadingParams.getDestinationTable())){
                 RollClubTwoDetails rollClubTwoDetails = new RollClubTwoDetails();
                 BeanUtils.copyProperties(x, rollClubTwoDetails);
+                rollClubTwoDetails.setHeatNo(String.join(",", heatNos));
                 rollClubTwoDetails.setBilletNo(x.getBilletNos());
                 rollClubTwoDetails.setStorageBillId(storageBill.getId());
                 rollClubTwoDetails.setStackStorey(x.getLayer());
                 rollClubTwoDetails.setStackNum(x.getAddress());
+                rollClubTwoDetails.setShiftGroup(billetBasicInfo.getShiftGroup());
+                rollClubTwoDetails.setShift(billetBasicInfo.getShift());
                 rollClubTwoDetails.setLicensePlate(storageBill.getLicensePlate());
-                rollClubTwoDetails.setId(String.valueOf(IdWorker.getId()));
                 rollClubTwoDetails.setCreateTime(new Date());
                 rollClubTwoDetails.setUpdateTime(new Date());
+                rollClubTwoDetails.setId(String.valueOf(IdWorker.getId()));
                 addRollClubTwoDetailsList.add(rollClubTwoDetails);
             }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
                 RollClubThreeDetails rollClubThreeDetails = new RollClubThreeDetails();
                 BeanUtils.copyProperties(x, rollClubThreeDetails);
+                rollClubThreeDetails.setHeatNo(String.join(",", heatNos));
                 rollClubThreeDetails.setBilletNo(x.getBilletNos());
+                rollClubThreeDetails.setShiftGroup(billetBasicInfo.getShiftGroup());
+                rollClubThreeDetails.setShift(billetBasicInfo.getShift());
                 rollClubThreeDetails.setStorageBillId(storageBill.getId());
                 rollClubThreeDetails.setStackStorey(x.getLayer());
                 rollClubThreeDetails.setStackNum(x.getAddress());
@@ -713,19 +648,22 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
             }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
                 RollOutShippDetails rollOutShippDetails = new RollOutShippDetails();
                 BeanUtils.copyProperties(x, rollOutShippDetails);
+                rollOutShippDetails.setHeatNo(String.join(",", heatNos));
                 rollOutShippDetails.setBilletNo(x.getBilletNos());
+                rollOutShippDetails.setShiftGroup(billetBasicInfo.getShiftGroup());
+                rollOutShippDetails.setShift(billetBasicInfo.getShift());
                 rollOutShippDetails.setStorageBillId(storageBill.getId());
                 rollOutShippDetails.setStackStorey(x.getLayer());
                 rollOutShippDetails.setStackNum(x.getAddress());
                 rollOutShippDetails.setLicensePlate(storageBill.getLicensePlate());
+                rollOutShippDetails.setId(String.valueOf(IdWorker.getId()));
                 rollOutShippDetails.setCreateTime(new Date());
                 rollOutShippDetails.setUpdateTime(new Date());
-                rollOutShippDetails.setId(String.valueOf(IdWorker.getId()));
                 addRollOutShippDetailsList.add(rollOutShippDetails);
             }
         });
         stackingDownLogService.saveBatch(stackingDownLogList);
-        // 根据所去的目的地 保存装运明细到对应的明细表
+        // 根据所去的目的地 保存到对应的明细表
         if ("roll_club_two".equals(loadingParams.getDestinationTable())){
             rollClubTwoDetailsService.saveBatch(addRollClubTwoDetailsList);
         }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
@@ -733,6 +671,18 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
         }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
             rollOutShippDetailsService.saveBatch(addRollOutShippDetailsList);
         }
+    }
+
+    @Override
+    @Transactional
+    public JSONObject stackDepartHandle(LoadingParams loadingParams) {
+        JSONObject result = new JSONObject();
+        // 根据billetHotsendTypeConfigId 查询基础垛位信息
+        BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getById(loadingParams.getBilletHotsendTypeConfigId());
+
+        BilletHotsend billetHotsend = loadingParams.getBilletHotsend();
+
+        List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
         // 获取所有的坯号集合
         List<String> billetNosList = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getBilletNos)
                 .flatMap(billetNos -> {
@@ -742,11 +692,53 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
                         return java.util.stream.Stream.empty();
                     }
                 }).collect(Collectors.toList());
-        //5 查询并批量更新钢坯基础信息 belongTable
         LambdaQueryWrapper<BilletBasicInfo> queryWrapperBB = new LambdaQueryWrapper<BilletBasicInfo>()
                 .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(billetHotsend.getCcmNo()))
                 .in(BilletBasicInfo::getBilletNo, billetNosList);
         List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapperBB);
+        List<RollClubCommon> rollClubCommonList= new ArrayList<>();
+        billetBasicInfoList.forEach(x ->{
+            RollClubCommon rollClubCommon = new RollClubCommon();
+            BeanUtils.copyProperties(x, rollClubCommon);
+            rollClubCommon.setCcmNo(x.getCcmNo().toString());
+            rollClubCommonList.add(rollClubCommon);
+        });
+
+        StorageBill storageBill =loadingParams.getStorageBill();
+
+        handleStackDepartCommon(billetHotsend, stackingAndLoadingVehiclesList, loadingParams, billetHotsendTypeConfig, storageBill);
+        Map<String, List<RollClubCommon>> rollClubCommonListttt = groupByShiftAttributes(rollClubCommonList);
+        for (Map.Entry<String, List<RollClubCommon>> entry : rollClubCommonListttt.entrySet()) {
+            String[] parts = entry.getKey().split(",");
+            billetHotsend.setHeatNo(parts[0]);// 炉号
+            billetHotsend.setShiftGroup(parts[1]);// 班组
+            billetHotsend.setShift(parts[2]);// 班别
+            List<RollClubCommon> groupRollClubCommonList = entry.getValue();
+            LambdaQueryWrapper<BilletHotsend> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsend::getCcmNo, billetHotsend.getCcmNo())
+                    .eq(BilletHotsend::getHeatNo, billetHotsend.getHeatNo())
+                    .eq(BilletHotsend::getShift,  billetHotsend.getShift())
+                    .eq(BilletHotsend::getShiftGroup, billetHotsend.getShiftGroup());
+            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper);
+            if (oConvertUtils.isEmpty(idExistBh)){
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                result.put("fail", "钢坯热送单为空,垛位发车失败");
+                return result;
+            }
+            billetHotsend.setId(idExistBh.getId());
+            billetHotsend.setStackNum(idExistBh.getStackNum() - groupRollClubCommonList.size());
+            // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
+            if ("roll_club_two".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRollclubtwoNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubtwoNum()) ? idExistBh.getRollclubtwoNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }else if ("roll_club_three".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRollclubthreeNum(oConvertUtils.isNotEmpty(idExistBh.getRollclubthreeNum()) ? idExistBh.getRollclubthreeNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }else if ("roll_out_shipp".equals(loadingParams.getDestinationTable())){
+                billetHotsend.setRolloutshippNum(oConvertUtils.isNotEmpty(idExistBh.getRolloutshippNum()) ? idExistBh.getRolloutshippNum() + groupRollClubCommonList.size() : groupRollClubCommonList.size());
+            }
+            billetHotsend.setUpdateTime(new Date());
+            billetHotsendBaseService.updateById(billetHotsend);
+        }
+        //5 获取所有的坯号集合 查询并批量更新钢坯基础信息 belongTable
         billetBasicInfoList.forEach(x ->{
             x.setBelongTable(loadingParams.getDestinationTable());
             x.setBhtcId(loadingParams.getDestinationId());
@@ -818,55 +810,23 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
         storageCarLog.setAmount(dd);// 支数
         storageCarLog.setDataTime(new Date());
         storageCarLogService.save(storageCarLog);
+        result.put("success", "堆垛发车操作成功");
+        return result;
     }
 
-    @Override
-    @Transactional
-    public void addStackInfo(LoadingParams loadingParams) {
-        // 根据billetHotsendTypeConfigId 查询基础垛位信息
-        BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getById(loadingParams.getBilletHotsendTypeConfigId());
-        List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
-        BilletHotsend billetHotsend = new BilletHotsend();
-        BeanUtils.copyProperties(loadingParams.getBilletHotsend(), billetHotsend);
-        String cacheShint = loadingParams.getBilletHotsend().getShift();
-        String cacheShintGroup = loadingParams.getBilletHotsend().getShiftGroup();
-        //1 新保存 钢坯热送基础信息
-        HeatsActuals heatsActuals = heatsActualsService.getOne(new LambdaQueryWrapper<HeatsActuals>().eq(HeatsActuals::getCasterCode, billetHotsend.getCcmNo()).eq(HeatsActuals::getHeatsCode, billetHotsend.getHeatNo()));
-        if (heatsActuals != null) {
-            cacheShint = heatsActuals.getShift();
-            cacheShintGroup = heatsActuals.getShiftGroup();
-        }
-        if (oConvertUtils.listIsEmpty(stackingAndLoadingVehiclesList)){
-            return;
-        }
-        LambdaQueryWrapper<BilletHotsend> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(BilletHotsend::getCcmNo, billetHotsend.getCcmNo())
-                .eq(BilletHotsend::getHeatNo, billetHotsend.getHeatNo())
-                .eq(BilletHotsend::getShift, cacheShint)
-                .eq(BilletHotsend::getShiftGroup, cacheShintGroup);
-        BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper);
-        if (oConvertUtils.isNotEmpty(idExistBh)){
-            // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
-            billetHotsend.setStackNum(idExistBh.getStackNum() + stackingAndLoadingVehiclesList.size() * 4); // 堆垛总支数
-            LambdaUpdateWrapper<BilletHotsend> updateWrapper = new LambdaUpdateWrapper<>();
-            updateWrapper.eq(BilletHotsend::getCcmNo, billetHotsend.getCcmNo())
-                    .eq(BilletHotsend::getHeatNo, billetHotsend.getHeatNo())
-                    .eq(BilletHotsend::getShift, cacheShint)
-                    .eq(BilletHotsend::getShiftGroup, cacheShintGroup)
-                    .set(BilletHotsend::getStackNum, billetHotsend.getStackNum())
-                    .set(BilletHotsend::getShift, cacheShint)
-                    .set(BilletHotsend::getShiftGroup, cacheShintGroup);
-            billetHotsendBaseService.update(billetHotsend, updateWrapper);
-        } else {
-            // 钢坯热送基础信息不存在,但是钢坯信息不存在 保存钢坯热送基础信息
-            billetHotsend.setStackNum(stackingAndLoadingVehiclesList.size() * 4);
-            billetHotsend.setShiftGroup(cacheShintGroup);
-            billetHotsend.setShift(cacheShint);
-            billetHotsendBaseService.save(billetHotsend);
-        }
+    /**
+     * 堆垛保存 公共方法
+     * @param billetHotsend
+     * @param stackingAndLoadingVehiclesList
+     * @param loadingParams
+     * @param billetHotsendTypeConfig
+     */
+    private void handleAddStackInfo(BilletHotsend billetHotsend, List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList, LoadingParams loadingParams, BilletHotsendTypeConfig billetHotsendTypeConfig){
+        String keyShiftGroup = String.format("class:shift:group:%s", billetHotsend.getCcmNo());
+        String keyShift = String.format("class:shift:%s", billetHotsend.getCcmNo());
+        String finalCacheShintGroup = redisTemplate.opsForValue().get(keyShiftGroup).toString();
+        String finalCacheShint = redisTemplate.opsForValue().get(keyShift).toString();
         // 2 发车后,动态更新容器中的垛位信息 初始化
-        String finalCacheShint1 = cacheShint;
-        String finalCacheShintGroup1 = cacheShintGroup;
         stackingAndLoadingVehiclesList.forEach(x ->{
             LambdaUpdateWrapper<StackingAndLoadingVehicles> queryWrapperSA = new LambdaUpdateWrapper<>();
             queryWrapperSA.eq(StackingAndLoadingVehicles::getCcmNo, x.getCcmNo())
@@ -875,12 +835,18 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
                     .eq(StackingAndLoadingVehicles::getTypeConfigId, loadingParams.getBilletHotsendTypeConfigId());
             StackingAndLoadingVehicles stackingAndLoadingVehicles = createInitializedVehicle();
             BeanUtils.copyProperties(x, stackingAndLoadingVehicles);
-            stackingAndLoadingVehicles.setShift(finalCacheShint1);
-            stackingAndLoadingVehicles.setShiftGroup(finalCacheShintGroup1);
+            // 根据坯号查询 对应的钢坯基础信息,获取到炉号
+            String[] parts = x.getBilletNos().split(",");
+            //4 获取所有的坯号集合
+            LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.in(BilletBasicInfo::getBilletNo, Arrays.asList(parts));
+            List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
+            BilletBasicInfo billetBasicInfo = billetBasicInfoList.stream().findFirst().orElse(null);
+            stackingAndLoadingVehicles.setShift(billetBasicInfo.getShift());
+            stackingAndLoadingVehicles.setShiftGroup(billetBasicInfo.getShiftGroup());
             stackingAndLoadingVehicles.setCreateDate(new Date());
             baseMapper.update(stackingAndLoadingVehicles, queryWrapperSA);
         });
-
         // 3 保存 起垛日志    stacking_up_log
         List<StackingUpLog> stackingUpLogList = new ArrayList<>();
         stackingAndLoadingVehiclesList.forEach(x ->{
@@ -888,17 +854,68 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
             BeanUtils.copyProperties(x, stackingUpLog);
             stackingUpLog.setId(String.valueOf(IdWorker.getId()));
             stackingUpLog.setBilletNo(x.getBilletNos());
+            // 根据坯号查询 对应的钢坯基础信息,获取到炉号
+            String[] parts = x.getBilletNos().split(",");
+            //4 获取所有的坯号集合
+            LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.in(BilletBasicInfo::getBilletNo, Arrays.asList(parts));
+            List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
+            BilletBasicInfo billetBasicInfo = billetBasicInfoList.stream().findFirst().orElse(null);
             stackingUpLog.setAmount(4); // 支数
             stackingUpLog.setLayer(x.getLayer());// 堆垛层号(1-20)
             stackingUpLog.setAddress(x.getAddress());// 堆垛编号(1-9)
-            stackingUpLog.setShift(finalCacheShint1);
-            stackingUpLog.setShiftGroup(finalCacheShintGroup1);
+            stackingUpLog.setShift(billetBasicInfo.getShift());
+            stackingUpLog.setShiftGroup(billetBasicInfo.getShiftGroup());
             stackingUpLog.setStackAddr(billetHotsendTypeConfig.getTypeName());
             stackingUpLogList.add(stackingUpLog);
         });
         stackingUpLogService.saveBatch(stackingUpLogList);
         // 根据铸机号、班次、班别 查询当天交班记录 存在就更新当前起跺总支数
-        updateShiftInfoByType(billetHotsend.getCcmNo(), cacheShint, cacheShintGroup, stackingUpLogList.size() * 4, "stackingUp");
+        updateShiftInfoByType(billetHotsend.getCcmNo(), finalCacheShint, finalCacheShintGroup, stackingUpLogList.size() * 4, "stackingUp");
+    }
+
+    @Override
+    @Transactional
+    public JSONObject addStackInfo(LoadingParams loadingParams) {
+        JSONObject result = new JSONObject();
+        List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList = loadingParams.getStackingAndLoadingVehiclesList();
+        if (oConvertUtils.listIsEmpty(stackingAndLoadingVehiclesList)){
+            result.put("fail", "堆垛信息为空,保存失败");
+            return result;
+        }
+        // 根据billetHotsendTypeConfigId 查询基础垛位信息
+        BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getById(loadingParams.getBilletHotsendTypeConfigId());
+
+        BilletHotsend billetHotsend = loadingParams.getBilletHotsend();
+
+        handleAddStackInfo(billetHotsend, stackingAndLoadingVehiclesList, loadingParams, billetHotsendTypeConfig);
+
+        List<RollClubCommon> rollClubCommonList= loadingParams.getRollClubCommonList();
+        Map<String, List<RollClubCommon>> rollClubCommonListttt = groupByShiftAttributes(rollClubCommonList);
+        for (Map.Entry<String, List<RollClubCommon>> entry : rollClubCommonListttt.entrySet()) {
+            String[] parts = entry.getKey().split(",");
+            billetHotsend.setHeatNo(parts[0]);// 炉号
+            billetHotsend.setShiftGroup(parts[1]);// 班组
+            billetHotsend.setShift(parts[2]);// 班别
+            List<RollClubCommon> groupRollClubCommonList = entry.getValue();
+            LambdaQueryWrapper<BilletHotsend> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsend::getCcmNo, billetHotsend.getCcmNo())
+                    .eq(BilletHotsend::getHeatNo, billetHotsend.getHeatNo())
+                    .eq(BilletHotsend::getShift,  billetHotsend.getShift())
+                    .eq(BilletHotsend::getShiftGroup, billetHotsend.getShiftGroup());
+            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper);
+            if (oConvertUtils.isEmpty(idExistBh)){
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                result.put("fail", "钢坯热送单为空,新增堆垛保存失败");
+                return result;
+            }
+            billetHotsend.setId(idExistBh.getId());
+            // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
+            billetHotsend.setStackNum(idExistBh.getStackNum() + groupRollClubCommonList.size()); // 堆垛总支数
+            billetHotsend.setUpdateTime(new Date());
+            billetHotsendBaseService.updateById(billetHotsend);
+        }
+
         //4 获取所有的坯号集合
         List<String> billetNosList = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getBilletNos)
                 .flatMap(billetNoss -> {
@@ -918,6 +935,8 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
             x.setBhtcId(loadingParams.getBilletHotsendTypeConfigId());
         });
         billetBasicInfoService.saveOrUpdateBatch(billetBasicInfoList);
+        result.put("success", "保存堆垛操作成功");
+        return result;
     }
 
     @Override
@@ -993,7 +1012,14 @@ public class StackingAndLoadingVehiclesServiceImpl extends ServiceImpl<StackingA
         return "钢坯叛废成功!";
     }
 
-
+    /**
+     * 根据班组班别对钢坯信息进行分组
+     * @param rollClubCommonList
+     * @return
+     */
+    public static Map<String, List<RollClubCommon>> groupByShiftAttributes(List<RollClubCommon> rollClubCommonList) {
+        return rollClubCommonList.stream().collect(Collectors.groupingBy(rollClubCommon -> rollClubCommon.getHeatNo() + "," + rollClubCommon.getShiftGroup() + "," + rollClubCommon.getShift()));
+    }
     /**
      * 初始化StackingAndLoadingVehicles对象
      * @return