|
@@ -4,12 +4,14 @@ package org.jeecg.modules.billet.rollClubTwo.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
import org.jeecg.modules.billet.rollClubTwo.entity.RollClubTwoDetails;
|
|
|
import org.jeecg.modules.billet.rollClubTwo.mapper.RollClubTwoDetailsMapper;
|
|
|
import org.jeecg.modules.billet.rollClubTwo.service.IRollClubTwoDetailsService;
|
|
|
+import org.jeecg.modules.billet.storageBill.dto.RollDetailQueryDTO;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBill;
|
|
|
import org.jeecg.modules.billet.storageBill.mapper.StorageBillMapper;
|
|
|
import org.jeecg.modules.billet.storageBill.vo.*;
|
|
@@ -19,9 +21,9 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -119,41 +121,127 @@ public class RollClubTwoDetailsServiceImpl extends ServiceImpl<RollClubTwoDetail
|
|
|
return infoVo;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- // 7. 计算历史数据统计
|
|
|
+ // 7. 组装最终对象
|
|
|
+ rollOnDutyVo.setRollOnDutyRecordList(recordVoList);
|
|
|
+ rollOnDutyVo.setRollOnDutyDetailList(detailVoList);
|
|
|
+ rollOnDutyVo.setRollOnDutyInfoList(infoVoList);
|
|
|
+
|
|
|
+ return rollOnDutyVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RollChargeDetailsVO queryWorkbenchesDetail(RollDetailQueryDTO queryDTO) {
|
|
|
+
|
|
|
LambdaQueryWrapper<RollClubTwoDetails> historyQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- historyQueryWrapper.eq(RollClubTwoDetails::getCcmNo, ccmNo);
|
|
|
+ historyQueryWrapper.eq(RollClubTwoDetails::getCcmNo, queryDTO.getCcmNo());
|
|
|
+
|
|
|
+ Date beginDate = queryDTO.getBeginCreateDate();
|
|
|
+ Date endDate = queryDTO.getEndCreateDate();
|
|
|
+
|
|
|
+ // 如果 beginCreateDate 和 endCreateDate 都为空,默认查询最近 7 天的数据
|
|
|
+ if (beginDate == null && endDate == null) {
|
|
|
+ beginDate = DateUtils.getStartOfDayByDate(DateUtils.getDateBeforeDays(7)); // 7 天前 00:00:00
|
|
|
+ endDate = DateUtils.getEndOfDayByDate(new Date()); // 当前时间 23:59:59
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理 beginCreateDate
|
|
|
+ if (beginDate != null) {
|
|
|
+ historyQueryWrapper.ge(RollClubTwoDetails::getCreateTime, DateUtils.getStartOfDayByDate(beginDate));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理 endCreateDate
|
|
|
+ if (endDate != null) {
|
|
|
+ historyQueryWrapper.le(RollClubTwoDetails::getCreateTime, DateUtils.getEndOfDayByDate(endDate));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RollClubTwoDetails> rollClubHistoryDetailsList = baseMapper.selectList(historyQueryWrapper);
|
|
|
+
|
|
|
+ // 计算总支数
|
|
|
+ int totalCount = rollClubHistoryDetailsList.stream()
|
|
|
+ .mapToInt(detail -> (detail.getStackAddr() == null || detail.getStackAddr().isEmpty()) ? 1 : 4)
|
|
|
+ .sum();
|
|
|
|
|
|
- List<RollClubTwoDetails> rollClubTwoHistoryDetailsList = baseMapper.selectList(historyQueryWrapper);
|
|
|
- List<RollHistoryDetailVo> historyDetailList = rollClubTwoHistoryDetailsList.stream()
|
|
|
- .collect(Collectors.groupingBy(RollClubTwoDetails::getSize))
|
|
|
+ // 计算总重量
|
|
|
+ BigDecimal totalWeight = rollClubHistoryDetailsList.stream()
|
|
|
+ .map(detail -> BigDecimal.valueOf(detail.getBlankOutput()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ // 创建 VO 并赋值
|
|
|
+ RollChargeDetailsVO rollChargeDetailsVO = new RollChargeDetailsVO();
|
|
|
+ rollChargeDetailsVO.setAmountTotal(totalCount);
|
|
|
+ rollChargeDetailsVO.setTotalWeight(totalWeight);
|
|
|
+
|
|
|
+
|
|
|
+ List<RollChargeDetailsVO.RollHistoryDetail> rollHistoryDetails = rollClubHistoryDetailsList.stream()
|
|
|
+ .collect(Collectors.groupingBy(detail -> DateUtils.formatDate(detail.getCreateTime())))
|
|
|
.entrySet().stream()
|
|
|
.map(entry -> {
|
|
|
- String size = entry.getKey();
|
|
|
+ String key = entry.getKey();
|
|
|
List<RollClubTwoDetails> detailsList = entry.getValue();
|
|
|
|
|
|
- int totalCount = detailsList.stream()
|
|
|
+ // 统计不重复的 storageBillId 个数,返回 Integer 类型
|
|
|
+ int uniqueStorageBillCount = (int) detailsList.stream()
|
|
|
+ .map(RollClubTwoDetails::getStorageBillId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet()) // 直接收集到 Set 去重
|
|
|
+ .size();
|
|
|
+
|
|
|
+
|
|
|
+ int currentDateCount = detailsList.stream()
|
|
|
.mapToInt(detail -> (detail.getStackAddr() == null || detail.getStackAddr().isEmpty()) ? 1 : 4)
|
|
|
.sum();
|
|
|
|
|
|
- BigDecimal totalBlankOutput = detailsList.stream()
|
|
|
+ BigDecimal currentBlankOutput = detailsList.stream()
|
|
|
.map(detail -> BigDecimal.valueOf(detail.getBlankOutput()))
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
.setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
- RollHistoryDetailVo rollHistoryDetailVo = new RollHistoryDetailVo();
|
|
|
- rollHistoryDetailVo.setSize(size);
|
|
|
- rollHistoryDetailVo.setAmountTotal(totalCount);
|
|
|
- rollHistoryDetailVo.setBlankOutput(totalBlankOutput);
|
|
|
- return rollHistoryDetailVo;
|
|
|
+ RollChargeDetailsVO.RollHistoryDetail rollHistoryDetail = new RollChargeDetailsVO.RollHistoryDetail();
|
|
|
+ rollHistoryDetail.setCurrentDate(key);
|
|
|
+ rollHistoryDetail.setCurrentDateAmount(currentDateCount);
|
|
|
+ rollHistoryDetail.setCurrentDateWeight(currentBlankOutput);
|
|
|
+ rollHistoryDetail.setCarNum(uniqueStorageBillCount);
|
|
|
+
|
|
|
+ List<RollChargeDetailsVO.CurrentDateDetail> currentDateDetails = detailsList.stream()
|
|
|
+ .collect(Collectors.groupingBy(RollClubTwoDetails::getSize))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(sizeEntry -> {
|
|
|
+ String size = sizeEntry.getKey();
|
|
|
+ List<RollClubTwoDetails> sizeList = sizeEntry.getValue();
|
|
|
+
|
|
|
+ int sizeCount = sizeList.stream()
|
|
|
+ .mapToInt(detail -> (detail.getStackAddr() == null || detail.getStackAddr().isEmpty()) ? 1 : 4)
|
|
|
+ .sum();
|
|
|
+
|
|
|
+ BigDecimal sizeBlankOutput = sizeList.stream()
|
|
|
+ .map(detail -> BigDecimal.valueOf(detail.getBlankOutput()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ RollChargeDetailsVO.CurrentDateDetail currentDateDetail = new RollChargeDetailsVO.CurrentDateDetail();
|
|
|
+ currentDateDetail.setSize(size);
|
|
|
+ currentDateDetail.setAmount(sizeCount);
|
|
|
+ currentDateDetail.setBlankOutput(sizeBlankOutput);
|
|
|
+ return currentDateDetail;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ rollHistoryDetail.setCurrentDateDetails(currentDateDetails);
|
|
|
+
|
|
|
+ return rollHistoryDetail;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- // 8. 组装最终对象
|
|
|
- rollOnDutyVo.setRollOnDutyRecordList(recordVoList);
|
|
|
- rollOnDutyVo.setRollOnDutyDetailList(detailVoList);
|
|
|
- rollOnDutyVo.setRollOnDutyInfoList(infoVoList);
|
|
|
- rollOnDutyVo.setRollHistoryDetailList(historyDetailList);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
- return rollOnDutyVo;
|
|
|
+ // 按 currentDate 降序排序
|
|
|
+ rollHistoryDetails.sort(Comparator.comparing(
|
|
|
+ detail -> LocalDate.parse(detail.getCurrentDate(), formatter), // 转换 String -> LocalDate
|
|
|
+ Comparator.reverseOrder() // 降序
|
|
|
+ ));
|
|
|
+
|
|
|
+ rollChargeDetailsVO.setRollHistoryDetails(rollHistoryDetails);
|
|
|
+
|
|
|
+ return rollChargeDetailsVO;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -168,4 +256,5 @@ public class RollClubTwoDetailsServiceImpl extends ServiceImpl<RollClubTwoDetail
|
|
|
String key = String.format(keyFormat, ccmNo);
|
|
|
return oConvertUtils.getString(redisTemplate.opsForValue().get(key));
|
|
|
}
|
|
|
+
|
|
|
}
|