|
@@ -1,18 +1,173 @@
|
|
|
package org.jeecg.modules.billet.rollOutShipp.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.oConvertUtils;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
+import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShippDetails;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.mapper.RollOutShippDetailsMapper;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippDetailsService;
|
|
|
+import org.jeecg.modules.billet.storageBill.entity.StorageBill;
|
|
|
+import org.jeecg.modules.billet.storageBill.mapper.StorageBillMapper;
|
|
|
+import org.jeecg.modules.billet.storageBill.vo.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 上若明细信息
|
|
|
* @Author: jeecg-boot
|
|
|
* @Date: 2024-11-20
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
+
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class RollOutShippDetailsServiceImpl extends ServiceImpl<RollOutShippDetailsMapper, RollOutShippDetails> implements IRollOutShippDetailsService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StorageBillMapper storageBillMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RollOnDutyDataVo queryOnDutyRecord(String ccmNo) {
|
|
|
+ RollOnDutyDataVo rollOnDutyVo = new RollOnDutyDataVo();
|
|
|
+
|
|
|
+ // 1. 从 Redis 获取班次信息
|
|
|
+ String shiftGroup = getShiftInfo(ccmNo, "class:shift:group:%s");
|
|
|
+ String shift = getShiftInfo(ccmNo, "class:shift:%s");
|
|
|
+
|
|
|
+ // 2. 获取交班记录
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
+ .eq(BilletHotsendChangeShift::getShift, shift)
|
|
|
+ .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
|
|
|
+ .isNull(BilletHotsendChangeShift::getChangeShiftTime)
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
+
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
|
|
|
+ if (billetHotsendChangeShift == null) {
|
|
|
+ log.info("{}{}", "查询当班装运单信息失败,交班记录为空!", ccmNo + "失败时间:" + new Date());
|
|
|
+ return rollOnDutyVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查询当班装运单信息
|
|
|
+ LambdaQueryWrapper<StorageBill> billQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ billQueryWrapper.eq(StorageBill::getCcmNo, ccmNo)
|
|
|
+ .eq(StorageBill::getDestination,"上若")
|
|
|
+ .gt(StorageBill::getAmountTotal, 0)
|
|
|
+ .between(StorageBill::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
|
|
|
+
|
|
|
+ List<StorageBill> storageBillList = storageBillMapper.selectList(billQueryWrapper);
|
|
|
+ if (oConvertUtils.listIsEmpty(storageBillList)) {
|
|
|
+ log.info("{}{}", "查询当班装运单信息为空!", ccmNo);
|
|
|
+ return rollOnDutyVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 查询上若明细数据
|
|
|
+ List<String> billIds = storageBillList.stream().map(StorageBill::getId).collect(Collectors.toList());
|
|
|
+ List<RollOutShippDetails> rollOutShippDetailsList = Collections.emptyList();
|
|
|
+
|
|
|
+ if (!billIds.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<RollOutShippDetails> rollClubQuery = new LambdaQueryWrapper<>();
|
|
|
+ rollClubQuery.eq(RollOutShippDetails::getCcmNo, ccmNo)
|
|
|
+ .in(RollOutShippDetails::getStorageBillId, billIds);
|
|
|
+ rollOutShippDetailsList = baseMapper.selectList(rollClubQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 组装 RecordVoList 和 DetailVoList
|
|
|
+ List<RollOnDutyRecordVo> recordVoList = storageBillList.stream()
|
|
|
+ .map(storageBill -> {
|
|
|
+ RollOnDutyRecordVo vo = new RollOnDutyRecordVo();
|
|
|
+ BeanUtils.copyProperties(storageBill, vo);
|
|
|
+ vo.setStorageBillId(storageBill.getId());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<RollOnDutyDetailVo> detailVoList = rollOutShippDetailsList.stream()
|
|
|
+ .map(details -> {
|
|
|
+ RollOnDutyDetailVo detailVo = new RollOnDutyDetailVo();
|
|
|
+ BeanUtils.copyProperties(details, detailVo);
|
|
|
+ return detailVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 6. 查询 Info 数据
|
|
|
+ LambdaQueryWrapper<RollOutShippDetails> infoQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ infoQueryWrapper.eq(RollOutShippDetails::getCcmNo, ccmNo)
|
|
|
+ .eq(RollOutShippDetails::getShift, shift)
|
|
|
+ .eq(RollOutShippDetails::getShiftGroup, shiftGroup)
|
|
|
+ .between(RollOutShippDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
|
|
|
+
|
|
|
+ List<RollOnDutyInfoVo> infoVoList = baseMapper.selectList(infoQueryWrapper).stream()
|
|
|
+ .map(details -> {
|
|
|
+ RollOnDutyInfoVo infoVo = new RollOnDutyInfoVo();
|
|
|
+ BeanUtils.copyProperties(details, infoVo);
|
|
|
+ return infoVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 7. 计算历史数据统计
|
|
|
+ LambdaQueryWrapper<RollOutShippDetails> historyQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ historyQueryWrapper.eq(RollOutShippDetails::getCcmNo, ccmNo);
|
|
|
+
|
|
|
+ List<RollOutShippDetails> rollOutShippHistoryDetailsList = baseMapper.selectList(historyQueryWrapper);
|
|
|
+ List<RollHistoryDetailVo> historyDetailList = rollOutShippHistoryDetailsList.stream()
|
|
|
+ .collect(Collectors.groupingBy(RollOutShippDetails::getSize))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(entry -> {
|
|
|
+ String size = entry.getKey();
|
|
|
+ List<RollOutShippDetails> detailsList = entry.getValue();
|
|
|
+
|
|
|
+ int totalCount = detailsList.stream()
|
|
|
+ .mapToInt(detail -> (detail.getStackAddr() == null || detail.getStackAddr().isEmpty()) ? 1 : 4)
|
|
|
+ .sum();
|
|
|
+
|
|
|
+ BigDecimal totalBlankOutput = 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;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 8. 组装最终对象
|
|
|
+ rollOnDutyVo.setRollOnDutyRecordList(recordVoList);
|
|
|
+ rollOnDutyVo.setRollOnDutyDetailList(detailVoList);
|
|
|
+ rollOnDutyVo.setRollOnDutyInfoList(infoVoList);
|
|
|
+ rollOnDutyVo.setRollHistoryDetailList(historyDetailList);
|
|
|
+
|
|
|
+ return rollOnDutyVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从Redis中获取班组班别
|
|
|
+ *
|
|
|
+ * @param ccmNo
|
|
|
+ * @param keyFormat
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getShiftInfo(String ccmNo, String keyFormat) {
|
|
|
+ String key = String.format(keyFormat, ccmNo);
|
|
|
+ return oConvertUtils.getString(redisTemplate.opsForValue().get(key));
|
|
|
+ }
|
|
|
}
|