Commit 03364e3e by fanjiaxin

联调问题处理

parent 66970561
Pipeline #71582 passed with stages
in 1 minute 6 seconds
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
...@@ -10,7 +11,8 @@ import java.math.BigDecimal; ...@@ -10,7 +11,8 @@ import java.math.BigDecimal;
* @Date 2025/3/11 11:05 * @Date 2025/3/11 11:05
*/ */
@Data @Data
public class ProductListVO { public class ProductListVO implements Serializable {
private static final long serialVersionUID = -8340371734171952574L;
/** /**
* 商品标题 * 商品标题
*/ */
...@@ -35,8 +37,4 @@ public class ProductListVO { ...@@ -35,8 +37,4 @@ public class ProductListVO {
* 商品ID * 商品ID
*/ */
private String productId; private String productId;
/**
* 商品推广链接
*/
private String productUrl;
} }
package com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @Description 商品短链
* @Author fanjiaxin
* @Date 2025/3/11 11:05
*/
@Data
public class ProductPromotionLinkVO implements Serializable {
private static final long serialVersionUID = -9193922166179487836L;
/**
* 商品短链
*/
private String promotionLink;
}
package com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo; package com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo;
import lombok.Data; import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/** /**
* @Description 用户信息 * @Description 用户信息
...@@ -47,4 +49,12 @@ public class SharerInfoVO { ...@@ -47,4 +49,12 @@ public class SharerInfoVO {
* 绑定时需要的queryString参数 * 绑定时需要的queryString参数
*/ */
private String bindQueryString; private String bindQueryString;
@Getter
@RequiredArgsConstructor
public enum bindStatus{
UNBIND(0),
BIND(1);
private final Integer code;
}
} }
package com.netease.yanxuan.wx.store.sharer.biz.service; package com.netease.yanxuan.wx.store.sharer.biz.service;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLinkVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO;
...@@ -15,4 +16,9 @@ public interface IProductService { ...@@ -15,4 +16,9 @@ public interface IProductService {
* 获取商品分页列表 * 获取商品分页列表
*/ */
PageVO<ProductListVO> getProductPageList(PageQuery pageQuery, String keyword); PageVO<ProductListVO> getProductPageList(PageQuery pageQuery, String keyword);
/**
* 商品分享短链
*/
ProductPromotionLinkVO getProductPromotionLink(String productId, String sharerAppid);
} }
...@@ -3,7 +3,9 @@ package com.netease.yanxuan.wx.store.sharer.biz.service.impl; ...@@ -3,7 +3,9 @@ package com.netease.yanxuan.wx.store.sharer.biz.service.impl;
import com.netease.yanxuan.wx.store.sharer.biz.config.DrmSharerConfig; import com.netease.yanxuan.wx.store.sharer.biz.config.DrmSharerConfig;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder; import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserContextHolder;
import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo; import com.netease.yanxuan.wx.store.sharer.biz.core.LoginUserInfo;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLinkVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO;
import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService; import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService;
...@@ -101,14 +103,6 @@ public class ProductServiceImpl implements IProductService { ...@@ -101,14 +103,6 @@ public class ProductServiceImpl implements IProductService {
listVO.setCommission(commission); listVO.setCommission(commission);
listVO.setShopAppid(item.getShop_appid()); listVO.setShopAppid(item.getShop_appid());
listVO.setProductId(item.getProduct_id()); listVO.setProductId(item.getProduct_id());
// 获取推广链接
if(null != loginUserInfo && StringUtils.isNotBlank(loginUserInfo.getSharerAppId())){
WeChatPromoteProductLinkVO promoteProductLinkVO = weChatShopPromoteProductLinkRequest.handle(
loginUserInfo.getSharerAppId(),
Long.valueOf(item.getProduct_id()),
item.getShop_appid());
listVO.setProductUrl(null != promoteProductLinkVO ? promoteProductLinkVO.getShort_link() : null);
}
return listVO; return listVO;
}) })
.filter(Objects::nonNull) .filter(Objects::nonNull)
...@@ -116,4 +110,23 @@ public class ProductServiceImpl implements IProductService { ...@@ -116,4 +110,23 @@ public class ProductServiceImpl implements IProductService {
pageVO.setList(resultList); pageVO.setList(resultList);
return pageVO; return pageVO;
} }
@Override
public ProductPromotionLinkVO getProductPromotionLink(String productId, String shopAppid) {
// 获取用户信息
LoginUserInfo loginUserInfo = LoginUserContextHolder.get();
if (StringUtils.isBlank(loginUserInfo.getSharerAppId())) {
throw new NoBindSharerException("未绑定推客");
}
WeChatPromoteProductLinkVO promoteProductLinkVO = weChatShopPromoteProductLinkRequest.handle(
loginUserInfo.getSharerAppId(),
Long.valueOf(productId),
shopAppid);
if (null != promoteProductLinkVO && StringUtils.isNotBlank(promoteProductLinkVO.getShort_link())) {
ProductPromotionLinkVO result = new ProductPromotionLinkVO();
result.setPromotionLink(promoteProductLinkVO.getShort_link());
return result;
}
return null;
}
} }
...@@ -11,7 +11,6 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.SharerInfoVO; ...@@ -11,7 +11,6 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.SharerInfoVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.UserCommissionRatioVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.UserCommissionRatioVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.UserTokenVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.UserTokenVO;
import com.netease.yanxuan.wx.store.sharer.biz.service.IUserService; import com.netease.yanxuan.wx.store.sharer.biz.service.IUserService;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException;
import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerInfoMapper; import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerInfoMapper;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo; import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerListRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerListRequest;
...@@ -82,43 +81,47 @@ public class UserServiceImpl implements IUserService { ...@@ -82,43 +81,47 @@ public class UserServiceImpl implements IUserService {
@Override @Override
public SharerInfoVO refreshUserInfo() { public SharerInfoVO refreshUserInfo() {
LoginUserInfo loginUserInfo = LoginUserContextHolder.get(); LoginUserInfo loginUserInfo = LoginUserContextHolder.get();
if (null == loginUserInfo) {
throw new NoAuthException("用户登录状态过期");
}
SharerInfoVO result = getSharerRegisterBindInfo(loginUserInfo.getOpenId());
// 获取本地用户信息 // 获取本地用户信息
LambdaQueryWrapper<SharerInfo> sharerInfoLqw = Wrappers.lambdaQuery(); LambdaQueryWrapper<SharerInfo> sharerInfoLqw = Wrappers.lambdaQuery();
sharerInfoLqw.eq(SharerInfo::getOpenId, loginUserInfo.getOpenId()); sharerInfoLqw.eq(SharerInfo::getOpenId, loginUserInfo.getOpenId());
sharerInfoLqw.last("LIMIT 1"); sharerInfoLqw.last("LIMIT 1");
SharerInfo sharerInfo = sharerInfoMapper.selectOne(sharerInfoLqw); SharerInfo sharerInfo = sharerInfoMapper.selectOne(sharerInfoLqw);
Date now = new Date(); SharerInfoVO result = getSharerRegisterBindInfo(loginUserInfo.getOpenId());
// 初始化保存 // 初始化保存
if (null == sharerInfo) { if (null == sharerInfo) {
sharerInfo = new SharerInfo(); sharerInfo = new SharerInfo();
sharerInfo.setOpenId(loginUserInfo.getOpenId()); sharerInfo.setOpenId(loginUserInfo.getOpenId());
}
WeChatSharerInfoVO sharerInfoVO;
Date now = new Date();
// 已绑定
if(SharerInfoVO.bindStatus.BIND.getCode().equals(result.getBindStatus())){
// 获取绑定信息
WeChatSharerListVO sharerListVO = weChatShopSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1);
if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) {
sharerInfoVO = sharerListVO.getSharer_info_list().get(0);
if(null != sharerInfoVO){
result.setSharerAppId(sharerInfoVO.getSharer_appid());
sharerInfo.setSharerAppid(sharerInfoVO.getSharer_appid());
Date bindTime = null != sharerInfoVO.getBind_time() ? new Date(sharerInfoVO.getBind_time()) : now;
sharerInfo.setBindTime(bindTime);
sharerInfo.setCommissionRatio(sharerInfoVO.getCommission_ratio());
String commissionType = null != sharerInfoVO.getCommission_type() ? sharerInfoVO.getCommission_type().toString() : CommissionTypeEnum.PLATFORM.getCode();
sharerInfo.setCommissionType(commissionType);
}
}
}
// 初始化保存
if (null == sharerInfo.getId()) {
// 默认佣金比例 // 默认佣金比例
sharerInfo.setCommissionRatio(drmSharerConfig.getDefaultCommissionRatio()); sharerInfo.setCommissionRatio(drmSharerConfig.getDefaultCommissionRatio());
sharerInfo.setCommissionType(CommissionTypeEnum.PLATFORM.getCode()); sharerInfo.setCommissionType(CommissionTypeEnum.PLATFORM.getCode());
sharerInfo.setCreateTime(now); sharerInfo.setCreateTime(now);
sharerInfo.setUpdateTime(now); sharerInfo.setUpdateTime(now);
sharerInfoMapper.insert(sharerInfo); sharerInfoMapper.insert(sharerInfo);
} }else{
// 已经绑定 sharerInfo.setUpdateTime(now);
if (StringUtils.isNotBlank(sharerInfo.getSharerAppid())) { sharerInfoMapper.updateById(sharerInfo);
result.setSharerAppId(sharerInfo.getSharerAppid());
}
WeChatSharerListVO sharerListVO = weChatShopSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1);
if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) {
WeChatSharerInfoVO sharerInfoVO = sharerListVO.getSharer_info_list().get(0);
if (null != sharerInfoVO && StringUtils.isNotBlank(sharerInfoVO.getSharer_appid())) {
result.setSharerAppId(sharerInfoVO.getSharer_appid());
sharerInfo.setSharerAppid(sharerInfoVO.getSharer_appid());
sharerInfo.setBindTime(new Date(sharerInfoVO.getBind_time()));
sharerInfo.setCommissionRatio(sharerInfoVO.getCommission_ratio());
sharerInfo.setCommissionType(sharerInfoVO.getCommission_type().toString());
sharerInfo.setUpdateTime(now);
sharerInfoMapper.updateById(sharerInfo);
}
} }
return result; return result;
} }
...@@ -126,9 +129,6 @@ public class UserServiceImpl implements IUserService { ...@@ -126,9 +129,6 @@ public class UserServiceImpl implements IUserService {
@Override @Override
public SharerInfoVO getUserInfo() { public SharerInfoVO getUserInfo() {
LoginUserInfo loginUserInfo = LoginUserContextHolder.get(); LoginUserInfo loginUserInfo = LoginUserContextHolder.get();
if (null == loginUserInfo) {
throw new NoAuthException("用户登录状态过期");
}
SharerInfoVO result = getSharerRegisterBindInfo(loginUserInfo.getOpenId()); SharerInfoVO result = getSharerRegisterBindInfo(loginUserInfo.getOpenId());
// 获取本地用户信息 // 获取本地用户信息
LambdaQueryWrapper<SharerInfo> sharerInfoLqw = Wrappers.lambdaQuery(); LambdaQueryWrapper<SharerInfo> sharerInfoLqw = Wrappers.lambdaQuery();
......
...@@ -10,11 +10,16 @@ public interface HttpStatusConstant { ...@@ -10,11 +10,16 @@ public interface HttpStatusConstant {
int SUCCESS = 200; int SUCCESS = 200;
/** /**
* 未授权 * 鉴权失败
*/ */
int UNAUTHORIZED = 401; int UNAUTHORIZED = 401;
/** /**
* 未绑定推客
*/
int UNAUTHSHARER = 40101;
/**
* 失败标记 * 失败标记
*/ */
int FAIL = 500; int FAIL = 500;
......
package com.netease.yanxuan.wx.store.sharer.common.exception;
/**
* 未绑定推客-异常类
*/
public class NoBindSharerException extends BizException {
private static final long serialVersionUID = 6300030459749920168L;
public NoBindSharerException() {
super();
}
public NoBindSharerException(String message) {
super(message);
}
public NoBindSharerException(String message, Throwable cause) {
super(message, cause);
}
public NoBindSharerException(Throwable cause) {
super(cause);
}
public NoBindSharerException(Object obj) {
super();
}
public NoBindSharerException(String message, Object obj) {
super(message);
}
public NoBindSharerException(String message, Throwable cause, Object obj) {
super(message, cause);
}
public NoBindSharerException(Throwable cause, Object obj) {
super(cause);
}
}
...@@ -5,6 +5,7 @@ import com.netease.yanxuan.wx.store.sharer.common.constant.HttpStatusConstant; ...@@ -5,6 +5,7 @@ import com.netease.yanxuan.wx.store.sharer.common.constant.HttpStatusConstant;
import com.netease.yanxuan.wx.store.sharer.common.core.Result; import com.netease.yanxuan.wx.store.sharer.common.core.Result;
import com.netease.yanxuan.wx.store.sharer.common.exception.BizException; import com.netease.yanxuan.wx.store.sharer.common.exception.BizException;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException; import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException;
import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException; import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
...@@ -30,13 +31,13 @@ public class GlobalExceptionHandler { ...@@ -30,13 +31,13 @@ public class GlobalExceptionHandler {
} }
/** /**
* 系统异常 * 未绑定推客异常
*/ */
@ExceptionHandler(Exception.class) @ExceptionHandler(NoBindSharerException.class)
public Result<Void> handleException(Exception e, HttpServletRequest request) { public Result<Void> handleNoBindSharerException(NoBindSharerException e, HttpServletRequest request) {
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e); log.error("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage());
return Result.fail(e); return Result.fail(HttpStatusConstant.UNAUTHSHARER, "未授权推客");
} }
/** /**
...@@ -58,4 +59,14 @@ public class GlobalExceptionHandler { ...@@ -58,4 +59,14 @@ public class GlobalExceptionHandler {
log.error("请求地址'{}',发生业务异常.", requestURI, e); log.error("请求地址'{}',发生业务异常.", requestURI, e);
return Result.fail(e); return Result.fail(e);
} }
/**
* 系统异常
*/
@ExceptionHandler(Exception.class)
public Result<Void> handleException(Exception e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
return Result.fail(e);
}
} }
package com.netease.yanxuan.wx.store.sharer.web.controller; package com.netease.yanxuan.wx.store.sharer.web.controller;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLinkVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO;
import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService; import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService;
...@@ -33,4 +34,14 @@ public class ProductController extends BaseController { ...@@ -33,4 +34,14 @@ public class ProductController extends BaseController {
return Result.ok(pageList); return Result.ok(pageList);
} }
/**
* 商品分享短链
*/
@GetMapping("/promotion/link")
public Result<ProductPromotionLinkVO> getProductPromotionLink(@RequestParam("shopAppid") String shopAppid,
@RequestParam("productId") String productId) {
ProductPromotionLinkVO promotionLink = iProductService.getProductPromotionLink(shopAppid, productId);
return Result.ok(promotionLink);
}
} }
/**
* vo对象
*
* @author 莫闲.
* @date 2021/1/29.
*/
package com.netease.yanxuan.wx.store.sharer.web.meta.model.vo;
/**
* web 部分一般包含常见的Controller,Servlet等组件
*
* @author hzwangliyuan.
* @date 2019/11/28.
*/
package com.netease.yanxuan.wx.store.sharer.web;
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