Browse Source

装运单打印数据下垛相应数据

lingpeng.li 3 weeks ago
parent
commit
651dd947aa

+ 3 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendConfig/service/IBilletHotsendTypeConfigService.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.billet.billetHotsendConfig.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
+import org.jeecg.modules.billet.storageBill.dto.StorageBillPrintAddDTO;
 
 /**
  * @Description: 钢坯类型配置
@@ -11,4 +12,6 @@ import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConf
  */
 public interface IBilletHotsendTypeConfigService extends IService<BilletHotsendTypeConfig> {
 
+    BilletHotsendTypeConfig getByParam(StorageBillPrintAddDTO addDTO);
+
 }

+ 30 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendConfig/service/impl/BilletHotsendTypeConfigServiceImpl.java

@@ -1,9 +1,12 @@
 package org.jeecg.modules.billet.billetHotsendConfig.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
 import org.jeecg.modules.billet.billetHotsendConfig.mapper.BilletHotsendTypeConfigMapper;
 import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
+import org.jeecg.modules.billet.storageBill.dto.StorageBillPrintAddDTO;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 /**
@@ -15,4 +18,31 @@ import org.springframework.stereotype.Service;
 @Service
 public class BilletHotsendTypeConfigServiceImpl extends ServiceImpl<BilletHotsendTypeConfigMapper, BilletHotsendTypeConfig> implements IBilletHotsendTypeConfigService {
 
+    @Autowired
+    private BilletHotsendTypeConfigMapper billetHotsendTypeConfigMapper;
+
+    @Override
+    public BilletHotsendTypeConfig getByParam(StorageBillPrintAddDTO addDTO) {
+        if (addDTO == null) {
+            log.warn("getByTypeName 参数 addDTO 为空");
+            return null;
+        }
+
+        String ccmNo = addDTO.getCcmNo();
+        String destination = addDTO.getDestination();
+
+        if (ccmNo == null || destination == null) {
+            log.warn("getByTypeName 参数字段为空: ccmNo=" + ccmNo + ", destination=" + destination);
+            return null;
+        }
+
+        LambdaQueryWrapper<BilletHotsendTypeConfig> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(BilletHotsendTypeConfig::getCastMachine, ccmNo)
+                .eq(BilletHotsendTypeConfig::getTypeName, destination)
+                .orderByDesc(BilletHotsendTypeConfig::getCreateTime)
+                .last("limit 1");
+
+        return billetHotsendTypeConfigMapper.selectOne(queryWrapper);
+    }
+
 }

+ 1 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -2851,6 +2851,7 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 	@ApiOperation(value="装运单打印表-添加", notes="装运单打印表-添加")
 	@PostMapping(value = "/saveStorageBillPrint")
 	public Result<String> saveStorageBillPrint(@RequestBody StorageBillPrintAddDTO addDTO) {
+		storageBillPrintService.loadingHandle(addDTO);
 		storageBillPrintService.saveStorageBillPrint(addDTO);
 		return Result.OK("添加成功!");
 	}

+ 11 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/IStorageBillPrintService.java

@@ -1,12 +1,20 @@
 package org.jeecg.modules.billet.storageBill.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
+import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.vo.LoadingParams;
 import org.jeecg.modules.billet.storageBill.dto.StorageBillPrintAddDTO;
+import org.jeecg.modules.billet.storageBill.entity.StorageBill;
 import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
 import org.jeecg.modules.billet.storageBill.vo.StorageBillPrintVO;
 import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoDetailVO;
 import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoInvoicingVO;
 
+import java.util.List;
+
 /**
  * @Description: 装运单打印表
  * @Author: jeecg-boot
@@ -23,4 +31,7 @@ public interface IStorageBillPrintService extends IService<StorageBillPrint> {
 
     StorageCenterHeatNoDetailVO storageCenterByHeatNo(String heatNo);
 
+    JSONObject loadingHandle(StorageBillPrintAddDTO addDTO);
+
+    void handleStackDepartCommon(BilletHotsend billetHotsend, List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList, StorageBillPrintAddDTO addDTO, BilletHotsendTypeConfig billetHotsendTypeConfig, StorageBill storageBill);
 }

+ 208 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/impl/StorageBillPrintServiceImpl.java

@@ -1,16 +1,25 @@
 package org.jeecg.modules.billet.storageBill.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 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.billet.billetHotsend.entity.BilletHotsend;
+import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
+import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
+import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.mapper.StackingAndLoadingVehiclesMapper;
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingAndLoadingVehiclesService;
 import org.jeecg.modules.billet.storageBill.dto.StorageBillPrintAddDTO;
 import org.jeecg.modules.billet.storageBill.entity.StorageBill;
 import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
@@ -22,7 +31,9 @@ import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoDetailVO;
 import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoInvoicingVO;
 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 javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -39,6 +50,7 @@ import java.util.stream.Collectors;
  * @Date: 2025-06-16
  * @Version: V1.0
  */
+@Slf4j
 @Service
 public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMapper, StorageBillPrint> implements IStorageBillPrintService {
 
@@ -51,6 +63,21 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
     @Autowired
     private StackingAndLoadingVehiclesMapper stackingAndLoadingVehiclesMapper;
 
+    @Autowired
+    private IBilletHotsendTypeConfigService billetHotsendTypeConfigService;
+
+    @Autowired
+    private IBilletHotsendBaseService billetHotsendBaseService;
+
+    @Autowired
+    private IStackingAndLoadingVehiclesService stackingAndLoadingVehiclesService;
+
+    @Autowired
+    private StorageBillPrintMapper storageBillPrintMapper;
+
+    @Autowired
+    public RedisTemplate redisTemplate;
+
     @Override
     public void saveStorageBillPrint(StorageBillPrintAddDTO addDTO) {
         if (addDTO.getStorageBillId() == null) {
@@ -147,7 +174,7 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
         if (StringUtils.isNotBlank(entity.getHeatNo())) {
             try {
                 ObjectMapper objectMapper = new ObjectMapper();
-                Map<String, Integer> heatNoMap = objectMapper.readValue(entity.getHeatNo(), new TypeReference<Map<String, Integer>>() {
+                Map<String, Integer> heatNoMap = objectMapper.readValue(entity.getHeatNo(), new com.fasterxml.jackson.core.type.TypeReference<Map<String, Integer>>() {
                 });
                 vo.setHeatNo(heatNoMap);
             } catch (JsonProcessingException e) {
@@ -1662,4 +1689,183 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
 
         return storageCenterHeatNoDetailVO;
     }
+
+    @Override
+    @Transactional
+    public JSONObject loadingHandle(StorageBillPrintAddDTO addDTO) {
+        JSONObject result = new JSONObject();
+        List<String> skippedHeatNos = new ArrayList<>();
+
+        // 根据 billetHotsendTypeConfigId 查询基础垛位信息
+        BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getByParam(addDTO);
+
+        // 查询是否已存在打印记录
+        List<StorageBillPrint> existingPrints = storageBillPrintMapper.selectList(
+                new LambdaQueryWrapper<StorageBillPrint>()
+                        .eq(StorageBillPrint::getStorageBillId, addDTO.getStorageBillId())
+        );
+        boolean alreadyPrinted = !existingPrints.isEmpty();
+
+        // 查询最新的储运单
+        StorageBill storageBill = storageBillMapper.selectOne(
+                new LambdaQueryWrapper<StorageBill>()
+                        .eq(StorageBill::getId, addDTO.getStorageBillId())
+                        .orderByDesc(StorageBill::getCreateTime)
+                        .last("limit 1")
+        );
+        if (storageBill == null) {
+            result.put("fail", "未找到对应储运单");
+            return result;
+        }
+
+        for (Map.Entry<String, Integer> entry : addDTO.getHeatNo().entrySet()) {
+            String heatNo = entry.getKey();
+            Integer currentCount = entry.getValue();
+
+            if (currentCount == null || currentCount <= 0) {
+                skippedHeatNos.add(heatNo + "(支数无效)");
+                continue;
+            }
+
+            int delta = currentCount;
+
+            if (alreadyPrinted) {
+                // 汇总历史支数
+                int previousCount = existingPrints.stream()
+                        .mapToInt(print -> {
+                            try {
+                                Map<String, Integer> heatNoMap = JSON.parseObject(
+                                        print.getHeatNo(),
+                                        new TypeReference<Map<String, Integer>>() {
+                                        }
+                                );
+                                return heatNoMap.getOrDefault(heatNo, 0);
+                            } catch (Exception e) {
+                                return 0;
+                            }
+                        })
+                        .sum();
+
+                delta = currentCount - previousCount;
+
+                if (delta <= 0) {
+                    skippedHeatNos.add(heatNo + "(未增加)");
+                    continue;
+                }
+
+                if (delta % 4 != 0) {
+                    skippedHeatNos.add(heatNo + "(增量非4倍数,剩余: " + delta + ")");
+                    continue;
+                }
+
+            } else {
+                // 首次:支数必须为4的倍数
+                if (currentCount % 4 != 0) {
+                    skippedHeatNos.add(heatNo + "(支数非4倍数)");
+                    continue;
+                }
+            }
+
+            int fetchCount = delta / 4;
+
+            // 获取传递单
+            BilletHotsend billetHotsend = billetHotsendBaseService.getOne(
+                    new LambdaQueryWrapper<BilletHotsend>()
+                            .eq(BilletHotsend::getCcmNo, addDTO.getCcmNo())
+                            .eq(BilletHotsend::getHeatNo, heatNo)
+                            .orderByDesc(BilletHotsend::getCreateTime)
+                            .last("limit 1")
+            );
+
+            // 查询垛位
+            List<StackingAndLoadingVehicles> vehicles = stackingAndLoadingVehiclesService.list(
+                    new LambdaQueryWrapper<StackingAndLoadingVehicles>()
+                            .eq(StackingAndLoadingVehicles::getCcmNo, addDTO.getCcmNo())
+                            .eq(StackingAndLoadingVehicles::getHeatNo, heatNo)
+                            .eq(StackingAndLoadingVehicles::getSize, addDTO.getSize())
+                            .orderByDesc(StackingAndLoadingVehicles::getLayer)
+                            .orderByDesc(StackingAndLoadingVehicles::getAddress)
+            );
+
+            int availableCount = vehicles.size();
+            int processCount = Math.min(fetchCount, availableCount);
+
+            if (processCount == 0) {
+                skippedHeatNos.add(heatNo + "(可用垛位不足)");
+                continue;
+            }
+
+            List<StackingAndLoadingVehicles> selected = new ArrayList<>(vehicles.subList(0, processCount));
+            vehicles.subList(0, processCount).clear();
+
+            // 执行堆垛逻辑
+            handleStackDepartCommon(billetHotsend, selected, addDTO, billetHotsendTypeConfig, storageBill);
+        }
+
+        result.put("success", "堆垛保存完成");
+//        if (!skippedHeatNos.isEmpty()) {
+//            result.put("skipped", "跳过炉号: " + String.join(",", skippedHeatNos));
+//        }
+
+        return result;
+    }
+
+
+    /**
+     * 堆垛保存、堆垛发车公共处理
+     *
+     * @param billetHotsend
+     * @param stackingAndLoadingVehiclesList
+     * @param addDTO
+     * @param billetHotsendTypeConfig
+     * @param storageBill
+     */
+    @Override
+    @Transactional
+    public void handleStackDepartCommon(BilletHotsend billetHotsend, List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList, StorageBillPrintAddDTO addDTO, BilletHotsendTypeConfig billetHotsendTypeConfig, StorageBill storageBill) {
+
+        // 根据铸机号、位置、层数、类型配置ID更新 初始化容器中的垛位信息
+        List<String> ids = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getId).collect(Collectors.toList());
+        // 创建更新包装器
+        LambdaUpdateWrapper<StackingAndLoadingVehicles> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.in(StackingAndLoadingVehicles::getId, ids)
+                .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)
+                .set(StackingAndLoadingVehicles::getUpdateTime, new Date());
+        // 执行批量更新
+        stackingAndLoadingVehiclesMapper.update(null, updateWrapper);
+
+    }
+
+    /**
+     * 根据班组班别对钢坯信息进行分组
+     *
+     * @param stackingAndLoadingVehiclesList
+     * @return
+     */
+    public static Map<String, List<StackingAndLoadingVehicles>> groupByShiftAttributes(List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList) {
+        return stackingAndLoadingVehiclesList.stream().collect(Collectors.groupingBy(stackingAndLoadingVehicles -> stackingAndLoadingVehicles.getHeatNo() + "," + stackingAndLoadingVehicles.getShiftGroup() + "," + stackingAndLoadingVehicles.getShift()));
+    }
+
+    public static Integer safeToInteger(String str) {
+        if (StringUtils.isBlank(str)) {
+            return 0;
+        }
+        try {
+            return Integer.parseInt(str);
+        } catch (NumberFormatException e) {
+            try {
+                // 尝试转成小数再取整
+                return new BigDecimal(str).intValue();
+            } catch (Exception ex) {
+                return 0;
+            }
+        }
+    }
 }