|
@@ -3,15 +3,18 @@ package com.fjhx.service.purchase.impl;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fjhx.base.BaseEntity;
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
import com.fjhx.entity.logistics.LogisticsInfo;
|
|
import com.fjhx.entity.logistics.LogisticsInfo;
|
|
import com.fjhx.entity.purchase.Purchase;
|
|
import com.fjhx.entity.purchase.Purchase;
|
|
|
|
+import com.fjhx.entity.supplier.Supplier;
|
|
import com.fjhx.enums.apply.ApplyPurchaseStatusEnum;
|
|
import com.fjhx.enums.apply.ApplyPurchaseStatusEnum;
|
|
import com.fjhx.enums.purchase.PurchaseStatusEnum;
|
|
import com.fjhx.enums.purchase.PurchaseStatusEnum;
|
|
import com.fjhx.mapper.purchase.PurchaseMapper;
|
|
import com.fjhx.mapper.purchase.PurchaseMapper;
|
|
import com.fjhx.service.apply.ApplyPurchaseService;
|
|
import com.fjhx.service.apply.ApplyPurchaseService;
|
|
import com.fjhx.service.logistics.LogisticsInfoService;
|
|
import com.fjhx.service.logistics.LogisticsInfoService;
|
|
import com.fjhx.service.purchase.PurchaseService;
|
|
import com.fjhx.service.purchase.PurchaseService;
|
|
|
|
+import com.fjhx.service.supplier.SupplierService;
|
|
import com.fjhx.utils.UserClientUtil;
|
|
import com.fjhx.utils.UserClientUtil;
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
@@ -41,6 +44,9 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Autowired
|
|
@Autowired
|
|
private LogisticsInfoService logisticsInfoService;
|
|
private LogisticsInfoService logisticsInfoService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SupplierService supplierService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 待采购列表
|
|
* 待采购列表
|
|
*
|
|
*
|
|
@@ -69,25 +75,36 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
.orderByDesc(ApplyPurchase::getId);
|
|
.orderByDesc(ApplyPurchase::getId);
|
|
|
|
|
|
Page<Purchase> page = page(condition, wrapper);
|
|
Page<Purchase> page = page(condition, wrapper);
|
|
- if (Func.isNotEmpty(page.getRecords())) {
|
|
|
|
- //采购ID集合
|
|
|
|
- List<Long> purchaseIds = page.getRecords().stream().map(Purchase::getId).distinct().collect(Collectors.toList());
|
|
|
|
- //查询物流信息
|
|
|
|
- Map<Long, List<LogisticsInfo>> logisticsInfoMap = logisticsInfoService.getByPurchaseIdsToMap(purchaseIds);
|
|
|
|
-
|
|
|
|
- //采购人名称map
|
|
|
|
- Map<Long, String> userNameMap = UserClientUtil.getUserNameMap(page.getRecords(), Purchase::getCreateUser);
|
|
|
|
-
|
|
|
|
- for (Purchase record : page.getRecords()) {
|
|
|
|
- if (Func.isNotEmpty(logisticsInfoMap) && Func.isNotEmpty(logisticsInfoMap.get(record.getId()))) {
|
|
|
|
- List<LogisticsInfo> infos = logisticsInfoMap.get(record.getId());
|
|
|
|
- record.setLogisticsCode(infos.stream().map(LogisticsInfo::getCode).distinct().collect(Collectors.joining(",")));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Func.isNotEmpty(userNameMap) && Func.isNotEmpty(userNameMap.get(record.getCreateUser()))) {
|
|
|
|
- record.setCreateName(userNameMap.get(record.getCreateUser()));
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ List<Purchase> records = page.getRecords();
|
|
|
|
+
|
|
|
|
+ if (records.size() == 0) {
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 采购ID集合
|
|
|
|
+ List<Long> purchaseIds = records.stream().map(Purchase::getId).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 查询物流信息
|
|
|
|
+ Map<Long, List<LogisticsInfo>> logisticsInfoMap = logisticsInfoService.getByPurchaseIdsToMap(purchaseIds);
|
|
|
|
+
|
|
|
|
+ // 采购人名称map
|
|
|
|
+ Map<Long, String> userNameMap = UserClientUtil.getUserNameMap(records, Purchase::getCreateUser);
|
|
|
|
+
|
|
|
|
+ // 供应商
|
|
|
|
+ List<Long> supplierIdList = records.stream().map(Purchase::getSupplierId).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList());
|
|
|
|
+ Map<Long, String> supplierIdNameMap = supplierService.getKV(Supplier::getId, Supplier::getName, q -> q.in(BaseEntity::getId, supplierIdList));
|
|
|
|
+
|
|
|
|
+ for (Purchase record : records) {
|
|
|
|
+ // 赋值物流单号
|
|
|
|
+ List<LogisticsInfo> logisticsInfos = logisticsInfoMap.get(record.getId());
|
|
|
|
+ if (ObjectUtil.isNotEmpty(logisticsInfos)) {
|
|
|
|
+ record.setLogisticsCode(logisticsInfos.stream().map(LogisticsInfo::getCode).distinct().collect(Collectors.joining(",")));
|
|
}
|
|
}
|
|
|
|
+ // 赋值采购人名称
|
|
|
|
+ record.setCreateName(userNameMap.get(record.getCreateUser()));
|
|
|
|
+ // 赋值供应商名称
|
|
|
|
+ record.setSupplierName(supplierIdNameMap.get(ObjectUtil.defaultIfNull(record.getSupplierId(), -1L)));
|
|
}
|
|
}
|
|
|
|
|
|
return page;
|
|
return page;
|