|
@@ -1,11 +1,6 @@
|
|
|
package com.sd.business.service.purchase.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.ListUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.excel.util.ListUtils;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
@@ -15,12 +10,15 @@ import com.sd.business.entity.purchase.po.Purchase;
|
|
|
import com.sd.business.entity.purchase.po.PurchaseBom;
|
|
|
import com.sd.business.entity.purchase.vo.PurchaseBomVo;
|
|
|
import com.sd.business.entity.purchase.vo.PurchaseVo;
|
|
|
+import com.sd.business.entity.supplier.po.Supplier;
|
|
|
import com.sd.business.mapper.purchase.PurchaseMapper;
|
|
|
+import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.purchase.PurchaseBomService;
|
|
|
import com.sd.business.service.purchase.PurchaseService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -36,39 +34,47 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService {
|
|
|
+
|
|
|
@Autowired
|
|
|
private PurchaseBomService purchaseBomService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
|
- //采购单号
|
|
|
- wrapper.like("p",Purchase::getCode,dto.getCode());
|
|
|
- //采购单价
|
|
|
- wrapper.eq("p",Purchase::getFlowStatus,dto.getFlowStatus());
|
|
|
- //供应商名称
|
|
|
- wrapper.like("s.name",dto.getSupplierName());
|
|
|
- wrapper.orderByDesc("p", Purchase::getCreateTime);
|
|
|
- //查询采购单数据
|
|
|
+ wrapper.like("p", Purchase::getCode, dto.getCode());
|
|
|
+ wrapper.eq("p", Purchase::getFlowStatus, dto.getFlowStatus());
|
|
|
+ wrapper.like("s", Supplier::getName, dto.getSupplierName());
|
|
|
+ wrapper.orderByDesc("p", Purchase::getId);
|
|
|
+
|
|
|
+ // 查询采购单数据
|
|
|
Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
|
|
|
List<PurchaseVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
|
|
|
- //获取到采购单ID
|
|
|
- List<Long> ids = records.stream().map(PurchaseVo::getId).collect(Collectors.toList());
|
|
|
- //查询采购单详情数据
|
|
|
- LambdaQueryWrapper<PurchaseBom> query = Wrappers.lambdaQuery();
|
|
|
- query.in(PurchaseBom::getPurchaseId,ids);
|
|
|
- List<PurchaseBomVo> purchaseBomVoList = purchaseBomService.getList(query);
|
|
|
- Map<Long, List<PurchaseBomVo>> purchaseBomVoMap = purchaseBomVoList.stream().collect(Collectors.groupingBy(PurchaseBomVo::getPurchaseId));
|
|
|
+ // 赋值采购明细
|
|
|
+ List<Long> idList = records.stream().map(PurchaseVo::getId).collect(Collectors.toList());
|
|
|
+ List<PurchaseBom> list = purchaseBomService.list(q -> q.in(PurchaseBom::getPurchaseId, idList));
|
|
|
+ List<PurchaseBomVo> purchaseBomList = BeanUtil.copyToList(list, PurchaseBomVo.class);
|
|
|
+ bomSpecService.attributeAssign(purchaseBomList, PurchaseBom::getBomSpecId, (item, bomSpec) -> {
|
|
|
+ item.setBomSpecCode(bomSpec.getCode());
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
+ item.setBomSpecColour(bomSpec.getColour());
|
|
|
+ item.setBomSpecLength(bomSpec.getLength());
|
|
|
+ item.setBomSpecWidth(bomSpec.getWidth());
|
|
|
+ item.setBomSpecHeight(bomSpec.getHeight());
|
|
|
+ });
|
|
|
|
|
|
- //赋值采购详情数据
|
|
|
+ Map<Long, List<PurchaseBomVo>> map = purchaseBomList.stream().collect(Collectors.groupingBy(PurchaseBom::getPurchaseId));
|
|
|
for (PurchaseVo record : records) {
|
|
|
- List<PurchaseBomVo> purchaseBomVos = purchaseBomVoMap.get(record.getId());
|
|
|
- if (ObjectUtil.isEmpty(purchaseBomVos)){
|
|
|
- record.setPurchaseBomVoList(purchaseBomVos);
|
|
|
- }
|
|
|
+ record.setPurchaseBomList(map.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
}
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|