Browse Source

下垛相应数据在原始数据中减去对应定尺的数量

lingpeng.li 3 weeks ago
parent
commit
b9e232a37a

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

@@ -17,6 +17,8 @@ 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.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
+import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.mapper.StackingAndLoadingVehiclesMapper;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingAndLoadingVehiclesService;
@@ -75,6 +77,9 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
     @Autowired
     private StorageBillPrintMapper storageBillPrintMapper;
 
+    @Autowired
+    private IBilletOriginalProductRecordService billetOriginalProductRecordService;
+
     @Autowired
     public RedisTemplate redisTemplate;
 
@@ -1768,6 +1773,8 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
 
             int fetchCount = delta / 4;
 
+
+
             // 获取传递单
             BilletHotsend billetHotsend = billetHotsendBaseService.getOne(
                     new LambdaQueryWrapper<BilletHotsend>()
@@ -1800,12 +1807,48 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
 
             // 执行堆垛逻辑
             handleStackDepartCommon(billetHotsend, selected, addDTO, billetHotsendTypeConfig, storageBill);
+
+            // 每次处理完成后,扣减原始记录中的 stack_length 数量
+            LambdaQueryWrapper<BilletOriginalProductRecord> recordWrapper = new LambdaQueryWrapper<>();
+            recordWrapper.eq(BilletOriginalProductRecord::getHeatNo, heatNo)
+                    .eq(BilletOriginalProductRecord::getCcmNo, addDTO.getCcmNo())
+                    .orderByDesc(BilletOriginalProductRecord::getCreateTime)
+                    .last("limit 1");
+
+            BilletOriginalProductRecord originalRecord = billetOriginalProductRecordService.getOne(recordWrapper);
+            if (originalRecord != null && StringUtils.isNotBlank(originalRecord.getStackLength())) {
+                try {
+                    List<Map<String, Object>> stackList = JSON.parseObject(originalRecord.getStackLength(),
+                            new TypeReference<List<Map<String, Object>>>() {
+                            });
+
+                    // 找到匹配的 stackingLength 项进行扣减(定尺匹配)
+                    for (Map<String, Object> item : stackList) {
+                        Integer length = (Integer) item.get("stackingLength");
+                        if (length != null && length.toString().equals(addDTO.getSize())) {
+                            Integer count = (Integer) item.get("stackingCount");
+                            if (count != null && count >= fetchCount * 4) {
+                                item.put("stackingCount", count - fetchCount * 4);
+                            } else {
+                                // 扣减超过当前数量,按0处理
+                                item.put("stackingCount", 0);
+                            }
+                            break;
+                        }
+                    }
+
+                    // 更新记录
+                    originalRecord.setStackLength(JSON.toJSONString(stackList));
+                    billetOriginalProductRecordService.updateById(originalRecord);
+
+                } catch (Exception e) {
+                    log.error("解析或更新 stack_length 出错", e);
+                }
+            }
+
         }
 
         result.put("success", "堆垛保存完成");
-//        if (!skippedHeatNos.isEmpty()) {
-//            result.put("skipped", "跳过炉号: " + String.join(",", skippedHeatNos));
-//        }
 
         return result;
     }