Authored by gemingdan

skn返佣-前台

... ... @@ -2,8 +2,10 @@ package com.yoho.unions.dal;
import com.yoho.service.model.union.request.UnionShareRebateReqBo;
import com.yoho.unions.dal.model.UnionShareRebateBrand;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
public interface UnionShareRebateBrandMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -15,6 +17,7 @@ public interface UnionShareRebateBrandMapper {
UnionShareRebateBrand selectByPrimaryKey(Integer id);
UnionShareRebateBrand selectByBrand(Integer brand);
List<UnionShareRebateBrand> selectListByCon(UnionShareRebateReqBo req);
List<UnionShareRebateBrand> selectListByBrands(@Param("brands")Set<Integer> brands);
int selectCountByCon(UnionShareRebateReqBo req);
int updateByPrimaryKeySelective(UnionShareRebateBrand record);
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.unions.dal.model.UnionShareRebateSkn;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
public interface UnionShareRebateSknMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -16,7 +17,7 @@ public interface UnionShareRebateSknMapper {
UnionShareRebateSkn selectByPrimaryKey(Integer id);
UnionShareRebateSkn selectBySkn(Integer skn);
List<UnionShareRebateSkn> selectListByCon(UnionShareRebateReqBo req);
List<UnionShareRebateSkn> selectListBySkns(@Param("skns")List<Integer> skns);
List<UnionShareRebateSkn> selectListBySkns(@Param("skns")Set<Integer> skns);
int selectCountByCon(UnionShareRebateReqBo req);
int updateByPrimaryKeySelective(UnionShareRebateSkn record);
... ...
... ... @@ -45,6 +45,15 @@
<if test="state != null"> and state = #{state,jdbcType=INTEGER}</if>
limit #{start},#{size}
</select>
<select id="selectListByBrands" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_rebate_brand
where brand in
<foreach collection="brands" item="brand" open="(" separator="," close=")">
#{brand}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_share_rebate_brand
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -48,6 +48,15 @@
<if test="state != null"> and state = #{state,jdbcType=INTEGER}</if>
limit #{start},#{size}
</select>
<select id="selectListBySkns" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_rebate_skn
where skn in
<foreach collection="skns" item="items" separator="," open="(" close=")">
#{items}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_share_rebate_skn
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -114,23 +114,23 @@ public class UnionRebateRest {
}
/**
* 批量查询skn返佣list todo
* 批量查询skn返佣list
* */
@RequestMapping("/queryRebateList")
@ResponseBody
public List<UnionShareRebateBo> queryRebateList(@RequestBody BatchBaseRequest<UnionSknRebateBo> req){
public List<UnionSknRebateBo> queryRebateList(@RequestBody BatchBaseRequest<UnionSknRebateBo> req){
log.info("queryBrandList.req is {}", req);
List<UnionShareRebateBo> result = unionShareRebateService.queryRebateList(req.getParams());
List<UnionSknRebateBo> result = unionShareRebateService.queryRebateList(req.getParams());
return result;
}
/**
* 查询skn返佣 todo
* 查询skn返佣
* */
@RequestMapping("/querySknRebate")
@ResponseBody
public UnionShareRebateBo querySknRebate(@RequestBody UnionSknRebateBo req) {
public UnionSknRebateBo querySknRebate(@RequestBody UnionSknRebateBo req) {
log.info("queryBrandList.req is {}", req);
UnionShareRebateBo result = unionShareRebateService.querySknRebate(req);
UnionSknRebateBo result = unionShareRebateService.querySknRebate(req);
return result;
}
... ...
... ... @@ -24,7 +24,8 @@ public interface IUnionShareRebateService {
int addBrand(UnionShareRebateBo req);
int updateBrand(UnionShareRebateBo req);
List<UnionShareRebateBo> queryRebateList(List<UnionSknRebateBo> req);
UnionShareRebateBo querySknRebate(UnionSknRebateBo req);
List<UnionSknRebateBo> queryRebateList(List<UnionSknRebateBo> req);
UnionSknRebateBo querySknRebate(UnionSknRebateBo req);
UnionSknRebateBo querySknRebate(Integer skn, Integer brand, String rebatesRatioDefault);
JSONArray queryAllBrandList();
}
... ...
... ... @@ -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 {
... ...
... ... @@ -34,6 +34,7 @@ import com.yoho.unions.constant.SendModelEnum;
import com.yoho.unions.dal.*;
import com.yoho.unions.dal.model.*;
import com.yoho.unions.helper.SendMessageHelper;
import com.yoho.unions.server.service.IUnionShareRebateService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.record.ContinueRecord;
... ... @@ -156,11 +157,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
UnionShareYohoNewUidMapper unionShareYohoNewUidMapper;
@Autowired
UnionShareRebateBrandMapper unionShareRebateBrandMapper;
@Autowired
UnionShareRebateSknMapper unionShareRebateSknMapper;
@Autowired
UnionShareRebateLogMapper unionShareRebateLogMapper;
IUnionShareRebateService unionShareRebateService;
@Resource
RedisValueCache redisValueCache;
... ... @@ -3393,55 +3390,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
private BigDecimal getProductRebates(UnionShareOrdersProduct product,String rebatesRatioDefault) {
int rebatesRatio = Integer.valueOf(rebatesRatioDefault)*100;//默认设置是百分点
UnionShareRebateSkn shareRebateSkn = unionShareRebateSknMapper.selectBySkn(product.getProductSkn());
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 = unionShareRebateBrandMapper.selectByBrand(product.getBrand());
}
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);
}
}
product.setVid(vidBuilder.toString());
if (!rebateState) {
//不返佣
product.setAmount(new BigDecimal(0));
return product.getAmount();
}
BigDecimal productAmount=(new BigDecimal(rebatesRatio).divide(new BigDecimal(10000)).multiply(product.getPrice())).setScale(2,BigDecimal.ROUND_DOWN);
UnionSknRebateBo rebateBo=unionShareRebateService.querySknRebate(product.getProductSkn(),product.getBrand(),rebatesRatioDefault);
product.setVid(rebateBo.getVid());
BigDecimal productAmount=(rebateBo.getRebatePercent().divide(new BigDecimal(100)).multiply(product.getPrice())).setScale(2,BigDecimal.ROUND_DOWN);
product.setAmount(productAmount);
return productAmount;
}
... ...