From 1b7b096f509f20729820453790393e9d84595265 Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Tue, 4 Mar 2025 18:04:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(myInvitation):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=82=80=E8=AF=B7=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myInvitation/InvitationController.java | 13 +++-- .../src/main/resources/application-druid.yml | 5 +- .../web/exception/GlobalExceptionHandler.java | 54 +++++++++---------- .../framework/web/service/TokenService.java | 3 ++ .../domain/dto/EarningsDisplayDto.java | 7 ++- .../myInvitation/domain/dto/SysUserDto.java | 15 ++++++ .../domain/vo/EarningsDisplayVO.java | 13 ++++- .../service/impl/InvitationServiceImpl.java | 6 ++- .../service/impl/OrderTradeServiceImpl.java | 2 +- .../impl/SysUserAttentionServiceImpl.java | 1 + .../resource/SysUserAttentionMapper.xml | 2 +- 11 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/SysUserDto.java diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/myInvitation/InvitationController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/myInvitation/InvitationController.java index 8e15ec7..82d58a6 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/myInvitation/InvitationController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/myInvitation/InvitationController.java @@ -10,6 +10,7 @@ import com.mcwl.myInvitation.service.InvitationService; import com.mcwl.myInvitation.domain.vo.EarningsDisplayVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; 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.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.Optional; @@ -60,9 +65,11 @@ public class InvitationController { * @return 邀请列表 */ - @GetMapping("/list/{userId}") + @GetMapping("/list") @ApiOperation(value = "获取邀请列表") - public R> list(@PathVariable Long userId) { + public R> list(@Valid + @NotNull(message = "用户id不能为空") + @ApiParam("用户id") Long userId) { List list = invitationService.lambdaQuery() .eq(Invitation::getUserId, userId) .list(); @@ -86,7 +93,7 @@ public class InvitationController { // 获取我的团员 List earningsDisplay = invitationService.getEarningsDisplay(userId); if (earningsDisplay == null || earningsDisplay.isEmpty()) { - return R.fail("暂无收益"); + return R.ok(new EarningsDisplayVO(totalAmount, Collections.emptyList())); } earningsDisplayVO.setTotalAmount(totalAmount); diff --git a/mcwl-admin/src/main/resources/application-druid.yml b/mcwl-admin/src/main/resources/application-druid.yml index f877370..a007af4 100644 --- a/mcwl-admin/src/main/resources/application-druid.yml +++ b/mcwl-admin/src/main/resources/application-druid.yml @@ -142,12 +142,11 @@ mall: alipayCertPath: cert/pro/alipayCertPublicKey_RSA2.crt # 线上支付宝根证书路径 alipayRootCertPath: cert/pro/alipayRootCert.crt - # 线上支付宝公钥 - notifyUrl: https://253d7236.r27.cpolar.top/ali/pay/notify + notifyUrl: https://36072a51.r27.cpolar.top/ali/pay/notify # 线上支付宝网关 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: obs: diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java index b329f36..f21d0ad 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java @@ -8,6 +8,7 @@ import com.mcwl.common.exception.ErrorCodeException; import com.mcwl.common.exception.ServiceException; import com.mcwl.common.utils.StringUtils; import com.mcwl.common.utils.html.EscapeUtil; +import io.lettuce.core.RedisCommandTimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.AccessDeniedException; @@ -27,8 +28,7 @@ import javax.servlet.http.HttpServletRequest; * @author mcwl */ @RestControllerAdvice -public class GlobalExceptionHandler -{ +public class GlobalExceptionHandler { private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); @@ -36,22 +36,30 @@ public class GlobalExceptionHandler * 仿照业务异常——自定义异常抛出 */ @ExceptionHandler(ErrorCodeException.class) - public AjaxResult UserDefinedException(ErrorCodeException e){ - System.out.println("StringUtils.isNull(e.getCode()):"+StringUtils.isNull(e.getCode())); - if (StringUtils.isNull(e.getCode())) - { + public AjaxResult UserDefinedException(ErrorCodeException e) { + System.out.println("StringUtils.isNull(e.getCode()):" + StringUtils.isNull(e.getCode())); + if (StringUtils.isNull(e.getCode())) { return AjaxResult.error(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) - public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) - { + public AjaxResult handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage()); return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权"); @@ -62,8 +70,7 @@ public class GlobalExceptionHandler */ @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, - HttpServletRequest request) - { + HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); return AjaxResult.error(e.getMessage()); @@ -73,8 +80,7 @@ public class GlobalExceptionHandler * 业务异常 */ @ExceptionHandler(ServiceException.class) - public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) - { + public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) { log.error(e.getMessage(), e); Integer code = e.getCode(); return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); @@ -84,8 +90,7 @@ public class GlobalExceptionHandler * 请求路径中缺少必需的路径变量 */ @ExceptionHandler(MissingPathVariableException.class) - public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) - { + public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e); return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName())); @@ -95,12 +100,10 @@ public class GlobalExceptionHandler * 请求参数类型不匹配 */ @ExceptionHandler(MethodArgumentTypeMismatchException.class) - public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) - { + public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); String value = Convert.toStr(e.getValue()); - if (StringUtils.isNotEmpty(value)) - { + if (StringUtils.isNotEmpty(value)) { value = EscapeUtil.clean(value); } log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e); @@ -111,8 +114,7 @@ public class GlobalExceptionHandler * 拦截未知的运行时异常 */ @ExceptionHandler(RuntimeException.class) - public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) - { + public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("请求地址'{}',发生未知异常.", requestURI, e); return AjaxResult.error(e.getMessage()); @@ -122,8 +124,7 @@ public class GlobalExceptionHandler * 系统异常 */ @ExceptionHandler(Exception.class) - public AjaxResult handleException(Exception e, HttpServletRequest request) - { + public AjaxResult handleException(Exception e, HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("请求地址'{}',发生系统异常.", requestURI, e); return AjaxResult.error(e.getMessage()); @@ -133,8 +134,7 @@ public class GlobalExceptionHandler * 自定义验证异常 */ @ExceptionHandler(BindException.class) - public AjaxResult handleBindException(BindException e) - { + public AjaxResult handleBindException(BindException e) { log.error(e.getMessage(), e); String message = e.getAllErrors().get(0).getDefaultMessage(); return AjaxResult.error(message); @@ -144,8 +144,7 @@ public class GlobalExceptionHandler * 自定义验证异常 */ @ExceptionHandler(MethodArgumentNotValidException.class) - public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) - { + public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { log.error(e.getMessage(), e); String message = e.getBindingResult().getFieldError().getDefaultMessage(); return AjaxResult.error(message); @@ -155,8 +154,7 @@ public class GlobalExceptionHandler * 演示模式异常 */ @ExceptionHandler(DemoModeException.class) - public AjaxResult handleDemoModeException(DemoModeException e) - { + public AjaxResult handleDemoModeException(DemoModeException e) { return AjaxResult.error("演示模式,不允许操作"); } } diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java index a36ec3f..ce887ba 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java @@ -4,6 +4,9 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + +import com.mcwl.common.exception.ServiceException; +import io.lettuce.core.RedisCommandTimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/EarningsDisplayDto.java b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/EarningsDisplayDto.java index 50e6ec7..1ad4634 100644 --- a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/EarningsDisplayDto.java +++ b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/EarningsDisplayDto.java @@ -1,13 +1,18 @@ package com.mcwl.myInvitation.domain.dto; import com.mcwl.common.core.domain.entity.SysUser; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data +@ApiModel(value = "被邀请者信息") public class EarningsDisplayDto { - private SysUser user; + @ApiModelProperty("被邀请人") + private SysUserDto user; + @ApiModelProperty("购买商品数") private Integer count; } diff --git a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/SysUserDto.java b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/SysUserDto.java new file mode 100644 index 0000000..a28d128 --- /dev/null +++ b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/dto/SysUserDto.java @@ -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; +} diff --git a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/vo/EarningsDisplayVO.java b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/vo/EarningsDisplayVO.java index 5bfd883..b93fba8 100644 --- a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/vo/EarningsDisplayVO.java +++ b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/domain/vo/EarningsDisplayVO.java @@ -2,20 +2,29 @@ package com.mcwl.myInvitation.domain.vo; import com.mcwl.myInvitation.domain.dto.EarningsDisplay; 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.NoArgsConstructor; import java.util.List; @Data +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value = "邀请人收益展示") public class EarningsDisplayVO { /** - * 总金额 + * 收益总额 */ + @ApiModelProperty("收益总额") private Double totalAmount; /** - * 提成列表 + * 邀请列表 */ + @ApiModelProperty("邀请列表") private List earningsDisplayList; } diff --git a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/service/impl/InvitationServiceImpl.java b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/service/impl/InvitationServiceImpl.java index 41c762e..f8b4fde 100644 --- a/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/service/impl/InvitationServiceImpl.java +++ b/mcwl-myInvitation/src/main/java/com/mcwl/myInvitation/service/impl/InvitationServiceImpl.java @@ -1,10 +1,13 @@ package com.mcwl.myInvitation.service.impl; +import cn.hutool.core.bean.BeanUtil; 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.myInvitation.domain.Invitation; import com.mcwl.myInvitation.domain.dto.EarningsDisplay; import com.mcwl.myInvitation.domain.dto.EarningsDisplayDto; +import com.mcwl.myInvitation.domain.dto.SysUserDto; import com.mcwl.myInvitation.mapper.InvitationMapper; import com.mcwl.myInvitation.service.ConsumeService; import com.mcwl.myInvitation.service.InvitationService; @@ -45,7 +48,8 @@ public class InvitationServiceImpl extends ServiceImpl list = new ArrayList<>(); earningsDisplay.forEach(item -> { 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()); list.add(edd); }); diff --git a/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java b/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java index f26bdc9..ad5f4b5 100644 --- a/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java +++ b/mcwl-pay/src/main/java/com/mcwl/pay/service/impl/OrderTradeServiceImpl.java @@ -209,6 +209,7 @@ public class OrderTradeServiceImpl extends ServiceImpl