|
|
@ -2,16 +2,24 @@ package com.qs.serve.modules.goods.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
import com.qs.serve.common.util.AuthContextUtils; |
|
|
|
import com.qs.serve.common.util.JsonUtil; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsCustomerPriceBo; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsCustomerPriceSingleBo; |
|
|
|
import com.qs.serve.modules.goods.entity.dto.InventoryCusPrice; |
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; |
|
|
|
import com.qs.serve.modules.seeyon.service.SeeYonRequestService; |
|
|
|
import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService; |
|
|
|
import com.qs.serve.modules.sys.entity.SysDictData; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.mapper.SysDictDataMapper; |
|
|
|
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsSeeYonConst; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -34,9 +42,11 @@ import java.util.stream.Collectors; |
|
|
|
@AllArgsConstructor |
|
|
|
public class GoodsCustomerPriceServiceImpl extends ServiceImpl<GoodsCustomerPriceMapper,GoodsCustomerPrice> implements GoodsCustomerPriceService { |
|
|
|
|
|
|
|
private final SysDictDataMapper sysDictDataMapper; |
|
|
|
private final BmsSupplierMapper bmsSupplierMapper; |
|
|
|
private final GoodsSkuMapper goodsSkuMapper; |
|
|
|
private final SysUserMapper sysUserMapper; |
|
|
|
private final SeeYonRequestBaseService seeYonRequestBaseService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<GoodsCustomerPrice> selectGoodsCustomerPriceList(GoodsCustomerPrice query) { |
|
|
@ -125,6 +135,14 @@ public class GoodsCustomerPriceServiceImpl extends ServiceImpl<GoodsCustomerPric |
|
|
|
return this.getOne(lqw,false); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public GoodsCustomerPrice getByCusCodeAndSkuCode(String supplierCode, String skuCode) { |
|
|
|
LambdaQueryWrapper<GoodsCustomerPrice> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(GoodsCustomerPrice::getSupplierCode,supplierCode) |
|
|
|
.eq(GoodsCustomerPrice::getSkuCode,skuCode); |
|
|
|
return this.getOne(lqw,false); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<GoodsCustomerPrice> getBySupplierCodeAndCode(String supplierCode, List<String> skuCodes) { |
|
|
|
LambdaQueryWrapper<GoodsCustomerPrice> lqw = new LambdaQueryWrapper<>(); |
|
|
@ -133,5 +151,65 @@ public class GoodsCustomerPriceServiceImpl extends ServiceImpl<GoodsCustomerPric |
|
|
|
return this.list(lqw); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void syncCustomerPrice() { |
|
|
|
final String DICT_KEY = "sync-customer-price-max-id"; |
|
|
|
SysDictData dictData = sysDictDataMapper |
|
|
|
.selectOne(new LambdaQueryWrapper<SysDictData>() |
|
|
|
.eq(SysDictData::getGroupKey,DICT_KEY)); |
|
|
|
Long maxId = 0L; |
|
|
|
if(dictData!=null&&dictData.getKeyVal()!=null){ |
|
|
|
maxId = Long.parseLong(dictData.getKeyVal()); |
|
|
|
} |
|
|
|
List<InventoryCusPrice> cusPriceList = new ArrayList<>(); |
|
|
|
|
|
|
|
R<String> res = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_LAST_UPD+"/"+maxId,null,"查询最近更新的客户特殊价"); |
|
|
|
if(res.getStatus().equals(200)){ |
|
|
|
cusPriceList = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class); |
|
|
|
} |
|
|
|
|
|
|
|
assert cusPriceList != null; |
|
|
|
for (InventoryCusPrice cusPrice : cusPriceList) { |
|
|
|
if(maxId==null || cusPrice.getRowId() > maxId){ |
|
|
|
maxId = cusPrice.getRowId(); |
|
|
|
} |
|
|
|
GoodsCustomerPrice customerPrice = this.getByCusCodeAndSkuCode(cusPrice.getCusCode(),cusPrice.getInvCode()); |
|
|
|
if(customerPrice==null){ |
|
|
|
GoodsSku goodsSku = goodsSkuMapper.selectBySkuCode(cusPrice.getInvCode()); |
|
|
|
BmsSupplier supplier = bmsSupplierMapper.selectOne(new LambdaQueryWrapper<BmsSupplier>() |
|
|
|
.eq(BmsSupplier::getCode,cusPrice.getCusCode())); |
|
|
|
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()); |
|
|
|
this.save(customerPrice); |
|
|
|
}else { |
|
|
|
customerPrice.setRealPrice(cusPrice.getPrice()); |
|
|
|
this.updateById(customerPrice); |
|
|
|
} |
|
|
|
} |
|
|
|
if(maxId!=0){ |
|
|
|
if(dictData==null){ |
|
|
|
dictData = new SysDictData(); |
|
|
|
dictData.setDictId(0L); |
|
|
|
dictData.setGroupKey(DICT_KEY); |
|
|
|
dictData.setKeyVal(maxId+""); |
|
|
|
dictData.setLabel("同步客户特殊价最大值ID"); |
|
|
|
dictData.setSort(0); |
|
|
|
dictData.setRemark("同步客户特殊价最大值ID"); |
|
|
|
sysDictDataMapper.insert(dictData); |
|
|
|
}else { |
|
|
|
dictData.setKeyVal(maxId+""); |
|
|
|
sysDictDataMapper.updateById(dictData); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|