|
|
@@ -58,6 +58,7 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
try {
|
|
|
List<BomDetail> bomDetails = bom.getBomDetails();
|
|
|
+ List<PriceLibrary> priceLibraries = new ArrayList<>();
|
|
|
bom = bomDao.save(bom);
|
|
|
for (BomDetail bomDetail : bomDetails) {
|
|
|
if (!StringUtils.isEmpty(bomDetail.getTaxUnitPrice()) && bomDetail.getTaxUnitPrice() != 0) {
|
|
|
@@ -66,8 +67,15 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
bomDetail.setBdId(bom.getBid());
|
|
|
bomDetail.setBomId(bom.getBomId());
|
|
|
bomDetailDao.save(bomDetail);
|
|
|
+
|
|
|
+ // 保存经过成本计算的价格
|
|
|
+ priceLibraries.add(bomDetailConvert(bomDetail, bom.getEnuu()));
|
|
|
}
|
|
|
}
|
|
|
+ List<Bom> boms = bomDao.findByEnuuAndBomId(bom.getEnuu(), bom.getBomId());
|
|
|
+ if (CollectionUtils.isEmpty(boms)) {
|
|
|
+ priceLibraryDao.save(priceLibraries);
|
|
|
+ }
|
|
|
bom.setBomDetails(bomDetails);
|
|
|
modelMap.put("success", true);
|
|
|
modelMap.put("data", bom);
|
|
|
@@ -79,6 +87,26 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
return modelMap;
|
|
|
}
|
|
|
|
|
|
+ private PriceLibrary bomDetailConvert(BomDetail bomDetail, Long buyerUU) {
|
|
|
+ PriceLibrary priceLirary = new PriceLibrary();
|
|
|
+ priceLirary.setBrand(bomDetail.getBrand());
|
|
|
+ priceLirary.setBuyerEnuu(buyerUU);
|
|
|
+ priceLirary.setCmpCode(bomDetail.getCmpCode());
|
|
|
+ priceLirary.setCode(bomDetail.getCode());
|
|
|
+ priceLirary.setCurrency(bomDetail.getCurrency());
|
|
|
+ priceLirary.setInbrand(bomDetail.getInbrand());
|
|
|
+ priceLirary.setKind(bomDetail.getProductTitle());
|
|
|
+ priceLirary.setPrice(bomDetail.getTaxUnitPrice());
|
|
|
+ priceLirary.setTaxRate(bomDetail.getTaxRate());
|
|
|
+ priceLirary.setSource("ERP");
|
|
|
+ priceLirary.setVendEnuu(bomDetail.getVendUU());
|
|
|
+ priceLirary.setVendName(bomDetail.getVendName());
|
|
|
+ priceLirary.setUasCode(bomDetail.getProductCode());
|
|
|
+ priceLirary.setSpec(bomDetail.getSpec());
|
|
|
+ priceLirary.setPriceType("BOMCOUNTPRICE");
|
|
|
+ return priceLirary;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 核价
|
|
|
* @param bomDetail
|
|
|
@@ -94,12 +122,19 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
// 核价
|
|
|
for (String type : PRICERULES) {
|
|
|
PriceLibrary priceLibrary = priceLibraryMap.get(type);
|
|
|
- if (!StringUtils.isEmpty(priceLibrary) && !StringUtils.isEmpty(priceLibrary.getPrice()) && priceLibrary.getPrice() != 0 && priceLibrary.getPrice() <= bomDetail.getTaxUnitPrice()) {
|
|
|
- bomDetail.setPid(priceLibrary.getId());
|
|
|
- double price = ((bomDetail.getTaxUnitPrice() - priceLibrary.getPrice()) * 0.618) + priceLibrary.getPrice();
|
|
|
- bomDetail.setPricingPrice((double) Math.round(price * 1000000) / 1000000);
|
|
|
- break;
|
|
|
+ if (!StringUtils.isEmpty(priceLibrary)) {
|
|
|
+ if (StringUtils.isEmpty(bomDetail.getTaxRate())) {
|
|
|
+ bomDetail.setTaxRate(0d);
|
|
|
+ }
|
|
|
+ double taxPrice = priceLibrary.getNoTaxPrice() * (1 + bomDetail.getTaxRate() / 100);
|
|
|
+ if (!StringUtils.isEmpty(priceLibrary) && !StringUtils.isEmpty(priceLibrary.getPrice()) && priceLibrary.getPrice() != 0 && taxPrice <= bomDetail.getTaxUnitPrice()) {
|
|
|
+ bomDetail.setPid(priceLibrary.getId());
|
|
|
+ double price = ((bomDetail.getTaxUnitPrice() - taxPrice) * 0.618) + taxPrice;
|
|
|
+ bomDetail.setPricingPrice((double) Math.round(price * 1000000) / 1000000);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
bomDetail.setPricingTime(new Date());
|
|
|
@@ -117,15 +152,15 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
bomDetail.setCurrency("RMB");
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(bomDetail.getCmpCode()) && !StringUtils.isEmpty(bomDetail.getInbrand())) {
|
|
|
- prices = priceLibraryDao.findByCmpCodeAndInbrandAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(bomDetail.getCmpCode(), bomDetail.getInbrand(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
+ prices = priceLibraryDao.findByCmpCodeAndInbrandAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(bomDetail.getCmpCode(), bomDetail.getInbrand(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
} else if (!StringUtils.isEmpty(bomDetail.getCmpCode())) {
|
|
|
- prices = priceLibraryDao.findByCmpCodeAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(bomDetail.getCmpCode(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
+ prices = priceLibraryDao.findByCmpCodeAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(bomDetail.getCmpCode(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
}else if (!StringUtils.isEmpty(bomDetail.getCode()) && !StringUtils.isEmpty(bomDetail.getBrand())) {// 如果bomDetail里面有型号和品牌
|
|
|
- prices = priceLibraryDao.findByCodeAndBrandAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(bomDetail.getCode(), bomDetail.getBrand(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
+ prices = priceLibraryDao.findByCodeAndBrandAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(bomDetail.getCode(), bomDetail.getBrand(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
} else if (!StringUtils.isEmpty(bomDetail.getCode())) {// 如果bomDetail只有型号
|
|
|
- prices = priceLibraryDao.findByCodeAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(bomDetail.getCode(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
+ prices = priceLibraryDao.findByCodeAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(bomDetail.getCode(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
} else if (!StringUtils.isEmpty(bomDetail.getSpec())) {// 如果bomDetail 规格不为空
|
|
|
- prices = priceLibraryDao.findBySpecAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(bomDetail.getSpec(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
+ prices = priceLibraryDao.findBySpecAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(bomDetail.getSpec(), bomDetail.getCurrency(), enuu, 0d);
|
|
|
}
|
|
|
return prices;
|
|
|
}
|
|
|
@@ -142,7 +177,7 @@ public class PriceLibraryServiceImpl implements PriceLibraryService{
|
|
|
if (StringUtils.isEmpty(oldPriceLibrary)) {
|
|
|
priceLibraryMap.put(priceLibrary.getPriceType(), priceLibrary);
|
|
|
} else {
|
|
|
- if (oldPriceLibrary.getPrice() > priceLibrary.getPrice()) {
|
|
|
+ if (oldPriceLibrary.getNoTaxPrice() > priceLibrary.getNoTaxPrice()) {
|
|
|
priceLibraryMap.put(priceLibrary.getPriceType(), priceLibrary);
|
|
|
}
|
|
|
}
|