|
@@ -67,7 +67,6 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
List<QualityInspectionVO> resultList = new ArrayList<>();
|
|
|
LambdaQueryWrapper<BilletOriginalProductRecord> oneQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
oneQueryWrapper.eq(BilletOriginalProductRecord::getCcmNo, queryDTO.getCcmNo());
|
|
|
- Boolean search = true;
|
|
|
LambdaQueryWrapper<BilletHotsendChangeShift> changeShiftQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
BilletHotsendChangeShift newBilletHotsendChangeShift = null;
|
|
@@ -166,12 +165,19 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
for (BilletOriginalProductRecord record : records) {
|
|
|
QualityInspectionVO vo = new QualityInspectionVO();
|
|
|
vo.setHeatNo(record.getHeatNo());
|
|
|
- String brandNum = Optional.ofNullable(record.getGrade())
|
|
|
- .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
|
|
|
- .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
|
|
|
- vo.setBrandNum(brandNum);
|
|
|
- vo.setDeliveryTime(record.getCreateTime());
|
|
|
+// String brandNum = Optional.ofNullable(record.getGrade())
|
|
|
+// .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
|
|
|
+// .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
|
|
|
+ vo.setBrandNum(
|
|
|
+ record.getBrandNum() != null ? record.getBrandNum() : record.getGrade()
|
|
|
+ );
|
|
|
+ vo.setDeliveryTime(
|
|
|
+ record.getDeliveryTime() != null ? record.getDeliveryTime() : record.getCreateTime()
|
|
|
+ );
|
|
|
vo.setOriginalProductRecordId(record.getId());
|
|
|
+ if (StringUtils.isNotBlank(record.getNotes())) {
|
|
|
+ vo.setNotes(record.getNotes());
|
|
|
+ }
|
|
|
|
|
|
Map<String, Integer> mergedCount = new HashMap<>();
|
|
|
Map<String, BigDecimal> mergedWeight = new HashMap<>();
|
|
@@ -297,80 +303,12 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void getQualityInspectionScreen(QualityInspectionQueryDTO queryDTO) {
|
|
|
+ public void getQualityInspectionScreen() {
|
|
|
String ccmNo = "5";
|
|
|
|
|
|
- // 1. 初始化补全月统计(缺失部分)
|
|
|
+ // 初始化补全月统计(缺失部分)
|
|
|
initMonthlyStatisticsIfMissing(ccmNo);
|
|
|
|
|
|
- // 2. 查询当天班次
|
|
|
- String nowDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
- Date dayStart = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(nowDate));
|
|
|
- Date dayEnd = DateUtils.getEndOfDayByDate(DateUtils.getEndOfDay(nowDate));
|
|
|
-
|
|
|
- List<BilletHotsendChangeShift> shifts = billetHotsendChangeShiftService.list(
|
|
|
- new LambdaQueryWrapper<BilletHotsendChangeShift>()
|
|
|
- .eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
- .between(BilletHotsendChangeShift::getCreateTime, dayStart, dayEnd)
|
|
|
- );
|
|
|
-
|
|
|
- // 按 change_shift_time 升序排序
|
|
|
- shifts.sort(Comparator.comparing(BilletHotsendChangeShift::getCreateTime));
|
|
|
-
|
|
|
- // 日累计起点
|
|
|
- BigDecimal dayStartWeight = BigDecimal.ONE;
|
|
|
- int dayStartCount = 1;
|
|
|
-
|
|
|
- // 月累计起点(查询已有最大记录)
|
|
|
- Date monthStart = DateUtils.getMonthStart(new Date());
|
|
|
- QualityInspectionStatistics last = qualityInspectionStatisticsMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<QualityInspectionStatistics>()
|
|
|
- .eq(QualityInspectionStatistics::getCcmNo, ccmNo)
|
|
|
- .ge(QualityInspectionStatistics::getChangeShiftTime, monthStart)
|
|
|
- .orderByDesc(QualityInspectionStatistics::getChangeShiftTime)
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
- BigDecimal monthStartWeight = last != null ? last.getMonthEndWeight().add(BigDecimal.ONE) : BigDecimal.ONE;
|
|
|
- int monthStartCount = last != null ? last.getMonthEndCount() + 1 : 1;
|
|
|
-
|
|
|
- for (BilletHotsendChangeShift shift : shifts) {
|
|
|
- QualityInspectionStatisticsVO vo = this.getStatisticsByShift(shift,shifts);
|
|
|
-
|
|
|
- QualityInspectionStatistics entity = new QualityInspectionStatistics();
|
|
|
- entity.setId(String.valueOf(IdWorker.getId()));
|
|
|
- entity.setClassLengthCountWeight(JSON.toJSONString(vo.getClassLengthCountWeight()));
|
|
|
- entity.setDayLengthCountWeight(JSON.toJSONString(vo.getDayLengthCountWeight()));
|
|
|
- entity.setClassTotalCount(vo.getClassTotalCount());
|
|
|
- entity.setClassTotalWeight(vo.getClassTotalWeight());
|
|
|
- entity.setChangeShiftId(shift.getId());
|
|
|
- entity.setShift(shift.getShift());
|
|
|
- entity.setShiftGroup(shift.getShiftGroup());
|
|
|
- entity.setClassHeatNum(vo.getClassHeatNum());
|
|
|
- entity.setChangeShiftTime(shift.getCreateTime());
|
|
|
- entity.setCcmNo(ccmNo);
|
|
|
-
|
|
|
- // 日累计
|
|
|
- entity.setDayStartCount(dayStartCount);
|
|
|
- entity.setDayStartWeight(dayStartWeight);
|
|
|
- int dayEndCount = dayStartCount + vo.getClassTotalCount() - 1;
|
|
|
- BigDecimal dayEndWeight = dayStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- entity.setDayEndCount(dayEndCount);
|
|
|
- entity.setDayEndWeight(dayEndWeight);
|
|
|
- dayStartCount = dayEndCount + 1;
|
|
|
- dayStartWeight = dayEndWeight.add(BigDecimal.ONE);
|
|
|
-
|
|
|
- // 月累计
|
|
|
- entity.setMonthStartCount(monthStartCount);
|
|
|
- entity.setMonthStartWeight(monthStartWeight);
|
|
|
- int monthEndCount = monthStartCount + vo.getClassTotalCount() - 1;
|
|
|
- BigDecimal monthEndWeight = monthStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- entity.setMonthEndCount(monthEndCount);
|
|
|
- entity.setMonthEndWeight(monthEndWeight);
|
|
|
- monthStartCount = monthEndCount + 1;
|
|
|
- monthStartWeight = monthEndWeight.add(BigDecimal.ONE);
|
|
|
-
|
|
|
- qualityInspectionStatisticsMapper.insert(entity);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -388,15 +326,18 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
|
|
|
// 按归属日期分组
|
|
|
Map<LocalDate, List<BilletHotsendChangeShift>> shiftByDate = allShifts.stream()
|
|
|
- .collect(Collectors.groupingBy(s -> getShiftDate(s.getCreateTime(), s.getShift()),
|
|
|
- TreeMap::new, Collectors.toList()));
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ s -> getShiftDate(s.getCreateTime(), s.getShift()),
|
|
|
+ TreeMap::new,
|
|
|
+ Collectors.toList())
|
|
|
+ );
|
|
|
|
|
|
- // 初始化月累计起点
|
|
|
+ // 月累计起点
|
|
|
int monthStartCount = 1;
|
|
|
BigDecimal monthStartWeight = BigDecimal.ONE;
|
|
|
|
|
|
for (List<BilletHotsendChangeShift> shiftList : shiftByDate.values()) {
|
|
|
- // 按班次顺序处理:夜班 > 白班 > 中班
|
|
|
+ // 按夜 -> 白 -> 中排序
|
|
|
Map<String, Integer> shiftOrder = new HashMap<>();
|
|
|
shiftOrder.put("1", 0); // 夜班
|
|
|
shiftOrder.put("0", 1); // 白班
|
|
@@ -411,55 +352,76 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
BigDecimal dayStartWeight = BigDecimal.ONE;
|
|
|
|
|
|
for (BilletHotsendChangeShift shift : shiftList) {
|
|
|
- Long count = qualityInspectionStatisticsMapper.selectCount(
|
|
|
+ QualityInspectionStatistics existing = qualityInspectionStatisticsMapper.selectOne(
|
|
|
new LambdaQueryWrapper<QualityInspectionStatistics>()
|
|
|
.eq(QualityInspectionStatistics::getChangeShiftId, shift.getId())
|
|
|
);
|
|
|
- if (count > 0) continue;
|
|
|
-
|
|
|
- QualityInspectionStatisticsVO vo = this.getStatisticsByShift(shift,shiftList);
|
|
|
-
|
|
|
- QualityInspectionStatistics entity = new QualityInspectionStatistics();
|
|
|
- entity.setId(String.valueOf(IdWorker.getId()));
|
|
|
- entity.setClassLengthCountWeight(JSON.toJSONString(vo.getClassLengthCountWeight()));
|
|
|
- entity.setDayLengthCountWeight(JSON.toJSONString(vo.getDayLengthCountWeight()));
|
|
|
- entity.setClassTotalCount(vo.getClassTotalCount());
|
|
|
- entity.setClassTotalWeight(vo.getClassTotalWeight());
|
|
|
- entity.setChangeShiftId(shift.getId());
|
|
|
- entity.setShift(shift.getShift());
|
|
|
- entity.setShiftGroup(shift.getShiftGroup());
|
|
|
- entity.setClassHeatNum(vo.getClassHeatNum());
|
|
|
- entity.setChangeShiftTime(shift.getCreateTime());
|
|
|
- entity.setCcmNo(ccmNo);
|
|
|
+
|
|
|
+ // 已存在且已交班,跳过
|
|
|
+ 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);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新建或更新记录
|
|
|
+ QualityInspectionStatisticsVO vo = this.getStatisticsByShift(shift, shiftList);
|
|
|
+ QualityInspectionStatistics record = existing != null ? existing : new QualityInspectionStatistics();
|
|
|
+ if (existing == null) {
|
|
|
+ record.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ record.setCcmNo(ccmNo);
|
|
|
+ record.setChangeShiftId(shift.getId());
|
|
|
+ record.setShift(shift.getShift());
|
|
|
+ record.setShiftGroup(shift.getShiftGroup());
|
|
|
+ record.setChangeShiftTime(shift.getCreateTime());
|
|
|
+ record.setClassLengthCountWeight(JSON.toJSONString(vo.getClassLengthCountWeight()));
|
|
|
+ record.setDayLengthCountWeight(JSON.toJSONString(vo.getDayLengthCountWeight()));
|
|
|
+ record.setClassTotalCount(vo.getClassTotalCount());
|
|
|
+ record.setClassTotalWeight(vo.getClassTotalWeight());
|
|
|
+ record.setClassHeatNum(vo.getClassHeatNum());
|
|
|
+ record.setDayStartHeatCount(vo.getDayStartHeatCount());
|
|
|
+ record.setDayEndHeatCount(vo.getDayEndHeatCount());
|
|
|
+ record.setDayHeatCount(vo.getDayHeatCount());
|
|
|
|
|
|
// 日累计
|
|
|
- entity.setDayStartCount(dayStartCount);
|
|
|
- entity.setDayStartWeight(dayStartWeight);
|
|
|
int dayEndCount = dayStartCount + vo.getClassTotalCount() - 1;
|
|
|
BigDecimal dayEndWeight = dayStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- entity.setDayEndCount(dayEndCount);
|
|
|
- entity.setDayEndWeight(dayEndWeight);
|
|
|
+ record.setDayStartCount(dayStartCount);
|
|
|
+ record.setDayStartWeight(dayStartWeight);
|
|
|
+ record.setDayEndCount(dayEndCount);
|
|
|
+ record.setDayEndWeight(dayEndWeight);
|
|
|
dayStartCount = dayEndCount + 1;
|
|
|
dayStartWeight = dayEndWeight.add(BigDecimal.ONE);
|
|
|
|
|
|
// 月累计
|
|
|
- entity.setMonthStartCount(monthStartCount);
|
|
|
- entity.setMonthStartWeight(monthStartWeight);
|
|
|
int monthEndCount = monthStartCount + vo.getClassTotalCount() - 1;
|
|
|
BigDecimal monthEndWeight = monthStartWeight.add(vo.getClassTotalWeight()).subtract(BigDecimal.ONE);
|
|
|
- entity.setMonthEndCount(monthEndCount);
|
|
|
- entity.setMonthEndWeight(monthEndWeight);
|
|
|
+ record.setMonthStartCount(monthStartCount);
|
|
|
+ record.setMonthStartWeight(monthStartWeight);
|
|
|
+ record.setMonthEndCount(monthEndCount);
|
|
|
+ record.setMonthEndWeight(monthEndWeight);
|
|
|
monthStartCount = monthEndCount + 1;
|
|
|
monthStartWeight = monthEndWeight.add(BigDecimal.ONE);
|
|
|
|
|
|
- qualityInspectionStatisticsMapper.insert(entity);
|
|
|
+ if (existing != null) {
|
|
|
+ qualityInspectionStatisticsMapper.updateById(record);
|
|
|
+ } else {
|
|
|
+ qualityInspectionStatisticsMapper.insert(record);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public QualityInspectionStatisticsVO getStatisticsByShift(BilletHotsendChangeShift shiftRecord, List<BilletHotsendChangeShift> allShiftsOfTheDay) {
|
|
|
Date classStartTime = shiftRecord.getCreateTime();
|
|
|
Date classEndTime = Optional.ofNullable(shiftRecord.getChangeShiftTime()).orElse(new Date());
|
|
@@ -597,14 +559,28 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
.sorted(Comparator.comparing(s -> shiftOrder.getOrDefault(s.getShift(), 99)))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+ // 当前班炉数
|
|
|
+ int classHeatNum = records.size();
|
|
|
+
|
|
|
+ // 初始化炉数相关统计
|
|
|
+ int dayStartHeatCount = 1;
|
|
|
+ int dayEndHeatCount = classHeatNum;
|
|
|
+ int dayHeatCount = classHeatNum;
|
|
|
+
|
|
|
for (BilletHotsendChangeShift previous : previousShifts) {
|
|
|
QualityInspectionStatisticsVO prevVO = this.getStatisticsByShift(previous, allShiftsOfTheDay);
|
|
|
prevVO.getClassLengthCountMap().forEach((k, v) -> dayLengthCountMap.merge(k, v, Integer::sum));
|
|
|
prevVO.getClassLengthWeightMap().forEach((k, v) -> dayLengthWeightMap.merge(k, v, BigDecimal::add));
|
|
|
dayTotalCount += prevVO.getClassTotalCount();
|
|
|
dayTotalWeight = dayTotalWeight.add(prevVO.getClassTotalWeight());
|
|
|
+
|
|
|
+ // 计算累计炉数位置
|
|
|
+ dayStartHeatCount = prevVO.getDayEndHeatCount() + 1;
|
|
|
+ dayHeatCount += prevVO.getClassHeatNum();
|
|
|
}
|
|
|
|
|
|
+ dayEndHeatCount = dayStartHeatCount + classHeatNum - 1;
|
|
|
+
|
|
|
// 四舍五入保留 4 位小数
|
|
|
Map<String, BigDecimal> roundedClassWeightMap = classLengthWeightMap.entrySet().stream()
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(4, RoundingMode.HALF_UP)));
|
|
@@ -613,10 +589,10 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().setScale(4, RoundingMode.HALF_UP)));
|
|
|
|
|
|
BigDecimal roundedClassTotalWeight = roundedClassWeightMap.values().stream()
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(4, RoundingMode.HALF_UP);
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
|
|
BigDecimal roundedDayTotalWeight = roundedDayWeightMap.values().stream()
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(4, RoundingMode.HALF_UP);
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(3, RoundingMode.HALF_UP);
|
|
|
|
|
|
QualityInspectionStatisticsVO stats = new QualityInspectionStatisticsVO();
|
|
|
stats.setClassLengthCountMap(classLengthCountMap);
|
|
@@ -628,6 +604,9 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
stats.setDayTotalCount(dayTotalCount);
|
|
|
stats.setDayTotalWeight(roundedDayTotalWeight);
|
|
|
stats.setClassHeatNum(records.size());
|
|
|
+ stats.setDayStartHeatCount(dayStartHeatCount);
|
|
|
+ stats.setDayEndHeatCount(dayEndHeatCount);
|
|
|
+ stats.setDayHeatCount(dayHeatCount);
|
|
|
|
|
|
// 合并展示格式
|
|
|
Map<String, String> classLengthCountWeight = new TreeMap<>();
|
|
@@ -651,31 +630,32 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 判断班次所属的业务日期(白班/中班/夜班)
|
|
|
- * - 夜班(shift = "1"):
|
|
|
- * - 如果时间在 00:00 ~ 08:00,视为“当天的夜班”
|
|
|
- * - 如果时间在 23:50 ~ 23:59,视为“第二天的夜班”
|
|
|
- * - 其他:按正常的 createTime 日期返回
|
|
|
- */
|
|
|
- /**
|
|
|
- * 获取班次逻辑日期:
|
|
|
- * - 夜班如果时间在 23:50 ~ 次日 08:00,算作第二天夜班
|
|
|
- * - 其他班次默认用日期当天
|
|
|
+ * 获取班次逻辑日期(夜班归属次日)
|
|
|
+ *
|
|
|
+ * @param date 班次创建时间
|
|
|
+ * @param shift 班次(1=夜班,0=白班,2=中班)
|
|
|
+ * @return 逻辑归属日期(LocalDate)
|
|
|
*/
|
|
|
private LocalDate getShiftDate(Date date, String shift) {
|
|
|
LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
|
|
|
- int hour = ldt.getHour();
|
|
|
- int minute = ldt.getMinute();
|
|
|
|
|
|
- if ("1".equals(shift)) { // 夜班
|
|
|
- if ((hour == 23 && minute >= 50) || hour < 8) {
|
|
|
- return ldt.toLocalDate().plusDays(1); // 属于第二天夜班
|
|
|
+ if ("1".equals(shift)) {
|
|
|
+ // 计算当天 00:00 和 08:00 的时间点
|
|
|
+ LocalDateTime currentDay = ldt.toLocalDate().atStartOfDay();
|
|
|
+ LocalDateTime shiftStart = currentDay.minusDays(1).withHour(23).withMinute(50); // 前一天 23:50
|
|
|
+ LocalDateTime shiftEnd = currentDay.withHour(8).withMinute(0); // 当天 08:00
|
|
|
+
|
|
|
+ // 如果时间在 23:50(前一天)~ 08:00(当天)之间,归属当天
|
|
|
+ if (!ldt.isBefore(shiftStart) && !ldt.isAfter(shiftEnd)) {
|
|
|
+ return currentDay.toLocalDate(); // 归属当天
|
|
|
+ } else {
|
|
|
+ return ldt.toLocalDate().plusDays(1); // 其余时间归属次日(保险)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 白班/中班正常按日归属
|
|
|
return ldt.toLocalDate();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|