feat:
1. 增加用户删除
This commit is contained in:
@@ -66,9 +66,9 @@ public class APPUserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/change-password")
|
@PostMapping("/change-password")
|
||||||
@ApiOperationSupport(order = 2)
|
@ApiOperationSupport(order = 2)
|
||||||
@Operation(summary = "修改登录密码", description = "传入String")
|
@Operation(summary = "修改登录密码", description = "传入request")
|
||||||
public R changePassword(@RequestBody String password) {
|
public R changePassword(@RequestBody @Valid ChangePasswordRequest request) {
|
||||||
return R.status(userService.changePassword(password));
|
return R.status(userService.changePassword(request.getPassword()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -252,15 +252,8 @@ public class APPUserController {
|
|||||||
return R.data(paymentService.modulePayTypeList(moduleCode));
|
return R.data(paymentService.modulePayTypeList(moduleCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/logout")
|
|
||||||
@ApiOperationSupport(order = 25)
|
|
||||||
@Operation(summary = "登出")
|
|
||||||
public R logout() {
|
|
||||||
return R.status(userService.logout());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/close-account")
|
@PostMapping("/close-account")
|
||||||
@ApiOperationSupport(order = 26)
|
@ApiOperationSupport(order = 25)
|
||||||
@Operation(summary = "删除账户")
|
@Operation(summary = "删除账户")
|
||||||
public R closeAccount() {
|
public R closeAccount() {
|
||||||
return R.status(userService.closeAccount());
|
return R.status(userService.closeAccount());
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.springblade.modules.api.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChangePasswordRequest implements Serializable {
|
||||||
|
|
||||||
|
@NotEmpty(message = "密码不能为空")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -76,10 +76,10 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void spendPointsForLottery(BigDecimal amount, Long userId) {
|
public void spendPointsForLottery(BigDecimal amount, Long userId) {
|
||||||
Assert.isTrue(amount.compareTo(BigDecimal.valueOf(100)) == 0 || amount.compareTo(BigDecimal.valueOf(1000)) == 0, "无效积分");
|
|
||||||
Assert.notNull(userId, "无效用户");
|
|
||||||
CommonUserPointEntity userPoint = getById(userId);
|
CommonUserPointEntity userPoint = getById(userId);
|
||||||
Assert.isTrue(userPoint.getAmount().compareTo(amount) >= 0, "积分不足");
|
if (userPoint.getAmount().compareTo(amount) < 0){
|
||||||
|
throw new ServiceException("积分不足");
|
||||||
|
}
|
||||||
BigDecimal lastAmount = userPoint.getAmount();
|
BigDecimal lastAmount = userPoint.getAmount();
|
||||||
int i = baseMapper.deductUserPoint(userId, amount, userPoint.getVersion());
|
int i = baseMapper.deductUserPoint(userId, amount, userPoint.getVersion());
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|||||||
@@ -314,8 +314,6 @@ public interface IUserService extends BaseService<User> {
|
|||||||
|
|
||||||
boolean retrievePassword(ResetPasswordRequest request);
|
boolean retrievePassword(ResetPasswordRequest request);
|
||||||
|
|
||||||
boolean logout();
|
|
||||||
|
|
||||||
boolean closeAccount();
|
boolean closeAccount();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springblade.common.constant.TenantConstant;
|
|||||||
import org.springblade.common.enums.DictEnum;
|
import org.springblade.common.enums.DictEnum;
|
||||||
import org.springblade.core.cache.utils.CacheUtil;
|
import org.springblade.core.cache.utils.CacheUtil;
|
||||||
import org.springblade.core.jwt.JwtUtil;
|
import org.springblade.core.jwt.JwtUtil;
|
||||||
|
import org.springblade.core.jwt.props.JwtProperties;
|
||||||
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||||
import org.springblade.core.mp.enums.StatusType;
|
import org.springblade.core.mp.enums.StatusType;
|
||||||
@@ -23,7 +24,9 @@ import org.springblade.core.oauth2.exception.ExceptionCode;
|
|||||||
import org.springblade.core.oauth2.exception.OAuth2Exception;
|
import org.springblade.core.oauth2.exception.OAuth2Exception;
|
||||||
import org.springblade.core.oauth2.exception.UserInvalidException;
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
import org.springblade.core.oauth2.props.OAuth2Properties;
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
import org.springblade.core.redis.cache.BladeRedis;
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.core.secure.BladeUser;
|
||||||
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
import org.springblade.core.tenant.BladeTenantProperties;
|
import org.springblade.core.tenant.BladeTenantProperties;
|
||||||
import org.springblade.core.tool.constant.BladeConstant;
|
import org.springblade.core.tool.constant.BladeConstant;
|
||||||
@@ -73,6 +76,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
|||||||
private final OAuth2Properties properties;
|
private final OAuth2Properties properties;
|
||||||
private final AliyunDynpsService dynpsService;
|
private final AliyunDynpsService dynpsService;
|
||||||
private final ICommonUserSmsLogService userSmsLogService;
|
private final ICommonUserSmsLogService userSmsLogService;
|
||||||
|
private final JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -721,15 +726,18 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
|||||||
return updateById(userInfo);
|
return updateById(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean logout() {
|
|
||||||
JwtUtil.removeAccessToken(AuthUtil.getTenantId(), String.valueOf(AuthUtil.getUserId()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean closeAccount() {
|
public boolean closeAccount() {
|
||||||
return false;
|
Long userId = AuthUtil.getUserId();
|
||||||
|
BladeUser user = AuthUtil.getUser();
|
||||||
|
// 退出登录,清除有状态模式下缓存的token
|
||||||
|
if (user != null && jwtProperties.getState()) {
|
||||||
|
OAuth2Request request = OAuth2Request.create().buildHeaderArgs();
|
||||||
|
String token = JwtUtil.getToken(request.getToken());
|
||||||
|
JwtUtil.removeAccessToken(user.getTenantId(), user.getClientId(), String.valueOf(user.getUserId()), token);
|
||||||
|
JwtUtil.removeRefreshToken(user.getTenantId(), user.getClientId(), String.valueOf(user.getUserId()), token);
|
||||||
|
}
|
||||||
|
return update(Wrappers.lambdaUpdate(User.class).eq(User::getId, userId).set(User::getIsDeleted, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) {
|
private boolean isPasswordValid(String password) {
|
||||||
|
|||||||
Reference in New Issue
Block a user