diff --git a/README.md b/README.md index 0b2319e6..5827e91e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ Snowy谐音“小诺”,恰应小诺团队名称;意思为”下雪的、纯

+ + bootstrap + Gitee star diff --git a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthExceptionEnum.java b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthExceptionEnum.java index 7753b20f..37516593 100644 --- a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthExceptionEnum.java +++ b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthExceptionEnum.java @@ -29,6 +29,9 @@ public enum AuthExceptionEnum { /** 验证码请求号不能为空 */ VALID_CODE_REQ_NO_EMPTY("验证码请求号不能为空"), + /** 验证码过期 */ + VALID_CODE_EXPIRED("验证码过期"), + /** 验证码错误 */ VALID_CODE_ERROR("验证码错误"), diff --git a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthStrategyWhenNoUserWithPhoneOrEmailEnum.java b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthStrategyWhenNoUserWithPhoneOrEmailEnum.java index d42e70a6..8dccc16c 100644 --- a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthStrategyWhenNoUserWithPhoneOrEmailEnum.java +++ b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/enums/AuthStrategyWhenNoUserWithPhoneOrEmailEnum.java @@ -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); } } } diff --git a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/service/impl/AuthServiceImpl.java b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/service/impl/AuthServiceImpl.java index 06cfaedd..e2bd2b07 100644 --- a/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/service/impl/AuthServiceImpl.java +++ b/snowy-plugin/snowy-plugin-auth/src/main/java/vip/xiaonuo/auth/modular/login/service/impl/AuthServiceImpl.java @@ -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); } } diff --git a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java index b31c8826..1449431a 100644 --- a/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java +++ b/snowy-plugin/snowy-plugin-biz/src/main/java/vip/xiaonuo/biz/modular/org/service/impl/BizOrgServiceImpl.java @@ -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 impleme } else { return CollectionUtil.newArrayList(); } - List> treeNodeList = bizOrgSet.stream().map(bizOrg -> + // 先根据排序码排序 + List bizOrgArrayList = CollectionUtil.sort(bizOrgSet, Comparator.comparingInt(BizOrg::getSortCode)); + // 再重置排序码,解决每次相同排序码顺序不一致的问题 + for (int i = 0; i < bizOrgArrayList.size(); i++) { + bizOrgArrayList.get(i).setSortCode(i); + } + List> treeNodeList = bizOrgArrayList.stream().map(bizOrg -> new TreeNode<>(bizOrg.getId(), bizOrg.getParentId(), bizOrg.getName(), bizOrg.getSortCode()).setExtra(JSONUtil.parseObj(bizOrg))) .collect(Collectors.toList()); diff --git a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/push/util/DevPushWorkWechatUtil.java b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/push/util/DevPushWorkWechatUtil.java index 837c058d..723f2222 100644 --- a/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/push/util/DevPushWorkWechatUtil.java +++ b/snowy-plugin/snowy-plugin-dev/src/main/java/vip/xiaonuo/dev/modular/push/util/DevPushWorkWechatUtil.java @@ -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())); diff --git a/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileButtonServiceImpl.java b/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileButtonServiceImpl.java index df04dce3..6fe0f560 100644 --- a/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileButtonServiceImpl.java +++ b/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileButtonServiceImpl.java @@ -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 leafMenuList = CollectionUtil.newArrayList(); + MobileMenu rootMobileMenu = new MobileMenu(); + rootMobileMenu.setId("0"); + rootMobileMenu.setParentId("-1"); + rootMobileMenu.setSortCode(-1); + mobileMenuList.add(rootMobileMenu); List> 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 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); } diff --git a/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileModuleServiceImpl.java b/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileModuleServiceImpl.java index ccc3c384..a56abd63 100644 --- a/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileModuleServiceImpl.java +++ b/snowy-plugin/snowy-plugin-mobile/src/main/java/vip/xiaonuo/mobile/modular/resource/service/impl/MobileModuleServiceImpl.java @@ -88,7 +88,9 @@ public class MobileModuleServiceImpl extends ServiceImpl 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); diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/resource/service/impl/SysModuleServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/resource/service/impl/SysModuleServiceImpl.java index ad6b367c..afc4540a 100644 --- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/resource/service/impl/SysModuleServiceImpl.java +++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/resource/service/impl/SysModuleServiceImpl.java @@ -92,7 +92,9 @@ public class SysModuleServiceImpl extends ServiceImpl 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() { - @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 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() { + @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/"); + } +} diff --git a/snowy-web-app/src/main/resources/_sql/snowy_mysql.sql b/snowy-web-app/src/main/resources/_sql/snowy_mysql.sql index f9533061..5d067fa4 100644 --- a/snowy-web-app/src/main/resources/_sql/snowy_mysql.sql +++ b/snowy-web-app/src/main/resources/_sql/snowy_mysql.sql @@ -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); diff --git a/snowy-web-app/src/main/resources/application.properties b/snowy-web-app/src/main/resources/application.properties index 7341fe54..35fa6054 100644 --- a/snowy-web-app/src/main/resources/application.properties +++ b/snowy-web-app/src/main/resources/application.properties @@ -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