|
@@ -328,10 +328,11 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
Map<String, Long> supplierMap = supplierService.mapKV(Supplier::getCode, BaseIdPo::getId, q -> q.in(Supplier::getCode, supplierCodes));
|
|
|
|
|
|
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));
|
|
|
+ Map<String, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BomSpec::getCode, q -> q.in(BomSpec::getCode, bomSpecCodes));
|
|
|
|
|
|
List<Purchase> purchaseList = new ArrayList<>();
|
|
|
List<PurchaseBom> purchaseBomList = new ArrayList<>();
|
|
|
+ List<BomSpec> bomSpecList = new ArrayList<>();
|
|
|
for (Map.Entry<String, List<PurchaseBomImportDataDto>> entry : bomMap.entrySet()) {
|
|
|
String purchaseCode = entry.getKey();
|
|
|
List<PurchaseBomImportDataDto> bomList = entry.getValue();
|
|
@@ -371,13 +372,13 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
|
|
|
|
|
|
List<PurchaseBom> bomData = bomList.stream().map(item -> {
|
|
|
- Long bomSpecId = bomSpecMap.get(item.getBomSpecCode());
|
|
|
- if (bomSpecId == null) {
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(item.getBomSpecCode());
|
|
|
+ if (bomSpec == null) {
|
|
|
throw new ServiceException("未知bom品号:" + item.getBomSpecCode());
|
|
|
}
|
|
|
PurchaseBom purchaseBom = new PurchaseBom();
|
|
|
purchaseBom.setPurchaseId(purchase.getId());
|
|
|
- purchaseBom.setBomSpecId(bomSpecId);
|
|
|
+ purchaseBom.setBomSpecId(bomSpec.getId());
|
|
|
purchaseBom.setUnitPrice(new BigDecimal(item.getUnitPrice()));
|
|
|
purchaseBom.setTaxRate(BigDecimal.TEN);
|
|
|
purchaseBom.setPurchaseQuantity(new BigDecimal(item.getQuantity()));
|
|
@@ -389,6 +390,13 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
// 计算不含税总金额
|
|
|
BigDecimal totalAmountIncludingTax = purchaseBom.getUnitPrice().divide(new BigDecimal("1.1"), 4, RoundingMode.HALF_UP).multiply(purchaseBom.getPurchaseQuantity());
|
|
|
purchase.setTotalAmountExcludingTax(purchase.getTotalAmountExcludingTax().add(totalAmountIncludingTax));
|
|
|
+
|
|
|
+ // bom成本价为空时,默认为采购bom单价
|
|
|
+ if (bomSpec.getCostPrice() == null) {
|
|
|
+ bomSpec.setCostPrice(purchaseBom.getUnitPrice());
|
|
|
+ bomSpec.setInternalSellingPrice(purchaseBom.getUnitPrice());
|
|
|
+ bomSpecList.add(bomSpec);
|
|
|
+ }
|
|
|
return purchaseBom;
|
|
|
}).collect(Collectors.toList());
|
|
|
purchaseList.add(purchase);
|
|
@@ -398,6 +406,9 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
|
|
|
|
this.saveBatch(purchaseList);
|
|
|
purchaseBomService.saveBatch(purchaseBomList);
|
|
|
+ if (!bomSpecList.isEmpty()) {
|
|
|
+ bomSpecService.updateBatchById(bomSpecList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void validatedImportData(List<PurchaseBomImportDataDto> list) {
|