refactor(myInvitation): 调整邀请功能模块

master
yang 2025-03-04 18:04:51 +08:00
parent e813ee9dff
commit 1b7b096f50
11 changed files with 81 additions and 40 deletions

View File

@ -10,6 +10,7 @@ import com.mcwl.myInvitation.service.InvitationService;
import com.mcwl.myInvitation.domain.vo.EarningsDisplayVO; import com.mcwl.myInvitation.domain.vo.EarningsDisplayVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -17,6 +18,10 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -60,9 +65,11 @@ public class InvitationController {
* @return * @return
*/ */
@GetMapping("/list/{userId}") @GetMapping("/list")
@ApiOperation(value = "获取邀请列表") @ApiOperation(value = "获取邀请列表")
public R<List<Invitation>> list(@PathVariable Long userId) { public R<List<Invitation>> list(@Valid
@NotNull(message = "用户id不能为空")
@ApiParam("用户id") Long userId) {
List<Invitation> list = invitationService.lambdaQuery() List<Invitation> list = invitationService.lambdaQuery()
.eq(Invitation::getUserId, userId) .eq(Invitation::getUserId, userId)
.list(); .list();
@ -86,7 +93,7 @@ public class InvitationController {
// 获取我的团员 // 获取我的团员
List<EarningsDisplayDto> earningsDisplay = invitationService.getEarningsDisplay(userId); List<EarningsDisplayDto> earningsDisplay = invitationService.getEarningsDisplay(userId);
if (earningsDisplay == null || earningsDisplay.isEmpty()) { if (earningsDisplay == null || earningsDisplay.isEmpty()) {
return R.fail("暂无收益"); return R.ok(new EarningsDisplayVO(totalAmount, Collections.emptyList()));
} }
earningsDisplayVO.setTotalAmount(totalAmount); earningsDisplayVO.setTotalAmount(totalAmount);

View File

@ -142,12 +142,11 @@ mall:
alipayCertPath: cert/pro/alipayCertPublicKey_RSA2.crt alipayCertPath: cert/pro/alipayCertPublicKey_RSA2.crt
# 线上支付宝根证书路径 # 线上支付宝根证书路径
alipayRootCertPath: cert/pro/alipayRootCert.crt alipayRootCertPath: cert/pro/alipayRootCert.crt
# 线上支付宝公钥 notifyUrl: https://36072a51.r27.cpolar.top/ali/pay/notify
notifyUrl: https://253d7236.r27.cpolar.top/ali/pay/notify
# 线上支付宝网关 # 线上支付宝网关
gatewayUrl: https://openapi.alipay.com/gateway.do gatewayUrl: https://openapi.alipay.com/gateway.do
# 绑定回调 # 绑定回调
bindUrl: https://4b0ca615.r27.cpolar.top/ali/pay/callback bindUrl: https://36072a51.r27.cpolar.top/ali/pay/callback
huawei: huawei:
obs: obs:

View File

@ -8,6 +8,7 @@ import com.mcwl.common.exception.ErrorCodeException;
import com.mcwl.common.exception.ServiceException; import com.mcwl.common.exception.ServiceException;
import com.mcwl.common.utils.StringUtils; import com.mcwl.common.utils.StringUtils;
import com.mcwl.common.utils.html.EscapeUtil; import com.mcwl.common.utils.html.EscapeUtil;
import io.lettuce.core.RedisCommandTimeoutException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
@ -27,8 +28,7 @@ import javax.servlet.http.HttpServletRequest;
* @author mcwl * @author mcwl
*/ */
@RestControllerAdvice @RestControllerAdvice
public class GlobalExceptionHandler public class GlobalExceptionHandler {
{
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ -38,20 +38,28 @@ public class GlobalExceptionHandler
@ExceptionHandler(ErrorCodeException.class) @ExceptionHandler(ErrorCodeException.class)
public AjaxResult UserDefinedException(ErrorCodeException e) { public AjaxResult UserDefinedException(ErrorCodeException e) {
System.out.println("StringUtils.isNull(e.getCode()):" + StringUtils.isNull(e.getCode())); System.out.println("StringUtils.isNull(e.getCode()):" + StringUtils.isNull(e.getCode()));
if (StringUtils.isNull(e.getCode())) if (StringUtils.isNull(e.getCode())) {
{
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
return AjaxResult.error(e.getCode(), e.getMessage()); return AjaxResult.error(e.getCode(), e.getMessage());
} }
/**
*
*/
@ExceptionHandler(RedisCommandTimeoutException.class)
public AjaxResult commandTimeoutException(AccessDeniedException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("连接超时{},{}", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.ERROR, "连接超时");
}
/** /**
* *
*/ */
@ExceptionHandler(AccessDeniedException.class) @ExceptionHandler(AccessDeniedException.class)
public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage()); log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权"); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权");
@ -62,8 +70,7 @@ public class GlobalExceptionHandler
*/ */
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
HttpServletRequest request) HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -73,8 +80,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(ServiceException.class) @ExceptionHandler(ServiceException.class)
public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) {
{
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
Integer code = e.getCode(); Integer code = e.getCode();
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
@ -84,8 +90,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(MissingPathVariableException.class) @ExceptionHandler(MissingPathVariableException.class)
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e); log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName())); return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
@ -95,12 +100,10 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
String value = Convert.toStr(e.getValue()); String value = Convert.toStr(e.getValue());
if (StringUtils.isNotEmpty(value)) if (StringUtils.isNotEmpty(value)) {
{
value = EscapeUtil.clean(value); value = EscapeUtil.clean(value);
} }
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e); log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
@ -111,8 +114,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e); log.error("请求地址'{}',发生未知异常.", requestURI, e);
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -122,8 +124,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public AjaxResult handleException(Exception e, HttpServletRequest request) public AjaxResult handleException(Exception e, HttpServletRequest request) {
{
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e); log.error("请求地址'{}',发生系统异常.", requestURI, e);
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
@ -133,8 +134,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(BindException.class) @ExceptionHandler(BindException.class)
public AjaxResult handleBindException(BindException e) public AjaxResult handleBindException(BindException e) {
{
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
String message = e.getAllErrors().get(0).getDefaultMessage(); String message = e.getAllErrors().get(0).getDefaultMessage();
return AjaxResult.error(message); return AjaxResult.error(message);
@ -144,8 +144,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(MethodArgumentNotValidException.class) @ExceptionHandler(MethodArgumentNotValidException.class)
public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
{
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
String message = e.getBindingResult().getFieldError().getDefaultMessage(); String message = e.getBindingResult().getFieldError().getDefaultMessage();
return AjaxResult.error(message); return AjaxResult.error(message);
@ -155,8 +154,7 @@ public class GlobalExceptionHandler
* *
*/ */
@ExceptionHandler(DemoModeException.class) @ExceptionHandler(DemoModeException.class)
public AjaxResult handleDemoModeException(DemoModeException e) public AjaxResult handleDemoModeException(DemoModeException e) {
{
return AjaxResult.error("演示模式,不允许操作"); return AjaxResult.error("演示模式,不允许操作");
} }
} }

View File

@ -4,6 +4,9 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.mcwl.common.exception.ServiceException;
import io.lettuce.core.RedisCommandTimeoutException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,13 +1,18 @@
package com.mcwl.myInvitation.domain.dto; package com.mcwl.myInvitation.domain.dto;
import com.mcwl.common.core.domain.entity.SysUser; import com.mcwl.common.core.domain.entity.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
@ApiModel(value = "被邀请者信息")
public class EarningsDisplayDto { public class EarningsDisplayDto {
private SysUser user; @ApiModelProperty("被邀请人")
private SysUserDto user;
@ApiModelProperty("购买商品数")
private Integer count; private Integer count;
} }

View File

@ -0,0 +1,15 @@
package com.mcwl.myInvitation.domain.dto;
import lombok.Data;
import java.util.Date;
/**
*
*/
@Data
public class SysUserDto {
private Long userId;
private String userName;
private String avatar;
}

View File

@ -2,20 +2,29 @@ package com.mcwl.myInvitation.domain.vo;
import com.mcwl.myInvitation.domain.dto.EarningsDisplay; import com.mcwl.myInvitation.domain.dto.EarningsDisplay;
import com.mcwl.myInvitation.domain.dto.EarningsDisplayDto; import com.mcwl.myInvitation.domain.dto.EarningsDisplayDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "邀请人收益展示")
public class EarningsDisplayVO { public class EarningsDisplayVO {
/** /**
* *
*/ */
@ApiModelProperty("收益总额")
private Double totalAmount; private Double totalAmount;
/** /**
* *
*/ */
@ApiModelProperty("邀请列表")
private List<EarningsDisplayDto> earningsDisplayList; private List<EarningsDisplayDto> earningsDisplayList;
} }

View File

@ -1,10 +1,13 @@
package com.mcwl.myInvitation.service.impl; package com.mcwl.myInvitation.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.core.domain.entity.SysUser;
import com.mcwl.common.utils.ShareCodeUtils; import com.mcwl.common.utils.ShareCodeUtils;
import com.mcwl.myInvitation.domain.Invitation; import com.mcwl.myInvitation.domain.Invitation;
import com.mcwl.myInvitation.domain.dto.EarningsDisplay; import com.mcwl.myInvitation.domain.dto.EarningsDisplay;
import com.mcwl.myInvitation.domain.dto.EarningsDisplayDto; import com.mcwl.myInvitation.domain.dto.EarningsDisplayDto;
import com.mcwl.myInvitation.domain.dto.SysUserDto;
import com.mcwl.myInvitation.mapper.InvitationMapper; import com.mcwl.myInvitation.mapper.InvitationMapper;
import com.mcwl.myInvitation.service.ConsumeService; import com.mcwl.myInvitation.service.ConsumeService;
import com.mcwl.myInvitation.service.InvitationService; import com.mcwl.myInvitation.service.InvitationService;
@ -45,7 +48,8 @@ public class InvitationServiceImpl extends ServiceImpl<InvitationMapper, Invitat
List<EarningsDisplayDto> list = new ArrayList<>(); List<EarningsDisplayDto> list = new ArrayList<>();
earningsDisplay.forEach(item -> { earningsDisplay.forEach(item -> {
EarningsDisplayDto edd = new EarningsDisplayDto(); EarningsDisplayDto edd = new EarningsDisplayDto();
edd.setUser(sysUserService.selectUserById(item.getUserId())); SysUser sysUser = sysUserService.selectUserById(item.getUserId());
edd.setUser(BeanUtil.copyProperties(sysUser, SysUserDto.class));
edd.setCount(item.getCount()); edd.setCount(item.getCount());
list.add(edd); list.add(edd);
}); });

View File

@ -209,6 +209,7 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) { } else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "promotionId"); Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "promotionId");
memberHandler(orderTrade, promotionId); memberHandler(orderTrade, promotionId);
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
} else if (OrderTypeEnum.WALLET.getName().equals(suffix)) { } else if (OrderTypeEnum.WALLET.getName().equals(suffix)) {
walletHandler(orderTrade, params); walletHandler(orderTrade, params);
} else { } else {
@ -218,7 +219,6 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
this.orderHandler(orderTrade, params); this.orderHandler(orderTrade, params);
// 删除redis缓存 // 删除redis缓存
redisCache.deleteObject(orderTrade.getCode()); redisCache.deleteObject(orderTrade.getCode());
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
} }

View File

@ -105,6 +105,7 @@ public class SysUserAttentionServiceImpl extends ServiceImpl<SysUserAttentionMap
userId = SecurityUtils.getUserIdMax(); userId = SecurityUtils.getUserIdMax();
} }
PageHelper.clearPage();
// 粉丝数 // 粉丝数
Long userBeanNum = sysUserAttentionMapper.selectBean(userId); Long userBeanNum = sysUserAttentionMapper.selectBean(userId);