|
@@ -15,6 +15,7 @@ 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.arrival.po.Arrival;
|
|
|
import com.fjhx.purchase.entity.invoice.vo.InvoiceDetailsVo;
|
|
|
import com.fjhx.purchase.entity.pay.vo.PayDetailVo;
|
|
|
import com.fjhx.purchase.entity.purchase.bo.PurchaseDocumentaryBo;
|
|
@@ -27,6 +28,7 @@ import com.fjhx.purchase.entity.purchase.vo.PurchaseDocumentaryVo;
|
|
|
import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
|
|
|
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;
|
|
@@ -34,6 +36,8 @@ import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
import com.fjhx.purchase.util.code.CodeEnum;
|
|
|
import com.fjhx.supply.entity.supplier.po.SupplierInfo;
|
|
|
import com.fjhx.supply.service.supplier.SupplierInfoService;
|
|
|
+import com.fjhx.wms.entity.warehouse.po.Warehouse;
|
|
|
+import com.fjhx.wms.service.warehouse.WarehouseService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.core.domain.BaseSelectDto;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
@@ -44,6 +48,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -82,6 +87,10 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
|
|
|
@Autowired
|
|
|
private CustomerService customerService;
|
|
|
+ @Autowired
|
|
|
+ WarehouseService warehouseService;
|
|
|
+ @Autowired
|
|
|
+ ArrivalService arrivalService;
|
|
|
|
|
|
/**
|
|
|
* 列表
|
|
@@ -93,25 +102,80 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
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.getPurchaseStatus())) {
|
|
|
+ wrapper.eq("p", Purchase::getPurchaseStatus, dto.getPurchaseStatus());
|
|
|
}
|
|
|
- if(ObjectUtils.isNotEmpty(dto.getArrivalStatus())){
|
|
|
- wrapper.eq("p",Purchase::getArrivalStatus,dto.getArrivalStatus());
|
|
|
+ if (ObjectUtils.isNotEmpty(dto.getArrivalStatus())) {
|
|
|
+ wrapper.eq("p", Purchase::getArrivalStatus, dto.getArrivalStatus());
|
|
|
}
|
|
|
- if(ObjectUtils.isNotEmpty(dto.getPayStatus())){
|
|
|
- wrapper.eq("p",Purchase::getPayStatus,dto.getPayStatus());
|
|
|
+ if (ObjectUtils.isNotEmpty(dto.getPayStatus())) {
|
|
|
+ wrapper.eq("p", Purchase::getPayStatus, dto.getPayStatus());
|
|
|
}
|
|
|
+ wrapper.eq("p", Purchase::getCode, dto.getKeyword());//根据采购单号关键字搜索
|
|
|
Page<PurchaseVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
List<PurchaseVo> list = page.getRecords();
|
|
|
- if(CollectionUtils.isNotEmpty(list)){
|
|
|
+ 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());
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PurchaseVo> getPageByWdly(PurchaseSelectDto dto) {
|
|
|
+ Page<PurchaseVo> page = getPage(dto);
|
|
|
+ List<PurchaseVo> list = page.getRecords();
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ //维多利亚 赋值收货仓库名称
|
|
|
+ List<Long> wids = new ArrayList<>();
|
|
|
+ for (PurchaseVo purchaseVo : list) {
|
|
|
+ String victoriatouristJson = purchaseVo.getVictoriatouristJson();
|
|
|
+ if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ wids.add(json.getLong("receiptWarehouseId"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isEmpty(wids)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ List<Warehouse> warehouses = warehouseService.listByIds(wids);
|
|
|
+ Map<Long, String> warehousesMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
|
|
|
+ for (PurchaseVo purchaseVo : list) {
|
|
|
+ String victoriatouristJson = purchaseVo.getVictoriatouristJson();
|
|
|
+ if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ String warehouseName = warehousesMap.get(json.getLong("receiptWarehouseId"));
|
|
|
+ json.put("receiptWarehouseName", warehouseName);
|
|
|
+ purchaseVo.setVictoriatouristJson(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //赋值到货状态
|
|
|
+ List<Long> pids = list.stream().map(PurchaseVo::getId).collect(Collectors.toList());
|
|
|
+ List<Arrival> arrivalList = arrivalService.list(q -> q.in(Arrival::getPurchaseId, pids));
|
|
|
+ Map<Long, List<Arrival>> arrivalMap = arrivalList.stream().collect(Collectors.groupingBy(Arrival::getPurchaseId));
|
|
|
+ for (PurchaseVo purchaseVo : list) {
|
|
|
+ List<Arrival> list1 = arrivalMap.get(purchaseVo.getId());
|
|
|
+ if(ObjectUtils.isEmpty(list1)){
|
|
|
+ purchaseVo.setArrivalStatus(0);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<Arrival> arrivalCount = list1.stream().filter(q -> q.equals(1)).collect(Collectors.toList());
|
|
|
+ if(arrivalCount.size()==0){
|
|
|
+ //未到货
|
|
|
+ purchaseVo.setArrivalStatus(0);
|
|
|
+ }else if(arrivalCount.size()<=list1.size()){
|
|
|
+ //部分到货
|
|
|
+ purchaseVo.setArrivalStatus(1);
|
|
|
+ }else{
|
|
|
+ //完全到货
|
|
|
+ purchaseVo.setArrivalStatus(2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -120,13 +184,14 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
|
|
|
/**
|
|
|
* 详情
|
|
|
+ *
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public PurchaseVo detail(Long id) {
|
|
|
Purchase purchase = this.getById(id);
|
|
|
- if(ObjectUtils.isEmpty(purchase)){
|
|
|
+ if (ObjectUtils.isEmpty(purchase)) {
|
|
|
throw new ServiceException("采购单不存在");
|
|
|
}
|
|
|
//查询出供应商名称
|
|
@@ -135,18 +200,18 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
result.setSupplyName(info.getName());
|
|
|
//查询出采购明细列表
|
|
|
List<PurchaseDetail> purchaseDetailList = purchaseDetailService.
|
|
|
- list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId,id));
|
|
|
+ list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, id));
|
|
|
//查询出产品
|
|
|
- if(CollectionUtils.isNotEmpty(purchaseDetailList)){
|
|
|
+ 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){
|
|
|
+ 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());
|
|
|
+ BigDecimal sumArrivalCount = arrivalDetailService.getSumCount(p.getId(), p.getBussinessId());
|
|
|
p.setSumArrivalCount(sumArrivalCount);
|
|
|
- List<ProductInfoVo> productInfoVos = productMap.getOrDefault(p.getBussinessId(),null);
|
|
|
+ List<ProductInfoVo> productInfoVos = productMap.getOrDefault(p.getBussinessId(), null);
|
|
|
ProductInfoVo vo = productInfoVos.get(0);
|
|
|
p.setProductCode(vo.getCode());
|
|
|
p.setProductName(vo.getName());
|
|
@@ -163,6 +228,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
|
|
|
/**
|
|
|
* 采购新增
|
|
|
+ *
|
|
|
* @param purchase
|
|
|
*/
|
|
|
@Override
|
|
@@ -172,8 +238,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
purchaseService.save(purchase);
|
|
|
- if(CollectionUtils.isNotEmpty(purchase.getPurchaseDetailList())){
|
|
|
- for(PurchaseDetail s : purchase.getPurchaseDetailList()){
|
|
|
+ if (CollectionUtils.isNotEmpty(purchase.getPurchaseDetailList())) {
|
|
|
+ for (PurchaseDetail s : purchase.getPurchaseDetailList()) {
|
|
|
s.setPurchaseId(purchase.getId());
|
|
|
}
|
|
|
purchaseDetailService.saveBatch(purchase.getPurchaseDetailList());
|
|
@@ -192,6 +258,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
|
|
|
|
|
|
/**
|
|
|
* 根据供应商查询采购合同
|
|
|
+ *
|
|
|
* @param supplyId
|
|
|
* @return
|
|
|
*/
|