remove
This commit is contained in:
@@ -22,6 +22,8 @@ public interface BladeAuthConstant {
|
|||||||
|
|
||||||
String SMS_SIMPLE_VALUE = "sms.simple";
|
String SMS_SIMPLE_VALUE = "sms.simple";
|
||||||
|
|
||||||
|
String INIT_PASSWD_VALUE = "account.initPassword";
|
||||||
|
|
||||||
String INVITATION_CODE = "invitation_code";
|
String INVITATION_CODE = "invitation_code";
|
||||||
|
|
||||||
String BINARY_TEMPLATE = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
String BINARY_TEMPLATE = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.springblade.common.cache.ParamCache;
|
import org.springblade.common.cache.ParamCache;
|
||||||
|
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.oauth2.provider.OAuth2Request;
|
||||||
import org.springblade.core.oauth2.service.OAuth2User;
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
import org.springblade.core.oauth2.service.OAuth2UserService;
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.redis.debounce.RedisDebounce;
|
||||||
|
import org.springblade.core.redis.ratelimiter.RateLimiter;
|
||||||
import org.springblade.core.sms.model.SmsCode;
|
import org.springblade.core.sms.model.SmsCode;
|
||||||
import org.springblade.core.sms.model.SmsData;
|
import org.springblade.core.sms.model.SmsData;
|
||||||
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.api.R;
|
||||||
@@ -23,8 +26,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.springblade.core.oauth2.constant.OAuth2TokenConstant.USER_PHONE_NOT_FOUND;
|
import static org.springblade.core.oauth2.constant.OAuth2TokenConstant.USER_PHONE_NOT_FOUND;
|
||||||
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.REGISTER_USER_VALUE;
|
||||||
import static org.springblade.modules.auth.constant.BladeAuthConstant.SMS_SIMPLE_VALUE;
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.SMS_SIMPLE_VALUE;
|
||||||
import static org.springblade.modules.resource.utils.SmsUtil.*;
|
import static org.springblade.modules.resource.utils.SmsUtil.*;
|
||||||
|
|
||||||
@@ -69,21 +74,11 @@ public class Oauth2SmsEndpoint {
|
|||||||
if (StringUtil.isBlank(decryptedPhone)) {
|
if (StringUtil.isBlank(decryptedPhone)) {
|
||||||
return R.fail(USER_PHONE_NOT_FOUND);
|
return R.fail(USER_PHONE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
Boolean simpleSMSOpen = Func.toBoolean(ParamCache.getValue(SMS_SIMPLE_VALUE), false);
|
|
||||||
// 校验手机是否已注册,防止恶意发送验证码
|
// 校验手机是否已注册,防止恶意发送验证码
|
||||||
OAuth2Request request = OAuth2Request.create();
|
OAuth2Request request = OAuth2Request.create();
|
||||||
request.setTenantId(tenantId);
|
request.setTenantId(tenantId);
|
||||||
OAuth2User oAuth2User = userService.loadByPhone(decryptedPhone, request);
|
OAuth2User oAuth2User = userService.loadByPhone(decryptedPhone, request);
|
||||||
if (oAuth2User == null && simpleSMSOpen) {
|
if (oAuth2User == null) {
|
||||||
try {
|
|
||||||
Boolean sendSms = dynpsService.sendSms(decryptedPhone);
|
|
||||||
return sendSms ? R.success(SEND_SUCCESS) : R.fail(SEND_FAIL);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return R.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}else if (oAuth2User != null && simpleSMSOpen){
|
|
||||||
return R.fail("该手机号码注册");
|
|
||||||
} else if (oAuth2User == null) {
|
|
||||||
return R.fail(USER_PHONE_NOT_FOUND);
|
return R.fail(USER_PHONE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
// 用户存在则发送验证码
|
// 用户存在则发送验证码
|
||||||
@@ -92,4 +87,38 @@ public class Oauth2SmsEndpoint {
|
|||||||
return smsCode.isSuccess() ? R.data(smsCode, SEND_SUCCESS) : R.fail(SEND_FAIL);
|
return smsCode.isSuccess() ? R.data(smsCode, SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RedisDebounce(key = "sms:debounce", param = "#phone", interval = 60, includeRemainingTime = true, message = "短信发送过于频繁")
|
||||||
|
@PostMapping("/oauth/sms/send-register")
|
||||||
|
public R sendRegister(@RequestParam String tenantId, @RequestParam String phone) {
|
||||||
|
// 校验手机加密认证,防止恶意发送验证码
|
||||||
|
String decryptedPhone = SM2Util.decrypt(phone, properties.getPublicKey(), properties.getPrivateKey());
|
||||||
|
if (StringUtil.isBlank(decryptedPhone)) {
|
||||||
|
return R.fail(USER_PHONE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
Boolean simpleSMSOpen = Func.toBoolean(ParamCache.getValue(SMS_SIMPLE_VALUE), false);
|
||||||
|
|
||||||
|
Boolean registerOpen = Func.toBoolean(ParamCache.getValue(REGISTER_USER_VALUE), false);
|
||||||
|
|
||||||
|
// 校验手机是否已注册,防止恶意发送验证码
|
||||||
|
OAuth2Request request = OAuth2Request.create();
|
||||||
|
request.setTenantId(tenantId);
|
||||||
|
OAuth2User oAuth2User = userService.loadByPhone(decryptedPhone, request);
|
||||||
|
if (oAuth2User != null) {
|
||||||
|
return R.fail("该用户已注册");
|
||||||
|
}
|
||||||
|
if (simpleSMSOpen && registerOpen) {
|
||||||
|
try {
|
||||||
|
Boolean sendSms = dynpsService.sendSms(decryptedPhone);
|
||||||
|
return sendSms ? R.success(SEND_SUCCESS) : R.fail(SEND_FAIL);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = e.getMessage();
|
||||||
|
if (e.getMessage().startsWith("您的访问次数")) {
|
||||||
|
msg = "您的访问次数已超限";
|
||||||
|
}
|
||||||
|
return R.fail(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
/**
|
||||||
|
* BladeX Commercial License Agreement
|
||||||
|
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||||
|
* <p>
|
||||||
|
* Use of this software is governed by the Commercial License Agreement
|
||||||
|
* obtained after purchasing a license from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 1. This software is for development use only under a valid license
|
||||||
|
* from BladeX.
|
||||||
|
* <p>
|
||||||
|
* 2. Redistribution of this software's source code to any third party
|
||||||
|
* without a commercial license is strictly prohibited.
|
||||||
|
* <p>
|
||||||
|
* 3. Licensees may copyright their own code but cannot use segments
|
||||||
|
* from this software for such purposes. Copyright of this software
|
||||||
|
* remains with BladeX.
|
||||||
|
* <p>
|
||||||
|
* Using this software signifies agreement to this License, and the software
|
||||||
|
* must not be used for illegal purposes.
|
||||||
|
* <p>
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||||
|
* not liable for any claims arising from secondary or illegal development.
|
||||||
|
* <p>
|
||||||
|
* Author: Chill Zhuang (bladejava@qq.com)
|
||||||
|
*/
|
||||||
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springblade.common.cache.ParamCache;
|
||||||
|
import org.springblade.core.launch.constant.TokenConstant;
|
||||||
|
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||||
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
|
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
|
||||||
|
import org.springblade.core.oauth2.handler.PasswordHandler;
|
||||||
|
import org.springblade.core.oauth2.props.OAuth2Properties;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Request;
|
||||||
|
import org.springblade.core.oauth2.provider.OAuth2Token;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2Client;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2ClientService;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
|
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
||||||
|
import org.springblade.core.tool.utils.*;
|
||||||
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
|
import org.springblade.modules.auth.utils.CodeUtil;
|
||||||
|
import org.springblade.modules.resource.utils.AliyunDynpsService;
|
||||||
|
import org.springblade.modules.system.pojo.entity.User;
|
||||||
|
import org.springblade.modules.system.service.IUserService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RegisterTokenGranter
|
||||||
|
*
|
||||||
|
* @author BladeX
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AppRegisterTokenGranter extends AbstractTokenGranter {
|
||||||
|
|
||||||
|
private final IUserService service;
|
||||||
|
private final OAuth2Properties properties;
|
||||||
|
private final AliyunDynpsService dynpsService;
|
||||||
|
|
||||||
|
public AppRegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, OAuth2Properties properties, AliyunDynpsService dynpsService) {
|
||||||
|
super(clientService, userService, passwordHandler);
|
||||||
|
this.service = service;
|
||||||
|
this.properties = properties;
|
||||||
|
this.dynpsService = dynpsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String type() {
|
||||||
|
return "app_register";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2User user(OAuth2Request request) {
|
||||||
|
// 校验注册功能是否开启
|
||||||
|
Boolean registerOpen = Func.toBoolean(ParamCache.getValue(REGISTER_USER_VALUE), false);
|
||||||
|
if (!registerOpen) {
|
||||||
|
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean simpleSMSOpen = Func.toBoolean(ParamCache.getValue(SMS_SIMPLE_VALUE), false);
|
||||||
|
if (!simpleSMSOpen) {
|
||||||
|
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户注册信息
|
||||||
|
User user = new User();
|
||||||
|
user.setUserType(UserType.of(request.getUserType()).getCategory());
|
||||||
|
user.setTenantId(request.getTenantId());
|
||||||
|
user.setAccount(request.getPhone());
|
||||||
|
user.setName(request.getName());
|
||||||
|
user.setRealName(request.getName());
|
||||||
|
user.setPhone(request.getPhone());
|
||||||
|
user.setEmail(request.getEmail());
|
||||||
|
|
||||||
|
if (UserType.APP.getCategory() != user.getUserType()) {
|
||||||
|
throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
String code = request.getCode();
|
||||||
|
Assert.isTrue(code.contains(StringPool.COMMA), ExceptionCode.INVALID_USER.getMessage());
|
||||||
|
String[] splitCode = code.split(StringPool.COMMA);
|
||||||
|
Assert.isTrue(splitCode.length == 2, ExceptionCode.INVALID_USER.getMessage());
|
||||||
|
String smsCode = splitCode[0];
|
||||||
|
String invitationCode = splitCode[1];
|
||||||
|
if (StringUtil.isBlank(smsCode)) {
|
||||||
|
throw new UserInvalidException("无效验证码");
|
||||||
|
}
|
||||||
|
Boolean verified;
|
||||||
|
try {
|
||||||
|
verified = dynpsService.verifySms(request.getPhone(), smsCode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new UserInvalidException(e.getMessage());
|
||||||
|
}
|
||||||
|
if (verified) {
|
||||||
|
if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) {
|
||||||
|
if (!CodeUtil.isValidBase36Nullable(invitationCode)) {
|
||||||
|
throw new UserInvalidException("无效邀请码");
|
||||||
|
}
|
||||||
|
long invitorId = Long.parseLong(invitationCode, 36);
|
||||||
|
User invitor = service.getById(invitorId);
|
||||||
|
if (invitor != null) {
|
||||||
|
throw new UserInvalidException("无效邀请码");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user.setPassword(DigestUtil.encrypt(ParamCache.getValue(INIT_PASSWD_VALUE)));
|
||||||
|
user.setRoleId("1123598816738675202");
|
||||||
|
user.setDeptId("2018922617095507970");
|
||||||
|
user.setPostId("1123598817738675208");
|
||||||
|
} else {
|
||||||
|
throw new UserInvalidException("验证码验证失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 执行用户注册
|
||||||
|
if (service.registerUser(user)) {
|
||||||
|
// 构建oauth2所需用户信息
|
||||||
|
return convertOAuth2UserDetail(user, client(request));
|
||||||
|
}
|
||||||
|
throw new UserInvalidException(ExceptionCode.INVALID_USER.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2Token token(OAuth2User user, OAuth2Request request) {
|
||||||
|
// 移除注册后返回的令牌与刷新令牌,防止外部攻击采用注册接口获取令牌并调用低权接口
|
||||||
|
// 注意:
|
||||||
|
// 1. 框架已默认开启严格模式,blade.secure.strict-token=true,不移除令牌则不受影响,注册令牌会被框架校验并拒绝
|
||||||
|
// 2. 若自行关闭严格模式,blade.secure.strict-token=false,必须将令牌移除,否则注册获取令牌后可调用低权接口
|
||||||
|
OAuth2Token token = super.token(user, request);
|
||||||
|
token.getArgs().remove(TokenConstant.ACCESS_TOKEN);
|
||||||
|
token.getArgs().remove(TokenConstant.REFRESH_TOKEN);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private OAuth2UserDetail convertOAuth2UserDetail(User user, OAuth2Client client) {
|
||||||
|
OAuth2UserDetail userDetail = new OAuth2UserDetail();
|
||||||
|
userDetail.setUserId(String.valueOf(user.getId()));
|
||||||
|
userDetail.setTenantId(user.getTenantId());
|
||||||
|
userDetail.setName(user.getName());
|
||||||
|
userDetail.setRealName(user.getName());
|
||||||
|
userDetail.setAccount(user.getAccount());
|
||||||
|
userDetail.setPassword(user.getPassword());
|
||||||
|
userDetail.setPhone(user.getPhone());
|
||||||
|
userDetail.setEmail(user.getEmail());
|
||||||
|
userDetail.setAuthorities(Collections.singletonList(REGISTER));
|
||||||
|
userDetail.setClient(client);
|
||||||
|
return userDetail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,10 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springblade.modules.auth.granter;
|
package org.springblade.modules.auth.granter;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springblade.common.cache.ParamCache;
|
import org.springblade.common.cache.ParamCache;
|
||||||
import org.springblade.common.constant.CommonConstant;
|
|
||||||
import org.springblade.core.launch.constant.TokenConstant;
|
import org.springblade.core.launch.constant.TokenConstant;
|
||||||
import org.springblade.core.oauth2.exception.ExceptionCode;
|
import org.springblade.core.oauth2.exception.ExceptionCode;
|
||||||
import org.springblade.core.oauth2.exception.UserInvalidException;
|
import org.springblade.core.oauth2.exception.UserInvalidException;
|
||||||
@@ -42,42 +40,33 @@ import org.springblade.core.oauth2.service.OAuth2ClientService;
|
|||||||
import org.springblade.core.oauth2.service.OAuth2User;
|
import org.springblade.core.oauth2.service.OAuth2User;
|
||||||
import org.springblade.core.oauth2.service.OAuth2UserService;
|
import org.springblade.core.oauth2.service.OAuth2UserService;
|
||||||
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
|
||||||
import org.springblade.core.oauth2.utils.OAuth2Util;
|
import org.springblade.core.tool.utils.Func;
|
||||||
import org.springblade.core.secure.TokenInfo;
|
import org.springblade.core.tool.utils.SM2Util;
|
||||||
import org.springblade.core.social.props.SocialProperties;
|
|
||||||
import org.springblade.core.tool.utils.*;
|
|
||||||
import org.springblade.modules.auth.provider.UserType;
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
import org.springblade.modules.auth.utils.CodeUtil;
|
|
||||||
import org.springblade.modules.resource.utils.AliyunDynpsService;
|
|
||||||
import org.springblade.modules.system.pojo.entity.User;
|
import org.springblade.modules.system.pojo.entity.User;
|
||||||
import org.springblade.modules.system.service.IUserService;
|
import org.springblade.modules.system.service.IUserService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static org.springblade.modules.auth.constant.BladeAuthConstant.REGISTER_USER_VALUE;
|
import static org.springblade.modules.auth.constant.BladeAuthConstant.REGISTER_USER_VALUE;
|
||||||
import static org.springblade.modules.auth.constant.BladeAuthConstant.SMS_SIMPLE_VALUE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RegisterTokenGranter
|
* RegisterTokenGranter
|
||||||
*
|
*
|
||||||
* @author BladeX
|
* @author BladeX
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@Component
|
@Component
|
||||||
public class RegisterTokenGranter extends AbstractTokenGranter {
|
public class RegisterTokenGranter extends AbstractTokenGranter {
|
||||||
|
|
||||||
private final IUserService service;
|
private final IUserService service;
|
||||||
private final OAuth2Properties properties;
|
private final OAuth2Properties properties;
|
||||||
private final AliyunDynpsService dynpsService;
|
|
||||||
|
|
||||||
public RegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, OAuth2Properties properties, AliyunDynpsService dynpsService) {
|
public RegisterTokenGranter(OAuth2ClientService clientService, OAuth2UserService userService, PasswordHandler passwordHandler, IUserService service, OAuth2Properties properties) {
|
||||||
super(clientService, userService, passwordHandler);
|
super(clientService, userService, passwordHandler);
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.dynpsService = dynpsService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,59 +82,19 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
|
|||||||
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean simpleSMSOpen = Func.toBoolean(ParamCache.getValue(SMS_SIMPLE_VALUE), false);
|
|
||||||
// 用户注册信息
|
// 用户注册信息
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setUserType(UserType.of(request.getUserType()).getCategory());
|
user.setUserType(UserType.of(request.getUserType()).getCategory());
|
||||||
user.setTenantId(request.getTenantId());
|
user.setTenantId(request.getTenantId());
|
||||||
user.setAccount(request.getPhone());
|
user.setAccount(request.getUsername());
|
||||||
|
user.setPassword(SM2Util.decrypt(request.getPassword(), properties.getPublicKey(), properties.getPrivateKey()));
|
||||||
user.setName(request.getName());
|
user.setName(request.getName());
|
||||||
user.setRealName(request.getName());
|
user.setRealName(request.getName());
|
||||||
user.setPhone(request.getPhone());
|
user.setPhone(request.getPhone());
|
||||||
user.setEmail(request.getEmail());
|
user.setEmail(request.getEmail());
|
||||||
|
|
||||||
if (UserType.APP.getCategory() != user.getUserType()) {
|
// 校验用户格式
|
||||||
user.setPassword(SM2Util.decrypt(request.getPassword(), properties.getPublicKey(), properties.getPrivateKey()));
|
validateUser(user);
|
||||||
// 校验用户格式
|
|
||||||
validateUser(user);
|
|
||||||
} else {
|
|
||||||
if (simpleSMSOpen) {
|
|
||||||
String code = request.getCode();
|
|
||||||
Assert.isTrue(code.contains(StringPool.COMMA), ExceptionCode.INVALID_USER.getMessage());
|
|
||||||
String[] splitCode = code.split(StringPool.COMMA);
|
|
||||||
Assert.isTrue(splitCode.length == 2, ExceptionCode.INVALID_USER.getMessage());
|
|
||||||
String smsCode = splitCode[0];
|
|
||||||
String invitationCode = splitCode[1];
|
|
||||||
if (StringUtil.isBlank(smsCode)) {
|
|
||||||
throw new UserInvalidException("无效验证码");
|
|
||||||
}
|
|
||||||
Boolean verified;
|
|
||||||
try {
|
|
||||||
verified = dynpsService.verifySms(request.getPhone(), smsCode);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new UserInvalidException(e.getMessage());
|
|
||||||
}
|
|
||||||
if (verified) {
|
|
||||||
if (StringUtil.isNotBlank(invitationCode) && !StringUtil.equals(invitationCode, "0")) {
|
|
||||||
if (!CodeUtil.isValidBase36Nullable(invitationCode)) {
|
|
||||||
throw new UserInvalidException("无效邀请码");
|
|
||||||
}
|
|
||||||
long invitorId = Long.parseLong(invitationCode, 36);
|
|
||||||
User invitor = service.getById(invitorId);
|
|
||||||
if (invitor != null) {
|
|
||||||
throw new UserInvalidException("无效邀请码");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
user.setPassword(DigestUtil.encrypt(smsCode));
|
|
||||||
user.setRoleId("1123598816738675202");
|
|
||||||
user.setDeptId("2018922617095507970");
|
|
||||||
user.setPostId("1123598817738675208");
|
|
||||||
} else {
|
|
||||||
throw new UserInvalidException("验证码验证失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行用户注册
|
// 执行用户注册
|
||||||
if (service.registerUser(user)) {
|
if (service.registerUser(user)) {
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ import com.aliyun.teaopenapi.models.Config;
|
|||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springblade.core.redis.ratelimiter.RateLimiter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AliyunDynpsService {
|
public class AliyunDynpsService {
|
||||||
@@ -47,6 +50,7 @@ public class AliyunDynpsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RateLimiter(value = "sms:limiter", param = "#phone", max = 3, ttl = 12, timeUnit = TimeUnit.HOURS)// 功能分类
|
||||||
public Boolean sendSms(String phone) {
|
public Boolean sendSms(String phone) {
|
||||||
|
|
||||||
SendSmsVerifyCodeRequest sendSmsVerifyCodeRequest = new SendSmsVerifyCodeRequest()
|
SendSmsVerifyCodeRequest sendSmsVerifyCodeRequest = new SendSmsVerifyCodeRequest()
|
||||||
|
|||||||
@@ -460,7 +460,11 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
|
|||||||
if (tenant == null || tenant.getId() == null) {
|
if (tenant == null || tenant.getId() == null) {
|
||||||
throw new OAuth2Exception("租户信息错误!");
|
throw new OAuth2Exception("租户信息错误!");
|
||||||
}
|
}
|
||||||
user.setStatus(StatusType.ACTIVE.getType());
|
user.setRealName(user.getName());
|
||||||
|
user.setRoleId(StringPool.MINUS_ONE);
|
||||||
|
user.setDeptId(StringPool.MINUS_ONE);
|
||||||
|
user.setPostId(StringPool.MINUS_ONE);
|
||||||
|
user.setStatus(StatusType.IN_ACTIVE.getType());
|
||||||
return this.submit(user);
|
return this.submit(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ blade:
|
|||||||
#redis序列化方式
|
#redis序列化方式
|
||||||
redis:
|
redis:
|
||||||
serializer-type: protostuff
|
serializer-type: protostuff
|
||||||
|
rate-limiter:
|
||||||
|
enabled: true
|
||||||
#日志配置
|
#日志配置
|
||||||
log:
|
log:
|
||||||
request:
|
request:
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
import org.springblade.core.test.BladeBootTest;
|
import org.springblade.core.test.BladeBootTest;
|
||||||
import org.springblade.core.test.BladeSpringExtension;
|
import org.springblade.core.test.BladeSpringExtension;
|
||||||
import org.springblade.core.tool.utils.StringUtil;
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
import org.springblade.flow.engine.entity.FlowModel;
|
|
||||||
import org.springblade.flow.engine.service.FlowEngineService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -20,26 +17,26 @@ import java.util.List;
|
|||||||
@BladeBootTest(appName = "blade-runner", enableLoader = true)
|
@BladeBootTest(appName = "blade-runner", enableLoader = true)
|
||||||
public class BladeTest {
|
public class BladeTest {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private FlowEngineService service;
|
// private FlowEngineService service;
|
||||||
|
//
|
||||||
//@Test
|
// //@Test
|
||||||
public void contextLoads() {
|
// public void contextLoads() {
|
||||||
System.out.println("=====数据迁移启动=====");
|
// System.out.println("=====数据迁移启动=====");
|
||||||
|
//
|
||||||
// 获取 ACT_DE_MODEL 表需要转换的数据
|
// // 获取 ACT_DE_MODEL 表需要转换的数据
|
||||||
List<FlowModel> list = service.list();
|
// List<FlowModel> list = service.list();
|
||||||
// 循环转换
|
// // 循环转换
|
||||||
list.forEach(flowModel -> {
|
// list.forEach(flowModel -> {
|
||||||
if (StringUtil.isBlank(flowModel.getModelEditorXml())) {
|
// if (StringUtil.isBlank(flowModel.getModelEditorXml())) {
|
||||||
service.update(Wrappers.<FlowModel>lambdaUpdate()
|
// service.update(Wrappers.<FlowModel>lambdaUpdate()
|
||||||
.set(FlowModel::getModelEditorXml, new String(service.getModelEditorXML(flowModel)))
|
// .set(FlowModel::getModelEditorXml, new String(service.getModelEditorXML(flowModel)))
|
||||||
.ge(FlowModel::getId, flowModel.getId())
|
// .ge(FlowModel::getId, flowModel.getId())
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
System.out.println("=====数据迁移完毕=====");
|
// System.out.println("=====数据迁移完毕=====");
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,37 +22,44 @@ public class Sm2KeyGenerator {
|
|||||||
String publicKey = "049a315b42a9fd789c321442185f0375fdd7686461fad1276e999a738700375ece22e8a343052ee6be0d1cba174adacaa875c4ffdd0a2b936df26c330f5815599a";
|
String publicKey = "049a315b42a9fd789c321442185f0375fdd7686461fad1276e999a738700375ece22e8a343052ee6be0d1cba174adacaa875c4ffdd0a2b936df26c330f5815599a";
|
||||||
String privateKey = "3d3713f75f9d91583360388428693ddbebd480b8141414b59655a6e6bbbaec15";
|
String privateKey = "3d3713f75f9d91583360388428693ddbebd480b8141414b59655a6e6bbbaec15";
|
||||||
|
|
||||||
System.out.println("#blade配置 \n" +
|
String phone = "13370065231";
|
||||||
"blade:\n" +
|
byte[] encryptedData = SM2Util.encrypt(phone, publicKey);
|
||||||
" oauth2:\n" +
|
|
||||||
" enabled: true\n" +
|
|
||||||
" public-key: " + publicKey + "\n" +
|
|
||||||
" private-key: " + privateKey);
|
|
||||||
System.out.println("=======================================================");
|
|
||||||
System.out.println(StringPool.EMPTY);
|
|
||||||
System.out.println("============== saber website.js 配置如下 ===============");
|
|
||||||
System.out.println("//saber配置\n" +
|
|
||||||
"oauth2: {\n" +
|
|
||||||
" publicKey: '" + publicKey + "',\n" +
|
|
||||||
"}");
|
|
||||||
System.out.println("=======================================================");
|
|
||||||
System.out.println(StringPool.EMPTY);
|
|
||||||
System.out.println("============== 密码:[admin] 加密流程如下 ================");
|
|
||||||
String password = "123456";
|
|
||||||
byte[] encryptedData = SM2Util.encrypt(password, publicKey);
|
|
||||||
String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
||||||
System.out.println("加密前: " + password);
|
|
||||||
System.out.println("加密后: " + Hex.toHexString(encryptedData));
|
System.out.println("加密后: " + Hex.toHexString(encryptedData));
|
||||||
System.out.println("解密后: " + decryptedText);
|
System.out.println("解密后: " + decryptedText);
|
||||||
System.out.println("请注意: 此密文为前端加密后调用token接口的密码参数");
|
|
||||||
System.out.println("=======================================================");
|
|
||||||
|
|
||||||
String encryptedPassword = "04a3ed85133ca830edd0e48e53836298a1528c7692240af9f73aade547d06bc80df13a155c304323f83e37ae5d6f68c385ede1bb3c17db921d218e45b75e9417ef0996f8671d77f87d26eea17a735812bb476b355f5cf4abbfe7bc2f32746e8c122d4edd5e3161";
|
|
||||||
System.out.println("密码: " + encryptedPassword);
|
|
||||||
System.out.println("解密后: " + SM2Util.decrypt(encryptedPassword, privateKey));
|
|
||||||
|
|
||||||
String hex = DigestUtil.encrypt("123456");
|
// System.out.println("#blade配置 \n" +
|
||||||
System.out.println("加密后: " + hex);
|
// "blade:\n" +
|
||||||
|
// " oauth2:\n" +
|
||||||
|
// " enabled: true\n" +
|
||||||
|
// " public-key: " + publicKey + "\n" +
|
||||||
|
// " private-key: " + privateKey);
|
||||||
|
// System.out.println("=======================================================");
|
||||||
|
// System.out.println(StringPool.EMPTY);
|
||||||
|
// System.out.println("============== saber website.js 配置如下 ===============");
|
||||||
|
// System.out.println("//saber配置\n" +
|
||||||
|
// "oauth2: {\n" +
|
||||||
|
// " publicKey: '" + publicKey + "',\n" +
|
||||||
|
// "}");
|
||||||
|
// System.out.println("=======================================================");
|
||||||
|
// System.out.println(StringPool.EMPTY);
|
||||||
|
// System.out.println("============== 密码:[admin] 加密流程如下 ================");
|
||||||
|
// String password = "123456";
|
||||||
|
// byte[] encryptedData = SM2Util.encrypt(password, publicKey);
|
||||||
|
// String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
||||||
|
// System.out.println("加密前: " + password);
|
||||||
|
// System.out.println("加密后: " + Hex.toHexString(encryptedData));
|
||||||
|
// System.out.println("解密后: " + decryptedText);
|
||||||
|
// System.out.println("请注意: 此密文为前端加密后调用token接口的密码参数");
|
||||||
|
// System.out.println("=======================================================");
|
||||||
|
//
|
||||||
|
// String encryptedPassword = "04a3ed85133ca830edd0e48e53836298a1528c7692240af9f73aade547d06bc80df13a155c304323f83e37ae5d6f68c385ede1bb3c17db921d218e45b75e9417ef0996f8671d77f87d26eea17a735812bb476b355f5cf4abbfe7bc2f32746e8c122d4edd5e3161";
|
||||||
|
// System.out.println("密码: " + encryptedPassword);
|
||||||
|
// System.out.println("解密后: " + SM2Util.decrypt(encryptedPassword, privateKey));
|
||||||
|
//
|
||||||
|
// String hex = DigestUtil.encrypt("123456");
|
||||||
|
// System.out.println("加密后: " + hex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,217 +0,0 @@
|
|||||||
package org.springblade.test.param;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.springblade.core.test.BladeBootTest;
|
|
||||||
import org.springblade.core.test.BladeSpringExtension;
|
|
||||||
import org.springblade.modules.appFormal.dto.CutAmountRangDTO;
|
|
||||||
import org.springblade.modules.appFormal.dto.PayOrderDicDTO;
|
|
||||||
import org.springblade.modules.appOffline.dto.WatchVideoTimeRangeDTO;
|
|
||||||
import org.springblade.modules.auth.dto.UserRegisterRoleDTO;
|
|
||||||
import org.springblade.modules.system.pojo.entity.Param;
|
|
||||||
import org.springblade.modules.system.service.IParamService;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@ExtendWith(BladeSpringExtension.class)
|
|
||||||
@BladeBootTest(appName = "blade-runner" , profile = "test")
|
|
||||||
public class ParamTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IParamService paramService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addRegisterRoleInfoParamValue() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:register:role-info";
|
|
||||||
String paramName = "app用户注册默认角色信息";
|
|
||||||
String remark = "app用户注册默认角色信息-包含角色、部门、岗位、头像";
|
|
||||||
|
|
||||||
UserRegisterRoleDTO userRegisterRoleInfo = new UserRegisterRoleDTO();
|
|
||||||
userRegisterRoleInfo.setRoleId("1123598816738675202");
|
|
||||||
userRegisterRoleInfo.setDeptId("1123598813738675201");
|
|
||||||
userRegisterRoleInfo.setPostId("1123598817738675208");
|
|
||||||
userRegisterRoleInfo.setAvatar("https://tse1-mm.cn.bing.net/th/id/OIP-C.BM4bF8_qipHCQu014y_8UgAAAA?w=220&h=217&c=7&r=0&o=7&pid=1.7&rm=3");
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(JSONObject.toJSONString(userRegisterRoleInfo));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalPrivacyParamValue() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:user:privacy";
|
|
||||||
String paramName = "商城app用户隐私政策";
|
|
||||||
String remark = "商城app用户隐私政策";
|
|
||||||
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue("隐私政策");
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalAgreementParamValue() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:user:agreement";
|
|
||||||
String paramName = "商城app用户协议";
|
|
||||||
String remark = "商城app用户协议";
|
|
||||||
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue("商城app用户协议");
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalOrderModelType() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:order:model_type";
|
|
||||||
String paramName = "商城app订单类型";
|
|
||||||
String remark = "商城app订单类型";
|
|
||||||
//{"id":1,"code":"MALL","name":"商城"}
|
|
||||||
List<PayOrderDicDTO> payOrderDicDTOS = List.of(
|
|
||||||
new PayOrderDicDTO().setId(1).setCode("MALL").setName("商城")
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(JSONArray.toJSONString(payOrderDicDTOS));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalCashToPointRate() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:mall.cash.to.point.Rate";
|
|
||||||
String paramName = "商城app订单现金兑换积分比例";
|
|
||||||
String remark = "商城app订单现金兑换积分比例";
|
|
||||||
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(String.valueOf("0.3"));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalCutAmountRang() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:mall.cut.amount.rang";
|
|
||||||
String paramName = "商城app随机立减比例范围";
|
|
||||||
String remark = "商城app随机立减比例范围";
|
|
||||||
|
|
||||||
CutAmountRangDTO cutAmountRangDTO = new CutAmountRangDTO();
|
|
||||||
cutAmountRangDTO.setMin(BigDecimal.valueOf(0.01));
|
|
||||||
cutAmountRangDTO.setMax(BigDecimal.valueOf(0.001));
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(JSONObject.toJSONString(cutAmountRangDTO));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAppFormalPayType() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:formal:pay.type";
|
|
||||||
String paramName = "商城app支付类型";
|
|
||||||
String remark = "商城app支付类型";
|
|
||||||
|
|
||||||
List<PayOrderDicDTO> payOrderDicDTOS = List.of(
|
|
||||||
new PayOrderDicDTO().setId(1).setCode("ALI").setName("支付宝"),
|
|
||||||
new PayOrderDicDTO().setId(2).setCode("WEI").setName("微信")
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<Integer, List<PayOrderDicDTO>> payOrderDicMap = new HashMap<>();
|
|
||||||
payOrderDicMap.put(1, payOrderDicDTOS);
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(JSONObject.toJSONString(payOrderDicMap));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addDailySignIsLookAds() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:dailysign.is.look.ads";
|
|
||||||
String paramName = "积分app是否看广告";
|
|
||||||
String remark = "积分app是否看广告";
|
|
||||||
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue("true");
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addWatchVideoTimeRange() {
|
|
||||||
|
|
||||||
String paramKey = "yichayilu:app:dailysign:watch.video.time.rang";
|
|
||||||
String paramName = "积分app看广告的时间范围";
|
|
||||||
String remark = "积分app看广告的时间范围";
|
|
||||||
|
|
||||||
WatchVideoTimeRangeDTO dto = new WatchVideoTimeRangeDTO();
|
|
||||||
dto.setStartTime("08:00");
|
|
||||||
dto.setEndTime("22:00");
|
|
||||||
|
|
||||||
Param param = new Param();
|
|
||||||
param.setParamKey(paramKey);
|
|
||||||
param.setParamName(paramName);
|
|
||||||
param.setParamValue(JSONObject.toJSONString(dto));
|
|
||||||
param.setRemark(remark);
|
|
||||||
|
|
||||||
paramService.save(param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package org.springblade.test.userPoint;
|
|
||||||
|
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.springblade.core.test.BladeBootTest;
|
|
||||||
import org.springblade.core.test.BladeSpringExtension;
|
|
||||||
import org.springblade.modules.userPoint.dto.UserAmountDTO;
|
|
||||||
import org.springblade.modules.userPoint.pojo.entity.UserMallIntegralEntity;
|
|
||||||
import org.springblade.modules.userPoint.service.IUserMallIntegralService;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@ExtendWith(BladeSpringExtension.class)
|
|
||||||
@BladeBootTest(appName = "blade-runner" , profile = "test")
|
|
||||||
public class UserPointTest {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IUserMallIntegralService userMallIntegralService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAmount() {
|
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++){
|
|
||||||
UserMallIntegralEntity mallIntegral = userMallIntegralService.getById(2017162601210183681L);
|
|
||||||
Integer version = 1;
|
|
||||||
if (mallIntegral == null){
|
|
||||||
mallIntegral = new UserMallIntegralEntity();
|
|
||||||
mallIntegral.setAmount(BigDecimal.ZERO);
|
|
||||||
mallIntegral.setId(2017162601210183681L);
|
|
||||||
mallIntegral.setVersion(version);
|
|
||||||
userMallIntegralService.save(mallIntegral);
|
|
||||||
}else {
|
|
||||||
version = mallIntegral.getVersion();
|
|
||||||
}
|
|
||||||
UserAmountDTO dto = new UserAmountDTO();
|
|
||||||
dto.setUserId(2017162601210183681L);
|
|
||||||
dto.setAmount(new BigDecimal(666));
|
|
||||||
dto.setOrderId(1L);
|
|
||||||
dto.setSourceId(2017162601210183681L);
|
|
||||||
dto.setSourceDetail("19115988697");
|
|
||||||
dto.setVersion(version);
|
|
||||||
dto.setRemark("测试");
|
|
||||||
|
|
||||||
userMallIntegralService.addAmount(dto);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user