no message

This commit is contained in:
cb 2025-09-01 17:23:26 +08:00
parent 49394a5172
commit a2a009a1e2
1 changed files with 112 additions and 61 deletions

View File

@ -987,6 +987,48 @@ public class OrderMasterController extends BaseController {
// orderMaster.setOrderStatuses();
// }
List<OrderMaster> list = orderMasterService.selectOrderMasterList(orderMaster);
if (CollectionUtils.isEmpty(list)) {
return voDataTable(orderListResponses, new ArrayList<>());
}
// 优化1收集所有需要查询的ID避免重复查询
Set<Long> workerIds = new HashSet<>();
Set<Long> addressIds = new HashSet<>();
Set<Long> goodsIds = new HashSet<>();
list.forEach(master -> {
if (master.getWorkerId() != null) {
workerIds.add(master.getWorkerId());
}
if (master.getAddressId() != null) {
addressIds.add(master.getAddressId());
}
if (master.getGoodsId() != null) {
goodsIds.add(master.getGoodsId());
}
});
// 优化2批量查询常用数据避免循环中的重复查询
Map<Long, Worker> workerMap = new HashMap<>();
Map<Long, CustomerAddress> addressMap = new HashMap<>();
Map<Long, Goods> goodsMap = new HashMap<>();
if (!CollectionUtils.isEmpty(workerIds)) {
List<Worker> workers = workerService.selectByIds(workerIds);
workers.forEach(worker -> workerMap.put(worker.getId(), worker));
}
if (!CollectionUtils.isEmpty(addressIds)) {
List<CustomerAddress> addresses = addressService.selectByCustomerAddressIds(addressIds);
addresses.forEach(address -> addressMap.put(address.getCustomerAddressId(), address));
}
if (!CollectionUtils.isEmpty(goodsIds)) {
List<Goods> goodsList = goodsService.selectByIds(goodsIds);
goodsList.forEach(goods -> goodsMap.put(goods.getGoodsId(), goods));
}
list.forEach(master -> {
//子单
List<OrderDetail> detailList = orderDetailService.selectByOrderMasterId(master.getId());
@ -995,19 +1037,26 @@ public class OrderMasterController extends BaseController {
OrderListResponse orderListResponse = new OrderListResponse();
List<OrderStandard> standardList = new ArrayList<>();
// 师傅信息
Worker worker = master.getWorkerId() != null ? workerService.selectById(master.getWorkerId()) : null;
// 优化3使用预查询的师傅信息
Worker worker = workerMap.get(master.getWorkerId());
// 消费者信息
// Customer customer = customerService.selectByCustomerId(master.getCustomerId());
// 商品规格及信息
List<OrderGoods> orderStandardList = orderGoodsService.selectByOrderMasterId(master.getId());
Goods goods = new Goods();
if (orderStandardList.size() > 0) {
// 商品信息
GoodsStandard goodsStandard = goodsStandardService.selectById(orderStandardList.get(0).getGoodsStandardId());
if (goodsStandard != null) {
goods = goodsService.selectById(goodsStandard.getGoodsId());
}
} else {
// 优化4使用预查询的商品信息
goods = goodsMap.getOrDefault(master.getGoodsId(), new Goods());
}
Goods goods = goodsService.selectById(goodsStandard.getGoodsId());
// 填充商品三级类目
if (goods.getDeptGoodsCategoryId() != null) {
Long categoryId = null;
@ -1053,7 +1102,6 @@ public class OrderMasterController extends BaseController {
.map(FinancialChangeRecord::getChangeMoney)
.reduce(BigDecimal.ZERO, BigDecimal::add);
paymentMoney = paymentMoney.add(changePaymentMoney);
logger.info("加价费已支付{}加价列表{}主单id为{}",changePaymentMoney,financialChangeRecords,master.getId());
for (OrderDetail detail : detailList) {
// 查询子单加价记录
@ -1072,22 +1120,27 @@ public class OrderMasterController extends BaseController {
paymentMoney = paymentMoney.add(orderAttachmentRecord.getAttachMoney());
}
}
logger.info("未支付的加价订单{}加价配件订单列表{}",record,orderAttachmentRecordList);
}
// 地址信息
CustomerAddress customerAddress = addressService.selectByCustomerAddressId(master.getAddressId());
// 优化5使用预查询的地址信息
CustomerAddress customerAddress = addressMap.get(master.getAddressId());
if (customerAddress == null) {
customerAddress = new CustomerAddress();
}
SysArea sysArea;
if (customerAddress.getStreetId() != null) {
sysArea = sysAreaService.selectById(customerAddress.getStreetId());
} else {
sysArea = sysAreaService.selectById(customerAddress.getCountryId());
}
String completeAddress = sysArea.getMergerName().replaceAll(",", "") + customerAddress.getAddress();
String completeAddress = "";
if (sysArea != null) {
completeAddress = sysArea.getMergerName().replaceAll(",", "") + customerAddress.getAddress();
}
// 查询售后记录
// 优化6避免重复查询订单详情
List<AfterServiceRecord> afterServiceRecords = new ArrayList<>();
List<OrderDetail> detailOrderList = orderDetailService.selectByOrderMasterId(master.getId());
detailOrderList.forEach(detail -> {
// 直接使用已经查询的detailList避免重复查询
detailList.forEach(detail -> {
AfterServiceRecord afterServiceRecordQry = new AfterServiceRecord();
afterServiceRecordQry.setOrderDetailId(detail.getId());
List<AfterServiceRecord> records = afterServiceRecordService.selectAfterServiceRecordList(afterServiceRecordQry);
@ -1156,13 +1209,21 @@ public class OrderMasterController extends BaseController {
orderListResponse.setAddress(master.getAddress());
} else {
if (!StringUtils.isEmpty(customerAddress.getStreetId() + "")) {
String addressSysArea=sysArea.getMergerName();
String addressSysArea = sysArea != null ? sysArea.getMergerName() : "";
String[] array = addressSysArea.split(",");
if (array.length > 0) {
orderListResponse.setProvinceName(array[0]);
}
if (array.length > 1) {
orderListResponse.setCityName(array[1]);
}
if (array.length == 3) {
orderListResponse.setCountryName(array[2]);
}
if (array.length == 4) {
orderListResponse.setStreetName(array[3]);
}
}
orderListResponse.setProvinceId(customerAddress.getProvinceId());
orderListResponse.setCityId(customerAddress.getCityId());
orderListResponse.setCountryId(customerAddress.getCountryId());
@ -1170,24 +1231,9 @@ public class OrderMasterController extends BaseController {
orderListResponse.setAddress(customerAddress.getAddress());
orderListResponse.setPhone(customerAddress.getPhone());
orderListResponse.setName(customerAddress.getName());
}
orderListResponses.add(orderListResponse);
});
// PageDomain pageDomain = TableSupport.buildPageRequest();
// if (null == pageDomain.getPageNum() || null == pageDomain.getPageSize()) {
// rspData.setRows(orderListResponses);
// rspData.setTotal(orderListResponses.size());
// return rspData;
// }
// Integer pageSize = pageDomain.getPageNum();
// if (pageSize > orderListResponses.size()) {
// pageSize = orderListResponses.size();
// }
// rspData.setRows(orderListResponses.subList(0, pageSize));
// rspData.setTotal(orderListResponses.size());
return voDataTable(orderListResponses, list);
}
@ -1661,9 +1707,14 @@ public class OrderMasterController extends BaseController {
String[] array = addressSysArea.split(",");
orderListResponse.setProvinceName(array[0]);
orderListResponse.setCityName(array[1]);
if (array.length==3){
orderListResponse.setCountryName(array[2]);
}
if (array.length==4){
orderListResponse.setStreetName(array[3]);
}
}
orderListResponse.setProvinceId(customerAddress.getProvinceId());
orderListResponse.setCityId(customerAddress.getCityId());
orderListResponse.setCountryId(customerAddress.getCountryId());