|
@@ -1,4 +1,6 @@
|
|
|
package org.jeecg.modules.billet.billetOriginalProductRecord.controller;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -28,6 +30,8 @@ import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOrigina
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.HeatsActualsInfo;
|
|
|
+import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
|
|
|
+import org.jeecg.modules.billet.storageBill.service.IStorageBillPrintService;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -68,6 +72,8 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
@Autowired
|
|
|
private IBilletBasicInfoService billetBasicInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IStorageBillPrintService storageBillPrintService;
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
@@ -495,29 +501,122 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
heatsActualsInfo.setStacking(jsonResult);
|
|
|
}
|
|
|
|
|
|
- // 定义需要筛选的belongTable列表
|
|
|
- List<String> targetTables = Arrays.asList("roll_club_two", "roll_club_three");
|
|
|
-
|
|
|
- // 热装过滤并计算
|
|
|
- List<BilletBasicInfo> filterHotChargeList = billetBasicInfoList.stream()
|
|
|
- .filter(info -> targetTables.contains(info.getBelongTable()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (oConvertUtils.listIsNotEmpty(filterHotChargeList)){
|
|
|
- // 计算总重(保留4位小数)
|
|
|
- double totalWeight = filterHotChargeList.stream()
|
|
|
- .mapToDouble(BilletBasicInfo::getBilletWeight)
|
|
|
- .sum();
|
|
|
- totalWeight = Math.round(totalWeight * 10000) / 10000.0;
|
|
|
-
|
|
|
- // 统计总数
|
|
|
- int totalCount = filterHotChargeList.size();
|
|
|
-
|
|
|
- // 转为JSON字符串
|
|
|
- Map<String, Object> hotChargeMap = new HashMap<>();
|
|
|
- hotChargeMap.put("hotChargeTotalWeight", totalWeight);
|
|
|
- hotChargeMap.put("hotChargeTotalCount", totalCount);
|
|
|
- String jsonResult = JSON.toJSONString(hotChargeMap); // 使用FastJSON转换
|
|
|
- heatsActualsInfo.setHotCharge(jsonResult);
|
|
|
+ // 根据铸机号、炉号查询装运单打印表
|
|
|
+ String heatNo = x.getHeatNo();
|
|
|
+ // 构建安全的 JSON 路径表达式
|
|
|
+ String jsonPath = "$.\"" + heatNo + "\"";
|
|
|
+ List<StorageBillPrint> storageBillPrintList = storageBillPrintService.list(
|
|
|
+ new QueryWrapper<StorageBillPrint>()
|
|
|
+ .lambda()
|
|
|
+ .eq(StorageBillPrint::getCcmNo, x.getCcmNo())
|
|
|
+ .apply("JSON_EXTRACT(heat_no, '" + jsonPath + "') IS NOT NULL")
|
|
|
+ );
|
|
|
+ if (oConvertUtils.listIsNotEmpty(storageBillPrintList)){
|
|
|
+ List<Map<String, Object>> hotChargeList = new ArrayList<>();
|
|
|
+ // 遍历列表,解析每个 heatNo JSON 并累加数量
|
|
|
+ for (StorageBillPrint print : storageBillPrintList) {
|
|
|
+ Map<String, Object> hotChargeMap = new HashMap<>();
|
|
|
+ String jsonHeatNo = print.getHeatNo();
|
|
|
+
|
|
|
+ // 初始化当前记录的数量和重量
|
|
|
+ Integer currentCount = 0;
|
|
|
+ BigDecimal currentWeight = BigDecimal.ZERO;
|
|
|
+ // 处理可能包含逗号的定尺值
|
|
|
+ String sizeValue = print.getSize();
|
|
|
+ String lengthValue = "0"; // 默认值
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(sizeValue)) {
|
|
|
+ lengthValue = sizeValue.contains(",")
|
|
|
+ ? sizeValue.split(",")[0] // 提取第一个值
|
|
|
+ : sizeValue; // 否则使用原值
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(jsonHeatNo)) {
|
|
|
+ try {
|
|
|
+ // 解析 JSON 对象
|
|
|
+ JSONObject heatNoJson = JSON.parseObject(jsonHeatNo);
|
|
|
+
|
|
|
+ // 获取指定炉号对应的数量(如果存在)
|
|
|
+ if (heatNoJson.containsKey(heatNo)) {
|
|
|
+ Integer count = heatNoJson.getInteger(heatNo);
|
|
|
+ if (count != null) {
|
|
|
+ currentCount = count;
|
|
|
+ // 使用 BigDecimal 计算重量,避免精度丢失
|
|
|
+ BigDecimal size = new BigDecimal(lengthValue);
|
|
|
+ BigDecimal factor = new BigDecimal("0.2265");
|
|
|
+ currentWeight = size.divide(new BigDecimal("1000"), 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(factor)
|
|
|
+ .multiply(new BigDecimal(count))
|
|
|
+ .setScale(4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析 heatNo JSON 失败: {}", jsonHeatNo, e);
|
|
|
+ continue; // 跳过当前记录
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置热装信息
|
|
|
+ hotChargeMap.put("hotChargeLength", lengthValue);
|
|
|
+ hotChargeMap.put("hotChargeTotalCount", currentCount);
|
|
|
+ hotChargeMap.put("hotChargeTotalWeight", currentWeight.toPlainString());
|
|
|
+
|
|
|
+ // 设置目的地简称(添加默认值)
|
|
|
+ String destination = "未知";
|
|
|
+ if ("棒二".equals(print.getDestination())) {
|
|
|
+ destination = "roll_club_two";
|
|
|
+ } else if ("棒三".equals(print.getDestination())) {
|
|
|
+ destination = "roll_club_three";
|
|
|
+ } else if ("上若".equals(print.getDestination())) {
|
|
|
+ destination = "roll_out_shipp";
|
|
|
+ }
|
|
|
+ hotChargeMap.put("hotChargeDestination", destination);
|
|
|
+ // 将当前记录的热装信息添加到列表
|
|
|
+ hotChargeList.add(hotChargeMap);
|
|
|
+ }
|
|
|
+ // 按 hotChargeLength 和 hotChargeDestination 分组统计
|
|
|
+ Map<String, Map<String, Object>> groupedResult = new HashMap<>();
|
|
|
+
|
|
|
+ if (oConvertUtils.listIsNotEmpty(hotChargeList)) {
|
|
|
+ for (Map<String, Object> item : hotChargeList) {
|
|
|
+ // 使用 getOrDefault 避免空指针
|
|
|
+ String length = (String) item.getOrDefault("hotChargeLength", "未知");
|
|
|
+ String destination = (String) item.getOrDefault("hotChargeDestination", "未知");
|
|
|
+ Integer count = (Integer) item.getOrDefault("hotChargeTotalCount", 0);
|
|
|
+ BigDecimal weight = new BigDecimal(item.getOrDefault("hotChargeTotalWeight", "0").toString());
|
|
|
+
|
|
|
+ // 构建分组键
|
|
|
+ String groupKey = length + "_" + destination;
|
|
|
+
|
|
|
+ // 初始化或获取分组统计结果
|
|
|
+ groupedResult.computeIfAbsent(groupKey, k -> {
|
|
|
+ Map<String, Object> groupData = new HashMap<>();
|
|
|
+ groupData.put("hotChargeLength", length);
|
|
|
+ groupData.put("hotChargeDestination", destination);
|
|
|
+ groupData.put("totalCount", 0);
|
|
|
+ groupData.put("totalWeight", BigDecimal.ZERO);
|
|
|
+ return groupData;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 累加数量和重量
|
|
|
+ Map<String, Object> groupData = groupedResult.get(groupKey);
|
|
|
+ Integer totalCount = (Integer) groupData.get("totalCount") + count;
|
|
|
+ BigDecimal totalWeight = ((BigDecimal) groupData.get("totalWeight")).add(weight);
|
|
|
+
|
|
|
+ groupData.put("totalCount", totalCount);
|
|
|
+ groupData.put("totalWeight", totalWeight);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 转换为列表并格式化重量
|
|
|
+ List<Map<String, Object>> finalResult = groupedResult.values().stream()
|
|
|
+ .peek(data -> {
|
|
|
+ // 格式化重量为字符串,保留4位小数
|
|
|
+ data.put("totalWeight", ((BigDecimal) data.get("totalWeight")).toPlainString());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 使用结果...
|
|
|
+ log.info("钢坯原始记录,热装打印表分组统计结果: {}", JSON.toJSONString(finalResult));
|
|
|
+ heatsActualsInfo.setHotCharge(JSON.toJSONString(finalResult));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 按length字段分组,并统计每组的总数和总重
|