|
@@ -1,7 +1,6 @@
|
|
|
package com.sd.business.service.purchase.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -18,7 +17,6 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
-import com.sd.business.entity.order.po.OrderInfo;
|
|
|
import com.sd.business.entity.purchase.dto.*;
|
|
|
import com.sd.business.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
import com.sd.business.entity.purchase.po.Purchase;
|
|
@@ -310,7 +308,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
// 采购入库查询排除胜德塑胶供应商
|
|
|
if (ObjectUtil.equals(dto.getQueryType(), 1)) {
|
|
|
wrapper.ne("s", Supplier::getName, "福清市胜德塑胶制品有限公司");
|
|
|
- wrapper.eq("p", Purchase::getStatus, PurchaseStatusEnum.UNDER_PURCHASE);
|
|
|
+ wrapper.eq("p", Purchase::getStatus, PurchaseStatusEnum.UNDER_PURCHASE.getKey());
|
|
|
}
|
|
|
wrapper.orderByDesc("p", Purchase::getId);
|
|
|
|
|
@@ -319,38 +317,37 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void purchaseImport(List<PurchaseImportDataDto> list, List<PurchaseBomImportDataDto> bomImportDataList) {
|
|
|
+ public void purchaseImport(List<PurchaseBomImportDataDto> list) {
|
|
|
// 验证导入数据
|
|
|
- validatedImportData(list, bomImportDataList);
|
|
|
+ validatedImportData(list);
|
|
|
|
|
|
- Map<String, List<PurchaseBomImportDataDto>> bomMap = bomImportDataList.stream().collect(Collectors.groupingBy(PurchaseBomImportDataDto::getPurchaseCode));
|
|
|
+ Map<String, List<PurchaseBomImportDataDto>> bomMap = list.stream().collect(Collectors.groupingBy(PurchaseBomImportDataDto::getPurchaseCode));
|
|
|
+ Map<String, Long> purchaseMap = this.mapKV(Purchase::getErpCode, BaseIdPo::getId, q -> q.in(Purchase::getErpCode, bomMap.keySet()));
|
|
|
|
|
|
- List<String> purchaseCodes = list.stream().map(PurchaseImportDataDto::getCode).collect(Collectors.toList());
|
|
|
- Map<String, Long> purchaseMap = this.mapKV(Purchase::getErpCode, BaseIdPo::getId, q -> q.in(Purchase::getErpCode, purchaseCodes));
|
|
|
-
|
|
|
- List<String> supplierCodes = list.stream().map(PurchaseImportDataDto::getSupplierCode).collect(Collectors.toList());
|
|
|
+ Set<String> supplierCodes = list.stream().map(PurchaseBomImportDataDto::getSupplierCode).collect(Collectors.toSet());
|
|
|
Map<String, Long> supplierMap = supplierService.mapKV(Supplier::getCode, BaseIdPo::getId, q -> q.in(Supplier::getCode, supplierCodes));
|
|
|
- List<String> bomSpecCodes = bomImportDataList.stream().map(PurchaseBomImportDataDto::getBomSpecCode).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<String> bomSpecCodes = list.stream().map(PurchaseBomImportDataDto::getBomSpecCode).collect(Collectors.toList());
|
|
|
Map<String, Long> bomSpecMap = bomSpecService.mapKV(BomSpec::getCode, BaseIdPo::getId, q -> q.in(BomSpec::getCode, bomSpecCodes));
|
|
|
|
|
|
List<Purchase> purchaseList = new ArrayList<>();
|
|
|
List<PurchaseBom> purchaseBomList = new ArrayList<>();
|
|
|
- for (PurchaseImportDataDto importDataDto : list) {
|
|
|
+ for (Map.Entry<String, List<PurchaseBomImportDataDto>> entry : bomMap.entrySet()) {
|
|
|
+ String purchaseCode = entry.getKey();
|
|
|
+ List<PurchaseBomImportDataDto> bomList = entry.getValue();
|
|
|
+ if (ObjectUtil.isEmpty(bomList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
// 判断是否存在重复编号
|
|
|
- Long purchaseId = purchaseMap.get(importDataDto.getCode());
|
|
|
+ Long purchaseId = purchaseMap.get(purchaseCode);
|
|
|
if (purchaseId != null) {
|
|
|
- throw new ServiceException("采购合同编号:" + importDataDto.getCode() + " 已存在");
|
|
|
+ throw new ServiceException("采购合同编号:" + purchaseCode + " 已存在");
|
|
|
}
|
|
|
|
|
|
- Long supplierId = supplierMap.get(importDataDto.getSupplierCode());
|
|
|
+ Long supplierId = supplierMap.get(bomList.get(0).getSupplierCode());
|
|
|
if (supplierId == null) {
|
|
|
- throw new ServiceException("未知供应商编号:" + importDataDto.getSupplierCode());
|
|
|
- }
|
|
|
-
|
|
|
- List<PurchaseBomImportDataDto> bomList = bomMap.get(importDataDto.getCode());
|
|
|
-
|
|
|
- if (ObjectUtil.isEmpty(bomList)) {
|
|
|
- continue;
|
|
|
+ throw new ServiceException("未知供应商编号:" + bomList.get(0).getSupplierCode());
|
|
|
}
|
|
|
|
|
|
// 保存采购合同
|
|
@@ -360,7 +357,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
purchase.setSupplierId(supplierId);
|
|
|
purchase.setStatus(PurchaseStatusEnum.UNDER_PURCHASE.getKey());
|
|
|
purchase.setFlowStatus(FlowStatusEnum.PASS.getKey());
|
|
|
- purchase.setErpCode(importDataDto.getCode());
|
|
|
+ purchase.setErpCode(purchaseCode);
|
|
|
purchase.setReceiveGoodsType(1);
|
|
|
purchase.setAdvancePayment(BigDecimal.ZERO);
|
|
|
purchase.setReturnAmount(BigDecimal.ZERO);
|
|
@@ -370,11 +367,8 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
purchase.setStorageStatus(StatusConstant.NO);
|
|
|
purchase.setTotalAmountIncludingTax(BigDecimal.ZERO);
|
|
|
purchase.setTotalAmountExcludingTax(BigDecimal.ZERO);
|
|
|
- try {
|
|
|
- purchase.setDeliveryDate(DateUtil.parse(bomList.get(0).getDeliveryDate()));
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("交付日期格式异常");
|
|
|
- }
|
|
|
+ purchase.setDeliveryDate(bomList.get(0).getDeliveryDate());
|
|
|
+
|
|
|
|
|
|
List<PurchaseBom> bomData = bomList.stream().map(item -> {
|
|
|
Long bomSpecId = bomSpecMap.get(item.getBomSpecCode());
|
|
@@ -399,26 +393,19 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
}).collect(Collectors.toList());
|
|
|
purchaseList.add(purchase);
|
|
|
purchaseBomList.addAll(bomData);
|
|
|
- purchaseMap.put(importDataDto.getCode(), purchase.getId());
|
|
|
+ purchaseMap.put(purchaseCode, purchase.getId());
|
|
|
}
|
|
|
|
|
|
this.saveBatch(purchaseList);
|
|
|
purchaseBomService.saveBatch(purchaseBomList);
|
|
|
}
|
|
|
|
|
|
- private void validatedImportData(List<PurchaseImportDataDto> list, List<PurchaseBomImportDataDto> bomImportDataList) {
|
|
|
- // 删除第一行表头字段
|
|
|
- list.remove(0);
|
|
|
- bomImportDataList.remove(0);
|
|
|
- Assert.notEmpty(list, "采购合同不能为空");
|
|
|
- Assert.notEmpty(bomImportDataList, "采购合同明细不能为空");
|
|
|
- for (PurchaseImportDataDto dto : list) {
|
|
|
- Assert.notNull(dto.getCode(), "采购合同编号不能为空");
|
|
|
- Assert.notNull(dto.getSupplierCode(), "供应商编号不能为空");
|
|
|
- }
|
|
|
- for (PurchaseBomImportDataDto dto : bomImportDataList) {
|
|
|
- Assert.notNull(dto.getPurchaseCode(), "采购合同编号不能为空");
|
|
|
- Assert.notNull(dto.getBomSpecCode(), "bom品号不能为空");
|
|
|
+ private void validatedImportData(List<PurchaseBomImportDataDto> list) {
|
|
|
+ Assert.notEmpty(list, "采购合同明细不能为空");
|
|
|
+ for (PurchaseBomImportDataDto dto : list) {
|
|
|
+ Assert.notBlank(dto.getPurchaseCode(), "采购合同编号不能为空");
|
|
|
+ Assert.notBlank(dto.getSupplierCode(), "供应商编号不能为空");
|
|
|
+ Assert.notBlank(dto.getBomSpecCode(), "bom品号不能为空");
|
|
|
Assert.eqTrue(NumberUtil.isNumber(dto.getQuantity()), "采购数量格式不正确");
|
|
|
Assert.eqTrue(NumberUtil.isNumber(dto.getUnitPrice()), "采购单价格式不正确");
|
|
|
Assert.eqTrue(NumberUtil.isNumber(dto.getTotalAmount()), "采购金额合计格式不正确");
|