Merge branch 'dev' of https://gitee.com/qian521/snowy into dev

pull/264/head
wangxu 2025-05-26 17:29:28 +08:00
commit b8f9513d9f
21 changed files with 340 additions and 279 deletions

View File

@ -16,6 +16,9 @@ Snowy谐音“小诺”恰应小诺团队名称意思为”下雪的、纯
<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">
<img src="https://gitee.com/xiaonuobase/snowy/badge/star.svg?theme=dark" alt="Gitee star">
</a>

View File

@ -29,6 +29,9 @@ public enum AuthExceptionEnum {
/** 验证码请求号不能为空 */
VALID_CODE_REQ_NO_EMPTY("验证码请求号不能为空"),
/** 验证码过期 */
VALID_CODE_EXPIRED("验证码过期"),
/** 验证码错误 */
VALID_CODE_ERROR("验证码错误"),

View File

@ -24,6 +24,9 @@ import vip.xiaonuo.common.exception.CommonException;
@Getter
public enum AuthStrategyWhenNoUserWithPhoneOrEmailEnum {
/** 允许登录(手机或者邮箱存在时) */
ALLOW_LOGIN("ALLOW_LOGIN"),
/** 不允许登录 */
NOT_ALLOW_LOGIN("NOT_ALLOW_LOGIN"),
@ -39,7 +42,7 @@ public enum AuthStrategyWhenNoUserWithPhoneOrEmailEnum {
public static void validate(String value) {
boolean flag = NOT_ALLOW_LOGIN.getValue().equals(value) || AUTO_CREATE_USER.getValue().equals(value);
if(!flag) {
throw new CommonException("不支持的手机号或邮箱无对应用户时策略型:{}", value);
throw new CommonException("不支持的手机号或邮箱无对应用户时策略型:{}", value);
}
}
}

View File

@ -194,7 +194,7 @@ public class AuthServiceImpl implements AuthService {
// 验证码请求号
String validCodeReqNo = authGetPhoneValidCodeParam.getValidCodeReqNo();
// 校验参数
validPhoneOrEmailValidCodeParam(null, AuthPhoneOrEmailTypeEnum.PHONE.getValue(), validCode, validCodeReqNo, type);
validValidCode(null, validCode, validCodeReqNo);
// 生成手机验证码的值随机6为数字
String phoneValidCode = RandomUtil.randomNumbers(6);
// 生成手机验证码的请求号
@ -257,7 +257,7 @@ public class AuthServiceImpl implements AuthService {
// 验证码请求号
String validCodeReqNo = authGetEmailValidCodeParam.getValidCodeReqNo();
// 校验参数
validPhoneOrEmailValidCodeParam(null, AuthPhoneOrEmailTypeEnum.EMAIL.getValue(), validCode, validCodeReqNo, type);
validValidCode(null, validCode, validCodeReqNo);
// 生成邮箱验证码的值随机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);
}
// 为空则直接验证码错误
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());
}
// 移除该验证码
// 验证成功,移除该验证码
if(ObjectUtil.isEmpty(phoneOrEmail)) {
// 图形验证码
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);
}
// 不一致则直接验证码错误
if (!validCode.equalsIgnoreCase(Convert.toStr(existValidCode))) {
throw new CommonException("验证码错误");
}
}
/**
@ -351,59 +351,63 @@ public class AuthServiceImpl implements AuthService {
* @author xuyuxiang
* @date 2022/8/25 14:29
**/
private String validPhoneOrEmailValidCodeParam(String phoneOrEmail, String phoneOrEmailType, String validCode,
String validCodeReqNo, String type) {
// 验证码正确则校验手机号格式
if(ObjectUtil.isEmpty(phoneOrEmail)) {
// 根据手机号或者邮箱获取用户信息判断用户是否存在根据B端或C端判断
if(SaClientTypeEnum.B.getValue().equals(type)) {
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phoneOrEmail);
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);
}
}
private String validPhoneOrEmailValidCodeParam(String phoneOrEmail, String phoneOrEmailType,
String validCode, String validCodeReqNo, String type) {
// 校验手机号或邮箱类型
AuthPhoneOrEmailTypeEnum.validate(phoneOrEmailType);
// 校验手机号或邮箱格式
if(phoneOrEmailType.equals(AuthPhoneOrEmailTypeEnum.PHONE.getValue())) {
if(!PhoneUtil.isMobile(phoneOrEmail)) {
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
}
// 执行校验图形验证码
validValidCode(null, validCode, validCodeReqNo);
// 返回空值
return null;
} 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(!PhoneUtil.isMobile(phoneOrEmail)) {
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phoneOrEmail);
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 {
if(CommonEmailUtil.isNotEmail(phoneOrEmail)) {
throw new CommonException(AuthExceptionEnum.PHONE_FORMAT_ERROR.getValue());
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 {
// 存在则允许登录
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端判断
if(SaClientTypeEnum.B.getValue().equals(type)) {
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByPhone(phone);
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 定义B端用户
SaBaseLoginUser saBaseLoginUser;
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 允许登录,即用户存在
saBaseLoginUser = loginUserApi.getUserByPhone(phone);
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 根据手机号自动创建B端用户
saBaseLoginUser = loginUserApi.createUserWithPhone(phone);
} else {
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
}
// 执行B端登录
return execLoginB(saBaseLoginUser, device);
}
}
// 执行B端登录
return execLoginB(saBaseLoginUser, device);
} else {
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phone);
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
// 判断手机号无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("手机号码:{}不存在对应用户", phone);
} else {
// 根据手机号自动创建C端用户
// 定义C端用户
SaBaseClientLoginUser saBaseClientLoginUser;
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 允许登录,即用户存在
saBaseClientLoginUser = clientLoginUserApi.getClientUserByPhone(phone);
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 根据手机号自动创建B端用户
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端判断
if(SaClientTypeEnum.B.getValue().equals(type)) {
SaBaseLoginUser saBaseLoginUser = loginUserApi.getUserByEmail(email);
if(ObjectUtil.isEmpty(saBaseLoginUser)) {
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
} else {
// 定义B端用户
SaBaseLoginUser saBaseLoginUser;
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 允许登录,即用户存在
saBaseLoginUser = loginUserApi.getUserByEmail(email);
}else if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.AUTO_CREATE_USER.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
// 根据邮箱自动创建B端用户
saBaseLoginUser = loginUserApi.createUserWithEmail(email);
} else {
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
}
// 执行B端登录
return execLoginB(saBaseLoginUser, device);
}
}
// 执行B端登录
return execLoginB(saBaseLoginUser, device);
} else {
SaBaseClientLoginUser saBaseClientLoginUser = clientLoginUserApi.getClientUserByEmail(email);
if(ObjectUtil.isEmpty(saBaseClientLoginUser)) {
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
// 判断邮箱无对应用户时的策略,如果为空则直接抛出异常
if(ObjectUtil.isEmpty(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
} else {
// 如果不允许登录,则抛出异常
if(AuthStrategyWhenNoUserWithPhoneOrEmailEnum.NOT_ALLOW_LOGIN.getValue().equals(strategyWhenNoUserWithPhoneOrEmail)) {
throw new CommonException("邮箱:{}不存在对应用户", email);
// 定义C端用户
SaBaseClientLoginUser saBaseClientLoginUser;
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 {
// 根据邮箱自动创建C端用户
saBaseClientLoginUser = clientLoginUserApi.createClientUserWithEmail(email);
throw new CommonException("不支持的手机号或邮箱无对应用户时策略类型:{}", strategyWhenNoUserWithPhoneOrEmail);
}
// 执行C端登录
return execLoginC(saBaseClientLoginUser, device);
}
}
// 执行C端登录
return execLoginC(saBaseClientLoginUser, device);
}
}
@ -924,9 +952,9 @@ public class AuthServiceImpl implements AuthService {
String passwordDecrypt = CommonCryptogramUtil.doSm2Decrypt(password);
// 根据账号获取用户信息根据B端或C端判断
if(SaClientTypeEnum.B.getValue().equals(type)) {
clientLoginUserApi.doRegister(account, passwordDecrypt);
} else {
loginUserApi.doRegister(account, passwordDecrypt);
} else {
clientLoginUserApi.doRegister(account, passwordDecrypt);
}
}

View File

@ -48,10 +48,7 @@ import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.sys.api.SysRoleApi;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -117,7 +114,13 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
} else {
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(),
bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg)))
.collect(Collectors.toList());

View File

@ -148,7 +148,7 @@ public class DevPushWorkWechatUtil {
weTalkRequestArticle.setDescription(content);
weTalkRequestArticle.setPicUrl(picUrl);
weTalkRequestArticle.setUrl(messageUrl);
request.setArticleList(CollectionUtil.newArrayList());
request.setArticleList(CollectionUtil.newArrayList(weTalkRequestArticle));
Response response = oaSender.sender(request, MessageType.WE_TALK_NEWS);
if(!response.isSuccess()) {
throw new CommonException("消息推送错误,返回内容:{}", JSONUtil.toJsonStr(response.getData()));

View File

@ -15,6 +15,7 @@ package vip.xiaonuo.mobile.modular.resource.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -85,7 +86,9 @@ public class MobileButtonServiceImpl extends ServiceImpl<MobileButtonMapper, Mob
if(repeatCode) {
throw new CommonException("存在重复的移动端按钮,编码为:{}", mobileButton.getCode());
}
mobileButton.setCategory(MobileResourceCategoryEnum.BUTTON.getValue());
if(ObjectUtil.isEmpty(mobileButton.getCode())) {
mobileButton.setCode(RandomUtil.randomString(10));
}
this.save(mobileButton);
}

View File

@ -99,7 +99,9 @@ public class MobileMenuServiceImpl extends ServiceImpl<MobileMenuMapper, MobileM
throw new CommonException("module与上级菜单不一致");
}
}
mobileMenu.setCode(RandomUtil.randomString(10));
if(ObjectUtil.isEmpty(mobileMenu.getCode())) {
mobileMenu.setCode(RandomUtil.randomString(10));
}
mobileMenu.setCategory(MobileResourceCategoryEnum.MENU.getValue());
this.save(mobileMenu);
}
@ -243,6 +245,11 @@ public class MobileMenuServiceImpl extends ServiceImpl<MobileMenuMapper, MobileM
}
});
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 ->
new TreeNode<>(mobileMenu.getId(), mobileMenu.getParentId(),
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("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()));
leafMenuList.add(mobileRoleGrantResourceMenuResult);
}

View File

@ -88,7 +88,9 @@ public class MobileModuleServiceImpl extends ServiceImpl<MobileModuleMapper, Mob
if(ObjectUtil.isEmpty(mobileModule.getCode())){
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());
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

View File

@ -97,7 +97,9 @@ public class SysButtonServiceImpl extends ServiceImpl<SysButtonMapper, SysButton
if(repeatCode) {
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());
this.save(sysButton);

View File

@ -165,7 +165,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
throw new CommonException("module与上级菜单不一致");
}
}
sysMenu.setCode(RandomUtil.randomString(10));
if(ObjectUtil.isEmpty(sysMenu.getCode())) {
sysMenu.setCode(RandomUtil.randomString(10));
}
sysMenu.setCategory(SysResourceCategoryEnum.MENU.getValue());
this.save(sysMenu);

View File

@ -92,7 +92,9 @@ public class SysModuleServiceImpl extends ServiceImpl<SysModuleMapper, SysModule
if(repeatTitle) {
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());
this.save(sysModule);
// 发布增加事件

View File

@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
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.service.SysUserExtService;
@ -36,6 +37,7 @@ public class SysUserExtServiceImpl extends ServiceImpl<SysUserExtMapper, SysUser
if(ObjectUtil.isEmpty(sysUserExt)){
sysUserExt = new SysUserExt();
sysUserExt.setUserId(userId);
sysUserExt.setSourceFromType(SysUserSourceFromTypeEnum.SYSTEM_ADD.getValue());
sysUserExt.setPasswordUpdateTime(DateTime.now());
this.save(sysUserExt);
} else {

View File

@ -1,165 +1,165 @@
package vip.xiaonuo.core.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* Jackson
* null
*/
@Configuration
public class JacksonConfig {
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
// 若是APP端请求则处理响应结果字段默认值
if (IS_APP_REQUEST.get()) {
handleNullValue(gen);
} else {
gen.writeNull();
}
}
private void handleNullValue(JsonGenerator gen) throws IOException {
JsonStreamContext context = gen.getOutputContext();
if (context.inObject()) {
String fieldName = context.getCurrentName();
Object currentObj = context.getCurrentValue();
if (currentObj != null) {
Class<?> clazz = currentObj.getClass();
Field field = getField(clazz, fieldName);
if (field != null) {
setDefaultByType(field.getType(), gen);
return;
}
}
}
// 默认处理
gen.writeString("");
}
private Field getField(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
// 查找父类字段
Class<?> superClass = clazz.getSuperclass();
while (superClass != null) {
try {
Field field = superClass.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
superClass = superClass.getSuperclass();
}
}
}
return null;
}
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
if (type.isPrimitive()) {
handlePrimitive(type, gen);
} else if (type == String.class) {
gen.writeString("");
} else if (Number.class.isAssignableFrom(type)) {
gen.writeNumber(0);
} else if (type == Boolean.class) {
gen.writeBoolean(false);
} else if (type == Date.class) {
gen.writeString("");
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
gen.writeStartArray();
gen.writeEndArray();
} else if (Map.class.isAssignableFrom(type)) {
gen.writeStartObject();
gen.writeEndObject();
} else {
gen.writeStartObject();
gen.writeEndObject();
}
}
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
if (type == int.class) {
gen.writeNumber(0);
} else if (type == long.class) {
gen.writeNumber(0L);
} else if (type == double.class) {
gen.writeNumber(0.0);
} else if (type == float.class) {
gen.writeNumber(0.0f);
} else if (type == boolean.class) {
gen.writeBoolean(false);
} else if (type == char.class) {
gen.writeString(String.valueOf('\0'));
} else {
gen.writeNull();
}
}
});
return objectMapper;
}
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
IS_APP_REQUEST.set(isAppRequest(request));
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
IS_APP_REQUEST.remove();
}
});
}
};
}
/**
*
* path
*/
private boolean isAppRequest(HttpServletRequest request) {
String path = request.getRequestURI();
String userAgent = request.getHeader("User-Agent");
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
}
}
package vip.xiaonuo.core.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* Jackson
* null
*/
@Configuration
public class JacksonConfigure {
private static final ThreadLocal<Boolean> IS_APP_REQUEST = ThreadLocal.withInitial(() -> false);
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
// 若是APP端请求则处理响应结果字段默认值
if (IS_APP_REQUEST.get()) {
handleNullValue(gen);
} else {
gen.writeNull();
}
}
private void handleNullValue(JsonGenerator gen) throws IOException {
JsonStreamContext context = gen.getOutputContext();
if (context.inObject()) {
String fieldName = context.getCurrentName();
Object currentObj = context.getCurrentValue();
if (currentObj != null) {
Class<?> clazz = currentObj.getClass();
Field field = getField(clazz, fieldName);
if (field != null) {
setDefaultByType(field.getType(), gen);
return;
}
}
}
// 默认处理
gen.writeString("");
}
private Field getField(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
// 查找父类字段
Class<?> superClass = clazz.getSuperclass();
while (superClass != null) {
try {
Field field = superClass.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
superClass = superClass.getSuperclass();
}
}
}
return null;
}
private void setDefaultByType(Class<?> type, JsonGenerator gen) throws IOException {
if (type.isPrimitive()) {
handlePrimitive(type, gen);
} else if (type == String.class) {
gen.writeString("");
} else if (Number.class.isAssignableFrom(type)) {
gen.writeNumber(0);
} else if (type == Boolean.class) {
gen.writeBoolean(false);
} else if (type == Date.class) {
gen.writeString("");
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
gen.writeStartArray();
gen.writeEndArray();
} else if (Map.class.isAssignableFrom(type)) {
gen.writeStartObject();
gen.writeEndObject();
} else {
gen.writeStartObject();
gen.writeEndObject();
}
}
private void handlePrimitive(Class<?> type, JsonGenerator gen) throws IOException {
if (type == int.class) {
gen.writeNumber(0);
} else if (type == long.class) {
gen.writeNumber(0L);
} else if (type == double.class) {
gen.writeNumber(0.0);
} else if (type == float.class) {
gen.writeNumber(0.0f);
} else if (type == boolean.class) {
gen.writeBoolean(false);
} else if (type == char.class) {
gen.writeString(String.valueOf('\0'));
} else {
gen.writeNull();
}
}
});
return objectMapper;
}
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
IS_APP_REQUEST.set(isAppRequest(request));
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
IS_APP_REQUEST.remove();
}
});
}
};
}
/**
*
* path
*/
private boolean isAppRequest(HttpServletRequest request) {
String path = request.getRequestURI();
String userAgent = request.getHeader("User-Agent");
return path.startsWith("/client/c/app/") || path.startsWith("/auth/c/");
}
}

View File

@ -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 ('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 ('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 ('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);

View File

@ -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-return=false
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.min-evictable-idle-time-millis=300000
spring.datasource.dynamic.druid.filters=stat