Parcourir la source

将bom成本计算的单价加入价格库

liusw il y a 7 ans
Parent
commit
6a948248d4

+ 9 - 0
src/main/java/com/uas/ps/pricing/dao/BomDao.java

@@ -5,6 +5,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * Bom
  *
@@ -14,4 +16,11 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface BomDao extends JpaRepository<Bom, Long>, JpaSpecificationExecutor<Bom> {
 
+    /**
+     * 根据企业uu和BomId判断是否核价
+     * @param enUU
+     * @param bomId
+     * @return
+     */
+    List<Bom> findByEnuuAndBomId(Long enUU, Long bomId);
 }

+ 5 - 5
src/main/java/com/uas/ps/pricing/dao/PriceLibraryDao.java

@@ -21,7 +21,7 @@ public interface PriceLibraryDao extends JpaRepository<PriceLibrary, Long>, JpaS
      * @param inbrand
      * @return
      */
-    Set<PriceLibrary> findByCmpCodeAndInbrandAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(String cmpCode, String inbrand, String currency, Long vendorEnuu, Double price);
+    Set<PriceLibrary> findByCmpCodeAndInbrandAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(String cmpCode, String inbrand, String currency, Long vendEnuu, Double price);
 
     /**
      * 通过原厂型号查询价格信息
@@ -29,7 +29,7 @@ public interface PriceLibraryDao extends JpaRepository<PriceLibrary, Long>, JpaS
      * @param currency
      * @return
      */
-    Set<PriceLibrary> findByCmpCodeAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(String cmpCode, String currency, Long vendorEnuu, Double price);
+    Set<PriceLibrary> findByCmpCodeAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(String cmpCode, String currency, Long vendEnuu, Double price);
 
     /**
      * 通过型号和品牌查询价格信息
@@ -37,19 +37,19 @@ public interface PriceLibraryDao extends JpaRepository<PriceLibrary, Long>, JpaS
      * @param brand
      * @return
      */
-    Set<PriceLibrary> findByCodeAndBrandAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(String code, String brand, String currency, Long vendorEnuu, Double price);
+    Set<PriceLibrary> findByCodeAndBrandAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(String code, String brand, String currency, Long vendEnuu, Double price);
 
     /**
      * 通过型号查询价格信息
      * @param code
      * @return
      */
-    Set<PriceLibrary> findByCodeAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(String code, String currency, Long vendorEnuu, Double price);
+    Set<PriceLibrary> findByCodeAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(String code, String currency, Long vendEnuu, Double price);
 
     /**
      * 通过规格查询价格信息
      * @param spec
      * @return
      */
-    Set<PriceLibrary> findBySpecAndCurrencyAndPriceIsNotNullAndVendorEnuuNotAndPriceNot(String spec, String currency, Long vendorEnuu, Double price);
+    Set<PriceLibrary> findBySpecAndCurrencyAndPriceIsNotNullAndVendEnuuNotAndPriceNot(String spec, String currency, Long vendEnuu, Double price);
 }

+ 1 - 1
src/main/java/com/uas/ps/pricing/model/BomDetail.java

@@ -107,7 +107,7 @@ public class BomDetail {
     /**
      * 供应商UU
       */
-    @Column(name = "bd_vendinfo")
+    @Column(name = "bd_venduu")
     private Long vendUU;
 
     /**

+ 48 - 50
src/main/java/com/uas/ps/pricing/model/PriceLibrary.java

@@ -1,5 +1,7 @@
 package com.uas.ps.pricing.model;
 
+import org.springframework.util.StringUtils;
+
 import javax.persistence.*;
 import java.util.Date;
 
@@ -143,14 +145,20 @@ public class PriceLibrary {
     /**
      * 卖家企业uu
      */
-    @Column(name = "pl_vendorenuu")
-    private Long vendorEnuu;
+    @Column(name = "pl_vendenuu")
+    private Long vendEnuu;
 
     /**
      * 卖家个人uu
      */
-    @Column(name = "pl_vendoruu")
-    private Long vendorUU;
+    @Column(name = "pl_venduu")
+    private Long vendUU;
+
+    /**
+     * 卖家名称
+     */
+    @Column(name = "pl_vendname")
+    private String vendName;
 
     /**
      * 买家企业uu
@@ -170,12 +178,19 @@ public class PriceLibrary {
     @Column(name = "pl_lasttime")
     private Date lastTime;
 
-    public Double getLapQty() {
-        return lapQty;
-    }
+    /**
+     * 不含税单价
+     */
+    @Transient
+    private Double noTaxPrice;
 
-    public void setLapQty(Double lapQty) {
-        this.lapQty = lapQty;
+    public Double getNoTaxPrice() {
+        if (!StringUtils.isEmpty(taxRate) && taxRate != 0) {
+            noTaxPrice = price / (1 + (taxRate/100));
+        } else {
+            noTaxPrice = price;
+        }
+        return noTaxPrice;
     }
 
     public Long getId() {
@@ -274,6 +289,14 @@ public class PriceLibrary {
         this.price = price;
     }
 
+    public Double getLapQty() {
+        return lapQty;
+    }
+
+    public void setLapQty(Double lapQty) {
+        this.lapQty = lapQty;
+    }
+
     public String getPriceType() {
         return priceType;
     }
@@ -346,20 +369,28 @@ public class PriceLibrary {
         this.collectionTerms = collectionTerms;
     }
 
-    public Long getVendorEnuu() {
-        return vendorEnuu;
+    public Long getVendEnuu() {
+        return vendEnuu;
     }
 
-    public void setVendorEnuu(Long vendorEnuu) {
-        this.vendorEnuu = vendorEnuu;
+    public void setVendEnuu(Long vendEnuu) {
+        this.vendEnuu = vendEnuu;
     }
 
-    public Long getVendorUU() {
-        return vendorUU;
+    public Long getVendUU() {
+        return vendUU;
     }
 
-    public void setVendorUU(Long vendorUU) {
-        this.vendorUU = vendorUU;
+    public void setVendUU(Long vendUU) {
+        this.vendUU = vendUU;
+    }
+
+    public String getVendName() {
+        return vendName;
+    }
+
+    public void setVendName(String vendName) {
+        this.vendName = vendName;
     }
 
     public Long getBuyerEnuu() {
@@ -385,37 +416,4 @@ public class PriceLibrary {
     public void setLastTime(Date lastTime) {
         this.lastTime = lastTime;
     }
-
-    @Override
-    public String toString() {
-        return "PriceLibrary{" +
-                "id=" + id +
-                ", uasCode='" + uasCode + '\'' +
-                ", standard=" + standard +
-                ", kind='" + kind + '\'' +
-                ", kindEn='" + kindEn + '\'' +
-                ", code='" + code + '\'' +
-                ", brand='" + brand + '\'' +
-                ", cmpCode='" + cmpCode + '\'' +
-                ", inbrand='" + inbrand + '\'' +
-                ", spec='" + spec + '\'' +
-                ", currency='" + currency + '\'' +
-                ", price=" + price +
-                ", lapQty=" + lapQty +
-                ", priceType='" + priceType + '\'' +
-                ", source='" + source + '\'' +
-                ", priceDeadline=" + priceDeadline +
-                ", taxRate=" + taxRate +
-                ", unit='" + unit + '\'' +
-                ", delivery='" + delivery + '\'' +
-                ", minPack=" + minPack +
-                ", minOrder=" + minOrder +
-                ", collectionTerms='" + collectionTerms + '\'' +
-                ", vendorEnuu=" + vendorEnuu +
-                ", vendorUU=" + vendorUU +
-                ", buyerEnuu=" + buyerEnuu +
-                ", buyerUU=" + buyerUU +
-                ", lastTime=" + lastTime +
-                '}';
-    }
 }

+ 46 - 11
src/main/java/com/uas/ps/pricing/service/impl/PriceLibraryServiceImpl.java

@@ -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);
                 }
             }