Commit a59e74b5 by fanjiaxin

代码初始化

parent 627087e8
Pipeline #71448 passed with stages
in 1 minute 8 seconds
......@@ -7,6 +7,8 @@
package com.netease.yanxuan.wx.store.sharer.biz.config;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
......@@ -17,7 +19,9 @@ import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo;
import com.netease.yanxuan.wx.store.sharer.biz.meta.enums.CommissionChangeOptTypeEnum;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.bo.CommissionSharerBO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.bo.CommissionSharerProductBO;
import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerInfoMapper;
import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerProductCommissionRecordMapper;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerProductCommissionRecord;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSetSharerCommissionRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSetSharerProductCommissionRequest;
......@@ -34,6 +38,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -48,11 +53,13 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
@EnableAutoUpdateApolloConfig("sharer-config")
public class DrmSharerConfig {
private final SharerInfoMapper sharerInfoMapper;
private final SharerProductCommissionRecordMapper sharerProdutcCommissionRecordMapper;
private final WeChatSharerListRequest weChatSharerListRequest;
private final WeChatSetSharerCommissionRequest weChatSetSharerCommissionRequest;
private final WeChatSetSharerProductCommissionRequest weChatSetSharerProductCommissionRequest;
private final Map<String, String> sharerAppidMap = new ConcurrentHashMap<>(0);
/**
* 默认分佣比例
......@@ -203,13 +210,18 @@ public class DrmSharerConfig {
*/
private void setSharerCommissionInfo(CommissionSharerBO newCommissionSharer,
CommissionSharerBO oldCommissionSharer) {
String sharerAppid = getSharerAppidByOpenId(newCommissionSharer.getOpenId());
if (StringUtils.isBlank(sharerAppid)) {
log.error("微信用户暂未绑定微信小店,openId={}", newCommissionSharer.getOpenId());
return;
}
// 分佣比例为小数, 微信接口参数应当分佣比例*1000 为整数
BigDecimal commissionRatio = newCommissionSharer.getCommissionRatio().divide(BigDecimal.valueOf(1000));
// 设置推客分佣比例
boolean isSuccess = false;
try {
// 设置推客分佣比例
weChatSetSharerCommissionRequest.handle(newCommissionSharer.getSharerId(), commissionRatio.toPlainString());
weChatSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString());
isSuccess = true;
} catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e);
......@@ -219,7 +231,7 @@ public class DrmSharerConfig {
Date now = new Date();
SharerProductCommissionRecord record = new SharerProductCommissionRecord();
record.setOpenId(loginUserInfo.getOpenId());
record.setSharerAppid(newCommissionSharer.getSharerId());
record.setSharerAppid(sharerAppid);
record.setProductId("");
record.setOptType(CommissionChangeOptTypeEnum.SET.getCode());
record.setOptInfo(oldCommissionSharer.getCommissionRatio().toPlainString()
......@@ -240,13 +252,18 @@ public class DrmSharerConfig {
* 删除推客的的分佣类型和比例信息
*/
private void deleteSharerCommissionInfo(CommissionSharerBO oldCommissionSharer) {
String sharerAppid = getSharerAppidByOpenId(oldCommissionSharer.getOpenId());
if (StringUtils.isBlank(sharerAppid)) {
log.error("微信用户暂未绑定微信小店,openId={}", oldCommissionSharer.getOpenId());
return;
}
// 分佣比例为小数, 微信接口参数应当分佣比例*1000 为整数
BigDecimal commissionRatio = defaultCommissionRatio.divide(BigDecimal.valueOf(1000));
// 设置推客分佣比例
boolean isSuccess = false;
try {
// 设置推客分佣比例
weChatSetSharerCommissionRequest.handle(oldCommissionSharer.getSharerId(), commissionRatio.toPlainString());
weChatSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString());
isSuccess = true;
} catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e);
......@@ -256,7 +273,7 @@ public class DrmSharerConfig {
Date now = new Date();
SharerProductCommissionRecord record = new SharerProductCommissionRecord();
record.setOpenId(loginUserInfo.getOpenId());
record.setSharerAppid(oldCommissionSharer.getSharerId());
record.setSharerAppid(sharerAppid);
record.setProductId("");
record.setOptType(CommissionChangeOptTypeEnum.UNSET.getCode());
record.setOptInfo(oldCommissionSharer.getCommissionRatio().toPlainString() + "&" + defaultCommissionRatio.toPlainString());
......@@ -317,13 +334,18 @@ public class DrmSharerConfig {
*/
private void setSharerProductCommissionInfo(CommissionSharerProductBO newBo,
CommissionSharerProductBO oldBo) {
String sharerAppid = getSharerAppidByOpenId(newBo.getOpenId());
if (StringUtils.isBlank(sharerAppid)) {
log.error("微信用户暂未绑定微信小店,openId={}", newBo.getOpenId());
return;
}
// 分佣比例为小数, 微信接口参数应当分佣比例*1000 为整数
BigDecimal commissionRatio = newBo.getCommissionRatio().divide(BigDecimal.valueOf(1000));
// 设置推客分佣比例
boolean isSuccess = false;
try {
// 设置推客分佣比例
weChatSetSharerProductCommissionRequest.handle(newBo.getSharerId(), newBo.getProductId(), commissionRatio.toPlainString());
weChatSetSharerProductCommissionRequest.handle(sharerAppid, newBo.getProductId(), commissionRatio.toPlainString());
isSuccess = true;
} catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e);
......@@ -333,7 +355,7 @@ public class DrmSharerConfig {
Date now = new Date();
SharerProductCommissionRecord record = new SharerProductCommissionRecord();
record.setOpenId(loginUserInfo.getOpenId());
record.setSharerAppid(newBo.getSharerId());
record.setSharerAppid(sharerAppid);
record.setProductId(newBo.getProductId().toString());
record.setOptType(CommissionChangeOptTypeEnum.SET.getCode());
record.setOptInfo(oldBo.getCommissionRatio().toPlainString()
......@@ -354,11 +376,16 @@ public class DrmSharerConfig {
* 删除推客的的分佣类型和比例信息
*/
private void deleteSharerProductCommissionInfo(CommissionSharerProductBO oldBo) {
String sharerAppid = getSharerAppidByOpenId(oldBo.getOpenId());
if (StringUtils.isBlank(sharerAppid)) {
log.error("微信用户暂未绑定微信小店,openId={}", oldBo.getOpenId());
return;
}
// 设置推客分佣比例
boolean isSuccess = false;
try {
// 设置推客分佣比例
weChatSetSharerProductCommissionRequest.handle(oldBo.getSharerId(), oldBo.getProductId(), null);
weChatSetSharerProductCommissionRequest.handle(sharerAppid, oldBo.getProductId(), null);
isSuccess = true;
} catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e);
......@@ -368,7 +395,7 @@ public class DrmSharerConfig {
Date now = new Date();
SharerProductCommissionRecord record = new SharerProductCommissionRecord();
record.setOpenId(loginUserInfo.getOpenId());
record.setSharerAppid(oldBo.getSharerId());
record.setSharerAppid(sharerAppid);
record.setProductId(oldBo.getProductId().toString());
record.setOptType(CommissionChangeOptTypeEnum.UNSET.getCode());
record.setOptInfo(oldBo.getCommissionRatio().toPlainString() + "&");
......@@ -383,4 +410,22 @@ public class DrmSharerConfig {
}
}
}
/**
* 根据 openId 获取推客的 SharerAppid
*/
private String getSharerAppidByOpenId(String openId) {
String sharerAppid = sharerAppidMap.get(openId);
if (StringUtils.isBlank(sharerAppid)) {
LambdaQueryWrapper<SharerInfo> sharerInfoLqw = Wrappers.lambdaQuery();
sharerInfoLqw.eq(SharerInfo::getOpenId, openId);
sharerInfoLqw.last("LIMIT 1");
SharerInfo sharerInfo = sharerInfoMapper.selectOne(sharerInfoLqw);
if (null != sharerInfo && StringUtils.isNotBlank(sharerInfo.getSharerAppid())) {
sharerAppid = sharerInfo.getSharerAppid();
sharerAppidMap.put(openId, sharerAppid);
}
}
return sharerAppid;
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ import java.util.Collections;
public class WebConfig implements WebMvcConfigurer {
private final AuthInterceptor authInterceptor;
private static final String[] EXCLUDE_URLS = {"/open/**", "/i/health", "/user/login", "/product/page/list"};
private static final String[] EXCLUDE_URLS = {"/open/**", "/test/**", "/i/health", "/user/login", "/product/page/list"};
@Override
public void addInterceptors(InterceptorRegistry registry) {
......
......@@ -19,10 +19,6 @@ public class CommissionSharerBO implements Serializable {
*/
private String openId;
/**
* 推客ID
*/
private String sharerId;
/**
* 分佣比例
*/
private BigDecimal CommissionRatio;
......
......@@ -19,10 +19,6 @@ public class CommissionSharerProductBO implements Serializable {
*/
private String openId;
/**
* 推客ID
*/
private String sharerId;
/**
* 商品ID
*/
private Integer productId;
......
......@@ -8,7 +8,8 @@ package com.netease.yanxuan.wx.store.sharer.web.controller;
import com.netease.yanxuan.wx.store.sharer.common.core.Result;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatAccessTokenRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatAccessTokenVO;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatUserInfoRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatUserInfoVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -22,10 +23,11 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class TestController {
private final WeChatAccessTokenRequest weChatAccessTokenRequest;
private final WeChatUserInfoRequest weChatUserInfoRequest;
@RequestMapping("/token")
public Result<WeChatAccessTokenVO> token() {
WeChatAccessTokenVO handle = weChatAccessTokenRequest.handle();
public Result<WeChatUserInfoVO> token() {
WeChatUserInfoVO handle = weChatUserInfoRequest.handle("0f11uE0w3hIUx43hre0w3NwgHb31uE0Z");
return Result.ok(handle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment