فهرست منبع

编辑出坯量时计算分炉的出坯量

lingpeng.li 2 روز پیش
والد
کامیت
0f2a337c65

+ 107 - 110
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/service/impl/BilletHotsendChangeShiftServiceImpl.java

@@ -449,14 +449,39 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
 
                 // 热送统计
                 try {
-                    JsonNode rollDetails = objectMapper.readTree(record.getRollClubOneDetails());
-                    JsonNode lengthGroupCount = rollDetails.path("lengthGroupCount");
+                    if (StringUtils.isNotBlank(record.getRollClubOneDetails())) {
+                        JsonNode rollDetails = objectMapper.readTree(record.getRollClubOneDetails());
+                        JsonNode lengthGroupCount = rollDetails.path("lengthGroupCount");
+
+                        if (lengthGroupCount.isObject()) {
+                            for (Iterator<Map.Entry<String, JsonNode>> it = lengthGroupCount.fields(); it.hasNext(); ) {
+                                Map.Entry<String, JsonNode> entry = it.next();
+                                String mm = entry.getKey();
+                                int count = entry.getValue().asInt(0);
+
+                                BigDecimal singleWeight = new BigDecimal(mm)
+                                        .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
+                                        .multiply(meterWeightFactor)
+                                        .setScale(3, RoundingMode.HALF_UP);
+
+                                BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
+
+                                mergedCountHotSend.merge(mm, count, Integer::sum);
+                                mergedWeightHotSend.merge(mm, weight, BigDecimal::add);
+                                mergedCount.merge(mm, count, Integer::sum);
+                                mergedWeight.merge(mm, weight, BigDecimal::add);
+                            }
+                        }
+                    }
+                } catch (Exception ignored) {}
 
-                    if (lengthGroupCount.isObject()) {
-                        for (Iterator<Map.Entry<String, JsonNode>> it = lengthGroupCount.fields(); it.hasNext(); ) {
-                            Map.Entry<String, JsonNode> entry = it.next();
-                            String mm = entry.getKey();
-                            int count = entry.getValue().asInt(0);
+                // 热装统计
+                try {
+                    if (StringUtils.isNotBlank(record.getHotChargeLength())) {
+                        JsonNode hotArray = objectMapper.readTree(record.getHotChargeLength());
+                        for (JsonNode node : hotArray) {
+                            String mm = node.path("hotChargeLength").asText();
+                            int count = node.path("totalCount").asInt(0);
 
                             BigDecimal singleWeight = new BigDecimal(mm)
                                     .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
@@ -465,134 +490,106 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
 
                             BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
 
-                            mergedCountHotSend.merge(mm, count, Integer::sum);
-                            mergedWeightHotSend.merge(mm, weight, BigDecimal::add);
-
+                            mergedCountHotFeign.merge(mm, count, Integer::sum);
+                            mergedWeightHotFeign.merge(mm, weight, BigDecimal::add);
                             mergedCount.merge(mm, count, Integer::sum);
                             mergedWeight.merge(mm, weight, BigDecimal::add);
                         }
                     }
-                } catch (Exception ignored) {
-                }
-
-                // 热装统计
-                try {
-                    JsonNode hotArray = objectMapper.readTree(record.getHotChargeLength());
-                    for (JsonNode node : hotArray) {
-                        String mm = node.path("hotChargeLength").asText();
-                        int count = node.path("totalCount").asInt(0);
-
-                        BigDecimal singleWeight = new BigDecimal(mm)
-                                .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
-                                .multiply(meterWeightFactor)
-                                .setScale(3, RoundingMode.HALF_UP);
-
-                        BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
-
-                        mergedCountHotFeign.merge(mm, count, Integer::sum);
-                        mergedWeightHotFeign.merge(mm, weight, BigDecimal::add);
-
-                        mergedCount.merge(mm, count, Integer::sum);
-                        mergedWeight.merge(mm, weight, BigDecimal::add);
-                    }
-                } catch (Exception ignored) {
-                }
+                } catch (Exception ignored) {}
 
                 // 堆垛统计
                 try {
-                    JsonNode stackArray = objectMapper.readTree(record.getStackLength());
-                    for (JsonNode node : stackArray) {
-                        String mm = node.path("stackingLength").asText();
-                        int count = node.path("stackingCount").asInt(0);
-
-                        BigDecimal singleWeight = new BigDecimal(mm)
-                                .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
-                                .multiply(meterWeightFactor)
-                                .setScale(3, RoundingMode.HALF_UP);
+                    if (StringUtils.isNotBlank(record.getStackLength())) {
+                        JsonNode stackArray = objectMapper.readTree(record.getStackLength());
+                        for (JsonNode node : stackArray) {
+                            String mm = node.path("stackingLength").asText();
+                            int count = node.path("stackingCount").asInt(0);
 
-                        BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
-
-                        mergedCountStack.merge(mm, count, Integer::sum);
-                        mergedWeightStack.merge(mm, weight, BigDecimal::add);
+                            BigDecimal singleWeight = new BigDecimal(mm)
+                                    .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
+                                    .multiply(meterWeightFactor)
+                                    .setScale(3, RoundingMode.HALF_UP);
 
-                        mergedCount.merge(mm, count, Integer::sum);
-                        mergedWeight.merge(mm, weight, BigDecimal::add);
-                    }
-                } catch (Exception ignored) {
-                }
+                            BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
 
-                try {
-                    JsonNode hotArray = objectMapper.readTree(record.getHotChargeLength());
-                    for (JsonNode node : hotArray) {
-                        String mm = node.path("hotChargeLength").asText(); // 定尺
-                        int count = node.path("totalCount").asInt(0);
-                        String destination = node.path("hotChargeDestination").asText(); // 目的地
-
-                        if (!destinationCountMap.containsKey(destination)) {
-                            continue; // 不属于目标五类,跳过
+                            mergedCountStack.merge(mm, count, Integer::sum);
+                            mergedWeightStack.merge(mm, weight, BigDecimal::add);
+                            mergedCount.merge(mm, count, Integer::sum);
+                            mergedWeight.merge(mm, weight, BigDecimal::add);
                         }
-
-                        // 单重
-                        BigDecimal singleWeight = new BigDecimal(mm)
-                                .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
-                                .multiply(meterWeightFactor)
-                                .setScale(3, RoundingMode.HALF_UP);
-
-                        // 总重
-                        BigDecimal totalWeightForThis = singleWeight.multiply(BigDecimal.valueOf(count));
-
-                        // 累加支数
-                        Map<String, Integer> countMap = destinationCountMap.get(destination);
-                        countMap.merge(mm, count, Integer::sum);
-
-                        // 累加重量
-                        Map<String, BigDecimal> weightMap = destinationWeightMap.get(destination);
-                        weightMap.merge(mm, totalWeightForThis, BigDecimal::add);
                     }
-                } catch (Exception ignored) {
-                }
+                } catch (Exception ignored) {}
 
+                // 热装目的地分类统计
                 try {
-                    JsonNode rollClubOneNode = objectMapper.readTree(record.getRollClubOneDetails());
-                    JsonNode lengthGroupNode = rollClubOneNode.path("lengthGroupCount");
-
-                    if (lengthGroupNode.isObject()) {
-                        for (Iterator<Map.Entry<String, JsonNode>> it = lengthGroupNode.fields(); it.hasNext(); ) {
-                            Map.Entry<String, JsonNode> entry = it.next();
-                            String length = entry.getKey();
-                            int count = entry.getValue().asInt(0);
+                    if (StringUtils.isNotBlank(record.getHotChargeLength())) {
+                        JsonNode hotArray = objectMapper.readTree(record.getHotChargeLength());
+                        for (JsonNode node : hotArray) {
+                            String mm = node.path("hotChargeLength").asText();
+                            int count = node.path("totalCount").asInt(0);
+                            String destination = node.path("hotChargeDestination").asText();
+
+                            if (!destinationCountMap.containsKey(destination)) {
+                                continue;
+                            }
 
-                            BigDecimal singleWeight = new BigDecimal(length)
+                            BigDecimal singleWeight = new BigDecimal(mm)
                                     .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
                                     .multiply(meterWeightFactor)
                                     .setScale(3, RoundingMode.HALF_UP);
 
-                            BigDecimal totalWeight = singleWeight.multiply(BigDecimal.valueOf(count)).setScale(4, RoundingMode.HALF_UP);
-
-                            DestinationStatisticsDetails stat = rollClubOneMap.get(length);
-                            if (stat == null) {
-                                stat = new DestinationStatisticsDetails();
-                                stat.setSize(length);
-                                stat.setNums(count);
-                                stat.setBlankOutput(totalWeight.doubleValue());
-                                stat.setCcmNo(billetHotsendChangeShift.getCcmNo());
-                                rollClubOneMap.put(length, stat);
-                            } else {
-                                stat.setNums(stat.getNums() + count);
-                                double updatedWeight = BigDecimal.valueOf(stat.getBlankOutput())
-                                        .add(totalWeight)
-                                        .setScale(3, RoundingMode.HALF_UP)
-                                        .doubleValue();
-
-                                stat.setBlankOutput(updatedWeight);
+                            BigDecimal totalWeightForThis = singleWeight.multiply(BigDecimal.valueOf(count));
+
+                            destinationCountMap.get(destination).merge(mm, count, Integer::sum);
+                            destinationWeightMap.get(destination).merge(mm, totalWeightForThis, BigDecimal::add);
+                        }
+                    }
+                } catch (Exception ignored) {}
+
+                // 单条 RollClubOneDetails 统计封装到 DestinationStatisticsDetails
+                try {
+                    if (StringUtils.isNotBlank(record.getRollClubOneDetails())) {
+                        JsonNode rollClubOneNode = objectMapper.readTree(record.getRollClubOneDetails());
+                        JsonNode lengthGroupNode = rollClubOneNode.path("lengthGroupCount");
+
+                        if (lengthGroupNode.isObject()) {
+                            for (Iterator<Map.Entry<String, JsonNode>> it = lengthGroupNode.fields(); it.hasNext(); ) {
+                                Map.Entry<String, JsonNode> entry = it.next();
+                                String length = entry.getKey();
+                                int count = entry.getValue().asInt(0);
+
+                                BigDecimal singleWeight = new BigDecimal(length)
+                                        .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
+                                        .multiply(meterWeightFactor)
+                                        .setScale(3, RoundingMode.HALF_UP);
+
+                                BigDecimal totalWeight = singleWeight.multiply(BigDecimal.valueOf(count)).setScale(4, RoundingMode.HALF_UP);
+
+                                DestinationStatisticsDetails stat = rollClubOneMap.get(length);
+                                if (stat == null) {
+                                    stat = new DestinationStatisticsDetails();
+                                    stat.setSize(length);
+                                    stat.setNums(count);
+                                    stat.setBlankOutput(totalWeight.doubleValue());
+                                    stat.setCcmNo(billetHotsendChangeShift.getCcmNo());
+                                    rollClubOneMap.put(length, stat);
+                                } else {
+                                    stat.setNums(stat.getNums() + count);
+                                    double updatedWeight = BigDecimal.valueOf(stat.getBlankOutput())
+                                            .add(totalWeight)
+                                            .setScale(3, RoundingMode.HALF_UP)
+                                            .doubleValue();
+                                    stat.setBlankOutput(updatedWeight);
+                                }
                             }
                         }
                     }
-                } catch (Exception ignored) {
-                }
+                } catch (Exception ignored) {}
 
             }
 
+
             // 汇总热送
             int totalHotSendCount = mergedCountHotSend.values().stream().mapToInt(Integer::intValue).sum();
             BigDecimal totalHotSendWeight = mergedWeightHotSend.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);

+ 97 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/controller/BilletOriginalProductRecordController.java

@@ -1450,11 +1450,95 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 
 		billetOriginalProductRecordService.update(updateWrapper);
 
+		BigDecimal totalWeight = BigDecimal.ZERO;
+
+		// 1. 查询前一条记录(相同 ccmNo 和 heatNo,创建时间小于当前记录 one 的)
+		LambdaQueryWrapper<BilletOriginalProductRecord> prevQuery = new LambdaQueryWrapper<>();
+		prevQuery.eq(BilletOriginalProductRecord::getCcmNo, ccmNo)
+				.eq(BilletOriginalProductRecord::getHeatNo, editDTO.getHeatNo())
+				.lt(BilletOriginalProductRecord::getCreateTime, one.getCreateTime())
+				.orderByDesc(BilletOriginalProductRecord::getCreateTime)
+				.last("LIMIT 1");
+
+		BilletOriginalProductRecord prev = billetOriginalProductRecordService.getOne(prevQuery);
+
+		// 合并两个记录
+		List<BilletOriginalProductRecord> recordsToCalc = new ArrayList<>();
+		recordsToCalc.add(one);
+		if (prev != null) {
+			recordsToCalc.add(prev);
+		}
+
+		ObjectMapper objectMapper = new ObjectMapper();
+		String meterWeightKey = String.format("ccmno:meter:weight:%s", ccmNo);
+		String mWeightStr = oConvertUtils.getString(redisTemplate.opsForValue().get(meterWeightKey));
+		BigDecimal meterWeightFactor = StringUtils.isNotEmpty(mWeightStr)
+				? new BigDecimal(mWeightStr)
+				: new BigDecimal("0.2265"); // 如果没有米重数据,使用 0.2265 作为系数
+
+		for (BilletOriginalProductRecord record : recordsToCalc) {
+			// 处理 RollClubOneDetails
+			try {
+				if (StringUtils.isNotBlank(record.getRollClubOneDetails())) {
+					JsonNode rollDetails = objectMapper.readTree(record.getRollClubOneDetails());
+					JsonNode lengthGroupCount = rollDetails.path("lengthGroupCount");
+
+					if (lengthGroupCount.isObject()) {
+						Iterator<Map.Entry<String, JsonNode>> it = lengthGroupCount.fields();
+						while (it.hasNext()) {
+							Map.Entry<String, JsonNode> entry = it.next();
+							String mm = entry.getKey();
+							int count = entry.getValue().asInt(0);
+
+							BigDecimal weight = calcWeight(mm, count, meterWeightFactor);
+							totalWeight = totalWeight.add(weight);
+						}
+					}
+				}
+			} catch (Exception e) {
+				log.warn("解析RollClubOneDetails失败: {}", e.getMessage());
+			}
+
+			// 处理 HotChargeLength
+			try {
+				if (StringUtils.isNotBlank(record.getHotChargeLength())) {
+					JsonNode hotArray = objectMapper.readTree(record.getHotChargeLength());
+					for (JsonNode node : hotArray) {
+						String mm = node.path("hotChargeLength").asText();
+						int count = node.path("totalCount").asInt(0);
+
+						BigDecimal weight = calcWeight(mm, count, meterWeightFactor);
+						totalWeight = totalWeight.add(weight);
+					}
+				}
+			} catch (Exception e) {
+				log.warn("解析HotChargeLength失败: {}", e.getMessage());
+			}
+
+			// 处理 StackLength
+			try {
+				if (StringUtils.isNotBlank(record.getStackLength())) {
+					JsonNode stackArray = objectMapper.readTree(record.getStackLength());
+					for (JsonNode node : stackArray) {
+						String mm = node.path("stackingLength").asText();
+						int count = node.path("stackingCount").asInt(0);
+
+						BigDecimal weight = calcWeight(mm, count, meterWeightFactor);
+						totalWeight = totalWeight.add(weight);
+					}
+				}
+			} catch (Exception e) {
+				log.warn("解析StackLength失败: {}", e.getMessage());
+			}
+
+		}
+
+
 		// 5. 推送处理数据
 		HandleBilletPushDTO pushDTO = new HandleBilletPushDTO();
 		pushDTO.setCcNo(ccmNo);
 		pushDTO.setHeatNo(editDTO.getHeatNo());
-		pushDTO.setBilletWt(editDTO.getBlankOutput());
+		pushDTO.setBilletWt(totalWeight.toPlainString());
 
 		billetOriginalProductRecordService.handleBilletPush(pushDTO);
 
@@ -1485,6 +1569,18 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 		}
 	}
 
+	private BigDecimal calcWeight(String mm, int count, BigDecimal meterWeightFactor) {
+		try {
+			BigDecimal singleWeight = new BigDecimal(mm)
+					.divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
+					.multiply(meterWeightFactor)
+					.setScale(3, RoundingMode.HALF_UP);
+			return singleWeight.multiply(BigDecimal.valueOf(count));
+		} catch (Exception e) {
+			return BigDecimal.ZERO;
+		}
+	}
+
 
 	/**
 	 * 获取当前班次下所有炉次浇筑数据

+ 1 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/dto/HandleBilletPushDTO.java

@@ -20,6 +20,6 @@ public class HandleBilletPushDTO {
     /**
      * 出坯量
      */
-    private BigDecimal billetWt;
+    private String billetWt;
 
 }

+ 3 - 13
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/service/impl/BilletOriginalProductRecordServiceImpl.java

@@ -359,16 +359,6 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
     @Override
     public void initMonthlyStatisticsIfMissing(String ccmNo,String changeShiftId) {
 
-        // 参数校验
-        if (ccmNo == null || ccmNo.trim().isEmpty()) {
-            log.warn("initMonthlyStatisticsIfMissing 失败:ccmNo 不能为空");
-            return;
-        }
-        if (changeShiftId == null || changeShiftId.trim().isEmpty()) {
-            log.warn("initMonthlyStatisticsIfMissing 失败:changeShiftId 不能为空");
-            return;
-        }
-
         Date monthStart = DateUtils.getMonthStart(new Date());
         Date searchStart = new Date(monthStart.getTime() - 10 * 60 * 1000); // 向前推10分钟
         Date now = new Date();
@@ -521,10 +511,10 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
         // 远程调用
         BilletPushResponse response = sendRequestAndLog(pushDTO);
         if (response != null) {
-            // 远程调用成功后,保存或更新推送日志
-            log.info("远程推送装运单接收接口成功!");
+            // 打印请求参数
+            log.info("远程推送炼钢一体化出坯量成功! 请求参数: {}", JSON.toJSONString(pushDTO));
         } else {
-            log.error("远程调用装运单接收接口失败!");
+            log.error("远程推送炼钢一体化出坯量成功! 请求参数: {}", JSON.toJSONString(pushDTO));
             throw new RuntimeException("远程调用装运单接收接口失败!");
         }