mirror of https://gitee.com/xiaonuobase/snowy
Merge branch 'dev' of https://gitee.com/qian521/snowy into dev
commit
b8f9513d9f
|
@ -16,6 +16,9 @@ Snowy谐音“小诺”,恰应小诺团队名称;意思为”下雪的、纯
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
<a href="https://gitcode.com/xiaonuobase/Snowy">
|
||||||
|
<img src="https://gitcode.com/xiaonuobase/Snowy/star/badge.svg" alt="bootstrap">
|
||||||
|
</a>
|
||||||
<a href="https://gitee.com/xiaonuobase/snowy">
|
<a href="https://gitee.com/xiaonuobase/snowy">
|
||||||
<img src="https://gitee.com/xiaonuobase/snowy/badge/star.svg?theme=dark" alt="Gitee star">
|
<img src="https://gitee.com/xiaonuobase/snowy/badge/star.svg?theme=dark" alt="Gitee star">
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -29,6 +29,9 @@ public enum AuthExceptionEnum {
|
||||||
/** 验证码请求号不能为空 */
|
/** 验证码请求号不能为空 */
|
||||||
VALID_CODE_REQ_NO_EMPTY("验证码请求号不能为空"),
|
VALID_CODE_REQ_NO_EMPTY("验证码请求号不能为空"),
|
||||||
|
|
||||||
|
/** 验证码过期 */
|
||||||
|
VALID_CODE_EXPIRED("验证码过期"),
|
||||||
|
|
||||||
/** 验证码错误 */
|
/** 验证码错误 */
|
||||||
VALID_CODE_ERROR("验证码错误"),
|
VALID_CODE_ERROR("验证码错误"),
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@ import vip.xiaonuo.common.exception.CommonException;
|
||||||
@Getter
|
@Getter
|
||||||
public enum AuthStrategyWhenNoUserWithPhoneOrEmailEnum {
|
public enum AuthStrategyWhenNoUserWithPhoneOrEmailEnum {
|
||||||
|
|
||||||
|
/** 允许登录(手机或者邮箱存在时) */
|
||||||
|
ALLOW_LOGIN("ALLOW_LOGIN"),
|
||||||
|
|
||||||
/** 不允许登录 */
|
/** 不允许登录 */
|
||||||
NOT_ALLOW_LOGIN("NOT_ALLOW_LOGIN"),
|
NOT_ALLOW_LOGIN("NOT_ALLOW_LOGIN"),
|
||||||
|
|
||||||
|
@ -39,7 +42,7 @@ public enum AuthStrategyWhenNoUserWithPhoneOrEmailEnum {
|
||||||
public static void validate(String value) {
|
public static void validate(String value) {
|
||||||
boolean flag = NOT_ALLOW_LOGIN.getValue().equals(value) || AUTO_CREATE_USER.getValue().equals(value);
|
boolean flag = NOT_ALLOW_LOGIN.getValue().equals(value) || AUTO_CREATE_USER.getValue().equals(value);
|
||||||
if(!flag) {
|
if(!flag) {
|
||||||
throw new CommonException("不支持的手机号或邮箱无对应用户时策略型:{}", value);
|
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class AuthServiceImpl implements AuthService {
|
||||||
// 验证码请求号
|
// 验证码请求号
|
||||||
String validCodeReqNo = authGetPhoneValidCodeParam.getValidCodeReqNo();
|
String validCodeReqNo = authGetPhoneValidCodeParam.getValidCodeReqNo();
|
||||||
// 校验参数
|
// 校验参数
|
||||||
validPhoneOrEmailValidCodeParam(null, AuthPhoneOrEmailTypeEnum.PHONE.getValue(), validCode, validCodeReqNo, type);
|
validValidCode(null, validCode, validCodeReqNo);
|
||||||
// 生成手机验证码的值,随机6为数字
|
// 生成手机验证码的值,随机6为数字
|
||||||
String phoneValidCode = RandomUtil.randomNumbers(6);
|
String phoneValidCode = RandomUtil.randomNumbers(6);
|
||||||
// 生成手机验证码的请求号
|
// 生成手机验证码的请求号
|
||||||
|
@ -257,7 +257,7 @@ public class AuthServiceImpl implements AuthService {
|
||||||
// 验证码请求号
|
// 验证码请求号
|
||||||
String validCodeReqNo = authGetEmailValidCodeParam.getValidCodeReqNo();
|
String validCodeReqNo = authGetEmailValidCodeParam.getValidCodeReqNo();
|
||||||
// 校验参数
|
// 校验参数
|
||||||
validPhoneOrEmailValidCodeParam(null, AuthPhoneOrEmailTypeEnum.EMAIL.getValue(), validCode, validCodeReqNo, type);
|
validValidCode(null, validCode, validCodeReqNo);
|
||||||
// 生成邮箱验证码的值,随机6为数字
|
// 生成邮箱验证码的值,随机6为数字
|
||||||
String emailValidCode = RandomUtil.randomNumbers(6);
|
String emailValidCode = RandomUtil.randomNumbers(6);
|
||||||
// 生成邮箱验证码的请求号
|
// 生成邮箱验证码的请求号
|
||||||
|
@ -327,11 +327,15 @@ public class AuthServiceImpl implements AuthService {
|
||||||
// 手机或者邮箱验证码
|
// 手机或者邮箱验证码
|
||||||
existValidCode = commonCacheOperator.get(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
existValidCode = commonCacheOperator.get(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
||||||
}
|
}
|
||||||
// 为空则直接验证码错误
|
// 缓存中不存在验证码则返回失效错误
|
||||||
if(ObjectUtil.isEmpty(existValidCode)) {
|
if (ObjectUtil.isEmpty(existValidCode)){
|
||||||
|
throw new CommonException(AuthExceptionEnum.VALID_CODE_EXPIRED.getValue());
|
||||||
|
}
|
||||||
|
// 不一致则直接验证码错误
|
||||||
|
if (!validCode.equalsIgnoreCase(Convert.toStr(existValidCode))) {
|
||||||
throw new CommonException(AuthExceptionEnum.VALID_CODE_ERROR.getValue());
|
throw new CommonException(AuthExceptionEnum.VALID_CODE_ERROR.getValue());
|
||||||
}
|
}
|
||||||
// 移除该验证码
|
// 验证成功,移除该验证码
|
||||||
if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
||||||
// 图形验证码
|
// 图形验证码
|
||||||
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + validCodeReqNo);
|
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + validCodeReqNo);
|
||||||
|
@ -339,10 +343,6 @@ public class AuthServiceImpl implements AuthService {
|
||||||
// 手机或者邮箱验证码
|
// 手机或者邮箱验证码
|
||||||
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
commonCacheOperator.remove(AUTH_VALID_CODE_CACHE_KEY + phoneOrEmail + StrUtil.UNDERLINE + validCodeReqNo);
|
||||||
}
|
}
|
||||||
// 不一致则直接验证码错误
|
|
||||||
if (!validCode.equalsIgnoreCase(Convert.toStr(existValidCode))) {
|
|
||||||
throw new CommonException("验证码错误");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,59 +351,63 @@ public class AuthServiceImpl implements AuthService {
|
||||||
* @author xuyuxiang
|
* @author xuyuxiang
|
||||||
* @date 2022/8/25 14:29
|
* @date 2022/8/25 14:29
|
||||||
**/
|
**/
|
||||||
private String validPhoneOrEmailValidCodeParam(String phoneOrEmail, String phoneOrEmailType, String validCode,
|
private String validPhoneOrEmailValidCodeParam(String phoneOrEmail, String phoneOrEmailType,
|
||||||
String validCodeReqNo, String type) {
|
String validCode, String validCodeReqNo, String type) {
|
||||||
// 验证码正确则校验手机号格式
|
// 校验手机号或邮箱类型
|
||||||
if(ObjectUtil.isEmpty(phoneOrEmail)) {
|
AuthPhoneOrEmailTypeEnum.validate(phoneOrEmailType);
|
||||||
// 根据手机号或者邮箱获取用户信息,判断用户是否存在,根据B端或C端判断
|
// 校验手机号或邮箱格式
|
||||||
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
||||||
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
if(!PhoneUtil.isMobile(phoneOrEmail)) {
|
||||||
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phoneOrEmail);
|
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
|
||||||
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
||||||
// B端手机号无对应用户时策略
|
|
||||||
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_PHONE_FOR_B_KEY);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByEmail(phoneOrEmail);
|
|
||||||
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
|
||||||
// B端邮箱无对应用户时策略
|
|
||||||
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_EMAIL_FOR_B_KEY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
|
||||||
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phoneOrEmail);
|
|
||||||
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
||||||
// C端手机号无对应用户时策略
|
|
||||||
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_PHONE_FOR_C_KEY);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByEmail(phoneOrEmail);
|
|
||||||
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
|
||||||
// BC端邮箱无对应用户时策略
|
|
||||||
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_EMAIL_FOR_C_KEY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 执行校验图形验证码
|
|
||||||
validValidCode(null, validCode, validCodeReqNo);
|
|
||||||
// 返回空值
|
|
||||||
return null;
|
|
||||||
} else {
|
} else {
|
||||||
AuthPhoneOrEmailTypeEnum.validate(phoneOrEmailType);
|
if(CommonEmailUtil.isNotEmail(phoneOrEmail)) {
|
||||||
|
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 先校验验证码
|
||||||
|
validValidCode(phoneOrEmail, validCode, validCodeReqNo);
|
||||||
|
// 根据手机号或者邮箱获取用户信息,判断用户是否存在,根据B端或C端判断
|
||||||
|
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
||||||
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
||||||
if(!PhoneUtil.isMobile(phoneOrEmail)) {
|
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phoneOrEmail);
|
||||||
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
|
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
||||||
|
// B端手机号无对应用户时策略
|
||||||
|
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_PHONE_FOR_B_KEY);
|
||||||
|
} else {
|
||||||
|
// 存在则允许登录
|
||||||
|
return AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(CommonEmailUtil.isNotEmail(phoneOrEmail)) {
|
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByEmail(phoneOrEmail);
|
||||||
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
|
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
||||||
|
// B端邮箱无对应用户时策略
|
||||||
|
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_EMAIL_FOR_B_KEY);
|
||||||
|
} else {
|
||||||
|
// 存在则允许登录
|
||||||
|
return AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
|
||||||
|
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phoneOrEmail);
|
||||||
|
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
||||||
|
// C端手机号无对应用户时策略
|
||||||
|
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_PHONE_FOR_C_KEY);
|
||||||
|
} else {
|
||||||
|
// 存在则允许登录
|
||||||
|
return AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByEmail(phoneOrEmail);
|
||||||
|
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
||||||
|
// C端邮箱无对应用户时策略
|
||||||
|
return devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_STRATEGY_WHEN_NO_USER_WITH_EMAIL_FOR_C_KEY);
|
||||||
|
} else {
|
||||||
|
// 存在则允许登录
|
||||||
|
return AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 执行校验手机或者邮箱验证码
|
|
||||||
validValidCode(phoneOrEmail, validCode, validCodeReqNo);
|
|
||||||
// 返回空值
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,41 +508,53 @@ public class AuthServiceImpl implements AuthService {
|
||||||
}
|
}
|
||||||
// 根据手机号获取用户信息,根据B端或C端判断
|
// 根据手机号获取用户信息,根据B端或C端判断
|
||||||
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
||||||
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phone);
|
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
|
||||||
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
|
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
||||||
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
} else {
|
||||||
|
// 如果不允许登录,则抛出异常
|
||||||
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
||||||
} else {
|
} else {
|
||||||
// 如果不允许登录,则抛出异常
|
// 定义B端用户
|
||||||
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
SaBaseLoginUser saBaseLoginUser;
|
||||||
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
} else {
|
// 允许登录,即用户存在
|
||||||
|
saBaseLoginUser = loginUserApi.getUserByPhone(phone);
|
||||||
|
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 根据手机号自动创建B端用户
|
// 根据手机号自动创建B端用户
|
||||||
saBaseLoginUser = loginUserApi.createUserWithPhone(phone);
|
saBaseLoginUser = loginUserApi.createUserWithPhone(phone);
|
||||||
|
} else {
|
||||||
|
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
|
||||||
}
|
}
|
||||||
|
// 执行B端登录
|
||||||
|
return execLoginB(saBaseLoginUser, device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 执行B端登录
|
|
||||||
return execLoginB(saBaseLoginUser, device);
|
|
||||||
} else {
|
} else {
|
||||||
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phone);
|
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
|
||||||
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
|
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
||||||
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
} else {
|
||||||
|
// 如果不允许登录,则抛出异常
|
||||||
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
||||||
} else {
|
} else {
|
||||||
// 如果不允许登录,则抛出异常
|
// 定义C端用户
|
||||||
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
SaBaseClientLoginUser saBaseClientLoginUser;
|
||||||
throw new CommonException("手机号码:{}不存在对应用户", phone);
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
} else {
|
// 允许登录,即用户存在
|
||||||
// 根据手机号自动创建C端用户
|
saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phone);
|
||||||
|
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
|
// 根据手机号自动创建B端用户
|
||||||
saBaseClientLoginUser = clientLoginUserApi.createClientUserWithPhone(phone);
|
saBaseClientLoginUser = clientLoginUserApi.createClientUserWithPhone(phone);
|
||||||
|
} else {
|
||||||
|
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
|
||||||
}
|
}
|
||||||
|
// 执行C端登录
|
||||||
|
return execLoginC(saBaseClientLoginUser, device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 执行C端登录
|
|
||||||
return execLoginC(saBaseClientLoginUser, device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,41 +578,53 @@ public class AuthServiceImpl implements AuthService {
|
||||||
}
|
}
|
||||||
// 根据邮箱获取用户信息,根据B端或C端判断
|
// 根据邮箱获取用户信息,根据B端或C端判断
|
||||||
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
||||||
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByEmail(email);
|
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
|
||||||
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
|
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
|
throw new CommonException("邮箱:{}不存在对应用户", email);
|
||||||
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
} else {
|
||||||
|
// 如果不允许登录,则抛出异常
|
||||||
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
throw new CommonException("邮箱:{}不存在对应用户", email);
|
throw new CommonException("邮箱:{}不存在对应用户", email);
|
||||||
} else {
|
} else {
|
||||||
// 如果不允许登录,则抛出异常
|
// 定义B端用户
|
||||||
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
SaBaseLoginUser saBaseLoginUser;
|
||||||
throw new CommonException("邮箱:{}不存在对应用户", email);
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
} else {
|
// 允许登录,即用户存在
|
||||||
|
saBaseLoginUser = loginUserApi.getUserByEmail(email);
|
||||||
|
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 根据邮箱自动创建B端用户
|
// 根据邮箱自动创建B端用户
|
||||||
saBaseLoginUser = loginUserApi.createUserWithEmail(email);
|
saBaseLoginUser = loginUserApi.createUserWithEmail(email);
|
||||||
|
} else {
|
||||||
|
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
|
||||||
}
|
}
|
||||||
|
// 执行B端登录
|
||||||
|
return execLoginB(saBaseLoginUser, device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 执行B端登录
|
|
||||||
return execLoginB(saBaseLoginUser, device);
|
|
||||||
} else {
|
} else {
|
||||||
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByEmail(email);
|
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
|
||||||
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
|
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
|
throw new CommonException("邮箱:{}不存在对应用户", email);
|
||||||
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
|
} else {
|
||||||
|
// 如果不允许登录,则抛出异常
|
||||||
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
throw new CommonException("邮箱:{}不存在对应用户", email);
|
throw new CommonException("邮箱:{}不存在对应用户", email);
|
||||||
} else {
|
} else {
|
||||||
// 如果不允许登录,则抛出异常
|
// 定义C端用户
|
||||||
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
SaBaseClientLoginUser saBaseClientLoginUser;
|
||||||
throw new CommonException("邮箱:{}不存在对应用户", email);
|
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
|
// 允许登录,即用户存在
|
||||||
|
saBaseClientLoginUser = clientLoginUserApi.getClientUserByEmail(email);
|
||||||
|
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
|
||||||
|
// 根据邮箱自动创建B端用户
|
||||||
|
saBaseClientLoginUser = loginUserApi.createClientUserWithEmail(email);
|
||||||
} else {
|
} else {
|
||||||
// 根据邮箱自动创建C端用户
|
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
|
||||||
saBaseClientLoginUser = clientLoginUserApi.createClientUserWithEmail(email);
|
|
||||||
}
|
}
|
||||||
|
// 执行C端登录
|
||||||
|
return execLoginC(saBaseClientLoginUser, device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 执行C端登录
|
|
||||||
return execLoginC(saBaseClientLoginUser, device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -924,9 +952,9 @@ public class AuthServiceImpl implements AuthService {
|
||||||
String passwordDecrypt = CommonCryptogramUtil.doSm2Decrypt(password);
|
String passwordDecrypt = CommonCryptogramUtil.doSm2Decrypt(password);
|
||||||
// 根据账号获取用户信息,根据B端或C端判断
|
// 根据账号获取用户信息,根据B端或C端判断
|
||||||
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
if(SaClientTypeEnum.B.getValue().equals(type)) {
|
||||||
clientLoginUserApi.doRegister(account, passwordDecrypt);
|
|
||||||
} else {
|
|
||||||
loginUserApi.doRegister(account, passwordDecrypt);
|
loginUserApi.doRegister(account, passwordDecrypt);
|
||||||
|
} else {
|
||||||
|
clientLoginUserApi.doRegister(account, passwordDecrypt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,7 @@ import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
|
||||||
import vip.xiaonuo.common.page.CommonPageRequest;
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
||||||
import vip.xiaonuo.sys.api.SysRoleApi;
|
import vip.xiaonuo.sys.api.SysRoleApi;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +114,13 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
||||||
} else {
|
} else {
|
||||||
return CollectionUtil.newArrayList();
|
return CollectionUtil.newArrayList();
|
||||||
}
|
}
|
||||||
List<TreeNode<String>> treeNodeList = bizOrgSet.stream().map(bizOrg ->
|
// 先根据排序码排序
|
||||||
|
List<BizOrg> bizOrgArrayList = CollectionUtil.sort(bizOrgSet, Comparator.comparingInt(BizOrg::getSortCode));
|
||||||
|
// 再重置排序码,解决每次相同排序码顺序不一致的问题
|
||||||
|
for (int i = 0; i < bizOrgArrayList.size(); i++) {
|
||||||
|
bizOrgArrayList.get(i).setSortCode(i);
|
||||||
|
}
|
||||||
|
List<TreeNode<String>> treeNodeList = bizOrgArrayList.stream().map(bizOrg ->
|
||||||
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(),
|
new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(),
|
||||||
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
|
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class DevPushWorkWechatUtil {
|
||||||
weTalkRequestArticle.setDescription(content);
|
weTalkRequestArticle.setDescription(content);
|
||||||
weTalkRequestArticle.setPicUrl(picUrl);
|
weTalkRequestArticle.setPicUrl(picUrl);
|
||||||
weTalkRequestArticle.setUrl(messageUrl);
|
weTalkRequestArticle.setUrl(messageUrl);
|
||||||
request.setArticleList(CollectionUtil.newArrayList());
|
request.setArticleList(CollectionUtil.newArrayList(weTalkRequestArticle));
|
||||||
Response response = oaSender.sender(request, MessageType.WE_TALK_NEWS);
|
Response response = oaSender.sender(request, MessageType.WE_TALK_NEWS);
|
||||||
if(!response.isSuccess()) {
|
if(!response.isSuccess()) {
|
||||||
throw new CommonException("消息推送错误,返回内容:{}", JSONUtil.toJsonStr(response.getData()));
|
throw new CommonException("消息推送错误,返回内容:{}", JSONUtil.toJsonStr(response.getData()));
|
||||||
|
|
|
@ -15,6 +15,7 @@ package vip.xiaonuo.mobile.modular.resource.service.impl;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollStreamUtil;
|
import cn.hutool.core.collection.CollStreamUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
@ -85,7 +86,9 @@ public class MobileButtonServiceImpl extends ServiceImpl<MobileButtonMapper, Mob
|
||||||
if(repeatCode) {
|
if(repeatCode) {
|
||||||
throw new CommonException("存在重复的移动端按钮,编码为:{}", mobileButton.getCode());
|
throw new CommonException("存在重复的移动端按钮,编码为:{}", mobileButton.getCode());
|
||||||
}
|
}
|
||||||
mobileButton.setCategory(MobileResourceCategoryEnum.BUTTON.getValue());
|
if(ObjectUtil.isEmpty(mobileButton.getCode())) {
|
||||||
|
mobileButton.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
this.save(mobileButton);
|
this.save(mobileButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,9 @@ public class MobileMenuServiceImpl extends ServiceImpl<MobileMenuMapper, MobileM
|
||||||
throw new CommonException("module与上级菜单不一致");
|
throw new CommonException("module与上级菜单不一致");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mobileMenu.setCode(RandomUtil.randomString(10));
|
if(ObjectUtil.isEmpty(mobileMenu.getCode())) {
|
||||||
|
mobileMenu.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
mobileMenu.setCategory(MobileResourceCategoryEnum.MENU.getValue());
|
mobileMenu.setCategory(MobileResourceCategoryEnum.MENU.getValue());
|
||||||
this.save(mobileMenu);
|
this.save(mobileMenu);
|
||||||
}
|
}
|
||||||
|
@ -243,6 +245,11 @@ public class MobileMenuServiceImpl extends ServiceImpl<MobileMenuMapper, MobileM
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<JSONObject> leafMenuList = CollectionUtil.newArrayList();
|
List<JSONObject> leafMenuList = CollectionUtil.newArrayList();
|
||||||
|
MobileMenu rootMobileMenu = new MobileMenu();
|
||||||
|
rootMobileMenu.setId("0");
|
||||||
|
rootMobileMenu.setParentId("-1");
|
||||||
|
rootMobileMenu.setSortCode(-1);
|
||||||
|
mobileMenuList.add(rootMobileMenu);
|
||||||
List<TreeNode<String>> treeNodeList = mobileMenuList.stream().map(mobileMenu ->
|
List<TreeNode<String>> treeNodeList = mobileMenuList.stream().map(mobileMenu ->
|
||||||
new TreeNode<>(mobileMenu.getId(), mobileMenu.getParentId(),
|
new TreeNode<>(mobileMenu.getId(), mobileMenu.getParentId(),
|
||||||
mobileMenu.getTitle(), mobileMenu.getSortCode())).collect(Collectors.toList());
|
mobileMenu.getTitle(), mobileMenu.getSortCode())).collect(Collectors.toList());
|
||||||
|
@ -267,7 +274,7 @@ public class MobileMenuServiceImpl extends ServiceImpl<MobileMenuMapper, MobileM
|
||||||
mobileRoleGrantResourceMenuResult.set("parentName", parentJsonObject.getStr("parentName"));
|
mobileRoleGrantResourceMenuResult.set("parentName", parentJsonObject.getStr("parentName"));
|
||||||
}
|
}
|
||||||
mobileRoleGrantResourceMenuResult.set("button", this.getChildListById(mobileButtonList, mobileMenu.getId(), false)
|
mobileRoleGrantResourceMenuResult.set("button", this.getChildListById(mobileButtonList, mobileMenu.getId(), false)
|
||||||
.stream().map(sysMenuItem -> JSONUtil.createObj().set("id", sysMenuItem.getId()).set("title", sysMenuItem.getTitle()))
|
.stream().map(tempMobileMenu -> JSONUtil.createObj().set("id", tempMobileMenu.getId()).set("title", tempMobileMenu.getTitle()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
leafMenuList.add(mobileRoleGrantResourceMenuResult);
|
leafMenuList.add(mobileRoleGrantResourceMenuResult);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,9 @@ public class MobileModuleServiceImpl extends ServiceImpl<MobileModuleMapper, Mob
|
||||||
if(ObjectUtil.isEmpty(mobileModule.getCode())){
|
if(ObjectUtil.isEmpty(mobileModule.getCode())){
|
||||||
mobileModule.setCode(RandomUtil.randomString(10));
|
mobileModule.setCode(RandomUtil.randomString(10));
|
||||||
}
|
}
|
||||||
mobileModule.setCode(RandomUtil.randomString(10));
|
if(ObjectUtil.isEmpty(mobileModule.getCode())) {
|
||||||
|
mobileModule.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
mobileModule.setCategory(MobileResourceCategoryEnum.MODULE.getValue());
|
mobileModule.setCategory(MobileResourceCategoryEnum.MODULE.getValue());
|
||||||
this.save(mobileModule);
|
this.save(mobileModule);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
|
@ -97,7 +97,9 @@ public class SysButtonServiceImpl extends ServiceImpl<SysButtonMapper, SysButton
|
||||||
if(repeatCode) {
|
if(repeatCode) {
|
||||||
throw new CommonException("存在重复的按钮,编码为:{}", sysButton.getCode());
|
throw new CommonException("存在重复的按钮,编码为:{}", sysButton.getCode());
|
||||||
}
|
}
|
||||||
sysButton.setCode(RandomUtil.randomString(10));
|
if(ObjectUtil.isEmpty(sysButton.getCode())) {
|
||||||
|
sysButton.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
sysButton.setCategory(SysResourceCategoryEnum.BUTTON.getValue());
|
sysButton.setCategory(SysResourceCategoryEnum.BUTTON.getValue());
|
||||||
this.save(sysButton);
|
this.save(sysButton);
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
throw new CommonException("module与上级菜单不一致");
|
throw new CommonException("module与上级菜单不一致");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sysMenu.setCode(RandomUtil.randomString(10));
|
if(ObjectUtil.isEmpty(sysMenu.getCode())) {
|
||||||
|
sysMenu.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
sysMenu.setCategory(SysResourceCategoryEnum.MENU.getValue());
|
sysMenu.setCategory(SysResourceCategoryEnum.MENU.getValue());
|
||||||
this.save(sysMenu);
|
this.save(sysMenu);
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,9 @@ public class SysModuleServiceImpl extends ServiceImpl<SysModuleMapper, SysModule
|
||||||
if(repeatTitle) {
|
if(repeatTitle) {
|
||||||
throw new CommonException("存在重复的模块,名称为:{}", sysModule.getTitle());
|
throw new CommonException("存在重复的模块,名称为:{}", sysModule.getTitle());
|
||||||
}
|
}
|
||||||
sysModule.setCode(RandomUtil.randomString(10));
|
if(ObjectUtil.isEmpty(sysModule.getCode())) {
|
||||||
|
sysModule.setCode(RandomUtil.randomString(10));
|
||||||
|
}
|
||||||
sysModule.setCategory(SysResourceCategoryEnum.MODULE.getValue());
|
sysModule.setCategory(SysResourceCategoryEnum.MODULE.getValue());
|
||||||
this.save(sysModule);
|
this.save(sysModule);
|
||||||
// 发布增加事件
|
// 发布增加事件
|
||||||
|
|
|
@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import vip.xiaonuo.sys.modular.user.entity.SysUserExt;
|
import vip.xiaonuo.sys.modular.user.entity.SysUserExt;
|
||||||
|
import vip.xiaonuo.sys.modular.user.enums.SysUserSourceFromTypeEnum;
|
||||||
import vip.xiaonuo.sys.modular.user.mapper.SysUserExtMapper;
|
import vip.xiaonuo.sys.modular.user.mapper.SysUserExtMapper;
|
||||||
import vip.xiaonuo.sys.modular.user.service.SysUserExtService;
|
import vip.xiaonuo.sys.modular.user.service.SysUserExtService;
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ public class SysUserExtServiceImpl extends ServiceImpl<SysUserExtMapper, SysUser
|
||||||
if(ObjectUtil.isEmpty(sysUserExt)){
|
if(ObjectUtil.isEmpty(sysUserExt)){
|
||||||
sysUserExt = new SysUserExt();
|
sysUserExt = new SysUserExt();
|
||||||
sysUserExt.setUserId(userId);
|
sysUserExt.setUserId(userId);
|
||||||
|
sysUserExt.setSourceFromType(SysUserSourceFromTypeEnum.SYSTEM_ADD.getValue());
|
||||||
sysUserExt.setPasswordUpdateTime(DateTime.now());
|
sysUserExt.setPasswordUpdateTime(DateTime.now());
|
||||||
this.save(sysUserExt);
|
this.save(sysUserExt);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,165 +1,165 @@
|
||||||
package vip.xiaonuo.core.config;
|
package vip.xiaonuo.core.config;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonStreamContext;
|
import com.fasterxml.jackson.core.JsonStreamContext;
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jackson序列化配置
|
* Jackson序列化配置
|
||||||
* 用于处理返回结果null值改为类型初始值等问题
|
* 用于处理返回结果null值改为类型初始值等问题
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class JacksonConfig {
|
public class JacksonConfigure {
|
||||||
|
|
||||||
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
|
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
@ConditionalOnMissingBean(ObjectMapper.class)
|
@ConditionalOnMissingBean(ObjectMapper.class)
|
||||||
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||||
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
||||||
|
|
||||||
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
|
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||||
// 若是APP端请求,则处理响应结果字段默认值
|
// 若是APP端请求,则处理响应结果字段默认值
|
||||||
if (IS_APP_REQUEST.get()) {
|
if (IS_APP_REQUEST.get()) {
|
||||||
handleNullValue(gen);
|
handleNullValue(gen);
|
||||||
} else {
|
} else {
|
||||||
gen.writeNull();
|
gen.writeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNullValue(JsonGenerator gen) throws IOException {
|
private void handleNullValue(JsonGenerator gen) throws IOException {
|
||||||
JsonStreamContext context = gen.getOutputContext();
|
JsonStreamContext context = gen.getOutputContext();
|
||||||
if (context.inObject()) {
|
if (context.inObject()) {
|
||||||
String fieldName = context.getCurrentName();
|
String fieldName = context.getCurrentName();
|
||||||
Object currentObj = context.getCurrentValue();
|
Object currentObj = context.getCurrentValue();
|
||||||
if (currentObj != null) {
|
if (currentObj != null) {
|
||||||
Class<?> clazz = currentObj.getClass();
|
Class<?> clazz = currentObj.getClass();
|
||||||
Field field = getField(clazz, fieldName);
|
Field field = getField(clazz, fieldName);
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
setDefaultByType(field.getType(), gen);
|
setDefaultByType(field.getType(), gen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 默认处理
|
// 默认处理
|
||||||
gen.writeString("");
|
gen.writeString("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(Class<?> clazz, String fieldName) {
|
private Field getField(Class<?> clazz, String fieldName) {
|
||||||
try {
|
try {
|
||||||
Field field = clazz.getDeclaredField(fieldName);
|
Field field = clazz.getDeclaredField(fieldName);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
// 查找父类字段
|
// 查找父类字段
|
||||||
Class<?> superClass = clazz.getSuperclass();
|
Class<?> superClass = clazz.getSuperclass();
|
||||||
while (superClass != null) {
|
while (superClass != null) {
|
||||||
try {
|
try {
|
||||||
Field field = superClass.getDeclaredField(fieldName);
|
Field field = superClass.getDeclaredField(fieldName);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
} catch (NoSuchFieldException ex) {
|
} catch (NoSuchFieldException ex) {
|
||||||
superClass = superClass.getSuperclass();
|
superClass = superClass.getSuperclass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
|
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
|
||||||
if (type.isPrimitive()) {
|
if (type.isPrimitive()) {
|
||||||
handlePrimitive(type, gen);
|
handlePrimitive(type, gen);
|
||||||
} else if (type == String.class) {
|
} else if (type == String.class) {
|
||||||
gen.writeString("");
|
gen.writeString("");
|
||||||
} else if (Number.class.isAssignableFrom(type)) {
|
} else if (Number.class.isAssignableFrom(type)) {
|
||||||
gen.writeNumber(0);
|
gen.writeNumber(0);
|
||||||
} else if (type == Boolean.class) {
|
} else if (type == Boolean.class) {
|
||||||
gen.writeBoolean(false);
|
gen.writeBoolean(false);
|
||||||
} else if (type == Date.class) {
|
} else if (type == Date.class) {
|
||||||
gen.writeString("");
|
gen.writeString("");
|
||||||
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
|
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
|
||||||
gen.writeStartArray();
|
gen.writeStartArray();
|
||||||
gen.writeEndArray();
|
gen.writeEndArray();
|
||||||
} else if (Map.class.isAssignableFrom(type)) {
|
} else if (Map.class.isAssignableFrom(type)) {
|
||||||
gen.writeStartObject();
|
gen.writeStartObject();
|
||||||
gen.writeEndObject();
|
gen.writeEndObject();
|
||||||
} else {
|
} else {
|
||||||
gen.writeStartObject();
|
gen.writeStartObject();
|
||||||
gen.writeEndObject();
|
gen.writeEndObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
|
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
|
||||||
if (type == int.class) {
|
if (type == int.class) {
|
||||||
gen.writeNumber(0);
|
gen.writeNumber(0);
|
||||||
} else if (type == long.class) {
|
} else if (type == long.class) {
|
||||||
gen.writeNumber(0L);
|
gen.writeNumber(0L);
|
||||||
} else if (type == double.class) {
|
} else if (type == double.class) {
|
||||||
gen.writeNumber(0.0);
|
gen.writeNumber(0.0);
|
||||||
} else if (type == float.class) {
|
} else if (type == float.class) {
|
||||||
gen.writeNumber(0.0f);
|
gen.writeNumber(0.0f);
|
||||||
} else if (type == boolean.class) {
|
} else if (type == boolean.class) {
|
||||||
gen.writeBoolean(false);
|
gen.writeBoolean(false);
|
||||||
} else if (type == char.class) {
|
} else if (type == char.class) {
|
||||||
gen.writeString(String.valueOf('\0'));
|
gen.writeString(String.valueOf('\0'));
|
||||||
} else {
|
} else {
|
||||||
gen.writeNull();
|
gen.writeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return objectMapper;
|
return objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public WebMvcConfigurer webMvcConfigurer() {
|
public WebMvcConfigurer webMvcConfigurer() {
|
||||||
return new WebMvcConfigurer() {
|
return new WebMvcConfigurer() {
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new HandlerInterceptor() {
|
registry.addInterceptor(new HandlerInterceptor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
IS_APP_REQUEST.set(isAppRequest(request));
|
IS_APP_REQUEST.set(isAppRequest(request));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||||
IS_APP_REQUEST.remove();
|
IS_APP_REQUEST.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否为移动端请求
|
* 判断是否为移动端请求
|
||||||
* path根据自己项目的实际路径进行判断
|
* path根据自己项目的实际路径进行判断
|
||||||
*/
|
*/
|
||||||
private boolean isAppRequest(HttpServletRequest request) {
|
private boolean isAppRequest(HttpServletRequest request) {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
String userAgent = request.getHeader("User-Agent");
|
String userAgent = request.getHeader("User-Agent");
|
||||||
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
|
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -895,7 +895,7 @@ CREATE TABLE `MOBILE_RESOURCE` (
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380023993298945', NULL, '业务', '217gcp9ifi', 'MODULE', NULL, NULL, NULL, 'container-outlined', '#1890ff', NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380023993298945', NULL, '业务', '217gcp9ifi', 'MODULE', NULL, NULL, NULL, 'container-outlined', '#1890ff', NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380258656219138', '0', '机构管理', 'UJ3Iwy3jsW', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/org/index', 'apartment-outlined', '#1890ff', 'YES', 'ENABLE', 0, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380258656219138', '0', '机构管理', 'UJ3Iwy3jsW', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/org/index', 'apartment-outlined', '#1890ff', 'YES', 'ENABLE', 0, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380614295449601', '0', '岗位管理', 'sjIY9oGYir', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/position/index', 'robot-outlined', '#9c28b1', 'YES', 'ENABLE', 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380614295449601', '0', '岗位管理', 'sjIY9oGYir', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/position/index', 'robot-outlined', '#9c28b1', 'YES', 'ENABLE', 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380765202313218', '0', '人员管理', 'sjIY9oGYir', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/user/index', 'team-outlined', '#fed835', 'YES', 'ENABLE', 4, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623380765202313218', '0', '人员管理', '2ppITl9dMw', 'MENU', '1623380023993298945', 'MENU', '/pages/biz/user/index', 'team-outlined', '#fed835', 'YES', 'ENABLE', 4, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381127095250946', '0', '更多', 'mFVJNzE7gx', 'MENU', '1623380023993298945', 'CATALOG', '7029146815941316608', 'small-dash-outlined', '#f1627e', 'YES', 'ENABLE', 7, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381127095250946', '0', '更多', 'mFVJNzE7gx', 'MENU', '1623380023993298945', 'CATALOG', '7029146815941316608', 'small-dash-outlined', '#f1627e', 'YES', 'ENABLE', 7, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381298801668098', '1623380258656219138', '新增机构', 'mobileBizOrgAdd', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381298801668098', '1623380258656219138', '新增机构', 'mobileBizOrgAdd', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381632131395586', '1623380258656219138', '编辑机构', 'mobileBizOrgEdit', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
INSERT INTO `MOBILE_RESOURCE` VALUES ('1623381632131395586', '1623380258656219138', '编辑机构', 'mobileBizOrgEdit', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||||
|
|
|
@ -84,6 +84,7 @@ spring.datasource.dynamic.druid.validation-query-timeout=2000
|
||||||
spring.datasource.dynamic.druid.test-on-borrow=false
|
spring.datasource.dynamic.druid.test-on-borrow=false
|
||||||
spring.datasource.dynamic.druid.test-on-return=false
|
spring.datasource.dynamic.druid.test-on-return=false
|
||||||
spring.datasource.dynamic.druid.test-while-idle=true
|
spring.datasource.dynamic.druid.test-while-idle=true
|
||||||
|
spring.datasource.dynamic.druid.validation-query=SELECT 1
|
||||||
spring.datasource.dynamic.druid.time-between-eviction-runs-millis=6000
|
spring.datasource.dynamic.druid.time-between-eviction-runs-millis=6000
|
||||||
spring.datasource.dynamic.druid.min-evictable-idle-time-millis=300000
|
spring.datasource.dynamic.druid.min-evictable-idle-time-millis=300000
|
||||||
spring.datasource.dynamic.druid.filters=stat
|
spring.datasource.dynamic.druid.filters=stat
|
||||||
|
|
Loading…
Reference in New Issue