|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -21,7 +20,6 @@ import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBa
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
|
import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
|
|
|
import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
|
|
|
-import org.jeecg.modules.billet.billetAutoException.entity.BilletAutoException;
|
|
|
import org.jeecg.modules.billet.billetAutoTmp.entity.BilletAutoTmp;
|
|
|
import org.jeecg.modules.billet.billetAutoTmp.service.IBilletAutoTmpService;
|
|
|
import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
|
|
@@ -1391,6 +1389,13 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
|
|
|
|
|
|
OnDutyInfo onDutyInfo = new OnDutyInfo();
|
|
|
|
|
|
+ String brandNum = String.format("billet:basic:info:brand:num:%s", ccmNo);
|
|
|
+ String brandNumStr = !oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)) : "";
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(brandNumStr)){
|
|
|
+ onDutyInfo.setBrandNum(brandNumStr);
|
|
|
+ }
|
|
|
+
|
|
|
String shiftGroup = "";
|
|
|
String shift = "";
|
|
|
BilletHotsendChangeShift billetHotsendChangeShift;
|
|
@@ -5964,53 +5969,47 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
|
|
|
public void fillCarNumbersAndShiftInfo(List<StorageBill> bills) {
|
|
|
if (CollectionUtils.isEmpty(bills)) return;
|
|
|
|
|
|
- // Step 1: 预提取所有用到的条件组合
|
|
|
- Set<String> shiftKeys = new HashSet<>();
|
|
|
- Set<String> billKeys = new HashSet<>();
|
|
|
- for (StorageBill bill : bills) {
|
|
|
- Date billDate = DateUtils.getStartOfDay(bill.getCreateTime());
|
|
|
- String shiftKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(), DateFormatUtils.format(billDate, "yyyy-MM-dd"));
|
|
|
- shiftKeys.add(shiftKey);
|
|
|
-
|
|
|
- String billKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(), DateFormatUtils.format(billDate, "yyyy-MM-dd"));
|
|
|
- billKeys.add(billKey);
|
|
|
- }
|
|
|
+ Set<String> ccmNos = bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet());
|
|
|
+ // 查询时间往前扩 1 小时
|
|
|
+ Date minDate = org.apache.commons.lang3.time.DateUtils.addHours(getMinDate(bills), -1);
|
|
|
+ Date maxDate = getMaxDate(bills);
|
|
|
|
|
|
- // Step 2: 批量查询交班记录并缓存
|
|
|
+ // Step 1: 查询交班记录并按 (ccmNo + shiftGroup + shift) 分组
|
|
|
List<BilletHotsendChangeShift> shiftList = billetHotsendChangeShiftService.lambdaQuery()
|
|
|
- .in(BilletHotsendChangeShift::getCcmNo, bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet()))
|
|
|
- .between(BilletHotsendChangeShift::getCreateTime, getMinDate(bills), getMaxDate(bills))
|
|
|
+ .in(BilletHotsendChangeShift::getCcmNo, ccmNos)
|
|
|
+ .between(BilletHotsendChangeShift::getCreateTime, minDate, maxDate)
|
|
|
.list();
|
|
|
|
|
|
- Map<String, BilletHotsendChangeShift> shiftMap = shiftList.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- s -> String.join("_", s.getCcmNo(), s.getShiftGroup(), s.getShift(), DateFormatUtils.format(DateUtils.getStartOfDay(s.getCreateTime()), "yyyy-MM-dd")),
|
|
|
- Function.identity(),
|
|
|
- (v1, v2) -> v1 // 取较早的那个记录
|
|
|
- ));
|
|
|
+ Map<String, List<BilletHotsendChangeShift>> shiftGroupMap = shiftList.stream()
|
|
|
+ .collect(Collectors.groupingBy(s -> String.join("_", s.getCcmNo(), s.getShiftGroup(), s.getShift())));
|
|
|
|
|
|
- // Step 3: 批量查询所有相关的 StorageBill
|
|
|
+ // Step 2: 查询所有相关 StorageBill 并按 key 分组 (含车牌)
|
|
|
List<StorageBill> allRelatedBills = this.lambdaQuery()
|
|
|
- .in(StorageBill::getCcmNo, bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet()))
|
|
|
- .between(StorageBill::getCreateTime, getMinDate(bills), getMaxDate(bills))
|
|
|
+ .in(StorageBill::getCcmNo, ccmNos)
|
|
|
+ .between(StorageBill::getCreateTime, minDate, maxDate)
|
|
|
.list();
|
|
|
|
|
|
- // 多级 map 存储 [ccmNo+shiftGroup+shift+licensePlate+day] -> List<StorageBill>
|
|
|
Map<String, List<StorageBill>> billGroupMap = allRelatedBills.stream().collect(Collectors.groupingBy(b ->
|
|
|
String.join("_", b.getCcmNo(), b.getShiftGroup(), b.getShift(), Optional.ofNullable(b.getLicensePlate()).orElse(""),
|
|
|
DateFormatUtils.format(DateUtils.getStartOfDay(b.getCreateTime()), "yyyy-MM-dd"))
|
|
|
));
|
|
|
|
|
|
- // Step 4: 处理每条 bill
|
|
|
for (StorageBill bill : bills) {
|
|
|
- // 生成一个新的对象
|
|
|
- StorageBill newBill = new StorageBill();
|
|
|
- newBill.setBtype(bill.getBtype());
|
|
|
- newBill.setId(bill.getId());
|
|
|
- String key = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(),
|
|
|
- DateFormatUtils.format(DateUtils.getStartOfDay(bill.getCreateTime()), "yyyy-MM-dd"));
|
|
|
+ // 获取所属班次的交班记录候选项
|
|
|
+ String groupKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift());
|
|
|
+ List<BilletHotsendChangeShift> candidates = shiftGroupMap.getOrDefault(groupKey, Collections.emptyList());
|
|
|
+
|
|
|
+ // 匹配交班记录:createTime <= bill.createTime < changeShiftTime
|
|
|
+ BilletHotsendChangeShift shiftRecord = candidates.stream()
|
|
|
+ .filter(s -> {
|
|
|
+ Date start = s.getCreateTime();
|
|
|
+ Date end = Optional.ofNullable(s.getChangeShiftTime())
|
|
|
+ .orElse(DateUtils.addDays(DateUtils.getStartOfDay(start), 1));
|
|
|
+ return !bill.getCreateTime().before(start) && bill.getCreateTime().before(end);
|
|
|
+ })
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
|
|
|
- BilletHotsendChangeShift shiftRecord = shiftMap.get(key);
|
|
|
if (shiftRecord == null) {
|
|
|
log.warn("未找到交班记录,跳过: {}", bill.getId());
|
|
|
continue;
|
|
@@ -6018,15 +6017,14 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
|
|
|
|
|
|
Date shiftStart = shiftRecord.getCreateTime();
|
|
|
Date shiftEnd = Optional.ofNullable(shiftRecord.getChangeShiftTime())
|
|
|
- .orElse(DateUtils.addDays(DateUtils.getStartOfDay(bill.getCreateTime()), 1));
|
|
|
+ .orElse(DateUtils.addDays(DateUtils.getStartOfDay(shiftStart), 1));
|
|
|
|
|
|
boolean licensePlateInvalid = bill.getLicensePlateStatus() != null && bill.getLicensePlateStatus() == 1;
|
|
|
-
|
|
|
boolean needCalcCarNum = !licensePlateInvalid && (bill.getCarNum() == null || bill.getCarNum() == 0);
|
|
|
boolean needCalcCarAllNum = bill.getCarAllNum() == null || bill.getCarAllNum() == 0;
|
|
|
boolean updated = false;
|
|
|
|
|
|
- // 查找对应车次列表
|
|
|
+ // 查询当前车牌的对应车次列表
|
|
|
String carNumKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(),
|
|
|
Optional.ofNullable(bill.getLicensePlate()).orElse(""),
|
|
|
DateFormatUtils.format(DateUtils.getStartOfDay(bill.getCreateTime()), "yyyy-MM-dd"));
|
|
@@ -6035,12 +6033,16 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
|
|
|
.sorted(Comparator.comparing(StorageBill::getCreateTime))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+ StorageBill updateBill = new StorageBill();
|
|
|
+ updateBill.setId(bill.getId());
|
|
|
+ updateBill.setBtype(bill.getBtype());
|
|
|
+
|
|
|
if (needCalcCarNum) {
|
|
|
long index = relatedBills.stream()
|
|
|
.filter(b -> !b.getId().equals(bill.getId()))
|
|
|
.filter(b -> b.getCreateTime().before(bill.getCreateTime()))
|
|
|
.count();
|
|
|
- newBill.setCarNum((int) index + 1);
|
|
|
+ updateBill.setCarNum((int) index + 1);
|
|
|
updated = true;
|
|
|
}
|
|
|
|
|
@@ -6057,29 +6059,39 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
|
|
|
.filter(b -> !b.getId().equals(bill.getId()))
|
|
|
.filter(b -> b.getCreateTime().before(bill.getCreateTime()))
|
|
|
.count();
|
|
|
- newBill.setCarAllNum((int) totalIndex + 1);
|
|
|
+ updateBill.setCarAllNum((int) totalIndex + 1);
|
|
|
updated = true;
|
|
|
}
|
|
|
|
|
|
if (updated) {
|
|
|
- update(newBill, new UpdateWrapper<StorageBill>()
|
|
|
- .eq("id", newBill.getId())
|
|
|
- .set("car_num", newBill.getCarNum())
|
|
|
- .set("car_all_num", newBill.getCarAllNum()));
|
|
|
+ UpdateWrapper<StorageBill> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", updateBill.getId());
|
|
|
+
|
|
|
+ if (needCalcCarNum) {
|
|
|
+ updateWrapper.set("car_num", updateBill.getCarNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needCalcCarAllNum) {
|
|
|
+ updateWrapper.set("car_all_num", updateBill.getCarAllNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ update(updateBill, updateWrapper);
|
|
|
}
|
|
|
|
|
|
- // 更新交班 outCarNum(依赖 carAllNum,不管车牌状态)
|
|
|
- if (shiftRecord.getOutCarNum() == null || shiftRecord.getOutCarNum() == 0) {
|
|
|
- UpdateWrapper<BilletHotsendChangeShift> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.eq("id", shiftRecord.getId())
|
|
|
- .set("out_car_num", bill.getCarAllNum());
|
|
|
|
|
|
- billetHotsendChangeShiftService.update(null, updateWrapper);
|
|
|
+ // 更新 shiftRecord.outCarNum
|
|
|
+ if (shiftRecord.getOutCarNum() == null || shiftRecord.getOutCarNum() == 0) {
|
|
|
+ billetHotsendChangeShiftService.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<BilletHotsendChangeShift>()
|
|
|
+ .eq("id", shiftRecord.getId())
|
|
|
+ .set("out_car_num", bill.getCarAllNum())
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String destinationSwitchHandle(StorageBill storageBill, String destination, String typeConfigId) {
|