Bläddra i källkod

采购分页代码优化

24282 2 år sedan
förälder
incheckning
ad8d3313d9

+ 23 - 40
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/impl/PurchaseServiceImpl.java

@@ -17,7 +17,6 @@ import com.fjhx.common.entity.documentary.bo.DocumentaryData;
 import com.fjhx.common.enums.CodingRuleEnum;
 import com.fjhx.common.service.coding.CodingRuleService;
 import com.fjhx.common.service.documentary.GetDocumentaryBusinessTemplate;
-import com.fjhx.customer.service.customer.CustomerService;
 import com.fjhx.item.entity.product.vo.ProductInfoVo;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.purchase.entity.invoice.vo.InvoiceDetailsVo;
@@ -35,12 +34,10 @@ import com.fjhx.purchase.entity.subscribe.po.Subscribe;
 import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.mapper.purchase.PurchaseMapper;
 import com.fjhx.purchase.service.arrival.ArrivalDetailService;
-import com.fjhx.purchase.service.arrival.ArrivalService;
 import com.fjhx.purchase.service.invoice.InvoiceDetailsService;
 import com.fjhx.purchase.service.pay.PayDetailService;
 import com.fjhx.purchase.service.purchase.PurchaseDetailService;
 import com.fjhx.purchase.service.purchase.PurchasePayRecordDetailService;
-import com.fjhx.purchase.service.purchase.PurchasePayRecordService;
 import com.fjhx.purchase.service.purchase.PurchaseService;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.purchase.service.subscribe.SubscribeService;
@@ -94,25 +91,19 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
     private ArrivalDetailService arrivalDetailService;
 
     @Autowired
-    private CustomerService customerService;
+    private WarehouseService warehouseService;
 
     @Autowired
-    WarehouseService warehouseService;
+    private SubscribeDetailService subscribeDetailService;
 
     @Autowired
-    ArrivalService arrivalService;
-    @Autowired
-    SubscribeDetailService subscribeDetailService;
-    @Autowired
-    SubscribeService subscribeService;
-
+    private SubscribeService subscribeService;
 
     @Autowired
     private CodingRuleService codingRuleService;
+
     @Autowired
     private PurchasePayRecordDetailService purchasePayRecordDetailService;
-    @Autowired
-    private PurchasePayRecordService purchasePayRecordService;
 
     /**
      * 列表
@@ -123,39 +114,31 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
     @Override
     public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
         IWrapper<Purchase> wrapper = getWrapper();
-        wrapper.orderByDesc("p", Purchase::getCreateTime);
-        if (ObjectUtils.isNotEmpty(dto.getPurchaseStatus())) {
-            wrapper.eq("p", Purchase::getPurchaseStatus, dto.getPurchaseStatus());
-        }
-        if (ObjectUtils.isNotEmpty(dto.getArrivalStatus())) {
-            wrapper.eq("p", Purchase::getArrivalStatus, dto.getArrivalStatus());
-        }
-        if (ObjectUtils.isNotEmpty(dto.getPayStatus())) {
-            wrapper.eq("p", Purchase::getPayStatus, dto.getPayStatus());
-        }
 
-        wrapper.like("p",Purchase::getCode,dto.getCode());//采购单号
-        wrapper.eq("p",Purchase::getSupplyId,dto.getSupplyId());//供应商ID
+        wrapper.eq("p", Purchase::getPurchaseStatus, dto.getPurchaseStatus());
+        wrapper.eq("p", Purchase::getArrivalStatus, dto.getArrivalStatus());
+        wrapper.eq("p", Purchase::getPayStatus, dto.getPayStatus());
+        wrapper.like("p", Purchase::getCode, dto.getCode());// 采购单号
+        wrapper.eq("p", Purchase::getSupplyId, dto.getSupplyId());// 供应商ID
+        wrapper.eq("p", Purchase::getCode, dto.getKeyword());// 根据采购单号关键字搜索
+        wrapper.ge("p", Purchase::getAmount, dto.getStartAmount());// 采购开始金额
+        wrapper.le("p", Purchase::getAmount, dto.getEndAmount());// 采购结束金额
+        wrapper.ge("P", Purchase::getCreateTime, dto.getBeginTime());// 采购开始时间
+        wrapper.le("p", Purchase::getCreateTime, dto.getEndTime());// 采购结束时间
 
-        wrapper.eq("p", Purchase::getCode, dto.getKeyword());//根据采购单号关键字搜索
+        wrapper.orderByDesc("p", Purchase::getCreateTime);
 
-        wrapper.ge("p",Purchase::getAmount,dto.getStartAmount());//采购开始金额
-        wrapper.le("p",Purchase::getAmount,dto.getEndAmount());//采购结束金额
-        wrapper.ge("P",Purchase::getCreateTime,dto.getBeginTime());//采购开始时间
-        wrapper.le("p",Purchase::getCreateTime,dto.getEndTime());//采购结束时间
         Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<PurchaseVo> list = page.getRecords();
-        if (CollectionUtils.isNotEmpty(list)) {
-            List<Long> supplyIds = list.stream().map(PurchaseVo::getSupplyId).collect(Collectors.toList());
-            List<SupplierInfo> supplierInfoList = supplierInfoService.list(Wrappers.<SupplierInfo>query().lambda().in(SupplierInfo::getId, supplyIds));
-            Map<Long, List<SupplierInfo>> supplyMap = supplierInfoList.stream().distinct().collect(Collectors.groupingBy(SupplierInfo::getId));
-            if (MapUtils.isNotEmpty(supplyMap)) {
-                for (PurchaseVo p : list) {
-                    List<SupplierInfo> supplys = supplyMap.getOrDefault(p.getSupplyId(), null);
-                    p.setSupplyName(supplys == null ? null : supplys.get(0).getName());
-                }
-            }
+
+        if (CollectionUtils.isEmpty(list)) {
+            return page;
         }
+
+        supplierInfoService.attributeAssign(list, PurchaseVo::getSupplyId, (item, supplierInfo) -> {
+            item.setSupplyName(supplierInfo.getName());
+        });
+
         return page;
     }