|
@@ -31,6 +31,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -342,8 +343,8 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
);
|
|
|
|
|
|
// 月累计起点
|
|
|
- int monthStartCount = 1;
|
|
|
- BigDecimal monthStartWeight = BigDecimal.ONE;
|
|
|
+ int monthStartCount = 0;
|
|
|
+ BigDecimal monthStartWeight = BigDecimal.ZERO;
|
|
|
|
|
|
for (List<BilletHotsendChangeShift> shiftList : shiftByDate.values()) {
|
|
|
// 按夜 -> 白 -> 中排序
|
|
@@ -357,8 +358,8 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
.thenComparing(BilletHotsendChangeShift::getCreateTime));
|
|
|
|
|
|
// 日累计起点
|
|
|
- int dayStartCount = 1;
|
|
|
- BigDecimal dayStartWeight = BigDecimal.ONE;
|
|
|
+ int dayStartCount = 0;
|
|
|
+ BigDecimal dayStartWeight = BigDecimal.ZERO;
|
|
|
|
|
|
for (BilletHotsendChangeShift shift : shiftList) {
|
|
|
QualityInspectionStatistics existing = qualityInspectionStatisticsMapper.selectOne(
|
|
@@ -368,15 +369,15 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
|
|
|
// 已存在且已交班,跳过
|
|
|
if (existing != null && shift.getChangeShiftTime() != null) {
|
|
|
- int dayEndCount = dayStartCount + existing.getClassTotalCount() - 1;
|
|
|
- BigDecimal dayEndWeight = dayStartWeight.add(existing.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- dayStartCount = dayEndCount + 1;
|
|
|
- dayStartWeight = dayEndWeight.add(BigDecimal.ONE);
|
|
|
-
|
|
|
- int monthEndCount = monthStartCount + existing.getClassTotalCount() - 1;
|
|
|
- BigDecimal monthEndWeight = monthStartWeight.add(existing.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- monthStartCount = monthEndCount + 1;
|
|
|
- monthStartWeight = monthEndWeight.add(BigDecimal.ONE);
|
|
|
+ int dayEndCount = dayStartCount + existing.getClassTotalCount();
|
|
|
+ BigDecimal dayEndWeight = dayStartWeight.add(existing.getClassTotalWeight());
|
|
|
+ dayStartCount = dayEndCount;
|
|
|
+ dayStartWeight = dayEndWeight;
|
|
|
+
|
|
|
+ int monthEndCount = monthStartCount + existing.getClassTotalCount();
|
|
|
+ BigDecimal monthEndWeight = monthStartWeight.add(existing.getClassTotalWeight());
|
|
|
+ monthStartCount = monthEndCount;
|
|
|
+ monthStartWeight = monthEndWeight;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -400,26 +401,29 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
record.setDayStartHeatCount(vo.getDayStartHeatCount());
|
|
|
record.setDayEndHeatCount(vo.getDayEndHeatCount());
|
|
|
record.setDayHeatCount(vo.getDayHeatCount());
|
|
|
+ record.setMonthStartHeatCount(vo.getMonthStartHeatCount());
|
|
|
+ record.setMonthEndHeatCount(vo.getMonthEndHeatCount());
|
|
|
+ record.setMonthHeatCount(vo.getMonthHeatCount());
|
|
|
|
|
|
// 日累计
|
|
|
- int dayEndCount = dayStartCount + vo.getClassTotalCount() - 1;
|
|
|
- BigDecimal dayEndWeight = dayStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
+ int dayEndCount = dayStartCount + vo.getClassTotalCount();
|
|
|
+ BigDecimal dayEndWeight = dayStartWeight.add(vo.getClassTotalWeight());
|
|
|
record.setDayStartCount(dayStartCount);
|
|
|
record.setDayStartWeight(dayStartWeight);
|
|
|
record.setDayEndCount(dayEndCount);
|
|
|
record.setDayEndWeight(dayEndWeight);
|
|
|
- dayStartCount = dayEndCount + 1;
|
|
|
- dayStartWeight = dayEndWeight.add(BigDecimal.ONE);
|
|
|
+ dayStartCount = dayEndCount;
|
|
|
+ dayStartWeight = dayEndWeight;
|
|
|
|
|
|
// 月累计
|
|
|
- int monthEndCount = monthStartCount + vo.getClassTotalCount() - 1;
|
|
|
- BigDecimal monthEndWeight = monthStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
+ int monthEndCount = monthStartCount + vo.getClassTotalCount();
|
|
|
+ BigDecimal monthEndWeight = monthStartWeight.add(vo.getClassTotalWeight());
|
|
|
record.setMonthStartCount(monthStartCount);
|
|
|
record.setMonthStartWeight(monthStartWeight);
|
|
|
record.setMonthEndCount(monthEndCount);
|
|
|
record.setMonthEndWeight(monthEndWeight);
|
|
|
- monthStartCount = monthEndCount + 1;
|
|
|
- monthStartWeight = monthEndWeight.add(BigDecimal.ONE);
|
|
|
+ monthStartCount = monthEndCount;
|
|
|
+ monthStartWeight = monthEndWeight;
|
|
|
|
|
|
if (existing != null) {
|
|
|
qualityInspectionStatisticsMapper.updateById(record);
|
|
@@ -471,29 +475,21 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
try {
|
|
|
JsonNode rollDetails = objectMapper.readTree(record.getRollClubOneDetails());
|
|
|
JsonNode lengthGroupCount = rollDetails.path("lengthGroupCount");
|
|
|
- BigDecimal totalWeight = rollDetails.path("directRollingTotalWeight").decimalValue();
|
|
|
- int totalCount = rollDetails.path("directRollingTotalCount").asInt(1);
|
|
|
+
|
|
|
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);
|
|
|
|
|
|
- LambdaQueryWrapper<BilletRulerConfig> configQuery = new LambdaQueryWrapper<BilletRulerConfig>()
|
|
|
- .eq(BilletRulerConfig::getLength, Integer.valueOf(mm));
|
|
|
- BilletRulerConfig rulerConfig = billetRulerConfigMapper.selectOne(configQuery);
|
|
|
-
|
|
|
- BigDecimal weight;
|
|
|
- if (rulerConfig != null && rulerConfig.getWeight() != null) {
|
|
|
- weight = BigDecimal.valueOf(rulerConfig.getWeight()).multiply(BigDecimal.valueOf(count));
|
|
|
- } else {
|
|
|
- weight = (totalCount > 0)
|
|
|
- ? totalWeight.divide(BigDecimal.valueOf(totalCount), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(count))
|
|
|
- : BigDecimal.ZERO;
|
|
|
- }
|
|
|
+ // 1. 计算单支重量:(定尺 ÷ 1000) × 米重系数,保留三位小数
|
|
|
+ BigDecimal singleWeight = new BigDecimal(mm)
|
|
|
+ .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(meterWeightFactor)
|
|
|
+ .setScale(3, RoundingMode.HALF_UP);
|
|
|
|
|
|
- // 应用米重系数
|
|
|
- weight = weight.multiply(meterWeightFactor);
|
|
|
+ // 2. 单支重量乘以支数得到总重量
|
|
|
+ BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
|
|
|
|
|
|
mergedCount.merge(mm, count, Integer::sum);
|
|
|
mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
@@ -506,10 +502,15 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
for (JsonNode node : hotArray) {
|
|
|
String mm = node.path("hotChargeLength").asText();
|
|
|
int count = node.path("totalCount").asInt(0);
|
|
|
- BigDecimal weight = new BigDecimal(node.path("totalWeight").asText("0"));
|
|
|
|
|
|
- // 应用米重系数
|
|
|
- weight = weight.multiply(meterWeightFactor);
|
|
|
+ // 1. 计算单支重量:(定尺 ÷ 1000) × 米重系数,保留三位小数
|
|
|
+ BigDecimal singleWeight = new BigDecimal(mm)
|
|
|
+ .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(meterWeightFactor)
|
|
|
+ .setScale(3, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 2. 单支重量乘以支数得到总重量
|
|
|
+ BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
|
|
|
|
|
|
mergedCount.merge(mm, count, Integer::sum);
|
|
|
mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
@@ -521,10 +522,15 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
for (JsonNode node : stackArray) {
|
|
|
String mm = node.path("stackingLength").asText();
|
|
|
int count = node.path("stackingCount").asInt(0);
|
|
|
- BigDecimal weight = new BigDecimal(node.path("stackingWeight").asText("0"));
|
|
|
|
|
|
- // 应用米重系数
|
|
|
- weight = weight.multiply(meterWeightFactor);
|
|
|
+ // 1. 计算单支重量:(定尺 ÷ 1000) × 米重系数,保留三位小数
|
|
|
+ BigDecimal singleWeight = new BigDecimal(mm)
|
|
|
+ .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(meterWeightFactor)
|
|
|
+ .setScale(3, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 2. 单支重量乘以支数得到总重量
|
|
|
+ BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(count));
|
|
|
|
|
|
mergedCount.merge(mm, count, Integer::sum);
|
|
|
mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
@@ -572,7 +578,7 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
int classHeatNum = records.size();
|
|
|
|
|
|
// 初始化炉数相关统计
|
|
|
- int dayStartHeatCount = 1;
|
|
|
+ int dayStartHeatCount = 0;
|
|
|
int dayEndHeatCount = classHeatNum;
|
|
|
int dayHeatCount = classHeatNum;
|
|
|
|
|
@@ -584,18 +590,18 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
dayTotalWeight = dayTotalWeight.add(prevVO.getClassTotalWeight());
|
|
|
|
|
|
// 计算累计炉数位置
|
|
|
- dayStartHeatCount = prevVO.getDayEndHeatCount() + 1;
|
|
|
+ dayStartHeatCount = prevVO.getDayEndHeatCount();
|
|
|
dayHeatCount += prevVO.getClassHeatNum();
|
|
|
}
|
|
|
|
|
|
- dayEndHeatCount = dayStartHeatCount + classHeatNum - 1;
|
|
|
+ dayEndHeatCount = dayStartHeatCount + classHeatNum;
|
|
|
|
|
|
- // 四舍五入保留 4 位小数
|
|
|
+ // 四舍五入保留 3 位小数
|
|
|
Map<String, BigDecimal> roundedClassWeightMap = classLengthWeightMap.entrySet().stream()
|
|
|
- .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(4, RoundingMode.HALF_UP)));
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(3, RoundingMode.HALF_UP)));
|
|
|
|
|
|
Map<String, BigDecimal> roundedDayWeightMap = dayLengthWeightMap.entrySet().stream()
|
|
|
- .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(4, RoundingMode.HALF_UP)));
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(3, RoundingMode.HALF_UP)));
|
|
|
|
|
|
BigDecimal roundedClassTotalWeight = roundedClassWeightMap.values().stream()
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add).setScale(3, RoundingMode.HALF_UP);
|
|
@@ -617,6 +623,29 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
stats.setDayEndHeatCount(dayEndHeatCount);
|
|
|
stats.setDayHeatCount(dayHeatCount);
|
|
|
|
|
|
+
|
|
|
+ // 统计月内所有炉记录(不递归调用)
|
|
|
+ // 获取本月第一天的起始时间:2025-07-01 00:00:00
|
|
|
+ LocalDate logicalMonth = logicalDay.withDayOfMonth(1);
|
|
|
+ Date monthStartTime = Date.from(logicalMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+ LambdaQueryWrapper<BilletOriginalProductRecord> monthQuery = new LambdaQueryWrapper<>();
|
|
|
+ monthQuery.eq(BilletOriginalProductRecord::getCcmNo, ccmNo)
|
|
|
+ .between(BilletOriginalProductRecord::getCreateTime, monthStartTime, classEndTime);
|
|
|
+ List<BilletOriginalProductRecord> monthRecords = this.list(monthQuery);
|
|
|
+
|
|
|
+ // 当前班次开始之前的炉数(止上班)
|
|
|
+ int monthStartHeatCount = (int) monthRecords.stream()
|
|
|
+ .filter(r -> r.getCreateTime().before(classStartTime))
|
|
|
+ .count();
|
|
|
+
|
|
|
+ // 整个月的炉数(包含当前班次)
|
|
|
+ int monthEndHeatCount = monthStartHeatCount + classHeatNum;
|
|
|
+
|
|
|
+ stats.setMonthStartHeatCount(monthStartHeatCount);
|
|
|
+ stats.setMonthEndHeatCount(monthEndHeatCount);
|
|
|
+ stats.setMonthHeatCount(monthEndHeatCount);
|
|
|
+
|
|
|
+
|
|
|
// 合并展示格式
|
|
|
Map<String, String> classLengthCountWeight = new TreeMap<>();
|
|
|
for (String length : classLengthCountMap.keySet()) {
|