|
@@ -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,保留第一个
|
|
|
- ));
|
|
|
+ if (!billetNos.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<BilletBasicInfo> billetQuery = new LambdaQueryWrapper<>();
|
|
|
+ billetQuery.in(BilletBasicInfo::getBilletNo, billetNos);
|
|
|
+ List<BilletBasicInfo> basicList = billetBasicInfoService.list(billetQuery);
|
|
|
+
|
|
|
+ billetToAssemblyMap = basicList.stream().collect(Collectors.toMap(
|
|
|
+ BilletBasicInfo::getBilletNo,
|
|
|
+ BilletBasicInfo::getAssemblyNumber,
|
|
|
+ (existing, replacement) -> existing // 遇重复保留第一个
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
- // 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);
|
|
|
- }
|
|
|
+ // 7. 遍历当前页 StorageBill,计算 amountTotal 和 assemblyNumber
|
|
|
+ for (StorageBill bill : records) {
|
|
|
+ List<BilletAutoTmp> relatedBillets = tmpMap.getOrDefault(bill.getId(), Collections.emptyList());
|
|
|
+
|
|
|
+ // 计算 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 7. 计算总数并分页
|
|
|
- long total = filteredRecords.size();
|
|
|
- int fromIndex = (pageNo - 1) * pageSize;
|
|
|
- int toIndex = Math.min(fromIndex + pageSize, filteredRecords.size());
|
|
|
-
|
|
|
- List<StorageBill> pageRecords = (fromIndex >= filteredRecords.size()) ?
|
|
|
- Collections.emptyList() : filteredRecords.subList(fromIndex, toIndex);
|
|
|
-
|
|
|
- // 8. 遍历 StorageBill 添加车次编号、总车次编号、更新交班记录
|
|
|
- storageBillService.fillCarNumbersAndShiftInfo(pageRecords);
|
|
|
+ // 8. 填充车次编号与交班记录信息
|
|
|
+ storageBillService.fillCarNumbersAndShiftInfo(records);
|
|
|
|
|
|
- // 9. 封装分页数据
|
|
|
- Page<StorageBill> pageList = new Page<>(pageNo, pageSize);
|
|
|
- pageList.setRecords(pageRecords);
|
|
|
- pageList.setTotal(total);
|
|
|
-
|
|
|
- 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,
|