@Override
public PageResult<PurchaseOrderMainVO> queryPage(PurchaseOrderParam purchaseOrderParam) {
// 查询主表数据
Page<PurchaseOrderMainDTO> page = new Page<>(purchaseOrderParam.getPageIndex(), purchaseOrderParam.getPageSize());
Page<PurchaseOrderMainDTO> mainPage = orderMainMapper.queryPurchaseOrderPage(page, purchaseOrderParam);
if (CollectionUtils.isEmpty(mainPage.getRecords())) {
return null;
}
// 构建复合键列表用于查询明细
List<CompositeKeyDTO> compositeKeys = mainPage.getRecords().stream()
.map(main -> new CompositeKeyDTO(
main.getPurchaseOrderNo(),
main.getCompanyCode(),
main.getSerialVersionNum()
))
.collect(Collectors.toList());
// 查询明细数据
List<PurchaseOrderDetailsDTO> detailList = orderDetailMapper.queryDetailsByCompositeKeys(compositeKeys);
// 按复合键分组明细数据
Map<String, List<PurchaseOrderDetailsDTO>> detailMap = detailList.stream()
.collect(Collectors.groupingBy(detail ->
detail.getPurchaseOrderNo() + "#" +
detail.getCompanyCode() + "#" +
detail.getSerialVersionNum()
));
// 转换主表数据到VO
List<PurchaseOrderMainVO> mainVOList = mainPage.getRecords().stream().map(mainDTO -> {
PurchaseOrderMainVO mainVO = BeanCopyUtils.copyBean(mainDTO, PurchaseOrderMainVO.class);
mainVO.setSpliceSupplierName(mainDTO.getSupplierCode() + " - " + mainDTO.getSupplierName());
mainVO.setSpliceFactoryName(mainDTO.getFactoryCode() + " - " + mainDTO.getFactoryName());
mainVO.setSpliceWarehouseName(mainDTO.getWarehouseCode() + " - " + mainDTO.getWarehouseName());
// 设置订单类型描述
if (mainDTO.getOrderType() != null) {
PurchaseOrderTypeEnum typeEnum = Arrays.stream(PurchaseOrderTypeEnum.values())
.filter(e -> e.getTypeCode().equals(mainDTO.getOrderType()))
.findFirst()
.orElse(null);
if (typeEnum != null) {
mainVO.setType(typeEnum.getTypeCode());
}
}
// 设置明细数据 - 使用复合键
String compositeKey = mainDTO.getPurchaseOrderNo() + "#" +
mainDTO.getCompanyCode() + "#" +
mainDTO.getSerialVersionNum();
List<PurchaseOrderDetailsVO> detailVOList = new ArrayList<>();
if (detailMap.containsKey(compositeKey)) {
detailVOList = detailMap.get(compositeKey).stream().map(detail -> {
PurchaseOrderDetailsVO detailVO = BeanCopyUtils.copyBean(detail, PurchaseOrderDetailsVO.class);
// 设置类型名称
if (detail.getType() != null) {
PurchaseOrderPlanTypeEnum planTypeEnum = Arrays.stream(PurchaseOrderPlanTypeEnum.values())
.filter(e -> e.getTypeCode().equals(detail.getType()))
.findFirst()
.orElse(null);
if (planTypeEnum != null) {
detailVO.setTypeName(planTypeEnum.getTypeDesc());
}
}
return detailVO;
}).collect(Collectors.toList());
}
mainVO.setDetailsList(detailVOList);
return mainVO;
}).collect(Collectors.toList());
// 构建分页结果
PageResult<PurchaseOrderMainVO> result = new PageResult<>();
result.setRecords(mainVOList);
result.setTotal(mainPage.getTotal());
result.setPageIndex(purchaseOrderParam.getPageIndex());
result.setPageSize(purchaseOrderParam.getPageSize());
return result;
}
2025-09-28 19:41:11.349 [http-nio-9001-exec-3] DEBUG o.s.web.server.adapter.HttpWebHandlerAdapter - [774d9bf2] HTTP POST "/order/query"
2025-09-28 19:41:11.350 [http-nio-9001-exec-3] DEBUG o.s.w.r.r.m.a.RequestMappingHandlerMapping - [774d9bf2] Mapped to com.hvlink.controller.PurchaseOrderController#queryPage(PurchaseOrderParam)
2025-09-28 19:41:11.351 [http-nio-9001-exec-3] DEBUG o.s.w.r.r.m.a.RequestBodyMethodArgumentResolver - [774d9bf2] Content-Type:application/json
2025-09-28 19:41:11.351 [http-nio-9001-exec-3] DEBUG o.s.w.r.r.m.a.RequestBodyMethodArgumentResolver - [774d9bf2] 0..1 [com.hvlink.entity.param.order.PurchaseOrderParam]
2025-09-28 19:41:11.351 [http-nio-9001-exec-3] DEBUG o.s.http.codec.json.Jackson2JsonDecoder - [774d9bf2] Decoded [PurchaseOrderParam(factoryCode=, factoryName=null, warehouseCode=, warehouseName=null, purchaseOrder (truncated)...]
2025-09-28 19:41:11.352 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
2025-09-28 19:41:11.352 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@798a6b6b] was not registered for synchronization because synchronization is not active
2025-09-28 19:41:11.378 [http-nio-9001-exec-3] DEBUG o.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2025-09-28 19:41:11.553 [http-nio-9001-exec-3] DEBUG o.m.spring.transaction.SpringManagedTransaction - JDBC Connection [ConnectionID:1 ClientConnectionId: 26a12f82-8ef8-4b10-bbc4-8e35841c56ab] will not be managed by Spring
2025-09-28 19:41:11.553 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryPurchaseOrderPage_mpCount - ==> Preparing: SELECT COUNT(*) AS total FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY purchase_order_no, company_code ORDER BY serial_version_num DESC) AS rn FROM tb_order_main WHERE is_deleted = 0 AND order_type = 2) m LEFT JOIN tm_supplier s ON m.supplier_code = s.supplier_code AND m.company_code = s.company_code LEFT JOIN tm_factory f ON m.factory_code = f.factory_code AND m.company_code = f.company_code LEFT JOIN tm_warehouse w ON m.warehouse_code = w.warehouse_code AND m.company_code = w.company_code WHERE m.rn = 1 AND f.status = 1 AND w.status = 1
2025-09-28 19:41:11.554 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryPurchaseOrderPage_mpCount - ==> Parameters:
2025-09-28 19:41:11.645 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryPurchaseOrderPage_mpCount - <== Total: 1
2025-09-28 19:41:11.646 [http-nio-9001-exec-3] DEBUG c.h.m.o.TbOrderMainMapper.queryPurchaseOrderPage - ==> Preparing: SELECT m.id, m.company_code, m.purchase_order_no, m.publish_date, s.supplier_code, s.supplier_name, f.factory_code, f.factory_name, w.warehouse_code, w.warehouse_name, m.serial_version_num, m.order_type FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY purchase_order_no, company_code ORDER BY serial_version_num DESC) AS rn FROM tb_order_main WHERE is_deleted = 0 AND order_type = 2 ) m LEFT JOIN tm_supplier s ON m.supplier_code = s.supplier_code AND m.company_code = s.company_code LEFT JOIN tm_factory f ON m.factory_code = f.factory_code AND m.company_code = f.company_code LEFT JOIN tm_warehouse w ON m.warehouse_code = w.warehouse_code AND m.company_code = w.company_code WHERE m.rn = 1 and f.status = 1 and w.status = 1 ORDER BY s.supplier_code DESC, m.purchase_order_no DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY
2025-09-28 19:41:11.646 [http-nio-9001-exec-3] DEBUG c.h.m.o.TbOrderMainMapper.queryPurchaseOrderPage - ==> Parameters: 0(Long), 10(Long)
2025-09-28 19:41:11.749 [http-nio-9001-exec-3] DEBUG c.h.m.o.TbOrderMainMapper.queryPurchaseOrderPage - <== Total: 1
2025-09-28 19:41:11.749 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@798a6b6b]
2025-09-28 19:41:11.749 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
2025-09-28 19:41:11.749 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@58989e1f] was not registered for synchronization because synchronization is not active
2025-09-28 19:41:11.750 [http-nio-9001-exec-3] DEBUG o.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2025-09-28 19:41:11.750 [http-nio-9001-exec-3] DEBUG o.m.spring.transaction.SpringManagedTransaction - JDBC Connection [ConnectionID:1 ClientConnectionId: 26a12f82-8ef8-4b10-bbc4-8e35841c56ab] will not be managed by Spring
2025-09-28 19:41:11.750 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryDetailsByCompositeKeys - ==> Preparing: SELECT d.purchase_order_no, d.line_no, d.delivery_date, d.part_code, d.part_desc, d.unit, d.total_qty, d.required_qty, d.available_qty, d.shipped_qty, d.type, d.frequency, d.approval_code, d.serial_version_num, d.company_code, d.order_type FROM tb_order_detail d WHERE EXISTS ( SELECT 1 FROM ( VALUES (?, ?, ?) ) AS keys(purchase_order_no, company_code, serial_version_num) WHERE d.purchase_order_no LIKE '%' + keys.purchase_order_no + '%' AND d.company_code LIKE '%' + keys.company_code + '%' AND d.serial_version_num = keys.serial_version_num ) ORDER BY d.purchase_order_no DESC, d.line_no ASC, d.delivery_date DESC
2025-09-28 19:41:11.750 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryDetailsByCompositeKeys - ==> Parameters: 5580000154(String), 8000(String), 1(String)
2025-09-28 19:41:11.852 [http-nio-9001-exec-3] DEBUG c.h.m.o.T.queryDetailsByCompositeKeys - <== Total: 1
2025-09-28 19:41:11.852 [http-nio-9001-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@58989e1f]
2025-09-28 19:41:11.852 [http-nio-9001-exec-3] DEBUG o.s.w.r.r.m.annotation.ResponseBodyResultHandler - [774d9bf2] Using 'application/json' given [application/json, text/plain, */*] and supported [application/json, application/*+json, application/x-ndjson, text/event-stream]
2025-09-28 19:41:11.853 [http-nio-9001-exec-3] DEBUG o.s.w.r.r.m.annotation.ResponseBodyResultHandler - [774d9bf2] 0..1 [com.hvlink.common.Result<com.hvlink.pagination.PageResult<com.hvlink.entity.vo.order.PurchaseOrderMainVO>>]
2025-09-28 19:41:11.853 [http-nio-9001-exec-3] DEBUG o.s.http.codec.json.Jackson2JsonEncoder - [774d9bf2] Encoding [Result(status=200, msg=成功, data=PageResult(total=1, records=[PurchaseOrderMainVO(id=90858, purchaseO (truncated)...]
2025-09-28 19:41:11.854 [http-nio-9001-exec-3] DEBUG o.s.web.server.adapter.HttpWebHandlerAdapter - [774d9bf2] Completed 200 OK
为什么我返回的明细中没有数据?
{
"status": "200",
"msg": "成功",
"data": {
"total": 1,
"records": [
{
"id": 90858,
"purchaseOrderNo": "5580000154",
"publishDate": null,
"supplierCode": "0012000048",
"supplierName": "上海信耀电子有限公司",
"spliceSupplierName": "0012000048 - 上海信耀电子有限公司",
"factoryCode": "8400",
"factoryName": "华域视觉科技(常熟)有限公司采购工厂",
"spliceFactoryName": "8400 - 华域视觉科技(常熟)有限公司采购工厂",
"warehouseCode": "8404",
"warehouseName": "车灯物流不良品仓",
"spliceWarehouseName": "8404 - 车灯物流不良品仓",
"serialVersionNum": "1",
"type": 2,
"detailsList": []
}
],
"pageIndex": 1,
"pageSize": 10
},
"timestamp": 1759059716284
}