【代码优化】SYSTEM:认证令牌的操作,增加 @Transactional 注解

This commit is contained in:
YunaiV 2024-09-03 10:34:44 +08:00
parent 9fbc953dd1
commit d3f28b92a7
3 changed files with 37 additions and 35 deletions

View File

@ -15,12 +15,12 @@
<!-- 各种 module 拓展 --> <!-- 各种 module 拓展 -->
<module>yudao-module-system</module> <module>yudao-module-system</module>
<module>yudao-module-infra</module> <module>yudao-module-infra</module>
<!-- <module>yudao-module-member</module>--> <module>yudao-module-member</module>
<!-- <module>yudao-module-bpm</module>--> <!-- <module>yudao-module-bpm</module>-->
<!-- <module>yudao-module-report</module>--> <!-- <module>yudao-module-report</module>-->
<!-- <module>yudao-module-mp</module>--> <!-- <module>yudao-module-mp</module>-->
<!-- <module>yudao-module-pay</module>--> <module>yudao-module-pay</module>
<!-- <module>yudao-module-mall</module>--> <module>yudao-module-mall</module>
<!-- <module>yudao-module-crm</module>--> <!-- <module>yudao-module-crm</module>-->
<!-- <module>yudao-module-erp</module>--> <!-- <module>yudao-module-erp</module>-->
<!-- <module>yudao-module-ai</module>--> <!-- <module>yudao-module-ai</module>-->

View File

@ -56,7 +56,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
private AdminUserService adminUserService; private AdminUserService adminUserService;
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) { public OAuth2AccessTokenDO createAccessToken(Long userId, Integer userType, String clientId, List<String> scopes) {
OAuth2ClientDO clientDO = oauth2ClientService.validOAuthClientFromCache(clientId); OAuth2ClientDO clientDO = oauth2ClientService.validOAuthClientFromCache(clientId);
// 创建刷新令牌 // 创建刷新令牌
@ -66,6 +66,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public OAuth2AccessTokenDO refreshAccessToken(String refreshToken, String clientId) { public OAuth2AccessTokenDO refreshAccessToken(String refreshToken, String clientId) {
// 查询访问令牌 // 查询访问令牌
OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectByRefreshToken(refreshToken); OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectByRefreshToken(refreshToken);
@ -82,7 +83,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
// 移除相关的访问令牌 // 移除相关的访问令牌
List<OAuth2AccessTokenDO> accessTokenDOs = oauth2AccessTokenMapper.selectListByRefreshToken(refreshToken); List<OAuth2AccessTokenDO> accessTokenDOs = oauth2AccessTokenMapper.selectListByRefreshToken(refreshToken);
if (CollUtil.isNotEmpty(accessTokenDOs)) { if (CollUtil.isNotEmpty(accessTokenDOs)) {
oauth2AccessTokenMapper.deleteBatchIds(convertSet(accessTokenDOs, OAuth2AccessTokenDO::getId)); oauth2AccessTokenMapper.deleteByIds(convertSet(accessTokenDOs, OAuth2AccessTokenDO::getId));
oauth2AccessTokenRedisDAO.deleteList(convertSet(accessTokenDOs, OAuth2AccessTokenDO::getAccessToken)); oauth2AccessTokenRedisDAO.deleteList(convertSet(accessTokenDOs, OAuth2AccessTokenDO::getAccessToken));
} }
@ -126,6 +127,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public OAuth2AccessTokenDO removeAccessToken(String accessToken) { public OAuth2AccessTokenDO removeAccessToken(String accessToken) {
// 删除访问令牌 // 删除访问令牌
OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessToken); OAuth2AccessTokenDO accessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessToken);

View File

@ -33,11 +33,11 @@
</dependency> </dependency>
<!-- 会员中心。默认注释,保证编译速度 --> <!-- 会员中心。默认注释,保证编译速度 -->
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-member-biz</artifactId>--> <artifactId>yudao-module-member-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- 数据报表。默认注释,保证编译速度 --> <!-- 数据报表。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->
@ -52,11 +52,11 @@
<!-- <version>${revision}</version>--> <!-- <version>${revision}</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- 支付服务。默认注释,保证编译速度 --> <!-- 支付服务。默认注释,保证编译速度 -->
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-pay-biz</artifactId>--> <artifactId>yudao-module-pay-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- 微信公众号模块。默认注释,保证编译速度 --> <!-- 微信公众号模块。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->
@ -66,26 +66,26 @@
<!-- </dependency>--> <!-- </dependency>-->
<!-- 商城相关模块。默认注释,保证编译速度--> <!-- 商城相关模块。默认注释,保证编译速度-->
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-promotion-biz</artifactId>--> <artifactId>yudao-module-promotion-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-product-biz</artifactId>--> <artifactId>yudao-module-product-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-trade-biz</artifactId>--> <artifactId>yudao-module-trade-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-statistics-biz</artifactId>--> <artifactId>yudao-module-statistics-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- CRM 相关模块。默认注释,保证编译速度 --> <!-- CRM 相关模块。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->