Browse Source

opt: 修改用户特殊价同步

checkBack
Yen 1 year ago
parent
commit
d0bd7b4b0b
  1. 11
      src/main/java/com/qs/serve/modules/goods/controller/GoodsCustomerPriceController.java
  2. 2
      src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java
  3. 158
      src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCustomerPriceServiceImpl.java
  4. 1
      src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java

11
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<GoodsCustomerPrice> syncCusInvPrice(String cusCode){
goodsCustomerPriceService.syncCustomerPrice(cusCode);
return R.ok();
}
}

2
src/main/java/com/qs/serve/modules/goods/service/GoodsCustomerPriceService.java

@ -33,5 +33,7 @@ public interface GoodsCustomerPriceService extends IService<GoodsCustomerPrice>
*/
void syncCustomerPrice();
void syncCustomerPrice(String cusCode);
}

158
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<GoodsCustomerPric
if(res.getStatus().equals(200)){
allCusPriceList = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class);
}
assert allCusPriceList != null;
long times = System.currentTimeMillis();
Map<String,List<InventoryCusPrice>> cusPriceMap = allCusPriceList.stream().collect(Collectors.groupingBy(InventoryCusPrice::getCusCode));
for (String cusCode : cusPriceMap.keySet()) {
List<InventoryCusPrice> cusPriceList = cusPriceMap.get(cusCode);
List<String> skuCodes = cusPriceList.stream().map(InventoryCusPrice::getInvCode).collect(Collectors.toList());
List<GoodsSku> goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper<GoodsSku>().in(GoodsSku::getSkuCode,skuCodes));
List<GoodsCustomerPrice> goodsCustomerPriceList = new ArrayList<>();
InventoryCusPriceQuery query = new InventoryCusPriceQuery();
query.setCusCode(cusCode);
query.setInvCodes(skuCodes);
R<String> erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价");
List<InventoryCusPrice> erpCusPriceList = new ArrayList<>();
if(erpRs.getStatus().equals(200)){
erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class);
}
BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper<BmsSupplier>()
.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<GoodsCustomerPrice>()
.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<GoodsCustomerPric
}
}
@Override
public void syncCustomerPrice(String cusCode) {
this.flushSupplierSkuPrices(cusCode);
}
/**
* 局部更新
* @param cusCode
* @param skuCodes
*/
private void flushSupplierSkuPrices(String cusCode, List<String> skuCodes) {
List<GoodsSku> goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper<GoodsSku>().in(GoodsSku::getSkuCode, skuCodes));
List<GoodsCustomerPrice> goodsCustomerPriceList = new ArrayList<>();
InventoryCusPriceQuery query = new InventoryCusPriceQuery();
query.setCusCode(cusCode);
query.setInvCodes(skuCodes);
R<String> erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价");
List<InventoryCusPrice> erpCusPriceList = new ArrayList<>();
if(erpRs.getStatus().equals(200)){
erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class);
}
BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper<BmsSupplier>()
.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<GoodsCustomerPrice>()
.eq(GoodsCustomerPrice::getSupplierCode, cusCode)
.in(GoodsCustomerPrice::getSkuCode,goodsSkus)
);
this.saveBatch(goodsCustomerPriceList);
}
}
/**
* 全量更新
* @param cusCode
*/
private void flushSupplierSkuPrices(String cusCode) {
BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper<BmsSupplier>()
.eq(BmsSupplier::getCode, cusCode));
R<String> erpRs = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE_CUS+cusCode,null,"查询客户特殊价");
List<InventoryCusPrice> erpCusPriceList = new ArrayList<>();
if(erpRs.getStatus().equals(200)){
erpCusPriceList = JsonUtil.jsonToList(erpRs.getData(), InventoryCusPrice.class);
}
Set<String> skuCodes = erpCusPriceList.stream().map(InventoryCusPrice::getInvCode).collect(Collectors.toSet());
List<GoodsSku> goodsSkus = goodsSkuMapper.selectList(new LambdaQueryWrapper<GoodsSku>().in(GoodsSku::getSkuCode, skuCodes));
List<GoodsCustomerPrice> 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<GoodsCustomerPrice>()
.eq(GoodsCustomerPrice::getSupplierCode, cusCode)
.in(GoodsCustomerPrice::getSkuCode,goodsSkus)
);
if(goodsCustomerPriceList.size()>0){
this.saveBatch(goodsCustomerPriceList);
}
}
}

1
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";

Loading…
Cancel
Save