Ver código fonte

Merge branch 'master' of http://123.57.213.14:3001/zgzt/dosb-java

guoqiang 3 meses atrás
pai
commit
26d45b7779

+ 62 - 81
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -132,109 +132,90 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 													@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
 													@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
 													HttpServletRequest req) {
+
+		// 1. 构造分页查询主表 StorageBill
+		IPage<StorageBill> page = new Page<>(pageNo, pageSize);
 		QueryWrapper<StorageBill> queryWrapper = QueryGenerator.initQueryWrapper(storageBill, req.getParameterMap());
+		IPage<StorageBill> pagedBills = storageBillService.page(page, queryWrapper);
+		List<StorageBill> records = pagedBills.getRecords();
 
-		// 1. 查询所有 StorageBill(不分页)
-		List<StorageBill> allRecords = storageBillService.list(queryWrapper);
-		if (allRecords.isEmpty()) {
-			return Result.OK(new Page<>(pageNo, pageSize));
+		if (CollectionUtils.isEmpty(records)) {
+			return Result.OK(pagedBills);
 		}
 
-		// 2. 批量查询所有 BilletAutoTmp 记录
-		List<String> storageBillIds = allRecords.stream()
-				.map(StorageBill::getId)
-				.collect(Collectors.toList());
+		// 2. 提取当前页的 StorageBill ID 列表
+		List<String> billIds = records.stream().map(StorageBill::getId).collect(Collectors.toList());
 
+		// 3. 查询当前页的 BilletAutoTmp 数据
 		LambdaQueryWrapper<BilletAutoTmp> tmpQueryWrapper = new LambdaQueryWrapper<>();
-		tmpQueryWrapper.in(BilletAutoTmp::getStorageBillId, storageBillIds);
+		tmpQueryWrapper.in(BilletAutoTmp::getStorageBillId, billIds);
 		List<BilletAutoTmp> billetAutoTmpList = billetAutoTmpService.list(tmpQueryWrapper);
 
-		// 3. 按 StorageBillId 分组 `BilletAutoTmp`
-		Map<String, List<BilletAutoTmp>> billetTmpMap = billetAutoTmpList.stream()
+		// 4. 按 billId 分组 BilletAutoTmp
+		Map<String, List<BilletAutoTmp>> tmpMap = billetAutoTmpList.stream()
 				.collect(Collectors.groupingBy(BilletAutoTmp::getStorageBillId));
 
-		// 4. 计算 `amountTotal`
-		Map<String, Long> billetCountMap = billetAutoTmpList.stream()
-				.collect(Collectors.groupingBy(
-						BilletAutoTmp::getStorageBillId,
-						Collectors.summingLong(tmp -> (tmp.getStackAddr() != null && !tmp.getStackAddr().isEmpty()) ? 4L : 1L)
-				));
-
-
-		List<StorageBill> filteredRecords = allRecords.stream()
-				.peek(bill -> bill.setAmountTotal(
-						bill.getAmountTotal() + billetCountMap.getOrDefault(bill.getId(), 0L).intValue()))
-				.collect(Collectors.toList());
-
-		// 5. **一次性查询所有 `BilletBasicInfo`,避免循环查询**
-		Set<String> allBilletNos = billetAutoTmpList.stream()
+		// 5. 收集所有 billetNo
+		Set<String> billetNos = billetAutoTmpList.stream()
 				.map(BilletAutoTmp::getBilletNo)
-				.filter(Objects::nonNull)
-				.flatMap(billetNo -> Arrays.stream(billetNo.split(","))) // 按逗号分割
-				.map(String::trim) // 去除可能的空格
-				.filter(bn -> !bn.isEmpty()) // 过滤空字符串
+				.filter(StringUtils::isNotBlank)
+				.flatMap(bn -> Arrays.stream(bn.split(",")))
+				.map(String::trim)
+				.filter(StringUtils::isNotBlank)
 				.collect(Collectors.toSet());
 
+		// 6. 查询 billetNo -> assemblyNumber 映射
 		Map<String, String> billetToAssemblyMap = new HashMap<>();
-		if (CollectionUtils.isNotEmpty(allBilletNos)) {
-			LambdaQueryWrapper<BilletBasicInfo> billetBasicQuery = new LambdaQueryWrapper<>();
-			billetBasicQuery.in(BilletBasicInfo::getBilletNo, allBilletNos);
-			List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(billetBasicQuery);
-
-			// 构建 `billetNo -> assemblyNumber` 映射
-			billetToAssemblyMap = billetBasicInfoList.stream()
-					.collect(Collectors.toMap(
-							BilletBasicInfo::getBilletNo,
-							BilletBasicInfo::getAssemblyNumber,
-							(existing, replacement) -> existing // 遇到重复 billetNo,保留第一个
-					));
-		}
-
-		// 6. **遍历 StorageBill 追加 assemblyNumber**
-		for (StorageBill bill : filteredRecords) {
-			List<BilletAutoTmp> relatedBillets = billetTmpMap.get(bill.getId());
-
-			if (CollectionUtils.isNotEmpty(relatedBillets)) {
-				// 获取所有 `assemblyNumber` 并去重拼接
-				String assemblyNumbers = relatedBillets.stream()
-						.map(BilletAutoTmp::getBilletNo)
-						.filter(Objects::nonNull)
-						.flatMap(billetNo -> Arrays.stream(billetNo.split(","))) // 逗号分割
-						.map(String::trim) // 去掉前后空格
-						.filter(bn -> !bn.isEmpty()) // 过滤空字符串
-						.map(billetToAssemblyMap::get) // 在 Map 中查找 AssemblyNumber
-						.filter(Objects::nonNull) // 过滤掉 null
-						.distinct() // 去重
-						.collect(Collectors.joining(",")); // 拼接
-
-				if (StringUtils.isNotBlank(assemblyNumbers)) {
-					bill.setAssemblyNumber(StringUtils.isNotBlank(bill.getAssemblyNumber()) ?
-							bill.getAssemblyNumber() + "," + assemblyNumbers : assemblyNumbers);
-				}
-			}
-		}
+		if (!billetNos.isEmpty()) {
+			LambdaQueryWrapper<BilletBasicInfo> billetQuery = new LambdaQueryWrapper<>();
+			billetQuery.in(BilletBasicInfo::getBilletNo, billetNos);
+			List<BilletBasicInfo> basicList = billetBasicInfoService.list(billetQuery);
 
-		// 7. 计算总数并分页
-		long total = filteredRecords.size();
-		int fromIndex = (pageNo - 1) * pageSize;
-		int toIndex = Math.min(fromIndex + pageSize, filteredRecords.size());
+			billetToAssemblyMap = basicList.stream().collect(Collectors.toMap(
+					BilletBasicInfo::getBilletNo,
+					BilletBasicInfo::getAssemblyNumber,
+					(existing, replacement) -> existing // 遇重复保留第一个
+			));
+		}
 
-		List<StorageBill> pageRecords = (fromIndex >= filteredRecords.size()) ?
-				Collections.emptyList() : filteredRecords.subList(fromIndex, toIndex);
+		// 7. 遍历当前页 StorageBill,计算 amountTotal 和 assemblyNumber
+		for (StorageBill bill : records) {
+			List<BilletAutoTmp> relatedBillets = tmpMap.getOrDefault(bill.getId(), Collections.emptyList());
 
-		// 8. 遍历 StorageBill 添加车次编号、总车次编号、更新交班记录
-		storageBillService.fillCarNumbersAndShiftInfo(pageRecords);
+			// 计算 amountTotal
+			long count = relatedBillets.stream()
+					.mapToLong(tmp -> StringUtils.isNotBlank(tmp.getStackAddr()) ? 4L : 1L)
+					.sum();
+			bill.setAmountTotal(Optional.ofNullable(bill.getAmountTotal()).orElse(0) + (int) count);
+
+			// 拼接 assemblyNumber
+			String assemblyNumbers = relatedBillets.stream()
+					.map(BilletAutoTmp::getBilletNo)
+					.filter(StringUtils::isNotBlank)
+					.flatMap(bn -> Arrays.stream(bn.split(",")))
+					.map(String::trim)
+					.filter(StringUtils::isNotBlank)
+					.map(billetToAssemblyMap::get)
+					.filter(Objects::nonNull)
+					.distinct()
+					.collect(Collectors.joining(","));
+
+			if (StringUtils.isNotBlank(assemblyNumbers)) {
+				bill.setAssemblyNumber(StringUtils.isNotBlank(bill.getAssemblyNumber())
+						? bill.getAssemblyNumber() + "," + assemblyNumbers
+						: assemblyNumbers);
+			}
+		}
 
-		// 9. 封装分页数据
-		Page<StorageBill> pageList = new Page<>(pageNo, pageSize);
-		pageList.setRecords(pageRecords);
-		pageList.setTotal(total);
+		// 8. 填充车次编号与交班记录信息
+		storageBillService.fillCarNumbersAndShiftInfo(records);
 
-		return Result.OK(pageList);
+		// 9. 返回分页结果
+		pagedBills.setRecords(records);
+		return Result.OK(pagedBills);
 	}
 
 
-
 	@ApiOperation(value="钢坯热送单-分页列表查询", notes="钢坯热送单-分页列表查询")
 	@GetMapping(value = "/listHotSend")
 	public Result<IPage<StorageBill>> queryHotSendPageList(StorageBill storageBill,

+ 9 - 4
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/impl/StorageBillServiceImpl.java

@@ -5634,15 +5634,19 @@ 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));
+            Date shiftEnd = Optional.ofNullable(shiftRecord.getChangeShiftTime())
+                    .orElse(DateUtils.addDays(DateUtils.getStartOfDay(bill.getCreateTime()), 1));
 
-            boolean needCalcCarNum = bill.getCarNum() == null || bill.getCarNum() == 0;
+            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"));
+                    Optional.ofNullable(bill.getLicensePlate()).orElse(""),
+                    DateFormatUtils.format(DateUtils.getStartOfDay(bill.getCreateTime()), "yyyy-MM-dd"));
             List<StorageBill> relatedBills = billGroupMap.getOrDefault(carNumKey, new ArrayList<>()).stream()
                     .filter(b -> b.getCreateTime().compareTo(shiftStart) >= 0 && b.getCreateTime().compareTo(shiftEnd) < 0)
                     .sorted(Comparator.comparing(StorageBill::getCreateTime))
@@ -5676,12 +5680,13 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
 
             if (updated) this.updateById(bill);
 
-            // 更新交班 outCarNum
+            // 更新交班 outCarNum(依赖 carAllNum,不管车牌状态)
             if (shiftRecord.getOutCarNum() == null || shiftRecord.getOutCarNum() == 0) {
                 shiftRecord.setOutCarNum(bill.getCarAllNum());
                 billetHotsendChangeShiftService.updateById(shiftRecord);
             }
         }
+
     }