...
|
...
|
@@ -2,7 +2,10 @@ package com.yoho.unions.server.service.impl; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.product.model.BrandBo;
|
|
|
import com.yoho.product.model.ProductBo;
|
|
|
import com.yoho.product.request.BaseRequest;
|
...
|
...
|
@@ -45,6 +48,8 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(UnionShareRebateServiceImpl.class);
|
|
|
|
|
|
private String NEW_USER_REBATES_RATIO_KEY = "union.newUserRebatesRatio";
|
|
|
|
|
|
@Autowired
|
|
|
UnionShareRebateBrandMapper unionShareRebateBrandMapper;
|
|
|
@Autowired
|
...
|
...
|
@@ -52,6 +57,9 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
@Autowired
|
|
|
UnionShareRebateLogMapper unionShareRebateLogMapper;
|
|
|
|
|
|
@Resource(name = "core-config-reader")
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Resource
|
|
|
ServiceCaller serviceCaller;
|
|
|
|
...
|
...
|
@@ -148,6 +156,9 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
@Override
|
|
|
public UnionShareRebateBo querySknById(int id) {
|
|
|
UnionShareRebateSkn rebateSkn= unionShareRebateSknMapper.selectByPrimaryKey(id);
|
|
|
if (rebateSkn == null) {
|
|
|
return null;
|
|
|
}
|
|
|
UnionShareRebateBo result = new UnionShareRebateBo();
|
|
|
BeanUtils.copyProperties(rebateSkn, result);
|
|
|
return result;
|
...
|
...
|
@@ -155,6 +166,9 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
@Override
|
|
|
public UnionShareRebateBo querySkn(int skn) {
|
|
|
UnionShareRebateSkn rebateSkn= unionShareRebateSknMapper.selectBySkn(skn);
|
|
|
if (rebateSkn == null) {
|
|
|
return null;
|
|
|
}
|
|
|
UnionShareRebateBo result = new UnionShareRebateBo();
|
|
|
BeanUtils.copyProperties(rebateSkn, result);
|
|
|
return result;
|
...
|
...
|
@@ -163,6 +177,9 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
@Override
|
|
|
public UnionShareRebateBo queryBrandById(int id) {
|
|
|
UnionShareRebateBrand rebateBrand= unionShareRebateBrandMapper.selectByPrimaryKey(id);
|
|
|
if (rebateBrand == null) {
|
|
|
return null;
|
|
|
}
|
|
|
UnionShareRebateBo result = new UnionShareRebateBo();
|
|
|
BeanUtils.copyProperties(rebateBrand, result);
|
|
|
return result;
|
...
|
...
|
@@ -170,6 +187,9 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
@Override
|
|
|
public UnionShareRebateBo queryBrand(int brand) {
|
|
|
UnionShareRebateBrand rebateBrand= unionShareRebateBrandMapper.selectByBrand(brand);
|
|
|
if (rebateBrand == null) {
|
|
|
return null;
|
|
|
}
|
|
|
UnionShareRebateBo result = new UnionShareRebateBo();
|
|
|
BeanUtils.copyProperties(rebateBrand, result);
|
|
|
return result;
|
...
|
...
|
@@ -246,14 +266,104 @@ public class UnionShareRebateServiceImpl implements IUnionShareRebateService,IBu |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UnionShareRebateBo> queryRebateList(List<UnionSknRebateBo> req){
|
|
|
return null;
|
|
|
public List<UnionSknRebateBo> queryRebateList(List<UnionSknRebateBo> req){
|
|
|
if (CollectionUtils.isEmpty(req)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
Set<Integer> skns = new HashSet<>();
|
|
|
Set<Integer> brands = new HashSet<>();
|
|
|
req.forEach(r->{
|
|
|
skns.add(r.getSkn());
|
|
|
brands.add(r.getBrand());
|
|
|
});
|
|
|
List<UnionShareRebateSkn> sknList=unionShareRebateSknMapper.selectListBySkns(skns);
|
|
|
List<UnionShareRebateBrand> brandList=unionShareRebateBrandMapper.selectListByBrands(brands);
|
|
|
Map<Integer, UnionShareRebateSkn> sknMap = sknList.stream().collect(Collectors.toMap(UnionShareRebateSkn::getSkn, skn -> skn));
|
|
|
Map<Integer, UnionShareRebateBrand> brandMap = brandList.stream().collect(Collectors.toMap(UnionShareRebateBrand::getBrand, b->b));
|
|
|
List<UnionSknRebateBo> result = new ArrayList<>();
|
|
|
String rebatesRatioDefault=configReader.getString(NEW_USER_REBATES_RATIO_KEY, "6");
|
|
|
req.forEach(r->{
|
|
|
UnionSknRebateBo rebatePercent=getProductRebatePercentBo(r.getSkn(), r.getBrand(), true, sknMap, brandMap, rebatesRatioDefault);
|
|
|
result.add(rebatePercent);
|
|
|
});
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public UnionShareRebateBo querySknRebate(UnionSknRebateBo req) {
|
|
|
return null;
|
|
|
public UnionSknRebateBo querySknRebate(UnionSknRebateBo bo) {
|
|
|
String rebatesRatioDefault=configReader.getString(NEW_USER_REBATES_RATIO_KEY, "6");
|
|
|
UnionSknRebateBo rebatePercent=getProductRebatePercentBo(bo.getSkn(), bo.getBrand(),false,null,null, rebatesRatioDefault);
|
|
|
return rebatePercent;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public UnionSknRebateBo querySknRebate(Integer skn,Integer brand,String rebatesRatioDefault ) {
|
|
|
UnionSknRebateBo rebatePercent=getProductRebatePercentBo(skn, brand,false,null,null, rebatesRatioDefault);
|
|
|
return rebatePercent;
|
|
|
}
|
|
|
|
|
|
private UnionSknRebateBo getProductRebatePercentBo(Integer skn,Integer brand,boolean hasQuery,Map<Integer, UnionShareRebateSkn> sknMap,Map<Integer, UnionShareRebateBrand> brandMap ,String rebatesRatioDefault) {
|
|
|
logger.info("getProductRebatePercentBo start.skn is {},brand is {},rebatesRatioDefault is {},hasQuery is {}.",skn,brand,rebatesRatioDefault,hasQuery);
|
|
|
|
|
|
if (skn==null||(hasQuery && (sknMap == null || brandMap == null))) {
|
|
|
throw new ServiceException(ServiceError.PARAM_ERROR);
|
|
|
}
|
|
|
int rebatesRatio = Integer.valueOf(rebatesRatioDefault)*100;//默认设置是百分点
|
|
|
UnionShareRebateSkn shareRebateSkn = hasQuery?sknMap.get(skn):unionShareRebateSknMapper.selectBySkn(skn);
|
|
|
boolean rebateState = true;
|
|
|
boolean brandStateCheck = false;
|
|
|
boolean brandRebateGet = false;
|
|
|
StringBuilder vidBuilder = new StringBuilder();
|
|
|
if (shareRebateSkn != null) {
|
|
|
vidBuilder.append(shareRebateSkn.getId()).append(":").append(shareRebateSkn.getLogId());
|
|
|
//是否返佣状态:1-根据品牌返佣状态判断是否返佣,2-返佣,3-不返佣
|
|
|
if (shareRebateSkn.getState() == 1) {
|
|
|
brandStateCheck = true;
|
|
|
}else if (shareRebateSkn.getState() == 3) {
|
|
|
rebateState = false;//不返佣
|
|
|
}
|
|
|
if (shareRebateSkn.getType() == 1) {
|
|
|
//返佣比例获取:1-获取品牌设置的返佣比例,2自定义返佣比例
|
|
|
brandRebateGet = true;
|
|
|
}else {
|
|
|
rebatesRatio = shareRebateSkn.getRebate();
|
|
|
vidBuilder.append(":").append(rebatesRatio);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
UnionShareRebateBrand rebateBrand = null;
|
|
|
if (rebateState&&(shareRebateSkn == null || brandStateCheck || brandRebateGet)) {
|
|
|
//未设置优先skn返佣、skn是否返佣根据品牌返佣状态判断、skn返佣比例根据品牌设置比例
|
|
|
rebateBrand = hasQuery?brandMap.get(brand):unionShareRebateBrandMapper.selectByBrand(brand);
|
|
|
}
|
|
|
if (rebateBrand != null) {
|
|
|
vidBuilder.append("-").append(rebateBrand.getId()).append(":").append(rebateBrand.getLogId());
|
|
|
if ((shareRebateSkn == null || brandStateCheck)&&rebateBrand.getState()==2) {
|
|
|
//1-品牌返佣,2-品牌不返佣
|
|
|
rebateState = false;//不返佣
|
|
|
}
|
|
|
if (rebateState&&(shareRebateSkn == null||brandRebateGet)&&rebateBrand.getType() == 2) {
|
|
|
//1-默认比例,2-自定义
|
|
|
rebatesRatio = rebateBrand.getRebate();//万分点
|
|
|
vidBuilder.append(":").append(rebatesRatio);
|
|
|
}
|
|
|
}
|
|
|
UnionSknRebateBo bo = new UnionSknRebateBo();
|
|
|
bo.setSkn(skn);
|
|
|
bo.setBrand(brand);
|
|
|
bo.setVid(vidBuilder.toString());
|
|
|
|
|
|
if (!rebateState) {
|
|
|
//不返佣
|
|
|
bo.setRebatePercent(new BigDecimal(0));
|
|
|
logger.info("getProductRebatePercentBo.skn is {},brand is {},hasQuery is {},rebatesRatio is 0,vid is {}.",skn,brand,hasQuery,bo.getVid());
|
|
|
return bo;
|
|
|
}
|
|
|
logger.info("getProductRebatePercentBo.skn is {},brand is {},hasQuery is {},rebatesRatio is {},vid is {}.",skn,brand,hasQuery,rebatesRatio,bo.getVid());
|
|
|
bo.setRebatePercent(new BigDecimal(rebatesRatio).divide(new BigDecimal(100)));
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JSONArray queryAllBrandList() {
|
|
|
try {
|
...
|
...
|
|