|
@@ -1,11 +1,31 @@
|
|
|
package org.jeecg.modules.billet.billetOriginalProductRecord.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletRulerConfig;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletRulerConfigMapper;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
+import org.jeecg.modules.billet.billetOriginalProductRecord.dto.QualityInspectionQueryDTO;
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.mapper.BilletOriginalProductRecordMapper;
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
|
|
|
+import org.jeecg.modules.billet.billetOriginalProductRecord.vo.QualityInspectionStatisticsVO;
|
|
|
+import org.jeecg.modules.billet.billetOriginalProductRecord.vo.QualityInspectionVO;
|
|
|
+import org.jeecg.modules.carUnit.service.ISysDictService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 钢坯生成原始记录
|
|
@@ -16,4 +36,506 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@Service
|
|
|
public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOriginalProductRecordMapper, BilletOriginalProductRecord> implements IBilletOriginalProductRecordService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDictService sysDictService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BilletRulerConfigMapper billetRulerConfigMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getQualityInspectionMenu(QualityInspectionQueryDTO queryDTO) {
|
|
|
+ if (queryDTO == null || StringUtils.isBlank(queryDTO.getCcmNo())) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ List<QualityInspectionVO> resultList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<BilletOriginalProductRecord> oneQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getCcmNo, queryDTO.getCcmNo());
|
|
|
+ Boolean search = true;
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getChangeShiftId())) {
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getId, queryDTO.getChangeShiftId()).eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo());
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+ if (billetHotsendChangeShift == null) {
|
|
|
+ return Collections.emptyMap(); // 空数据返回
|
|
|
+ }
|
|
|
+ Date startChangeTime = billetHotsendChangeShift.getCreateTime();
|
|
|
+ Date endChangeTime = oConvertUtils.isNotEmpty(billetHotsendChangeShift.getChangeShiftTime()) ? billetHotsendChangeShift.getChangeShiftTime() : new Date();
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getShift, billetHotsendChangeShift.getShift());
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getShiftGroup, billetHotsendChangeShift.getShiftGroup());
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, startChangeTime, endChangeTime);
|
|
|
+ search = false;
|
|
|
+ } else if (oConvertUtils.isNotEmpty(queryDTO.getStartTime()) && oConvertUtils.isNotEmpty(queryDTO.getEndTime())) {
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, queryDTO.getStartTime(), queryDTO.getEndTime());
|
|
|
+ search = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getQueryDate()) || search) {
|
|
|
+ if (oConvertUtils.isEmpty(queryDTO.getQueryDate())) {
|
|
|
+ String nowDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
+ Date startOneTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(nowDate));
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo()).orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+ oneQueryWrapper.ge(BilletOriginalProductRecord::getCreateTime,
|
|
|
+ oConvertUtils.isNotEmpty(billetHotsendChangeShift.getCreateTime()) ? billetHotsendChangeShift.getCreateTime() : startOneTime);
|
|
|
+ } else {
|
|
|
+ Date queryDate = queryDTO.getQueryDate();
|
|
|
+ Date startTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(queryDate));
|
|
|
+ Date endTime = DateUtils.getEndOfDayByDate(startTime);
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, startTime, endTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getHeatNo())) {
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getHeatNo, queryDTO.getHeatNo());
|
|
|
+ }
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getSize())) {
|
|
|
+ oneQueryWrapper.like(BilletOriginalProductRecord::getRollClubOneDetails, queryDTO.getSize());
|
|
|
+ }
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getBrandNum())) {
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getGrade, queryDTO.getBrandNum());
|
|
|
+ }
|
|
|
+ oneQueryWrapper.orderByAsc(BilletOriginalProductRecord::getCreateTime);
|
|
|
+
|
|
|
+ List<BilletOriginalProductRecord> records = this.list(oneQueryWrapper);
|
|
|
+ Set<String> allLengths = new TreeSet<>();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ // 获取当前班次记录
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo())
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+
|
|
|
+ // 设置班次时间范围
|
|
|
+ Date classStartTime = billetHotsendChangeShift != null ? billetHotsendChangeShift.getCreateTime() : null;
|
|
|
+ Date classEndTime = billetHotsendChangeShift != null && billetHotsendChangeShift.getChangeShiftTime() != null
|
|
|
+ ? billetHotsendChangeShift.getChangeShiftTime()
|
|
|
+ : new Date();
|
|
|
+
|
|
|
+ String nowDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
+
|
|
|
+ Date startCurrentTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(nowDate));
|
|
|
+ Date endCurrentTime = DateUtils.getEndOfDayByDate(DateUtils.getEndOfDay(nowDate));
|
|
|
+
|
|
|
+ // 汇总统计
|
|
|
+ Map<String, Integer> classLengthCountMap = new TreeMap<>();
|
|
|
+ Map<String, BigDecimal> classLengthWeightMap = new TreeMap<>();
|
|
|
+ Map<String, Integer> dayLengthCountMap = new TreeMap<>();
|
|
|
+ Map<String, BigDecimal> dayLengthWeightMap = new TreeMap<>();
|
|
|
+ int classTotalCount = 0;
|
|
|
+ BigDecimal classTotalWeight = BigDecimal.ZERO;
|
|
|
+ int dayTotalCount = 0;
|
|
|
+ BigDecimal dayTotalWeight = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ Map<String, Integer> mergedCount = new HashMap<>();
|
|
|
+ Map<String, BigDecimal> mergedWeight = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- rollClubOneDetails ---
|
|
|
+ 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)); // 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- hotChargeLength ---
|
|
|
+ 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 = new BigDecimal(node.path("totalWeight").asText("0"));
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- stackLength ---
|
|
|
+ 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 = new BigDecimal(node.path("stackingWeight").asText("0"));
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ Date createTime = record.getCreateTime();
|
|
|
+ boolean isInClassTime = createTime != null && !createTime.before(classStartTime) && !createTime.after(classEndTime);
|
|
|
+ boolean isInDayTime = createTime != null && !createTime.before(startCurrentTime) && !createTime.after(endCurrentTime);
|
|
|
+
|
|
|
+ for (Map.Entry<String, Integer> entry : mergedCount.entrySet()) {
|
|
|
+ String mmStr = entry.getKey();
|
|
|
+ int count = entry.getValue();
|
|
|
+ BigDecimal weight = mergedWeight.getOrDefault(mmStr, BigDecimal.ZERO);
|
|
|
+ String mStr;
|
|
|
+ try {
|
|
|
+ BigDecimal mm = new BigDecimal(mmStr);
|
|
|
+ mStr = mm.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP).toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ mStr = mmStr;
|
|
|
+ }
|
|
|
+ vo.getLengthCountMap().put(mStr, count);
|
|
|
+ allLengths.add(mStr);
|
|
|
+
|
|
|
+ if (isInClassTime) {
|
|
|
+ classLengthCountMap.merge(mStr, count, Integer::sum);
|
|
|
+ classLengthWeightMap.merge(mStr, weight, BigDecimal::add);
|
|
|
+ classTotalCount += count;
|
|
|
+ classTotalWeight = classTotalWeight.add(weight);
|
|
|
+ }
|
|
|
+ if (isInDayTime) {
|
|
|
+ dayLengthCountMap.merge(mStr, count, Integer::sum);
|
|
|
+ dayLengthWeightMap.merge(mStr, weight, BigDecimal::add);
|
|
|
+ dayTotalCount += count;
|
|
|
+ dayTotalWeight = dayTotalWeight.add(weight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 补齐定尺列
|
|
|
+ for (QualityInspectionVO vo : resultList) {
|
|
|
+ for (String length : allLengths) {
|
|
|
+ vo.getLengthCountMap().putIfAbsent(length, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 先对定尺重量 map 统一保留4位小数(班次 + 当天)
|
|
|
+ Map<String, BigDecimal> roundedClassWeightMap = classLengthWeightMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().setScale(4, RoundingMode.HALF_UP)
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<String, BigDecimal> roundedDayWeightMap = dayLengthWeightMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().setScale(4, RoundingMode.HALF_UP)
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 2. 总重量使用已四舍五入后的子项重量相加,再保留4位小数
|
|
|
+ BigDecimal roundedClassTotalWeight = roundedClassWeightMap.values().stream()
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ BigDecimal roundedDayTotalWeight = roundedDayWeightMap.values().stream()
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 3. 封装 VO 返回
|
|
|
+ QualityInspectionStatisticsVO stats = new QualityInspectionStatisticsVO();
|
|
|
+ stats.setClassLengthCountMap(classLengthCountMap);
|
|
|
+ stats.setClassLengthWeightMap(roundedClassWeightMap);
|
|
|
+ stats.setClassTotalCount(classTotalCount);
|
|
|
+ stats.setClassTotalWeight(roundedClassTotalWeight);
|
|
|
+
|
|
|
+ stats.setDayLengthCountMap(dayLengthCountMap);
|
|
|
+ stats.setDayLengthWeightMap(roundedDayWeightMap);
|
|
|
+ stats.setDayTotalCount(dayTotalCount);
|
|
|
+ stats.setDayTotalWeight(roundedDayTotalWeight);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("records", resultList);
|
|
|
+ result.put("statistics", stats);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getQualityInspectionScreen(QualityInspectionQueryDTO queryDTO) {
|
|
|
+ if (queryDTO == null || StringUtils.isBlank(queryDTO.getCcmNo())) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ List<QualityInspectionVO> resultList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<BilletOriginalProductRecord> oneQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getCcmNo, queryDTO.getCcmNo());
|
|
|
+ Boolean search = true;
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getChangeShiftId())) {
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getId, queryDTO.getChangeShiftId()).eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo());
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+ if (billetHotsendChangeShift == null) {
|
|
|
+ return Collections.emptyMap(); // 空数据返回
|
|
|
+ }
|
|
|
+ Date startChangeTime = billetHotsendChangeShift.getCreateTime();
|
|
|
+ Date endChangeTime = oConvertUtils.isNotEmpty(billetHotsendChangeShift.getChangeShiftTime()) ? billetHotsendChangeShift.getChangeShiftTime() : new Date();
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getShift, billetHotsendChangeShift.getShift());
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getShiftGroup, billetHotsendChangeShift.getShiftGroup());
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, startChangeTime, endChangeTime);
|
|
|
+ search = false;
|
|
|
+ } else if (oConvertUtils.isNotEmpty(queryDTO.getStartTime()) && oConvertUtils.isNotEmpty(queryDTO.getEndTime())) {
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, queryDTO.getStartTime(), queryDTO.getEndTime());
|
|
|
+ search = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getQueryDate()) || search) {
|
|
|
+ if (oConvertUtils.isEmpty(queryDTO.getQueryDate())) {
|
|
|
+ String nowDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
+ Date startOneTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(nowDate));
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo()).orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+ oneQueryWrapper.ge(BilletOriginalProductRecord::getCreateTime,
|
|
|
+ oConvertUtils.isNotEmpty(billetHotsendChangeShift.getCreateTime()) ? billetHotsendChangeShift.getCreateTime() : startOneTime);
|
|
|
+ } else {
|
|
|
+ Date queryDate = queryDTO.getQueryDate();
|
|
|
+ Date startTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(queryDate));
|
|
|
+ Date endTime = DateUtils.getEndOfDayByDate(startTime);
|
|
|
+ oneQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, startTime, endTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getHeatNo())) {
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getHeatNo, queryDTO.getHeatNo());
|
|
|
+ }
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getSize())) {
|
|
|
+ oneQueryWrapper.like(BilletOriginalProductRecord::getRollClubOneDetails, queryDTO.getSize());
|
|
|
+ }
|
|
|
+ if (oConvertUtils.isNotEmpty(queryDTO.getBrandNum())) {
|
|
|
+ oneQueryWrapper.eq(BilletOriginalProductRecord::getGrade, queryDTO.getBrandNum());
|
|
|
+ }
|
|
|
+ oneQueryWrapper.orderByAsc(BilletOriginalProductRecord::getCreateTime);
|
|
|
+
|
|
|
+ List<BilletOriginalProductRecord> records = this.list(oneQueryWrapper);
|
|
|
+ Set<String> allLengths = new TreeSet<>();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ // 获取当前班次记录
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo())
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+
|
|
|
+ // 设置班次时间范围
|
|
|
+ Date classStartTime = billetHotsendChangeShift != null ? billetHotsendChangeShift.getCreateTime() : null;
|
|
|
+ Date classEndTime = billetHotsendChangeShift != null && billetHotsendChangeShift.getChangeShiftTime() != null
|
|
|
+ ? billetHotsendChangeShift.getChangeShiftTime()
|
|
|
+ : new Date();
|
|
|
+
|
|
|
+ String nowDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
+
|
|
|
+ Date startCurrentTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(nowDate));
|
|
|
+ Date endCurrentTime = DateUtils.getEndOfDayByDate(DateUtils.getEndOfDay(nowDate));
|
|
|
+
|
|
|
+ // 汇总统计
|
|
|
+ Map<String, Integer> classLengthCountMap = new TreeMap<>();
|
|
|
+ Map<String, BigDecimal> classLengthWeightMap = new TreeMap<>();
|
|
|
+ Map<String, Integer> dayLengthCountMap = new TreeMap<>();
|
|
|
+ Map<String, BigDecimal> dayLengthWeightMap = new TreeMap<>();
|
|
|
+ int classTotalCount = 0;
|
|
|
+ BigDecimal classTotalWeight = BigDecimal.ZERO;
|
|
|
+ int dayTotalCount = 0;
|
|
|
+ BigDecimal dayTotalWeight = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ Map<String, Integer> mergedCount = new HashMap<>();
|
|
|
+ Map<String, BigDecimal> mergedWeight = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- rollClubOneDetails ---
|
|
|
+ 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)); // 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- hotChargeLength ---
|
|
|
+ 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 = new BigDecimal(node.path("totalWeight").asText("0"));
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ // --- stackLength ---
|
|
|
+ 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 = new BigDecimal(node.path("stackingWeight").asText("0"));
|
|
|
+ mergedCount.merge(mm, count, Integer::sum);
|
|
|
+ mergedWeight.merge(mm, weight, BigDecimal::add);
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+
|
|
|
+ Date createTime = record.getCreateTime();
|
|
|
+ boolean isInClassTime = createTime != null && !createTime.before(classStartTime) && !createTime.after(classEndTime);
|
|
|
+ boolean isInDayTime = createTime != null && !createTime.before(startCurrentTime) && !createTime.after(endCurrentTime);
|
|
|
+
|
|
|
+ for (Map.Entry<String, Integer> entry : mergedCount.entrySet()) {
|
|
|
+ String mmStr = entry.getKey();
|
|
|
+ int count = entry.getValue();
|
|
|
+ BigDecimal weight = mergedWeight.getOrDefault(mmStr, BigDecimal.ZERO);
|
|
|
+ String mStr;
|
|
|
+ try {
|
|
|
+ BigDecimal mm = new BigDecimal(mmStr);
|
|
|
+ mStr = mm.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP).toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ mStr = mmStr;
|
|
|
+ }
|
|
|
+ vo.getLengthCountMap().put(mStr, count);
|
|
|
+ allLengths.add(mStr);
|
|
|
+
|
|
|
+ if (isInClassTime) {
|
|
|
+ classLengthCountMap.merge(mStr, count, Integer::sum);
|
|
|
+ classLengthWeightMap.merge(mStr, weight, BigDecimal::add);
|
|
|
+ classTotalCount += count;
|
|
|
+ classTotalWeight = classTotalWeight.add(weight);
|
|
|
+ }
|
|
|
+ if (isInDayTime) {
|
|
|
+ dayLengthCountMap.merge(mStr, count, Integer::sum);
|
|
|
+ dayLengthWeightMap.merge(mStr, weight, BigDecimal::add);
|
|
|
+ dayTotalCount += count;
|
|
|
+ dayTotalWeight = dayTotalWeight.add(weight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 补齐定尺列
|
|
|
+ for (QualityInspectionVO vo : resultList) {
|
|
|
+ for (String length : allLengths) {
|
|
|
+ vo.getLengthCountMap().putIfAbsent(length, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 先对定尺重量 map 统一保留4位小数(班次 + 当天)
|
|
|
+ Map<String, BigDecimal> roundedClassWeightMap = classLengthWeightMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().setScale(4, RoundingMode.HALF_UP)
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<String, BigDecimal> roundedDayWeightMap = dayLengthWeightMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().setScale(4, RoundingMode.HALF_UP)
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 2. 总重量使用已四舍五入后的子项重量相加,再保留4位小数
|
|
|
+ BigDecimal roundedClassTotalWeight = roundedClassWeightMap.values().stream()
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ BigDecimal roundedDayTotalWeight = roundedDayWeightMap.values().stream()
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 3. 封装 VO 返回
|
|
|
+ QualityInspectionStatisticsVO stats = new QualityInspectionStatisticsVO();
|
|
|
+ stats.setClassLengthCountMap(classLengthCountMap);
|
|
|
+ stats.setClassLengthWeightMap(roundedClassWeightMap);
|
|
|
+ stats.setClassTotalCount(classTotalCount);
|
|
|
+ stats.setClassTotalWeight(roundedClassTotalWeight);
|
|
|
+
|
|
|
+ stats.setDayLengthCountMap(dayLengthCountMap);
|
|
|
+ stats.setDayLengthWeightMap(roundedDayWeightMap);
|
|
|
+ stats.setDayTotalCount(dayTotalCount);
|
|
|
+ stats.setDayTotalWeight(roundedDayTotalWeight);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("records", resultList);
|
|
|
+ result.put("statistics", stats);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|