Commit cc2cf7d3e93c4ccab16837fea28954e8e31ae1ef

Authored by 房远帅
1 parent 586d7043

销售-草稿要车单:查询速度优化

... ... @@ -31,7 +31,10 @@ import org.springframework.web.bind.annotation.*;
31 31 import javax.annotation.Resource;
32 32 import javax.validation.Valid;
33 33 import javax.validation.constraints.NotBlank;
  34 +import java.util.Collections;
34 35 import java.util.List;
  36 +import java.util.Map;
  37 +import java.util.function.Function;
35 38 import java.util.stream.Collectors;
36 39
37 40 /**
... ... @@ -66,12 +69,20 @@ public class DraftRequestCarTicketController extends DefaultBaseController {
66 69 if (!CollectionUtil.isEmpty(datas)) {
67 70 String currentUserId = SecurityUtil.getCurrentUser().getId();
68 71
  72 + // 批量查询订货单数据,避免循环内逐条查库拖慢列表
  73 + List<String> purchaseOrderIds = datas.stream()
  74 + .map(DraftRequestCarTicket::getPurchaseOrderId)
  75 + .filter(StringUtils::isNotEmpty)
  76 + .distinct()
  77 + .collect(Collectors.toList());
  78 + Map<String, PurchaseOrderInfo> orderInfoMap = purchaseOrderIds.isEmpty()
  79 + ? Collections.emptyMap()
  80 + : purchaseOrderInfoService.listByIds(purchaseOrderIds).stream()
  81 + .collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
  82 +
69 83 results = datas.stream().map(draftRequestCarTicket -> {
70 84 GetDraftRequestCarTicketBo bo = new GetDraftRequestCarTicketBo(draftRequestCarTicket);
71   - PurchaseOrderInfo purchaseOrderInfo = null;
72   - if (StringUtils.isNotEmpty(draftRequestCarTicket.getPurchaseOrderId())) {
73   - purchaseOrderInfo = purchaseOrderInfoService.findById(draftRequestCarTicket.getPurchaseOrderId());
74   - }
  85 + PurchaseOrderInfo purchaseOrderInfo = orderInfoMap.get(draftRequestCarTicket.getPurchaseOrderId());
75 86 // 判断 createById 是否等于当前用户 ID
76 87 boolean isCreateBy = false;
77 88 if (purchaseOrderInfo != null && currentUserId.equals(purchaseOrderInfo.getContractCreateById())) {
... ...