|
@@ -126,31 +126,34 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
|
|
|
* @return
|
|
|
*/
|
|
|
//@AutoLog(value = "钢坯装运单-分页列表查询")
|
|
|
- @ApiOperation(value="钢坯装运单-分页列表查询", notes="钢坯装运单-分页列表查询")
|
|
|
+ @ApiOperation(value = "钢坯装运单-分页列表查询", notes = "钢坯装运单-分页列表查询")
|
|
|
@GetMapping(value = "/list")
|
|
|
public Result<IPage<StorageBill>> queryPageList(StorageBill storageBill,
|
|
|
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
HttpServletRequest req) {
|
|
|
QueryWrapper<StorageBill> queryWrapper = QueryGenerator.initQueryWrapper(storageBill, req.getParameterMap());
|
|
|
|
|
|
- // 先查询所有 StorageBill 数据(不分页)
|
|
|
+ // 1. 查询所有 StorageBill(不分页)
|
|
|
List<StorageBill> allRecords = storageBillService.list(queryWrapper);
|
|
|
if (allRecords.isEmpty()) {
|
|
|
- return Result.OK(new Page<StorageBill>(pageNo, pageSize));
|
|
|
+ return Result.OK(new Page<>(pageNo, pageSize));
|
|
|
}
|
|
|
|
|
|
- // 批量查询所有 storageBillId 相关的 BilletAutoTmp 记录
|
|
|
+ // 2. 批量查询所有 BilletAutoTmp 记录
|
|
|
List<String> storageBillIds = allRecords.stream()
|
|
|
.map(StorageBill::getId)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 查询所有 BilletAutoTmp,并按 storageBillId 进行分组统计
|
|
|
LambdaQueryWrapper<BilletAutoTmp> tmpQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
tmpQueryWrapper.in(BilletAutoTmp::getStorageBillId, storageBillIds);
|
|
|
List<BilletAutoTmp> billetAutoTmpList = billetAutoTmpService.list(tmpQueryWrapper);
|
|
|
|
|
|
- // 将 BilletAutoTmp 数据按 storageBillId 进行分组统计
|
|
|
+ // 3. 按 StorageBillId 分组 `BilletAutoTmp`
|
|
|
+ Map<String, List<BilletAutoTmp>> billetTmpMap = billetAutoTmpList.stream()
|
|
|
+ .collect(Collectors.groupingBy(BilletAutoTmp::getStorageBillId));
|
|
|
+
|
|
|
+ // 4. 计算 `amountTotal`
|
|
|
Map<String, Long> billetCountMap = billetAutoTmpList.stream()
|
|
|
.collect(Collectors.groupingBy(BilletAutoTmp::getStorageBillId, Collectors.counting()));
|
|
|
|
|
@@ -160,83 +163,65 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
|
|
|
.filter(bill -> bill.getOutTime() == null || bill.getAmountTotal() > 0) // 仅当 outTime 非空时过滤 0
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 将 BilletAutoTmp 数据按 storageBillId 进行分组统计
|
|
|
- Map<String, List<BilletAutoTmp>> collect = billetAutoTmpList.stream()
|
|
|
- .collect(Collectors.groupingBy(BilletAutoTmp::getStorageBillId));
|
|
|
- for (StorageBill filteredRecord : filteredRecords) {
|
|
|
-
|
|
|
- List<BilletAutoTmp> billetAutoTmps = collect.get(filteredRecord.getId());
|
|
|
+ // 5. **一次性查询所有 `BilletBasicInfo`,避免循环查询**
|
|
|
+ Set<String> allBilletNos = billetAutoTmpList.stream()
|
|
|
+ .map(BilletAutoTmp::getBilletNo)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ 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,保留第一个
|
|
|
+ ));
|
|
|
+ }
|
|
|
|
|
|
- Set<String> billetNos = new HashSet<>();
|
|
|
+ // 6. **遍历 StorageBill 追加 assemblyNumber**
|
|
|
+ for (StorageBill bill : filteredRecords) {
|
|
|
+ List<BilletAutoTmp> relatedBillets = billetTmpMap.get(bill.getId());
|
|
|
|
|
|
- if(CollectionUtils.isNotEmpty(billetAutoTmps)) {
|
|
|
- // 1. 从 BilletAutoTmp 里获取所有 billetNo
|
|
|
- billetNos = billetAutoTmps.stream()
|
|
|
+ if (CollectionUtils.isNotEmpty(relatedBillets)) {
|
|
|
+ // 获取所有 `assemblyNumber` 并去重拼接
|
|
|
+ String assemblyNumbers = relatedBillets.stream()
|
|
|
.map(BilletAutoTmp::getBilletNo)
|
|
|
- .filter(Objects::nonNull) // 过滤掉 null 值
|
|
|
- .collect(Collectors.toSet());
|
|
|
- }
|
|
|
+ .map(billetToAssemblyMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
|
- if (CollectionUtils.isNotEmpty(billetNos)) {
|
|
|
- // 2. 查询 BilletBasicInfo 获取 assemblyNumber,并去重
|
|
|
- LambdaQueryWrapper<BilletBasicInfo> billetBasicQuery = new LambdaQueryWrapper<>();
|
|
|
- billetBasicQuery.in(BilletBasicInfo::getBilletNo, billetNos);
|
|
|
- List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(billetBasicQuery);
|
|
|
-
|
|
|
- // 3. 根据 billetNo 进行映射,获取 assemblyNumber
|
|
|
- Map<String, String> billetToAssemblyMap = billetBasicInfoList.stream()
|
|
|
- .collect(Collectors.toMap(
|
|
|
- BilletBasicInfo::getBilletNo,
|
|
|
- BilletBasicInfo::getAssemblyNumber,
|
|
|
- (existing, replacement) -> existing // 遇到重复 billetNo,保留第一个
|
|
|
- ));
|
|
|
-
|
|
|
- // 获取当前 StorageBill 关联的 billetNos
|
|
|
- List<String> relatedBilletNos = billetAutoTmpList.stream()
|
|
|
- .filter(tmp -> filteredRecord.getId().equals(tmp.getStorageBillId()))
|
|
|
- .map(BilletAutoTmp::getBilletNo)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 获取对应的 assemblyNumbers,去重并拼接
|
|
|
- String assemblyNumbers = relatedBilletNos.stream()
|
|
|
- .map(billetToAssemblyMap::get)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .distinct() // 去重
|
|
|
- .collect(Collectors.joining(",")); // 拼接
|
|
|
-
|
|
|
- // **追加到原来的 assemblyNumber**
|
|
|
if (StringUtils.isNotBlank(assemblyNumbers)) {
|
|
|
- if (StringUtils.isNotBlank(filteredRecord.getAssemblyNumber())) {
|
|
|
- filteredRecord.setAssemblyNumber(filteredRecord.getAssemblyNumber() + "," + assemblyNumbers);
|
|
|
- } else {
|
|
|
- filteredRecord.setAssemblyNumber(assemblyNumbers);
|
|
|
- }
|
|
|
+ bill.setAssemblyNumber(StringUtils.isNotBlank(bill.getAssemblyNumber()) ?
|
|
|
+ bill.getAssemblyNumber() + "," + assemblyNumbers : assemblyNumbers);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- // 更新 total
|
|
|
- long total = filteredRecords.size(); // 最终过滤后的总记录数
|
|
|
-
|
|
|
- // 分页处理
|
|
|
+ // 7. 计算总数并分页
|
|
|
+ long total = filteredRecords.size();
|
|
|
int fromIndex = (pageNo - 1) * pageSize;
|
|
|
int toIndex = Math.min(fromIndex + pageSize, filteredRecords.size());
|
|
|
|
|
|
- // 如果 fromIndex 超过 total,返回空集合
|
|
|
List<StorageBill> pageRecords = (fromIndex >= filteredRecords.size()) ?
|
|
|
Collections.emptyList() : filteredRecords.subList(fromIndex, toIndex);
|
|
|
|
|
|
- // 封装分页数据
|
|
|
+ // 8. 封装分页数据
|
|
|
Page<StorageBill> pageList = new Page<>(pageNo, pageSize);
|
|
|
pageList.setRecords(pageRecords);
|
|
|
- pageList.setTotal(total); // 更新为最终正确的 total
|
|
|
+ pageList.setTotal(total);
|
|
|
|
|
|
return Result.OK(pageList);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
@ApiOperation(value="钢坯热送单-分页列表查询", notes="钢坯热送单-分页列表查询")
|
|
|
@GetMapping(value = "/listHotSend")
|
|
|
public Result<IPage<StorageBill>> queryHotSendPageList(StorageBill storageBill,
|