diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsCustomerPriceController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsCustomerPriceController.java index bfad5de4..88dfb645 100644 --- a/src/main/java/com/qs/serve/modules/goods/controller/GoodsCustomerPriceController.java +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsCustomerPriceController.java @@ -126,5 +126,16 @@ public class GoodsCustomerPriceController { return R.ok(); } + + /** + * 同步客户特殊价 + * @return + */ + @GetMapping("/syncCus") + public R syncCusInvPrice(String cusCode){ + goodsCustomerPriceService.syncCustomerPrice(cusCode); + return R.ok(); + } + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java index 033fa3a4..de540086 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java @@ -33,5 +33,7 @@ public interface GoodsCustomerPriceService extends IService */ void syncCustomerPrice(); + void syncCustomerPrice(String cusCode); + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCustomerPriceServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCustomerPriceServiceImpl.java index b1b88ed3..3f438b8a 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCustomerPriceServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCustomerPriceServiceImpl.java @@ -33,6 +33,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; /** @@ -170,60 +171,12 @@ public class GoodsCustomerPriceServiceImpl extends ServiceImpl> cusPriceMap = allCusPriceList.stream().collect(Collectors.groupingBy(InventoryCusPrice::getCusCode)); for (String cusCode : cusPriceMap.keySet()) { List cusPriceList = cusPriceMap.get(cusCode); List skuCodes = cusPriceList.stream().map(InventoryCusPrice::getInvCode).collect(Collectors.toList()); - List goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper().in(GoodsSku::getSkuCode,skuCodes)); - List goodsCustomerPriceList = new ArrayList<>(); - - InventoryCusPriceQuery query = new InventoryCusPriceQuery(); - query.setCusCode(cusCode); - query.setInvCodes(skuCodes); - R erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); - List erpCusPriceList = new ArrayList<>(); - if(erpRs.getStatus().equals(200)){ - erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class); - } - - BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper() - .eq(BmsSupplier::getCode,cusCode)); - - for (InventoryCusPrice cusPrice : erpCusPriceList) { - GoodsSku goodsSku = null; - for (GoodsSku skuItem : goodsSkus) { - if(skuItem.getSkuCode().equals(cusPrice.getInvCode())){ - goodsSku = skuItem; - } - } - //跳过无效商品 - if(goodsSku==null){ - continue; - } - GoodsCustomerPrice customerPrice = new GoodsCustomerPrice(); - customerPrice.setSupplierId(supplier.getId()); - customerPrice.setSupplierCode(supplier.getCode()); - customerPrice.setSupplierName(supplier.getName()); - customerPrice.setSkuId(goodsSku.getId()+""); - customerPrice.setSkuCode(goodsSku.getSkuCode()); - customerPrice.setSkuName(goodsSku.getSkuName()); - customerPrice.setSkuUnit(goodsSku.getUnitName()); - customerPrice.setInitPrice(cusPrice.getPrice()); - customerPrice.setRealPrice(cusPrice.getPrice()); - goodsCustomerPriceList.add(customerPrice); - } - if(goodsCustomerPriceList.size()>0){ - //移除旧历史 - this.remove(new LambdaQueryWrapper() - .eq(GoodsCustomerPrice::getSupplierCode,cusCode) - .in(GoodsCustomerPrice::getSkuCode,goodsSkus) - ); - this.saveBatch(goodsCustomerPriceList); - } + flushSupplierSkuPrices(cusCode, skuCodes); } for (InventoryCusPrice cusPrice : allCusPriceList) { @@ -248,5 +201,112 @@ public class GoodsCustomerPriceServiceImpl extends ServiceImpl skuCodes) { + List goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper().in(GoodsSku::getSkuCode, skuCodes)); + List goodsCustomerPriceList = new ArrayList<>(); + + InventoryCusPriceQuery query = new InventoryCusPriceQuery(); + query.setCusCode(cusCode); + query.setInvCodes(skuCodes); + R erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); + List erpCusPriceList = new ArrayList<>(); + if(erpRs.getStatus().equals(200)){ + erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class); + } + + BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper() + .eq(BmsSupplier::getCode, cusCode)); + + for (InventoryCusPrice cusPrice : erpCusPriceList) { + GoodsSku goodsSku = null; + for (GoodsSku skuItem : goodsSkus) { + if(skuItem.getSkuCode().equals(cusPrice.getInvCode())){ + goodsSku = skuItem; + } + } + //跳过无效商品 + if(goodsSku==null){ + continue; + } + GoodsCustomerPrice customerPrice = new GoodsCustomerPrice(); + customerPrice.setSupplierId(supplier.getId()); + customerPrice.setSupplierCode(supplier.getCode()); + customerPrice.setSupplierName(supplier.getName()); + customerPrice.setSkuId(goodsSku.getId()+""); + customerPrice.setSkuCode(goodsSku.getSkuCode()); + customerPrice.setSkuName(goodsSku.getSkuName()); + customerPrice.setSkuUnit(goodsSku.getUnitName()); + customerPrice.setInitPrice(cusPrice.getPrice()); + customerPrice.setRealPrice(cusPrice.getPrice()); + goodsCustomerPriceList.add(customerPrice); + } + if(goodsCustomerPriceList.size()>0){ + //移除旧历史 + this.remove(new LambdaQueryWrapper() + .eq(GoodsCustomerPrice::getSupplierCode, cusCode) + .in(GoodsCustomerPrice::getSkuCode,goodsSkus) + ); + this.saveBatch(goodsCustomerPriceList); + } + } + + /** + * 全量更新 + * @param cusCode + */ + private void flushSupplierSkuPrices(String cusCode) { + BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper() + .eq(BmsSupplier::getCode, cusCode)); + R erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE_CUS+cusCode,null,"查询客户特殊价"); + List erpCusPriceList = new ArrayList<>(); + if(erpRs.getStatus().equals(200)){ + erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class); + } + Set skuCodes = erpCusPriceList.stream().map(InventoryCusPrice::getInvCode).collect(Collectors.toSet()); + List goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper().in(GoodsSku::getSkuCode, skuCodes)); + List goodsCustomerPriceList = new ArrayList<>(); + for (InventoryCusPrice cusPrice : erpCusPriceList) { + GoodsSku goodsSku = null; + for (GoodsSku skuItem : goodsSkus) { + if(skuItem.getSkuCode().equals(cusPrice.getInvCode())){ + goodsSku = skuItem; + } + } + //跳过无效商品 + if(goodsSku==null){ + continue; + } + GoodsCustomerPrice customerPrice = new GoodsCustomerPrice(); + customerPrice.setSupplierId(supplier.getId()); + customerPrice.setSupplierCode(supplier.getCode()); + customerPrice.setSupplierName(supplier.getName()); + customerPrice.setSkuId(goodsSku.getId()+""); + customerPrice.setSkuCode(goodsSku.getSkuCode()); + customerPrice.setSkuName(goodsSku.getSkuName()); + customerPrice.setSkuUnit(goodsSku.getUnitName()); + customerPrice.setInitPrice(cusPrice.getPrice()); + customerPrice.setRealPrice(cusPrice.getPrice()); + goodsCustomerPriceList.add(customerPrice); + } + //移除旧历史 + this.remove(new LambdaQueryWrapper() + .eq(GoodsCustomerPrice::getSupplierCode, cusCode) + .in(GoodsCustomerPrice::getSkuCode,goodsSkus) + ); + if(goodsCustomerPriceList.size()>0){ + this.saveBatch(goodsCustomerPriceList); + } + } + } diff --git a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java index 7aa0e3c7..fc73df52 100644 --- a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java +++ b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java @@ -105,6 +105,7 @@ public interface TbsSeeYonConst { String ERP_CUS_AMOUNT = "/erp/customer/amount"; String ERP_CUS_AMOUNT_QUO = "/erp/customer/quoAmount"; String ERP_CUS_INV_PRICE = "/erp/inventory/invPrices"; + String ERP_CUS_INV_PRICE_CUS = "/erp/inventory/invPricesByCusCode?cusCode="; String ERP_CUS_INV_LAST_UPD = "/erp/inventory/lastUpdateCusInvPrices"; String ERP_CUS_INV_STAND = "/erp/inventory/standList"; String ERP_CUS_INV_SYNC_PRICE = "/erp/inventory/syncPrice";