Browse Source

去掉用户类型。

master
刘忱 2 years ago
parent
commit
5c087f25a8
  1. 40
      win-framework/win-common/src/main/java/com/win/framework/common/enums/TerminalEnum.java
  2. 39
      win-framework/win-common/src/main/java/com/win/framework/common/enums/UserTypeEnum.java
  3. 8
      win-framework/win-spring-boot-starter-biz-data-permission/src/main/java/com/win/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java
  4. 8
      win-framework/win-spring-boot-starter-biz-operatelog/src/main/java/com/win/framework/operatelog/core/aop/OperateLogAspect.java
  5. 4
      win-framework/win-spring-boot-starter-biz-operatelog/src/main/java/com/win/framework/operatelog/core/service/OperateLog.java
  6. 4
      win-framework/win-spring-boot-starter-biz-tenant/src/main/java/com/win/framework/tenant/core/security/TenantSecurityWebFilter.java
  7. 2
      win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java
  8. 7
      win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/LoginUser.java
  9. 21
      win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/filter/TokenAuthenticationFilter.java
  10. 1
      win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/util/SecurityFrameworkUtils.java
  11. 1
      win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/filter/ApiAccessLogFilter.java
  12. 4
      win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/service/ApiAccessLog.java
  13. 4
      win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/service/ApiErrorLog.java
  14. 1
      win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/handler/GlobalExceptionHandler.java
  15. 39
      win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/WebFrameworkUtils.java
  16. 4
      win-module-infra/win-module-infra-api/src/main/java/com/win/module/infra/api/logger/dto/ApiAccessLogCreateReqDTO.java
  17. 4
      win-module-infra/win-module-infra-api/src/main/java/com/win/module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
  18. 4
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java
  19. 7
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java
  20. 3
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java
  21. 3
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogPageReqVO.java
  22. 4
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogBaseVO.java
  23. 4
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogExcelVO.java
  24. 3
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java
  25. 3
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogPageReqVO.java
  26. 7
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/dataobject/logger/ApiAccessLogDO.java
  27. 7
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/dataobject/logger/ApiErrorLogDO.java
  28. 2
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/mysql/logger/ApiAccessLogMapper.java
  29. 2
      win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/mysql/logger/ApiErrorLogMapper.java
  30. 3
      win-module-report/win-module-report-biz/src/main/java/com/win/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java
  31. 5
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/logger/dto/LoginLogCreateReqDTO.java
  32. 6
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/logger/dto/OperateLogCreateReqDTO.java
  33. 10
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/mail/MailSendApi.java
  34. 4
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java
  35. 8
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenCreateReqDTO.java
  36. 4
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenRespDTO.java
  37. 10
      win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/sms/SmsSendApi.java
  38. 6
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/mail/MailSendApiImpl.java
  39. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/oauth2/OAuth2TokenApiImpl.java
  40. 6
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/sms/SmsSendApiImpl.java
  41. 5
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/logger/vo/loginlog/LoginLogRespVO.java
  42. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/mail/vo/log/MailLogBaseVO.java
  43. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/mail/vo/log/MailLogPageReqVO.java
  44. 13
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/NotifyMessageController.java
  45. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/vo/message/NotifyMessageBaseVO.java
  46. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/vo/message/NotifyMessagePageReqVO.java
  47. 16
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/OAuth2OpenController.java
  48. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java
  49. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/token/OAuth2AccessTokenPageReqVO.java
  50. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/token/OAuth2AccessTokenRespVO.java
  51. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/sms/vo/log/SmsLogExcelVO.java
  52. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/sms/vo/log/SmsLogRespVO.java
  53. 2
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/oauth2/OAuth2OpenConvert.java
  54. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/logger/LoginLogDO.java
  55. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/logger/OperateLogDO.java
  56. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/mail/MailLogDO.java
  57. 9
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/notify/NotifyMessageDO.java
  58. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java
  59. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2ApproveDO.java
  60. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2CodeDO.java
  61. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java
  62. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/sms/SmsLogDO.java
  63. 1
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/mail/MailLogMapper.java
  64. 18
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/notify/NotifyMessageMapper.java
  65. 1
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java
  66. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/oauth2/OAuth2ApproveMapper.java
  67. 23
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java
  68. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailLogService.java
  69. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailLogServiceImpl.java
  70. 16
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailSendService.java
  71. 22
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailSendServiceImpl.java
  72. 26
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/MemberService.java
  73. 54
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/MemberServiceImpl.java
  74. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/package-info.java
  75. 19
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifyMessageService.java
  76. 27
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifyMessageServiceImpl.java
  77. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifySendService.java
  78. 11
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifySendServiceImpl.java
  79. 9
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2ApproveService.java
  80. 21
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2ApproveServiceImpl.java
  81. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2CodeService.java
  82. 6
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2CodeServiceImpl.java
  83. 9
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2GrantService.java
  84. 18
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2GrantServiceImpl.java
  85. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2TokenService.java
  86. 11
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2TokenServiceImpl.java
  87. 3
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsCodeServiceImpl.java
  88. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsLogService.java
  89. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsLogServiceImpl.java
  90. 21
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsSendService.java
  91. 23
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsSendServiceImpl.java
  92. 2
      win-server/src/main/resources/application-test.yaml
  93. 1
      win-server/src/main/resources/application.yaml

40
win-framework/win-common/src/main/java/com/win/framework/common/enums/TerminalEnum.java

@ -1,40 +0,0 @@
package com.win.framework.common.enums;
import com.win.framework.common.core.IntArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* 终端的枚举
*
* @author 闻荫源码
*/
@RequiredArgsConstructor
@Getter
public enum TerminalEnum implements IntArrayValuable {
WECHAT_MINI_PROGRAM(10, "微信小程序"),
WECHAT_WAP(11, "微信公众号"),
H5(20, "H5 网页"),
IOS(31, "苹果 App"),
ANDROID(32, "安卓 App"),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TerminalEnum::getTerminal).toArray();
/**
* 终端
*/
private final Integer terminal;
/**
* 终端名
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

39
win-framework/win-common/src/main/java/com/win/framework/common/enums/UserTypeEnum.java

@ -1,39 +0,0 @@
package com.win.framework.common.enums;
import cn.hutool.core.util.ArrayUtil;
import com.win.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 全局用户类型枚举
*/
@AllArgsConstructor
@Getter
public enum UserTypeEnum implements IntArrayValuable {
MEMBER(1, "会员"), // 面向 c 端,普通用户
ADMIN(2, "管理员"); // 面向 b 端,管理后台
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserTypeEnum::getValue).toArray();
/**
* 类型
*/
private final Integer value;
/**
* 类型名
*/
private final String name;
public static UserTypeEnum valueOf(Integer value) {
return ArrayUtil.firstMatch(userType -> userType.getValue().equals(value), UserTypeEnum.values());
}
@Override
public int[] array() {
return ARRAYS;
}
}

8
win-framework/win-spring-boot-starter-biz-data-permission/src/main/java/com/win/framework/datapermission/core/rule/dept/DeptDataPermissionRule.java

@ -1,9 +1,8 @@
package com.win.framework.datapermission.core.rule.dept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.win.framework.common.util.collection.CollectionUtils;
import com.win.framework.common.util.json.JsonUtils;
import com.win.framework.datapermission.core.rule.DataPermissionRule;
@ -13,7 +12,6 @@ import com.win.framework.security.core.LoginUser;
import com.win.framework.security.core.util.SecurityFrameworkUtils;
import com.win.module.system.api.permission.PermissionApi;
import com.win.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.*;
@ -93,10 +91,6 @@ public class DeptDataPermissionRule implements DataPermissionRule {
if (loginUser == null) {
return null;
}
// 只有管理员类型的用户,才进行数据权限的处理
if (ObjectUtil.notEqual(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue())) {
return null;
}
// 获得数据权限
DeptDataPermissionRespDTO deptDataPermission = loginUser.getContext(CONTEXT_KEY, DeptDataPermissionRespDTO.class);

8
win-framework/win-spring-boot-starter-biz-operatelog/src/main/java/com/win/framework/operatelog/core/aop/OperateLogAspect.java

@ -4,7 +4,6 @@ import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.common.util.json.JsonUtils;
import com.win.framework.common.util.monitor.TracerUtils;
@ -88,12 +87,6 @@ public class OperateLogAspect {
private Object around0(ProceedingJoinPoint joinPoint,
com.win.framework.operatelog.core.annotations.OperateLog operateLog,
Operation operation) throws Throwable {
// 目前,只有管理员,才记录操作日志!所以非管理员,直接调用,不进行记录
Integer userType = WebFrameworkUtils.getLoginUserType();
if (!Objects.equals(userType, UserTypeEnum.ADMIN.getValue())) {
return joinPoint.proceed();
}
// 记录开始时间
LocalDateTime startTime = LocalDateTime.now();
try {
@ -166,7 +159,6 @@ public class OperateLogAspect {
private static void fillUserFields(OperateLog operateLogObj) {
operateLogObj.setUserId(WebFrameworkUtils.getLoginUserId());
operateLogObj.setUserType(WebFrameworkUtils.getLoginUserType());
}
private static void fillModuleFields(OperateLog operateLogObj,

4
win-framework/win-spring-boot-starter-biz-operatelog/src/main/java/com/win/framework/operatelog/core/service/OperateLog.java

@ -22,10 +22,6 @@ public class OperateLog {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 操作模块

4
win-framework/win-spring-boot-starter-biz-tenant/src/main/java/com/win/framework/tenant/core/security/TenantSecurityWebFilter.java

@ -64,8 +64,8 @@ public class TenantSecurityWebFilter extends ApiRequestFilter {
TenantContextHolder.setTenantId(tenantId);
// 如果传递了租户编号,则进行比对租户编号,避免越权问题
} else if (!Objects.equals(user.getTenantId(), TenantContextHolder.getTenantId())) {
log.error("[doFilterInternal][租户({}) User({}/{}) 越权访问租户({}) URL({}/{})]",
user.getTenantId(), user.getId(), user.getUserType(),
log.error("[doFilterInternal][租户({}) User({}/{}) 越权访问租户({}) URL({})]",
user.getTenantId(), user.getId(),
TenantContextHolder.getTenantId(), request.getRequestURI(), request.getMethod());
ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.FORBIDDEN.getCode(),
"您无权访问该租户的数据"));

2
win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java

@ -117,7 +117,7 @@ public class WinWebSecurityConfigurerAdapter {
// ①:全局共享规则
.authorizeRequests()
// 1.1 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/favicon.ico").permitAll()
// 1.2 设置 @PermitAll 无需认证
.antMatchers(HttpMethod.GET, permitAllUrls.get(HttpMethod.GET).toArray(new String[0])).permitAll()
.antMatchers(HttpMethod.POST, permitAllUrls.get(HttpMethod.POST).toArray(new String[0])).permitAll()

7
win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/LoginUser.java

@ -1,7 +1,6 @@
package com.win.framework.security.core;
import cn.hutool.core.map.MapUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
@ -21,12 +20,6 @@ public class LoginUser {
* 用户编号
*/
private Long id;
/**
* 用户类型
*
* 关联 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 租户编号
*/

21
win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/filter/TokenAuthenticationFilter.java

@ -1,6 +1,5 @@
package com.win.framework.security.core.filter;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.exception.ServiceException;
import com.win.framework.common.pojo.CommonResult;
@ -13,7 +12,6 @@ import com.win.framework.web.core.util.WebFrameworkUtils;
import com.win.module.system.api.oauth2.OAuth2TokenApi;
import com.win.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
@ -43,13 +41,12 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
throws ServletException, IOException {
String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader());
if (StrUtil.isNotEmpty(token)) {
Integer userType = WebFrameworkUtils.getLoginUserType(request);
try {
// 1.1 基于 token 构建登录用户
LoginUser loginUser = buildLoginUserByToken(token, userType);
LoginUser loginUser = buildLoginUserByToken(token);
// 1.2 模拟 Login 功能,方便日常开发调试
if (loginUser == null) {
loginUser = mockLoginUser(request, token, userType);
loginUser = mockLoginUser(request, token);
}
// 2. 设置当前用户
@ -67,18 +64,14 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
chain.doFilter(request, response);
}
private LoginUser buildLoginUserByToken(String token, Integer userType) {
private LoginUser buildLoginUserByToken(String token) {
try {
OAuth2AccessTokenCheckRespDTO accessToken = oauth2TokenApi.checkAccessToken(token);
if (accessToken == null) {
return null;
}
// 用户类型不匹配,无权限
if (ObjectUtil.notEqual(accessToken.getUserType(), userType)) {
throw new AccessDeniedException("错误的用户类型");
}
// 构建登录用户
return new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
return new LoginUser().setId(accessToken.getUserId())
.setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
} catch (ServiceException serviceException) {
// 校验 Token 不通过时,考虑到一些接口是无需登录的,所以直接返回 null 即可
@ -93,10 +86,9 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
*
* @param request 请求
* @param token 模拟的 token格式为 {@link SecurityProperties#getMockSecret()} + 用户编号
* @param userType 用户类型
* @return 模拟的 LoginUser
*/
private LoginUser mockLoginUser(HttpServletRequest request, String token, Integer userType) {
private LoginUser mockLoginUser(HttpServletRequest request, String token) {
if (!securityProperties.getMockEnable()) {
return null;
}
@ -106,8 +98,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
}
// 构建模拟用户
Long userId = Long.valueOf(token.substring(securityProperties.getMockSecret().length()));
return new LoginUser().setId(userId).setUserType(userType)
.setTenantId(WebFrameworkUtils.getTenantId(request));
return new LoginUser().setId(userId).setTenantId(WebFrameworkUtils.getTenantId(request));
}
}

1
win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/core/util/SecurityFrameworkUtils.java

@ -95,7 +95,6 @@ public class SecurityFrameworkUtils {
// 额外设置到 request 中,用于 ApiAccessLogFilter 可以获取到用户编号;
// 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息
WebFrameworkUtils.setLoginUserId(request, loginUser.getId());
WebFrameworkUtils.setLoginUserType(request, loginUser.getUserType());
}
private static Authentication buildAuthentication(LoginUser loginUser, HttpServletRequest request) {

1
win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/filter/ApiAccessLogFilter.java

@ -79,7 +79,6 @@ public class ApiAccessLogFilter extends ApiRequestFilter {
Map<String, String> queryString, String requestBody, Exception ex) {
// 处理用户信息
accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
accessLog.setUserType(WebFrameworkUtils.getLoginUserType(request));
// 设置访问结果
CommonResult<?> result = WebFrameworkUtils.getCommonResult(request);
if (result != null) {

4
win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/service/ApiAccessLog.java

@ -21,10 +21,6 @@ public class ApiAccessLog {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 应用名
*/

4
win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/apilog/core/service/ApiErrorLog.java

@ -21,10 +21,6 @@ public class ApiErrorLog {
* 账号编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 应用名
*/

1
win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/handler/GlobalExceptionHandler.java

@ -251,7 +251,6 @@ public class GlobalExceptionHandler {
private void initExceptionLog(ApiErrorLog errorLog, HttpServletRequest request, Throwable e) {
// 处理用户信息
errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
errorLog.setUserType(WebFrameworkUtils.getLoginUserType(request));
// 设置异常字段
errorLog.setExceptionName(e.getClass().getName());
errorLog.setExceptionMessage(ExceptionUtil.getMessage(e));

39
win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/WebFrameworkUtils.java

@ -1,7 +1,6 @@
package com.win.framework.web.core.util;
import cn.hutool.core.util.NumberUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.web.config.WebProperties;
import org.springframework.web.context.request.RequestAttributes;
@ -47,16 +46,6 @@ public class WebFrameworkUtils {
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId);
}
/**
* 设置用户类型
*
* @param request 请求
* @param userType 用户类型
*/
public static void setLoginUserType(ServletRequest request, Integer userType) {
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE, userType);
}
/**
* 获得当前用户的编号从请求中
* 注意该方法仅限于 framework 框架使用
@ -71,34 +60,6 @@ public class WebFrameworkUtils {
return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID);
}
/**
* 获得当前用户的类型
* 注意该方法仅限于 web 相关的 framework 组件使用
*
* @param request 请求
* @return 用户编号
*/
public static Integer getLoginUserType(HttpServletRequest request) {
if (request == null) {
return null;
}
// 1. 优先,从 Attribute 中获取
Integer userType = (Integer) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE);
if (userType != null) {
return userType;
}
// 2. 其次,基于 URL 前缀的约定
if (request.getServletPath().startsWith(properties.getAdminApi().getPrefix())) {
return UserTypeEnum.ADMIN.getValue();
}
return null;
}
public static Integer getLoginUserType() {
HttpServletRequest request = getRequest();
return getLoginUserType(request);
}
public static Long getLoginUserId() {
HttpServletRequest request = getRequest();
return getLoginUserId(request);

4
win-module-infra/win-module-infra-api/src/main/java/com/win/module/infra/api/logger/dto/ApiAccessLogCreateReqDTO.java

@ -21,10 +21,6 @@ public class ApiAccessLogCreateReqDTO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 应用名
*/

4
win-module-infra/win-module-infra-api/src/main/java/com/win/module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java

@ -21,10 +21,6 @@ public class ApiErrorLogCreateReqDTO {
* 账号编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 应用名
*/

4
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogBaseVO.java

@ -24,10 +24,6 @@ public class ApiAccessLogBaseVO {
@NotNull(message = "用户编号不能为空")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "用户类型不能为空")
private Integer userType;
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard")
@NotNull(message = "应用名不能为空")
private String applicationName;

7
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogExcelVO.java

@ -1,8 +1,5 @@
package com.win.module.infra.controller.logger.vo.apiaccesslog;
import com.win.framework.excel.core.annotations.DictFormat;
import com.win.framework.excel.core.convert.DictConvert;
import com.win.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@ -25,10 +22,6 @@ public class ApiAccessLogExcelVO {
@ExcelProperty("用户编号")
private Long userId;
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.USER_TYPE)
private Integer userType;
@ExcelProperty("应用名")
private String applicationName;

3
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogExportReqVO.java

@ -15,9 +15,6 @@ public class ApiAccessLogExportReqVO {
@Schema(description = "用户编号", example = "666")
private Long userId;
@Schema(description = "用户类型", example = "2")
private Integer userType;
@Schema(description = "应用名", example = "dashboard")
private String applicationName;

3
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apiaccesslog/ApiAccessLogPageReqVO.java

@ -20,9 +20,6 @@ public class ApiAccessLogPageReqVO extends PageParam {
@Schema(description = "用户编号", example = "666")
private Long userId;
@Schema(description = "用户类型", example = "2")
private Integer userType;
@Schema(description = "应用名", example = "dashboard")
private String applicationName;

4
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogBaseVO.java

@ -23,10 +23,6 @@ public class ApiErrorLogBaseVO {
@NotNull(message = "用户编号不能为空")
private Integer userId;
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "用户类型不能为空")
private Integer userType;
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "dashboard")
@NotNull(message = "应用名不能为空")
private String applicationName;

4
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogExcelVO.java

@ -25,10 +25,6 @@ public class ApiErrorLogExcelVO {
@ExcelProperty("用户编号")
private Integer userId;
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(com.win.module.system.enums.DictTypeConstants.USER_TYPE)
private Integer userType;
@ExcelProperty("应用名")
private String applicationName;

3
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogExportReqVO.java

@ -15,9 +15,6 @@ public class ApiErrorLogExportReqVO {
@Schema(description = "用户编号", example = "666")
private Long userId;
@Schema(description = "用户类型", example = "1")
private Integer userType;
@Schema(description = "应用名", example = "dashboard")
private String applicationName;

3
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/controller/logger/vo/apierrorlog/ApiErrorLogPageReqVO.java

@ -20,9 +20,6 @@ public class ApiErrorLogPageReqVO extends PageParam {
@Schema(description = "用户编号", example = "666")
private Long userId;
@Schema(description = "用户类型", example = "1")
private Integer userType;
@Schema(description = "应用名", example = "dashboard")
private String applicationName;

7
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/dataobject/logger/ApiAccessLogDO.java

@ -1,6 +1,5 @@
package com.win.module.infra.dal.dataobject.logger;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
@ -40,12 +39,6 @@ public class ApiAccessLogDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 应用名
*

7
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/dataobject/logger/ApiErrorLogDO.java

@ -1,6 +1,5 @@
package com.win.module.infra.dal.dataobject.logger;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.module.infra.enums.logger.ApiErrorLogProcessStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
@ -40,12 +39,6 @@ public class ApiErrorLogDO extends BaseDO {
* 一般来说通过链路追踪编号可以将访问日志错误日志链路追踪日志logger 打印日志等结合在一起从而进行排错
*/
private String traceId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 应用名
*

2
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/mysql/logger/ApiAccessLogMapper.java

@ -21,7 +21,6 @@ public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
default PageResult<ApiAccessLogDO> selectPage(ApiAccessLogPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ApiAccessLogDO>()
.eqIfPresent(ApiAccessLogDO::getUserId, reqVO.getUserId())
.eqIfPresent(ApiAccessLogDO::getUserType, reqVO.getUserType())
.eqIfPresent(ApiAccessLogDO::getApplicationName, reqVO.getApplicationName())
.likeIfPresent(ApiAccessLogDO::getRequestUrl, reqVO.getRequestUrl())
.betweenIfPresent(ApiAccessLogDO::getBeginTime, reqVO.getBeginTime())
@ -34,7 +33,6 @@ public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
default List<ApiAccessLogDO> selectList(ApiAccessLogExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ApiAccessLogDO>()
.eqIfPresent(ApiAccessLogDO::getUserId, reqVO.getUserId())
.eqIfPresent(ApiAccessLogDO::getUserType, reqVO.getUserType())
.eqIfPresent(ApiAccessLogDO::getApplicationName, reqVO.getApplicationName())
.likeIfPresent(ApiAccessLogDO::getRequestUrl, reqVO.getRequestUrl())
.betweenIfPresent(ApiAccessLogDO::getBeginTime, reqVO.getBeginTime())

2
win-module-infra/win-module-infra-biz/src/main/java/com/win/module/infra/dal/mysql/logger/ApiErrorLogMapper.java

@ -21,7 +21,6 @@ public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {
default PageResult<ApiErrorLogDO> selectPage(ApiErrorLogPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ApiErrorLogDO>()
.eqIfPresent(ApiErrorLogDO::getUserId, reqVO.getUserId())
.eqIfPresent(ApiErrorLogDO::getUserType, reqVO.getUserType())
.eqIfPresent(ApiErrorLogDO::getApplicationName, reqVO.getApplicationName())
.likeIfPresent(ApiErrorLogDO::getRequestUrl, reqVO.getRequestUrl())
.betweenIfPresent(ApiErrorLogDO::getExceptionTime, reqVO.getExceptionTime())
@ -33,7 +32,6 @@ public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLogDO> {
default List<ApiErrorLogDO> selectList(ApiErrorLogExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ApiErrorLogDO>()
.eqIfPresent(ApiErrorLogDO::getUserId, reqVO.getUserId())
.eqIfPresent(ApiErrorLogDO::getUserType, reqVO.getUserType())
.eqIfPresent(ApiErrorLogDO::getApplicationName, reqVO.getApplicationName())
.likeIfPresent(ApiErrorLogDO::getRequestUrl, reqVO.getRequestUrl())
.betweenIfPresent(ApiErrorLogDO::getExceptionTime, reqVO.getExceptionTime())

3
win-module-report/win-module-report-biz/src/main/java/com/win/module/report/framework/jmreport/core/service/JmReportTokenServiceImpl.java

@ -111,8 +111,7 @@ public class JmReportTokenServiceImpl implements JmReportTokenServiceI {
if (accessToken == null) {
return null;
}
user = new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
.setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
user = new LoginUser().setId(accessToken.getUserId()).setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes());
} catch (ServiceException ignored) {
// do nothing:如果报错,说明认证失败,则返回 false 即可
}

5
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/logger/dto/LoginLogCreateReqDTO.java

@ -29,11 +29,6 @@ public class LoginLogCreateReqDTO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
@NotNull(message = "用户类型不能为空")
private Integer userType;
/**
* 用户账号
*/

6
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/logger/dto/OperateLogCreateReqDTO.java

@ -23,12 +23,6 @@ public class OperateLogCreateReqDTO {
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 用户类型
*/
@NotNull(message = "用户类型不能为空")
private Integer userType;
/**
* 操作模块
*/

10
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/mail/MailSendApi.java

@ -21,14 +21,4 @@ public interface MailSendApi {
*/
Long sendSingleMailToAdmin(@Valid MailSendSingleToUserReqDTO reqDTO);
/**
* 发送单条邮箱给 Member 用户
*
* mail 为空时使用 userId 加载对应 Member 的邮箱
*
* @param reqDTO 发送请求
* @return 发送日志编号
*/
Long sendSingleMailToMember(@Valid MailSendSingleToUserReqDTO reqDTO);
}

4
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java

@ -17,10 +17,6 @@ public class OAuth2AccessTokenCheckRespDTO implements Serializable {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 租户编号
*/

8
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenCreateReqDTO.java

@ -1,7 +1,5 @@
package com.win.module.system.api.oauth2.dto;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.validation.InEnum;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ -21,12 +19,6 @@ public class OAuth2AccessTokenCreateReqDTO implements Serializable {
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
/**
* 用户类型
*/
@NotNull(message = "用户类型不能为空")
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
private Integer userType;
/**
* 客户端编号
*/

4
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/oauth2/dto/OAuth2AccessTokenRespDTO.java

@ -27,10 +27,6 @@ public class OAuth2AccessTokenRespDTO implements Serializable {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*/
private Integer userType;
/**
* 过期时间
*/

10
win-module-system/win-module-system-api/src/main/java/com/win/module/system/api/sms/SmsSendApi.java

@ -21,14 +21,4 @@ public interface SmsSendApi {
*/
Long sendSingleSmsToAdmin(@Valid SmsSendSingleToUserReqDTO reqDTO);
/**
* 发送单条短信给 Member 用户
*
* mobile 为空时使用 userId 加载对应 Member 的手机号
*
* @param reqDTO 发送请求
* @return 发送日志编号
*/
Long sendSingleSmsToMember(@Valid SmsSendSingleToUserReqDTO reqDTO);
}

6
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/mail/MailSendApiImpl.java

@ -25,10 +25,4 @@ public class MailSendApiImpl implements MailSendApi {
reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
}
@Override
public Long sendSingleMailToMember(MailSendSingleToUserReqDTO reqDTO) {
return mailSendService.sendSingleMailToMember(reqDTO.getMail(), reqDTO.getUserId(),
reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
}
}

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/oauth2/OAuth2TokenApiImpl.java

@ -23,8 +23,7 @@ public class OAuth2TokenApiImpl implements OAuth2TokenApi {
@Override
public OAuth2AccessTokenRespDTO createAccessToken(OAuth2AccessTokenCreateReqDTO reqDTO) {
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(
reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes());
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(reqDTO.getUserId(), reqDTO.getClientId(), reqDTO.getScopes());
return OAuth2TokenConvert.INSTANCE.convert2(accessTokenDO);
}

6
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/api/sms/SmsSendApiImpl.java

@ -25,10 +25,4 @@ public class SmsSendApiImpl implements SmsSendApi {
reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
}
@Override
public Long sendSingleSmsToMember(SmsSendSingleToUserReqDTO reqDTO) {
return smsSendService.sendSingleSmsToMember(reqDTO.getMobile(), reqDTO.getUserId(),
reqDTO.getTemplateCode(), reqDTO.getTemplateParams());
}
}

5
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/logger/vo/loginlog/LoginLogRespVO.java

@ -5,7 +5,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 登录日志 Response VO")
@ -20,10 +19,6 @@ public class LoginLogRespVO extends LoginLogBaseVO {
@Schema(description = "用户编号", example = "666")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "用户类型不能为空")
private Integer userType;
@Schema(description = "登录时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/mail/vo/log/MailLogBaseVO.java

@ -20,9 +20,6 @@ public class MailLogBaseVO {
@Schema(description = "用户编号", example = "30883")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2")
private Byte userType;
@Schema(description = "接收邮箱地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "76854@qq.com")
@NotNull(message = "接收邮箱地址不能为空")
private String toMail;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/mail/vo/log/MailLogPageReqVO.java

@ -20,9 +20,6 @@ public class MailLogPageReqVO extends PageParam {
@Schema(description = "用户编号", example = "30883")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", example = "2")
private Integer userType;
@Schema(description = "接收邮箱地址,模糊匹配", example = "76854@qq.com")
private String toMail;

13
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/NotifyMessageController.java

@ -1,6 +1,5 @@
package com.win.module.system.controller.notify;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.common.pojo.PageResult;
import com.win.module.system.controller.notify.vo.message.NotifyMessageMyPageReqVO;
@ -56,8 +55,7 @@ public class NotifyMessageController {
@GetMapping("/my-page")
@Operation(summary = "获得我的站内信分页")
public CommonResult<PageResult<NotifyMessageRespVO>> getMyMyNotifyMessagePage(@Valid NotifyMessageMyPageReqVO pageVO) {
PageResult<NotifyMessageDO> pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO,
getLoginUserId(), UserTypeEnum.ADMIN.getValue());
PageResult<NotifyMessageDO> pageResult = notifyMessageService.getMyMyNotifyMessagePage(pageVO, getLoginUserId());
return success(NotifyMessageConvert.INSTANCE.convertPage(pageResult));
}
@ -65,14 +63,14 @@ public class NotifyMessageController {
@Operation(summary = "标记站内信为已读")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
public CommonResult<Boolean> updateNotifyMessageRead(@RequestParam("ids") List<Long> ids) {
notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId(), UserTypeEnum.ADMIN.getValue());
notifyMessageService.updateNotifyMessageRead(ids, getLoginUserId());
return success(Boolean.TRUE);
}
@PutMapping("/update-all-read")
@Operation(summary = "标记所有站内信为已读")
public CommonResult<Boolean> updateAllNotifyMessageRead() {
notifyMessageService.updateAllNotifyMessageRead(getLoginUserId(), UserTypeEnum.ADMIN.getValue());
notifyMessageService.updateAllNotifyMessageRead(getLoginUserId());
return success(Boolean.TRUE);
}
@ -81,15 +79,14 @@ public class NotifyMessageController {
@Parameter(name = "size", description = "10")
public CommonResult<List<NotifyMessageRespVO>> getUnreadNotifyMessageList(
@RequestParam(name = "size", defaultValue = "10") Integer size) {
List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(
getLoginUserId(), UserTypeEnum.ADMIN.getValue(), size);
List<NotifyMessageDO> list = notifyMessageService.getUnreadNotifyMessageList(getLoginUserId(), size);
return success(NotifyMessageConvert.INSTANCE.convertList(list));
}
@GetMapping("/get-unread-count")
@Operation(summary = "获得当前用户的未读站内信数量")
public CommonResult<Long> getUnreadNotifyMessageCount() {
return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId(), UserTypeEnum.ADMIN.getValue()));
return success(notifyMessageService.getUnreadNotifyMessageCount(getLoginUserId()));
}
}

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/vo/message/NotifyMessageBaseVO.java

@ -21,10 +21,6 @@ public class NotifyMessageBaseVO {
@NotNull(message = "用户编号不能为空")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "用户类型不能为空")
private Byte userType;
@Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13013")
@NotNull(message = "模版编号不能为空")
private Long templateId;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/notify/vo/message/NotifyMessagePageReqVO.java

@ -20,9 +20,6 @@ public class NotifyMessagePageReqVO extends PageParam {
@Schema(description = "用户编号", example = "25025")
private Long userId;
@Schema(description = "用户类型", example = "1")
private Integer userType;
@Schema(description = "模板编码", example = "test_01")
private String templateCode;

16
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/OAuth2OpenController.java

@ -4,7 +4,6 @@ import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.common.util.http.HttpUtils;
import com.win.framework.common.util.json.JsonUtils;
@ -191,7 +190,7 @@ public class OAuth2OpenController {
// 1. 获得 Client 客户端的信息
OAuth2ClientDO client = oauth2ClientService.validOAuthClientFromCache(clientId);
// 2. 获得用户已经授权的信息
List<OAuth2ApproveDO> approves = oauth2ApproveService.getApproveList(getLoginUserId(), getUserType(), clientId);
List<OAuth2ApproveDO> approves = oauth2ApproveService.getApproveList(getLoginUserId(), clientId);
// 拼接返回
return success(OAuth2OpenConvert.INSTANCE.convert(client, approves));
}
@ -237,12 +236,12 @@ public class OAuth2OpenController {
// 2.1 假设 approved 为 null,说明是场景一
if (Boolean.TRUE.equals(autoApprove)) {
// 如果无法自动授权通过,则返回空 url,前端不进行跳转
if (!oauth2ApproveService.checkForPreApproval(getLoginUserId(), getUserType(), clientId, scopes.keySet())) {
if (!oauth2ApproveService.checkForPreApproval(getLoginUserId(), clientId, scopes.keySet())) {
return success(null);
}
} else { // 2.2 假设 approved 非 null,说明是场景二
// 如果计算后不通过,则跳转一个错误链接
if (!oauth2ApproveService.updateAfterApproval(getLoginUserId(), getUserType(), clientId, scopes)) {
if (!oauth2ApproveService.updateAfterApproval(getLoginUserId(), clientId, scopes)) {
return success(OAuth2Utils.buildUnsuccessfulRedirect(redirectUri, responseType, state,
"access_denied", "User denied access"));
}
@ -270,7 +269,7 @@ public class OAuth2OpenController {
private String getImplicitGrantRedirect(Long userId, OAuth2ClientDO client,
List<String> scopes, String redirectUri, String state) {
// 1. 创建 access token 访问令牌
OAuth2AccessTokenDO accessTokenDO = oauth2GrantService.grantImplicit(userId, getUserType(), client.getClientId(), scopes);
OAuth2AccessTokenDO accessTokenDO = oauth2GrantService.grantImplicit(userId, client.getClientId(), scopes);
Assert.notNull(accessTokenDO, "访问令牌不能为空"); // 防御性检查
// 2. 拼接重定向的 URL
// noinspection unchecked
@ -281,16 +280,11 @@ public class OAuth2OpenController {
private String getAuthorizationCodeRedirect(Long userId, OAuth2ClientDO client,
List<String> scopes, String redirectUri, String state) {
// 1. 创建 code 授权码
String authorizationCode = oauth2GrantService.grantAuthorizationCodeForCode(userId, getUserType(), client.getClientId(), scopes,
redirectUri, state);
String authorizationCode = oauth2GrantService.grantAuthorizationCodeForCode(userId, client.getClientId(), scopes, redirectUri, state);
// 2. 拼接重定向的 URL
return OAuth2Utils.buildAuthorizationCodeRedirectUri(redirectUri, authorizationCode, state);
}
private Integer getUserType() {
return UserTypeEnum.ADMIN.getValue();
}
private String[] obtainBasicAuthorization(HttpServletRequest request) {
String[] clientIdAndSecret = HttpUtils.obtainBasicAuthorization(request);
if (ArrayUtil.isEmpty(clientIdAndSecret) || clientIdAndSecret.length != 2) {

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java

@ -17,9 +17,6 @@ public class OAuth2OpenCheckTokenRespVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
@JsonProperty("user_id")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@JsonProperty("user_type")
private Integer userType;
@Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@JsonProperty("tenant_id")
private Long tenantId;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/token/OAuth2AccessTokenPageReqVO.java

@ -13,9 +13,6 @@ public class OAuth2AccessTokenPageReqVO extends PageParam {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer userType;
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String clientId;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/oauth2/vo/token/OAuth2AccessTokenRespVO.java

@ -25,9 +25,6 @@ public class OAuth2AccessTokenRespVO {
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Long userId;
@Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer userType;
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private String clientId;

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/sms/vo/log/SmsLogExcelVO.java

@ -52,10 +52,6 @@ public class SmsLogExcelVO {
@ExcelProperty("用户编号")
private Long userId;
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.USER_TYPE)
private Integer userType;
@ExcelProperty(value = "发送状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.SMS_SEND_STATUS)
private Integer sendStatus;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/sms/vo/log/SmsLogRespVO.java

@ -43,9 +43,6 @@ public class SmsLogRespVO {
@Schema(description = "用户编号", example = "10")
private Long userId;
@Schema(description = "用户类型", example = "1")
private Integer userType;
@Schema(description = "发送状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer sendStatus;

2
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/convert/oauth2/OAuth2OpenConvert.java

@ -2,7 +2,6 @@ package com.win.module.system.convert.oauth2;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.win.framework.common.core.KeyValue;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.util.collection.CollectionUtils;
import com.win.framework.security.core.util.SecurityFrameworkUtils;
import com.win.module.system.controller.oauth2.vo.open.OAuth2OpenAccessTokenRespVO;
@ -36,7 +35,6 @@ public interface OAuth2OpenConvert {
default OAuth2OpenCheckTokenRespVO convert2(OAuth2AccessTokenDO bean) {
OAuth2OpenCheckTokenRespVO respVO = convert3(bean);
respVO.setExp(LocalDateTimeUtil.toEpochMilli(bean.getExpiresTime()) / 1000L);
respVO.setUserType(UserTypeEnum.ADMIN.getValue());
return respVO;
}
OAuth2OpenCheckTokenRespVO convert3(OAuth2AccessTokenDO bean);

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/logger/LoginLogDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.logger;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.module.system.enums.logger.LoginLogTypeEnum;
import com.win.module.system.enums.logger.LoginResultEnum;
@ -42,12 +41,6 @@ public class LoginLogDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 用户账号
*

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/logger/OperateLogDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.logger;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.pojo.CommonResult;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.framework.operatelog.core.enums.OperateTypeEnum;
@ -53,12 +52,6 @@ public class OperateLogDO extends BaseDO {
* 关联 MemberUserDO id 属性或者 AdminUserDO id 属性
*/
private Long userId;
/**
* 用户类型
*
* 关联 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 操作模块
*/

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/mail/MailLogDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.mail;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.module.system.enums.mail.MailSendStatusEnum;
import com.baomidou.mybatisplus.annotation.TableField;
@ -37,12 +36,6 @@ public class MailLogDO extends BaseDO implements Serializable {
* 用户编码
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 接收邮箱地址
*/

9
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/notify/NotifyMessageDO.java

@ -1,8 +1,6 @@
package com.win.module.system.dal.dataobject.notify;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.module.system.dal.dataobject.mail.MailTemplateDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -11,7 +9,6 @@ import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
/**
@ -40,12 +37,6 @@ public class NotifyMessageDO extends BaseDO {
* 关联 MemberUserDO id 字段或者 AdminUserDO id 字段
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
// ========= 模板相关字段 =========

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.oauth2;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.tenant.core.db.TenantBaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
@ -44,12 +43,6 @@ public class OAuth2AccessTokenDO extends TenantBaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 客户端编号
*

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2ApproveDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.oauth2;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
@ -32,12 +31,6 @@ public class OAuth2ApproveDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 客户端编号
*

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2CodeDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.oauth2;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
@ -35,12 +34,6 @@ public class OAuth2CodeDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 客户端编号
*

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java

@ -1,6 +1,5 @@
package com.win.module.system.dal.dataobject.oauth2;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
@ -38,12 +37,6 @@ public class OAuth2RefreshTokenDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
/**
* 客户端编号
*

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/dataobject/sms/SmsLogDO.java

@ -2,7 +2,6 @@ package com.win.module.system.dal.dataobject.sms;
import com.win.module.system.enums.sms.SmsReceiveStatusEnum;
import com.win.module.system.enums.sms.SmsSendStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.mybatis.core.dataobject.BaseDO;
import com.win.framework.sms.core.enums.SmsFrameworkErrorCodeConstants;
import com.baomidou.mybatisplus.annotation.KeySequence;
@ -96,12 +95,6 @@ public class SmsLogDO extends BaseDO {
* 用户编号
*/
private Long userId;
/**
* 用户类型
*
* 枚举 {@link UserTypeEnum}
*/
private Integer userType;
// ========= 发送相关字段 =========

1
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/mail/MailLogMapper.java

@ -13,7 +13,6 @@ public interface MailLogMapper extends BaseMapperX<MailLogDO> {
default PageResult<MailLogDO> selectPage(MailLogPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MailLogDO>()
.eqIfPresent(MailLogDO::getUserId, reqVO.getUserId())
.eqIfPresent(MailLogDO::getUserType, reqVO.getUserType())
.likeIfPresent(MailLogDO::getToMail, reqVO.getToMail())
.eqIfPresent(MailLogDO::getAccountId, reqVO.getAccountId())
.eqIfPresent(MailLogDO::getTemplateId, reqVO.getTemplateId())

18
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/notify/NotifyMessageMapper.java

@ -19,52 +19,46 @@ public interface NotifyMessageMapper extends BaseMapperX<NotifyMessageDO> {
default PageResult<NotifyMessageDO> selectPage(NotifyMessagePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<NotifyMessageDO>()
.eqIfPresent(NotifyMessageDO::getUserId, reqVO.getUserId())
.eqIfPresent(NotifyMessageDO::getUserType, reqVO.getUserType())
.likeIfPresent(NotifyMessageDO::getTemplateCode, reqVO.getTemplateCode())
.eqIfPresent(NotifyMessageDO::getTemplateType, reqVO.getTemplateType())
.betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(NotifyMessageDO::getId));
}
default PageResult<NotifyMessageDO> selectPage(NotifyMessageMyPageReqVO reqVO, Long userId, Integer userType) {
default PageResult<NotifyMessageDO> selectPage(NotifyMessageMyPageReqVO reqVO, Long userId) {
return selectPage(reqVO, new LambdaQueryWrapperX<NotifyMessageDO>()
.eqIfPresent(NotifyMessageDO::getReadStatus, reqVO.getReadStatus())
.betweenIfPresent(NotifyMessageDO::getCreateTime, reqVO.getCreateTime())
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType)
.orderByDesc(NotifyMessageDO::getId));
}
default int updateListRead(Collection<Long> ids, Long userId, Integer userType) {
default int updateListRead(Collection<Long> ids, Long userId) {
return update(new NotifyMessageDO().setReadStatus(true).setReadTime(LocalDateTime.now()),
new LambdaQueryWrapperX<NotifyMessageDO>()
.in(NotifyMessageDO::getId, ids)
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType)
.eq(NotifyMessageDO::getReadStatus, false));
}
default int updateListRead(Long userId, Integer userType) {
default int updateListRead(Long userId) {
return update(new NotifyMessageDO().setReadStatus(true).setReadTime(LocalDateTime.now()),
new LambdaQueryWrapperX<NotifyMessageDO>()
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType)
.eq(NotifyMessageDO::getReadStatus, false));
}
default List<NotifyMessageDO> selectUnreadListByUserIdAndUserType(Long userId, Integer userType, Integer size) {
default List<NotifyMessageDO> selectUnreadListByUserId(Long userId, Integer size) {
return selectList(new QueryWrapperX<NotifyMessageDO>() // 由于要使用 limitN 语句,所以只能用 QueryWrapperX
.eq("user_id", userId)
.eq("user_type", userType)
.eq("read_status", false)
.orderByDesc("id").limitN(size));
}
default Long selectUnreadCountByUserIdAndUserType(Long userId, Integer userType) {
default Long selectUnreadCountByUserId(Long userId) {
return selectCount(new LambdaQueryWrapperX<NotifyMessageDO>()
.eq(NotifyMessageDO::getReadStatus, false)
.eq(NotifyMessageDO::getUserId, userId)
.eq(NotifyMessageDO::getUserType, userType));
.eq(NotifyMessageDO::getUserId, userId));
}
}

1
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java

@ -24,7 +24,6 @@ public interface OAuth2AccessTokenMapper extends BaseMapperX<OAuth2AccessTokenDO
default PageResult<OAuth2AccessTokenDO> selectPage(OAuth2AccessTokenPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<OAuth2AccessTokenDO>()
.eqIfPresent(OAuth2AccessTokenDO::getUserId, reqVO.getUserId())
.eqIfPresent(OAuth2AccessTokenDO::getUserType, reqVO.getUserType())
.likeIfPresent(OAuth2AccessTokenDO::getClientId, reqVO.getClientId())
.gt(OAuth2AccessTokenDO::getExpiresTime, LocalDateTime.now())
.orderByDesc(OAuth2AccessTokenDO::getId));

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/dal/mysql/oauth2/OAuth2ApproveMapper.java

@ -13,15 +13,13 @@ public interface OAuth2ApproveMapper extends BaseMapperX<OAuth2ApproveDO> {
default int update(OAuth2ApproveDO updateObj) {
return update(updateObj, new LambdaQueryWrapperX<OAuth2ApproveDO>()
.eq(OAuth2ApproveDO::getUserId, updateObj.getUserId())
.eq(OAuth2ApproveDO::getUserType, updateObj.getUserType())
.eq(OAuth2ApproveDO::getClientId, updateObj.getClientId())
.eq(OAuth2ApproveDO::getScope, updateObj.getScope()));
}
default List<OAuth2ApproveDO> selectListByUserIdAndUserTypeAndClientId(Long userId, Integer userType, String clientId) {
default List<OAuth2ApproveDO> selectListByUserIdAndClientId(Long userId, String clientId) {
return selectList(new LambdaQueryWrapperX<OAuth2ApproveDO>()
.eq(OAuth2ApproveDO::getUserId, userId)
.eq(OAuth2ApproveDO::getUserType, userType)
.eq(OAuth2ApproveDO::getClientId, clientId));
}

23
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/auth/AdminAuthServiceImpl.java

@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil;
import com.win.framework.captcha.config.CaptchaProperties;
import com.win.framework.captcha.enums.CaptchaRedisKeyConstants;
import com.win.framework.common.enums.CommonStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.common.util.monitor.TracerUtils;
import com.win.framework.common.util.servlet.ServletUtils;
import com.win.framework.redis.util.RedisCache;
@ -19,7 +18,6 @@ import com.win.module.system.enums.logger.LoginLogTypeEnum;
import com.win.module.system.enums.logger.LoginResultEnum;
import com.win.module.system.enums.oauth2.OAuth2ClientConstants;
import com.win.module.system.service.logger.LoginLogService;
import com.win.module.system.service.member.MemberService;
import com.win.module.system.service.oauth2.OAuth2TokenService;
import com.win.module.system.service.user.AdminUserService;
import lombok.extern.slf4j.Slf4j;
@ -50,8 +48,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Resource
private OAuth2TokenService oauth2TokenService;
@Resource
private MemberService memberService;
@Resource
private Validator validator;
@Resource
private SmsCodeApi smsCodeApi;
@ -103,7 +99,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
reqDTO.setLogType(logTypeEnum.getType());
reqDTO.setTraceId(TracerUtils.getTraceId());
reqDTO.setUserId(userId);
reqDTO.setUserType(getUserType().getValue());
reqDTO.setUsername(username);
reqDTO.setUserAgent(ServletUtils.getUserAgent());
reqDTO.setUserIp(ServletUtils.getClientIP());
@ -141,8 +136,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
// 插入登陆日志
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
// 创建访问令牌
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(),
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null);
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, OAuth2ClientConstants.CLIENT_ID_DEFAULT, null);
// 构建返回结果
return AuthConvert.INSTANCE.convert(accessTokenDO);
}
@ -161,20 +155,15 @@ public class AdminAuthServiceImpl implements AdminAuthService {
return;
}
// 删除成功,则记录登出日志
createLogoutLog(accessTokenDO.getUserId(), accessTokenDO.getUserType(), logType);
createLogoutLog(accessTokenDO.getUserId(), logType);
}
private void createLogoutLog(Long userId, Integer userType, Integer logType) {
private void createLogoutLog(Long userId, Integer logType) {
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
reqDTO.setLogType(logType);
reqDTO.setTraceId(TracerUtils.getTraceId());
reqDTO.setUserId(userId);
reqDTO.setUserType(userType);
if (ObjectUtil.equal(getUserType().getValue(), userType)) {
reqDTO.setUsername(getUsername(userId));
} else {
reqDTO.setUsername(memberService.getMemberUserMobile(userId));
}
reqDTO.setUsername(getUsername(userId));
reqDTO.setUserAgent(ServletUtils.getUserAgent());
reqDTO.setUserIp(ServletUtils.getClientIP());
reqDTO.setResult(LoginResultEnum.SUCCESS.getResult());
@ -189,8 +178,4 @@ public class AdminAuthServiceImpl implements AdminAuthService {
return user != null ? user.getUsername() : null;
}
private UserTypeEnum getUserType() {
return UserTypeEnum.ADMIN;
}
}

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailLogService.java

@ -36,7 +36,6 @@ public interface MailLogService {
* 创建邮件日志
*
* @param userId 用户编码
* @param userType 用户类型
* @param toMail 收件人邮件
* @param account 邮件账号信息
* @param template 模版信息
@ -45,7 +44,7 @@ public interface MailLogService {
* @param isSend 是否发送成功
* @return 日志编号
*/
Long createMailLog(Long userId, Integer userType, String toMail,
Long createMailLog(Long userId, String toMail,
MailAccountDO account, MailTemplateDO template ,
String templateContent, Map<String, Object> templateParams, Boolean isSend);

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailLogServiceImpl.java

@ -41,7 +41,7 @@ public class MailLogServiceImpl implements MailLogService {
}
@Override
public Long createMailLog(Long userId, Integer userType, String toMail,
public Long createMailLog(Long userId, String toMail,
MailAccountDO account, MailTemplateDO template,
String templateContent, Map<String, Object> templateParams, Boolean isSend) {
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
@ -49,7 +49,7 @@ public class MailLogServiceImpl implements MailLogService {
logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus()
: MailSendStatusEnum.IGNORE.getStatus())
// 用户信息
.userId(userId).userType(userType).toMail(toMail)
.userId(userId).toMail(toMail)
.accountId(account.getId()).fromMail(account.getMail())
// 模板相关字段
.templateId(template.getId()).templateCode(template.getCode()).templateNickname(template.getNickname())

16
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailSendService.java

@ -24,30 +24,16 @@ public interface MailSendService {
Long sendSingleMailToAdmin(String mail, Long userId,
String templateCode, Map<String, Object> templateParams);
/**
* 发送单条邮件给用户 APP 的用户
*
* @param mail 邮箱
* @param userId 用户编码
* @param templateCode 邮件模版编码
* @param templateParams 邮件模版参数
* @return 发送日志编号
*/
Long sendSingleMailToMember(String mail, Long userId,
String templateCode, Map<String, Object> templateParams);
/**
* 发送单条邮件给用户
*
* @param mail 邮箱
* @param userId 用户编码
* @param userType 用户类型
* @param templateCode 邮件模版编码
* @param templateParams 邮件模版参数
* @return 发送日志编号
*/
Long sendSingleMail(String mail, Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams);
Long sendSingleMail(String mail, Long userId, String templateCode, Map<String, Object> templateParams);
/**
* 执行真正的邮件发送

22
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/mail/MailSendServiceImpl.java

@ -4,14 +4,12 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.win.framework.common.enums.CommonStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.module.system.convert.mail.MailAccountConvert;
import com.win.module.system.dal.dataobject.mail.MailAccountDO;
import com.win.module.system.dal.dataobject.mail.MailTemplateDO;
import com.win.module.system.dal.dataobject.user.AdminUserDO;
import com.win.module.system.mq.message.mail.MailSendMessage;
import com.win.module.system.mq.producer.mail.MailProducer;
import com.win.module.system.service.member.MemberService;
import com.win.module.system.service.user.AdminUserService;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
@ -37,8 +35,6 @@ public class MailSendServiceImpl implements MailSendService {
@Resource
private AdminUserService adminUserService;
@Resource
private MemberService memberService;
@Resource
private MailAccountService mailAccountService;
@ -61,23 +57,11 @@ public class MailSendServiceImpl implements MailSendService {
}
}
// 执行发送
return sendSingleMail(mail, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
}
@Override
public Long sendSingleMailToMember(String mail, Long userId,
String templateCode, Map<String, Object> templateParams) {
// 如果 mail 为空,则加载用户编号对应的邮箱
if (StrUtil.isEmpty(mail)) {
mail = memberService.getMemberUserEmail(userId);
}
// 执行发送
return sendSingleMail(mail, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
return sendSingleMail(mail, userId, templateCode, templateParams);
}
@Override
public Long sendSingleMail(String mail, Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams) {
public Long sendSingleMail(String mail, Long userId, String templateCode, Map<String, Object> templateParams) {
// 校验邮箱模版是否合法
MailTemplateDO template = validateMailTemplate(templateCode);
// 校验邮箱账号是否合法
@ -91,7 +75,7 @@ public class MailSendServiceImpl implements MailSendService {
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus());
String title = mailTemplateService.formatMailTemplateContent(template.getTitle(), templateParams);
String content = mailTemplateService.formatMailTemplateContent(template.getContent(), templateParams);
Long sendLogId = mailLogService.createMailLog(userId, userType, mail,
Long sendLogId = mailLogService.createMailLog(userId, mail,
account, template, content, templateParams, isSend);
// 发送 MQ 消息,异步执行发送短信
if (isSend) {

26
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/MemberService.java

@ -1,26 +0,0 @@
package com.win.module.system.service.member;
/**
* Member Service 接口
*
* @author 闻荫源码
*/
public interface MemberService {
/**
* 获得会员用户的手机号码
*
* @param id 会员用户编号
* @return 手机号码
*/
String getMemberUserMobile(Long id);
/**
* 获得会员用户的邮箱
*
* @param id 会员用户编号
* @return 邮箱
*/
String getMemberUserEmail(Long id);
}

54
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/MemberServiceImpl.java

@ -1,54 +0,0 @@
package com.win.module.system.service.member;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* Member Service 实现类
*
* @author 闻荫源码
*/
@Service
public class MemberServiceImpl implements MemberService {
@Value("${win.info.base-package}")
private String basePackage;
private volatile Object memberUserApi;
@Override
public String getMemberUserMobile(Long id) {
Object user = getMemberUser(id);
if (user == null) {
return null;
}
return ReflectUtil.invoke(user, "getMobile");
}
@Override
public String getMemberUserEmail(Long id) {
Object user = getMemberUser(id);
if (user == null) {
return null;
}
return ReflectUtil.invoke(user, "getEmail");
}
private Object getMemberUser(Long id) {
if (id == null) {
return null;
}
return ReflectUtil.invoke(getMemberUserApi(), "getUser", id);
}
private Object getMemberUserApi() {
if (memberUserApi == null) {
memberUserApi = SpringUtil.getBean(ClassUtil.loadClass(String.format("%s.module.member.api.user.MemberUserApi", basePackage)));
}
return memberUserApi;
}
}

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/member/package-info.java

@ -1,4 +0,0 @@
/**
* win-module-member 模块的适配解除 win-module-system 对它们的依赖
*/
package com.win.module.system.service.member;

19
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifyMessageService.java

@ -21,14 +21,12 @@ public interface NotifyMessageService {
* 创建站内信
*
* @param userId 用户编号
* @param userType 用户类型
* @param template 模版信息
* @param templateContent 模版内容
* @param templateParams 模版参数
* @return 站内信编号
*/
Long createNotifyMessage(Long userId, Integer userType,
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams);
Long createNotifyMessage(Long userId, NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams);
/**
* 获得站内信分页
@ -43,10 +41,9 @@ public interface NotifyMessageService {
*
* @param pageReqVO 分页查询
* @param userId 用户编号
* @param userType 用户类型
* @return 站内信分页
*/
PageResult<NotifyMessageDO> getMyMyNotifyMessagePage(NotifyMessageMyPageReqVO pageReqVO, Long userId, Integer userType);
PageResult<NotifyMessageDO> getMyMyNotifyMessagePage(NotifyMessageMyPageReqVO pageReqVO, Long userId);
/**
* 获得站内信
@ -60,38 +57,34 @@ public interface NotifyMessageService {
* 获得我的未读站内信列表
*
* @param userId 用户编号
* @param userType 用户类型
* @param size 数量
* @return 站内信列表
*/
List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size);
List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer size);
/**
* 统计用户未读站内信条数
*
* @param userId 用户编号
* @param userType 用户类型
* @return 返回未读站内信条数
*/
Long getUnreadNotifyMessageCount(Long userId, Integer userType);
Long getUnreadNotifyMessageCount(Long userId);
/**
* 标记站内信为已读
*
* @param ids 站内信编号集合
* @param userId 用户编号
* @param userType 用户类型
* @return 更新到的条数
*/
int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType);
int updateNotifyMessageRead(Collection<Long> ids, Long userId);
/**
* 标记所有站内信为已读
*
* @param userId 用户编号
* @param userType 用户类型
* @return 更新到的条数
*/
int updateAllNotifyMessageRead(Long userId, Integer userType);
int updateAllNotifyMessageRead(Long userId);
}

27
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifyMessageServiceImpl.java

@ -14,8 +14,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 站内信 Service 实现类
*
@ -29,9 +27,8 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
private NotifyMessageMapper notifyMessageMapper;
@Override
public Long createNotifyMessage(Long userId, Integer userType,
NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams) {
NotifyMessageDO message = new NotifyMessageDO().setUserId(userId).setUserType(userType)
public Long createNotifyMessage(Long userId, NotifyTemplateDO template, String templateContent, Map<String, Object> templateParams) {
NotifyMessageDO message = new NotifyMessageDO().setUserId(userId)
.setTemplateId(template.getId()).setTemplateCode(template.getCode())
.setTemplateType(template.getType()).setTemplateNickname(template.getNickname())
.setTemplateContent(templateContent).setTemplateParams(templateParams).setReadStatus(false);
@ -45,8 +42,8 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
}
@Override
public PageResult<NotifyMessageDO> getMyMyNotifyMessagePage(NotifyMessageMyPageReqVO pageReqVO, Long userId, Integer userType) {
return notifyMessageMapper.selectPage(pageReqVO, userId, userType);
public PageResult<NotifyMessageDO> getMyMyNotifyMessagePage(NotifyMessageMyPageReqVO pageReqVO, Long userId) {
return notifyMessageMapper.selectPage(pageReqVO, userId);
}
@Override
@ -55,23 +52,23 @@ public class NotifyMessageServiceImpl implements NotifyMessageService {
}
@Override
public List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer userType, Integer size) {
return notifyMessageMapper.selectUnreadListByUserIdAndUserType(userId, userType, size);
public List<NotifyMessageDO> getUnreadNotifyMessageList(Long userId, Integer size) {
return notifyMessageMapper.selectUnreadListByUserId(userId, size);
}
@Override
public Long getUnreadNotifyMessageCount(Long userId, Integer userType) {
return notifyMessageMapper.selectUnreadCountByUserIdAndUserType(userId, userType);
public Long getUnreadNotifyMessageCount(Long userId) {
return notifyMessageMapper.selectUnreadCountByUserId(userId);
}
@Override
public int updateNotifyMessageRead(Collection<Long> ids, Long userId, Integer userType) {
return notifyMessageMapper.updateListRead(ids, userId, userType);
public int updateNotifyMessageRead(Collection<Long> ids, Long userId) {
return notifyMessageMapper.updateListRead(ids, userId);
}
@Override
public int updateAllNotifyMessageRead(Long userId, Integer userType) {
return notifyMessageMapper.updateListRead(userId, userType);
public int updateAllNotifyMessageRead(Long userId) {
return notifyMessageMapper.updateListRead(userId);
}
}

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifySendService.java

@ -39,16 +39,13 @@ public interface NotifySendService {
* 发送单条站内信给用户
*
* @param userId 用户编号
* @param userType 用户类型
* @param templateCode 站内信模板编号
* @param templateParams 站内信模板参数
* @return 发送日志编号
*/
Long sendSingleNotify( Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams);
Long sendSingleNotify(Long userId, String templateCode, Map<String, Object> templateParams);
default void sendBatchNotify(List<String> mobiles, List<Long> userIds, Integer userType,
String templateCode, Map<String, Object> templateParams) {
default void sendBatchNotify(List<String> mobiles, List<Long> userIds, String templateCode, Map<String, Object> templateParams) {
throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!");
}

11
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/notify/NotifySendServiceImpl.java

@ -1,7 +1,6 @@
package com.win.module.system.service.notify;
import com.win.framework.common.enums.CommonStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.module.system.dal.dataobject.notify.NotifyTemplateDO;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
@ -33,20 +32,20 @@ public class NotifySendServiceImpl implements NotifySendService {
@Override
public Long sendSingleNotifyToAdmin(Long userId, String templateCode, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
return sendSingleNotify(userId, templateCode, templateParams);
}
@Override
public Long sendSingleNotifyToMember(Long userId, String templateCode, Map<String, Object> templateParams) {
return sendSingleNotify(userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
return sendSingleNotify(userId, templateCode, templateParams);
}
@Override
public Long sendSingleNotify(Long userId, Integer userType, String templateCode, Map<String, Object> templateParams) {
public Long sendSingleNotify(Long userId, String templateCode, Map<String, Object> templateParams) {
// 校验模版
NotifyTemplateDO template = validateNotifyTemplate(templateCode);
if (Objects.equals(template.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({}/{})发送]", templateCode, userId, userType);
log.info("[sendSingleNotify][模版({})已经关闭,无法给用户({})发送]", templateCode, userId);
return null;
}
// 校验参数
@ -54,7 +53,7 @@ public class NotifySendServiceImpl implements NotifySendService {
// 发送站内信
String content = notifyTemplateService.formatNotifyTemplateContent(template.getContent(), templateParams);
return notifyMessageService.createNotifyMessage(userId, userType, template, content, templateParams);
return notifyMessageService.createNotifyMessage(userId, template, content, templateParams);
}
@VisibleForTesting

9
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2ApproveService.java

@ -21,32 +21,29 @@ public interface OAuth2ApproveService {
* 参考 ApprovalStoreUserApprovalHandler checkForPreApproval 方法
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param requestedScopes 授权范围
* @return 是否授权通过
*/
boolean checkForPreApproval(Long userId, Integer userType, String clientId, Collection<String> requestedScopes);
boolean checkForPreApproval(Long userId, String clientId, Collection<String> requestedScopes);
/**
* 在用户发起批准时基于 scopes 的选项计算最终是否通过
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param requestedScopes 授权范围
* @return 是否授权通过
*/
boolean updateAfterApproval(Long userId, Integer userType, String clientId, Map<String, Boolean> requestedScopes);
boolean updateAfterApproval(Long userId, String clientId, Map<String, Boolean> requestedScopes);
/**
* 获得用户的批准列表排除已过期的
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @return 是否授权通过
*/
List<OAuth2ApproveDO> getApproveList(Long userId, Integer userType, String clientId);
List<OAuth2ApproveDO> getApproveList(Long userId, String clientId);
}

21
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2ApproveServiceImpl.java

@ -39,7 +39,7 @@ public class OAuth2ApproveServiceImpl implements OAuth2ApproveService {
@Override
@Transactional
public boolean checkForPreApproval(Long userId, Integer userType, String clientId, Collection<String> requestedScopes) {
public boolean checkForPreApproval(Long userId, String clientId, Collection<String> requestedScopes) {
// 第一步,基于 Client 的自动授权计算,如果 scopes 都在自动授权中,则返回 true 通过
OAuth2ClientDO clientDO = oauth2ClientService.validOAuthClientFromCache(clientId);
Assert.notNull(clientDO, "客户端不能为空"); // 防御性编程
@ -47,13 +47,13 @@ public class OAuth2ApproveServiceImpl implements OAuth2ApproveService {
// gh-877 - if all scopes are auto approved, approvals still need to be added to the approval store.
LocalDateTime expireTime = LocalDateTime.now().plusSeconds(TIMEOUT);
for (String scope : requestedScopes) {
saveApprove(userId, userType, clientId, scope, true, expireTime);
saveApprove(userId, clientId, scope, true, expireTime);
}
return true;
}
// 第二步,算上用户已经批准的授权。如果 scopes 都包含,则返回 true
List<OAuth2ApproveDO> approveDOs = getApproveList(userId, userType, clientId);
List<OAuth2ApproveDO> approveDOs = getApproveList(userId, clientId);
Set<String> scopes = convertSet(approveDOs, OAuth2ApproveDO::getScope,
OAuth2ApproveDO::getApproved); // 只保留未过期的 + 同意的
return CollUtil.containsAll(scopes, requestedScopes);
@ -61,7 +61,7 @@ public class OAuth2ApproveServiceImpl implements OAuth2ApproveService {
@Override
@Transactional
public boolean updateAfterApproval(Long userId, Integer userType, String clientId, Map<String, Boolean> requestedScopes) {
public boolean updateAfterApproval(Long userId, String clientId, Map<String, Boolean> requestedScopes) {
// 如果 requestedScopes 为空,说明没有要求,则返回 true 通过
if (CollUtil.isEmpty(requestedScopes)) {
return true;
@ -74,25 +74,22 @@ public class OAuth2ApproveServiceImpl implements OAuth2ApproveService {
if (entry.getValue()) {
success = true;
}
saveApprove(userId, userType, clientId, entry.getKey(), entry.getValue(), expireTime);
saveApprove(userId, clientId, entry.getKey(), entry.getValue(), expireTime);
}
return success;
}
@Override
public List<OAuth2ApproveDO> getApproveList(Long userId, Integer userType, String clientId) {
List<OAuth2ApproveDO> approveDOs = oauth2ApproveMapper.selectListByUserIdAndUserTypeAndClientId(
userId, userType, clientId);
public List<OAuth2ApproveDO> getApproveList(Long userId, String clientId) {
List<OAuth2ApproveDO> approveDOs = oauth2ApproveMapper.selectListByUserIdAndClientId(userId, clientId);
approveDOs.removeIf(o -> DateUtils.isExpired(o.getExpiresTime()));
return approveDOs;
}
@VisibleForTesting
void saveApprove(Long userId, Integer userType, String clientId,
String scope, Boolean approved, LocalDateTime expireTime) {
void saveApprove(Long userId, String clientId, String scope, Boolean approved, LocalDateTime expireTime) {
// 先更新
OAuth2ApproveDO approveDO = new OAuth2ApproveDO().setUserId(userId).setUserType(userType)
.setClientId(clientId).setScope(scope).setApproved(approved).setExpiresTime(expireTime);
OAuth2ApproveDO approveDO = new OAuth2ApproveDO().setUserId(userId).setClientId(clientId).setScope(scope).setApproved(approved).setExpiresTime(expireTime);
if (oauth2ApproveMapper.update(approveDO) == 1) {
return;
}

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2CodeService.java

@ -19,15 +19,13 @@ public interface OAuth2CodeService {
* 参考 JdbcAuthorizationCodeServices createAuthorizationCode 方法
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param scopes 授权范围
* @param redirectUri 重定向 URI
* @param state 状态
* @return 授权码的信息
*/
OAuth2CodeDO createAuthorizationCode(Long userId, Integer userType, String clientId,
List<String> scopes, String redirectUri, String state);
OAuth2CodeDO createAuthorizationCode(Long userId, String clientId, List<String> scopes, String redirectUri, String state);
/**
* 使用授权码

6
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2CodeServiceImpl.java

@ -33,11 +33,9 @@ public class OAuth2CodeServiceImpl implements OAuth2CodeService {
private OAuth2CodeMapper oauth2CodeMapper;
@Override
public OAuth2CodeDO createAuthorizationCode(Long userId, Integer userType, String clientId,
List<String> scopes, String redirectUri, String state) {
public OAuth2CodeDO createAuthorizationCode(Long userId, String clientId, List<String> scopes, String redirectUri, String state) {
OAuth2CodeDO codeDO = new OAuth2CodeDO().setCode(generateCode())
.setUserId(userId).setUserType(userType)
.setClientId(clientId).setScopes(scopes)
.setUserId(userId).setClientId(clientId).setScopes(scopes)
.setExpiresTime(LocalDateTime.now().plusSeconds(TIMEOUT))
.setRedirectUri(redirectUri).setState(state);
oauth2CodeMapper.insert(codeDO);

9
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2GrantService.java

@ -24,13 +24,11 @@ public interface OAuth2GrantService {
* 对应 Spring Security OAuth2 ImplicitTokenGranter 功能
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param scopes 授权范围
* @return 访问令牌
*/
OAuth2AccessTokenDO grantImplicit(Long userId, Integer userType,
String clientId, List<String> scopes);
OAuth2AccessTokenDO grantImplicit(Long userId, String clientId, List<String> scopes);
/**
* 授权码模式第一阶段获得 code 授权码
@ -38,16 +36,13 @@ public interface OAuth2GrantService {
* 对应 Spring Security OAuth2 AuthorizationEndpoint generateCode 方法
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param scopes 授权范围
* @param redirectUri 重定向 URI
* @param state 状态
* @return 授权码
*/
String grantAuthorizationCodeForCode(Long userId, Integer userType,
String clientId, List<String> scopes,
String redirectUri, String state);
String grantAuthorizationCodeForCode(Long userId, String clientId, List<String> scopes, String redirectUri, String state);
/**
* 授权码模式第二阶段获得 accessToken 访问令牌

18
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2GrantServiceImpl.java

@ -3,7 +3,6 @@ package com.win.module.system.service.oauth2;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import com.win.module.system.dal.dataobject.oauth2.OAuth2CodeDO;
import com.win.module.system.dal.dataobject.user.AdminUserDO;
@ -32,17 +31,13 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
private AdminAuthService adminAuthService;
@Override
public OAuth2AccessTokenDO grantImplicit(Long userId, Integer userType,
String clientId, List<String> scopes) {
return oauth2TokenService.createAccessToken(userId, userType, clientId, scopes);
public OAuth2AccessTokenDO grantImplicit(Long userId, String clientId, List<String> scopes) {
return oauth2TokenService.createAccessToken(userId, clientId, scopes);
}
@Override
public String grantAuthorizationCodeForCode(Long userId, Integer userType,
String clientId, List<String> scopes,
String redirectUri, String state) {
return oauth2CodeService.createAuthorizationCode(userId, userType, clientId, scopes,
redirectUri, state).getCode();
public String grantAuthorizationCodeForCode(Long userId, String clientId, List<String> scopes, String redirectUri, String state) {
return oauth2CodeService.createAuthorizationCode(userId, clientId, scopes, redirectUri, state).getCode();
}
@Override
@ -65,8 +60,7 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
}
// 创建访问令牌
return oauth2TokenService.createAccessToken(codeDO.getUserId(), codeDO.getUserType(),
codeDO.getClientId(), codeDO.getScopes());
return oauth2TokenService.createAccessToken(codeDO.getUserId(), codeDO.getClientId(), codeDO.getScopes());
}
@Override
@ -76,7 +70,7 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
Assert.notNull(user, "用户不能为空!"); // 防御性编程
// 创建访问令牌
return oauth2TokenService.createAccessToken(user.getId(), UserTypeEnum.ADMIN.getValue(), clientId, scopes);
return oauth2TokenService.createAccessToken(user.getId(), clientId, scopes);
}
@Override

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2TokenService.java

@ -22,12 +22,11 @@ public interface OAuth2TokenService {
* 参考 DefaultTokenServices createAccessToken 方法
*
* @param userId 用户编号
* @param userType 用户类型
* @param clientId 客户端编号
* @param scopes 授权范围
* @return 访问令牌的信息
*/
OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes);
OAuth2AccessTokenDO createAccessToken(Long userId, String clientId, List<String> scopes);
/**
* 刷新访问令牌

11
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/oauth2/OAuth2TokenServiceImpl.java

@ -45,10 +45,10 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
@Override
@Transactional
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) {
public OAuth2AccessTokenDO createAccessToken(Long userId, String clientId, List<String> scopes) {
OAuth2ClientDO clientDO = oauth2ClientService.validOAuthClientFromCache(clientId);
// 创建刷新令牌
OAuth2RefreshTokenDO refreshTokenDO = createOAuth2RefreshToken(userId, userType, clientDO, scopes);
OAuth2RefreshTokenDO refreshTokenDO = createOAuth2RefreshToken(userId, clientDO, scopes);
// 创建访问令牌
return createOAuth2AccessToken(refreshTokenDO, clientDO);
}
@ -134,7 +134,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
private OAuth2AccessTokenDO createOAuth2AccessToken(OAuth2RefreshTokenDO refreshTokenDO, OAuth2ClientDO clientDO) {
OAuth2AccessTokenDO accessTokenDO = new OAuth2AccessTokenDO().setAccessToken(generateAccessToken())
.setUserId(refreshTokenDO.getUserId()).setUserType(refreshTokenDO.getUserType())
.setUserId(refreshTokenDO.getUserId())
.setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes())
.setRefreshToken(refreshTokenDO.getRefreshToken())
.setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds()));
@ -145,10 +145,9 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
return accessTokenDO;
}
private OAuth2RefreshTokenDO createOAuth2RefreshToken(Long userId, Integer userType, OAuth2ClientDO clientDO, List<String> scopes) {
private OAuth2RefreshTokenDO createOAuth2RefreshToken(Long userId, OAuth2ClientDO clientDO, List<String> scopes) {
OAuth2RefreshTokenDO refreshToken = new OAuth2RefreshTokenDO().setRefreshToken(generateRefreshToken())
.setUserId(userId).setUserType(userType)
.setClientId(clientDO.getClientId()).setScopes(scopes)
.setUserId(userId).setClientId(clientDO.getClientId()).setScopes(scopes)
.setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getRefreshTokenValiditySeconds()));
oauth2RefreshTokenMapper.insert(refreshToken);
return refreshToken;

3
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsCodeServiceImpl.java

@ -46,8 +46,7 @@ public class SmsCodeServiceImpl implements SmsCodeService {
// 创建验证码
String code = createSmsCode(reqDTO.getMobile(), reqDTO.getScene(), reqDTO.getCreateIp());
// 发送验证码
smsSendService.sendSingleSms(reqDTO.getMobile(), null, null,
sceneEnum.getTemplateCode(), MapUtil.of("code", code));
smsSendService.sendSingleSms(reqDTO.getMobile(), null, sceneEnum.getTemplateCode(), MapUtil.of("code", code));
}
private String createSmsCode(String mobile, Integer scene, String ip) {

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsLogService.java

@ -23,15 +23,13 @@ public interface SmsLogService {
*
* @param mobile 手机号
* @param userId 用户编号
* @param userType 用户类型
* @param isSend 是否发送
* @param template 短信模板
* @param templateContent 短信内容
* @param templateParams 短信参数
* @return 发送日志编号
*/
Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend,
SmsTemplateDO template, String templateContent, Map<String, Object> templateParams);
Long createSmsLog(String mobile, Long userId, Boolean isSend, SmsTemplateDO template, String templateContent, Map<String, Object> templateParams);
/**
* 更新日志的发送结果

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsLogServiceImpl.java

@ -31,14 +31,14 @@ public class SmsLogServiceImpl implements SmsLogService {
private SmsLogMapper smsLogMapper;
@Override
public Long createSmsLog(String mobile, Long userId, Integer userType, Boolean isSend,
public Long createSmsLog(String mobile, Long userId, Boolean isSend,
SmsTemplateDO template, String templateContent, Map<String, Object> templateParams) {
SmsLogDO.SmsLogDOBuilder logBuilder = SmsLogDO.builder();
// 根据是否要发送,设置状态
logBuilder.sendStatus(Objects.equals(isSend, true) ? SmsSendStatusEnum.INIT.getStatus()
: SmsSendStatusEnum.IGNORE.getStatus());
// 设置手机相关字段
logBuilder.mobile(mobile).userId(userId).userType(userType);
logBuilder.mobile(mobile).userId(userId);
// 设置模板相关字段
logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType());
logBuilder.templateContent(templateContent).templateParams(templateParams)

21
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsSendService.java

@ -26,35 +26,18 @@ public interface SmsSendService {
Long sendSingleSmsToAdmin(String mobile, Long userId,
String templateCode, Map<String, Object> templateParams);
/**
* 发送单条短信给用户 APP 的用户
*
* mobile 为空时使用 userId 加载对应会员的手机号
*
* @param mobile 手机号
* @param userId 用户编号
* @param templateCode 短信模板编号
* @param templateParams 短信模板参数
* @return 发送日志编号
*/
Long sendSingleSmsToMember(String mobile, Long userId,
String templateCode, Map<String, Object> templateParams);
/**
* 发送单条短信给用户
*
* @param mobile 手机号
* @param userId 用户编号
* @param userType 用户类型
* @param templateCode 短信模板编号
* @param templateParams 短信模板参数
* @return 发送日志编号
*/
Long sendSingleSms(String mobile, Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams);
Long sendSingleSms(String mobile, Long userId, String templateCode, Map<String, Object> templateParams);
default void sendBatchSms(List<String> mobiles, List<Long> userIds, Integer userType,
String templateCode, Map<String, Object> templateParams) {
default void sendBatchSms(List<String> mobiles, List<Long> userIds, String templateCode, Map<String, Object> templateParams) {
throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!");
}

23
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/sms/SmsSendServiceImpl.java

@ -3,9 +3,9 @@ package com.win.module.system.service.sms;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.google.common.annotations.VisibleForTesting;
import com.win.framework.common.core.KeyValue;
import com.win.framework.common.enums.CommonStatusEnum;
import com.win.framework.common.enums.UserTypeEnum;
import com.win.framework.datapermission.core.annotation.DataPermission;
import com.win.framework.sms.core.client.SmsClient;
import com.win.framework.sms.core.client.SmsCommonResult;
@ -16,9 +16,7 @@ import com.win.module.system.dal.dataobject.sms.SmsTemplateDO;
import com.win.module.system.dal.dataobject.user.AdminUserDO;
import com.win.module.system.mq.message.sms.SmsSendMessage;
import com.win.module.system.mq.producer.sms.SmsProducer;
import com.win.module.system.service.member.MemberService;
import com.win.module.system.service.user.AdminUserService;
import com.google.common.annotations.VisibleForTesting;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -40,8 +38,6 @@ public class SmsSendServiceImpl implements SmsSendService {
@Resource
private AdminUserService adminUserService;
@Resource
private MemberService memberService;
@Resource
private SmsChannelService smsChannelService;
@Resource
private SmsTemplateService smsTemplateService;
@ -62,22 +58,11 @@ public class SmsSendServiceImpl implements SmsSendService {
}
}
// 执行发送
return sendSingleSms(mobile, userId, UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
}
@Override
public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) {
// 如果 mobile 为空,则加载用户编号对应的手机号
if (StrUtil.isEmpty(mobile)) {
mobile = memberService.getMemberUserMobile(userId);
}
// 执行发送
return sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams);
return sendSingleSms(mobile, userId, templateCode, templateParams);
}
@Override
public Long sendSingleSms(String mobile, Long userId, Integer userType,
String templateCode, Map<String, Object> templateParams) {
public Long sendSingleSms(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) {
// 校验短信模板是否合法
SmsTemplateDO template = validateSmsTemplate(templateCode);
// 校验短信渠道是否合法
@ -92,7 +77,7 @@ public class SmsSendServiceImpl implements SmsSendService {
Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus())
&& CommonStatusEnum.ENABLE.getStatus().equals(smsChannel.getStatus());
String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams);
Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams);
Long sendLogId = smsLogService.createSmsLog(mobile, userId, isSend, template, content, templateParams);
// 发送 MQ 消息,异步执行发送短信
if (isSend) {

2
win-server/src/main/resources/application-test.yaml

@ -1,5 +1,5 @@
server:
port: 12080
port: 25110
--- #################### 数据库相关配置 ####################

1
win-server/src/main/resources/application.yaml

@ -144,7 +144,6 @@ win:
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
- /admin-api/system/captcha/captchaImage # 校验图片验证码,和租户无关
- /admin-api/infra/file/*/get/** # 获取图片,和租户无关
- /jmreport/* # 积木报表,无法携带租户编号
- /magic/web/* # magic-api 和租户无关
ignore-tables:
- system_tenant

Loading…
Cancel
Save