Showing
1 changed file
with
15 additions
and
4 deletions
| @@ -31,7 +31,10 @@ import org.springframework.web.bind.annotation.*; | @@ -31,7 +31,10 @@ import org.springframework.web.bind.annotation.*; | ||
| 31 | import javax.annotation.Resource; | 31 | import javax.annotation.Resource; |
| 32 | import javax.validation.Valid; | 32 | import javax.validation.Valid; |
| 33 | import javax.validation.constraints.NotBlank; | 33 | import javax.validation.constraints.NotBlank; |
| 34 | +import java.util.Collections; | ||
| 34 | import java.util.List; | 35 | import java.util.List; |
| 36 | +import java.util.Map; | ||
| 37 | +import java.util.function.Function; | ||
| 35 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; |
| 36 | 39 | ||
| 37 | /** | 40 | /** |
| @@ -66,12 +69,20 @@ public class DraftRequestCarTicketController extends DefaultBaseController { | @@ -66,12 +69,20 @@ public class DraftRequestCarTicketController extends DefaultBaseController { | ||
| 66 | if (!CollectionUtil.isEmpty(datas)) { | 69 | if (!CollectionUtil.isEmpty(datas)) { |
| 67 | String currentUserId = SecurityUtil.getCurrentUser().getId(); | 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 | results = datas.stream().map(draftRequestCarTicket -> { | 83 | results = datas.stream().map(draftRequestCarTicket -> { |
| 70 | GetDraftRequestCarTicketBo bo = new GetDraftRequestCarTicketBo(draftRequestCarTicket); | 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 | // 判断 createById 是否等于当前用户 ID | 86 | // 判断 createById 是否等于当前用户 ID |
| 76 | boolean isCreateBy = false; | 87 | boolean isCreateBy = false; |
| 77 | if (purchaseOrderInfo != null && currentUserId.equals(purchaseOrderInfo.getContractCreateById())) { | 88 | if (purchaseOrderInfo != null && currentUserId.equals(purchaseOrderInfo.getContractCreateById())) { |