|
@@ -3,18 +3,24 @@ package com.fjhx.purchase.service.purchase.impl;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
|
+import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
|
+import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
|
|
import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
|
|
import com.fjhx.purchase.mapper.purchase.PurchaseMapper;
|
|
import com.fjhx.purchase.mapper.purchase.PurchaseMapper;
|
|
|
|
+import com.fjhx.purchase.service.arrival.ArrivalDetailService;
|
|
import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fjhx.purchase.util.code.CodeEnum;
|
|
import com.fjhx.purchase.util.code.CodeEnum;
|
|
import com.fjhx.supply.entity.supplier.po.SupplierInfo;
|
|
import com.fjhx.supply.entity.supplier.po.SupplierInfo;
|
|
import com.fjhx.supply.service.supplier.SupplierInfoService;
|
|
import com.fjhx.supply.service.supplier.SupplierInfoService;
|
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,6 +32,7 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
|
|
import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -46,6 +53,14 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Autowired
|
|
@Autowired
|
|
private SupplierInfoService supplierInfoService;
|
|
private SupplierInfoService supplierInfoService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PurchaseDetailService purchaseDetailService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ArrivalDetailService arrivalDetailService;
|
|
/**
|
|
/**
|
|
* 列表
|
|
* 列表
|
|
* @param dto
|
|
* @param dto
|
|
@@ -54,7 +69,16 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Override
|
|
@Override
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
- wrapper.orderByDesc("p", Purchase::getId);
|
|
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
List<PurchaseVo> list = page.getRecords();
|
|
List<PurchaseVo> list = page.getRecords();
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
@@ -78,8 +102,39 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public PurchaseVo detail(Long id) {
|
|
public PurchaseVo detail(Long id) {
|
|
- Purchase Purchase = this.getById(id);
|
|
|
|
- PurchaseVo result = BeanUtil.toBean(Purchase, PurchaseVo.class);
|
|
|
|
|
|
+ Purchase purchase = this.getById(id);
|
|
|
|
+ if(ObjectUtils.isEmpty(purchase)){
|
|
|
|
+ throw new ServiceException("采购单不存在");
|
|
|
|
+ }
|
|
|
|
+ //查询出供应商名称
|
|
|
|
+ SupplierInfo info = supplierInfoService.getById(purchase.getSupplyId());
|
|
|
|
+ PurchaseVo result = BeanUtil.toBean(purchase, PurchaseVo.class);
|
|
|
|
+ result.setSupplyName(info.getName());
|
|
|
|
+ //查询出采购明细列表
|
|
|
|
+ List<PurchaseDetail> purchaseDetailList = purchaseDetailService.
|
|
|
|
+ list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId,id));
|
|
|
|
+ //查询出产品
|
|
|
|
+ if(CollectionUtils.isNotEmpty(purchaseDetailList)){
|
|
|
|
+ List<Long> productIds = purchaseDetailList.stream().map(PurchaseDetail::getBussinessId).collect(Collectors.toList());
|
|
|
|
+ List<ProductInfoVo> productInfos = productInfoService.getListByProductIds(productIds);
|
|
|
|
+ Map<Long,List<ProductInfoVo>> productMap = productInfos.stream().distinct().collect(Collectors.groupingBy(ProductInfoVo::getId));
|
|
|
|
+ if(MapUtils.isNotEmpty(productMap)){
|
|
|
|
+ for(PurchaseDetail p:purchaseDetailList){
|
|
|
|
+ //查询出到货总量
|
|
|
|
+ BigDecimal sumArrivalCount = arrivalDetailService.getSumCount(p.getId(),p.getBussinessId());
|
|
|
|
+ p.setSumArrivalCount(sumArrivalCount);
|
|
|
|
+ List<ProductInfoVo> productInfoVos = productMap.getOrDefault(p.getBussinessId(),null);
|
|
|
|
+ ProductInfoVo vo = productInfoVos.get(0);
|
|
|
|
+ p.setProductCode(vo.getCode());
|
|
|
|
+ p.setProductName(vo.getName());
|
|
|
|
+ p.setProductType(vo.getType());
|
|
|
|
+ p.setProductCategory(vo.getClassifyName());
|
|
|
|
+ p.setProductUnit(vo.getUnit());
|
|
|
|
+ p.setProductSpec(vo.getSpec());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result.setPurchaseDetailList(purchaseDetailList);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|