├── .docs ├── intro │ ├── application-config-example.md │ ├── create-service-example.md │ └── some-code-specification.md └── sql │ ├── common │ ├── mysql │ │ └── common-plugin.sql │ └── oracle │ │ └── common-plugin.oracle.sql │ ├── framework │ ├── mysql │ │ ├── data.sql │ │ └── schema.sql │ └── oracle │ │ ├── data.oracle.sql │ │ └── schema.orace.sql │ └── other │ ├── nacos_v1.4.6.sql │ └── xxl-job_v2.4.0.sql ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── LICENSE ├── README.md ├── ci └── git-hooks │ └── commit-msg ├── common ├── core │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── common │ │ └── core │ │ ├── annotation │ │ └── ExcelField.java │ │ ├── enums │ │ ├── ApiErrorCode.java │ │ └── ExtTypeCode.java │ │ ├── exception │ │ ├── ApiException.java │ │ ├── BaseException.java │ │ ├── ExtException.java │ │ └── UtilException.java │ │ ├── extension │ │ ├── pipeline │ │ │ ├── AbstractPipelineContext.java │ │ │ ├── DefaultPipelineFilterChain.java │ │ │ ├── PipelineContext.java │ │ │ ├── PipelineFilterChain.java │ │ │ ├── PipelineGenerator.java │ │ │ ├── filter │ │ │ │ ├── AbstractPipelineFilter.java │ │ │ │ └── PipelineFilter.java │ │ │ └── selector │ │ │ │ ├── FilterSelector.java │ │ │ │ └── LocalListFilterSelector.java │ │ └── strategy │ │ │ ├── AbstractStrategyExecutor.java │ │ │ ├── StrategyContext.java │ │ │ ├── StrategyExecutor.java │ │ │ ├── StrategySelectorExecutor.java │ │ │ └── StrategyService.java │ │ ├── util │ │ ├── AssertUtil.java │ │ ├── JacksonUtil.java │ │ ├── OfficeUtil.java │ │ ├── SpringUtil.java │ │ ├── TokenUtil.java │ │ └── TreeUtil.java │ │ └── web │ │ ├── convertor │ │ ├── ParamEnumConvertor.java │ │ └── ParamEnumConvertorFactory.java │ │ └── response │ │ ├── ApiResult.java │ │ ├── ApiStatus.java │ │ ├── PageParams.java │ │ └── PageResult.java ├── plugin │ ├── actuator │ │ └── pom.xml │ ├── cache │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── cache │ │ │ ├── config │ │ │ ├── CacheConfig.java │ │ │ └── RedisConfig.java │ │ │ ├── consts │ │ │ └── CacheConst.java │ │ │ ├── exception │ │ │ ├── DLCacheException.java │ │ │ ├── RedisLockException.java │ │ │ └── RedisMessageException.java │ │ │ ├── l2cache │ │ │ ├── DLCacheProperties.java │ │ │ ├── cache │ │ │ │ ├── DLCache.java │ │ │ │ └── DLCacheManager.java │ │ │ └── sync │ │ │ │ ├── DLCacheRefreshListener.java │ │ │ │ └── DLCacheRefreshMsg.java │ │ │ ├── listener │ │ │ ├── RedisExpiredHandler.java │ │ │ ├── RedisExpiredListener.java │ │ │ └── RedisMessageListener.java │ │ │ └── util │ │ │ ├── KeyGeneUtil.java │ │ │ ├── RedisLockKit.java │ │ │ └── RedisUtil.java │ ├── concurrent │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── concurrent │ │ │ ├── annotation │ │ │ └── RateLimit.java │ │ │ ├── aspect │ │ │ └── RateLimitAspect.java │ │ │ ├── config │ │ │ └── DynamicTpConfig.java │ │ │ ├── exception │ │ │ └── RateLimitException.java │ │ │ └── util │ │ │ └── TransmitUtil.java │ ├── datasource │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── datasource │ │ │ ├── annotation │ │ │ └── DynamicDs.java │ │ │ ├── aspect │ │ │ └── DynamicDsAspect.java │ │ │ ├── config │ │ │ ├── DruidConfig.java │ │ │ ├── DynamicDsAutoConfig.java │ │ │ └── DynamicDsProperties.java │ │ │ ├── dynamic │ │ │ ├── DynamicDs.java │ │ │ └── DynamicDsHolder.java │ │ │ ├── exception │ │ │ └── DynamicDsException.java │ │ │ └── util │ │ │ └── TransactionUtil.java │ ├── job │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── job │ │ │ └── config │ │ │ ├── XxlJobAutoConfig.java │ │ │ └── XxlJobProperties.java │ ├── log │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── log │ │ │ ├── annotation │ │ │ └── ApiLogger.java │ │ │ ├── aspect │ │ │ └── ApiLoggerAspect.java │ │ │ ├── handler │ │ │ └── AbstractApiLogHandler.java │ │ │ └── model │ │ │ ├── BaseLogInfo.java │ │ │ └── LogInfo.java │ ├── mq │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── mq │ │ │ ├── config │ │ │ ├── RabbitAutoConfig.java │ │ │ ├── RabbitProperties.java │ │ │ ├── TxMsgAutoConfig.java │ │ │ └── TxMsgProperties.java │ │ │ ├── consts │ │ │ └── RabbitConst.java │ │ │ ├── exception │ │ │ └── TxMsgException.java │ │ │ ├── handler │ │ │ └── AbstractTxMsgHandler.java │ │ │ ├── job │ │ │ └── TxMsgJobRegister.java │ │ │ ├── model │ │ │ ├── BaseTxMsg.java │ │ │ └── TxMsg.java │ │ │ ├── rabbit │ │ │ ├── RabbitCallback.java │ │ │ └── RabbitConverter.java │ │ │ └── util │ │ │ ├── RabbitUtil.java │ │ │ └── TxMsgKit.java │ ├── mybatis │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── mybatis │ │ │ ├── annotation │ │ │ └── UseDataScope.java │ │ │ ├── aspect │ │ │ └── DataScopeAspect.java │ │ │ ├── config │ │ │ └── MybatisConfig.java │ │ │ ├── converter │ │ │ ├── BoolToIntTypeHandler.java │ │ │ ├── DefaultEnumTypeHandler.java │ │ │ ├── EnumDbConvertor.java │ │ │ └── ObjToStrTypeHandler.java │ │ │ └── handler │ │ │ ├── AbstractObjectFillHandler.java │ │ │ ├── DataScopePermissionHandler.java │ │ │ └── DataScopeResolver.java │ ├── pom.xml │ ├── storage │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── cadecode │ │ │ └── uniboot │ │ │ └── common │ │ │ └── plugin │ │ │ └── storage │ │ │ ├── config │ │ │ └── XFileStorageConfig.java │ │ │ ├── handler │ │ │ └── AbstractStorageHandler.java │ │ │ └── util │ │ │ └── FtpPoolUtil.java │ └── swagger │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── common │ │ └── plugin │ │ └── swagger │ │ ├── config │ │ ├── SwaggerAutoConfig.java │ │ └── SwaggerProperties.java │ │ └── util │ │ └── SwaggerRegisterKit.java └── pom.xml ├── dependencies └── pom.xml ├── example ├── example_api │ └── pom.xml ├── example_svc │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── cadecode │ │ │ │ └── uniboot │ │ │ │ └── example │ │ │ │ └── svc │ │ │ │ ├── UniExampleApplication.java │ │ │ │ ├── bean │ │ │ │ └── data │ │ │ │ │ └── ExampleMsgDo.java │ │ │ │ ├── consumer │ │ │ │ └── RabbitExampleConsumer.java │ │ │ │ ├── controller │ │ │ │ ├── DLCacheController.java │ │ │ │ ├── DynamicDsController.java │ │ │ │ ├── DynamicTpController.java │ │ │ │ ├── LogExampleController.java │ │ │ │ ├── MqExampleController.java │ │ │ │ ├── RpcExampleController.java │ │ │ │ ├── SpringRetryController.java │ │ │ │ ├── TtlExecutorController.java │ │ │ │ └── XFileStorageController.java │ │ │ │ └── job │ │ │ │ └── XxJobDemoJob.java │ │ └── resources │ │ │ ├── banner.txt │ │ │ ├── bootstrap.yml │ │ │ ├── logback-spring.xml │ │ │ └── spy.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── example │ │ └── svc │ │ └── UniExampleApplicationTests.java └── pom.xml ├── framework ├── framework_api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── framework │ │ └── api │ │ ├── bean │ │ └── dto │ │ │ ├── SysApiDto.java │ │ │ └── SysUserDto.java │ │ ├── consts │ │ ├── HttpConst.java │ │ ├── KeyPrefixConst.java │ │ ├── LogTypeConst.java │ │ └── SvcNameConst.java │ │ ├── enums │ │ ├── AuthErrorEnum.java │ │ ├── AuthModelEnum.java │ │ └── FrameErrorEnum.java │ │ └── feignclient │ │ ├── ExampleClient.java │ │ ├── SysApiClient.java │ │ └── SysUserClient.java ├── framework_base │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── framework │ │ └── base │ │ ├── advisor │ │ ├── ApiExceptionAdvisor.java │ │ ├── ApiResultAdvisor.java │ │ └── FrameExceptionAdvisor.java │ │ ├── annotation │ │ ├── ApiFormat.java │ │ └── ApiInner.java │ │ ├── aspect │ │ └── ApiInnerAspect.java │ │ ├── config │ │ ├── FeignConfig.java │ │ ├── JacksonConfig.java │ │ ├── PluginConfig.java │ │ ├── RetryConfig.java │ │ ├── SecurityConfig.java │ │ ├── ThreadPoolConfig.java │ │ └── WebMvcConfig.java │ │ ├── enums │ │ └── RoleTypeEnum.java │ │ ├── exception │ │ └── RetryableException.java │ │ ├── feign │ │ ├── FeignClientDecorator.java │ │ └── FeignErrorDecoder.java │ │ ├── plugin │ │ ├── bean │ │ │ ├── po │ │ │ │ ├── PlgFile.java │ │ │ │ ├── PlgLog.java │ │ │ │ └── PlgMqMsg.java │ │ │ └── vo │ │ │ │ ├── PlgFileVo.java │ │ │ │ ├── PlgLogVo.java │ │ │ │ ├── PlgMqMsgVo.java │ │ │ │ └── PlgSwaggerVo.java │ │ ├── controller │ │ │ ├── PlgFileController.java │ │ │ ├── PlgLogController.java │ │ │ ├── PlgMqMsgController.java │ │ │ └── PlgSwaggerController.java │ │ ├── convert │ │ │ ├── PlgFileConvert.java │ │ │ ├── PlgLogConvert.java │ │ │ └── PlgMqMsgConvert.java │ │ ├── enums │ │ │ ├── ConsumeStateEnum.java │ │ │ └── SendStateEnum.java │ │ ├── handler │ │ │ ├── LogSaveHandler.java │ │ │ ├── MqTxMsgHandler.java │ │ │ ├── MybatisFillHandler.java │ │ │ ├── StorageRecordHandler.java │ │ │ └── UserRoleDataScopeResolver.java │ │ ├── mapper │ │ │ ├── PlgFileMapper.java │ │ │ ├── PlgLogMapper.java │ │ │ └── PlgMqMsgMapper.java │ │ ├── service │ │ │ ├── PlgFileService.java │ │ │ ├── PlgLogService.java │ │ │ └── PlgMqMsgService.java │ │ └── serviceimpl │ │ │ ├── PlgFileServiceImpl.java │ │ │ ├── PlgLogServiceImpl.java │ │ │ └── PlgMqMsgServiceImpl.java │ │ ├── security │ │ ├── filter │ │ │ ├── CorsAllowAnyFilter.java │ │ │ ├── TokenAuthFilter.java │ │ │ └── TraceInfoFilter.java │ │ ├── handler │ │ │ ├── NoAuthenticationHandler.java │ │ │ └── NoAuthorityHandler.java │ │ ├── model │ │ │ └── SysUserDetails.java │ │ ├── strategy │ │ │ ├── JwtTokenAuthStrategyImpl.java │ │ │ ├── RedisTokenAuthStrategyImpl.java │ │ │ └── TokenAuthStrategy.java │ │ └── voter │ │ │ └── DataBaseRoleVoter.java │ │ └── util │ │ ├── RequestUtil.java │ │ └── SecurityUtil.java ├── framework_svc │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── cadecode │ │ │ │ └── uniboot │ │ │ │ └── framework │ │ │ │ └── svc │ │ │ │ ├── UniFrameworkApplication.java │ │ │ │ ├── bean │ │ │ │ ├── po │ │ │ │ │ ├── SysApi.java │ │ │ │ │ ├── SysDept.java │ │ │ │ │ ├── SysDict.java │ │ │ │ │ ├── SysMenu.java │ │ │ │ │ ├── SysRole.java │ │ │ │ │ └── SysUser.java │ │ │ │ └── vo │ │ │ │ │ ├── SysApiVo.java │ │ │ │ │ ├── SysDeptVo.java │ │ │ │ │ ├── SysDictVo.java │ │ │ │ │ ├── SysMenuVo.java │ │ │ │ │ ├── SysRoleVo.java │ │ │ │ │ └── SysUserVo.java │ │ │ │ ├── config │ │ │ │ ├── FrameSecurityConfig.java │ │ │ │ └── UniFrameworkConfig.java │ │ │ │ ├── controller │ │ │ │ ├── AuthController.java │ │ │ │ ├── CommonController.java │ │ │ │ ├── ExampleControllerR.java │ │ │ │ ├── SysApiController.java │ │ │ │ ├── SysApiControllerR.java │ │ │ │ ├── SysDeptController.java │ │ │ │ ├── SysDictController.java │ │ │ │ ├── SysMenuController.java │ │ │ │ ├── SysRoleController.java │ │ │ │ ├── SysUserController.java │ │ │ │ └── SysUserControllerR.java │ │ │ │ ├── convert │ │ │ │ ├── SysApiConvert.java │ │ │ │ ├── SysDeptConvert.java │ │ │ │ ├── SysDictConvert.java │ │ │ │ ├── SysMenuConvert.java │ │ │ │ ├── SysRoleConvert.java │ │ │ │ └── SysUserConvert.java │ │ │ │ ├── mapper │ │ │ │ ├── SysApiMapper.java │ │ │ │ ├── SysDeptMapper.java │ │ │ │ ├── SysDictMapper.java │ │ │ │ ├── SysMenuMapper.java │ │ │ │ ├── SysRoleMapper.java │ │ │ │ └── SysUserMapper.java │ │ │ │ ├── security │ │ │ │ ├── JwtLoginSuccessHandleService.java │ │ │ │ ├── LoginFailureHandler.java │ │ │ │ ├── LoginSuccessHandleService.java │ │ │ │ ├── LoginSuccessHandler.java │ │ │ │ ├── RedisLoginSuccessHandleService.java │ │ │ │ └── SignOutSuccessHandler.java │ │ │ │ ├── service │ │ │ │ ├── SysApiService.java │ │ │ │ ├── SysDeptService.java │ │ │ │ ├── SysDictService.java │ │ │ │ ├── SysMenuService.java │ │ │ │ ├── SysRoleService.java │ │ │ │ └── SysUserService.java │ │ │ │ ├── serviceimpl │ │ │ │ ├── SysApiServiceImpl.java │ │ │ │ ├── SysDeptServiceImpl.java │ │ │ │ ├── SysDictServiceImpl.java │ │ │ │ ├── SysMenuServiceImpl.java │ │ │ │ ├── SysRoleServiceImpl.java │ │ │ │ └── SysUserServiceImpl.java │ │ │ │ └── util │ │ │ │ └── FileUploadUtil.java │ │ └── resources │ │ │ ├── banner.txt │ │ │ ├── bootstrap.yml │ │ │ ├── logback-spring.xml │ │ │ ├── mapper │ │ │ ├── mysql │ │ │ │ ├── SysApiMapper.xml │ │ │ │ ├── SysMenuMapper.xml │ │ │ │ ├── SysRoleMapper.xml │ │ │ │ └── SysUserMapper.xml │ │ │ └── oracle │ │ │ │ ├── SysApiMapper.xml │ │ │ │ ├── SysMenuMapper.xml │ │ │ │ ├── SysRoleMapper.xml │ │ │ │ └── SysUserMapper.xml │ │ │ └── spy.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── framework │ │ └── svc │ │ ├── JasyptEncryptorTest.java │ │ └── UniFrameworkApplicationTests.java └── pom.xml ├── gateway ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── cadecode │ │ └── uniboot │ │ └── gateway │ │ ├── UniGatewayApplication.java │ │ ├── config │ │ └── GatewaySwaggerConfig.java │ │ ├── controller │ │ └── SwaggerController.java │ │ ├── filter │ │ ├── RequestHeaderFilter.java │ │ └── TraceInfoFilter.java │ │ └── handler │ │ └── GlobalExceptionHandler.java │ └── resources │ ├── banner.txt │ ├── bootstrap.yml │ ├── logback-spring.xml │ └── spy.properties └── pom.xml /.docs/intro/some-code-specification.md: -------------------------------------------------------------------------------- 1 | ## 一些代码规约 2 | 3 | ### 常见命名规范 4 | 5 | web 接口,以 Controller 结尾,放于 controller 包 6 | 7 | service,以 Service 结尾,放于 service 包 8 | 9 | service 实现,以 ServiceImpl 结尾,放于 serviceimpl 包 10 | 11 | dao,以 Mapper 结尾,放于 mapper 包 12 | 13 | manager(复杂业务聚合处理),以 Manager 结尾,放于 manager 包 14 | 15 | feign 客户端,以 Client 结尾,放于 feignclient 包 16 | 17 | bean 转换器,以 Convert 结尾,放于 convert 包 18 | 19 | aop 切面,以 Aspect 结尾,放于 aspect 包 20 | 21 | 常量类,以 Const 结尾,放于 consts 包 22 | 23 | 枚举类,以 Enum 结尾,放于 enums 包 24 | 25 | ### bean 的命名 26 | 27 | 在 bean 包下维护各类简单 bean(贫血模型) 28 | 29 | 数据表实体,类名和表名一致,放于 bean.po 或 bean.entity 包 30 | 31 | web 请求/返回实体,以 ReqVo/ResVo 结尾,放于 bean.vo 包 32 | 33 | feign 请求/返回实体,以 ReqDto/ResDto 结尾,放于 bean.dto 包 34 | 35 | mongoDB 实体,以 doc 结尾,放于 bean.doc 包 36 | 37 | 复杂业务实体,以 Bo 结尾,放于 bean.bo 包 38 | 39 | 其他数据实体,以 Do 结尾并冠以前缀,放于 bean.data 包,如 40 | 41 | - 缓存实体,以 CacheDo 结尾 42 | - es 实体,以 IdxDo 结尾 43 | - 消息实体,以 MsgDo 结尾 44 | 45 | 另外,一些独立于业务之外的简单 bean,由于工具类、框架配置等的需要,可放于 model 包下,也可使用内部类方式 46 | 47 | ### 工具类的命名 48 | 49 | 工具类放于 util 包 50 | 51 | 一般使用单数的 Util 结尾,当工具类需要注入使用时,推荐以 Kit 结尾进行区分 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Bug Report 4 | about: 问题报告 5 | 6 | --- 7 | 8 | ### Describe the bug 问题描述 9 | 10 | A clear and concise description of what the bug is. 简洁有效的说明问题。 11 | 12 | ### To Reproduce 重现问题 13 | 14 | Steps to reproduce the behavior. 把遇到的问题的发生步骤下下来: 15 | 16 | 1. xxx 17 | 2. xxx 18 | 19 | ### Expected behavior 期望效果 20 | 21 | A clear and concise description of what you expected to happen. 简单描述期望达成的效果。 22 | 23 | ### Screenshots 相关截图 24 | 25 | If applicable, add screenshots to help explain your problem. 如有必要,可以截图说明 26 | 27 | ### Version 版本说明 28 | 29 | Provide version information. 提供相关版本信息。 30 | 31 | 1. JDK 版本:8 32 | 2. xxx 版本:xxx 33 | 34 | ### Additional context 其他说明 35 | 36 | Add any other context about the problem here. 添加你认为有必要的补充内容。 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Feature Request 4 | about: 功能需求 5 | 6 | --- 7 | 8 | ### Describe the request 需求描述 9 | 10 | A clear and concise description of what the request is. 简洁有效的说明需求。 11 | 12 | ### Describe the solution 建议描述 13 | 14 | If applicable, add screenshots to help explain your problem. 如有必要,可以截图说明 15 | 16 | ### Additional context 其他说明 17 | 18 | Add any other context about the problem here. 添加你认为有必要的补充内容。 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | 35 | # Custom 36 | logs 37 | 38 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "app"] 2 | path = app 3 | url = https://github.com/cadecode/uni-boot-cloud-vue.git 4 | -------------------------------------------------------------------------------- /ci/git-hooks/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 获取提交信息 3 | commit_msg_file=$(git rev-parse --git-dir)/COMMIT_EDITMSG 4 | commit_msg=$(head -n 1 ${commit_msg_file}) 5 | # 使用正则匹配 Angular 提交日志格式 6 | regex="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip|workflow|release)(\(.+\))?: .{1,72}$" 7 | 8 | if [[ ! ${commit_msg} =~ ${regex} ]]; then 9 | echo "Error: Commit message format does not comply with Angular commit message convention" 10 | echo "The correct format is: type(scope): short description (not exceeding 72 characters)" 11 | echo "For example: feat(core): Add new feature" 12 | exit 1 13 | fi 14 | 15 | exit 0 16 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/annotation/ExcelField.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Excel 字段注解 7 | * 基于 hutool-poi,提供注解支持 8 | * 9 | * @author Cade Li 10 | * @date 2023/6/9 11 | */ 12 | @Target(ElementType.FIELD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | public @interface ExcelField { 16 | 17 | /** 18 | * 按表头对应名称映射字段 19 | * 读:用于根据表头确定列,比 colIndex 优先级高 20 | * 写:用于确定写出时的表头 21 | * 注意:由于使用 BeanUtil 进行 Map 到 Bean 的拷贝,即便 headAlias/colIndex 都没有生效,默认同名属性也会拷贝成功 22 | */ 23 | String headAlias() default ""; 24 | 25 | /** 26 | * 按列顺序映射字段 27 | * 读:在没有设置 headAlias 时 / 在读取没有表头的表格时用于确定列 28 | * 写:用于确定写出时列的顺序 29 | * 注意:多个字段 colIndex 不相同时只会有一个字段生效 30 | */ 31 | int colIndex() default -1; 32 | 33 | /** 34 | * 是否读时忽略 35 | */ 36 | boolean readIgnore() default false; 37 | 38 | /** 39 | * 是否写时忽略 40 | */ 41 | boolean writeIgnore() default false; 42 | } 43 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/enums/ApiErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.enums; 2 | 3 | import com.github.cadecode.uniboot.common.core.web.response.ApiStatus; 4 | 5 | /** 6 | * 通用异常错误码接口,使用枚举类继承该类,便于统一管理异常信息 7 | * 8 | * @author Cade Li 9 | * @date 2022/5/8 10 | */ 11 | public interface ApiErrorCode { 12 | 13 | String DEFAULT_CODE = "UNKNOWN"; 14 | String DEFAULT_MESSAGE = "未知错误"; 15 | 16 | default String getCode() { 17 | return DEFAULT_CODE; 18 | } 19 | 20 | default String getMessage() { 21 | return DEFAULT_MESSAGE; 22 | } 23 | 24 | default int getStatus() { 25 | return ApiStatus.SERVER_ERROR; 26 | } 27 | 28 | /** 29 | * 未知异常 30 | */ 31 | ApiErrorCode UNKNOWN = new ApiErrorCode() {}; 32 | } 33 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/enums/ExtTypeCode.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.enums; 2 | 3 | /** 4 | * 扩展类型码接口,使用枚举类继承该类,便于统一管理扩展类型 5 | * 6 | * @author Cade Li 7 | * @since 2023/6/23 8 | */ 9 | public interface ExtTypeCode { 10 | 11 | String getCode(); 12 | } 13 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.exception; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | 5 | /** 6 | * 基础异常类 7 | *

message 支持字符串模板,由 hutool {@code StrUtil.format} 提供 8 | * 9 | * @author Cade Li 10 | * @since 2024/4/23 11 | */ 12 | public class BaseException extends RuntimeException { 13 | public BaseException() { 14 | } 15 | 16 | public BaseException(String message, Object... params) { 17 | super(StrUtil.format(message, params)); 18 | } 19 | 20 | public BaseException(String message, Throwable cause, Object... params) { 21 | super(StrUtil.format(message, params), cause); 22 | } 23 | 24 | public BaseException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Object... params) { 29 | super(StrUtil.format(message, params), cause, enableSuppression, writableStackTrace); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/exception/ExtException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.exception; 2 | 3 | /** 4 | * 扩展异常 5 | * 6 | * @author Cade Li 7 | * @since 2023/6/24 8 | */ 9 | public class ExtException extends BaseException { 10 | public ExtException() { 11 | } 12 | 13 | public ExtException(String message, Object... params) { 14 | super(message, params); 15 | } 16 | 17 | public ExtException(String message, Throwable cause, Object... params) { 18 | super(message, cause, params); 19 | } 20 | 21 | public ExtException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public ExtException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Object... params) { 26 | super(message, cause, enableSuppression, writableStackTrace, params); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/exception/UtilException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.exception; 2 | 3 | /** 4 | * 工具类异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/9 8 | */ 9 | public class UtilException extends BaseException { 10 | public UtilException() { 11 | } 12 | 13 | public UtilException(String message, Object... params) { 14 | super(message, params); 15 | } 16 | 17 | public UtilException(String message, Throwable cause, Object... params) { 18 | super(message, cause, params); 19 | } 20 | 21 | public UtilException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public UtilException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Object... params) { 26 | super(message, cause, enableSuppression, writableStackTrace, params); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/AbstractPipelineContext.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ExtTypeCode; 4 | import com.github.cadecode.uniboot.common.core.extension.pipeline.selector.FilterSelector; 5 | import lombok.Getter; 6 | 7 | /** 8 | * pipeline 上下文抽象类 9 | * 10 | * @author Cade Li 11 | * @since 2023/6/25 12 | */ 13 | @Getter 14 | public abstract class AbstractPipelineContext implements PipelineContext { 15 | 16 | private final ExtTypeCode pipelineType; 17 | private final FilterSelector filterSelector; 18 | 19 | public AbstractPipelineContext(ExtTypeCode pipelineType, FilterSelector filterSelector) { 20 | this.pipelineType = pipelineType; 21 | this.filterSelector = filterSelector; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/DefaultPipelineFilterChain.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.pipeline.filter.PipelineFilter; 4 | import lombok.Setter; 5 | 6 | import java.util.Objects; 7 | 8 | /** 9 | * 过滤器链默认实现 10 | * 11 | * @author Cade Li 12 | * @date 2023/6/20 13 | */ 14 | public class DefaultPipelineFilterChain implements PipelineFilterChain { 15 | 16 | @Setter 17 | private PipelineFilterChain next; 18 | private final PipelineFilter filter; 19 | 20 | public DefaultPipelineFilterChain(PipelineFilterChain next, PipelineFilter filter) { 21 | this.next = next; 22 | this.filter = filter; 23 | } 24 | 25 | 26 | /** 27 | * 当前 filter 处理 28 | */ 29 | @Override 30 | public void filter(T context) { 31 | filter.doFilter(context, this); 32 | } 33 | 34 | /** 35 | * 下一 filter 处理 36 | */ 37 | @Override 38 | public void next(T context) { 39 | if (Objects.nonNull(this.next)) { 40 | this.next.filter(context); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/PipelineContext.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ExtTypeCode; 4 | import com.github.cadecode.uniboot.common.core.extension.pipeline.selector.FilterSelector; 5 | 6 | /** 7 | * pipeline 上下文 8 | * 9 | * @author Cade Li 10 | * @since 2023/6/23 11 | */ 12 | public interface PipelineContext { 13 | 14 | ExtTypeCode getPipelineType(); 15 | 16 | FilterSelector getFilterSelector(); 17 | 18 | boolean continueChain(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/PipelineFilterChain.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline; 2 | 3 | /** 4 | * 过滤器链接口 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/20 8 | */ 9 | public interface PipelineFilterChain { 10 | 11 | void filter(T context); 12 | 13 | void next(T context); 14 | } 15 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/PipelineGenerator.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.pipeline.filter.PipelineFilter; 4 | import lombok.Getter; 5 | 6 | import java.util.Objects; 7 | 8 | /** 9 | * 管道构建器 10 | * 11 | * @author Cade Li 12 | * @date 2023/6/20 13 | */ 14 | public class PipelineGenerator, A extends PipelineContext> { 15 | 16 | @Getter 17 | private DefaultPipelineFilterChain firstChain; 18 | private DefaultPipelineFilterChain lastChain; 19 | 20 | public void appendFilter(T filter) { 21 | DefaultPipelineFilterChain newChain = new DefaultPipelineFilterChain<>(null, filter); 22 | if (Objects.isNull(firstChain)) { 23 | firstChain = newChain; 24 | lastChain = firstChain; 25 | return; 26 | } 27 | lastChain.setNext(newChain); 28 | lastChain = newChain; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/filter/AbstractPipelineFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline.filter; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.pipeline.PipelineContext; 4 | import com.github.cadecode.uniboot.common.core.extension.pipeline.PipelineFilterChain; 5 | 6 | /** 7 | * 过滤器抽象类 8 | * 9 | * @author Cade Li 10 | * @date 2023/6/20 11 | */ 12 | public abstract class AbstractPipelineFilter implements PipelineFilter { 13 | 14 | /** 15 | * 过滤方法模板 16 | */ 17 | @Override 18 | public void doFilter(T context, PipelineFilterChain filterChain) { 19 | // 如果包含该 filter 20 | if (context.getFilterSelector().matchFilter(this.getClass().getSimpleName())) { 21 | handle(context); 22 | } 23 | if (context.continueChain()) { 24 | filterChain.next(context); 25 | } 26 | } 27 | 28 | /** 29 | * 过滤处理主逻辑 30 | */ 31 | public abstract void handle(T context); 32 | } 33 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/filter/PipelineFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline.filter; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.pipeline.PipelineContext; 4 | import com.github.cadecode.uniboot.common.core.extension.pipeline.PipelineFilterChain; 5 | 6 | /** 7 | * 过滤器接口 8 | * 9 | * @author Cade Li 10 | * @date 2023/6/20 11 | */ 12 | public interface PipelineFilter { 13 | 14 | void doFilter(T context, PipelineFilterChain filterChain); 15 | } 16 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/selector/FilterSelector.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline.selector; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 过滤器选择器 7 | * 8 | * @author Cade Li 9 | * @date 2023/6/20 10 | */ 11 | public interface FilterSelector { 12 | 13 | boolean matchFilter(String currFilterName); 14 | 15 | List getFilterNames(); 16 | } 17 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/pipeline/selector/LocalListFilterSelector.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.pipeline.selector; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.NoArgsConstructor; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Objects; 9 | 10 | /** 11 | * 基于本地 list 的过滤器选择器 12 | * 13 | * @author Cade Li 14 | * @date 2023/6/20 15 | */ 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class LocalListFilterSelector implements FilterSelector { 19 | 20 | private List filterNames = new ArrayList<>(); 21 | 22 | @Override 23 | public boolean matchFilter(String currFilterName) { 24 | return filterNames.stream().anyMatch(o -> Objects.equals(currFilterName, o)); 25 | } 26 | 27 | @Override 28 | public List getFilterNames() { 29 | return filterNames; 30 | } 31 | 32 | public void addFilter(String filterName) { 33 | filterNames.add(filterName); 34 | } 35 | 36 | private void addFilters(List filterNames) { 37 | this.filterNames.addAll(filterNames); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/strategy/AbstractStrategyExecutor.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.strategy; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | /** 7 | * 策略执行器抽象类 8 | * 9 | * @author Cade Li 10 | * @since 2023/6/24 11 | */ 12 | public abstract class AbstractStrategyExecutor implements StrategyExecutor { 13 | 14 | public abstract Optional selectService(Class clazz, StrategyContext context); 15 | 16 | public abstract List selectServices(Class clazz, StrategyContext context); 17 | } 18 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/strategy/StrategyContext.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.strategy; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ExtTypeCode; 4 | 5 | /** 6 | * 策略上下文 7 | * 8 | * @author Cade Li 9 | * @since 2023/6/25 10 | */ 11 | public interface StrategyContext { 12 | 13 | ExtTypeCode getStrategyType(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/strategy/StrategyExecutor.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.strategy; 2 | 3 | import java.util.List; 4 | import java.util.function.Consumer; 5 | import java.util.function.Function; 6 | 7 | /** 8 | * 策略执行器接口 9 | * 10 | * @author Cade Li 11 | * @since 2023/6/24 12 | */ 13 | public interface StrategyExecutor { 14 | 15 | void execute(Class clazz, StrategyContext context, Consumer consumer); 16 | 17 | void executeAll(Class clazz, StrategyContext context, Consumer consumer); 18 | 19 | R submit(Class clazz, StrategyContext context, Function function); 20 | 21 | List submitAll(Class clazz, StrategyContext context, Function function); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/extension/strategy/StrategyService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.extension.strategy; 2 | 3 | import org.springframework.plugin.core.Plugin; 4 | 5 | /** 6 | * 策略模式统一服务接口 7 | * 8 | * @author Cade Li 9 | * @since 2023/6/23 10 | */ 11 | public interface StrategyService extends Plugin { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/util/TreeUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.util; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | 5 | import java.util.List; 6 | import java.util.function.BiConsumer; 7 | import java.util.function.Function; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Tree 工具 12 | * 13 | * @author Cade Li 14 | * @since 2023/11/26 15 | */ 16 | public class TreeUtil { 17 | 18 | /** 19 | * List 树形化 20 | * 21 | * @param list 原数据列表 22 | * @param rootId root id 23 | * @param idGetter 获取 id 的方法 24 | * @param parentIdGetter 获取 parentId 的方法 25 | * @param childrenSetter 设置 children 的方法 26 | * @return 树形化之后的列表 27 | * @param 原数据类型 28 | * @param 数据 ID 类型 29 | */ 30 | public static List listToTree(List list, 31 | L rootId, 32 | Function idGetter, 33 | Function parentIdGetter, 34 | BiConsumer> childrenSetter) { 35 | List parentList = list.stream() 36 | .filter(o -> ObjUtil.equals(rootId, parentIdGetter.apply(o))) 37 | .collect(Collectors.toList()); 38 | parentList.forEach(p -> { 39 | List children = list.stream() 40 | .filter(c -> ObjUtil.equals(parentIdGetter.apply(c), idGetter.apply(p))) 41 | .peek(c -> childrenSetter.accept(c, listToTree(list, idGetter.apply(c), idGetter, parentIdGetter, childrenSetter))) 42 | .collect(Collectors.toList()); 43 | childrenSetter.accept(p, children); 44 | }); 45 | return parentList; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/web/convertor/ParamEnumConvertor.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.web.convertor; 2 | 3 | /** 4 | * 请求参数枚举转换接口 5 | * 6 | * @author Cade Li 7 | * @date 2022/5/28 8 | */ 9 | public interface ParamEnumConvertor { 10 | 11 | /** 12 | * 返回枚举元素的对应标记 13 | */ 14 | String convertBy(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/web/convertor/ParamEnumConvertorFactory.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.web.convertor; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | import org.springframework.core.convert.converter.ConverterFactory; 5 | 6 | import java.util.Arrays; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | import static java.util.stream.Collectors.toMap; 12 | 13 | /** 14 | * spring mvc 接口参数字符串转枚举转换器工厂 15 | * 16 | * @author Cade Li 17 | * @date 2022/6/14 18 | */ 19 | public class ParamEnumConvertorFactory implements ConverterFactory { 20 | 21 | private static final Map, Converter> CONVERTER_MAP = new ConcurrentHashMap<>(); 22 | 23 | @SuppressWarnings("unchecked") 24 | @Override 25 | public Converter getConverter(Class targetType) { 26 | Converter stringConverter = CONVERTER_MAP.get(targetType); 27 | if (Objects.isNull(stringConverter)) { 28 | stringConverter = new StringEnumConvertor<>(targetType); 29 | CONVERTER_MAP.put(targetType, stringConverter); 30 | } 31 | return (Converter) stringConverter; 32 | } 33 | 34 | /** 35 | * 字符串转枚举转换器 36 | */ 37 | public static class StringEnumConvertor implements Converter { 38 | 39 | private final Map enumMap; 40 | 41 | public StringEnumConvertor(Class targetType) { 42 | enumMap = Arrays.stream(targetType.getEnumConstants()) 43 | .collect(toMap(ParamEnumConvertor::convertBy, o -> o, (p, n) -> n)); 44 | } 45 | 46 | @Override 47 | public T convert(String source) { 48 | return enumMap.get(source); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/web/response/ApiStatus.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.web.response; 2 | 3 | /** 4 | * Http 状态码 5 | * 6 | * @author Cade Li 7 | * @date 2022/5/8 8 | */ 9 | public interface ApiStatus { 10 | 11 | /** 12 | * 200 OK 13 | */ 14 | int OK = 200; 15 | /** 16 | * 400 错误的请求 17 | */ 18 | int BAD_REQUEST = 400; 19 | /** 20 | * 401 未验证 21 | */ 22 | int NO_AUTHENTICATION = 401; 23 | /** 24 | * 403 被拒绝 25 | */ 26 | int NO_AUTHORITY = 403; 27 | /** 28 | * 404 无法找到 29 | */ 30 | int NOT_FOUND = 404; 31 | /** 32 | * 405 请求方法不合适 33 | */ 34 | int BAD_REQUEST_METHOD = 405; 35 | /** 36 | * 410 已下线 37 | */ 38 | int NOT_SUPPORT = 410; 39 | /** 40 | * 429 过多的请求 41 | */ 42 | int TOO_MANY_REQUESTS = 429; 43 | /** 44 | * 500 内部服务错误 45 | */ 46 | int SERVER_ERROR = 500; 47 | /** 48 | * 502 无效代理 49 | */ 50 | int INVALID_AGENT = 502; 51 | /** 52 | * 503 服务暂时失效 53 | */ 54 | int SERVER_UNAVAILABLE = 503; 55 | /** 56 | * 504 代理超时 57 | */ 58 | int AGENT_TIMEOUT = 504; 59 | } 60 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/web/response/PageParams.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.web.response; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotNull; 6 | 7 | /** 8 | * 分页参数 9 | * 10 | * @author Cade Li 11 | * @date 2023/4/23 12 | */ 13 | @Data 14 | public class PageParams { 15 | @NotNull 16 | private Integer pageSize = 1; 17 | @NotNull 18 | private Integer pageNumber = 10; 19 | 20 | private String orderBy; 21 | } 22 | -------------------------------------------------------------------------------- /common/core/src/main/java/com/github/cadecode/uniboot/common/core/web/response/PageResult.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.core.web.response; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * 分页查询返回格式 11 | * 12 | * @author Cade Li 13 | * @date 2022/5/27 14 | */ 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class PageResult { 19 | 20 | /** 21 | * 总条数 22 | */ 23 | private Integer total; 24 | 25 | /** 26 | * 当前结果集 27 | */ 28 | private List records; 29 | } 30 | -------------------------------------------------------------------------------- /common/plugin/actuator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-actuator 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-actuator 19 | 20 | 21 | 22 | de.codecentric 23 | spring-boot-admin-starter-client 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /common/plugin/cache/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-cache 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-cache 25 | 26 | 27 | io.lettuce 28 | lettuce-core 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-redis 36 | 37 | 38 | redis.clients 39 | jedis 40 | 41 | 42 | 43 | org.apache.commons 44 | commons-pool2 45 | 46 | 47 | 48 | com.github.ben-manes.caffeine 49 | caffeine 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/consts/CacheConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.consts; 2 | 3 | /** 4 | * Cache 常量 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/17 8 | */ 9 | public class CacheConst { 10 | 11 | // cache manager name 12 | public static final String CCM_5S = "caffeineCacheManager5s"; 13 | public static final String RCM_5M = "redisCacheManager5m"; 14 | public static final String RCM_30M = "redisCacheManager30m"; 15 | // 二级缓存 16 | public static final String DL = "dlCacheManager"; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/exception/DLCacheException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.exception; 2 | 3 | /** 4 | * DLCache 异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/17 8 | */ 9 | public class DLCacheException extends RuntimeException { 10 | public DLCacheException() { 11 | super(); 12 | } 13 | 14 | public DLCacheException(String message) { 15 | super(message); 16 | } 17 | 18 | public DLCacheException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | public DLCacheException(Throwable cause) { 23 | super(cause); 24 | } 25 | 26 | protected DLCacheException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 27 | super(message, cause, enableSuppression, writableStackTrace); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/exception/RedisLockException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.exception; 2 | 3 | /** 4 | * Redis 相关异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/9 8 | */ 9 | public class RedisLockException extends RuntimeException { 10 | public RedisLockException() { 11 | } 12 | 13 | public RedisLockException(String message) { 14 | super(message); 15 | } 16 | 17 | public RedisLockException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public RedisLockException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public RedisLockException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/exception/RedisMessageException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.exception; 2 | 3 | /** 4 | * Redis 过期处理异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/13 8 | */ 9 | public class RedisMessageException extends RuntimeException { 10 | 11 | public RedisMessageException() { 12 | super(); 13 | } 14 | 15 | public RedisMessageException(String message) { 16 | super(message); 17 | } 18 | 19 | public RedisMessageException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public RedisMessageException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | protected RedisMessageException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 28 | super(message, cause, enableSuppression, writableStackTrace); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/l2cache/DLCacheProperties.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.l2cache; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.util.Map; 7 | 8 | 9 | /** 10 | * 二级缓存配置项 11 | * 12 | * @author Cade Li 13 | * @date 2023/6/15 14 | */ 15 | @Data 16 | @ConfigurationProperties(prefix = "uni-boot.cache.dl") 17 | public class DLCacheProperties { 18 | 19 | /** 20 | * 是否存储 null 值 21 | */ 22 | private boolean allowNullValues = true; 23 | 24 | /** 25 | * 过期时间,为 0 表示不过期,默认 30 分钟 26 | * 单位:毫秒 27 | */ 28 | private long defaultExpiration = 30 * 60 * 1000; 29 | 30 | /** 31 | * 针对 cacheName 设置过期时间,为 0 表示不过期 32 | * 单位:毫秒 33 | */ 34 | private Map cacheExpirationMap; 35 | 36 | /** 37 | * 本地缓存 caffeine 配置 38 | */ 39 | private LocalConfig local = new LocalConfig(); 40 | 41 | /** 42 | * 远程缓存 redis 配置 43 | */ 44 | private RemoteConfig remote = new RemoteConfig(); 45 | 46 | 47 | @Data 48 | public static class LocalConfig { 49 | 50 | /** 51 | * 初始化大小,为 0 表示默认 52 | */ 53 | private int initialCapacity; 54 | 55 | /** 56 | * 最大缓存个数,为 0 表示默认 57 | * 默认最多 5 万条 58 | */ 59 | private long maximumSize = 10000L; 60 | } 61 | 62 | @Data 63 | public static class RemoteConfig { 64 | 65 | /** 66 | * Redis pub/sub 缓存刷新通知主题 67 | */ 68 | private String syncTopic = "cache:dl:refresh:topic"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/l2cache/sync/DLCacheRefreshMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.l2cache.sync; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 二级缓存刷新消息 10 | * 11 | * @author Cade Li 12 | * @date 2023/6/15 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class DLCacheRefreshMsg { 19 | 20 | private String cacheName; 21 | 22 | private Object key; 23 | } 24 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/listener/RedisExpiredHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.listener; 2 | 3 | /** 4 | * Redis 过期时间处理器接口 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/12 8 | */ 9 | public interface RedisExpiredHandler { 10 | 11 | boolean checkKey(String key); 12 | 13 | void handle(String key); 14 | } 15 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/listener/RedisMessageListener.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.listener; 2 | 3 | import org.springframework.data.redis.connection.MessageListener; 4 | import org.springframework.data.redis.listener.Topic; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Redis 消息监听器父类 10 | * 添加 topics 方法方便注册到 RedisMessageListenerContainer 11 | * 12 | * @author Cade Li 13 | * @date 2023/6/14 14 | */ 15 | public abstract class RedisMessageListener implements MessageListener { 16 | 17 | public abstract List topics(); 18 | } 19 | -------------------------------------------------------------------------------- /common/plugin/cache/src/main/java/com/github/cadecode/uniboot/common/plugin/cache/util/KeyGeneUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.cache.util; 2 | 3 | /** 4 | * Redis key 命名生成器 5 | * 6 | * @author Cade Li 7 | * @date 2022/5/29 8 | */ 9 | public class KeyGeneUtil { 10 | 11 | public static final String SEPARATOR = ":"; 12 | 13 | /** 14 | * 生成 : 分割的 redis key 15 | * 16 | * @param prefix 前缀 17 | * @param extra 其他字符串 18 | * @return redis key 19 | */ 20 | public static String key(String prefix, Object... extra) { 21 | StringBuilder prefixBuilder = new StringBuilder(prefix); 22 | for (Object obj : extra) { 23 | prefixBuilder.append(SEPARATOR).append(obj); 24 | } 25 | return prefixBuilder.toString(); 26 | } 27 | 28 | public static String lockKey(Object... extra) { 29 | return key("lock", extra); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /common/plugin/concurrent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-concurrent 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | com.alibaba 24 | transmittable-thread-local 25 | 26 | 27 | 28 | org.dromara.dynamictp 29 | dynamic-tp-spring-cloud-starter-nacos 30 | 31 | 32 | 33 | org.dromara.dynamictp 34 | dynamic-tp-spring-boot-starter-extension-notify-email 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /common/plugin/concurrent/src/main/java/com/github/cadecode/uniboot/common/plugin/concurrent/annotation/RateLimit.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.concurrent.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | 5 | import java.lang.annotation.*; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | /** 9 | * 限流注解 10 | * 11 | * @author Cade Li 12 | * @date 2022/9/4 13 | */ 14 | @Target({ElementType.METHOD}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Documented 17 | public @interface RateLimit { 18 | 19 | 20 | @AliasFor("limitPerSecond") 21 | double value() default 1; 22 | 23 | /** 24 | * 每秒限制数量 25 | */ 26 | @AliasFor("value") 27 | double limitPerSecond() default 1; 28 | 29 | /** 30 | * 等待超时时间 31 | * <0 表示时间不限 32 | * =0 表示不等待,直接返回结果 33 | * >0 表示超时时间 34 | */ 35 | long waitTimeout() default -1; 36 | 37 | /** 38 | * 等待时间单位 39 | */ 40 | TimeUnit waitTimeUnit() default TimeUnit.SECONDS; 41 | 42 | /** 43 | * 预热时间,单位毫秒 44 | * < 0 表示不需要预热 45 | */ 46 | long warmupMillis() default -1; 47 | } 48 | -------------------------------------------------------------------------------- /common/plugin/concurrent/src/main/java/com/github/cadecode/uniboot/common/plugin/concurrent/config/DynamicTpConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.concurrent.config; 2 | 3 | import org.dromara.dynamictp.core.spring.EnableDynamicTp; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * DynamicTp Config 8 | * 9 | * @author Cade Li 10 | * @since 2023/6/9 11 | */ 12 | @EnableDynamicTp 13 | @Configuration 14 | public class DynamicTpConfig { 15 | } 16 | -------------------------------------------------------------------------------- /common/plugin/concurrent/src/main/java/com/github/cadecode/uniboot/common/plugin/concurrent/exception/RateLimitException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.concurrent.exception; 2 | 3 | /** 4 | * 限流异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/9 8 | */ 9 | public class RateLimitException extends RuntimeException{ 10 | } 11 | -------------------------------------------------------------------------------- /common/plugin/concurrent/src/main/java/com/github/cadecode/uniboot/common/plugin/concurrent/util/TransmitUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.concurrent.util; 2 | 3 | import com.alibaba.ttl.TtlCallable; 4 | import com.alibaba.ttl.TtlRunnable; 5 | import com.alibaba.ttl.threadpool.TtlExecutors; 6 | 7 | import java.util.concurrent.Callable; 8 | import java.util.concurrent.Executor; 9 | 10 | /** 11 | * Transmittable 工具类 12 | * 13 | * @author Cade Li 14 | * @since 2023/6/9 15 | */ 16 | public class TransmitUtil { 17 | 18 | // 包装线程池或者 Runnable/Callable 19 | 20 | public static Executor wrap(Executor executor) { 21 | return TtlExecutors.getTtlExecutor(executor); 22 | } 23 | 24 | public static TtlRunnable wrap(Runnable runnable) { 25 | return TtlRunnable.get(runnable); 26 | } 27 | 28 | public static TtlCallable wrap(Callable callable) { 29 | return TtlCallable.get(callable); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /common/plugin/datasource/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-datasource 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | mysql 24 | mysql-connector-java 25 | runtime 26 | 27 | 28 | 29 | p6spy 30 | p6spy 31 | 32 | 33 | 34 | com.alibaba 35 | druid-spring-boot-starter 36 | 37 | 38 | 39 | com.baomidou 40 | dynamic-datasource-spring-boot-starter 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/annotation/DynamicDs.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 指定动态数据源注解 7 | * 8 | * @author Cade Li 9 | * @date 2022/5/10 10 | */ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface DynamicDs { 15 | String value(); 16 | } 17 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/config/DynamicDsProperties.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.config; 2 | 3 | import com.zaxxer.hikari.HikariConfig; 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * HikariDataSource 的动态数据源配置 11 | * 12 | * @author Cade Li 13 | * @since 2023/6/8 14 | */ 15 | @Data 16 | @ConfigurationProperties("uni-boot.dynamic-ds") 17 | public class DynamicDsProperties { 18 | 19 | private boolean enable; 20 | 21 | /** 22 | * 主数据源 KEY 23 | */ 24 | private String master; 25 | 26 | /** 27 | * 数据源 MAP 28 | */ 29 | private Map datasource; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/dynamic/DynamicDs.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.dynamic; 2 | 3 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 4 | 5 | import javax.sql.DataSource; 6 | import java.util.Map; 7 | 8 | /** 9 | * 动态数据源类 10 | * 11 | * @author Cade Li 12 | * @date 2021/12/3 13 | */ 14 | public class DynamicDs extends AbstractRoutingDataSource { 15 | 16 | /** 17 | * 设置数据源 key 18 | */ 19 | @Override 20 | protected Object determineCurrentLookupKey() { 21 | return DynamicDsHolder.getDataSourceKey(); 22 | } 23 | 24 | /** 25 | * 设置全部数据源 26 | */ 27 | @Override 28 | public void setTargetDataSources(Map targetDataSources) { 29 | super.setTargetDataSources(targetDataSources); 30 | // 存储数据源 key 31 | DynamicDsHolder.addDataSourceKeys(targetDataSources.keySet()); 32 | } 33 | 34 | /** 35 | * 设置默认数据源 36 | */ 37 | @Override 38 | public void setDefaultTargetDataSource(Object defaultTargetDataSource) { 39 | super.setDefaultTargetDataSource(defaultTargetDataSource); 40 | } 41 | 42 | /** 43 | * 切换数据源 44 | */ 45 | @Override 46 | protected DataSource determineTargetDataSource() { 47 | return super.determineTargetDataSource(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/dynamic/DynamicDsHolder.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.dynamic; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | import java.util.Stack; 6 | 7 | /** 8 | * 动态数据源控制器 9 | * 10 | * @author Cade Li 11 | * @date 2021/12/3 12 | */ 13 | public class DynamicDsHolder { 14 | 15 | // 定义容器,存储当前线程的数据源 key,使用 stack 实现嵌套切换 16 | private static final ThreadLocal> HOLDER = ThreadLocal.withInitial(Stack::new); 17 | // 定义容器,存储所有数据源 key 18 | private static final Set KEYS = new HashSet<>(); 19 | 20 | /** 21 | * 设置数据源 key 22 | */ 23 | public static void setDataSourceKey(String key) { 24 | HOLDER.get().push(key); 25 | } 26 | 27 | /** 28 | * 取出数据源 key 29 | */ 30 | public static String getDataSourceKey() { 31 | // 栈空时返回 null,自动使用默认数据源 32 | if (HOLDER.get().isEmpty()) { 33 | return null; 34 | } 35 | return HOLDER.get().peek(); 36 | } 37 | 38 | /** 39 | * 删除数据源 key 40 | */ 41 | public static void clearDataSourceKey() { 42 | if (!HOLDER.get().isEmpty()) { 43 | HOLDER.get().pop(); 44 | } 45 | } 46 | 47 | /** 48 | * 判断是否包含数据源 49 | */ 50 | public static boolean containDataSourceKey(String key) { 51 | return KEYS.contains(key); 52 | } 53 | 54 | /** 55 | * 添加数据源 key 56 | */ 57 | public static void addDataSourceKeys(Set keys) { 58 | KEYS.addAll(keys); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/exception/DynamicDsException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.exception; 2 | 3 | /** 4 | * 动态数据源异常 5 | * 6 | * @author Cade Li 7 | * @date 2023/6/9 8 | */ 9 | public class DynamicDsException extends RuntimeException { 10 | public DynamicDsException() { 11 | } 12 | 13 | public DynamicDsException(String message) { 14 | super(message); 15 | } 16 | 17 | public DynamicDsException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public DynamicDsException(Throwable cause) { 22 | super(cause); 23 | } 24 | 25 | public DynamicDsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/plugin/datasource/src/main/java/com/github/cadecode/uniboot/common/plugin/datasource/util/TransactionUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.datasource.util; 2 | 3 | import org.springframework.transaction.support.TransactionSynchronization; 4 | import org.springframework.transaction.support.TransactionSynchronizationManager; 5 | 6 | /** 7 | * 事务工具类 8 | * 9 | * @author Cade Li 10 | * @since 2023/6/13 11 | */ 12 | public class TransactionUtil { 13 | 14 | /** 15 | * 在当前事务完成后执行回调 16 | * 17 | * @param runnable 回调 18 | */ 19 | public static void doAfterCompletion(Runnable runnable) { 20 | // 若没有事务 21 | if (!TransactionSynchronizationManager.isActualTransactionActive()) { 22 | return; 23 | } 24 | TransactionSynchronizationManager.registerSynchronization(new DoTransactionCompletion(runnable)); 25 | } 26 | 27 | public static class DoTransactionCompletion implements TransactionSynchronization { 28 | 29 | private final Runnable runnable; 30 | 31 | public DoTransactionCompletion(Runnable runnable) { 32 | this.runnable = runnable; 33 | } 34 | 35 | @Override 36 | public void afterCompletion(int status) { 37 | if (status != TransactionSynchronization.STATUS_COMMITTED) { 38 | return; 39 | } 40 | this.runnable.run(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/plugin/job/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.cadecode 8 | uni-boot-common-plugin 9 | 2024.2.0 10 | 11 | 12 | uni-boot-common-plugin-job 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | com.xuxueli 23 | xxl-job-core 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /common/plugin/job/src/main/java/com/github/cadecode/uniboot/common/plugin/job/config/XxlJobAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.job.config; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.job.config.XxlJobProperties.XxlJobAdminProperties; 4 | import com.github.cadecode.uniboot.common.plugin.job.config.XxlJobProperties.XxlJobExecutorProperties; 5 | import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | /** 13 | * xxl-job 自动配置 14 | * 15 | * @author Cade Li 16 | * @since 2023/11/10 17 | */ 18 | @Slf4j 19 | @ConditionalOnProperty(name = "xxl.job.enabled", havingValue = "true") 20 | @EnableConfigurationProperties({XxlJobProperties.class, XxlJobAdminProperties.class, XxlJobExecutorProperties.class}) 21 | @Configuration 22 | public class XxlJobAutoConfig { 23 | 24 | @Bean 25 | public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties, 26 | XxlJobAdminProperties adminProperties, 27 | XxlJobExecutorProperties executorProperties) { 28 | log.info("xxl-job config init"); 29 | // init executor 30 | XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); 31 | xxlJobSpringExecutor.setAdminAddresses(adminProperties.getAddresses()); 32 | xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken()); 33 | xxlJobSpringExecutor.setAppname(executorProperties.getAppname()); 34 | xxlJobSpringExecutor.setAddress(executorProperties.getAddress()); 35 | xxlJobSpringExecutor.setIp(executorProperties.getIp()); 36 | xxlJobSpringExecutor.setPort(executorProperties.getPort()); 37 | xxlJobSpringExecutor.setLogPath(executorProperties.getLogpath()); 38 | xxlJobSpringExecutor.setLogRetentionDays(executorProperties.getLogRetentionDays()); 39 | return xxlJobSpringExecutor; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /common/plugin/job/src/main/java/com/github/cadecode/uniboot/common/plugin/job/config/XxlJobProperties.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.job.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * xxl-job 配置项 8 | * 9 | * @author Cade Li 10 | * @since 2023/11/10 11 | */ 12 | @ConfigurationProperties(prefix = "xxl.job") 13 | @Data 14 | public class XxlJobProperties { 15 | 16 | private Boolean enabled; 17 | 18 | private String accessToken; 19 | 20 | 21 | @ConfigurationProperties(prefix = "xxl.job.admin") 22 | @Data 23 | public static class XxlJobAdminProperties { 24 | 25 | private String addresses; 26 | 27 | } 28 | 29 | @ConfigurationProperties(prefix = "xxl.job.executor") 30 | @Data 31 | public static class XxlJobExecutorProperties { 32 | 33 | private String appname; 34 | 35 | private String address; 36 | 37 | private String ip; 38 | 39 | private int port; 40 | 41 | private String logpath; 42 | 43 | private int logRetentionDays; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /common/plugin/log/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-log 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /common/plugin/log/src/main/java/com/github/cadecode/uniboot/common/plugin/log/annotation/ApiLogger.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.log.annotation; 2 | 3 | 4 | import java.lang.annotation.*; 5 | 6 | /** 7 | * 用于开启打印接口日志的注解 8 | * 9 | * @author Cade Li 10 | * @date 2021/12/4 11 | */ 12 | @Target({ElementType.TYPE, ElementType.METHOD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | public @interface ApiLogger { 16 | boolean value() default true; 17 | 18 | String type() default ""; 19 | 20 | String description() default ""; 21 | 22 | /** 23 | * 启用持久化 24 | */ 25 | boolean enableSave() default false; 26 | 27 | /** 28 | * 保存参数 29 | */ 30 | boolean saveParams() default true; 31 | 32 | /** 33 | * 保存结果 34 | */ 35 | boolean saveResult() default true; 36 | } 37 | -------------------------------------------------------------------------------- /common/plugin/log/src/main/java/com/github/cadecode/uniboot/common/plugin/log/model/BaseLogInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.log.model; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.log.annotation.ApiLogger; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | /** 8 | * api log 信息 9 | * 10 | * @author Cade Li 11 | * @since 2023/8/13 12 | */ 13 | public interface BaseLogInfo { 14 | ApiLogger getApiLogger(); 15 | 16 | Boolean getExceptional(); 17 | 18 | HttpServletRequest getRequest(); 19 | 20 | String getResultStr(); 21 | 22 | Long getTimeCost(); 23 | } 24 | -------------------------------------------------------------------------------- /common/plugin/log/src/main/java/com/github/cadecode/uniboot/common/plugin/log/model/LogInfo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.log.model; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.log.annotation.ApiLogger; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | /** 12 | * api log 信息 13 | * 14 | * @author Cade Li 15 | * @since 2023/8/19 16 | */ 17 | @Data 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @Builder 21 | public class LogInfo implements BaseLogInfo { 22 | private ApiLogger apiLogger; 23 | private Boolean exceptional; 24 | private HttpServletRequest request; 25 | private String resultStr; 26 | private Long timeCost; 27 | } 28 | -------------------------------------------------------------------------------- /common/plugin/mq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-mq 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | com.free-now.multirabbit 24 | spring-multirabbit 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-amqp 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/config/TxMsgAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.config; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * 事务消息自动配置 10 | * 11 | * @author Cade Li 12 | * @since 2023/8/20 13 | */ 14 | @Slf4j 15 | @RequiredArgsConstructor 16 | @EnableConfigurationProperties(TxMsgProperties.class) 17 | @Configuration 18 | public class TxMsgAutoConfig { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/consts/RabbitConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.consts; 2 | 3 | /** 4 | * RabbitMQ 常量 5 | * 6 | * @author Cade Li 7 | * @since 2023/8/17 8 | */ 9 | public interface RabbitConst { 10 | 11 | // 交换机类型 12 | 13 | String EXC_TYPE_TOPIC = "topic"; 14 | 15 | String EXC_TYPE_DIRECT = "direct"; 16 | 17 | String EXC_TYPE_FANOUT = "fanout"; 18 | 19 | /** 20 | * delay 交换机类型 21 | */ 22 | String EXC_TYPE_DELAYED = "x-delayed-message"; 23 | 24 | // 交换机类型 --- end 25 | 26 | // 交换机名称 27 | /** 28 | * 默认交换机 29 | */ 30 | String EXC_DEFAULT = ""; 31 | 32 | // 交换机名称 --- end 33 | } 34 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/exception/TxMsgException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.exception; 2 | 3 | /** 4 | * 事务消息异常 5 | * 6 | * @author Cade Li 7 | * @since 2023/8/20 8 | */ 9 | public class TxMsgException extends RuntimeException { 10 | public TxMsgException() { 11 | super(); 12 | } 13 | 14 | public TxMsgException(String message) { 15 | super(message); 16 | } 17 | 18 | public TxMsgException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | public TxMsgException(Throwable cause) { 23 | super(cause); 24 | } 25 | 26 | protected TxMsgException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 27 | super(message, cause, enableSuppression, writableStackTrace); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/handler/AbstractTxMsgHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.handler; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.mq.config.TxMsgProperties.MsgOption; 4 | import com.github.cadecode.uniboot.common.plugin.mq.model.BaseTxMsg; 5 | import org.springframework.amqp.core.ReturnedMessage; 6 | import org.springframework.amqp.rabbit.connection.CorrelationData; 7 | 8 | /** 9 | * 事务消息处理器 10 | * 1. 入库/更新 11 | * 2. 重试/清理记录 12 | * 13 | * @author Cade Li 14 | * @since 2023/8/20 15 | */ 16 | public abstract class AbstractTxMsgHandler { 17 | 18 | public abstract void doRetry(); 19 | 20 | public abstract void doClear(); 21 | 22 | public abstract void checkBeforeSend(BaseTxMsg txMsg, MsgOption msgOption); 23 | 24 | public abstract void sendNoTransaction(BaseTxMsg txMsg, MsgOption msgOption); 25 | 26 | public abstract void sendNotCommit(BaseTxMsg txMsg, MsgOption msgOption); 27 | 28 | public abstract void saveBeforeRegister(BaseTxMsg txMsg, MsgOption msgOption); 29 | 30 | public abstract void sendCommitted(BaseTxMsg txMsg, MsgOption msgOption); 31 | 32 | public abstract void handleConfirm(CorrelationData correlationData, boolean ack, String cause); 33 | 34 | public abstract void handleReturned(ReturnedMessage returned); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/job/TxMsgJobRegister.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.job; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | import com.github.cadecode.uniboot.common.plugin.mq.config.TxMsgProperties; 5 | import com.github.cadecode.uniboot.common.plugin.mq.handler.AbstractTxMsgHandler; 6 | import lombok.RequiredArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.boot.context.event.ApplicationStartedEvent; 9 | import org.springframework.context.event.EventListener; 10 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 11 | import org.springframework.stereotype.Component; 12 | 13 | /** 14 | * 事务消息定时任务 15 | * 16 | * @author Cade Li 17 | * @since 2023/8/19 18 | */ 19 | @Slf4j 20 | @RequiredArgsConstructor 21 | @Component 22 | public class TxMsgJobRegister { 23 | 24 | private final ThreadPoolTaskScheduler taskScheduler; 25 | 26 | private final TxMsgProperties txMsgProperties; 27 | 28 | private final AbstractTxMsgHandler txMsgTaskHandler; 29 | 30 | @EventListener(ApplicationStartedEvent.class) 31 | public void onApplicationStartedEvent() { 32 | registerRetryJob(); 33 | registerAutoClearJob(); 34 | } 35 | 36 | private void registerRetryJob() { 37 | // 消息定时 retry 38 | log.info("TxMsg task retry start, {}", txMsgProperties.getEnableRetry()); 39 | if (ObjUtil.equals(txMsgProperties.getEnableRetry(), true)) { 40 | taskScheduler.scheduleWithFixedDelay(txMsgTaskHandler::doRetry, txMsgProperties.getRetryFixDelay()); 41 | } 42 | } 43 | 44 | private void registerAutoClearJob() { 45 | // 消息定时清理 46 | log.info("TxMsg task auto clear start, {}", txMsgProperties.getAutoClear()); 47 | if (ObjUtil.equals(txMsgProperties.getAutoClear(), true)) { 48 | taskScheduler.scheduleWithFixedDelay(txMsgTaskHandler::doClear, txMsgProperties.getClearFixDelay()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/model/BaseTxMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.model; 2 | 3 | /** 4 | * 事务消息基本信息抽象 5 | * 6 | * @author Cade Li 7 | * @since 2023/8/19 8 | */ 9 | public interface BaseTxMsg { 10 | 11 | String getId(); 12 | 13 | String getBizType(); 14 | 15 | String getBizKey(); 16 | 17 | String getExchange(); 18 | 19 | String getRoutingKey(); 20 | 21 | String getMessage(); 22 | 23 | String getConnectionName(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/model/TxMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mq.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 事务消息基本信息 10 | * 11 | * @author Cade Li 12 | * @since 2023/8/18 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class TxMsg implements BaseTxMsg { 19 | 20 | private String id; 21 | 22 | /** 23 | * 业务类型 24 | */ 25 | private String bizType; 26 | 27 | /** 28 | * 业务键 29 | */ 30 | private String bizKey; 31 | 32 | private String exchange; 33 | 34 | private String routingKey; 35 | 36 | private String message; 37 | 38 | private String connectionName; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /common/plugin/mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-mybatis 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | org.mybatis.spring.boot 24 | mybatis-spring-boot-starter 25 | 26 | 27 | 28 | com.baomidou 29 | mybatis-plus-boot-starter 30 | 31 | 32 | 33 | com.github.pagehelper 34 | pagehelper-spring-boot-starter 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /common/plugin/mybatis/src/main/java/com/github/cadecode/uniboot/common/plugin/mybatis/annotation/UseDataScope.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mybatis.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 数据权限注解 7 | * 8 | * @author Cade Li 9 | * @since 2024/5/23 10 | */ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface UseDataScope { 15 | 16 | String DEFAULT_FIELD = "data_scope"; 17 | String DEFAULT_RESOLVER_NAME = "defaultDataScopeResolver"; 18 | 19 | /** 20 | * 是否启用过滤 21 | */ 22 | boolean enableFilter() default true; 23 | 24 | /** 25 | * 需要作用的字段名 26 | */ 27 | String field() default ""; 28 | 29 | /** 30 | * 权限范围解析器 Bean 名称 31 | */ 32 | String resolverName() default ""; 33 | } 34 | -------------------------------------------------------------------------------- /common/plugin/mybatis/src/main/java/com/github/cadecode/uniboot/common/plugin/mybatis/converter/BoolToIntTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mybatis.converter; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | import org.apache.ibatis.type.BaseTypeHandler; 5 | import org.apache.ibatis.type.JdbcType; 6 | import org.apache.ibatis.type.MappedJdbcTypes; 7 | import org.apache.ibatis.type.MappedTypes; 8 | 9 | import java.sql.CallableStatement; 10 | import java.sql.PreparedStatement; 11 | import java.sql.ResultSet; 12 | import java.sql.SQLException; 13 | 14 | /** 15 | * java 布尔值和 db 数字类型转换 16 | * 17 | * @author Cade Li 18 | * @since 2023/4/25 19 | */ 20 | @MappedTypes({Boolean.class}) 21 | @MappedJdbcTypes({JdbcType.INTEGER}) 22 | public class BoolToIntTypeHandler extends BaseTypeHandler { 23 | 24 | /** 25 | * 用于 mybatis plus update set mapping 参数指定 typeHandler 26 | */ 27 | public static final String MAPPING = "typeHandler=BoolToIntTypeHandler"; 28 | 29 | public static Integer mapping(Boolean o) { 30 | return ObjUtil.isNull(o) ? null : (o ? 1 : 0); 31 | } 32 | 33 | @Override 34 | public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException { 35 | if (parameter) { 36 | ps.setInt(i, 1); 37 | return; 38 | } 39 | ps.setInt(i, 0); 40 | } 41 | 42 | @Override 43 | public Boolean getNullableResult(ResultSet rs, String columnName) throws SQLException { 44 | int i = rs.getInt(columnName); 45 | return i != 0; 46 | } 47 | 48 | @Override 49 | public Boolean getNullableResult(ResultSet rs, int columnIndex) throws SQLException { 50 | int i = rs.getInt(columnIndex); 51 | return i != 0; 52 | } 53 | 54 | @Override 55 | public Boolean getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { 56 | int i = cs.getInt(columnIndex); 57 | return i != 0; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /common/plugin/mybatis/src/main/java/com/github/cadecode/uniboot/common/plugin/mybatis/converter/EnumDbConvertor.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mybatis.converter; 2 | 3 | /** 4 | * 枚举到数据库转换接口 5 | * 6 | * @author Cade Li 7 | * @since 2023/6/8 8 | */ 9 | public interface EnumDbConvertor { 10 | 11 | /** 12 | * 返回用于数据库持久化的字段内容 13 | * 数据库使用数值类型存储,如 tinyint unsigned 0~255 14 | */ 15 | Integer persistBy(); 16 | } 17 | -------------------------------------------------------------------------------- /common/plugin/mybatis/src/main/java/com/github/cadecode/uniboot/common/plugin/mybatis/handler/AbstractObjectFillHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mybatis.handler; 2 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 4 | import org.apache.ibatis.reflection.MetaObject; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * 对象填充处理器 10 | * 重写 updateUser 来实现 更新者 字段的填充 11 | * 12 | * @author Cade Li 13 | * @since 2023/6/8 14 | */ 15 | public abstract class AbstractObjectFillHandler implements MetaObjectHandler { 16 | 17 | @Override 18 | public void insertFill(MetaObject metaObject) { 19 | this.setFieldValByName("createTime", new Date(), metaObject); 20 | updateUser(metaObject); 21 | } 22 | 23 | @Override 24 | public void updateFill(MetaObject metaObject) { 25 | this.setFieldValByName("updateTime", new Date(), metaObject); 26 | updateUser(metaObject); 27 | } 28 | 29 | public void updateUser(MetaObject metaObject) { 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /common/plugin/mybatis/src/main/java/com/github/cadecode/uniboot/common/plugin/mybatis/handler/DataScopeResolver.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.mybatis.handler; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 数据权限范围 7 | * 8 | * @author Cade Li 9 | * @since 2024/5/23 10 | */ 11 | public interface DataScopeResolver { 12 | 13 | List getScopes(); 14 | 15 | default boolean isAdmin() { 16 | return false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /common/plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | pom 13 | uni-boot-common-plugin 14 | 插件集成模块 15 | 16 | 17 | log 18 | actuator 19 | cache 20 | datasource 21 | mybatis 22 | swagger 23 | concurrent 24 | mq 25 | storage 26 | job 27 | 28 | 29 | 30 | 31 | net.dreamlu 32 | mica-auto 33 | provided 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /common/plugin/storage/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.cadecode 8 | uni-boot-common-plugin 9 | 2024.2.0 10 | 11 | 12 | uni-boot-common-plugin-storage 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | org.dromara.x-file-storage 24 | x-file-storage-spring 25 | 26 | 27 | org.apache.commons 28 | commons-pool2 29 | 30 | 31 | cn.hutool 32 | hutool-extra 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /common/plugin/storage/src/main/java/com/github/cadecode/uniboot/common/plugin/storage/config/XFileStorageConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.storage.config; 2 | 3 | import org.dromara.x.file.storage.spring.EnableFileStorage; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * x-file-storage 配置类 8 | * 9 | * @author Cade Li 10 | * @since 2023/10/25 11 | */ 12 | @EnableFileStorage 13 | @Configuration 14 | public class XFileStorageConfig { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /common/plugin/storage/src/main/java/com/github/cadecode/uniboot/common/plugin/storage/handler/AbstractStorageHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.storage.handler; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.dromara.x.file.storage.core.recorder.FileRecorder; 5 | import org.springframework.beans.factory.InitializingBean; 6 | 7 | /** 8 | * 文件存储处理器 9 | * 10 | * @author Cade Li 11 | * @since 2023/10/27 12 | */ 13 | @Slf4j 14 | public abstract class AbstractStorageHandler implements FileRecorder, InitializingBean { 15 | 16 | @Override 17 | public void afterPropertiesSet() throws Exception { 18 | log.info("File storage handler {} is loaded", this.getClass().getName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /common/plugin/swagger/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-common-plugin 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-common-plugin-swagger 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | 22 | 23 | com.github.xiaoymin 24 | knife4j-spring-boot-starter 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /common/plugin/swagger/src/main/java/com/github/cadecode/uniboot/common/plugin/swagger/config/SwaggerAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.swagger.config; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.swagger.util.SwaggerRegisterKit; 4 | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.beans.factory.InitializingBean; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Import; 11 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 12 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 13 | 14 | /** 15 | * Swagger WebMvc 配置 16 | * 17 | * @author Cade Li 18 | * @since 2023/6/8 19 | */ 20 | @RequiredArgsConstructor 21 | @EnableKnife4j 22 | @Configuration 23 | @Import(SwaggerRegisterKit.class) 24 | @EnableConfigurationProperties(SwaggerProperties.class) 25 | @ConditionalOnProperty(name = "uni-boot.swagger.enable", havingValue = "true") 26 | public class SwaggerAutoConfig implements WebMvcConfigurer, InitializingBean { 27 | 28 | private final SwaggerProperties swaggerProperties; 29 | private final SwaggerRegisterKit swaggerRegisterKit; 30 | 31 | /** 32 | * 添加静态资源,映射 Swagger 网页文件 33 | */ 34 | @Override 35 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 36 | registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); 37 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 38 | } 39 | 40 | @Override 41 | public void afterPropertiesSet() { 42 | swaggerRegisterKit.registerModule(swaggerProperties); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /common/plugin/swagger/src/main/java/com/github/cadecode/uniboot/common/plugin/swagger/config/SwaggerProperties.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.common.plugin.swagger.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * Swagger2 统一配置类 10 | * 11 | * @author Cade Li 12 | * @date 2021/8/23 13 | */ 14 | @Data 15 | @ConfigurationProperties("uni-boot.swagger") 16 | public class SwaggerProperties { 17 | 18 | private boolean enable; 19 | 20 | /** 21 | * 模块和包名 MAP 22 | */ 23 | private Map module; 24 | 25 | /** 26 | * 文档标题 27 | */ 28 | private String title; 29 | 30 | /** 31 | * 文档描述 32 | */ 33 | private String description; 34 | 35 | /** 36 | * 联系人 37 | */ 38 | private String name; 39 | 40 | /** 41 | * 项目地址 42 | */ 43 | private String url; 44 | 45 | /** 46 | * 邮箱 47 | */ 48 | private String email; 49 | 50 | /** 51 | * 版本 52 | */ 53 | private String version; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | uni-boot-parent 7 | com.github.cadecode 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | pom 13 | uni-boot-common 14 | 通用模块 15 | 16 | 17 | core 18 | plugin 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/example_api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.github.cadecode 7 | uni-boot-example 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | uni-boot-example-api 13 | 微服务样例模块-API 14 | 15 | 16 | 17 | net.dreamlu 18 | mica-auto 19 | provided 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-openfeign 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-loadbalancer 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/UniExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 11 | 12 | /** 13 | * 启动类 14 | */ 15 | @MapperScan("com.github.cadecode.**.mapper") 16 | @EnableFeignClients("com.github.cadecode") 17 | @EnableDiscoveryClient 18 | @EnableAspectJAutoProxy(exposeProxy = true) 19 | @SpringBootApplication 20 | public class UniExampleApplication extends SpringBootServletInitializer { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(UniExampleApplication.class, args); 24 | } 25 | 26 | @Override 27 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 28 | return application.sources(UniExampleApplication.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/bean/data/ExampleMsgDo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.bean.data; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 测试消息 DO 10 | * 11 | * @author Cade Li 12 | * @since 2023/8/20 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class ExampleMsgDo { 19 | 20 | private String testKey; 21 | 22 | private String testVal; 23 | } 24 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/controller/DynamicDsController.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.controller; 2 | 3 | import com.baomidou.dynamic.datasource.annotation.DS; 4 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import lombok.RequiredArgsConstructor; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.context.annotation.DependsOn; 10 | import org.springframework.jdbc.datasource.AbstractDataSource; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.sql.SQLException; 16 | 17 | /** 18 | * dynamic-datasource 测试 19 | * 20 | * @author Cade Li 21 | * @date 2023/2/22 22 | */ 23 | @ApiFormat 24 | @Slf4j 25 | @RequiredArgsConstructor 26 | @Api(tags = "dynamic-datasource 测试") 27 | @DependsOn("dataSource") 28 | @RestController 29 | @RequestMapping("demo/ds") 30 | public class DynamicDsController { 31 | 32 | /** 33 | * 注入 Spring 数据源,用来查看 jdbc url 验证数据源切换 34 | */ 35 | private final AbstractDataSource dataSource; 36 | 37 | @DS("master") 38 | @ApiOperation("测试 master 数据源") 39 | @PostMapping("test_master") 40 | public String testMaster() throws SQLException { 41 | return dataSource.getConnection().getMetaData().getURL(); 42 | } 43 | 44 | @DS("slave1") 45 | @ApiOperation("测试 slave1 数据源") 46 | @PostMapping("test_slave1") 47 | public String testSlave1() throws SQLException { 48 | return dataSource.getConnection().getMetaData().getURL(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/controller/DynamicTpController.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import lombok.RequiredArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.core.task.AsyncTaskExecutor; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * dynamic-tp 测试 15 | * 16 | * @author Cade Li 17 | * @date 2023/3/15 18 | */ 19 | @ApiFormat 20 | @Slf4j 21 | @RequiredArgsConstructor 22 | @Api(tags = "动态线程池测试") 23 | @RestController 24 | @RequestMapping("demo/tp") 25 | public class DynamicTpController { 26 | 27 | private final AsyncTaskExecutor asyncExecutor; 28 | 29 | @ApiOperation("测试 reject 通知") 30 | @PostMapping("test_reject") 31 | public String testReject() { 32 | // 提交 1000 个任务,测试 reject 33 | for (int i = 0; i < 10000; i++) { 34 | int finalI = i; 35 | asyncExecutor.execute(() -> { 36 | log.info("task {}", finalI); 37 | }); 38 | } 39 | return "OK"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/controller/LogExampleController.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.log.annotation.ApiLogger; 4 | import com.github.cadecode.uniboot.framework.api.consts.LogTypeConst; 5 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import lombok.RequiredArgsConstructor; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * 日志测试 16 | * 17 | * @author Cade Li 18 | * @since 2023/8/18 19 | */ 20 | @ApiFormat 21 | @Slf4j 22 | @RequiredArgsConstructor 23 | @Api(tags = "日志测试") 24 | @RestController 25 | @RequestMapping("demo/log") 26 | public class LogExampleController { 27 | 28 | @ApiLogger(type = LogTypeConst.QUERY, description = "测试查询log",enableSave = true) 29 | @ApiOperation("测试查询log") 30 | @GetMapping("query") 31 | public String query() { 32 | return "OK"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/controller/RpcExampleController.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.framework.api.feignclient.ExampleClient; 4 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import lombok.RequiredArgsConstructor; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * RPC 测试 16 | * 17 | * @author Cade Li 18 | * @since 2023/7/29 19 | */ 20 | @ApiFormat 21 | @Slf4j 22 | @RequiredArgsConstructor 23 | @Api(tags = "RPC 测试") 24 | @RestController 25 | @RequestMapping("rpc_example") 26 | public class RpcExampleController { 27 | 28 | private final ExampleClient exampleClient; 29 | 30 | @ApiOperation("传递字符串") 31 | @PostMapping("test_str") 32 | public String testStr(@RequestParam String str) { 33 | return exampleClient.testStr(str); 34 | } 35 | 36 | @ApiOperation("返回异常结果") 37 | @PostMapping("test_result") 38 | public Object testApiResult() { 39 | return exampleClient.testApiResult(); 40 | } 41 | 42 | @ApiOperation("直接抛出异常") 43 | @PostMapping("test_exception") 44 | public Object testException() { 45 | return exampleClient.testException(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /example/example_svc/src/main/java/com/github/cadecode/uniboot/example/svc/job/XxJobDemoJob.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc.job; 2 | 3 | import com.xxl.job.core.handler.annotation.XxlJob; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * xxl-job demo 9 | * 10 | * @author Cade Li 11 | * @since 2023/11/10 12 | */ 13 | @Slf4j 14 | @Component 15 | public class XxJobDemoJob { 16 | 17 | @XxlJob("DemoJobHandleTest1") 18 | public void handleTest1() { 19 | log.info("XxJobDemoJob handleTest1"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /example/example_svc/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ _ ___ ___ ___ ___ _____ 2 | | | | | | \| | |_ _| | _ ) / _ \ / _ \ |_ _| 3 | | |_| | | .` | | | | _ \ | (_) | | (_) | | | 4 | \___/ |_|\_| |___| |___/ \___/ \___/ _|_|_ 5 | _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 6 | "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 7 | :: Spring Boot :: (${spring-boot.version}) 8 | -------------------------------------------------------------------------------- /example/example_svc/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | file: 3 | path: /log/uni_boot_admin/example 4 | 5 | spring: 6 | application: 7 | name: uni-boot-example 8 | cloud: 9 | nacos: 10 | server-addr: localhost:8848 11 | username: nacos 12 | password: nacos 13 | discovery: 14 | enabled: true 15 | namespace: uni_dev 16 | group: DEFAULT_GROUP 17 | config: 18 | enabled: true 19 | namespace: uni_dev 20 | group: DEFAULT_GROUP 21 | file-extension: yml 22 | shared-configs: 23 | - shared-config.${spring.cloud.nacos.config.file-extension} 24 | - shared-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} 25 | -------------------------------------------------------------------------------- /example/example_svc/src/main/resources/spy.properties: -------------------------------------------------------------------------------- 1 | # 配置日志拦截模块 2 | # 加入 MybatisPlus 日志 3 | modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory 4 | # 设置日志打印格式 5 | logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat 6 | customLogMessageFormat===> P6Spy: %(executionTime) ms, connection%(connectionId), sql: %(sqlSingleLine) 7 | # 设置日志系统 8 | # 使用 SLF4J 即系统日志 9 | appender=com.p6spy.engine.spy.appender.Slf4JLogger 10 | # 设置 p6spy driver 代理 11 | deregisterdrivers=true 12 | # 取消 JDBC URL 前缀 13 | useprefix=true 14 | # 设置要排除的日志记录 15 | excludecategories=info,debug,result,commit,resultset 16 | # 设置日期格式 17 | dateformat=yyyy-MM-dd HH:mm:ss 18 | # 开启慢 SQL 记录 19 | outagedetection=true 20 | # 设置慢 SQL 记录标准 2 秒 21 | outagedetectioninterval=2 22 | -------------------------------------------------------------------------------- /example/example_svc/src/test/java/com/github/cadecode/uniboot/example/svc/UniExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.example.svc; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | /** 8 | * 主测试类 9 | * 10 | * @author Cade Li 11 | * @date 2022/5/8 12 | */ 13 | @SpringBootTest 14 | public class UniExampleApplicationTests { 15 | 16 | @Test 17 | void contextLoads() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | uni-boot-parent 7 | com.github.cadecode 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | pom 13 | uni-boot-example 14 | 微服务样例模块 15 | 16 | 17 | example_api 18 | example_svc 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /framework/framework_api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.cadecode 8 | uni-boot-framework 9 | 2024.2.0 10 | 11 | 12 | uni-boot-framework-api 13 | 14 | 15 | 16 | com.github.cadecode 17 | uni-boot-common-core 18 | ${uni.version} 19 | 20 | 21 | com.github.cadecode 22 | uni-boot-common-plugin-cache 23 | ${uni.version} 24 | 25 | 26 | 27 | net.dreamlu 28 | mica-auto 29 | provided 30 | 31 | 32 | 33 | org.springframework.cloud 34 | spring-cloud-starter-openfeign 35 | 36 | 37 | io.github.openfeign 38 | feign-httpclient 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-starter-loadbalancer 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/bean/dto/SysApiDto.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.bean.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * SysApi res dto 10 | * 11 | * @author Cade Li 12 | * @since 2023/8/11 13 | */ 14 | public class SysApiDto { 15 | 16 | @Data 17 | public static class SysApiRolesResDto { 18 | 19 | private Long id; 20 | 21 | private String url; 22 | 23 | private String description; 24 | 25 | private Date createTime; 26 | 27 | private Date updateTime; 28 | 29 | private String updateUser; 30 | 31 | private List roles; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/bean/dto/SysUserDto.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.bean.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * SysUser Dto 10 | * 11 | * @author Cade Li 12 | * @since 2023/10/31 13 | */ 14 | public class SysUserDto { 15 | 16 | @Data 17 | public static class SysUserGetByUsernameResDto { 18 | private Long id; 19 | 20 | private String username; 21 | 22 | private String nickName; 23 | 24 | private Boolean enableFlag; 25 | 26 | private String sex; 27 | 28 | private String mail; 29 | 30 | private String phone; 31 | 32 | private String loginIp; 33 | 34 | private Date loginDate; 35 | 36 | private Date createTime; 37 | 38 | private Date updateTime; 39 | 40 | private String updateUser; 41 | 42 | private List roles; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/consts/HttpConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.consts; 2 | 3 | /** 4 | * HTTP 常量 5 | * 6 | * @author Cade Li 7 | * @since 2023/7/29 8 | */ 9 | public interface HttpConst { 10 | 11 | /** 12 | * token 请求头名称 13 | */ 14 | String HEAD_TOKEN = "token"; 15 | 16 | /** 17 | * 请求来源请求头名称 18 | */ 19 | String HEAD_SOURCE = "from-source"; 20 | 21 | /** 22 | * 请求来源请求头固定值 23 | */ 24 | String HEAD_SOURCE_VALUE = "inner-rpc"; 25 | 26 | /** 27 | * 用户信息请求头名称 28 | */ 29 | String HEAD_USER_DETAILS = "inner-user-details"; 30 | 31 | /** 32 | * X-Forwarded-For 33 | */ 34 | String HEAD_FORWARDED_FOR = "X-Forwarded-For"; 35 | 36 | /** 37 | * trace id 38 | */ 39 | String HEAD_TRACE_ID = "trace-id"; 40 | 41 | /** 42 | * User-Agent 43 | */ 44 | String HEAD_USER_AGENT = "User-Agent"; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/consts/KeyPrefixConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.consts; 2 | 3 | /** 4 | * Redis key 命名前缀 5 | * 6 | * @author Cade Li 7 | * @date 2022/5/29 8 | */ 9 | public interface KeyPrefixConst { 10 | 11 | /** 12 | * 登录用户信息 13 | */ 14 | String LOGIN_USER = "frame:loginUser"; 15 | 16 | // 缓存 17 | 18 | /** 19 | * Api Roles 映射关系 20 | */ 21 | String API_ROLES = "frame:cache:apiRoles"; 22 | 23 | /** 24 | * 字典 25 | */ 26 | String DICT = "frame:cache:dict"; 27 | } 28 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/consts/LogTypeConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.consts; 2 | 3 | /** 4 | * Api log 类型 5 | * 6 | * @author Cade Li 7 | * @since 2023/8/13 8 | */ 9 | public interface LogTypeConst { 10 | 11 | /** 12 | * curd 13 | */ 14 | String QUERY = "Query"; 15 | String UPDATE = "Update"; 16 | String REMOVE = "Remove"; 17 | String ADD = "Add"; 18 | /** 19 | * 鉴权 20 | */ 21 | String AUTH = "Auth"; 22 | /** 23 | * 导入导出 24 | */ 25 | String IMPORT = "Import"; 26 | String EXPORT = "Export"; 27 | /** 28 | * 上传下载 29 | */ 30 | String UPLOAD = "Upload"; 31 | String DOWNLOAD = "Download"; 32 | } 33 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/consts/SvcNameConst.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.consts; 2 | 3 | /** 4 | * 服务名称 5 | * 6 | * @author Cade Li 7 | * @since 2023/7/29 8 | */ 9 | public interface SvcNameConst { 10 | 11 | String FRAMEWORK = "uni-boot-framework"; 12 | 13 | String EXAMPLE = "uni-boot-example"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/enums/AuthErrorEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.enums; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ApiErrorCode; 4 | import com.github.cadecode.uniboot.common.core.web.response.ApiStatus; 5 | import lombok.Getter; 6 | 7 | /** 8 | * 认证授权错误码枚举 9 | * 10 | * @author Cade Li 11 | * @date 2022/5/8 12 | */ 13 | @Getter 14 | public enum AuthErrorEnum implements ApiErrorCode { 15 | 16 | TOKEN_NOT_EXIST(1000, "未登录") { 17 | @Override 18 | public int getStatus() { 19 | return ApiStatus.NO_AUTHENTICATION; 20 | } 21 | }, 22 | TOKEN_ERROR(1001, "Token 错误") { 23 | @Override 24 | public int getStatus() { 25 | return ApiStatus.NO_AUTHENTICATION; 26 | } 27 | }, 28 | TOKEN_EXPIRED(1002, "Token 已过期") { 29 | @Override 30 | public int getStatus() { 31 | return ApiStatus.NO_AUTHENTICATION; 32 | } 33 | }, 34 | TOKEN_NO_AUTHORITY(1003, "权限不足") { 35 | @Override 36 | public int getStatus() { 37 | return ApiStatus.NO_AUTHORITY; 38 | } 39 | }, 40 | TOKEN_CREATE_ERROR(1004, "登录失败") { 41 | @Override 42 | public int getStatus() { 43 | return ApiStatus.OK; 44 | } 45 | }, 46 | TOKEN_LOGOUT(1005, "用户主动注销") { 47 | @Override 48 | public int getStatus() { 49 | return ApiStatus.NO_AUTHENTICATION; 50 | } 51 | }, 52 | ; 53 | 54 | private final String code; 55 | 56 | private final String message; 57 | 58 | AuthErrorEnum(int code, String message) { 59 | this.code = "AUTH_" + code; 60 | this.message = message; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/enums/AuthModelEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.enums; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ExtTypeCode; 4 | import lombok.Getter; 5 | 6 | /** 7 | * Token 校验模式枚举 8 | * 9 | * @author Cade Li 10 | * @date 2022/5/28 11 | */ 12 | @Getter 13 | public enum AuthModelEnum implements ExtTypeCode { 14 | 15 | /** 16 | * JWT 模式,快过期时下发新 token 17 | */ 18 | JWT("JWT"), 19 | 20 | /** 21 | * Redis + Token 模式,访问时刷新过期时间 22 | */ 23 | REDIS("REDIS"); 24 | 25 | private final String code; 26 | 27 | AuthModelEnum(String code) { 28 | 29 | this.code = code; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/feignclient/ExampleClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.feignclient; 2 | 3 | import com.github.cadecode.uniboot.framework.api.consts.SvcNameConst; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * 测试 feign client 10 | * 11 | * @author Cade Li 12 | * @since 2023/7/28 13 | */ 14 | @FeignClient(contextId = "ExampleClient", name = SvcNameConst.FRAMEWORK) 15 | public interface ExampleClient { 16 | 17 | @PostMapping("example/r/test_str") 18 | String testStr(@RequestParam("str") String str); 19 | 20 | @PostMapping("example/r/test_result") 21 | Object testApiResult(); 22 | 23 | @PostMapping("example/r/test_exception") 24 | Object testException(); 25 | } 26 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/feignclient/SysApiClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.feignclient; 2 | 3 | import com.github.cadecode.uniboot.framework.api.bean.dto.SysApiDto.SysApiRolesResDto; 4 | import com.github.cadecode.uniboot.framework.api.consts.KeyPrefixConst; 5 | import com.github.cadecode.uniboot.framework.api.consts.SvcNameConst; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.cloud.openfeign.FeignClient; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * SysApi feign client 14 | * 15 | * @author Cade Li 16 | * @since 2023/7/28 17 | */ 18 | @FeignClient(contextId = "SysApiClient", name = SvcNameConst.FRAMEWORK) 19 | public interface SysApiClient { 20 | 21 | @Cacheable(cacheNames = KeyPrefixConst.API_ROLES, key = "'ALL'") 22 | @PostMapping("system/api/r/list_roles_vo") 23 | List listRolesResVo(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /framework/framework_api/src/main/java/com/github/cadecode/uniboot/framework/api/feignclient/SysUserClient.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.api.feignclient; 2 | 3 | import com.github.cadecode.uniboot.framework.api.bean.dto.SysUserDto.SysUserGetByUsernameResDto; 4 | import com.github.cadecode.uniboot.framework.api.consts.SvcNameConst; 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | /** 10 | * SysApi feign client 11 | * 12 | * @author Cade Li 13 | * @since 2023/7/28 14 | */ 15 | @FeignClient(contextId = "SysUserClient", name = SvcNameConst.FRAMEWORK) 16 | public interface SysUserClient { 17 | 18 | @PostMapping("system/user/r/get_by_username") 19 | SysUserGetByUsernameResDto getByUsername(@RequestParam("username") String username); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/advisor/ApiExceptionAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.advisor; 2 | 3 | import com.github.cadecode.uniboot.common.core.enums.ApiErrorCode; 4 | import com.github.cadecode.uniboot.common.core.exception.ApiException; 5 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 6 | import com.github.cadecode.uniboot.framework.api.enums.FrameErrorEnum; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | /** 12 | * ApiException 统一处理器 13 | * 14 | * @author Cade Li 15 | * @date 2022/5/8 16 | */ 17 | @Slf4j 18 | @RestControllerAdvice 19 | public class ApiExceptionAdvisor { 20 | 21 | /** 22 | * 处理 ApiException 23 | */ 24 | @ExceptionHandler(ApiException.class) 25 | public ApiResult handleApiException(ApiException e) { 26 | // 特殊处理接口返回 null 的情况 27 | if (FrameErrorEnum.RES_BODY_NULL.getCode().equals(e.getErrorCode().getCode())) { 28 | return ApiResult.ok(null); 29 | } 30 | log.error("Api Exception =>", e); 31 | return ApiResult.error(e.getErrorCode()).moreInfo(e.getMoreInfo()); 32 | } 33 | 34 | /** 35 | * 兜底处理一般异常 36 | */ 37 | @ExceptionHandler(Exception.class) 38 | public ApiResult handleException(Exception e) { 39 | log.error("Exception =>", e); 40 | return ApiResult.error(ApiErrorCode.UNKNOWN).moreInfo(e.getMessage()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/annotation/ApiFormat.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 是否开启 ApiResult 格式化 7 | * 8 | * @author Cade Li 9 | * @date 2022/5/8 10 | */ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface ApiFormat { 15 | boolean value() default true; 16 | } 17 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/annotation/ApiInner.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 标识供内部调用的接口 7 | * 当有些内部调用不方便传递 token 时(比如异步线程中的 feign 调用,无法直接拿到 token 请求头等) 8 | * 可以将接口配置到 security ignore url 列表中,将不再需要登录 9 | * 10 | * @author Cade Li 11 | * @since 2023/8/1 12 | */ 13 | @Target({ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface ApiInner { 17 | 18 | /** 19 | * 是否仅供内部调用 20 | * 用于防止接口被来自网关的流量随意访问 21 | */ 22 | boolean onlyClient() default false; 23 | 24 | /** 25 | * 是否需要用户登录 26 | * 用于防止接口被未登录访问 27 | */ 28 | boolean requireUser() default false; 29 | } 30 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.config; 2 | 3 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 4 | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * Jackson配置 10 | * 11 | * @author Cade Li 12 | * @since 2023/4/12 13 | */ 14 | @Configuration 15 | public class JacksonConfig { 16 | 17 | @Bean 18 | public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() { 19 | return jacksonObjectMapperBuilder -> { 20 | // 关闭空对象序列化失败,如 new Object() 21 | jacksonObjectMapperBuilder.failOnEmptyBeans(false); 22 | jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance); 23 | jacksonObjectMapperBuilder.serializerByType(Long.TYPE, ToStringSerializer.instance); 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/config/PluginConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.config; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.strategy.StrategyService; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.plugin.core.config.EnablePluginRegistries; 6 | 7 | /** 8 | * Spring Plugin 插件配置 9 | * 10 | * @author Cade Li 11 | * @since 2023/6/24 12 | */ 13 | // 配置策略模式统一接口 14 | @EnablePluginRegistries({StrategyService.class}) 15 | @Configuration 16 | public class PluginConfig { 17 | } 18 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/config/RetryConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.config; 2 | 3 | import com.github.cadecode.uniboot.framework.base.exception.RetryableException; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Primary; 7 | import org.springframework.retry.annotation.EnableRetry; 8 | import org.springframework.retry.support.RetryTemplate; 9 | 10 | /** 11 | * Spring Retry 配置类 12 | * 13 | * @author Cade Li 14 | * @date 2022/9/28 15 | */ 16 | @EnableRetry 17 | @Configuration 18 | public class RetryConfig { 19 | 20 | /** 21 | * 默认重试模板,所有异常类型 22 | * 重试 5 次,间隔 1 秒,每次间隔时间 x2 23 | */ 24 | @Primary 25 | @Bean 26 | public RetryTemplate retryTemplate() { 27 | /* 28 | SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); 29 | retryPolicy.setMaxAttempts(3); 30 | ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); 31 | backOffPolicy.setInitialInterval(1000L); 32 | backOffPolicy.setMaxInterval(10000L); 33 | backOffPolicy.setMultiplier(2); 34 | RetryTemplate retryTemplate = new RetryTemplate(); 35 | retryTemplate.setRetryPolicy(retryPolicy); 36 | retryTemplate.setBackOffPolicy(backOffPolicy); 37 | */ 38 | 39 | // 使用 builder 模式代替以上代码 40 | return RetryTemplate.builder() 41 | .maxAttempts(5) 42 | .retryOn(Exception.class) 43 | .exponentialBackoff(1000L, 2, 30000L) 44 | .build(); 45 | } 46 | 47 | /** 48 | * 指定异常类型的重试模板,只重试异常类型或异常 cause 为 RetryableException 49 | * 通过抛出 RetryableException 实现自定义控制重试逻辑 50 | * 重试 5 次,间隔 1 秒,每次间隔时间 x2 51 | */ 52 | @Bean 53 | public RetryTemplate retryTemplateOnRetryable() { 54 | return RetryTemplate.builder() 55 | .maxAttempts(5) 56 | .retryOn(RetryableException.class) 57 | // 开启 cause 穿透,可根据 cause 判断 58 | .traversingCauses() 59 | .exponentialBackoff(1000L, 2, 30000L) 60 | .build(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.config; 2 | 3 | import com.github.cadecode.uniboot.common.core.web.convertor.ParamEnumConvertorFactory; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.format.FormatterRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | /** 9 | * Spring MVC 配置 10 | * 11 | * @author Cade Li 12 | * @date 2022/6/14 13 | */ 14 | @Configuration 15 | public class WebMvcConfig implements WebMvcConfigurer { 16 | 17 | @Override 18 | public void addFormatters(FormatterRegistry registry) { 19 | // 添加枚举类的转换器工厂 20 | registry.addConverterFactory(new ParamEnumConvertorFactory()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/enums/RoleTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import lombok.Getter; 6 | 7 | /** 8 | * 角色类型枚举 9 | * 10 | * @author Cade Li 11 | * @since 2024/5/26 12 | */ 13 | @Getter 14 | public enum RoleTypeEnum { 15 | 16 | ACCESS("ACCESS"), 17 | DATA("DATA"), 18 | ; 19 | 20 | @EnumValue 21 | @JsonValue 22 | private final String prefix; 23 | 24 | RoleTypeEnum(String prefix) { 25 | this.prefix = prefix; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/exception/RetryableException.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.exception; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * 可重试异常 7 | * 8 | * @author Cade Li 9 | * @date 2023/7/4 10 | */ 11 | @Getter 12 | public class RetryableException extends RuntimeException { 13 | 14 | /** 15 | * 用于传递重试中的状态信息 16 | */ 17 | private Object state; 18 | 19 | public RetryableException() { 20 | } 21 | 22 | public RetryableException(String message) { 23 | super(message); 24 | } 25 | 26 | public RetryableException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | public RetryableException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public RetryableException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 35 | super(message, cause, enableSuppression, writableStackTrace); 36 | } 37 | 38 | public RetryableException(Object state) { 39 | this.state = state; 40 | } 41 | 42 | public RetryableException(String message, Object state) { 43 | super(message); 44 | this.state = state; 45 | } 46 | 47 | public RetryableException(String message, Throwable cause, Object state) { 48 | super(message, cause); 49 | this.state = state; 50 | } 51 | 52 | public RetryableException(Throwable cause, Object state) { 53 | super(cause); 54 | this.state = state; 55 | } 56 | 57 | public RetryableException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Object state) { 58 | super(message, cause, enableSuppression, writableStackTrace); 59 | this.state = state; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/feign/FeignClientDecorator.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.feign; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | import com.github.cadecode.uniboot.framework.api.consts.HttpConst; 5 | import com.github.cadecode.uniboot.framework.base.util.RequestUtil; 6 | import feign.Client; 7 | import feign.Request; 8 | import feign.Request.Options; 9 | import feign.Response; 10 | 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | import java.util.Map; 15 | 16 | /** 17 | * FeignClient 装饰器 18 | * 19 | * @author Cade Li 20 | * @since 2023/8/1 21 | */ 22 | public class FeignClientDecorator implements Client { 23 | 24 | private final Client delegate; 25 | 26 | public FeignClientDecorator(Client delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | public Response execute(Request request, Options options) throws IOException { 32 | Response response = delegate.execute(request, options); 33 | fillResponseHeader(response.headers()); 34 | return response; 35 | } 36 | 37 | /** 38 | * 回填响应头到请求上下文的 HttpServletResponse 中 39 | */ 40 | protected void fillResponseHeader(Map> headers) { 41 | HttpServletResponse servletResponse = RequestUtil.getResponse(); 42 | if (ObjUtil.isNull(servletResponse)) { 43 | return; 44 | } 45 | // 获取 token 46 | if (headers.containsKey(HttpConst.HEAD_TOKEN)) { 47 | String token = headers.get(HttpConst.HEAD_TOKEN).stream().findFirst().get(); 48 | servletResponse.addHeader(HttpConst.HEAD_TOKEN, token); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/bean/po/PlgMqMsg.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.github.cadecode.uniboot.framework.base.plugin.enums.ConsumeStateEnum; 5 | import com.github.cadecode.uniboot.framework.base.plugin.enums.SendStateEnum; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.util.Date; 12 | 13 | /** 14 | * MQ 消息实体 15 | * 16 | * @author Cade Li 17 | * @since 2023/8/19 18 | */ 19 | @Data 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | @Builder 23 | @TableName(autoResultMap = true) 24 | public class PlgMqMsg { 25 | 26 | @TableId(type = IdType.ASSIGN_ID) 27 | private String id; 28 | 29 | private String bizType; 30 | 31 | private String bizKey; 32 | 33 | private String exchange; 34 | 35 | private String routingKey; 36 | 37 | private String message; 38 | 39 | private String connectionName; 40 | 41 | private SendStateEnum sendState; 42 | 43 | private ConsumeStateEnum consumeState; 44 | 45 | private Date nextRetryTime; 46 | 47 | private String cause; 48 | 49 | private Integer leftRetryTimes; 50 | 51 | private Integer maxRetryTimes; 52 | 53 | private Long backoffInitInterval; 54 | 55 | private Double backoffMultiplier; 56 | 57 | private Long backoffMaxInterval; 58 | 59 | @TableField(fill = FieldFill.INSERT) 60 | private Date createTime; 61 | 62 | @TableField(fill = FieldFill.UPDATE) 63 | private Date updateTime; 64 | 65 | @TableField(fill = FieldFill.INSERT_UPDATE) 66 | private String updateUser; 67 | } 68 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/bean/vo/PlgFileVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.bean.vo; 2 | 3 | import cn.hutool.core.lang.Dict; 4 | import com.github.cadecode.uniboot.common.core.web.response.PageParams; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | import java.util.Date; 9 | import java.util.Map; 10 | 11 | /** 12 | * 文件记录 VO 13 | * 14 | * @author Cade Li 15 | * @since 2023/10/25 16 | */ 17 | public class PlgFileVo { 18 | 19 | @Data 20 | @EqualsAndHashCode(callSuper = true) 21 | public static class PlgFilePageReqVo extends PageParams { 22 | private Date startTime; 23 | private Date endTime; 24 | private String platform; 25 | private String url; 26 | private String filename; 27 | private String objectId; 28 | private String objectType; 29 | } 30 | 31 | @Data 32 | public static class PlgFilePageResVo { 33 | private Long id; 34 | private String url; 35 | private Long size; 36 | private String filename; 37 | private String originalFilename; 38 | private String basePath; 39 | private String path; 40 | private String ext; 41 | private String contentType; 42 | private String platform; 43 | private String thUrl; 44 | private String thFilename; 45 | private Long thSize; 46 | private String thContentType; 47 | private String objectId; 48 | private String objectType; 49 | private Map metadata; 50 | private Map userMetadata; 51 | private Map thMetadata; 52 | private Map thUserMetadata; 53 | private Dict attr; 54 | private Date createTime; 55 | private Date updateTime; 56 | private String updateUser; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/bean/vo/PlgLogVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.bean.vo; 2 | 3 | import com.github.cadecode.uniboot.common.core.web.response.PageParams; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | /** 11 | * 系统日志 VO 12 | * 13 | * @author Cade Li 14 | * @since 2023/5/26 15 | */ 16 | public class PlgLogVo { 17 | 18 | @Data 19 | @EqualsAndHashCode(callSuper = true) 20 | public static class PlgLogPageReqVo extends PageParams { 21 | 22 | private Date startTime; 23 | private Date endTime; 24 | private List logTypeList; 25 | private String url; 26 | private String accessUser; 27 | private Boolean exceptional; 28 | 29 | } 30 | 31 | @Data 32 | public static class PlgLogPageResVo { 33 | 34 | private Long id; 35 | 36 | private String logType; 37 | 38 | private String url; 39 | 40 | private Boolean exceptional; 41 | 42 | private String accessUser; 43 | 44 | private String description; 45 | 46 | private String classMethod; 47 | 48 | private String threadId; 49 | 50 | private String threadName; 51 | 52 | private String ip; 53 | 54 | private String httpMethod; 55 | 56 | private String requestParams; 57 | 58 | private String result; 59 | 60 | private Long timeCost; 61 | 62 | private String os; 63 | 64 | private String browser; 65 | 66 | private String userAgent; 67 | 68 | private String traceId; 69 | 70 | private Date createTime; 71 | 72 | private Date updateTime; 73 | 74 | private String updateUser; 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/bean/vo/PlgMqMsgVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.bean.vo; 2 | 3 | import com.github.cadecode.uniboot.common.core.web.response.PageParams; 4 | import com.github.cadecode.uniboot.framework.base.plugin.enums.ConsumeStateEnum; 5 | import com.github.cadecode.uniboot.framework.base.plugin.enums.SendStateEnum; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | import javax.validation.constraints.NotNull; 10 | import java.util.Date; 11 | import java.util.List; 12 | 13 | /** 14 | * MQ 消息实体 VO 15 | * 16 | * @author Cade Li 17 | * @since 2023/8/19 18 | */ 19 | public class PlgMqMsgVo { 20 | 21 | @EqualsAndHashCode(callSuper = true) 22 | @Data 23 | public static class PlgMqMsgPageReqVo extends PageParams { 24 | private Date startCreateTime; 25 | private Date endCreateTime; 26 | private String bizType; 27 | private List sendStateList; 28 | } 29 | 30 | @Data 31 | public static class PlgMqMsgPageResVo { 32 | private String id; 33 | private String bizType; 34 | private String bizKey; 35 | private String exchange; 36 | private String routingKey; 37 | private String connectionName; 38 | private String message; 39 | private SendStateEnum sendState; 40 | private ConsumeStateEnum consumeState; 41 | private Date nextRetryTime; 42 | private String cause; 43 | private Integer leftRetryTimes; 44 | private Integer maxRetryTimes; 45 | private Long backoffInitInterval; 46 | private Double backoffMultiplier; 47 | private Long backoffMaxInterval; 48 | private Date createTime; 49 | private Date updateTime; 50 | private String updateUser; 51 | } 52 | 53 | @Data 54 | public static class PlgMqMsgUpdateReqVo { 55 | @NotNull 56 | private String id; 57 | private SendStateEnum sendState; 58 | private Integer leftRetryTimes; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/bean/vo/PlgSwaggerVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.bean.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * plugin swagger vo 10 | * 11 | * @author Cade Li 12 | * @since 2023/8/19 13 | */ 14 | public class PlgSwaggerVo { 15 | 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Builder 20 | public static class PlgSwaggerDescResVo { 21 | 22 | private String url; 23 | 24 | private String description; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/convert/PlgFileConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgFile; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.vo.PlgFileVo.PlgFilePageResVo; 5 | import org.dromara.x.file.storage.core.FileInfo; 6 | import org.mapstruct.Mapper; 7 | import org.mapstruct.Mapping; 8 | import org.mapstruct.factory.Mappers; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 文件记录 bean convert 14 | * 15 | * @author Cade Li 16 | * @since 2023/10/25 17 | */ 18 | @Mapper 19 | public interface PlgFileConvert { 20 | 21 | PlgFileConvert INSTANCE = Mappers.getMapper(PlgFileConvert.class); 22 | 23 | @Mapping(target = "thFileAcl", ignore = true) 24 | @Mapping(target = "fileAcl", ignore = true) 25 | FileInfo poToFileInfo(PlgFile po); 26 | 27 | @Mapping(target = "updateUser", ignore = true) 28 | @Mapping(target = "updateTime", ignore = true) 29 | PlgFile fileInfoToPo(FileInfo fileInfo); 30 | 31 | List poToPageResVo(List poList); 32 | 33 | List poToFileInfo(List plgFileList); 34 | } 35 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/convert/PlgLogConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgLog; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.vo.PlgLogVo.PlgLogPageResVo; 5 | import org.mapstruct.Mapper; 6 | import org.mapstruct.factory.Mappers; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 系统日志 bean convert 12 | * 13 | * @author Cade Li 14 | * @since 2023/5/26 15 | */ 16 | @Mapper 17 | public interface PlgLogConvert { 18 | 19 | PlgLogConvert INSTANCE = Mappers.getMapper(PlgLogConvert.class); 20 | 21 | List poToPageResVo(List records); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/enums/ConsumeStateEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import lombok.Getter; 6 | 7 | /** 8 | * 消费者消息确认状态枚举 9 | * 10 | * @author Cade Li 11 | * @since 2023/8/19 12 | */ 13 | @Getter 14 | public enum ConsumeStateEnum { 15 | 16 | /** 17 | * 确认 18 | */ 19 | ACK("ACK"), 20 | 21 | /** 22 | * 不确认 23 | */ 24 | NACK("NACK"), 25 | 26 | ; 27 | 28 | @EnumValue 29 | @JsonValue 30 | private final String state; 31 | 32 | ConsumeStateEnum(String state) { 33 | this.state = state; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/enums/SendStateEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import lombok.Getter; 6 | 7 | /** 8 | * 生产者消息发送状态枚举 9 | * 10 | * @author Cade Li 11 | * @since 2023/8/19 12 | */ 13 | @Getter 14 | public enum SendStateEnum { 15 | 16 | /** 17 | * 处理中 18 | */ 19 | PREPARING("PREPARING"), 20 | 21 | /** 22 | * 完成 23 | */ 24 | OVER("OVER"), 25 | 26 | /** 27 | * 失败 28 | */ 29 | FAIL("FAIL"), 30 | 31 | ; 32 | 33 | @EnumValue 34 | @JsonValue 35 | private final String state; 36 | 37 | SendStateEnum(String state) { 38 | this.state = state; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/handler/MybatisFillHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.handler; 2 | 3 | import com.github.cadecode.uniboot.common.plugin.mybatis.handler.AbstractObjectFillHandler; 4 | import com.github.cadecode.uniboot.framework.base.util.SecurityUtil; 5 | import org.apache.ibatis.reflection.MetaObject; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * mybatis plus 对象填充处理器 10 | * 11 | * @author Cade Li 12 | * @since 2023/6/8 13 | */ 14 | @Component 15 | public class MybatisFillHandler extends AbstractObjectFillHandler { 16 | @Override 17 | public void updateUser(MetaObject metaObject) { 18 | this.setFieldValByName("updateUser", SecurityUtil.getUsername(), metaObject); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/handler/UserRoleDataScopeResolver.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.handler; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | import com.github.cadecode.uniboot.common.plugin.mybatis.annotation.UseDataScope; 5 | import com.github.cadecode.uniboot.common.plugin.mybatis.config.MybatisConfig; 6 | import com.github.cadecode.uniboot.common.plugin.mybatis.handler.DataScopeResolver; 7 | import com.github.cadecode.uniboot.framework.base.enums.RoleTypeEnum; 8 | import com.github.cadecode.uniboot.framework.base.security.model.SysUserDetails; 9 | import com.github.cadecode.uniboot.framework.base.util.SecurityUtil; 10 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.List; 14 | import java.util.Objects; 15 | import java.util.stream.Collectors; 16 | 17 | /** 18 | * 基于用户角色的数据权限范围解析器 19 | * 20 | * @author Cade Li 21 | * @since 2024/5/23 22 | */ 23 | @AutoConfigureBefore(MybatisConfig.class) 24 | @Component(UseDataScope.DEFAULT_RESOLVER_NAME) 25 | public class UserRoleDataScopeResolver implements DataScopeResolver { 26 | 27 | public static final String SCOPE_ROLE_PREFIX = RoleTypeEnum.DATA.getPrefix() + ":"; 28 | 29 | @Override 30 | public List getScopes() { 31 | SysUserDetails userDetails = SecurityUtil.getUserDetails(null); 32 | if (Objects.isNull(userDetails)) { 33 | return null; 34 | } 35 | if (ObjUtil.isEmpty(userDetails.getRoles())) { 36 | return null; 37 | } 38 | return userDetails.getRoles() 39 | .stream() 40 | .filter(o -> Objects.nonNull(o) && o.startsWith(SCOPE_ROLE_PREFIX)) 41 | .map(o -> (Object) o.substring(SCOPE_ROLE_PREFIX.length())) 42 | .collect(Collectors.toList()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/mapper/PlgFileMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgFile; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * PlgFile Mapper 9 | * 10 | * @author Cade Li 11 | * @since 2023/10/25 12 | */ 13 | @Mapper 14 | public interface PlgFileMapper extends BaseMapper { 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/mapper/PlgLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgLog; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * 系统日志 DAO 9 | * 10 | * @author Cade Li 11 | * @since 2023/5/26 12 | */ 13 | @Mapper 14 | public interface PlgLogMapper extends BaseMapper { 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/mapper/PlgMqMsgMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgMqMsg; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * PlgMqMsg Mapper 9 | * 10 | * @author Cade Li 11 | * @since 2023/8/19 12 | */ 13 | @Mapper 14 | public interface PlgMqMsgMapper extends BaseMapper { 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/service/PlgFileService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgFile; 5 | 6 | /** 7 | * PlgFile Service 8 | * 9 | * @author Cade Li 10 | * @since 2023/10/25 11 | */ 12 | public interface PlgFileService extends IService { 13 | } 14 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/service/PlgLogService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgLog; 5 | 6 | /** 7 | * 系统日志服务 8 | * 9 | * @author Cade Li 10 | * @since 2023/5/26 11 | */ 12 | public interface PlgLogService extends IService { 13 | } 14 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/service/PlgMqMsgService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgMqMsg; 5 | 6 | /** 7 | * PlgMqMsg Service 8 | * 9 | * @author Cade Li 10 | * @since 2023/5/26 11 | */ 12 | public interface PlgMqMsgService extends IService { 13 | } 14 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/serviceimpl/PlgFileServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.serviceimpl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgFile; 5 | import com.github.cadecode.uniboot.framework.base.plugin.mapper.PlgFileMapper; 6 | import com.github.cadecode.uniboot.framework.base.plugin.service.PlgFileService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * PlgFile ServiceImpl 11 | * 12 | * @author Cade Li 13 | * @since 2023/10/25 14 | */ 15 | @Service 16 | public class PlgFileServiceImpl extends ServiceImpl implements PlgFileService { 17 | } 18 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/serviceimpl/PlgLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.serviceimpl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgLog; 5 | import com.github.cadecode.uniboot.framework.base.plugin.mapper.PlgLogMapper; 6 | import com.github.cadecode.uniboot.framework.base.plugin.service.PlgLogService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * 系统日志服务实现 11 | * 12 | * @author Cade Li 13 | * @since 2023/5/26 14 | */ 15 | @Service 16 | public class PlgLogServiceImpl extends ServiceImpl implements PlgLogService { 17 | } 18 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/plugin/serviceimpl/PlgMqMsgServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.plugin.serviceimpl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.cadecode.uniboot.framework.base.plugin.bean.po.PlgMqMsg; 5 | import com.github.cadecode.uniboot.framework.base.plugin.mapper.PlgMqMsgMapper; 6 | import com.github.cadecode.uniboot.framework.base.plugin.service.PlgMqMsgService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * PlgMqMsg Service 实现 11 | * 12 | * @author Cade Li 13 | * @since 2023/5/26 14 | */ 15 | @Service 16 | public class PlgMqMsgServiceImpl extends ServiceImpl implements PlgMqMsgService { 17 | } 18 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/filter/CorsAllowAnyFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.filter; 2 | 3 | import org.springframework.web.cors.CorsConfiguration; 4 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 5 | import org.springframework.web.filter.CorsFilter; 6 | 7 | /** 8 | * Filter, cors support 9 | * 10 | * @author Cade Li 11 | * @since 2023/9/11 12 | */ 13 | public class CorsAllowAnyFilter extends CorsFilter { 14 | 15 | static UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); 16 | 17 | static { 18 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 19 | corsConfiguration.addAllowedHeader("*"); 20 | corsConfiguration.addAllowedMethod("*"); 21 | corsConfiguration.addAllowedOriginPattern("*"); 22 | corsConfiguration.setAllowCredentials(true); 23 | urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); 24 | } 25 | 26 | public CorsAllowAnyFilter() { 27 | super(urlBasedCorsConfigurationSource); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/filter/TokenAuthFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.filter; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.strategy.StrategyExecutor; 4 | import com.github.cadecode.uniboot.framework.base.config.SecurityConfig.SecurityProperties; 5 | import com.github.cadecode.uniboot.framework.base.security.strategy.TokenAuthStrategy; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.web.filter.OncePerRequestFilter; 8 | 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | /** 14 | * Filter, token auth 15 | * 16 | * @author Cade Li 17 | * @since 2023/9/11 18 | */ 19 | @RequiredArgsConstructor 20 | public class TokenAuthFilter extends OncePerRequestFilter { 21 | 22 | private final StrategyExecutor strategyExecutor; 23 | 24 | private final SecurityProperties securityProperties; 25 | 26 | @Override 27 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) { 28 | strategyExecutor.execute(TokenAuthStrategy.class, securityProperties::getAuthModel, s -> { 29 | try { 30 | s.filter(request, response, filterChain); 31 | } catch (Exception e) { 32 | throw new RuntimeException(e); 33 | } 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/filter/TraceInfoFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.filter; 2 | 3 | import cn.hutool.core.util.CharsetUtil; 4 | import cn.hutool.core.util.ObjUtil; 5 | import cn.hutool.extra.servlet.ServletUtil; 6 | import com.github.cadecode.uniboot.framework.api.consts.HttpConst; 7 | import org.slf4j.MDC; 8 | import org.springframework.web.filter.OncePerRequestFilter; 9 | 10 | import javax.servlet.FilterChain; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | /** 17 | * Filter, trace id to MDC 18 | * 19 | * @author Cade Li 20 | * @since 2023/9/11 21 | */ 22 | public class TraceInfoFilter extends OncePerRequestFilter { 23 | @Override 24 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain 25 | filterChain) 26 | throws ServletException, IOException { 27 | String traceId = ServletUtil.getHeader(request, HttpConst.HEAD_TRACE_ID, CharsetUtil.CHARSET_UTF_8); 28 | if (ObjUtil.isNotEmpty(traceId)) { 29 | MDC.put(HttpConst.HEAD_TRACE_ID, traceId); 30 | } 31 | filterChain.doFilter(request, response); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/handler/NoAuthenticationHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.handler; 2 | 3 | import cn.hutool.core.util.CharsetUtil; 4 | import cn.hutool.extra.servlet.ServletUtil; 5 | import cn.hutool.http.ContentType; 6 | import com.github.cadecode.uniboot.common.core.util.JacksonUtil; 7 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 8 | import com.github.cadecode.uniboot.framework.api.enums.AuthErrorEnum; 9 | import org.springframework.security.core.AuthenticationException; 10 | import org.springframework.security.web.AuthenticationEntryPoint; 11 | import org.springframework.stereotype.Component; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | * 未认证处理器 18 | * 19 | * @author Cade Li 20 | * @date 2021/12/11 21 | */ 22 | @Component 23 | public class NoAuthenticationHandler implements AuthenticationEntryPoint { 24 | @Override 25 | public void commence(HttpServletRequest request, HttpServletResponse response, 26 | AuthenticationException authException) { 27 | ApiResult result = ApiResult.error(AuthErrorEnum.TOKEN_NOT_EXIST).path(request.getRequestURI()); 28 | response.setStatus(AuthErrorEnum.TOKEN_NOT_EXIST.getStatus()); 29 | ServletUtil.write(response, JacksonUtil.toJson(result), ContentType.JSON.toString(CharsetUtil.CHARSET_UTF_8)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/handler/NoAuthorityHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.handler; 2 | 3 | import cn.hutool.core.util.CharsetUtil; 4 | import cn.hutool.extra.servlet.ServletUtil; 5 | import cn.hutool.http.ContentType; 6 | import com.github.cadecode.uniboot.common.core.util.JacksonUtil; 7 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 8 | import com.github.cadecode.uniboot.framework.api.enums.AuthErrorEnum; 9 | import org.springframework.security.access.AccessDeniedException; 10 | import org.springframework.security.web.access.AccessDeniedHandler; 11 | import org.springframework.stereotype.Component; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | * 权限不足处理器 18 | * 19 | * @author Cade Li 20 | * @date 2021/12/11 21 | */ 22 | @Component 23 | public class NoAuthorityHandler implements AccessDeniedHandler { 24 | @Override 25 | public void handle(HttpServletRequest request, HttpServletResponse response, 26 | AccessDeniedException accessDeniedException) { 27 | ApiResult result = ApiResult.error(AuthErrorEnum.TOKEN_NO_AUTHORITY).path(request.getRequestURI()); 28 | response.setStatus(AuthErrorEnum.TOKEN_NO_AUTHORITY.getStatus()); 29 | ServletUtil.write(response, JacksonUtil.toJson(result), ContentType.JSON.toString(CharsetUtil.CHARSET_UTF_8)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /framework/framework_base/src/main/java/com/github/cadecode/uniboot/framework/base/security/model/SysUserDetails.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.base.security.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.Data; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | 9 | import java.util.Collection; 10 | import java.util.Date; 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * SpringSecurity UserDetails实现 16 | * 17 | * @author Cade Li 18 | * @since 2023/8/11 19 | */ 20 | @Data 21 | public class SysUserDetails implements UserDetails { 22 | 23 | private Long id; 24 | 25 | private String username; 26 | 27 | @JsonIgnore 28 | private String password; 29 | 30 | private String nickName; 31 | 32 | private Long deptId; 33 | 34 | private String deptName; 35 | 36 | private Boolean enableFlag; 37 | 38 | private String sex; 39 | 40 | private String mail; 41 | 42 | private String phone; 43 | 44 | private String loginIp; 45 | 46 | private Date loginDate; 47 | 48 | List roles; 49 | 50 | @JsonIgnore 51 | @Override 52 | public Collection getAuthorities() { 53 | // 重写获取权限的方法,从角色字符串创建 SimpleGrantedAuthority 54 | return roles.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()); 55 | } 56 | 57 | @JsonIgnore 58 | @Override 59 | public boolean isAccountNonExpired() { 60 | return true; 61 | } 62 | 63 | @JsonIgnore 64 | @Override 65 | public boolean isAccountNonLocked() { 66 | return true; 67 | } 68 | 69 | @JsonIgnore 70 | @Override 71 | public boolean isCredentialsNonExpired() { 72 | return true; 73 | } 74 | 75 | @JsonIgnore 76 | @Override 77 | public boolean isEnabled() { 78 | return true; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/UniFrameworkApplication.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 11 | 12 | /** 13 | * 启动类 14 | */ 15 | @MapperScan("com.github.cadecode.**.mapper") 16 | @EnableFeignClients("com.github.cadecode") 17 | @EnableDiscoveryClient 18 | @EnableAspectJAutoProxy(exposeProxy = true) 19 | @SpringBootApplication 20 | public class UniFrameworkApplication extends SpringBootServletInitializer { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(UniFrameworkApplication.class, args); 24 | } 25 | 26 | @Override 27 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 28 | return application.sources(UniFrameworkApplication.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysApi.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Builder; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | 12 | import java.util.Date; 13 | 14 | /** 15 | * 系统接口 PO 16 | * 17 | * @author Cade Li 18 | * @date 2022/5/24 19 | */ 20 | @Data 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | @Builder 24 | public class SysApi { 25 | 26 | /** 27 | * id 28 | */ 29 | @TableId(type = IdType.ASSIGN_ID) 30 | private Long id; 31 | 32 | /** 33 | * 接口 url 34 | */ 35 | private String url; 36 | 37 | /** 38 | * 描述 39 | */ 40 | private String description; 41 | 42 | @TableField(fill = FieldFill.INSERT) 43 | private Date createTime; 44 | 45 | @TableField(fill = FieldFill.UPDATE) 46 | private Date updateTime; 47 | 48 | @TableField(fill = FieldFill.INSERT_UPDATE) 49 | private String updateUser; 50 | } 51 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysDept.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * 部门 PO 13 | * 14 | * @author Cade Li 15 | * @since 2023/11/24 16 | */ 17 | @Data 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @Builder 21 | @TableName(autoResultMap = true) 22 | public class SysDept { 23 | 24 | @TableId(type = IdType.ASSIGN_ID) 25 | private Long id; 26 | 27 | /** 28 | * 部门名称 29 | */ 30 | private String deptName; 31 | 32 | /** 33 | * 父级 ID 34 | */ 35 | private Long parentId; 36 | 37 | /** 38 | * 排序 39 | */ 40 | private Integer orderNum; 41 | 42 | /** 43 | * leader 名 44 | */ 45 | private String leader; 46 | 47 | /** 48 | * 邮箱 49 | */ 50 | private String mail; 51 | 52 | /** 53 | * 电话 54 | */ 55 | private String phone; 56 | 57 | @TableField(fill = FieldFill.INSERT) 58 | private Date createTime; 59 | 60 | @TableField(fill = FieldFill.UPDATE) 61 | private Date updateTime; 62 | 63 | @TableField(fill = FieldFill.INSERT_UPDATE) 64 | private String updateUser; 65 | } 66 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysDict.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.github.cadecode.uniboot.common.plugin.mybatis.converter.BoolToIntTypeHandler; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * 系统字典 14 | * 15 | * @author Cade Li 16 | * @date 2023/6/11 17 | */ 18 | @Data 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Builder 22 | @TableName(autoResultMap = true) 23 | public class SysDict { 24 | 25 | @TableId(type = IdType.ASSIGN_ID) 26 | private Long id; 27 | 28 | /** 29 | * 字典名称 30 | */ 31 | private String name; 32 | 33 | /** 34 | * 字典类型 35 | */ 36 | private String type; 37 | 38 | /** 39 | * 字典标签 40 | */ 41 | private String label; 42 | 43 | /** 44 | * 字典值 45 | */ 46 | private String value; 47 | 48 | /** 49 | * 是否是默认值 50 | */ 51 | @TableField(typeHandler = BoolToIntTypeHandler.class) 52 | private Boolean defaultFlag; 53 | 54 | /** 55 | * 描述 56 | */ 57 | private String description; 58 | 59 | /** 60 | * 排序 61 | */ 62 | private Integer orderNum; 63 | 64 | @TableField(fill = FieldFill.INSERT) 65 | private Date createTime; 66 | 67 | @TableField(fill = FieldFill.UPDATE) 68 | private Date updateTime; 69 | 70 | @TableField(fill = FieldFill.INSERT_UPDATE) 71 | private String updateUser; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysMenu.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.github.cadecode.uniboot.common.plugin.mybatis.converter.BoolToIntTypeHandler; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * 系统菜单 PO 14 | * 15 | * @author Cade Li 16 | * @since 2023/4/11 17 | */ 18 | @Data 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Builder 22 | @TableName(autoResultMap = true) 23 | public class SysMenu { 24 | 25 | @TableId(type = IdType.ASSIGN_ID) 26 | private Long id; 27 | 28 | /** 29 | * 父级ID 30 | */ 31 | private Long parentId; 32 | 33 | /** 34 | * 路由名称 35 | */ 36 | private String routeName; 37 | 38 | /** 39 | * 路由路径 40 | */ 41 | private String routePath; 42 | 43 | /** 44 | * 组件路径 45 | */ 46 | private String componentPath; 47 | 48 | /** 49 | * 菜单名称 50 | */ 51 | private String menuName; 52 | 53 | /** 54 | * 是否页面 55 | */ 56 | @TableField(typeHandler = BoolToIntTypeHandler.class) 57 | private Boolean leafFlag; 58 | 59 | /** 60 | * 图标 61 | */ 62 | private String icon; 63 | 64 | /** 65 | * 排序 66 | */ 67 | private Integer orderNum; 68 | 69 | /** 70 | * 是否启用 71 | */ 72 | @TableField(typeHandler = BoolToIntTypeHandler.class) 73 | private Boolean enableFlag; 74 | 75 | /** 76 | * 是否隐藏(用于内部路由) 77 | */ 78 | @TableField(typeHandler = BoolToIntTypeHandler.class) 79 | private Boolean hiddenFlag; 80 | 81 | /** 82 | * 是否启用内部缓存 83 | */ 84 | @TableField(typeHandler = BoolToIntTypeHandler.class) 85 | private Boolean cacheFlag; 86 | 87 | @TableField(fill = FieldFill.INSERT) 88 | private Date createTime; 89 | 90 | @TableField(fill = FieldFill.UPDATE) 91 | private Date updateTime; 92 | 93 | @TableField(fill = FieldFill.INSERT_UPDATE) 94 | private String updateUser; 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysRole.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import com.github.cadecode.uniboot.framework.base.enums.RoleTypeEnum; 8 | import lombok.AllArgsConstructor; 9 | import lombok.Builder; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | 13 | import java.util.Date; 14 | 15 | /** 16 | * 系统角色 PO 17 | * 18 | * @author Cade Li 19 | * @date 2022/5/24 20 | */ 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | @Builder 25 | public class SysRole { 26 | 27 | /** 28 | * id 29 | */ 30 | @TableId(type = IdType.ASSIGN_ID) 31 | private Long id; 32 | 33 | /** 34 | * 角色代码 35 | */ 36 | private String code; 37 | 38 | /** 39 | * 名称 40 | */ 41 | private String name; 42 | 43 | /** 44 | * 角色类型 45 | */ 46 | private RoleTypeEnum type; 47 | 48 | /** 49 | * 描述 50 | */ 51 | private String description; 52 | 53 | @TableField(fill = FieldFill.INSERT) 54 | private Date createTime; 55 | 56 | @TableField(fill = FieldFill.UPDATE) 57 | private Date updateTime; 58 | 59 | @TableField(fill = FieldFill.INSERT_UPDATE) 60 | private String updateUser; 61 | } 62 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/po/SysUser.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.github.cadecode.uniboot.common.plugin.mybatis.converter.BoolToIntTypeHandler; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * 系统用户 PO 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/24 17 | */ 18 | @Data 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Builder 22 | @TableName(autoResultMap = true) 23 | public class SysUser { 24 | 25 | /** 26 | * id 27 | */ 28 | @TableId(type = IdType.ASSIGN_ID) 29 | private Long id; 30 | 31 | /** 32 | * 用户名 33 | */ 34 | private String username; 35 | 36 | /** 37 | * 密码 38 | */ 39 | private String password; 40 | 41 | /** 42 | * 昵称 43 | */ 44 | private String nickName; 45 | 46 | /** 47 | * 部门 ID 48 | */ 49 | private Long deptId; 50 | 51 | /** 52 | * 是否启用 53 | */ 54 | @TableField(typeHandler = BoolToIntTypeHandler.class) 55 | private Boolean enableFlag; 56 | 57 | /** 58 | * 性别 59 | */ 60 | private String sex; 61 | 62 | /** 63 | * 邮箱 64 | */ 65 | private String mail; 66 | 67 | /** 68 | * 电话 69 | */ 70 | private String phone; 71 | 72 | /** 73 | * 登录 IP 74 | */ 75 | private String loginIp; 76 | 77 | /** 78 | * 登录时间 79 | */ 80 | private Date loginDate; 81 | 82 | @TableField(fill = FieldFill.INSERT) 83 | private Date createTime; 84 | 85 | @TableField(fill = FieldFill.UPDATE) 86 | private Date updateTime; 87 | 88 | @TableField(fill = FieldFill.INSERT_UPDATE) 89 | private String updateUser; 90 | } 91 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/vo/SysApiVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.vo; 2 | 3 | import com.github.cadecode.uniboot.common.core.web.response.PageParams; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | import javax.validation.constraints.NotEmpty; 8 | import javax.validation.constraints.NotNull; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | /** 13 | * 系统接口 VO 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/24 17 | */ 18 | public class SysApiVo { 19 | 20 | @Data 21 | @EqualsAndHashCode(callSuper = true) 22 | public static class SysApiRolesReqVo extends PageParams { 23 | private String url; 24 | private String description; 25 | } 26 | 27 | @Data 28 | public static class SysApiUpdateReqVo { 29 | @NotNull 30 | private Long id; 31 | private String url; 32 | private String description; 33 | } 34 | 35 | @Data 36 | public static class SysApiAddReqVo { 37 | @NotNull 38 | @NotEmpty 39 | private String url; 40 | @NotNull 41 | @NotEmpty 42 | private String description; 43 | } 44 | 45 | @Data 46 | public static class SysApiRolesResVo { 47 | 48 | private Long id; 49 | 50 | private String url; 51 | 52 | private String description; 53 | 54 | private Date createTime; 55 | 56 | private Date updateTime; 57 | 58 | private String updateUser; 59 | 60 | private List roles; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/bean/vo/SysDeptVo.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.bean.vo; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotEmpty; 6 | import javax.validation.constraints.NotNull; 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | /** 11 | * 部门 VO 12 | * 13 | * @author Cade Li 14 | * @since 2023/11/24 15 | */ 16 | public class SysDeptVo { 17 | 18 | @Data 19 | public static class SysDeptTreeReqVo { 20 | private String deptName; 21 | } 22 | 23 | @Data 24 | public static class SysDeptTreeResVo { 25 | private Long id; 26 | private String deptName; 27 | private Long parentId; 28 | private Integer orderNum; 29 | private String leader; 30 | private String mail; 31 | private String phone; 32 | private Date createTime; 33 | private Date updateTime; 34 | private String updateUser; 35 | private List children; 36 | } 37 | 38 | @Data 39 | public static class SysDeptQueryResVo { 40 | private Long id; 41 | private String deptName; 42 | private Long parentId; 43 | private Integer orderNum; 44 | private String leader; 45 | private String mail; 46 | private String phone; 47 | private Date createTime; 48 | private Date updateTime; 49 | private String updateUser; 50 | } 51 | 52 | @Data 53 | public static class SysDeptUpdateReqVo { 54 | @NotNull 55 | private Long id; 56 | private String deptName; 57 | private Integer orderNum; 58 | private String leader; 59 | private String mail; 60 | private String phone; 61 | } 62 | 63 | @Data 64 | public static class SysDeptAddReqVo { 65 | private Long parentId; 66 | @NotNull 67 | @NotEmpty 68 | private String deptName; 69 | @NotNull 70 | private Integer orderNum; 71 | private String leader; 72 | private String mail; 73 | private String phone; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/config/UniFrameworkConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.config; 2 | 3 | import lombok.Data; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * uni-boot-cloud framework 服务配置 13 | * 14 | * @author Cade Li 15 | * @since 2023/7/28 16 | */ 17 | @Slf4j 18 | @Data 19 | @RequiredArgsConstructor 20 | @Configuration 21 | @ConfigurationProperties("uni-boot.framework") 22 | public class UniFrameworkConfig { 23 | 24 | /** 25 | * 文件基本路径,以/结尾 26 | */ 27 | private String fileBasePath; 28 | 29 | /** 30 | * 可上传下载的扩展文件类型 31 | */ 32 | private List allowedFileExtensions; 33 | } 34 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/controller/ExampleControllerR.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.common.core.exception.ApiException; 4 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 5 | import com.github.cadecode.uniboot.framework.api.enums.FrameErrorEnum; 6 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import lombok.RequiredArgsConstructor; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | /** 17 | * 测试接口 18 | * 19 | * @author Cade Li 20 | * @since 2023/7/29 21 | */ 22 | @ApiFormat 23 | @Slf4j 24 | @RequiredArgsConstructor 25 | @Api(tags = "测试接口-RPC") 26 | @RestController 27 | @RequestMapping("example/r") 28 | public class ExampleControllerR { 29 | 30 | @ApiOperation("传递字符串") 31 | @PostMapping("test_str") 32 | public String testStr(@RequestParam String str) { 33 | return str; 34 | } 35 | 36 | @ApiOperation("返回异常结果") 37 | @PostMapping("test_result") 38 | public ApiResult testApiResult() { 39 | return ApiResult.error(FrameErrorEnum.UNKNOWN).moreInfo("测试返回异常结果"); 40 | } 41 | 42 | @ApiOperation("直接抛出异常") 43 | @PostMapping("test_exception") 44 | public Object testException() { 45 | throw ApiException.of("测试直接抛出异常"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/controller/SysApiControllerR.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 4 | import com.github.cadecode.uniboot.framework.base.annotation.ApiInner; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesResVo; 6 | import com.github.cadecode.uniboot.framework.svc.service.SysApiService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import lombok.RequiredArgsConstructor; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.validation.annotation.Validated; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * API 管理 20 | * 21 | * @author Cade Li 22 | * @date 2023/5/14 23 | */ 24 | @ApiFormat 25 | @Slf4j 26 | @RequiredArgsConstructor 27 | @Api(tags = "API 管理-RPC") 28 | @RequestMapping("system/api/r") 29 | @RestController 30 | @Validated 31 | public class SysApiControllerR { 32 | 33 | private final SysApiService sysApiService; 34 | 35 | @ApiInner(onlyClient = true) 36 | @ApiOperation("查询API列表-全部") 37 | @PostMapping("list_roles_vo") 38 | public List listRolesVo() { 39 | return sysApiService.listRolesVo(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/controller/SysUserControllerR.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.controller; 2 | 3 | import com.github.cadecode.uniboot.common.core.util.AssertUtil; 4 | import com.github.cadecode.uniboot.framework.base.annotation.ApiFormat; 5 | import com.github.cadecode.uniboot.framework.base.annotation.ApiInner; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesReqVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesResVo; 8 | import com.github.cadecode.uniboot.framework.svc.service.SysUserService; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import lombok.RequiredArgsConstructor; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.validation.annotation.Validated; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * 用户管理API 23 | * 24 | * @author Cade Li 25 | * @since 2023/4/12 26 | */ 27 | @ApiFormat 28 | @Slf4j 29 | @RequiredArgsConstructor 30 | @Api(tags = "用户管理-RPC") 31 | @RequestMapping("system/user/r") 32 | @RestController 33 | @Validated 34 | public class SysUserControllerR { 35 | 36 | private final SysUserService sysUserService; 37 | 38 | @ApiInner(onlyClient = true) 39 | @ApiOperation("查询用户信息") 40 | @PostMapping("get_by_username") 41 | public SysUserRolesResVo getByUsername(@RequestParam String username) { 42 | // 根据用户名查询 43 | SysUserRolesReqVo reqVo = new SysUserRolesReqVo(); 44 | reqVo.setUsername(username); 45 | List voList = sysUserService.listRolesVo(reqVo); 46 | AssertUtil.isEmpty(voList, "此用户名不存在"); 47 | return voList.get(0); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/convert/SysApiConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysApi; 4 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiAddReqVo; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiUpdateReqVo; 6 | import org.mapstruct.Mapper; 7 | import org.mapstruct.Mapping; 8 | import org.mapstruct.factory.Mappers; 9 | 10 | /** 11 | * 系统接口 BEAN 转换 12 | * 13 | * @author Cade Li 14 | * @date 2022/5/27 15 | */ 16 | @Mapper 17 | public interface SysApiConvert { 18 | 19 | SysApiConvert INSTANCE = Mappers.getMapper(SysApiConvert.class); 20 | 21 | @Mapping(target = "updateUser", ignore = true) 22 | @Mapping(target = "updateTime", ignore = true) 23 | @Mapping(target = "createTime", ignore = true) 24 | SysApi voToPo(SysApiUpdateReqVo reqVo); 25 | 26 | @Mapping(target = "updateUser", ignore = true) 27 | @Mapping(target = "updateTime", ignore = true) 28 | @Mapping(target = "id", ignore = true) 29 | @Mapping(target = "createTime", ignore = true) 30 | SysApi voToPo(SysApiAddReqVo reqVo); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/convert/SysDeptConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDept; 4 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptAddReqVo; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptQueryResVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeResVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptUpdateReqVo; 8 | import org.mapstruct.Mapper; 9 | import org.mapstruct.Mapping; 10 | import org.mapstruct.factory.Mappers; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 部门 bean convert 16 | * 17 | * @author Cade Li 18 | * @since 2023/11/24 19 | */ 20 | @Mapper 21 | public interface SysDeptConvert { 22 | 23 | SysDeptConvert INSTANCE = Mappers.getMapper(SysDeptConvert.class); 24 | 25 | @Mapping(target = "updateUser", ignore = true) 26 | @Mapping(target = "updateTime", ignore = true) 27 | @Mapping(target = "id", ignore = true) 28 | @Mapping(target = "createTime", ignore = true) 29 | SysDept voToPo(SysDeptAddReqVo reqVo); 30 | 31 | @Mapping(target = "parentId", ignore = true) 32 | @Mapping(target = "updateUser", ignore = true) 33 | @Mapping(target = "updateTime", ignore = true) 34 | @Mapping(target = "createTime", ignore = true) 35 | SysDept voToPo(SysDeptUpdateReqVo reqVo); 36 | 37 | List poToQueryResVo(List poList); 38 | 39 | List poToTreeResVo(List poList); 40 | } 41 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/convert/SysDictConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDict; 4 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDictVo.*; 5 | import org.mapstruct.Mapper; 6 | import org.mapstruct.Mapping; 7 | import org.mapstruct.factory.Mappers; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 系统字典 Bean 转换 13 | * 14 | * @author Cade Li 15 | * @date 2023/6/11 16 | */ 17 | @Mapper 18 | public interface SysDictConvert { 19 | SysDictConvert INSTANCE = Mappers.getMapper(SysDictConvert.class); 20 | 21 | List poToPageResVo(List records); 22 | 23 | @Mapping(target = "updateUser", ignore = true) 24 | @Mapping(target = "updateTime", ignore = true) 25 | @Mapping(target = "id", ignore = true) 26 | @Mapping(target = "createTime", ignore = true) 27 | SysDict voToPo(SysDictAddReqVo reqVo); 28 | 29 | @Mapping(target = "updateUser", ignore = true) 30 | @Mapping(target = "updateTime", ignore = true) 31 | @Mapping(target = "createTime", ignore = true) 32 | SysDict voToPo(SysDictUpdateReqVo reqVo); 33 | 34 | List poToGetByTypeResVo(List dictList); 35 | 36 | SysDictSuggestResVo poToSuggestResVo(SysDict po); 37 | } 38 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/convert/SysMenuConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysMenu; 4 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuAddReqVo; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuQueryResVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuTreeResVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuUpdateReqVo; 8 | import org.mapstruct.Mapper; 9 | import org.mapstruct.Mapping; 10 | import org.mapstruct.factory.Mappers; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 系统菜单BEAN转换 16 | * 17 | * @author Cade Li 18 | * @date 2022/5/27 19 | */ 20 | @Mapper 21 | public interface SysMenuConvert { 22 | 23 | SysMenuConvert INSTANCE = Mappers.getMapper(SysMenuConvert.class); 24 | 25 | 26 | @Mapping(target = "children", ignore = true) 27 | SysMenuTreeResVo poToTreeResVo(SysMenu sysMenu); 28 | 29 | @Mapping(target = "parentId", ignore = true) 30 | @Mapping(target = "hiddenFlag", ignore = true) 31 | @Mapping(target = "updateUser", ignore = true) 32 | @Mapping(target = "updateTime", ignore = true) 33 | @Mapping(target = "leafFlag", ignore = true) 34 | @Mapping(target = "enableFlag", ignore = true) 35 | @Mapping(target = "createTime", ignore = true) 36 | SysMenu voToPo(SysMenuUpdateReqVo reqVo); 37 | 38 | @Mapping(target = "updateUser", ignore = true) 39 | @Mapping(target = "updateTime", ignore = true) 40 | @Mapping(target = "id", ignore = true) 41 | @Mapping(target = "createTime", ignore = true) 42 | SysMenu voToPo(SysMenuAddReqVo reqVo); 43 | 44 | List poToQueryResVo(List list); 45 | } 46 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/convert/SysRoleConvert.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.convert; 2 | 3 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysRole; 4 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleAddReqVo; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleListResVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleUpdateReqVo; 7 | import org.mapstruct.Mapper; 8 | import org.mapstruct.Mapping; 9 | import org.mapstruct.factory.Mappers; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * 系统角色 BEAN 转换 15 | * 16 | * @author Cade Li 17 | * @date 2022/5/27 18 | */ 19 | @Mapper 20 | public interface SysRoleConvert { 21 | 22 | SysRoleConvert INSTANCE = Mappers.getMapper(SysRoleConvert.class); 23 | 24 | SysRoleListResVo poToListResVo(SysRole po); 25 | 26 | List poToListResVo(List po); 27 | 28 | @Mapping(target = "updateUser", ignore = true) 29 | @Mapping(target = "updateTime", ignore = true) 30 | @Mapping(target = "createTime", ignore = true) 31 | SysRole voToPo(SysRoleUpdateReqVo reqVo); 32 | 33 | @Mapping(target = "updateUser", ignore = true) 34 | @Mapping(target = "updateTime", ignore = true) 35 | @Mapping(target = "id", ignore = true) 36 | @Mapping(target = "createTime", ignore = true) 37 | SysRole voToPo(SysRoleAddReqVo reqVo); 38 | } 39 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysApiMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysApi; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesResVo; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统接口 DAO 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | @Mapper 19 | public interface SysApiMapper extends BaseMapper { 20 | 21 | List selectRolesVoByApiIds(@Param("apiIds") List apiIds); 22 | 23 | List selectRolesVo(@Param("req") SysApiRolesReqVo reqVo); 24 | } 25 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysDeptMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDept; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * 部门 DAO 9 | * 10 | * @author Cade Li 11 | * @since 2023/11/24 12 | */ 13 | @Mapper 14 | public interface SysDeptMapper extends BaseMapper { 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysDictMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDict; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * 系统字典 DAO 9 | * 10 | * @author Cade Li 11 | * @since 2023/5/26 12 | */ 13 | @Mapper 14 | public interface SysDictMapper extends BaseMapper { 15 | } 16 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysMenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysMenu; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuRolesResVo; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统菜单DAO 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | @Mapper 19 | public interface SysMenuMapper extends BaseMapper { 20 | 21 | List selectByRoles(@Param("roleCodes") List roleCodes); 22 | 23 | List selectRolesVo(@Param("req") SysMenuRolesReqVo reqVo); 24 | 25 | List selectRolesVoByMenuIds(@Param("menuIds") List menuIds); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysRole; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleMappingReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleUnionReqVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleUnionResVo; 8 | import org.apache.ibatis.annotations.Mapper; 9 | import org.apache.ibatis.annotations.Param; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * 系统角色 DAO 15 | * 16 | * @author Cade Li 17 | * @date 2022/5/27 18 | */ 19 | @Mapper 20 | public interface SysRoleMapper extends BaseMapper { 21 | 22 | List selectByUserIds(@Param("userIds") List userIds); 23 | 24 | List selectByMenuIds(@Param("menuIds") List menuIds); 25 | 26 | List selectByApiIds(@Param("apiIds") List apiIds); 27 | 28 | int deleteRoleUserByUserIds(@Param("userIds") List userIds); 29 | 30 | int deleteRoleUserByRoleIds(@Param("roleIds") List roleIds); 31 | 32 | int deleteRoleMenuByMenuIds(@Param("menuIds") List menuIds); 33 | 34 | int deleteRoleMenuByRoleIds(@Param("roleIds") List roleIds); 35 | 36 | int deleteRoleApiByApiIds(@Param("apiIds") List apiIds); 37 | 38 | int deleteRoleApiByRoleIds(@Param("roleIds") List roleIds); 39 | 40 | int deleteRoleUser(List list); 41 | 42 | int deleteRoleMenu(List list); 43 | 44 | int deleteRoleApi(List list); 45 | 46 | int insertRoleUser(List list); 47 | 48 | int insertRoleMenu(List list); 49 | 50 | int insertRoleApi(List list); 51 | 52 | List selectUnionVo(@Param("req") SysRoleUnionReqVo reqVo); 53 | 54 | List selectUnionVoByRoleIds(@Param("roleIds") List roleIds); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/mapper/SysUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysUser; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesResVo; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统用户 DAO 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | @Mapper 19 | public interface SysUserMapper extends BaseMapper { 20 | 21 | List selectRolesVoByUserIds(@Param("userIds") List userIds); 22 | 23 | List selectRolesVoByUsername(@Param("username") String username); 24 | 25 | List selectRolesVo(@Param("req") SysUserRolesReqVo reqVo); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/security/JwtLoginSuccessHandleService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.security; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.strategy.StrategyContext; 4 | import com.github.cadecode.uniboot.common.core.util.TokenUtil; 5 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 6 | import com.github.cadecode.uniboot.framework.api.consts.HttpConst; 7 | import com.github.cadecode.uniboot.framework.api.enums.AuthModelEnum; 8 | import com.github.cadecode.uniboot.framework.base.security.model.SysUserDetails; 9 | import com.github.cadecode.uniboot.framework.base.util.SecurityUtil; 10 | import com.github.cadecode.uniboot.framework.svc.config.FrameSecurityConfig; 11 | import org.springframework.security.core.Authentication; 12 | import org.springframework.stereotype.Component; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | /** 18 | * 登录成功处理器 19 | * 20 | * @author Cade Li 21 | * @date 2021/12/11 22 | */ 23 | @Component 24 | public class JwtLoginSuccessHandleService extends LoginSuccessHandleService { 25 | 26 | @Override 27 | public ApiResult getResult(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { 28 | // 从认证信息中获取用户对象 29 | SysUserDetails sysUserDetails = (SysUserDetails) authentication.getPrincipal(); 30 | // 生成 jwt token 31 | String jwtToken = TokenUtil.generateToken(sysUserDetails.getId(), sysUserDetails.getUsername(), sysUserDetails.getRoles(), 32 | SecurityUtil.getTokenExpiration(), SecurityUtil.getTokenSecret()); 33 | // token 放在请求头 34 | response.addHeader(HttpConst.HEAD_TOKEN, jwtToken); 35 | return ApiResult.ok(sysUserDetails).path(FrameSecurityConfig.LOGOUT_URL); 36 | } 37 | 38 | @Override 39 | public boolean supports(StrategyContext delimiter) { 40 | return delimiter.getStrategyType() == AuthModelEnum.JWT; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/security/LoginFailureHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.security; 2 | 3 | import cn.hutool.core.util.CharsetUtil; 4 | import cn.hutool.extra.servlet.ServletUtil; 5 | import cn.hutool.http.ContentType; 6 | import com.github.cadecode.uniboot.common.core.exception.ApiException; 7 | import com.github.cadecode.uniboot.common.core.util.JacksonUtil; 8 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 9 | import com.github.cadecode.uniboot.framework.api.enums.AuthErrorEnum; 10 | import com.github.cadecode.uniboot.framework.svc.config.FrameSecurityConfig; 11 | import org.springframework.security.authentication.BadCredentialsException; 12 | import org.springframework.security.core.AuthenticationException; 13 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 14 | import org.springframework.stereotype.Component; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | 19 | /** 20 | * 登录失败处理器 21 | * 22 | * @author Cade Li 23 | * @date 2021/12/11 24 | */ 25 | @Component 26 | public class LoginFailureHandler implements AuthenticationFailureHandler { 27 | 28 | @Override 29 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, 30 | AuthenticationException exception) { 31 | ApiResult result = ApiResult.error(AuthErrorEnum.TOKEN_CREATE_ERROR).path(FrameSecurityConfig.LOGIN_URL); 32 | response.setStatus(AuthErrorEnum.TOKEN_CREATE_ERROR.getStatus()); 33 | Throwable cause = exception.getCause() == null ? exception : exception.getCause(); 34 | if (cause instanceof ApiException) { 35 | result.moreInfo(((ApiException) cause).getMoreInfo()); 36 | } else if (cause instanceof BadCredentialsException) { 37 | result.moreInfo("密码错误"); 38 | } 39 | ServletUtil.write(response, JacksonUtil.toJson(result), ContentType.JSON.toString(CharsetUtil.CHARSET_UTF_8)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/security/LoginSuccessHandleService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.security; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.strategy.StrategyService; 4 | import com.github.cadecode.uniboot.common.core.web.response.ApiResult; 5 | import com.github.cadecode.uniboot.framework.base.security.model.SysUserDetails; 6 | import org.springframework.security.core.Authentication; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | /** 12 | * 登录成功处理服务 13 | * 14 | * @author Cade Li 15 | * @since 2023/6/25 16 | */ 17 | public abstract class LoginSuccessHandleService implements StrategyService { 18 | 19 | public abstract ApiResult getResult(HttpServletRequest request, HttpServletResponse response, Authentication authentication); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysApiService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysApi; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesResVo; 7 | import com.github.pagehelper.PageInfo; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 系统接口服务 13 | * 14 | * @author Cade Li 15 | * @date 2022/5/27 16 | */ 17 | public interface SysApiService extends IService { 18 | 19 | List listRolesVo(); 20 | 21 | List listRolesVoByApiIds(List userIds); 22 | 23 | List listRolesVo(SysApiRolesReqVo reqVo); 24 | 25 | PageInfo pageRolesVo(SysApiRolesReqVo reqVo); 26 | } 27 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysDeptService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDept; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeResVo; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 部门服务 12 | * 13 | * @author Cade Li 14 | * @since 2023/11/24 15 | */ 16 | public interface SysDeptService extends IService { 17 | 18 | List listTreeVo(SysDeptTreeReqVo reqVo); 19 | } 20 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysDictService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDict; 5 | 6 | /** 7 | * 系统字典服务 8 | * 9 | * @author Cade Li 10 | * @since 2023/5/26 11 | */ 12 | public interface SysDictService extends IService { 13 | } 14 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysMenuService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysMenu; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuRolesResVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysMenuVo.SysMenuTreeResVo; 8 | import com.github.pagehelper.PageInfo; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统菜单服务 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | public interface SysMenuService extends IService { 19 | 20 | List listByRoles(List roleCodes); 21 | 22 | List listTreeVoByRoles(List roleCodes); 23 | 24 | List listRolesVo(SysMenuRolesReqVo reqVo); 25 | 26 | PageInfo pageRolesVo(SysMenuRolesReqVo reqVo); 27 | 28 | List listRolesVoByMenuIds(List menuIds); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysRoleService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysRole; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleMappingReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleUnionReqVo; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysRoleVo.SysRoleUnionResVo; 8 | import com.github.pagehelper.PageInfo; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统角色服务 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | public interface SysRoleService extends IService { 19 | 20 | List listByUserIds(List userIds); 21 | 22 | List listByMenuIds(List menuIds); 23 | 24 | List listByApiIds(List apiIds); 25 | 26 | int removeRoleUserByUserIds(List userIds); 27 | 28 | int removeRoleUserByRoleIds(List roleIds); 29 | 30 | int removeRoleMenuByMenuIds(List menuIds); 31 | 32 | int removeRoleMenuByRoleIds(List roleIds); 33 | 34 | int removeRoleApiByApiIds(List apiIds); 35 | 36 | int removeRoleApiByRoleIds(List roleIds); 37 | 38 | int removeRoleUser(List list); 39 | 40 | int removeRoleMenu(List list); 41 | 42 | int removeRoleApi(List list); 43 | 44 | int addRoleUser(List list); 45 | 46 | int addRoleMenu(List list); 47 | 48 | int addRoleApi(List list); 49 | 50 | List listUnionVo(SysRoleUnionReqVo reqVo); 51 | 52 | PageInfo pageUnionVo(SysRoleUnionReqVo reqVo); 53 | 54 | List listUnionVoByRoleIds(List roleIds); 55 | } 56 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysUser; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysUserVo.SysUserRolesResVo; 7 | import com.github.pagehelper.PageInfo; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * 系统用户服务 14 | * 15 | * @author Cade Li 16 | * @date 2022/5/27 17 | */ 18 | public interface SysUserService extends IService, UserDetailsService { 19 | 20 | List listRolesVoByUserIds(List userIds); 21 | 22 | List listRolesVo(SysUserRolesReqVo reqVo); 23 | 24 | PageInfo pageRolesVo(SysUserRolesReqVo reqVo); 25 | } 26 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/serviceimpl/SysApiServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.serviceimpl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysApi; 5 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesReqVo; 6 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysApiVo.SysApiRolesResVo; 7 | import com.github.cadecode.uniboot.framework.svc.mapper.SysApiMapper; 8 | import com.github.cadecode.uniboot.framework.svc.service.SysApiService; 9 | import com.github.pagehelper.PageHelper; 10 | import com.github.pagehelper.PageInfo; 11 | import lombok.RequiredArgsConstructor; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * 系统接口服务实现 18 | * 19 | * @author Cade Li 20 | * @date 2022/5/27 21 | */ 22 | @RequiredArgsConstructor 23 | @Service 24 | public class SysApiServiceImpl extends ServiceImpl implements SysApiService { 25 | 26 | private final SysApiMapper sysApiMapper; 27 | 28 | @Override 29 | public List listRolesVo() { 30 | return sysApiMapper.selectRolesVo(null); 31 | } 32 | 33 | @Override 34 | public List listRolesVoByApiIds(List userIds) { 35 | return sysApiMapper.selectRolesVoByApiIds(userIds); 36 | } 37 | 38 | @Override 39 | public List listRolesVo(SysApiRolesReqVo reqVo) { 40 | return sysApiMapper.selectRolesVo(reqVo); 41 | } 42 | 43 | @Override 44 | public PageInfo pageRolesVo(SysApiRolesReqVo reqVo) { 45 | return PageHelper.startPage(reqVo.getPageNumber(), reqVo.getPageSize()) 46 | .doSelectPageInfo(() -> listRolesVo(reqVo)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/serviceimpl/SysDeptServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.serviceimpl; 2 | 3 | import cn.hutool.core.util.ObjUtil; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.github.cadecode.uniboot.common.core.util.TreeUtil; 6 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDept; 7 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeReqVo; 8 | import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeResVo; 9 | import com.github.cadecode.uniboot.framework.svc.convert.SysDeptConvert; 10 | import com.github.cadecode.uniboot.framework.svc.mapper.SysDeptMapper; 11 | import com.github.cadecode.uniboot.framework.svc.service.SysDeptService; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.Comparator; 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | /** 19 | * 部门服务实现 20 | * 21 | * @author Cade Li 22 | * @since 2023/11/24 23 | */ 24 | @Service 25 | public class SysDeptServiceImpl extends ServiceImpl implements SysDeptService { 26 | @Override 27 | public List listTreeVo(SysDeptTreeReqVo reqVo) { 28 | List poList = lambdaQuery() 29 | .likeRight(ObjUtil.isNotEmpty(reqVo.getDeptName()), SysDept::getDeptName, reqVo.getDeptName()) 30 | .list() 31 | .stream() 32 | .sorted(Comparator.comparing(SysDept::getOrderNum)) 33 | .collect(Collectors.toList()); 34 | List treeResVoList = SysDeptConvert.INSTANCE.poToTreeResVo(poList); 35 | return TreeUtil.listToTree(treeResVoList, null, SysDeptTreeResVo::getId, SysDeptTreeResVo::getParentId, SysDeptTreeResVo::setChildren); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/serviceimpl/SysDictServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc.serviceimpl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.github.cadecode.uniboot.framework.svc.bean.po.SysDict; 5 | import com.github.cadecode.uniboot.framework.svc.mapper.SysDictMapper; 6 | import com.github.cadecode.uniboot.framework.svc.service.SysDictService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * 系统字典服务实现 11 | * 12 | * @author Cade Li 13 | * @since 2023/5/26 14 | */ 15 | @Service 16 | public class SysDictServiceImpl extends ServiceImpl implements SysDictService { 17 | } 18 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ _ ___ ___ ___ ___ _____ 2 | | | | | | \| | |_ _| | _ ) / _ \ / _ \ |_ _| 3 | | |_| | | .` | | | | _ \ | (_) | | (_) | | | 4 | \___/ |_|\_| |___| |___/ \___/ \___/ _|_|_ 5 | _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 6 | "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 7 | :: Spring Boot :: (${spring-boot.version}) 8 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | file: 3 | path: /log/uni_boot_admin/framework 4 | 5 | spring: 6 | application: 7 | name: uni-boot-framework 8 | cloud: 9 | nacos: 10 | server-addr: localhost:8848 11 | username: nacos 12 | password: nacos 13 | discovery: 14 | enabled: true 15 | namespace: uni_dev 16 | group: DEFAULT_GROUP 17 | config: 18 | enabled: true 19 | namespace: uni_dev 20 | group: DEFAULT_GROUP 21 | file-extension: yml 22 | shared-configs: 23 | - shared-config.${spring.cloud.nacos.config.file-extension} 24 | - shared-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} 25 | -------------------------------------------------------------------------------- /framework/framework_svc/src/main/resources/spy.properties: -------------------------------------------------------------------------------- 1 | # 配置日志拦截模块 2 | # 加入 MybatisPlus 日志 3 | modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory 4 | # 设置日志打印格式 5 | logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat 6 | customLogMessageFormat===> P6Spy: %(executionTime) ms, connection%(connectionId), sql: %(sqlSingleLine) 7 | # 设置日志系统 8 | # 使用 SLF4J 即系统日志 9 | appender=com.p6spy.engine.spy.appender.Slf4JLogger 10 | # 设置 p6spy driver 代理 11 | deregisterdrivers=true 12 | # 取消 JDBC URL 前缀 13 | useprefix=true 14 | # 设置要排除的日志记录 15 | excludecategories=info,debug,result,commit,resultset 16 | # 设置日期格式 17 | dateformat=yyyy-MM-dd HH:mm:ss 18 | # 开启慢 SQL 记录 19 | outagedetection=true 20 | # 设置慢 SQL 记录标准 2 秒 21 | outagedetectioninterval=2 22 | -------------------------------------------------------------------------------- /framework/framework_svc/src/test/java/com/github/cadecode/uniboot/framework/svc/JasyptEncryptorTest.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc; 2 | 3 | import org.jasypt.encryption.StringEncryptor; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | /** 9 | * 用于生成加密配置的测试工具 10 | * 11 | * @author Cade Li 12 | * @since 2023/4/24 13 | */ 14 | @SpringBootTest 15 | public class JasyptEncryptorTest { 16 | 17 | @Autowired 18 | private StringEncryptor stringEncryptor; 19 | 20 | @Test 21 | void encrypt() { 22 | // 执行加密前需要在配置文件中配置jasypt.encryptor.password 23 | stringEncryptor.encrypt("string waiting encrypt"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /framework/framework_svc/src/test/java/com/github/cadecode/uniboot/framework/svc/UniFrameworkApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.framework.svc; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | /** 8 | * 主测试类 9 | * 10 | * @author Cade Li 11 | * @date 2022/5/8 12 | */ 13 | @SpringBootTest 14 | public class UniFrameworkApplicationTests { 15 | 16 | @Test 17 | void contextLoads() { 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /framework/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | uni-boot-parent 7 | com.github.cadecode 8 | 2024.2.0 9 | 10 | 4.0.0 11 | 12 | pom 13 | uni-boot-framework 14 | 系统框架模块 15 | 16 | 17 | framework_api 18 | framework_base 19 | framework_svc 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gateway/src/main/java/com/github/cadecode/uniboot/gateway/UniGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.gateway; 2 | 3 | import com.github.cadecode.uniboot.common.core.extension.strategy.StrategyService; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 9 | import org.springframework.plugin.core.config.EnablePluginRegistries; 10 | 11 | /** 12 | * 启动类 13 | */ 14 | @EnablePluginRegistries({StrategyService.class}) 15 | @EnableFeignClients("com.github.cadecode") 16 | @EnableDiscoveryClient 17 | @EnableAspectJAutoProxy(exposeProxy = true) 18 | @SpringBootApplication 19 | public class UniGatewayApplication { 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(UniGatewayApplication.class, args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gateway/src/main/java/com/github/cadecode/uniboot/gateway/filter/RequestHeaderFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.gateway.filter; 2 | 3 | import com.github.cadecode.uniboot.framework.api.consts.HttpConst; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.http.server.reactive.ServerHttpRequest; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.server.ServerWebExchange; 10 | import reactor.core.publisher.Mono; 11 | 12 | /** 13 | * 请求头统一过滤 14 | * 15 | * @author Cade Li 16 | * @since 2023/8/8 17 | */ 18 | @Order(1) 19 | @Component 20 | public class RequestHeaderFilter implements GlobalFilter { 21 | 22 | @Override 23 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 24 | // 去掉内部调用专用的请求头,防止伪造 25 | ServerHttpRequest request = exchange.getRequest().mutate() 26 | .headers(h -> { 27 | h.remove(HttpConst.HEAD_SOURCE); 28 | h.remove(HttpConst.HEAD_USER_DETAILS); 29 | }) 30 | .build(); 31 | return chain.filter(exchange.mutate().request(request).build()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gateway/src/main/java/com/github/cadecode/uniboot/gateway/filter/TraceInfoFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.cadecode.uniboot.gateway.filter; 2 | 3 | import cn.hutool.core.lang.UUID; 4 | import com.github.cadecode.uniboot.framework.api.consts.HttpConst; 5 | import org.slf4j.MDC; 6 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 7 | import org.springframework.cloud.gateway.filter.GlobalFilter; 8 | import org.springframework.core.annotation.Order; 9 | import org.springframework.http.server.reactive.ServerHttpRequest; 10 | import org.springframework.stereotype.Component; 11 | import org.springframework.web.server.ServerWebExchange; 12 | import reactor.core.publisher.Mono; 13 | 14 | /** 15 | * 用于添加 trace id 的过滤器 16 | * 17 | * @author Cade Li 18 | * @since 2023/8/10 19 | */ 20 | @Order(0) 21 | @Component 22 | public class TraceInfoFilter implements GlobalFilter { 23 | 24 | @Override 25 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 26 | String traceId = UUID.fastUUID().toString(true); 27 | ServerHttpRequest request = exchange.getRequest().mutate() 28 | .headers(h -> { 29 | MDC.put(HttpConst.HEAD_TRACE_ID, traceId); 30 | h.set(HttpConst.HEAD_TRACE_ID, traceId); 31 | }) 32 | .build(); 33 | exchange.getResponse().getHeaders().set(HttpConst.HEAD_TRACE_ID, traceId); 34 | return chain.filter(exchange.mutate().request(request).build()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gateway/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ _ ___ ___ ___ ___ _____ 2 | | | | | | \| | |_ _| | _ ) / _ \ / _ \ |_ _| 3 | | |_| | | .` | | | | _ \ | (_) | | (_) | | | 4 | \___/ |_|\_| |___| |___/ \___/ \___/ _|_|_ 5 | _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 6 | "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 7 | :: Spring Boot :: (${spring-boot.version}) 8 | -------------------------------------------------------------------------------- /gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | file: 3 | path: /log/uni_boot_admin/gateway 4 | 5 | spring: 6 | application: 7 | name: uni-boot-gateway 8 | cloud: 9 | nacos: 10 | server-addr: localhost:8848 11 | username: nacos 12 | password: nacos 13 | discovery: 14 | enabled: true 15 | namespace: uni_dev 16 | group: DEFAULT_GROUP 17 | config: 18 | enabled: true 19 | namespace: uni_dev 20 | group: DEFAULT_GROUP 21 | file-extension: yml 22 | shared-configs: 23 | - shared-config.${spring.cloud.nacos.config.file-extension} 24 | - shared-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} 25 | -------------------------------------------------------------------------------- /gateway/src/main/resources/spy.properties: -------------------------------------------------------------------------------- 1 | # 配置日志拦截模块 2 | # 加入 MybatisPlus 日志 3 | modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory 4 | # 设置日志打印格式 5 | logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat 6 | customLogMessageFormat===> P6Spy: %(executionTime) ms, connection%(connectionId), sql: %(sqlSingleLine) 7 | # 设置日志系统 8 | # 使用 SLF4J 即系统日志 9 | appender=com.p6spy.engine.spy.appender.Slf4JLogger 10 | # 设置 p6spy driver 代理 11 | deregisterdrivers=true 12 | # 取消 JDBC URL 前缀 13 | useprefix=true 14 | # 设置要排除的日志记录 15 | excludecategories=info,debug,result,commit,resultset 16 | # 设置日期格式 17 | dateformat=yyyy-MM-dd HH:mm:ss 18 | # 开启慢 SQL 记录 19 | outagedetection=true 20 | # 设置慢 SQL 记录标准 2 秒 21 | outagedetectioninterval=2 22 | --------------------------------------------------------------------------------