From 9e702d1aea5fb6c4e584986d7bc075d310583282 Mon Sep 17 00:00:00 2001 From: Parker Date: Thu, 19 Nov 2020 10:34:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=A0=B8=E5=BF=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../org/opsli/api/base/result/ResultVo.java | 17 +- .../opsli/api/base/warpper/ApiWrapper.java | 19 + .../opsli/api/conf/SpringWebMvcConfig.java | 49 ++- .../api/conf/prop/ApiPathProperties.java | 17 +- .../java/org/opsli/api/msg/ValidationMsg.java | 15 + .../thread/factory/NameableThreadFactory.java | 59 +++ .../org/opsli/api/utils/ValidationUtil.java | 27 +- .../opsli/api/web/system/dict/DictApi.java | 29 +- .../api/web/system/dict/DictDetailApi.java | 20 +- .../opsli/api/web/system/logs/LogsApi.java | 85 +++++ .../opsli/api/web/system/menu/MenuApi.java | 62 ++- .../opsli/api/web/system/role/RoleApi.java | 20 +- .../api/web/system/role/RoleMenuRefApi.java | 67 ++++ .../api/web/system/tenant/TenantApi.java | 128 +++++++ .../opsli/api/web/system/user/UserApi.java | 71 +++- .../api/web/system/user/UserRoleRefApi.java | 55 +++ .../org/opsli/api/web/test/TestRestApi.java | 128 +++++++ .../wrapper/system/dict/DictDetailModel.java | 31 +- .../api/wrapper/system/dict/DictModel.java | 27 +- .../api/wrapper/system/dict/DictWrapper.java | 15 + .../api/wrapper/system/logs/LogsModel.java | 77 ++++ .../api/wrapper/system/menu/MenuModel.java | 75 +++- .../wrapper/system/role/RoleMenuRefModel.java | 52 +++ .../api/wrapper/system/role/RoleModel.java | 38 +- .../wrapper/system/tenant/TenantModel.java | 67 ++++ .../api/wrapper/system/user/UserInfo.java | 109 ++++++ .../api/wrapper/system/user/UserModel.java | 44 ++- .../api/wrapper/system/user/UserPassword.java | 68 ++++ .../wrapper/system/user/UserRoleRefModel.java | 52 +++ .../org/opsli/api/wrapper/test/TestModel.java | 17 +- .../common/annotation/ApiRestController.java | 15 + .../opsli/common/annotation/EnableLog.java | 36 ++ .../annotation/hotdata/EnableHotData.java | 15 + .../common/annotation/hotdata/HotDataDel.java | 15 + .../common/annotation/hotdata/HotDataPut.java | 15 + .../annotation/validation/ValidationArgs.java | 15 + .../validation/ValidationArgsLenMax.java | 38 ++ .../validation/ValidationArgsLenMin.java | 38 ++ .../validation/ValidationArgsMax.java | 23 -- .../validation/ValidationArgsMin.java | 23 -- .../java/org/opsli/common/api/ResultDto.java | 19 +- .../org/opsli/common/api/ResultVoMap.java | 33 +- .../opsli/common/api/TokenThreadLocal.java | 15 + .../org/opsli/common/base/msg/BaseMsg.java | 15 + .../common/constants/CacheConstants.java | 15 + .../opsli/common/constants/DictConstants.java | 22 +- .../common/constants/MyBatisConstants.java | 20 +- .../common/constants/OrderConstants.java | 21 + .../opsli/common/constants/SignConstants.java | 15 + .../common/constants/TokenConstants.java | 17 +- .../java/org/opsli/common/enums/DictType.java | 27 ++ .../org/opsli/common/enums/ExcelOperate.java | 15 + .../org/opsli/common/enums/SystemInfo.java | 15 + .../org/opsli/common/enums/ValiArgsType.java | 15 + .../common/exception/EmptyException.java | 15 + .../opsli/common/exception/JwtException.java | 15 + .../common/exception/ServiceException.java | 15 + .../common/exception/TokenException.java | 15 + .../opsli/common/exception/WafException.java | 35 ++ .../java/org/opsli/common/msg/CommonMsg.java | 15 + .../java/org/opsli/common/utils/HumpUtil.java | 15 + .../java/org/opsli/common/utils/IPUtil.java | 147 +++++++ .../org/opsli/common/utils/PackageUtil.java | 17 +- .../java/org/opsli/common/utils/Props.java | 361 ++++++++++++++++++ .../org/opsli/common/utils/WrapperUtil.java | 56 +++ .../org/opsli/core/aspect/CacheDataAop.java | 15 + .../org/opsli/core/aspect/SQLDataAop.java | 15 + .../java/org/opsli/core/aspect/TokenAop.java | 46 ++- .../UserCachingOperationNameGenerator.java | 15 + .../opsli/core/aspect/ValitaionArgsAop.java | 22 +- .../base/concroller/BaseRestController.java | 32 ++ .../opsli/core/base/entity/BaseEntity.java | 15 + .../core/base/service/base/BaseService.java | 15 + .../base/service/impl/CrudServiceImpl.java | 49 ++- .../interfaces/BaseServiceInterface.java | 15 + .../interfaces/CrudServiceInterface.java | 19 +- .../org/opsli/core/cache/local/CacheUtil.java | 45 ++- .../cache/pushsub/entity/CacheDataEntity.java | 15 + .../core/cache/pushsub/enums/CacheType.java | 15 + .../cache/pushsub/enums/DictModelType.java | 15 + .../core/cache/pushsub/enums/MsgArgsType.java | 19 + .../core/cache/pushsub/enums/PushSubType.java | 18 + .../cache/pushsub/enums/UserModelType.java | 15 + .../cache/pushsub/handler/DictHandler.java | 15 + .../pushsub/handler/EdenDataHandler.java | 15 + .../cache/pushsub/handler/HotDataHandler.java | 15 + .../cache/pushsub/handler/MenuHandler.java | 75 ++++ .../pushsub/handler/RedisPushSubHandler.java | 15 + .../cache/pushsub/handler/UserHandler.java | 58 +-- .../pushsub/msgs/CacheDataMsgFactory.java | 15 + .../cache/pushsub/msgs/DictMsgFactory.java | 15 + .../cache/pushsub/msgs/MenuMsgFactory.java | 60 +++ .../cache/pushsub/msgs/UserMsgFactory.java | 15 + .../receiver/RedisPushSubReceiver.java | 34 +- .../org/opsli/core/conf/KaptchaConfig.java | 15 + .../opsli/core/conf/MyBatisPlusConfig.java | 15 + .../core/conf/RedisMessageListenerConfig.java | 17 +- .../java/org/opsli/core/conf/ShiroConfig.java | 16 + .../org/opsli/core/conf/SwaggerConfig.java | 28 +- .../java/org/opsli/core/conf/WafConfig.java | 42 +- .../conf/mybatis/AutoFillInterceptor.java | 51 ++- .../org/opsli/core/general/StartPrint.java | 75 +++- .../core/handler/GlobalExceptionHandler.java | 57 ++- .../ApplicationReadyEventListene.java | 7 +- .../main/java/org/opsli/core/msg/CoreMsg.java | 33 +- .../main/java/org/opsli/core/msg/JwtMsg.java | 15 + .../java/org/opsli/core/msg/TokenMsg.java | 19 +- .../java/org/opsli/core/persistence/Page.java | 34 +- .../querybuilder/GenQueryBuilder.java | 15 + .../querybuilder/QueryBuilder.java | 16 +- .../querybuilder/WebQueryBuilder.java | 21 +- .../querybuilder/chain/QueryBuilderChain.java | 15 + .../querybuilder/chain/TenantHandler.java | 15 + .../security/shiro/filter/OAuth2Filter.java | 8 +- .../security/shiro/realm/OAuth2Realm.java | 7 +- .../org/opsli/core/thread/LogsThreadPool.java | 62 +++ .../org/opsli/core/utils/CaptchaUtil.java | 40 +- .../java/org/opsli/core/utils/DictUtil.java | 107 +++++- .../java/org/opsli/core/utils/ExcelUtil.java | 21 + .../java/org/opsli/core/utils/JwtUtil.java | 5 +- .../java/org/opsli/core/utils/LogUtil.java | 204 ++++++++++ .../java/org/opsli/core/utils/MenuUtil.java | 170 +++++++++ .../opsli/core/utils/SpringContextHolder.java | 81 ++++ .../org/opsli/core/utils/TokenGenerator.java | 15 + .../org/opsli/core/utils/UserTokenUtil.java | 51 ++- .../java/org/opsli/core/utils/UserUtil.java | 179 +++++---- ...{XssProperties.java => WafProperties.java} | 38 +- .../org/opsli/core/waf/filter/WafFilter.java | 16 + .../servlet/WafHttpServletRequestWrapper.java | 43 +-- .../org/opsli/core/waf/util/SQLFilterKit.java | 48 ++- .../org/opsli/core/waf/util/XSSFilterKit.java | 15 + .../opsli-modulars-creater/README.md | 1 + opsli-modulars/opsli-modulars-creater/pom.xml | 15 + .../opsli/core/creater/msg/CreaterMsg.java | 64 ++++ .../strategy/sync/MySQLSyncBuilder.java | 169 ++++++++ .../creater/strategy/sync/SyncStrategy.java | 25 ++ .../sync/mysql/entity/FieldTypeAttribute.java | 28 ++ .../sync/mysql/enums/MySQLSyncColumnType.java | 54 +++ .../strategy/sync/util/SQLSyncUtil.java | 81 ++++ .../column/entity/CreaterTableColumn.java | 81 ++++ .../column/mapper/TableColumnMapper.java | 40 ++ .../column/mapper/xml/TableColumnMapper.xml | 20 + .../column/service/ITableColumnService.java | 54 +++ .../service/impl/TableColumnServiceImpl.java | 170 +++++++++ .../wrapper/CreaterTableColumnModel.java | 163 ++++++++ .../creater/general/actuator/SQLActuator.java | 37 ++ .../modulars/creater/table/api/TableApi.java | 113 ++++++ .../creater/table/entity/CreaterTable.java | 62 +++ .../creater/table/mapper/TableMapper.java | 45 +++ .../creater/table/mapper/xml/TableMapper.xml | 26 ++ .../creater/table/service/ITableService.java | 66 ++++ .../table/service/impl/TableServiceImpl.java | 180 +++++++++ .../table/web/TableRestController.java | 227 +++++++++++ .../wrapper/CreaterTableAndColumnModel.java | 108 ++++++ .../table/wrapper/CreaterTableModel.java | 98 +++++ .../src/main/resources/creater.yaml | 14 + .../org/opsli/modulars/system/SystemMsg.java | 41 +- .../modulars/system/dict/entity/SysDict.java | 18 + .../system/dict/entity/SysDictDetail.java | 18 + .../system/dict/mapper/DictDetailMapper.java | 15 + .../system/dict/mapper/DictMapper.java | 15 + .../dict/service/IDictDetailService.java | 15 + .../system/dict/service/IDictService.java | 15 + .../service/impl/DictDetailServiceImpl.java | 45 ++- .../dict/service/impl/DictServiceImpl.java | 36 +- .../dict/web/DictDetailRestController.java | 98 ++++- .../system/dict/web/DictRestController.java | 120 +++++- .../system/login/entity/LoginForm.java | 14 +- .../system/login/web/LoginRestController.java | 124 +++++- .../opsli/modulars/system/logs/api/README.md | 1 + .../modulars/system/logs/entity/SysLogs.java | 73 ++++ .../system/logs/mapper/LogsMapper.java | 41 ++ .../system/logs/mapper/xml/LogsMapper.xml | 11 + .../system/logs/service/ILogsService.java | 38 ++ .../logs/service/impl/LogsServiceImpl.java | 63 +++ .../system/logs/web/LogsRestController.java | 105 +++++ .../modulars/system/menu/entity/SysMenu.java | 34 +- .../system/menu/mapper/MenuMapper.java | 15 + .../xml/{RoleMapper.xml => MenuMapper.xml} | 7 +- .../system/menu/service/IMenuService.java | 22 ++ .../menu/service/impl/MenuServiceImpl.java | 116 +++++- .../system/menu/web/MenuRestController.java | 285 ++++++++++++++ .../modulars/system/role/entity/SysRole.java | 21 + .../system/role/entity/SysRoleMenuRef.java | 46 +++ .../system/role/mapper/RoleMapper.java | 21 +- .../system/role/mapper/RoleMenuRefMapper.java | 42 ++ .../system/role/mapper/xml/RoleMapper.xml | 14 +- .../role/mapper/xml/RoleMenuRefMapper.xml | 19 + .../role/service/IRoleMenuRefService.java | 46 +++ .../system/role/service/IRoleService.java | 15 + .../service/impl/RoleMenuRefServiceImpl.java | 96 +++++ .../role/service/impl/RoleServiceImpl.java | 35 +- .../role/web/RoleMenuRefRestController.java | 147 +++++++ .../system/role/web/RoleRestController.java | 92 +++++ .../modulars/system/tenant/api/README.md | 1 + .../system/tenant/entity/SysTenant.java | 54 +++ .../system/tenant/mapper/TenantMapper.java | 41 ++ .../system/tenant/mapper/xml/TenantMapper.xml | 20 + .../system/tenant/service/ITenantService.java | 33 ++ .../service/impl/TenantServiceImpl.java | 78 ++++ .../tenant/web/TenantRestController.java | 198 ++++++++++ .../modulars/system/user/entity/SysUser.java | 24 ++ .../system/user/entity/SysUserRoleRef.java | 46 +++ .../system/user/mapper/UserMapper.java | 54 ++- .../system/user/mapper/UserRoleRefMapper.java | 47 +++ .../system/user/mapper/xml/UserMapper.xml | 67 +++- .../user/mapper/xml/UserRoleRefMapper.xml | 25 ++ .../user/service/IUserRoleRefService.java | 51 +++ .../system/user/service/IUserService.java | 46 +++ .../service/impl/UserRoleRefServiceImpl.java | 97 +++++ .../user/service/impl/UserServiceImpl.java | 164 +++++++- .../system/user/web/UserRestController.java | 214 ++++++++++- .../user/web/UserRoleRefRestController.java | 86 +++++ .../modulars/test/web/TestRestController.java | 173 +++++++++ .../test/web/TestRestRestController.java | 2 +- .../test/web/TestRestRestController2.java | 2 +- opsli-modulars/pom.xml | 3 +- .../opsli/plugins/cache/EhCachePlugin.java | 15 + .../plugins/cache/conf/EhCacheConfig.java | 17 +- .../opsli/plugins/cache/msg/EhCacheMsg.java | 15 + .../cache/service/EhCachePluginImpl.java | 24 +- .../org/opsli/plugins/excel/ExcelPlugin.java | 17 +- .../excel/annotation/CellFontFormat.java | 15 + .../excel/annotation/CellStyleFormat.java | 17 +- .../plugins/excel/annotation/ExcelInfo.java | 17 +- .../excel/exception/ExcelPluginException.java | 15 + .../excel/factory/ExcelWriterFactory.java | 17 +- .../plugins/excel/listener/ExcelListener.java | 17 +- .../org/opsli/plugins/excel/msg/ExcelMsg.java | 17 +- .../org/opsli/plugins/mail/MailPlugin.java | 15 + .../mail/exception/MailPluginException.java | 15 + .../plugins/mail/handler/MailPlugInImpl.java | 15 + .../opsli/plugins/mail/model/MailModel.java | 15 + .../org/opsli/plugins/mail/msg/MailMsg.java | 15 + .../opsli/plugins/redis/RedisLockPlugins.java | 15 + .../org/opsli/plugins/redis/RedisPlugin.java | 19 +- .../plugins/redis/conf/RedisPluginConfig.java | 49 ++- .../redis/exception/RedisPluginException.java | 15 + .../opsli/plugins/redis/lock/RedisLock.java | 15 + .../plugins/redis/lock/RedisLockImpl.java | 15 + .../org/opsli/plugins/redis/msg/RedisMsg.java | 15 + .../redis/pushsub/entity/BaseSubMessage.java | 17 +- .../pushsub/entity/RedisPushSubMessage.java | 15 + .../redis/scripts/RedisScriptCache.java | 15 + .../redis/scripts/enums/RedisScriptsEnum.java | 15 + opsli-starter/pom.xml | 8 +- .../main/java/org/opsli/OpsliApplication.java | 24 +- .../src/main/resources/application-beta.yaml | 64 ++-- .../src/main/resources/application-dev.yaml | 16 +- .../main/resources/application-release.yaml | 47 ++- .../src/main/resources/application.yaml | 41 +- .../resources/{config => }/logback-spring.xml | 0 pom.xml | 38 +- 254 files changed, 10677 insertions(+), 582 deletions(-) create mode 100644 opsli-api/src/main/java/org/opsli/api/thread/factory/NameableThreadFactory.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/system/logs/LogsApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/system/role/RoleMenuRefApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/system/user/UserRoleRefApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/web/test/TestRestApi.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/logs/LogsModel.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleMenuRefModel.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/tenant/TenantModel.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserPassword.java create mode 100644 opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserRoleRefModel.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/EnableLog.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMax.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMin.java delete mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMax.java delete mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMin.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/WafException.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java create mode 100644 opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/MenuMsgFactory.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/thread/LogsThreadPool.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/MenuUtil.java create mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/SpringContextHolder.java rename opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/{XssProperties.java => WafProperties.java} (58%) create mode 100644 opsli-modulars/opsli-modulars-creater/README.md create mode 100644 opsli-modulars/opsli-modulars-creater/pom.xml create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/util/SQLSyncUtil.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/TableColumnMapper.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/xml/TableColumnMapper.xml create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/ITableColumnService.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/impl/TableColumnServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/general/actuator/SQLActuator.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/TableMapper.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/xml/TableMapper.xml create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/ITableService.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/web/TableRestController.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableAndColumnModel.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableModel.java create mode 100644 opsli-modulars/opsli-modulars-creater/src/main/resources/creater.yaml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/api/README.md create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/entity/SysLogs.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/LogsMapper.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/xml/LogsMapper.xml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/ILogsService.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/impl/LogsServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/web/LogsRestController.java rename opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/{RoleMapper.xml => MenuMapper.xml} (89%) create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRoleMenuRef.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMenuRefMapper.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMenuRefMapper.xml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleMenuRefService.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleMenuRefServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/web/RoleMenuRefRestController.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/api/README.md create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/entity/SysTenant.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/TenantMapper.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/xml/TenantMapper.xml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserRoleRef.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserRoleRefMapper.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserRoleRefMapper.xml create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserRoleRefService.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java create mode 100644 opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRoleRefRestController.java create mode 100644 opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java rename opsli-starter/src/main/resources/{config => }/logback-spring.xml (100%) diff --git a/.gitignore b/.gitignore index 5ee6550..b1866c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store HELP.md target/ !.mvn/wrapper/maven-wrapper.jar diff --git a/opsli-api/src/main/java/org/opsli/api/base/result/ResultVo.java b/opsli-api/src/main/java/org/opsli/api/base/result/ResultVo.java index ad3f64c..f25f2d7 100644 --- a/opsli-api/src/main/java/org/opsli/api/base/result/ResultVo.java +++ b/opsli-api/src/main/java/org/opsli/api/base/result/ResultVo.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.base.result; import com.alibaba.fastjson.JSONObject; @@ -179,4 +194,4 @@ public class ResultVo implements Serializable { return ret; } -} \ No newline at end of file +} diff --git a/opsli-api/src/main/java/org/opsli/api/base/warpper/ApiWrapper.java b/opsli-api/src/main/java/org/opsli/api/base/warpper/ApiWrapper.java index b708dd7..42654f7 100644 --- a/opsli-api/src/main/java/org/opsli/api/base/warpper/ApiWrapper.java +++ b/opsli-api/src/main/java/org/opsli/api/base/warpper/ApiWrapper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.base.warpper; import com.alibaba.excel.annotation.ExcelIgnore; @@ -94,4 +109,8 @@ public abstract class ApiWrapper implements Serializable { /** 是否是内部Api调用 */ @TableField(exist = false) private Boolean izApi = false; + + /** 是否 手动操控 (如果为true 则可以手动指定创建人和修改人 如果为空则默认) */ + @TableField(exist = false) + private Boolean izManual = false; } diff --git a/opsli-api/src/main/java/org/opsli/api/conf/SpringWebMvcConfig.java b/opsli-api/src/main/java/org/opsli/api/conf/SpringWebMvcConfig.java index a9e4edc..32bfc1c 100644 --- a/opsli-api/src/main/java/org/opsli/api/conf/SpringWebMvcConfig.java +++ b/opsli-api/src/main/java/org/opsli/api/conf/SpringWebMvcConfig.java @@ -1,9 +1,29 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.conf; import lombok.extern.slf4j.Slf4j; import org.opsli.api.conf.prop.ApiPathProperties; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.utils.Props; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -17,6 +37,14 @@ import javax.annotation.Resource; @Configuration public class SpringWebMvcConfig implements WebMvcConfigurer { + /** 虚拟根路径 */ + private static final String BASE_DIR; + static { + Props props = new Props("application.yaml"); + BASE_DIR = props.getStr("server.tomcat.basedir"); + } + + @Resource private ApiPathProperties apiPathProperties; @@ -30,5 +58,24 @@ public class SpringWebMvcConfig implements WebMvcConfigurer { .addPathPrefix(apiPathProperties.getGlobalPrefix(),c -> c.isAnnotationPresent(ApiRestController.class)); } - + /** + * 解决跨域问题 + * @return + */ + @Bean + public CorsFilter corsFilter() { + final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); + final CorsConfiguration corsConfiguration = new CorsConfiguration(); + /* 是否允许请求带有验证信息 */ + corsConfiguration.setAllowCredentials(true); + /* 允许访问的客户端域名 */ + corsConfiguration.addAllowedOrigin("*"); + /* 允许服务端访问的客户端请求头 */ + corsConfiguration.addAllowedHeader("*"); + /* 允许访问的方法名,GET POST等 */ + corsConfiguration.addAllowedMethod("*"); + urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); + return new CorsFilter(urlBasedCorsConfigurationSource); + } + } diff --git a/opsli-api/src/main/java/org/opsli/api/conf/prop/ApiPathProperties.java b/opsli-api/src/main/java/org/opsli/api/conf/prop/ApiPathProperties.java index 205831e..917d8b8 100644 --- a/opsli-api/src/main/java/org/opsli/api/conf/prop/ApiPathProperties.java +++ b/opsli-api/src/main/java/org/opsli/api/conf/prop/ApiPathProperties.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.conf.prop; import lombok.Data; @@ -15,4 +30,4 @@ public class ApiPathProperties { String globalPrefix = "api"; -} \ No newline at end of file +} diff --git a/opsli-api/src/main/java/org/opsli/api/msg/ValidationMsg.java b/opsli-api/src/main/java/org/opsli/api/msg/ValidationMsg.java index dbab91c..54cc7bb 100644 --- a/opsli-api/src/main/java/org/opsli/api/msg/ValidationMsg.java +++ b/opsli-api/src/main/java/org/opsli/api/msg/ValidationMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-api/src/main/java/org/opsli/api/thread/factory/NameableThreadFactory.java b/opsli-api/src/main/java/org/opsli/api/thread/factory/NameableThreadFactory.java new file mode 100644 index 0000000..e16d609 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/thread/factory/NameableThreadFactory.java @@ -0,0 +1,59 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.thread.factory; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created Date by 2019/12/26 0026. + * 自定义线程池工厂 + * @author Parker + */ +public class NameableThreadFactory implements ThreadFactory{ + + private final AtomicInteger poolNumber = new AtomicInteger(1); + + private final ThreadGroup threadGroup; + + private final AtomicInteger threadNumber = new AtomicInteger(1); + + public final String namePrefix; + + public NameableThreadFactory(String name){ + SecurityManager s = System.getSecurityManager(); + threadGroup = (s != null) ? s.getThreadGroup() : + Thread.currentThread().getThreadGroup(); + if (null==name || "".equals(name.trim())){ + name = "pool"; + } + namePrefix = name +"-"+ + poolNumber.getAndIncrement() + + "-thread-"; + } + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(threadGroup, r, + namePrefix + threadNumber.getAndIncrement(), + 0); + if (t.isDaemon()) + t.setDaemon(false); + if (t.getPriority() != Thread.NORM_PRIORITY) + t.setPriority(Thread.NORM_PRIORITY); + return t; + } +} diff --git a/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java b/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java index a065021..28b6167 100644 --- a/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java +++ b/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.utils; import cn.hutool.core.lang.Validator; @@ -8,8 +23,8 @@ import org.apache.commons.lang3.StringUtils; import org.opsli.api.msg.ValidationMsg; import org.opsli.api.wrapper.system.dict.DictModel; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; -import org.opsli.common.annotation.validation.ValidationArgsMin; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMin; import org.opsli.common.enums.ValiArgsType; import org.opsli.common.exception.ServiceException; @@ -49,7 +64,7 @@ public final class ValidationUtil { } // 获得 最大长度 注解 - ValidationArgsMax validationArgsMax = field.getAnnotation(ValidationArgsMax.class); + ValidationArgsLenMax validationArgsMax = field.getAnnotation(ValidationArgsLenMax.class); if(validationArgsMax != null){ int maxLength = validationArgsMax.value(); Object fieldValue = ReflectUtil.getFieldValue(obj, field); @@ -57,7 +72,7 @@ public final class ValidationUtil { } // 获得 最小长度 注解 - ValidationArgsMin validationArgsMin = field.getAnnotation(ValidationArgsMin.class); + ValidationArgsLenMin validationArgsMin = field.getAnnotation(ValidationArgsLenMin.class); if(validationArgsMin != null){ int minLength = validationArgsMin.value(); Object fieldValue = ReflectUtil.getFieldValue(obj, field); @@ -284,7 +299,7 @@ public final class ValidationUtil { // 循环验证 try { String value = String.valueOf(fieldValue); - if(value != null){ + if(value != null && !"null".equals(value)){ // 转换为 数据库真实 长度 int strLength = value.getBytes(CHARSET_NAME).length; if(strLength > maxLength){ @@ -317,7 +332,7 @@ public final class ValidationUtil { // 循环验证 try { String value = String.valueOf(fieldValue); - if(value != null){ + if(value != null && !"null".equals(value)){ // 转换为 数据库真实 长度 int strLength = value.getBytes(CHARSET_NAME).length; if(strLength < minLength){ diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictApi.java index caf48aa..c813860 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictApi.java @@ -1,9 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.web.system.dict; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.dict.DictModel; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -58,7 +74,7 @@ public interface DictApi { * @return ResultVo */ @PostMapping("/insert") - ResultVo insert(DictModel model); + ResultVo insert(@RequestBody DictModel model); /** * 数据字典 修改 @@ -66,7 +82,7 @@ public interface DictApi { * @return ResultVo */ @PostMapping("/update") - ResultVo update(DictModel model); + ResultVo update(@RequestBody DictModel model); /** * 数据字典 删除 @@ -109,4 +125,13 @@ public interface DictApi { @GetMapping("/exportImport/template") ResultVo importTemplate(HttpServletResponse response); + + /** + * 根据字典类型编号 查询出所有字典 + * + * @param typeCode 字典类型编号 + * @return + */ + @GetMapping("/getDictListByCode") + ResultVo getDictListByCode(String typeCode); } diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictDetailApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictDetailApi.java index 8021d41..854efa7 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictDetailApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/dict/DictDetailApi.java @@ -1,9 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.web.system.dict; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.dict.DictDetailModel; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -58,7 +74,7 @@ public interface DictDetailApi { * @return ResultVo */ @PostMapping("/insert") - ResultVo insert(DictDetailModel model); + ResultVo insert(@RequestBody DictDetailModel model); /** * 数据字典 修改 @@ -66,7 +82,7 @@ public interface DictDetailApi { * @return ResultVo */ @PostMapping("/update") - ResultVo update(DictDetailModel model); + ResultVo update(@RequestBody DictDetailModel model); /** * 数据字典 删除 diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/logs/LogsApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/logs/LogsApi.java new file mode 100644 index 0000000..e6a80e2 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/logs/LogsApi.java @@ -0,0 +1,85 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.system.logs; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.api.wrapper.system.menu.MenuModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.servlet.http.HttpServletRequest; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 日志 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface LogsApi { + + /** 标题 */ + String TITLE = "日志"; + + /** + * 日志 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(LogsModel model); + + /** + * 日志 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 清空一个月前的日志 + * @return ResultVo + */ + @PostMapping("/emptyByOneMonth") + ResultVo emptyByOneMonth(); + + + /** + * 日志 新增 + * @param model 模型 + * @return ResultVo + */ + ResultVo insert(LogsModel model); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/menu/MenuApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/menu/MenuApi.java index a422901..06a0b48 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/menu/MenuApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/menu/MenuApi.java @@ -1,15 +1,31 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.web.system.menu; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.menu.MenuModel; -import org.opsli.api.wrapper.system.user.UserModel; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** @@ -31,6 +47,37 @@ public interface MenuApi { /** 标题 */ String TITLE = "菜单"; + + /** + * 获得菜单 + * @return ResultVo + */ + @GetMapping("/findMenuTreePage") + ResultVo findMenuTreePage(HttpServletRequest request); + + /** + * 获得当前用户登录菜单 + * @return ResultVo + */ + @PostMapping("/findMenuTree") + ResultVo findMenuTree(); + + + /** + * 根据 获得用户 菜单 - 权限 + * @return ResultVo + */ + @GetMapping("/getMenuAndPermsTree") + ResultVo getMenuAndPermsTree(); + + /** + * 获得集合 + * @return ResultVo + */ + @GetMapping("/findList") + ResultVo> findList(); + + /** * 菜单 查一条 * @param model 模型 @@ -59,7 +106,7 @@ public interface MenuApi { * @return ResultVo */ @PostMapping("/insert") - ResultVo insert(MenuModel model); + ResultVo insert(@RequestBody MenuModel model); /** * 菜单 修改 @@ -67,7 +114,7 @@ public interface MenuApi { * @return ResultVo */ @PostMapping("/update") - ResultVo update(MenuModel model); + ResultVo update(@RequestBody MenuModel model); /** * 菜单 删除 @@ -110,4 +157,13 @@ public interface MenuApi { @GetMapping("/exportImport/template") ResultVo importTemplate(HttpServletResponse response); + + + // ================= 普通 + /** + * 根据菜单编号 获得菜单 + * @param menuCode 菜单编号 + * @return ResultVo + */ + ResultVo getByCode(String menuCode); } diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleApi.java index 4503d69..655b888 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleApi.java @@ -1,9 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.web.system.role; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.role.RoleModel; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -58,7 +74,7 @@ public interface RoleApi { * @return ResultVo */ @PostMapping("/insert") - ResultVo insert(RoleModel model); + ResultVo insert(@RequestBody RoleModel model); /** * 角色 修改 @@ -66,7 +82,7 @@ public interface RoleApi { * @return ResultVo */ @PostMapping("/update") - ResultVo update(RoleModel model); + ResultVo update(@RequestBody RoleModel model); /** * 角色 删除 diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleMenuRefApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleMenuRefApi.java new file mode 100644 index 0000000..2bb4e23 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/role/RoleMenuRefApi.java @@ -0,0 +1,67 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.system.role; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.role.RoleMenuRefModel; +import org.opsli.api.wrapper.system.role.RoleModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 角色菜单 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface RoleMenuRefApi { + + /** 标题 */ + String TITLE = "角色权限"; + + /** + * 获得当前已有权限 + * @param model 角色Id + * @return ResultVo + */ + @GetMapping("/getPerms") + ResultVo getPerms(RoleMenuRefModel model); + + /** + * 设置权限 + * @param model roleId 角色Id + * @param model permsIds 权限Id 数组 + * @return ResultVo + */ + @PostMapping("/setPerms") + ResultVo setPerms(@RequestBody RoleMenuRefModel model); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java new file mode 100644 index 0000000..915c9ff --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/tenant/TenantApi.java @@ -0,0 +1,128 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.system.tenant; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 租户 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface TenantApi { + + /** 标题 */ + String TITLE = "租户"; + + /** + * 租户 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(TenantModel model); + + /** + * 租户 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 租户 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody TenantModel model); + + /** + * 租户 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody TenantModel model); + + /** + * 租户 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 租户 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * 租户 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @GetMapping("/exportExcel") + ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 租户 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @GetMapping("/exportImport") + ResultVo excelImport(MultipartHttpServletRequest request); + + /** + * 租户 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @GetMapping("/exportImport/template") + ResultVo importTemplate(HttpServletResponse response); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java index 3a23a58..b51a4ee 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserApi.java @@ -1,12 +1,31 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.web.system.user; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.role.RoleModel; +import org.opsli.api.wrapper.system.user.UserInfo; import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserPassword; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; @@ -33,6 +52,53 @@ public interface UserApi { /** 标题 */ String TITLE = "用户信息"; + /** + * 当前登陆用户信息 + * @return ResultVo + */ + @GetMapping("/getInfo") + ResultVo getInfo(HttpServletRequest request); + + /** + * 当前登陆用户信息 + * @return ResultVo + */ + @GetMapping("/getInfoById") + ResultVo getInfoById(@RequestParam(name = "userId") String userId); + + /** + * 根据 userId 获得用户角色Id集合 + * @param userId 用户Id + * @return ResultVo + */ + @GetMapping("/getRoleIdsByUserId") + ResultVo> getRoleIdsByUserId(String userId); + + + /** + * 修改密码 + * @return ResultVo + */ + @PostMapping("/updatePassword") + ResultVo updatePassword(@RequestBody UserPassword userPassword); + + /** + * 修改密码 ID + * @return ResultVo + */ + @PostMapping("/updatePasswordById") + ResultVo updatePasswordById(@RequestBody UserPassword userPassword); + + + /** + * 上传头像 + * @param request 文件流 request + * @return ResultVo + */ + @PostMapping("/updateAvatar") + ResultVo updateAvatar(MultipartHttpServletRequest request); + + /** * 用户信息 查一条 * @param model 模型 @@ -61,7 +127,7 @@ public interface UserApi { * @return ResultVo */ @PostMapping("/insert") - ResultVo insert(UserModel model); + ResultVo insert(@RequestBody UserModel model); /** * 用户信息 修改 @@ -69,7 +135,7 @@ public interface UserApi { * @return ResultVo */ @PostMapping("/update") - ResultVo update(UserModel model); + ResultVo update(@RequestBody UserModel model); /** * 用户信息 删除 @@ -104,6 +170,7 @@ public interface UserApi { @GetMapping("/exportImport") ResultVo excelImport(MultipartHttpServletRequest request); + /** * 用户信息 Excel 下载导入模版 * @param response response diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/user/UserRoleRefApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserRoleRefApi.java new file mode 100644 index 0000000..44fb67a --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/system/user/UserRoleRefApi.java @@ -0,0 +1,55 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.system.user; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.role.RoleMenuRefModel; +import org.opsli.api.wrapper.system.user.UserRoleRefModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 用户角色 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface UserRoleRefApi { + + /** 标题 */ + String TITLE = "用户角色"; + + + /** + * 设置角色 + * @param model userId 用户Id + * @param model roleIds 角色Id 数组 + * @return ResultVo + */ + @PostMapping("/setRoles") + ResultVo setRoles(@RequestBody UserRoleRefModel model); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/web/test/TestRestApi.java b/opsli-api/src/main/java/org/opsli/api/web/test/TestRestApi.java new file mode 100644 index 0000000..90ec4f5 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/test/TestRestApi.java @@ -0,0 +1,128 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.test; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.test.TestModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 测试 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface TestRestApi { + + /** 标题 */ + String TITLE = "测试"; + + /** + * 测试 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(TestModel model); + + /** + * 测试 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 测试 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody TestModel model); + + /** + * 测试 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody TestModel model); + + /** + * 测试 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 测试 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * 测试 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @GetMapping("/exportExcel") + ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 测试 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @GetMapping("/exportImport") + ResultVo excelImport(MultipartHttpServletRequest request); + + /** + * 测试 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @GetMapping("/exportImport/template") + ResultVo importTemplate(HttpServletResponse response); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictDetailModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictDetailModel.java index 95d8d6e..f1c7599 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictDetailModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictDetailModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.dict; import com.alibaba.excel.annotation.ExcelIgnore; @@ -7,7 +22,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; import org.opsli.common.enums.ValiArgsType; import org.opsli.plugins.excel.annotation.ExcelInfo; @@ -34,7 +49,7 @@ public class DictDetailModel extends ApiWrapper { @ExcelIgnore // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(120) + @ValidationArgsLenMax(120) private String typeCode; /** 字典名称 */ @@ -43,7 +58,7 @@ public class DictDetailModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE}) - @ValidationArgsMax(120) + @ValidationArgsLenMax(120) private String dictName; /** 字典值 */ @@ -52,16 +67,16 @@ public class DictDetailModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL}) - @ValidationArgsMax(120) + @ValidationArgsLenMax(120) private String dictValue; /** 是否内置数据 0是 1否*/ @ApiModelProperty(value = "是否内置数据 0是 1否") @ExcelProperty(value = "是否内置数据", order = 2) - @ExcelInfo(dictType = "yes_no") + @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL}) - @ValidationArgsMax(1) + @ValidationArgsLenMax(1) private Character izLock; /** 排序 */ @@ -70,7 +85,7 @@ public class DictDetailModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_NUMBER}) - @ValidationArgsMax(10) + @ValidationArgsLenMax(10) private Integer sortNo; /** 备注 */ @@ -78,7 +93,7 @@ public class DictDetailModel extends ApiWrapper { @ExcelProperty(value = "备注", order = 2) @ExcelInfo // 验证器 - @ValidationArgsMax(255) + @ValidationArgsLenMax(255) private String remark; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictModel.java index b454126..d86ab8d 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.dict; import com.alibaba.excel.annotation.ExcelProperty; @@ -6,7 +21,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; import org.opsli.common.enums.ValiArgsType; import org.opsli.plugins.excel.annotation.ExcelInfo; @@ -29,7 +44,7 @@ public class DictModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(120) + @ValidationArgsLenMax(120) private String typeCode; /** 字典类型名称 */ @@ -38,16 +53,16 @@ public class DictModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE}) - @ValidationArgsMax(120) + @ValidationArgsLenMax(120) private String typeName; /** 是否内置数据 0是 1否*/ @ApiModelProperty(value = "是否内置数据 0是 1否") @ExcelProperty(value = "是否内置数据", order = 3) - @ExcelInfo(dictType = "yes_no") + @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgs(ValiArgsType.IS_NOT_NULL) - @ValidationArgsMax(1) + @ValidationArgsLenMax(1) private Character izLock; /** 备注 */ @@ -55,7 +70,7 @@ public class DictModel extends ApiWrapper { @ExcelProperty(value = "备注", order = 4) @ExcelInfo // 验证器 - @ValidationArgsMax(255) + @ValidationArgsLenMax(255) private String remark; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictWrapper.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictWrapper.java index 83b37ac..cc429b7 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictWrapper.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/dict/DictWrapper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.dict; import lombok.Data; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/logs/LogsModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/logs/LogsModel.java new file mode 100644 index 0000000..887539d --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/logs/LogsModel.java @@ -0,0 +1,77 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.logs; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 日志表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class LogsModel extends ApiWrapper { + + /** 日志类型(1:接入日志;2:错误日志) */ + public static final String TYPE_ACCESS = "1"; + public static final String TYPE_EXCEPTION = "2"; + + + /** 日志类型(1:接入日志;2:错误日志) */ + @ApiModelProperty(value = "日志类型") + private String type; + + /** 日志标题 */ + @ApiModelProperty(value = "日志标题") + private String title; + + /** 操作用户的IP地址 */ + @ApiModelProperty(value = "操作用户的IP地址") + private String remoteAddr; + + /** 操作用户代理信息 */ + @ApiModelProperty(value = "操作用户代理信息") + private String userAgent; + + /** 执行时间 */ + @ApiModelProperty(value = "执行时间") + private Long timeout; + + /** 操作的URI */ + @ApiModelProperty(value = "操作的URI") + private String requestUri; + + /** 操作的方式 */ + @ApiModelProperty(value = "操作的方式") + private String method; + + /** 操作提交的数据 */ + @ApiModelProperty(value = "操作提交的数据") + private String params; + + /** 异常信息 */ + @ApiModelProperty(value = "异常信息") + private String exception; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/menu/MenuModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/menu/MenuModel.java index 1ff466c..df38588 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/menu/MenuModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/menu/MenuModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.menu; import com.alibaba.excel.annotation.ExcelProperty; @@ -6,7 +21,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; import org.opsli.common.enums.ValiArgsType; import org.opsli.plugins.excel.annotation.ExcelInfo; @@ -26,26 +41,25 @@ public class MenuModel extends ApiWrapper { @ExcelProperty(value = "父级主键", order = 1) @ExcelInfo // 验证器 - @ValidationArgs(ValiArgsType.IS_NOT_NULL) - @ValidationArgsMax(20) + @ValidationArgsLenMax(20) private String parentId; /** 菜单编号 */ - @ApiModelProperty(value = "菜单编号") - @ExcelProperty(value = "菜单编号", order = 2) + @ApiModelProperty(value = "编号") + @ExcelProperty(value = "编号", order = 2) @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String menuCode; /** 菜单名称 */ - @ApiModelProperty(value = "菜单名称") - @ExcelProperty(value = "菜单名称", order = 3) + @ApiModelProperty(value = "名称") + @ExcelProperty(value = "名称", order = 3) @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String menuName; /** 图标 */ @@ -53,16 +67,16 @@ public class MenuModel extends ApiWrapper { @ExcelProperty(value = "图标", order = 4) @ExcelInfo // 验证器 - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String icon; - /** 项目类型:1-菜单2-按钮3-链接4-表单 */ - @ApiModelProperty(value = "项目类型:1-菜单2-按钮3-链接4-表单") + /** 项目类型: 1-菜单 2-按钮 3-链接 */ + @ApiModelProperty(value = "项目类型") @ExcelProperty(value = "项目类型", order = 5) - @ExcelInfo(dictType = "menuType") + @ExcelInfo(dictType = "menu_type") // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL}) - @ValidationArgsMax(20) + @ValidationArgsLenMax(20) private String type; /** url地址 */ @@ -70,8 +84,39 @@ public class MenuModel extends ApiWrapper { @ExcelProperty(value = "url地址", order = 6) @ExcelInfo // 验证器 - @ValidationArgsMax(200) + @ValidationArgsLenMax(200) private String url; + /** 组件 - vue 对应组件 */ + @ApiModelProperty(value = "组件") + @ExcelProperty(value = "组件", order = 7) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(200) + private String component; + + /** 重定向 */ + @ApiModelProperty(value = "重定向") + @ExcelProperty(value = "重定向", order = 8) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(200) + private String redirect; + + /** 排序 */ + @ApiModelProperty(value = "排序") + @ExcelProperty(value = "排序", order = 8) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + private Integer sortNo; + + /** 是否隐藏 0为否 1为是 */ + @ApiModelProperty(value = "是否隐藏") + @ExcelProperty(value = "是否隐藏", order = 8) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + private String hidden; } diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleMenuRefModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleMenuRefModel.java new file mode 100644 index 0000000..a17e8e2 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleMenuRefModel.java @@ -0,0 +1,52 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.role; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 角色表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class RoleMenuRefModel implements Serializable { + + /** 角色ID */ + @ApiModelProperty(value = "角色ID") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(50) + private String roleId; + + /** 权限数组 */ + @ApiModelProperty(value = "权限数组") + // 验证器 + private String[] permsIds; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleModel.java index 05e30b2..0832b0d 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/role/RoleModel.java @@ -1,12 +1,28 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.role; +import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; import org.opsli.common.enums.ValiArgsType; import org.opsli.plugins.excel.annotation.ExcelInfo; @@ -29,7 +45,7 @@ public class RoleModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String roleCode; /** 角色名称 */ @@ -37,8 +53,8 @@ public class RoleModel extends ApiWrapper { @ExcelProperty(value = "角色编码", order = 2) @ExcelInfo // 验证器 - @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(50) + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(50) private String roleName; /** 是否内置数据 0是 1否*/ @@ -46,8 +62,8 @@ public class RoleModel extends ApiWrapper { @ExcelProperty(value = "是否内置数据", order = 3) @ExcelInfo(dictType = "yes_no") // 验证器 - @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(1) + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(1) private Character izLock; /** 备注 */ @@ -55,7 +71,15 @@ public class RoleModel extends ApiWrapper { @ExcelProperty(value = "备注", order = 4) @ExcelInfo // 验证器 - @ValidationArgsMax(255) + @ValidationArgsLenMax(255) private String remark; + + /** 多租户字段 */ + @ApiModelProperty(value = "多租户ID") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(20) + private String tenantId; + } diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/tenant/TenantModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/tenant/TenantModel.java new file mode 100644 index 0000000..19f87e3 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/tenant/TenantModel.java @@ -0,0 +1,67 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.tenant; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 租户表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class TenantModel extends ApiWrapper { + + + /** 租户名称 */ + @ApiModelProperty(value = "租户名称") + @ExcelProperty(value = "租户名称", order = 1) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(50) + private String tenantName; + + /** 是否启用 0是 1否*/ + @ApiModelProperty(value = "是否启用") + @ExcelProperty(value = "是否启用", order = 2) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(1) + private Character izUsable; + + /** 备注 */ + @ApiModelProperty(value = "备注") + @ExcelProperty(value = "备注", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String remark; + + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java new file mode 100644 index 0000000..d18e253 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserInfo.java @@ -0,0 +1,109 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.user; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户信息表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class UserInfo extends ApiWrapper { + + + /** 登录账户 */ + @ApiModelProperty(value = "登录账户") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(32) + private String username; + + /** 真实姓名 */ + @ApiModelProperty(value = "真实姓名") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(50) + private String realName; + + /** 手机 */ + @ApiModelProperty(value = "手机") + // 验证器 + @ValidationArgs({ValiArgsType.IS_MOBILE}) + private String mobile; + + /** 邮箱 */ + @ApiModelProperty(value = "邮箱") + @ExcelProperty(value = "邮箱", order = 3) + // 验证器 + @ValidationArgs({ValiArgsType.IS_EMAIL}) + private String email; + + /** 工号 */ + @ApiModelProperty(value = "工号") + @ExcelProperty(value = "工号", order = 4) + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(32) + private String no; + + /** 头像 */ + @ApiModelProperty(value = "头像") + // 验证器 + @ValidationArgsLenMax(255) + private String avatar; + + /** 备注 */ + @ApiModelProperty(value = "备注") + // 验证器 + @ValidationArgsLenMax(255) + private String remark; + + /** 签名 */ + @ApiModelProperty(value = "签名") + // 验证器 + @ValidationArgsLenMax(255) + private String sign; + + /** 角色列表 */ + @ApiModelProperty(value = "角色列表") + private List roles; + + /** 权限列表 */ + @ApiModelProperty(value = "权限列表") + private List perms; + + + /** 是否是超级管理员 */ + @ApiModelProperty(value = "是否是超级管理员") + private boolean izSuperAdmin; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java index eab9147..710f5bc 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.system.user; import com.alibaba.excel.annotation.ExcelIgnore; @@ -7,7 +22,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.common.annotation.validation.ValidationArgs; -import org.opsli.common.annotation.validation.ValidationArgsMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; import org.opsli.common.enums.ValiArgsType; import org.opsli.plugins.excel.annotation.ExcelInfo; @@ -28,21 +43,21 @@ public class UserModel extends ApiWrapper { @ExcelIgnore // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(32) + @ValidationArgsLenMax(32) private String username; /** 登录密码 */ @ApiModelProperty(value = "登录密码") @ExcelIgnore // 验证器 - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String password; /** 盐值,密码秘钥 */ @ApiModelProperty(value = "盐值,密码秘钥") @ExcelIgnore // 验证器 - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String secretkey; /** 是否锁定 */ @@ -50,7 +65,7 @@ public class UserModel extends ApiWrapper { @ExcelIgnore // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL}) - @ValidationArgsMax(1) + @ValidationArgsLenMax(1) private Character locked; /** 真实姓名 */ @@ -59,7 +74,7 @@ public class UserModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL_WITH_CHINESE}) - @ValidationArgsMax(50) + @ValidationArgsLenMax(50) private String realName; /** 手机 */ @@ -76,6 +91,7 @@ public class UserModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_EMAIL}) + @ValidationArgsLenMax(100) private String email; /** 工号 */ @@ -84,14 +100,14 @@ public class UserModel extends ApiWrapper { @ExcelInfo // 验证器 @ValidationArgs({ValiArgsType.IS_GENERAL}) - @ValidationArgsMax(32) + @ValidationArgsLenMax(32) private String no; /** 头像 */ @ApiModelProperty(value = "头像") @ExcelIgnore // 验证器 - @ValidationArgsMax(255) + @ValidationArgsLenMax(255) private String avatar; /** 最后登陆IP */ @@ -106,15 +122,23 @@ public class UserModel extends ApiWrapper { @ExcelProperty(value = "备注", order = 5) @ExcelInfo // 验证器 - @ValidationArgsMax(255) + @ValidationArgsLenMax(255) private String remark; + /** 签名 */ + @ApiModelProperty(value = "签名") + @ExcelProperty(value = "签名", order = 5) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String sign; + /** 多租户字段 */ @ApiModelProperty(value = "多租户ID") @ExcelIgnore // 验证器 - @ValidationArgsMax(20) + @ValidationArgsLenMax(20) private String tenantId; diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserPassword.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserPassword.java new file mode 100644 index 0000000..b533e0d --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserPassword.java @@ -0,0 +1,68 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.user; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户 修改密码 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class UserPassword implements Serializable { + + private static final long serialVersionUID = 1L; + + /** User Id */ + @ApiModelProperty(value = "用户Id") + private String userId; + + /** 旧密码 */ + @ApiModelProperty(value = "旧密码") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(50) + private String oldPassword; + + /** 新密码 */ + @ApiModelProperty(value = "新密码") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(50) + private String newPassword; + + /** 盐值,密码秘钥 */ + @ApiModelProperty(value = "盐值,密码秘钥") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(50) + private String salt; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserRoleRefModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserRoleRefModel.java new file mode 100644 index 0000000..87a7003 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserRoleRefModel.java @@ -0,0 +1,52 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.system.user; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 角色表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ExcelIgnoreUnannotated +public class UserRoleRefModel implements Serializable { + + /** 用户ID */ + @ApiModelProperty(value = "用户ID") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(50) + private String userId; + + /** 角色数组 */ + @ApiModelProperty(value = "权限数组") + // 验证器 + private String[] roleIds; + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/test/TestModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/test/TestModel.java index fd0abd1..f26306d 100644 --- a/opsli-api/src/main/java/org/opsli/api/wrapper/test/TestModel.java +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/test/TestModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.api.wrapper.test; import com.alibaba.excel.annotation.ExcelProperty; @@ -28,7 +43,7 @@ public class TestModel extends ApiWrapper { @ApiModelProperty(value = "分类") @ExcelProperty(value = "分类", order = 2) - @ExcelInfo(dictType = "testType") + @ExcelInfo(dictType = "test_type") private String type; @ApiModelProperty(value = "备注") diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/ApiRestController.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/ApiRestController.java index da06a78..143d5de 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/ApiRestController.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/ApiRestController.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.annotation; import org.springframework.core.annotation.AliasFor; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/EnableLog.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/EnableLog.java new file mode 100644 index 0000000..6fcf789 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/EnableLog.java @@ -0,0 +1,36 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 自定义操作日志注解 + * @author parker + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface EnableLog { + + /** 标题 */ + String title() default ""; + +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/EnableHotData.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/EnableHotData.java index aea5b06..ca13900 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/EnableHotData.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/EnableHotData.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.annotation.hotdata; import java.lang.annotation.*; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataDel.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataDel.java index b6141b0..48d6e91 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataDel.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataDel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.annotation.hotdata; import org.opsli.common.constants.CacheConstants; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataPut.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataPut.java index 940e59d..00caf82 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataPut.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/hotdata/HotDataPut.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.annotation.hotdata; import org.opsli.common.constants.CacheConstants; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgs.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgs.java index 43b5483..a717c46 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgs.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgs.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.annotation.validation; import org.opsli.common.enums.ValiArgsType; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMax.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMax.java new file mode 100644 index 0000000..dce3a3c --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMax.java @@ -0,0 +1,38 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.annotation.validation; + + +import java.lang.annotation.*; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.common.annotation + * @Author: Parker + * @CreateTime: 2020-09-22 17:07 + * @Description: 字段验证器 - 字段最大长度 + * + * 对应 数据库 真实长度数 + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Documented +public @interface ValidationArgsLenMax { + + int value(); + +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMin.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMin.java new file mode 100644 index 0000000..a5fa8e8 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsLenMin.java @@ -0,0 +1,38 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.annotation.validation; + + +import java.lang.annotation.*; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.common.annotation + * @Author: Parker + * @CreateTime: 2020-09-22 17:07 + * @Description: 字段验证器 - 字段最大长度 + * + * 对应 数据库 真实长度数 + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Documented +public @interface ValidationArgsLenMin { + + int value(); + +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMax.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMax.java deleted file mode 100644 index 742228c..0000000 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMax.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.opsli.common.annotation.validation; - - -import java.lang.annotation.*; - -/** - * @BelongsProject: opsli-boot - * @BelongsPackage: org.opsli.common.annotation - * @Author: Parker - * @CreateTime: 2020-09-22 17:07 - * @Description: 字段验证器 - 字段最大长度 - * - * 对应 数据库 真实长度数 - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface ValidationArgsMax { - - int value(); - -} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMin.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMin.java deleted file mode 100644 index 8191752..0000000 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/annotation/validation/ValidationArgsMin.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.opsli.common.annotation.validation; - - -import java.lang.annotation.*; - -/** - * @BelongsProject: opsli-boot - * @BelongsPackage: org.opsli.common.annotation - * @Author: Parker - * @CreateTime: 2020-09-22 17:07 - * @Description: 字段验证器 - 字段最大长度 - * - * 对应 数据库 真实长度数 - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface ValidationArgsMin { - - int value(); - -} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultDto.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultDto.java index 444cfd8..6973bf4 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultDto.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultDto.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.api; import com.fasterxml.jackson.annotation.JsonProperty; @@ -82,7 +97,7 @@ public class ResultDto implements Serializable { public void setSuccess(boolean success) { resultMap.put("success", success); } - + // --------------------------------- @@ -104,4 +119,4 @@ public class ResultDto implements Serializable { return data; } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultVoMap.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultVoMap.java index 9fea25b..f543eca 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultVoMap.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/ResultVoMap.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.api; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -13,11 +28,11 @@ import java.util.Map; * * @date 2020年5月15日10:40:54 * @author Parker - * + * */ public class ResultVoMap extends HashMap implements Serializable { - - + + public ResultVoMap(){ this.put("success", true); this.put("code", HttpStatus.OK.value()); @@ -33,7 +48,7 @@ public class ResultVoMap extends HashMap implements Serializable public String getMsg() { return (String)this.get("msg"); } - + public void setMsg(String msg) {//向json中添加属性,在js中访问,请调用data.msg this.put("msg", msg); } @@ -49,7 +64,7 @@ public class ResultVoMap extends HashMap implements Serializable public boolean isSuccess() { return (boolean)this.get("success"); } - + public void setSuccess(boolean success) { this.put("success", success); } @@ -81,17 +96,17 @@ public class ResultVoMap extends HashMap implements Serializable public static ResultVoMap success() { return new ResultVoMap(); } - - + + @Override public ResultVoMap put(String key, Object value) { super.put(key, value); return this; } - + public ResultVoMap putMap(Map m) { super.putAll(m); return this; } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java index 1c77c73..f2dbf62 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.api; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/base/msg/BaseMsg.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/base/msg/BaseMsg.java index ff9d887..a6f9fb9 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/base/msg/BaseMsg.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/base/msg/BaseMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.base.msg; /** diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/CacheConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/CacheConstants.java index 2017605..4b12f15 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/CacheConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/CacheConstants.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; /** diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/DictConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/DictConstants.java index fe7e57e..619df17 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/DictConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/DictConstants.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; /** @@ -9,10 +24,13 @@ package org.opsli.common.constants; */ public interface DictConstants { - /** 缓存前缀 */ + /** 缓存前缀 NAME */ String CACHE_PREFIX_NAME = "dict:name:"; - /** 缓存前缀 */ + /** 缓存前缀 VALUE*/ String CACHE_PREFIX_VALUE = "dict:value:"; + /** 缓存前缀 LIST*/ + String CACHE_PREFIX_LIST = "dict:list:"; + } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java index 32eb5d9..686f1ba 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java @@ -1,6 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; -import cn.hutool.setting.dialect.Props; + +import org.opsli.common.utils.Props; /** * @BelongsProject: opsli-boot @@ -11,7 +27,7 @@ import cn.hutool.setting.dialect.Props; */ public final class MyBatisConstants { - private static final Props prop = Props.getProp("application.yaml"); + private static final Props prop = new Props("application.yaml"); /** 逻辑删除值 */ public static final char LOGIC_DELETE_VALUE = diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/OrderConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/OrderConstants.java index 2369d2c..d31f295 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/OrderConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/OrderConstants.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; /** @@ -7,6 +22,9 @@ package org.opsli.common.constants; */ public interface OrderConstants { + /** Util 加载顺序 */ + int UTIL_ORDER = 140; + /** token */ int TOKEN_AOP_SORT = 150; @@ -19,6 +37,9 @@ public interface OrderConstants { /** SQL 切面执行顺序 */ int SQL_ORDER = 190; + /** 参数非法验证顺序 */ + int LOG_ORDER = 200; + /** Controller异常拦截顺序 */ int EXCEPTION_HANDLER_ORDER = 260; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/SignConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/SignConstants.java index 3289143..7b4a3bd 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/SignConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/SignConstants.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; /** diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TokenConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TokenConstants.java index b49999c..eaeb7de 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TokenConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/TokenConstants.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.constants; /** @@ -10,6 +25,6 @@ package org.opsli.common.constants; public interface TokenConstants { /** ACCESS_TOKEN */ - String ACCESS_TOKEN = "token"; + String ACCESS_TOKEN = "X-Token"; } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java new file mode 100644 index 0000000..978caee --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/DictType.java @@ -0,0 +1,27 @@ +package org.opsli.common.enums; + + +/** + * @Author: 周鹏程 + * @CreateTime: 2020-09-17 23:40 + * @Description: 字典 + */ +public enum DictType { + + /** no_yes */ + NO_YES_NO("0"), + NO_YES_YES("1"), + + ; + + private String code; + + DictType(String code){ + this.code = code; + } + + + public String getCode(){ + return this.code; + } +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ExcelOperate.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ExcelOperate.java index 6217068..d399042 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ExcelOperate.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ExcelOperate.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.enums; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/SystemInfo.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/SystemInfo.java index 05d81bb..877e479 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/SystemInfo.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/SystemInfo.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.enums; import java.util.UUID; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ValiArgsType.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ValiArgsType.java index 623a01f..a085e29 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ValiArgsType.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/ValiArgsType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.enums; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/EmptyException.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/EmptyException.java index 2ad34b9..578c81a 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/EmptyException.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/EmptyException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.exception; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/JwtException.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/JwtException.java index d2c7efb..d998aa2 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/JwtException.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/JwtException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/ServiceException.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/ServiceException.java index 99722bf..d82ceaf 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/ServiceException.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/ServiceException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/TokenException.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/TokenException.java index 717d2c4..61b53df 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/TokenException.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/TokenException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/WafException.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/WafException.java new file mode 100644 index 0000000..3e89c29 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/exception/WafException.java @@ -0,0 +1,35 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.exception; + +import org.opsli.common.base.msg.BaseMsg; + +/** + * Java 防火墙 异常类 + * + * @author Parker + * @date 2020-10-09 + */ +public class WafException extends ServiceException { + + public WafException(Integer code, String errorMessage) { + super(code, errorMessage); + } + + public WafException(BaseMsg msg) { + super(msg); + } +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/msg/CommonMsg.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/msg/CommonMsg.java index a9b3e10..d1a13fc 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/msg/CommonMsg.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/msg/CommonMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java index c311a0a..fc70e44 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.utils; /** diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java new file mode 100644 index 0000000..55a5762 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java @@ -0,0 +1,147 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.utils; + +import javax.servlet.http.HttpServletRequest; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.common.utils + * @Author: Parker + * @CreateTime: 2020-10-08 10:24 + * @Description: IP 工具类 + */ +public final class IPUtil { + + /** + * 获取客户端ip地址(可以穿透代理) + * + * @param request + * @return + */ + public static String getRemoteAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } + private static final String[] HEADERS_TO_TRY = { + "X-Forwarded-For", + "Proxy-Client-IP", + "WL-Proxy-Client-IP", + "HTTP_X_FORWARDED_FOR", + "HTTP_X_FORWARDED", + "HTTP_X_CLUSTER_CLIENT_IP", + "HTTP_CLIENT_IP", + "HTTP_FORWARDED_FOR", + "HTTP_FORWARDED", + "HTTP_VIA", + "REMOTE_ADDR", + "X-Real-IP"}; + + /*** + * 获取客户端ip地址(可以穿透代理) + * @param request + * @return + */ + public static String getClientIpAddress(HttpServletRequest request) { + for (String header : HEADERS_TO_TRY) { + String ip = request.getHeader(header); + if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { + return ip; + } + } + return request.getRemoteAddr(); + } + /*** + * 获取客户端ip地址(可以穿透代理) + * @param request + * @return + */ + public static String getClientIpAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_FORWARDED"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_VIA"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("REMOTE_ADDR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } + public static String getIpAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Real-IP"); + if (null != ip && !"".equals(ip.trim()) + && !"unknown".equalsIgnoreCase(ip)) { + return ip; + } + ip = request.getHeader("X-Forwarded-For"); + if (null != ip && !"".equals(ip.trim()) + && !"unknown".equalsIgnoreCase(ip)) { + // get first ip from proxy ip + int index = ip.indexOf(','); + if (index != -1) { + return ip.substring(0, index); + } else { + return ip; + } + } + return request.getRemoteAddr(); + } + + + // =============== + private IPUtil(){} +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/PackageUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/PackageUtil.java index efaaada..fccddd7 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/PackageUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/PackageUtil.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.utils; import java.io.File; @@ -375,4 +390,4 @@ public final class PackageUtil { return src; } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java new file mode 100644 index 0000000..a29b4c1 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java @@ -0,0 +1,361 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.common.utils; + +import cn.hutool.core.convert.Convert; +import lombok.extern.slf4j.Slf4j; +import org.yaml.snakeyaml.Yaml; + +import java.io.InputStream; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 读取resources下的yaml配置类 + * + * 使用的maven包 + * + * org.yaml + * snakeyaml + * 1.25 + * + * map->bean使用此包 + * + * commons-beanutils + * commons-beanutils-core + * 1.8.3 + * + * + *使用方法 + *eg: + * opsli: + * config: + * key: value + * list: + * - 张三 + * - 李四 + * map: + * - name: 张三map + * age: 12 + * - name: 李四map + * age: 121 + * + *支持获取指定层级之后的数据,如"opsli.config" : new ConfigBean().prefix("opsli.config").getObj() + * + *支持获取list中指定数据,如"opsli.config.list.1" : new ConfigBean().prefix("opsli.config.list.1").getObj() + * + *支持获取list中指定数据之后的数据,如"opsli.config.map.1.name" :new ConfigBean().prefix("opsli.config.list.1").getString() + * + * + * 针对 hutool 工具类 Props不是很有好, 重新写了自定义Yaml工具类 + * @author Parker + */ +@Slf4j +public class Props { + + /** 缓存 Prop 防止重复开启IO 注: 多线程安全 */ + private static final Map> CACHE_MAP = new ConcurrentHashMap<>(); + + /** 文件名 */ + private final String fileName; + + /** + * 获取的对象 + */ + private Map temp; + + public Props(String fileName){ + this.fileName = fileName; + this.load(); + } + + /** + * 加载指定的文件 + */ + private void load() { + + if(CACHE_MAP.get(this.fileName) != null){ + temp = CACHE_MAP.get(this.fileName); + return; + } + + try (InputStream inputStream = Props.class.getResourceAsStream("/" + this.fileName)) { + Yaml yaml = new Yaml(); + temp = yaml.load(inputStream); + + // 初始化保护 + if(temp == null){ + temp = new LinkedHashMap<>(); + } + + CACHE_MAP.put(this.fileName, temp); + + } catch (Exception e) { + log.error("load config file {} error", this.fileName, e); + } + } + + + /** + * 获得 Obj对象 + * @return + */ + public Object getObj(String key){ + return this.getObj(key, null); + } + + /** + * 获得 Obj对象 + * @return + */ + public Object getObj(String key, Object def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + + /** + * 获得 字符串类型对象 + * @return + */ + public String getStr(String key){ + return this.getStr(key, null); + } + + /** + * 获得 字符串类型对象 + * @return + */ + public String getStr(String key, String def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + /** + * 获得 Int 类型对象 + * @return + */ + public Integer getInt(String key){ + return this.getInt(key, null); + } + + /** + * 获得 Int 类型对象 + * @return + */ + public Integer getInt(String key, Integer def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + /** + * 获得 Long 类型对象 + * @return + */ + public Long getLong(String key){ + return this.getLong(key, null); + } + + /** + * 获得 Long 类型对象 + * @return + */ + public Long getLong(String key, Long def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + + /** + * 获得 Double 类型对象 + * @return + */ + public Double getDouble(String key){ + return this.getDouble(key, null); + } + + /** + * 获得 Double 类型对象 + * @return + */ + public Double getDouble(String key, Double def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + + + /** + * 获得 Float 类型对象 + * @return + */ + public Float getFloat(String key){ + return this.getFloat(key, null); + } + + /** + * 获得 Float 类型对象 + * @return + */ + public Float getFloat(String key, Float def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + + /** + * 获得 Char 类型对象 + * @return + */ + public Character getChar(String key){ + return this.getChar(key, null); + } + + /** + * 获得 Char 类型对象 + * @return + */ + public Character getChar(String key, Character def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + /** + * 获得 布尔类型对象 + * @return + */ + public Boolean getBool(String key){ + return this.getBool(key, null); + } + + /** + * 获得 布尔类型对象 + * @return + */ + public Boolean getBool(String key, Boolean def){ + if(key == null || "".equals(key) ){ + return def; + } + // key 集合 + String[] keys = key.split("\\."); + + // 获得对象 + Object obj = this.getObject(keys); + + if(obj != null){ + def = Convert.convert(def.getClass(), obj); + } + return def; + } + + + /** + * 获得对象 + * @param keys + * @return + */ + private Object getObject(String[] keys){ + // 循环查找 + Object obj = null; + for (String k : keys) { + if(obj == null){ + obj = temp.get(k); + } else if(obj instanceof LinkedHashMap){ + obj = ((LinkedHashMap) obj).get(k); + } + } + return obj; + } + +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java index f3c7e79..b740dd0 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/WrapperUtil.java @@ -1,13 +1,30 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.common.utils; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Map; +import java.util.Set; /** * @BelongsProject: opsli-boot @@ -77,6 +94,33 @@ public final class WrapperUtil { return toInstanceList; } + /** + * 转化集合对象 + * @param froms + * @param toClass + * @param + * @return + */ + public static Set transformInstance(Set froms, Class toClass){ + Set toInstanceList = Sets.newHashSetWithExpectedSize(froms.size()); + try { + for (Object from : froms) { + Object toObj = ReflectUtil.newInstance(toClass); + Map stringBeanMap = BeanUtil.beanToMap(from); + if(stringBeanMap != null){ + Object toInstance = BeanUtil.fillBeanWithMapIgnoreCase(stringBeanMap, toObj, true); + if(toInstance != null){ + toInstanceList.add((M) toInstance); + } + } + } + + }catch (Exception e){ + log.error(e.getMessage(),e); + } + return toInstanceList; + } + /** * 克隆并且转化对象 * @param from @@ -102,4 +146,16 @@ public final class WrapperUtil { return transformInstance(ts,toClass); } + /** + * 克隆并且转化集合对象 + * @param froms + * @param toClass + * @param + * @return + */ + public static Set cloneTransformInstance(Set froms, Class toClass){ + Set ts = ObjectUtil.cloneByStream(froms); + return transformInstance(ts,toClass); + } + } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java index b66313a..10a6f9a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.aspect; import com.google.common.collect.Lists; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/SQLDataAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/SQLDataAop.java index 0db4f7d..c232d6d 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/SQLDataAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/SQLDataAop.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.aspect; import lombok.extern.slf4j.Slf4j; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/TokenAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/TokenAop.java index 3ac415e..9db3e5c 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/TokenAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/TokenAop.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.aspect; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.date.TimeInterval; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.aspectj.lang.ProceedingJoinPoint; @@ -8,6 +25,7 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.opsli.common.api.TokenThreadLocal; import org.opsli.common.exception.ServiceException; +import org.opsli.core.utils.LogUtil; import org.opsli.core.utils.UserTokenUtil; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -47,11 +65,13 @@ public class TokenAop { try { RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; - HttpServletRequest request = sra.getRequest(); - String requestToken = UserTokenUtil.getRequestToken(request); - if(StringUtils.isNotEmpty(requestToken)){ - // 放入当前线程缓存中 - TokenThreadLocal.put(requestToken); + if(sra != null) { + HttpServletRequest request = sra.getRequest(); + String requestToken = UserTokenUtil.getRequestToken(request); + if(StringUtils.isNotEmpty(requestToken)){ + // 放入当前线程缓存中 + TokenThreadLocal.put(requestToken); + } } }catch (ServiceException e){ throw e; @@ -59,13 +79,23 @@ public class TokenAop { log.error(e.getMessage(),e); } + // 计时器 + TimeInterval timer = DateUtil.timer(); + // 执行 + Exception exception = null; // 防止线程抛异常 线程变量不回收 导致oom - Object returnValue = null; + Object returnValue; try { // 执行正常操作 - Object[] args= point.getArgs(); - returnValue = point.proceed(args); + returnValue = point.proceed(); + }catch (Exception e){ + exception = e; + throw e; } finally { + // 花费毫秒数 + long timerCount = timer.interval(); + //保存日志 + LogUtil.saveLog(point, exception, timerCount); // 线程销毁时 删除 token TokenThreadLocal.remove(); } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/UserCachingOperationNameGenerator.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/UserCachingOperationNameGenerator.java index a0eef8a..6f95321 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/UserCachingOperationNameGenerator.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/UserCachingOperationNameGenerator.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.aspect; import com.google.common.collect.Maps; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java index ef774e1..01614db 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.aspect; import lombok.extern.slf4j.Slf4j; @@ -45,6 +60,7 @@ public class ValitaionArgsAop { try { RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; + if(sra == null) return; HttpServletRequest request = sra.getRequest(); String method = request.getMethod(); @@ -53,7 +69,11 @@ public class ValitaionArgsAop { for (Object arg : args) { // 参数校验 if(arg instanceof ApiWrapper){ - ValidationUtil.verify(arg); + ApiWrapper apiWrapper = (ApiWrapper) arg; + // 如果是内部调用 则不判断参数非法情况 + if(apiWrapper.getIzApi() != null && !apiWrapper.getIzApi()){ + ValidationUtil.verify(arg); + } } } } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java index 01c2da8..affaa1a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.concroller; @@ -13,6 +28,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.result.ResultVo; import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.hotdata.EnableHotData; import org.opsli.common.exception.ServiceException; import org.opsli.common.msg.CommonMsg; @@ -22,10 +38,12 @@ import org.opsli.core.base.service.interfaces.CrudServiceInterface; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.msg.CoreMsg; import org.opsli.core.utils.ExcelUtil; +import org.opsli.core.utils.UserUtil; import org.opsli.plugins.excel.exception.ExcelPluginException; import org.opsli.plugins.redis.RedisLockPlugins; import org.opsli.plugins.redis.lock.RedisLock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -52,6 +70,9 @@ import java.util.List; @RestController public abstract class BaseRestController >{ + @Value("${opsli.enable-demo}") + private boolean enableDemo; + /** 开启热点数据状态 */ protected boolean hotDataFlag = false; @@ -243,6 +264,17 @@ public abstract class BaseRestController + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.entity; import lombok.Data; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/base/BaseService.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/base/BaseService.java index 7bae81a..06873ac 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/base/BaseService.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/base/BaseService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.service.base; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java index e0dee77..69ad33b 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.service.impl; import cn.hutool.core.convert.Convert; @@ -75,6 +90,15 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Transactional(readOnly = false) public E insert(E model) { if(model == null) return null; + + // 默认清空 创建人和修改人 + if(model.getIzManual() != null && !model.getIzManual()){ + model.setCreateBy(null); + model.setCreateTime(null); + model.setUpdateBy(null); + model.setUpdateTime(null); + } + T entity = transformM2T(model); boolean ret = super.save(entity); if(ret){ @@ -87,6 +111,18 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Transactional(readOnly = false) public boolean insertBatch(List models) { if(models == null || models.size() == 0) return false; + + for (E model : models) { + // 默认清空 创建人和修改人 + if(model.getIzManual() != null && !model.getIzManual()){ + model.setCreateBy(null); + model.setCreateTime(null); + model.setUpdateBy(null); + model.setUpdateTime(null); + } + } + + List entitys = transformMs2Ts(models); return super.saveBatch(entitys); } @@ -95,6 +131,13 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Transactional(readOnly = false) public E update(E model) { if(model == null) return null; + + // 默认清空 创建人和修改人 + if(model.getIzManual() != null && !model.getIzManual()){ + model.setUpdateBy(null); + model.setUpdateTime(null); + } + T entity = transformM2T(model); boolean ret = super.updateById(entity); if(ret){ @@ -157,9 +200,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt page.pageHelperBegin(); try{ List list = this.findList(page.getQueryWrapper()); - List es = WrapperUtil.transformInstance(list, modelClazz); - PageInfo pageInfo = new PageInfo<>(es); - page.instance(pageInfo); + PageInfo pageInfo = new PageInfo<>(list); + List es = transformTs2Ms(pageInfo.getList()); + page.instance(pageInfo, es); } finally { page.pageHelperEnd(); } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/BaseServiceInterface.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/BaseServiceInterface.java index e208f9f..71e188a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/BaseServiceInterface.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/BaseServiceInterface.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.service.interfaces; import com.baomidou.mybatisplus.extension.service.IService; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/CrudServiceInterface.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/CrudServiceInterface.java index 888d9a8..ce23bb2 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/CrudServiceInterface.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/interfaces/CrudServiceInterface.java @@ -1,8 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.base.service.interfaces; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.core.base.entity.BaseEntity; import org.opsli.core.persistence.Page; import java.util.Collection; @@ -21,7 +38,7 @@ import java.util.List; * @param * @param */ -public interface CrudServiceInterface extends BaseServiceInterface { +public interface CrudServiceInterface extends BaseServiceInterface { /** diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/local/CacheUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/local/CacheUtil.java index b153212..6cab506 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/local/CacheUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/local/CacheUtil.java @@ -1,25 +1,48 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.local; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.file.FileReader; import cn.hutool.core.util.XmlUtil; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.opsli.common.constants.CacheConstants; import org.opsli.core.aspect.CacheDataAop; import org.opsli.plugins.cache.EhCachePlugin; import org.opsli.plugins.redis.RedisPlugin; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.core.annotation.Order; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.io.BufferedInputStream; +import java.io.IOException; import java.util.List; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; /** * @BelongsProject: opsli-boot @@ -37,23 +60,27 @@ import java.util.List; * */ @Slf4j +@Order(UTIL_ORDER) @Component +@AutoConfigureAfter({RedisPlugin.class , EhCachePlugin.class}) public class CacheUtil { - private static final String JSON_KEY = "data"; + public static final String JSON_KEY = "data"; /** 空状态 key 前缀 */ private static final String NIL_FLAG_PREFIX = "opsli:nil:"; /** 热点数据缓存时间 秒 */ - private static int ttlHotData; + private static int ttlHotData = 60000; /** Redis插件 */ private static RedisPlugin redisPlugin; /** EhCache插件 */ private static EhCachePlugin ehCachePlugin; static { - // 读取配置信息 - CacheUtil.readPropertyXML(); + try { + // 读取配置信息 + CacheUtil.readPropertyXML(); + }catch (Exception ignored){} } /** @@ -842,7 +869,7 @@ public class CacheUtil { jsonObject.put(JSON_KEY, value); // 存入EhCache - ehCachePlugin.put(CacheConstants.HOT_DATA,key, jsonObject); + ehCachePlugin.put(CacheConstants.HOT_DATA, key, jsonObject); if(timeFlag){ @@ -1057,8 +1084,10 @@ public class CacheUtil { /** * 读配置文件 */ - private static void readPropertyXML(){ - Document document = XmlUtil.readXML("config/ehcache-opsli.xml"); + private static void readPropertyXML() throws IOException { + // 有坑 读 xml + ClassPathResource resource = new ClassPathResource("config/ehcache-opsli.xml"); + Document document = XmlUtil.readXML(resource.getInputStream()); NodeList nodeList = document.getElementsByTagName("cache"); if(nodeList != null){ for (int i = 0; i < nodeList.getLength(); i++) { diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/entity/CacheDataEntity.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/entity/CacheDataEntity.java index 6f46239..7fd2695 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/entity/CacheDataEntity.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/entity/CacheDataEntity.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.entity; import lombok.Data; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/CacheType.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/CacheType.java index 3be3077..77897b1 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/CacheType.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/CacheType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.enums; /** diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/DictModelType.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/DictModelType.java index e168aef..2134be2 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/DictModelType.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/DictModelType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.enums; /** diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/MsgArgsType.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/MsgArgsType.java index 03be0eb..858872f 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/MsgArgsType.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/MsgArgsType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.enums; /** @@ -27,6 +42,10 @@ public enum MsgArgsType { /** 用户数据*/ USER_MODEL_DATA, + /** 菜单编号 */ + MENU_CODE, + /** 菜单数据*/ + MENU_MODEL_DATA, /** 缓存数据Key */ CACHE_DATA_KEY, diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/PushSubType.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/PushSubType.java index b2002d4..c51ac3b 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/PushSubType.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/PushSubType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.enums; /** @@ -15,6 +30,9 @@ public enum PushSubType { /** 用户数据 */ USER, + /** 菜单数据 */ + MENU, + /** 热点数据 */ HOT_DATA, diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/UserModelType.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/UserModelType.java index 36153ed..9058425 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/UserModelType.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/enums/UserModelType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.enums; /** diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java index 45f39a8..cf99d4a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.handler; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/EdenDataHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/EdenDataHandler.java index ba56cae..f9d3746 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/EdenDataHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/EdenDataHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.handler; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/HotDataHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/HotDataHandler.java index 7c97268..b8283d0 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/HotDataHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/HotDataHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.handler; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java new file mode 100644 index 0000000..c0677e6 --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java @@ -0,0 +1,75 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.cache.pushsub.handler; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.constants.CacheConstants; +import org.opsli.core.cache.local.CacheUtil; +import org.opsli.core.cache.pushsub.enums.MsgArgsType; +import org.opsli.core.cache.pushsub.enums.PushSubType; +import org.opsli.core.utils.MenuUtil; +import org.opsli.plugins.cache.EhCachePlugin; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.cache.pushsub.handler + * @Author: Parker + * @CreateTime: 2020-09-15 16:24 + * @Description: 字典消息处理 + */ +@Slf4j +public class MenuHandler implements RedisPushSubHandler{ + + @Autowired + EhCachePlugin ehCachePlugin; + + @Override + public PushSubType getType() { + return PushSubType.MENU; + } + + @Override + public void handler(JSONObject msgJson) { + // 用户刷新 + this.menuHandler(msgJson); + } + + /** + * 用户数据处理 + * @param msgJson + */ + private void menuHandler(JSONObject msgJson){ + JSONObject data = msgJson.getJSONObject(MsgArgsType.MENU_MODEL_DATA.toString()); + // 数据为空则不执行 + if(data == null) return; + + // 获得用户ID 和 用户名 + String menuCode = (String) msgJson.get(MsgArgsType.MENU_CODE.toString()); + if(StringUtils.isEmpty(menuCode)){ + return; + } + + // 先删除 + ehCachePlugin.delete(CacheConstants.HOT_DATA, MenuUtil.PREFIX_CODE + menuCode); + // 清除空拦截 + CacheUtil.delNilFlag(MenuUtil.PREFIX_CODE + menuCode); + } + + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/RedisPushSubHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/RedisPushSubHandler.java index 85edfba..8e64370 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/RedisPushSubHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/RedisPushSubHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.handler; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java index f62ee8e..955c772 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java @@ -1,11 +1,24 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.handler; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.opsli.api.wrapper.system.menu.MenuModel; -import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.constants.CacheConstants; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.cache.pushsub.enums.MsgArgsType; @@ -15,9 +28,6 @@ import org.opsli.core.utils.UserUtil; import org.opsli.plugins.cache.EhCachePlugin; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.List; - /** * @BelongsProject: opsli-boot * @BelongsPackage: org.opsli.core.cache.pushsub.handler @@ -69,8 +79,6 @@ public class UserHandler implements RedisPushSubHandler{ // 数据为空则不执行 if(data == null) return; - // 获得数据 - UserModel userModel = data.toJavaObject(UserModel.class); // 获得用户ID 和 用户名 String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); String username = (String) msgJson.get(MsgArgsType.USER_USERNAME.toString()); @@ -81,12 +89,9 @@ public class UserHandler implements RedisPushSubHandler{ // 先删除 ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID + userId); ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_USERNAME + username); - // 再赋值 - ehCachePlugin.put(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID + userId, userModel); - ehCachePlugin.put(CacheConstants.HOT_DATA,UserUtil.PREFIX_USERNAME + username, userModel); // 清除空拦截 - CacheUtil.putNilFlag(UserUtil.PREFIX_ID + userId); - CacheUtil.putNilFlag(UserUtil.PREFIX_USERNAME + username); + CacheUtil.delNilFlag(UserUtil.PREFIX_ID + userId); + CacheUtil.delNilFlag(UserUtil.PREFIX_USERNAME + username); } /** @@ -104,19 +109,10 @@ public class UserHandler implements RedisPushSubHandler{ return; } - // 用户角色列表 - List roleCodes = dataArray.toJavaList(String.class); - if(roleCodes == null || roleCodes.isEmpty()){ - return; - } - // 先删除 ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_ROLES + userId); - // 存入缓存 - ehCachePlugin.put(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_ROLES + userId, roleCodes); // 清除空拦截 - CacheUtil.putNilFlag(UserUtil.PREFIX_ID_ROLES + userId); - + CacheUtil.delNilFlag(UserUtil.PREFIX_ID_ROLES + userId); } /** @@ -133,18 +129,11 @@ public class UserHandler implements RedisPushSubHandler{ if(StringUtils.isEmpty(userId)){ return; } - // 用户权限列表 - List perms = dataArray.toJavaList(String.class); - if(perms == null || perms.isEmpty()){ - return; - } // 先删除 ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_PERMISSIONS + userId); - // 存入缓存 - ehCachePlugin.put(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_PERMISSIONS + userId, perms); // 清除空拦截 - CacheUtil.putNilFlag(UserUtil.PREFIX_ID_PERMISSIONS + userId); + CacheUtil.delNilFlag(UserUtil.PREFIX_ID_PERMISSIONS + userId); } /** @@ -161,18 +150,11 @@ public class UserHandler implements RedisPushSubHandler{ if(StringUtils.isEmpty(userId)){ return; } - // 用户菜单列表 - List menus = dataArray.toJavaList(MenuModel.class); - if(menus == null || menus.isEmpty()){ - return; - } // 先删除 ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_MENUS + userId); - // 存入缓存 - ehCachePlugin.put(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_MENUS + userId, menus); // 清除空拦截 - CacheUtil.putNilFlag(UserUtil.PREFIX_ID_MENUS + userId); + CacheUtil.delNilFlag(UserUtil.PREFIX_ID_MENUS + userId); } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/CacheDataMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/CacheDataMsgFactory.java index d180ab1..cbabe30 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/CacheDataMsgFactory.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/CacheDataMsgFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.msgs; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/DictMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/DictMsgFactory.java index cfc2dc9..82f42d6 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/DictMsgFactory.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/DictMsgFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.msgs; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/MenuMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/MenuMsgFactory.java new file mode 100644 index 0000000..2503757 --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/MenuMsgFactory.java @@ -0,0 +1,60 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.cache.pushsub.msgs; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.experimental.Accessors; +import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.core.cache.pushsub.enums.MsgArgsType; +import org.opsli.core.cache.pushsub.enums.PushSubType; +import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver; +import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.cache.pushsub.msgs + * @Author: Parker + * @CreateTime: 2020-09-15 16:50 + * @Description: 用户消息 + */ + +@Data +@Accessors(chain = true) +public final class MenuMsgFactory extends BaseSubMessage{ + + /** 通道 */ + private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL; + + private MenuMsgFactory(){} + + /** + * 构建消息 - 菜单 + */ + public static BaseSubMessage createMenuMsg(MenuModel menuModel){ + BaseSubMessage baseSubMessage = new BaseSubMessage(); + // 数据 + JSONObject jsonObj = new JSONObject(); + jsonObj.put(MsgArgsType.MENU_CODE.toString(), menuModel.getMenuCode()); + jsonObj.put(MsgArgsType.MENU_MODEL_DATA.toString(), menuModel); + + // 用户 + baseSubMessage.build(CHANNEL,PushSubType.MENU.toString(),jsonObj); + return baseSubMessage; + } + + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/UserMsgFactory.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/UserMsgFactory.java index a7abeed..df8db70 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/UserMsgFactory.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/msgs/UserMsgFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.msgs; import com.alibaba.fastjson.JSONObject; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/receiver/RedisPushSubReceiver.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/receiver/RedisPushSubReceiver.java index 8cdaa11..bd4e501 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/receiver/RedisPushSubReceiver.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/receiver/RedisPushSubReceiver.java @@ -1,9 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.cache.pushsub.receiver; +import cn.hutool.core.util.ClassUtil; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.opsli.common.enums.SystemInfo; -import org.opsli.common.utils.PackageUtil; import org.opsli.core.cache.pushsub.enums.PushSubType; import org.opsli.core.cache.pushsub.handler.RedisPushSubHandler; import org.opsli.core.msg.CoreMsg; @@ -53,10 +69,10 @@ public class RedisPushSubReceiver extends BaseReceiver { @Bean public void initRedisPushSubHandler(){ + // 拿到state包下 实现了 SystemEventState 接口的,所有子类 - Set> clazzSet = PackageUtil.listSubClazz(RedisPushSubHandler.class.getPackage().getName(), - true, - RedisPushSubHandler.class + Set> clazzSet = ClassUtil.scanPackageBySuper(RedisPushSubHandler.class.getPackage().getName() + , RedisPushSubHandler.class ); int count = 0; @@ -79,7 +95,7 @@ public class RedisPushSubReceiver extends BaseReceiver { //自动注入依赖 beanFactory.autowireBean(obj); - + } catch (Exception e){ log.error(CoreMsg.REDIS_EXCEPTION_PUSH_SUB.getMessage()); } @@ -100,10 +116,10 @@ public class RedisPushSubReceiver extends BaseReceiver { JSONObject msgJson = JSONObject.parseObject(substring); String type = (String) msgJson.get(BaseSubMessage.BASE_TYPE); String identifier = (String) msgJson.get(BaseSubMessage.BASE_ID); - // TODO 本机不广播 -// if(SystemInfo.INSTANCE.getSystemID().equals(identifier)){ -// return; -// } + // 本机不广播 + if(SystemInfo.INSTANCE.getSystemID().equals(identifier)){ + return; + } PushSubType pt = PushSubType.valueOf(type); RedisPushSubHandler redisPushSubHandler = HANDLER_MAP.get(pt); if(redisPushSubHandler == null){ diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/KaptchaConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/KaptchaConfig.java index b8c264f..b97c11d 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/KaptchaConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/KaptchaConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; import com.google.code.kaptcha.impl.DefaultKaptcha; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/MyBatisPlusConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/MyBatisPlusConfig.java index b086e07..0cc99fc 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/MyBatisPlusConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/MyBatisPlusConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/RedisMessageListenerConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/RedisMessageListenerConfig.java index 24c6755..d838dcf 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/RedisMessageListenerConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/RedisMessageListenerConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; import lombok.extern.slf4j.Slf4j; @@ -33,7 +48,7 @@ public class RedisMessageListenerConfig { * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理 * @return */ - + @Bean public RedisMessageListenerContainer container(LettuceConnectionFactory lettuceConnectionFactory) { RedisPushSubReceiver receiver = new RedisPushSubReceiver(); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java index 8e0868c..adadee9 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; import org.apache.shiro.mgt.SecurityManager; @@ -62,6 +77,7 @@ public class ShiroConfig { filterMap.put("/swagger-resources/**", "anon"); filterMap.put("/captcha.jpg", "anon"); filterMap.put("/ueditor/**", "anon"); + filterMap.put("/static/file/**", "anon"); filterMap.put("/**", "oauth2"); shiroFilter.setFilterChainDefinitionMap(filterMap); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/SwaggerConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/SwaggerConfig.java index 7b97fc4..0fc5615 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/SwaggerConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/SwaggerConfig.java @@ -1,10 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; import com.fasterxml.classmate.TypeResolver; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import com.google.common.collect.Lists; import io.swagger.annotations.ApiOperation; -import org.opsli.common.constants.TokenConstants; +import org.opsli.core.utils.UserTokenUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -23,6 +38,9 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.List; +/** + * @author parker + */ @Configuration @EnableSwagger2 @EnableKnife4j @@ -100,7 +118,7 @@ public class SwaggerConfig { private List defaultToken() { ParameterBuilder parameterBuilder = new ParameterBuilder(); List parameters= Lists.newArrayList(); - parameterBuilder.name(TokenConstants.ACCESS_TOKEN) + parameterBuilder.name(UserTokenUtil.TOKEN_NAME) .description("Token 令牌") .modelRef(new ModelRef("String")) .parameterType("header") @@ -117,11 +135,11 @@ public class SwaggerConfig { AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; - return Lists.newArrayList(new SecurityReference(TokenConstants.ACCESS_TOKEN, authorizationScopes)); + return Lists.newArrayList(new SecurityReference(UserTokenUtil.TOKEN_NAME, authorizationScopes)); } private ApiKey apiKey() { - return new ApiKey(TokenConstants.ACCESS_TOKEN, TokenConstants.ACCESS_TOKEN, "header"); + return new ApiKey(UserTokenUtil.TOKEN_NAME, UserTokenUtil.TOKEN_NAME, "header"); } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/WafConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/WafConfig.java index 16bcc5c..f0203c6 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/WafConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/WafConfig.java @@ -1,6 +1,21 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf; -import org.opsli.core.waf.XssProperties; +import org.opsli.core.waf.WafProperties; import org.opsli.core.waf.filter.WafFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -12,30 +27,33 @@ import org.springframework.context.annotation.Configuration; import javax.servlet.DispatcherType; /** - * @author 毕子航 951755883@qq.com - * @date 2018/10/26 + * 软件防火墙 + * 防止XSS SQL 攻击 + * + * @author Parker + * @date 2020-10-09 */ @Configuration -@EnableConfigurationProperties({XssProperties.class}) +@EnableConfigurationProperties({WafProperties.class}) public class WafConfig { @Autowired - XssProperties xssProperties; + WafProperties wafProperties; @Bean - @ConditionalOnProperty(prefix = XssProperties.XSS, name = "enable", havingValue = "true", matchIfMissing = false) + @ConditionalOnProperty(prefix = WafProperties.WAF, name = "enable", havingValue = "true", matchIfMissing = false) public FilterRegistrationBean xssFilterRegistration() { WafFilter wafFilter = new WafFilter(); - wafFilter.setUrlExclusion(xssProperties.getUrlExclusion()); - wafFilter.setEnableSqlFilter(xssProperties.isSqlFilter()); - wafFilter.setEnableXssFilter(xssProperties.isEnable()); + wafFilter.setUrlExclusion(wafProperties.getUrlExclusion()); + wafFilter.setEnableSqlFilter(wafProperties.isSqlFilter()); + wafFilter.setEnableXssFilter(wafProperties.isXssFilter()); FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setDispatcherTypes(DispatcherType.REQUEST); registration.setFilter(wafFilter); - registration.addUrlPatterns(xssProperties.getUrlPatterns()); - registration.setName(xssProperties.getName()); - registration.setOrder(xssProperties.getOrder()); + registration.addUrlPatterns(wafProperties.getUrlPatterns()); + registration.setName(wafProperties.getName()); + registration.setOrder(wafProperties.getOrder()); return registration; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java index b545a57..ef512e6 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.conf.mybatis; import cn.hutool.core.bean.BeanUtil; @@ -80,14 +95,19 @@ public class AutoFillInterceptor implements Interceptor { * @param arg */ public void insertFill(Object arg) { - UserModel userModel = UserUtil.getUser(); + if(arg == null ) return; + Field[] fields = ReflectUtil.getFields(arg.getClass()); for (Field f : fields) { f.setAccessible(true); switch (f.getName()) { // 创建人 case MyBatisConstants.FIELD_CREATE_BY: - setProperty(arg, MyBatisConstants.FIELD_CREATE_BY, userModel.getId()); + // 如果创建人 为空则进行默认赋值 + Object createValue = ReflectUtil.getFieldValue(arg, f.getName()); + if(createValue == null){ + setProperty(arg, MyBatisConstants.FIELD_CREATE_BY, UserUtil.getUser().getId()); + } break; // 创建日期 case MyBatisConstants.FIELD_CREATE_TIME: @@ -95,7 +115,11 @@ public class AutoFillInterceptor implements Interceptor { break; // 更新人 case MyBatisConstants.FIELD_UPDATE_BY: - setProperty(arg, MyBatisConstants.FIELD_UPDATE_BY, userModel.getId()); + // 如果更新人 为空则进行默认赋值 + Object updateValue = ReflectUtil.getFieldValue(arg, f.getName()); + if(updateValue == null){ + setProperty(arg, MyBatisConstants.FIELD_UPDATE_BY, UserUtil.getUser().getId()); + } break; // 更新日期 case MyBatisConstants.FIELD_UPDATE_TIME: @@ -111,7 +135,11 @@ public class AutoFillInterceptor implements Interceptor { break; // 多租户设置 case MyBatisConstants.FIELD_TENANT: - setProperty(arg, MyBatisConstants.FIELD_TENANT, UserUtil.getTenantId()); + // 如果租户ID 为空则进行默认赋值 + Object tenantValue = ReflectUtil.getFieldValue(arg, f.getName()); + if(tenantValue == null){ + setProperty(arg, MyBatisConstants.FIELD_TENANT, UserUtil.getTenantId()); + } break; default: break; @@ -125,7 +153,8 @@ public class AutoFillInterceptor implements Interceptor { * @param arg */ public void updateFill(Object arg) { - UserModel userModel = UserUtil.getUser(); + if(arg == null ) return; + // 2020-09-19 // 修改这儿 有可能会拿到一个 MapperMethod,需要特殊处理 Field[] fields; @@ -139,16 +168,18 @@ public class AutoFillInterceptor implements Interceptor { if (arg == null) { return; } - fields = ReflectUtil.getFields(arg.getClass()); - } else { - fields = ReflectUtil.getFields(arg.getClass()); } + fields = ReflectUtil.getFields(arg.getClass()); for (Field f : fields) { f.setAccessible(true); switch (f.getName()) { // 更新人 case MyBatisConstants.FIELD_UPDATE_BY: - setProperty(arg, MyBatisConstants.FIELD_UPDATE_BY, userModel.getId()); + // 如果更新人 为空则进行默认赋值 + Object updateValue = ReflectUtil.getFieldValue(arg, f.getName()); + if(updateValue == null){ + setProperty(arg, MyBatisConstants.FIELD_UPDATE_BY, UserUtil.getUser().getId()); + } break; // 更新日期 case MyBatisConstants.FIELD_UPDATE_TIME: @@ -182,4 +213,4 @@ public class AutoFillInterceptor implements Interceptor { public void setProperties(Properties properties) { } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/general/StartPrint.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/general/StartPrint.java index 8975cf8..4156616 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/general/StartPrint.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/general/StartPrint.java @@ -1,47 +1,70 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.general; import cn.hutool.core.lang.Console; import cn.hutool.core.thread.ThreadUtil; import lombok.extern.slf4j.Slf4j; -import org.springframework.core.env.Environment; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; /** - * @BelongsProject: opsli-boot - * @BelongsPackage: org.opsli.core.print - * @Author: Parker - * @CreateTime: 2020-09-12 17:54 + * @Author: 周鹏程 + * @CreateTime: 2020-11-04 17:34 * @Description: 打印启动日志 */ @Slf4j -public enum StartPrint { +@Component +public class StartPrint { /** 实例对象 */ - INSTANCE; + public static StartPrint INSTANCE = new StartPrint(); + + /** 服务端口 */ + private static String serverPort; + /** 服务根地址 */ + private static String serverContextPath; + + @Value("${server.port:8080}") + public void setServerPort(String serverPort) { + StartPrint.serverPort = serverPort; + } + + @Value("${server.servlet.context-path:/think-bboss}") + public void setServerContextPath(String serverContextPath) { + StartPrint.serverContextPath = serverContextPath; + } /** * 成功 * 打印启动日志 */ - public void successPrint(Environment env){ + public void successPrint(){ // 睡一秒打印 ThreadUtil.sleep(1, TimeUnit.SECONDS); - String ip = "localhost"; - try { - ip = InetAddress.getLocalHost().getHostAddress(); - }catch (UnknownHostException e){ - log.error("网卡IP 获取失败"); - } - String serverPort = env.getProperty("server.port"); - String contextPath = env.getProperty("server.servlet.context-path"); + String basePath = getBasePath(); StringBuilder printStr = new StringBuilder(); printStr.append("\n----------------------------------------------------------\n") - .append("Opsli-Boot 框架启动成功! 相关URLs:\n") - .append("项目地址: \t\thttp://" + ip + ":" + serverPort + contextPath + "/\n") - .append("Doc文档: \t\thttp://" + ip + ":" + serverPort + contextPath + "/doc.html\n") + .append("Think-BBoss 框架启动成功! 相关URLs:\n") + .append("项目地址: \t\thttp://" + basePath + "/\n") + .append("Doc文档: \t\thttp://" + basePath + "/doc.html\n") .append("----------------------------------------------------------\n"); Console.log(printStr.toString()); } @@ -55,9 +78,21 @@ public enum StartPrint { ThreadUtil.sleep(1, TimeUnit.SECONDS); StringBuilder printStr = new StringBuilder(); printStr.append("\n----------------------------------------------------------\n") - .append("Opsli-Boot 框架启动失败! 请检查相关配置!\n") + .append("Think-BBoss 框架启动失败! 请检查相关配置!\n") .append("----------------------------------------------------------\n"); Console.log(printStr.toString()); } + + /** + * 获得服务根路径 + * @return + */ + public String getBasePath(){ + String ip = "127.0.0.1"; + try { + ip = InetAddress.getLocalHost().getHostAddress(); + }catch (UnknownHostException ignored){} + return ip + ":" + serverPort + serverContextPath; + } } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java index d602fe6..5940955 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.handler; import cn.hutool.core.text.StrFormatter; @@ -5,12 +20,11 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authc.IncorrectCredentialsException; import org.apache.shiro.authc.LockedAccountException; +import org.apache.shiro.authz.AuthorizationException; import org.opsli.api.base.result.ResultVo; -import org.opsli.common.exception.EmptyException; -import org.opsli.common.exception.JwtException; -import org.opsli.common.exception.ServiceException; -import org.opsli.common.exception.TokenException; +import org.opsli.common.exception.*; import org.opsli.core.msg.CoreMsg; +import org.opsli.core.msg.TokenMsg; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -96,7 +110,7 @@ public class GlobalExceptionHandler { * 拦截 自定义 Shiro 认证异常 */ @ExceptionHandler(IncorrectCredentialsException.class) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseBody public ResultVo incorrectCredentialsException(IncorrectCredentialsException e) { // token失效,请重新登录 @@ -114,6 +128,20 @@ public class GlobalExceptionHandler { return ResultVo.error(e.getMessage()); } + /** + * 拦截 自定义 Shiro 认证异常 + */ + @ExceptionHandler(AuthorizationException.class) + @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) + @ResponseBody + public ResultVo authorizationException(AuthorizationException e) { + // 无权访问该方法 + return ResultVo.error(TokenMsg.EXCEPTION_NOT_AUTH.getCode(), + TokenMsg.EXCEPTION_NOT_AUTH.getMessage() + ); + } + + /** * 拦截 自定义 Token 认证异常 */ @@ -122,7 +150,17 @@ public class GlobalExceptionHandler { @ResponseBody public ResultVo tokenException(TokenException e) { // Token 异常 - return ResultVo.error(e.getMessage()); + return ResultVo.error(e.getCode(), e.getMessage()); + } + + /** + * 拦截 自定义 防火墙 + */ + @ExceptionHandler(WafException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ResponseBody + public ResultVo wafException(WafException e) { + return ResultVo.error(e.getCode(), e.getMessage()); } // ============================ @@ -133,8 +171,9 @@ public class GlobalExceptionHandler { @ExceptionHandler(NullPointerException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody - public ResultVo nullPointerException(EmptyException e) { - return ResultVo.error(e.getCode(), e.getMessage()); + public ResultVo nullPointerException(NullPointerException e) { + log.error("空指针异常:{}",e.getMessage(),e); + return ResultVo.error(e.getMessage()); } @@ -168,4 +207,4 @@ public class GlobalExceptionHandler { return ResultVo.error(CoreMsg.SQL_EXCEPTION_UNKNOWN.getCode(), msg); } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/listener/ApplicationReadyEventListene.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/listener/ApplicationReadyEventListene.java index 488c04c..3a7a831 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/listener/ApplicationReadyEventListene.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/listener/ApplicationReadyEventListene.java @@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j; import org.opsli.core.general.StartPrint; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Component; /** @@ -18,7 +17,7 @@ import org.springframework.stereotype.Component; public class ApplicationReadyEventListene implements ApplicationListener { @Override public void onApplicationEvent(ApplicationReadyEvent event) { - ConfigurableApplicationContext applicationContext = event.getApplicationContext(); - StartPrint.INSTANCE.successPrint(applicationContext.getEnvironment()); + event.getApplicationContext(); + StartPrint.INSTANCE.successPrint(); } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/CoreMsg.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/CoreMsg.java index 3f0a3c5..ec37a66 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/CoreMsg.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/CoreMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.msg; import org.opsli.common.base.msg.BaseMsg; @@ -19,7 +34,6 @@ public enum CoreMsg implements BaseMsg { SQL_EXCEPTION_NOT_HAVE_DEFAULT_VALUE(10106,"数据异常:{} 字段没有默认值!"), SQL_EXCEPTION_UNKNOWN(10106,"数据异常:未知异常,请联系系统管理员 {}"), - /** * Redis */ @@ -28,9 +42,9 @@ public enum CoreMsg implements BaseMsg { /** * Excel */ - EXCEL_EXPORT_SUCCESS(10300,"Excel 导出成功! - 数据行数:{} - 耗时:{}毫秒"), + EXCEL_EXPORT_SUCCESS(200,"Excel 导出成功! - 数据行数:{} - 耗时:{}毫秒"), EXCEL_EXPORT_ERROR(10301,"Excel 导出失败! - 耗时:{}毫秒 - 失败信息:{}"), - EXCEL_IMPORT_SUCCESS(10302,"EXCEL 导入成功! - 耗时:{}毫秒"), + EXCEL_IMPORT_SUCCESS(200,"EXCEL 导入成功! - 耗时:{}毫秒"), EXCEL_IMPORT_ERROR(10303,"Excel导入失败! - 耗时:{}毫秒 - 失败信息:{}"), EXCEL_IMPORT_NO(10304,""), EXCEL_FILE_NULL(10305,"请选择文件"), @@ -38,7 +52,18 @@ public enum CoreMsg implements BaseMsg { /** * 缓存 */ - CACHE_PUNCTURE_EXCEPTION(10405, "当期服务繁忙,客官请稍微再次尝试!") + CACHE_PUNCTURE_EXCEPTION(10405, "当期服务繁忙,客官请稍微再次尝试!"), + + + /** + * 防火墙 + */ + WAF_EXCEPTION_XSS(10500, "包含非法字符!"), + WAF_EXCEPTION_SQL(10501, "包含非法字符!"), + + /** 演示模式 */ + EXCEPTION_ENABLE_DEMO(10600,"演示模式不允许操作"), + ; private int code; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java index c32c182..448c3c0 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/TokenMsg.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/TokenMsg.java index b484f89..a626b7f 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/TokenMsg.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/TokenMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.msg; import org.opsli.common.base.msg.BaseMsg; @@ -26,13 +41,15 @@ public enum TokenMsg implements BaseMsg { EXCEPTION_LOGIN_ACCOUNT_LOCKED(12102,"账号已被锁定,请联系管理员!"), EXCEPTION_LOGOUT_ERROR(12103,"登出失败,没有授权Token!"), EXCEPTION_LOGOUT_SUCCESS(12104,"登出成功!"), + EXCEPTION_LOGIN_ACCOUNT_LOCK(12104,"账号已锁定,请{}后,再次尝试"), + EXCEPTION_LOGIN_TENANT_NOT_USABLE(12105,"租户未启用,请联系管理员"), /** * 其他 */ EXCEPTION_USER_NULL(12200, "用户为空"), EXCEPTION_CAPTCHA_NULL(12201, "验证码已失效"), - + EXCEPTION_NOT_AUTH(12202, "无权访问该方法"), ; private int code; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java index 8f90435..3288991 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java @@ -1,15 +1,41 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageSerializable; +import lombok.extern.slf4j.Slf4j; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.core.base.entity.BaseEntity; import java.util.HashMap; +import java.util.List; import java.util.Map; -public class Page extends PageSerializable{ - +/** + * 分页类 + * + * @author parker + * @param + * @param + */ +@Slf4j +public class Page extends PageSerializable{ private int pageNo = 1; private int pageSize = 10; @@ -76,8 +102,8 @@ public class Page extends PageSerializable{ * 设置数据 * @param pageInfo */ - public void instance(PageInfo pageInfo) { - super.setList(pageInfo.getList()); + public void instance(PageInfo pageInfo, List list) { + super.setList(list); super.setTotal(pageInfo.getTotal()); } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/GenQueryBuilder.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/GenQueryBuilder.java index e9ae857..06c5190 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/GenQueryBuilder.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/GenQueryBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence.querybuilder; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/QueryBuilder.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/QueryBuilder.java index 5078c19..8a611ba 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/QueryBuilder.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/QueryBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence.querybuilder; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -15,7 +30,6 @@ public interface QueryBuilder { /** * 构造器 - * @param * @return */ QueryWrapper build(); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java index bc3cb42..036b6d3 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/WebQueryBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence.querybuilder; import cn.hutool.core.util.ReflectUtil; @@ -56,7 +71,7 @@ public class WebQueryBuilder implements QueryBuilder{ * @param defaultOrderField 默认排序字段 */ public WebQueryBuilder(Class entityClazz, Map parameterMap, - String defaultOrderField){ + String defaultOrderField){ this.parameterMap = parameterMap; this.entityClazz = entityClazz; this.defaultOrderField = defaultOrderField; @@ -114,7 +129,9 @@ public class WebQueryBuilder implements QueryBuilder{ } // 如果没有排序 默认按照 修改时间倒叙排序 if(orderCount == 0){ - queryWrapper.orderByDesc(HumpUtil.humpToUnderline(this.defaultOrderField)); + if(StringUtils.isNotEmpty(this.defaultOrderField)){ + queryWrapper.orderByDesc(HumpUtil.humpToUnderline(this.defaultOrderField)); + } } return queryWrapper; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryBuilderChain.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryBuilderChain.java index 3332799..bbcccbd 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryBuilderChain.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/QueryBuilderChain.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence.querybuilder.chain; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java index 77a997e..71a9dec 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/querybuilder/chain/TenantHandler.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.persistence.querybuilder.chain; import cn.hutool.core.util.ReflectUtil; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/filter/OAuth2Filter.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/filter/OAuth2Filter.java index 0098798..3de600b 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/filter/OAuth2Filter.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/filter/OAuth2Filter.java @@ -59,7 +59,9 @@ public class OAuth2Filter extends AuthenticatingFilter { if(StringUtils.isBlank(token)){ HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); + httpResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE"); httpResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin")); + httpResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers")); httpResponse.setContentType("application/json; charset=utf-8"); // 401 Token失效,请重新登录 ResultVo error = ResultVo.error(TokenMsg.EXCEPTION_TOKEN_LOSE_EFFICACY.getCode(), @@ -75,9 +77,10 @@ public class OAuth2Filter extends AuthenticatingFilter { protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; - httpResponse.setContentType("application/json;charset=utf-8"); - httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); + httpResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE"); httpResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin")); + httpResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers")); + httpResponse.setContentType("application/json; charset=utf-8"); try { //处理登录失败的异常 @@ -90,5 +93,4 @@ public class OAuth2Filter extends AuthenticatingFilter { return false; } - } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java index 2aa2162..d6e171f 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java @@ -56,7 +56,7 @@ public class OAuth2Realm extends AuthorizingRealm { */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) - throws AuthenticationException { + throws AuthenticationException,TokenException { String accessToken = (String) token.getPrincipal(); @@ -75,8 +75,9 @@ public class OAuth2Realm extends AuthorizingRealm { // 3. 校验账户是否锁定 if(user == null || user.getLocked().equals('1')){ // 账号已被锁定,请联系管理员 - throw new LockedAccountException( - TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCKED.getMessage()); + // token失效,请重新登录 + throw new TokenException( + TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCKED); } return new SimpleAuthenticationInfo(user, accessToken, getName()); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/thread/LogsThreadPool.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/thread/LogsThreadPool.java new file mode 100644 index 0000000..1a9007a --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/thread/LogsThreadPool.java @@ -0,0 +1,62 @@ +package org.opsli.core.thread; + +import lombok.extern.slf4j.Slf4j; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.thread.factory.NameableThreadFactory; +import org.opsli.api.web.system.logs.LogsApi; +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.common.api.TokenThreadLocal; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * @BelongsProject: tank-design + * @BelongsPackage: com.parker.tank.net.thread + * @Author: Parker + * @CreateTime: 2020-08-21 14:22 + * @Description: 日志保存线程 + */ +@Slf4j +@Component +public class LogsThreadPool { + + + private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(4, + new NameableThreadFactory("日志保存线程")); + + + /** 日志API */ + private static LogsApi logsApi; + + /** + * 执行 + * @param logsModel + */ + public static void process(LogsModel logsModel){ + if(logsModel == null){ + return; + } + EXECUTOR_SERVICE.submit(()->{ + // 存储临时 token + try { + ResultVo ret = logsApi.insert(logsModel); + if(!ret.isSuccess()){ + log.error(ret.getMsg()); + } + }catch (Exception e){ + log.error(e.getMessage(), e); + } + }); + } + + + // ======================== + @Autowired + public void setLogsApi(LogsApi logsApi) { + LogsThreadPool.logsApi = logsApi; + } + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java index d5a876a..7734f06 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java @@ -1,16 +1,37 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; -import com.alibaba.fastjson.JSONObject; import com.google.code.kaptcha.Producer; import org.apache.commons.lang3.StringUtils; +import org.opsli.api.web.system.dict.DictDetailApi; import org.opsli.common.exception.TokenException; import org.opsli.core.msg.TokenMsg; +import org.opsli.plugins.redis.RedisLockPlugins; import org.opsli.plugins.redis.RedisPlugin; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.awt.image.BufferedImage; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + /** * 验证码 * @@ -18,6 +39,9 @@ import java.awt.image.BufferedImage; * @since 2.0.0 2018-02-10 */ @Component +@Order(UTIL_ORDER) +@AutoConfigureAfter({RedisPlugin.class}) +@Lazy(false) public class CaptchaUtil{ /** 缓存前缀 */ @@ -66,14 +90,24 @@ public class CaptchaUtil{ throw new TokenException(TokenMsg.EXCEPTION_CAPTCHA_NULL); } - //删除验证码 - redisPlugin.del(PREFIX + uuid); + // 删除验证码 + //redisPlugin.del(PREFIX + uuid); return codeTemp.equalsIgnoreCase(code); } + /** + * 删除验证码 + * @param uuid + * @return + */ + public static boolean delCaptcha(String uuid) { + if(StringUtils.isEmpty(uuid)) return false; + //删除验证码 + return redisPlugin.del(PREFIX + uuid); + } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java index 972376a..4e60ded 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; import com.alibaba.fastjson.JSONObject; @@ -6,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.dict.DictDetailApi; +import org.opsli.api.web.system.menu.MenuApi; import org.opsli.api.wrapper.system.dict.DictWrapper; import org.opsli.api.wrapper.system.dict.DictDetailModel; import org.opsli.common.constants.CacheConstants; @@ -15,12 +31,17 @@ import org.opsli.plugins.redis.RedisLockPlugins; import org.opsli.plugins.redis.RedisPlugin; import org.opsli.plugins.redis.lock.RedisLock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; import java.util.Set; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + /** * @BelongsProject: opsli-boot * @BelongsPackage: org.opsli.core.utils @@ -29,7 +50,10 @@ import java.util.Set; * @Description: 字典工具类 */ @Slf4j +@Order(UTIL_ORDER) @Component +@AutoConfigureAfter({RedisPlugin.class , RedisLockPlugins.class, DictDetailApi.class}) +@Lazy(false) public class DictUtil { /** Redis插件 */ @@ -61,7 +85,7 @@ public class DictUtil { // 防止缓存穿透判断 - boolean hasNilFlag = CacheUtil.hasNilFlag("dict:" + typeCode + ":" + dictValue); + boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_VALUE + typeCode + ":" + dictValue); if(hasNilFlag){ return defaultVal; } @@ -70,7 +94,7 @@ public class DictUtil { // 锁凭证 redisLock 贯穿全程 RedisLock redisLock = new RedisLock(); - redisLock.setLockName("dictLock:" + typeCode + ":" + dictValue) + redisLock.setLockName(DictConstants.CACHE_PREFIX_VALUE + typeCode + ":" + dictValue) .setAcquireTimeOut(3000L) .setLockTimeOut(5000L); @@ -115,7 +139,7 @@ public class DictUtil { if(StringUtils.isEmpty(dictName)){ // 加入缓存防穿透 // 设置空变量 用于防止穿透判断 - CacheUtil.putNilFlag("dict:" + typeCode + ":" + dictValue); + CacheUtil.putNilFlag(DictConstants.CACHE_PREFIX_VALUE + typeCode + ":" + dictValue); dictName = defaultVal; } return dictName; @@ -139,14 +163,14 @@ public class DictUtil { if (StringUtils.isNotEmpty(dictValue)) return dictValue; // 防止缓存穿透判断 - boolean hasNilFlag = CacheUtil.hasNilFlag("dict:" + typeCode + ":" + dictName); + boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName); if(hasNilFlag){ return defaultVal; } // 锁凭证 redisLock 贯穿全程 RedisLock redisLock = new RedisLock(); - redisLock.setLockName("dictLock:" + typeCode + ":" + dictName) + redisLock.setLockName(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName) .setAcquireTimeOut(3000L) .setLockTimeOut(10000L); @@ -192,7 +216,7 @@ public class DictUtil { if(StringUtils.isEmpty(dictValue)){ // 加入缓存防穿透 // 设置空变量 用于防止穿透判断 - CacheUtil.putNilFlag("dict:" + typeCode + ":" + dictName); + CacheUtil.putNilFlag(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName); dictValue = defaultVal; } return dictValue; @@ -215,13 +239,73 @@ public class DictUtil { if(jsonObject == null){ continue; } - DictDetailModel model = jsonObject.toJavaObject(DictDetailModel.class); + JSONObject dataJson = jsonObject.getJSONObject(CacheUtil.JSON_KEY); + if(dataJson == null){ + continue; + } + DictDetailModel model = dataJson.toJavaObject(DictDetailModel.class); DictWrapper dictWrapperModel = new DictWrapper(); dictWrapperModel.setTypeCode(typeCode); dictWrapperModel.setDictName(model.getDictName()); dictWrapperModel.setDictValue(model.getDictValue()); dictWrapperModels.add(dictWrapperModel); } + + if(dictWrapperModels.isEmpty()){ + // 防止缓存穿透判断 + boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_LIST + typeCode); + if(hasNilFlag){ + return dictWrapperModels; + } + + // 锁凭证 redisLock 贯穿全程 + RedisLock redisLock = new RedisLock(); + redisLock.setLockName(DictConstants.CACHE_PREFIX_LIST + typeCode) + .setAcquireTimeOut(3000L) + .setLockTimeOut(10000L); + + try { + // 这里增加分布式锁 防止缓存击穿 + // ============ 尝试加锁 + redisLock = redisLockPlugins.tryLock(redisLock); + if(redisLock == null){ + return dictWrapperModels; + } + + // 查询数据库 并保存到缓存内 + ResultVo> resultVo = dictDetailApi.findListByTypeCode(typeCode); + if(resultVo.isSuccess()){ + List dictDetailModels = resultVo.getData(); + for (DictDetailModel model : dictDetailModels) { + DictWrapper dictWrapperModel = new DictWrapper(); + dictWrapperModel.setTypeCode(model.getTypeCode()); + dictWrapperModel.setDictName(model.getDictName()); + dictWrapperModel.setDictValue(model.getDictValue()); + dictWrapperModel.setModel(model); + dictWrapperModels.add(dictWrapperModel); + // 保存至缓存 + DictUtil.put(dictWrapperModel); + } + } + + }catch (Exception e){ + log.error(e.getMessage(),e); + return dictWrapperModels; + }finally { + // ============ 释放锁 + redisLockPlugins.unLock(redisLock); + redisLock = null; + } + + + // 如果值还是 为空 则赋默认值 + if(dictWrapperModels.isEmpty()){ + // 加入缓存防穿透 + // 设置空变量 用于防止穿透判断 + CacheUtil.putNilFlag(DictConstants.CACHE_PREFIX_LIST + typeCode ); + } + + } }catch (Exception e){ log.error(e.getMessage(),e); dictWrapperModels = Lists.newArrayList(); @@ -244,8 +328,8 @@ public class DictUtil { CacheUtil.putEdenHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(), model.getDictValue(), model.getModel()); // 删除 空属性 拦截 - CacheUtil.putNilFlag("dict:" + model.getTypeCode() + ":" + model.getDictName()); - CacheUtil.putNilFlag("dict:" + model.getTypeCode() + ":" + model.getTypeCode()); + CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode() + ":" + model.getDictName()); + CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode() + ":" + model.getTypeCode()); } /** @@ -256,6 +340,9 @@ public class DictUtil { public static void del(DictWrapper model){ CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(), model.getDictName()); CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(), model.getDictValue()); + // 删除 空属性 拦截 + CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode() + ":" + model.getDictName()); + CacheUtil.delNilFlag(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode() + ":" + model.getTypeCode()); } /** @@ -285,6 +372,6 @@ public class DictUtil { @Autowired public void setDictDetailApi(DictDetailApi dictDetailApi) { - // DictUtil.dictDetailApi = dictDetailApi; + DictUtil.dictDetailApi = dictDetailApi; } } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java index b7321e5..6903bc9 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; import cn.hutool.core.util.ReflectUtil; @@ -10,6 +25,8 @@ import org.opsli.common.enums.ExcelOperate; import org.opsli.plugins.excel.ExcelPlugin; import org.opsli.plugins.excel.annotation.ExcelInfo; import org.opsli.plugins.excel.exception.ExcelPluginException; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -18,6 +35,8 @@ import java.lang.reflect.Field; import java.util.List; import java.util.Map; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + /** * @BelongsProject: opsli-boot * @BelongsPackage: org.opsli.core.utils @@ -26,7 +45,9 @@ import java.util.Map; * @Description: ExcelUtil */ @Slf4j +@Order(UTIL_ORDER) @Component +@Lazy(false) public class ExcelUtil extends ExcelPlugin { @Override diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java index bc46473..bf98879 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java @@ -1,8 +1,6 @@ package org.opsli.core.utils; import cn.hutool.core.util.StrUtil; -import cn.hutool.setting.dialect.Props; -import cn.hutool.setting.dialect.PropsUtil; import com.auth0.jwt.JWT; import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.algorithms.Algorithm; @@ -11,6 +9,7 @@ import com.auth0.jwt.interfaces.DecodedJWT; import lombok.extern.slf4j.Slf4j; import org.opsli.common.constants.SignConstants; import org.opsli.common.exception.JwtException; +import org.opsli.common.utils.Props; import org.opsli.core.msg.JwtMsg; import java.io.UnsupportedEncodingException; @@ -36,7 +35,7 @@ public final class JwtUtil { private static final String encryptJWTKey="a30ade6452725123436288ccae58570738ee"; static { - Props props = PropsUtil.get("application.yaml"); + Props props = new Props("application.yaml"); // token 有效时间 EXPIRE = props.getLong("opsli.token-effective-time", 120L) * 60 * 1000; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java new file mode 100644 index 0000000..9ed5956 --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java @@ -0,0 +1,204 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.utils; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.reflect.MethodSignature; +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.utils.IPUtil; +import org.opsli.core.thread.LogsThreadPool; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.utils + * @Author: Parker + * @CreateTime: 2020-09-19 20:03 + * @Description: 日志工具类 + */ +@Slf4j +public final class LogUtil { + + /** + * 保存日志 + * @param point + * @param e 异常 + * @param timerCount 花费毫秒数 + */ + public static void saveLog(ProceedingJoinPoint point, Exception e, long timerCount){ + + try { + Object[] args = point.getArgs(); + MethodSignature signature = (MethodSignature) point.getSignature(); + Method method = signature.getMethod(); + + RequestAttributes ra = RequestContextHolder.getRequestAttributes(); + ServletRequestAttributes sra = (ServletRequestAttributes) ra; + if(sra == null) return; + HttpServletRequest request = sra.getRequest(); + + // EnableLog 如果不被 EnableLog修饰 则直接退出 + // 判断 方法上是否使用 HotData注解 如果没有表示开启热数据 则直接跳过 + EnableLog enableLog = method.getAnnotation(EnableLog.class); + if(enableLog == null){ + return; + } + + UserModel user; + try { + user = UserUtil.getUser(); + }catch (Exception ex){ + return; + } + + LogsModel logsModel = new LogsModel(); + // 操作方法 + String methodName = request.getMethod(); + // 获得IP + String clientIpAddress = IPUtil.getClientIpAddress(request); + + // 设置标题 + setTitle(point, method, logsModel, user); + // 设置类型 + logsModel.setType(e == null ? LogsModel.TYPE_ACCESS : LogsModel.TYPE_EXCEPTION); + // 设置客户端代理 + logsModel.setUserAgent(request.getHeader("user-agent")); + // 设置URI + logsModel.setRequestUri(request.getRequestURI()); + // 设置IP + logsModel.setRemoteAddr(clientIpAddress); + // 设置参数 + logsModel.setParams(ToStringBuilder.reflectionToString(args)); + // 设置方法 + logsModel.setMethod(methodName); + // 设置执行时长 + logsModel.setTimeout(timerCount); + // 设置异常信息 + if(e != null){ + logsModel.setException(e.getMessage()); + } + + logsModel.setCreateBy(user.getId()); + logsModel.setUpdateBy(user.getId()); + logsModel.setIzManual(true); + + // 保存日志 + LogsThreadPool.process(logsModel); + } catch (Exception ex){ + log.error(ex.getMessage(), ex); + } + } + + /** + * 设置日志标题 + * @param point + * @param method + * @param logsModel + */ + private static void setTitle(ProceedingJoinPoint point, Method method, LogsModel logsModel, UserModel user){ + // 设置 title + EnableLog enableLog = method.getAnnotation(EnableLog.class); + if(enableLog != null){ + //注解上的描述,操作日志内容 + String title = enableLog.title(); + if(StringUtils.isNotEmpty(title)){ + logsModel.setTitle(title); + } + } + // 如果title 还为空 则系统自动赋值 + if(StringUtils.isEmpty(logsModel.getTitle())){ + RequiresPermissions permissions = method.getAnnotation(RequiresPermissions.class); + if(permissions != null){ + String[] values = permissions.value(); + if(values.length > 0){ + String perms = values[0]; + // 获得当前用户所持有菜单 + List menuListByUserId = UserUtil.getMenuListByUserId(user.getId()); + if(menuListByUserId != null){ + // 根据当前controller权限 获得对应权限数据 + MenuModel permsModel = MenuUtil.getMenuByCode(perms); + if(permsModel != null){ + // 依次获得菜单全名 + StringBuilder logTitleBuf = new StringBuilder(); + List parentMenu = getParentMenu(menuListByUserId, permsModel); + for (int i = parentMenu.size() - 1; i >= 0; i--) { + logTitleBuf.append(parentMenu.get(i).getMenuName()) + .append("-"); + } + String logTitle = logTitleBuf.toString(); + if(StringUtils.isNotEmpty(logTitle)){ + logsModel.setTitle(logTitle + permsModel.getMenuName()); + } + } + } + } + } + + // 如果title 还是为空 则系统自动赋class + if(StringUtils.isEmpty(logsModel.getTitle())){ + // 获取请求的类名 + String className = point.getTarget().getClass().getName(); + String methodName = method.getName(); + logsModel.setTitle(className+"."+methodName); + } + } + } + + + /** + * 递归 获得菜单全名 + * @param menuList + * @param permsModel + * @return + */ + private static List getParentMenu(List menuList, MenuModel permsModel){ + List menuModels = Lists.newArrayList(); + MenuModel parentMenu = null; + for (MenuModel menu : menuList) { + if(menu.getId().equals(permsModel.getParentId())){ + parentMenu = menu; + break; + } + } + + if(parentMenu != null){ + menuModels.add(parentMenu); + List temp = getParentMenu(menuList, parentMenu); + menuModels.addAll(temp); + } + + return menuModels; + } + + + // ================= + + private LogUtil(){} +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/MenuUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/MenuUtil.java new file mode 100644 index 0000000..5e46110 --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/MenuUtil.java @@ -0,0 +1,170 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.utils; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.menu.MenuApi; +import org.opsli.api.web.system.user.UserApi; +import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.core.cache.local.CacheUtil; +import org.opsli.core.cache.pushsub.msgs.MenuMsgFactory; +import org.opsli.plugins.redis.RedisLockPlugins; +import org.opsli.plugins.redis.RedisPlugin; +import org.opsli.plugins.redis.lock.RedisLock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.utils + * @Author: Parker + * @CreateTime: 2020-09-19 20:03 + * @Description: 菜单工具类 + */ +@Slf4j +@Order(UTIL_ORDER) +@Component +@AutoConfigureAfter({RedisPlugin.class , RedisLockPlugins.class, MenuApi.class}) +@Lazy(false) +public class MenuUtil { + + /** 前缀 */ + public static final String PREFIX_CODE = "menu:code:"; + + + /** Redis插件 */ + private static RedisPlugin redisPlugin; + + /** Redis分布式锁 */ + private static RedisLockPlugins redisLockPlugins; + + /** 用户Service */ + private static MenuApi menuApi; + + + /** + * 根据 userName 获得用户 + * @param menuCode + * @return + */ + public static MenuModel getMenuByCode(String menuCode){ + // 先从缓存里拿 + MenuModel menuModel = CacheUtil.get(PREFIX_CODE + menuCode, MenuModel.class); + if (menuModel != null){ + return menuModel; + } + + // 拿不到 -------- + // 防止缓存穿透判断 + boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + menuCode); + if(hasNilFlag){ + return null; + } + + // 锁凭证 redisLock 贯穿全程 + RedisLock redisLock = new RedisLock(); + redisLock.setLockName(PREFIX_CODE + menuCode) + .setAcquireTimeOut(3000L) + .setLockTimeOut(5000L); + + try { + // 这里增加分布式锁 防止缓存击穿 + // ============ 尝试加锁 + redisLock = redisLockPlugins.tryLock(redisLock); + if(redisLock == null){ + return null; + } + + // 查询数据库 + ResultVo resultVo = menuApi.getByCode(menuCode); + if(resultVo.isSuccess()){ + menuModel = resultVo.getData(); + // 存入缓存 + CacheUtil.put(PREFIX_CODE + menuCode, menuModel); + } + }catch (Exception e){ + log.error(e.getMessage(),e); + }finally { + // ============ 释放锁 + redisLockPlugins.unLock(redisLock); + redisLock = null; + } + + if(menuModel == null){ + // 设置空变量 用于防止穿透判断 + CacheUtil.putNilFlag(PREFIX_CODE + menuCode); + return null; + } + + return menuModel; + } + + + // ============== 刷新缓存 ============== + + /** + * 刷新用户 - 删就完了 + * @param menu + * @return + */ + public static void refreshMenu(MenuModel menu){ + if(menu == null || StringUtils.isEmpty(menu.getMenuCode())){ + return; + } + + MenuModel menuModel = CacheUtil.get(PREFIX_CODE + menu.getMenuCode(), MenuModel.class); + + // 只要不为空 则执行刷新 + if (menuModel != null){ + // 先删除 + CacheUtil.del(PREFIX_CODE + menu.getMenuCode()); + // 清除空拦截 + CacheUtil.delNilFlag(PREFIX_CODE + menu.getMenuCode()); + + // 发送通知消息 + redisPlugin.sendMessage( + MenuMsgFactory.createMenuMsg(menu) + ); + } + } + + + + + // ===================================== + + @Autowired + public void setRedisPlugin(RedisPlugin redisPlugin) { + MenuUtil.redisPlugin = redisPlugin; + } + + @Autowired + public void setRedisLockPlugins(RedisLockPlugins redisLockPlugins) { + MenuUtil.redisLockPlugins = redisLockPlugins; + } + + @Autowired + public void setMenuApi(MenuApi menuApi) { + MenuUtil.menuApi = menuApi; + } +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/SpringContextHolder.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/SpringContextHolder.java new file mode 100644 index 0000000..1f5efc3 --- /dev/null +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/SpringContextHolder.java @@ -0,0 +1,81 @@ +package org.opsli.core.utils; + +import org.apache.commons.lang3.Validate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +/** + * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext. + * + * @author Zaric + * @date 2016-5-29 下午1:25:40 + */ +@Component +@Lazy(false) +public class SpringContextHolder implements ApplicationContextAware, DisposableBean { + + private static ApplicationContext applicationContext = null; + + private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class); + + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) { + assertContextInjected(); + return (T) applicationContext.getBean(name); + } + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + public static T getBean(Class requiredType) { + assertContextInjected(); + return applicationContext.getBean(requiredType); + } + + /** + * 清除SpringContextHolder中的ApplicationContext为Null. + */ + public static void clearHolder() { + if (logger.isDebugEnabled()){ + logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext); + } + applicationContext = null; + } + + + + /** + * 检查ApplicationContext不为空. + */ + private static void assertContextInjected() { + Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder."); + } + + // ================== + + /** + * 实现ApplicationContextAware接口, 注入Context到静态变量中. + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + SpringContextHolder.applicationContext = applicationContext; + } + + /** + * 实现DisposableBean接口, 在Context关闭时清理静态变量. + */ + @Override + public void destroy() throws Exception { + SpringContextHolder.clearHolder(); + } + +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java index 2d13e00..755c6c4 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java index e209259..c6489e0 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java @@ -1,8 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; -import com.auth0.jwt.exceptions.TokenExpiredException; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -10,25 +24,35 @@ import org.apache.shiro.crypto.hash.Md5Hash; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.constants.SignConstants; +import org.opsli.common.constants.TokenConstants; import org.opsli.core.msg.TokenMsg; import org.opsli.plugins.redis.RedisPlugin; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import java.util.Map; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + /** * User Token Util * * @author parker */ + @Slf4j +@Order(UTIL_ORDER) @Component +@AutoConfigureAfter({RedisPlugin.class}) +@Lazy(false) public class UserTokenUtil { - /** token缓存名 */ - private static final String TOKEN_NAME = "token"; + /** token 缓存名 */ + public static final String TOKEN_NAME = TokenConstants.ACCESS_TOKEN; /** 缓存前缀 */ private static final String PREFIX = "opsli:ticket:"; @@ -111,7 +135,7 @@ public class UserTokenUtil { String username = ""; try { username = JwtUtil.getClaim(token, SignConstants.ACCOUNT); - }catch (Exception e){} + }catch (Exception ignored){} return username; } @@ -128,7 +152,18 @@ public class UserTokenUtil { String signTokenHex = new Md5Hash(token).toHex(); redisPlugin.del(PREFIX + signTokenHex); - }catch (Exception e){} + + // 删除相关信息 + String userId = getUserIdByToken(token); + UserModel user = UserUtil.getUser(userId); + if(user != null){ + UserUtil.refreshUser(user); + UserUtil.refreshUserRoles(user.getId()); + UserUtil.refreshUserAllPerms(user.getId()); + UserUtil.refreshUserMenus(user.getId()); + } + + }catch (Exception ignored){} } /** @@ -148,7 +183,6 @@ public class UserTokenUtil { // 2. 校验当前缓存中token是否失效 // 生成MD5 16进制码 用于缩减存储 String signTokenHex = new Md5Hash(token).toHex(); - Long endTimestamp = (Long) redisPlugin.get(PREFIX + signTokenHex); if(endTimestamp == null){ return false; @@ -156,9 +190,7 @@ public class UserTokenUtil { // JWT 自带过期校验 无需多做处理 - }catch (TokenExpiredException e){ - return false; - }catch (Exception e){ + } catch (Exception e){ return false; } return true; @@ -171,6 +203,7 @@ public class UserTokenUtil { * 获取请求的token */ public static String getRequestToken(HttpServletRequest httpRequest){ + //从header中获取token String token = httpRequest.getHeader(TOKEN_NAME); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java index bf29505..a7f4980 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserUtil.java @@ -1,13 +1,33 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.utils; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.crypto.hash.Md5Hash; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.user.UserApi; import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.api.TokenThreadLocal; import org.opsli.common.exception.TokenException; +import org.opsli.common.utils.Props; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.cache.pushsub.msgs.UserMsgFactory; import org.opsli.core.msg.TokenMsg; @@ -15,10 +35,15 @@ import org.opsli.plugins.redis.RedisLockPlugins; import org.opsli.plugins.redis.RedisPlugin; import org.opsli.plugins.redis.lock.RedisLock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.util.List; +import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; + /** * @BelongsProject: opsli-boot * @BelongsPackage: org.opsli.core.utils @@ -27,11 +52,16 @@ import java.util.List; * @Description: 用户工具类 */ @Slf4j +@Order(UTIL_ORDER) @Component +@AutoConfigureAfter({RedisPlugin.class , RedisLockPlugins.class, UserApi.class}) +@Lazy(false) public class UserUtil { - /** 超级管理员名称 */ - public static final String SUPER_ADMIN = "system"; + /** 超级管理员 */ + public static final String SUPER_ADMIN; + + /** 前缀 */ public static final String PREFIX_ID = "userId:"; public static final String PREFIX_ID_ROLES = "userId:roles:"; public static final String PREFIX_ID_PERMISSIONS = "userId:permissions:"; @@ -49,6 +79,11 @@ public class UserUtil { private static UserApi userApi; + static{ + Props props = new Props("application.yaml"); + SUPER_ADMIN = props.getStr("opsli.superadmin","system"); + } + /** * 获得当前系统登陆用户 * @return @@ -57,7 +92,8 @@ public class UserUtil { String token = TokenThreadLocal.get(); if(StringUtils.isEmpty(token)){ - return null; + // Token失效,请重新登录 + throw new TokenException(TokenMsg.EXCEPTION_TOKEN_LOSE_EFFICACY); } String userId = UserTokenUtil.getUserIdByToken(token); @@ -199,9 +235,17 @@ public class UserUtil { // 先从缓存里拿 try { - roles = (List) CacheUtil.get(PREFIX_ID_ROLES + userId); - if (roles != null && !roles.isEmpty()){ - return roles; + Object obj = CacheUtil.get(PREFIX_ID_ROLES + userId); + if(obj instanceof List){ + List list = (List) obj; + if (!list.isEmpty()) { + return list; + } + }else { + JSONArray jsonArray = (JSONArray) obj; + if (jsonArray != null && !jsonArray.isEmpty()) { + return jsonArray.toJavaList(String.class); + } } }catch (Exception e){ log.error(e.getMessage(), e); @@ -243,7 +287,7 @@ public class UserUtil { redisLock = null; } - if(roles == null){ + if(roles == null || roles.size() == 0){ // 设置空变量 用于防止穿透判断 CacheUtil.putNilFlag(PREFIX_ID_ROLES + userId); return null; @@ -263,9 +307,17 @@ public class UserUtil { // 先从缓存里拿 try { - permissions = (List) CacheUtil.get(PREFIX_ID_PERMISSIONS + userId); - if (permissions != null && !permissions.isEmpty()){ - return permissions; + Object obj = CacheUtil.get(PREFIX_ID_PERMISSIONS + userId); + if(obj instanceof List){ + List list = (List) obj; + if (!list.isEmpty()) { + return list; + } + }else { + JSONArray jsonArray = (JSONArray) obj; + if (jsonArray != null && !jsonArray.isEmpty()) { + return jsonArray.toJavaList(String.class); + } } }catch (Exception e){ log.error(e.getMessage(), e); @@ -308,7 +360,7 @@ public class UserUtil { redisLock = null; } - if(permissions == null){ + if(permissions == null || permissions.size() == 0){ // 设置空变量 用于防止穿透判断 CacheUtil.putNilFlag(PREFIX_ID_PERMISSIONS + userId); return null; @@ -327,9 +379,27 @@ public class UserUtil { // 先从缓存里拿 try { - menus = (List) CacheUtil.get(PREFIX_ID_MENUS + userId); - if (menus != null && !menus.isEmpty()){ - return menus; + Object obj = CacheUtil.get(PREFIX_ID_MENUS + userId); + if(obj instanceof List){ + List list = (List) obj; + if (!list.isEmpty()) { + List menuModels = Lists.newArrayListWithCapacity(list.size()); + for (Object menuObj : list) { + if(menuObj instanceof MenuModel){ + menuModels.add((MenuModel) menuObj); + }else if(menuObj instanceof JSONObject){ + JSONObject jsonObject = (JSONObject) menuObj; + MenuModel t = JSONObject.toJavaObject(jsonObject, MenuModel.class); + menuModels.add(t); + } + } + return menuModels; + } + }else { + JSONArray jsonArray = (JSONArray) obj; + if (jsonArray != null && !jsonArray.isEmpty()) { + return jsonArray.toJavaList(MenuModel.class); + } } }catch (Exception e){ log.error(e.getMessage(), e); @@ -372,7 +442,7 @@ public class UserUtil { redisLock = null; } - if(menus == null){ + if(menus == null || menus.size() == 0){ // 设置空变量 用于防止穿透判断 CacheUtil.putNilFlag(PREFIX_ID_MENUS + userId); return null; @@ -384,7 +454,7 @@ public class UserUtil { // ============== 刷新缓存 ============== /** - * 刷新用户 + * 刷新用户 - 删就完了 * @param user * @return */ @@ -402,12 +472,9 @@ public class UserUtil { // 先删除 CacheUtil.del(PREFIX_ID + user.getId()); CacheUtil.del(PREFIX_USERNAME + user.getUsername()); - // 再赋值 - CacheUtil.put(PREFIX_ID + user.getId(), user); - CacheUtil.put(PREFIX_USERNAME + user.getUsername(), user); // 清除空拦截 - CacheUtil.putNilFlag(PREFIX_ID + user.getId()); - CacheUtil.putNilFlag(PREFIX_USERNAME + user.getUsername()); + CacheUtil.delNilFlag(PREFIX_ID + user.getId()); + CacheUtil.delNilFlag(PREFIX_USERNAME + user.getUsername()); // 发送通知消息 redisPlugin.sendMessage( @@ -418,29 +485,22 @@ public class UserUtil { /** - * 刷新用户角色 + * 刷新用户角色 - 删就完了 * @param userId - * @param roleCodes * @return */ - public static void refreshUserRoles(String userId, List roleCodes){ - if(roleCodes == null || roleCodes.isEmpty()){ - return; - } - + public static void refreshUserRoles(String userId){ try { - List list = (List) CacheUtil.get(PREFIX_ID_ROLES + userId); - if(list != null && !list.isEmpty()){ + Object obj = CacheUtil.get(PREFIX_ID_ROLES + userId); + if(obj != null){ // 先删除 CacheUtil.del(PREFIX_ID_ROLES + userId); - // 存入缓存 - CacheUtil.put(PREFIX_ID_ROLES + userId, list); // 清除空拦截 - CacheUtil.putNilFlag(PREFIX_ID_ROLES + userId); + CacheUtil.delNilFlag(PREFIX_ID_ROLES + userId); // 发送通知消息 redisPlugin.sendMessage( - UserMsgFactory.createUserRolesMsg(userId, roleCodes) + UserMsgFactory.createUserRolesMsg(userId, null) ); } }catch (Exception e){ @@ -449,29 +509,22 @@ public class UserUtil { } /** - * 刷新用户权限 + * 刷新用户权限 - 删就完了 * @param userId - * @param permissions * @return */ - public static void refreshUserAllPerms(String userId, List permissions){ - if(permissions == null || permissions.isEmpty()){ - return; - } - + public static void refreshUserAllPerms(String userId){ try { - List list = (List) CacheUtil.get(PREFIX_ID_PERMISSIONS + userId); - if(list != null && !list.isEmpty()){ + Object obj = CacheUtil.get(PREFIX_ID_PERMISSIONS + userId); + if(obj != null){ // 先删除 CacheUtil.del(PREFIX_ID_PERMISSIONS + userId); - // 存入缓存 - CacheUtil.put(PREFIX_ID_PERMISSIONS + userId, permissions); // 清除空拦截 - CacheUtil.putNilFlag(PREFIX_ID_PERMISSIONS + userId); + CacheUtil.delNilFlag(PREFIX_ID_PERMISSIONS + userId); // 发送通知消息 redisPlugin.sendMessage( - UserMsgFactory.createUserPermsMsg(userId, permissions) + UserMsgFactory.createUserPermsMsg(userId, null) ); } }catch (Exception e){ @@ -480,29 +533,22 @@ public class UserUtil { } /** - * 刷新用户菜单 + * 刷新用户菜单 - 删就完了 * @param userId - * @param menus * @return */ - public static void refreshUserMenus(String userId, List menus){ - if(menus == null || menus.isEmpty()){ - return; - } - + public static void refreshUserMenus(String userId){ try { - List list = (List) CacheUtil.get(PREFIX_ID_MENUS + userId); - if(list != null && !list.isEmpty()){ + Object obj = CacheUtil.get(PREFIX_ID_MENUS + userId); + if(obj != null){ // 先删除 CacheUtil.del(PREFIX_ID_MENUS + userId); - // 存入缓存 - CacheUtil.put(PREFIX_ID_MENUS + userId, menus); // 清除空拦截 - CacheUtil.putNilFlag(PREFIX_ID_MENUS + userId); + CacheUtil.delNilFlag(PREFIX_ID_MENUS + userId); // 发送通知消息 redisPlugin.sendMessage( - UserMsgFactory.createUserMenusMsg(userId, menus) + UserMsgFactory.createUserMenusMsg(userId, null) ); } }catch (Exception e){ @@ -519,10 +565,6 @@ public class UserUtil { // 如果表中 没有 tenant_id 字段 则不进行多租户处理 UserModel user = getUser(); - if(user == null){ - // 用户为空 - throw new TokenException(TokenMsg.EXCEPTION_USER_NULL); - } // 如果是超级管理员 则不进行租户处理 if(SUPER_ADMIN.equals(user.getUsername())){ @@ -531,6 +573,15 @@ public class UserUtil { return user.getTenantId(); } + /** + * 处理密码 + * @param password 密码 + * @param secretkey 盐值 + * @return + */ + public static String handlePassword(String password, String secretkey){ + return new Md5Hash(password, secretkey).toHex(); + } // ===================================== diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/XssProperties.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/WafProperties.java similarity index 58% rename from opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/XssProperties.java rename to opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/WafProperties.java index d54f066..a993b02 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/XssProperties.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/WafProperties.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.waf; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -10,14 +25,21 @@ import java.util.List; * @author 毕子航 951755883@qq.com * @date 2018/10/26 */ -@ConfigurationProperties(prefix = XssProperties.XSS) -public class XssProperties { - public static final String XSS = "xss"; +@ConfigurationProperties(prefix = WafProperties.WAF) +public class WafProperties { + + public static final String WAF = "opsli.waf"; /** - * xss 是否生效 + * 是否生效 */ boolean enable = false; + + /** + * xss 过滤 + */ + boolean xssFilter = false; + /** * sql 过滤 */ @@ -79,6 +101,14 @@ public class XssProperties { this.enable = enable; } + public boolean isXssFilter() { + return xssFilter; + } + + public void setXssFilter(boolean xssFilter) { + this.xssFilter = xssFilter; + } + public boolean isSqlFilter() { return sqlFilter; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/filter/WafFilter.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/filter/WafFilter.java index 6faf7fe..1ef9673 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/filter/WafFilter.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/filter/WafFilter.java @@ -1,6 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.waf.filter; +import org.opsli.common.exception.TokenException; import org.opsli.core.waf.servlet.WafHttpServletRequestWrapper; import javax.servlet.*; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/servlet/WafHttpServletRequestWrapper.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/servlet/WafHttpServletRequestWrapper.java index e00aee8..df93e09 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/servlet/WafHttpServletRequestWrapper.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/servlet/WafHttpServletRequestWrapper.java @@ -1,12 +1,25 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.waf.servlet; -import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.opsli.common.constants.TokenConstants; -import org.opsli.common.exception.WafException; -import org.opsli.core.waf.util.XSSFilterKit; import org.opsli.core.waf.util.SQLFilterKit; +import org.opsli.core.waf.util.XSSFilterKit; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -20,7 +33,6 @@ import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Set; /** * 防火墙过滤处理器 @@ -72,30 +84,15 @@ public class WafHttpServletRequestWrapper extends HttpServletRequestWrapper { return super.getInputStream(); } - //为空,直接返回 + // 为空,直接返回 String json = StreamUtils.copyToString(super.getInputStream(), StandardCharsets.UTF_8); if (StringUtils.isEmpty(json)) { return super.getInputStream(); } - ByteArrayInputStream bis; - try { - // 防火墙过滤 - JSONObject jsonObject = JSONObject.parseObject(json); - Set keys = jsonObject.keySet(); - for (String key : keys) { - jsonObject.put(key, - filterParamString(String.valueOf(jsonObject.get(key))) - ); - } - json = jsonObject.toJSONString(); - }catch (WafException e){ - throw e; - }catch (Exception e){ - log.error(e.getMessage(),e); - }finally { - bis = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); - } + // 防火墙过滤 + json = filterParamString(json); + ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); return new ServletInputStream() { @Override diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java index 2c364c0..b6fe777 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.waf.util; import org.opsli.common.exception.WafException; @@ -23,7 +38,7 @@ public final class SQLFilterKit { } //去掉'|"|;|\字符 str = StringUtils.replace(str, "'", ""); - str = StringUtils.replace(str, "\"", ""); + //str = StringUtils.replace(str, "\"", ""); str = StringUtils.replace(str, ";", ""); str = StringUtils.replace(str, "\\", ""); @@ -42,6 +57,37 @@ public final class SQLFilterKit { return str; } + + /** + * SQL注入过滤 + * + * @param str 待验证的字符串 + */ + public static String replaceSQL(String str) { + if (StringUtils.isEmpty(str)) { + return null; + } + //去掉'|"|;|\字符 + str = StringUtils.replace(str, "'", ""); + str = StringUtils.replace(str, "\"", ""); + str = StringUtils.replace(str, ";", ""); + str = StringUtils.replace(str, "\\", ""); + str = StringUtils.replace(str, "|", ""); + + //转换成小写 + //str = str.toLowerCase(); + + //非法字符 + String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"}; + + // 替换非法字符 + for (String keyword : keywords) { + str = StringUtils.replace(str, keyword, ""); + } + + return str; + } + // ==================== private SQLFilterKit(){} } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java index 33f41d2..ea2545a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.waf.util; import org.apache.commons.lang3.StringUtils; diff --git a/opsli-modulars/opsli-modulars-creater/README.md b/opsli-modulars/opsli-modulars-creater/README.md new file mode 100644 index 0000000..8020af2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/README.md @@ -0,0 +1 @@ +## 代码生成器 diff --git a/opsli-modulars/opsli-modulars-creater/pom.xml b/opsli-modulars/opsli-modulars-creater/pom.xml new file mode 100644 index 0000000..6dcb2c6 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/pom.xml @@ -0,0 +1,15 @@ + + + + opsli-modulars + org.opsliframework.boot + 1.0.0 + + 4.0.0 + + opsli-modulars-creater + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java new file mode 100644 index 0000000..20fda14 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java @@ -0,0 +1,64 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.msg; + +import org.opsli.common.base.msg.BaseMsg; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.msg + * @Author: Parker + * @CreateTime: 2020-09-13 19:36 + * @Description: 代码生成器 - 消息 + */ +public enum CreaterMsg implements BaseMsg { + + /** + * 表 + */ + EXCEPTION_TABLE_NAME_REPEAT(50000,"表名重复"), + + /** + * 字段 + */ + EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT(50001,"字段名重复"), + + /** + * 同步 + */ + EXCEPTION_SYNC_NULL(50100,"同步表失败,暂无该表"), + EXCEPTION_SYNC_CORE(50101,"系统核心关键表不允许同步"), + + ; + + private int code; + private String message; + + CreaterMsg(int code, String message){ + this.code = code; + this.message = message; + } + + @Override + public Integer getCode() { + return this.code; + } + + @Override + public String getMessage() { + return this.message; + } +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java new file mode 100644 index 0000000..bcb8c1c --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java @@ -0,0 +1,169 @@ +package org.opsli.core.creater.strategy.sync; + +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.creater.msg.CreaterMsg; +import org.opsli.core.creater.strategy.sync.mysql.entity.FieldTypeAttribute; +import org.opsli.core.creater.strategy.sync.mysql.enums.MySQLSyncColumnType; +import org.opsli.core.waf.util.SQLFilterKit; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.general.actuator.SQLActuator; +import org.opsli.modulars.creater.table.service.ITableService; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.creater.strategy.sync.mysql + * @Author: Parker + * @CreateTime: 2020-11-18 13:21 + * @Description: MySQL 同步构建器 + */ +@Service +@Transactional(readOnly = true) +public class MySQLSyncBuilder implements SyncStrategy { + + /** 数据库引擎 */ + private static final String ENGINE = "InnoDB"; + /** 字符格式 */ + private static final String CHARSET = "utf8mb4"; + + /** 是 */ + private static final char YES = '1'; + /** 否 */ + private static final char NO = '0'; + + @Autowired(required = false) + private SQLActuator sqlActuator; + + @Autowired + private ITableService iTableService; + + @Override + public String getType() { + return "mysql"; + } + + /** + * 新建表 + * @param model + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void execute(CreaterTableAndColumnModel model) { + if(model == null) return; + + CreaterTableModel currTable = iTableService.get(model.getId()); + if(currTable == null){ + // 同步表失败,暂无该表 + throw new ServiceException(CreaterMsg.EXCEPTION_SYNC_NULL); + } + + // 排查该表 是否是 在排除外的表, 如果是则不允许同步 + List excludeTables = new ArrayList<>(); + excludeTables.add("creater_table"); + if(excludeTables.contains(currTable.getOldTableName()) || excludeTables.contains(currTable.getTableName())){ + // 同步表失败 系统核心关键表不允许同步 + throw new ServiceException(CreaterMsg.EXCEPTION_SYNC_CORE); + } + + // 删除表 + sqlActuator.execute(this.genDropTableSQL(model.getOldTableName())); + sqlActuator.execute(this.genDropTableSQL(model.getTableName())); + + // 新建表 + sqlActuator.execute(this.genCreateTableSQL(model)); + + // 更新同步状态 + iTableService.renewSyncState(model.getId()); + } + + /** + * 生成删除表SQL + * @param tableName + * @return sql + */ + private String genDropTableSQL(String tableName) { + return "DROP TABLE IF EXISTS " + SQLFilterKit.replaceSQL(tableName) + ";"; + } + + /** + * 生成创建表SQL + * @param model + * @return sql + */ + private String genCreateTableSQL(CreaterTableAndColumnModel model){ + // 表名 + String tableName = model.getTableName(); + // 表字段 + List columnList = model.getColumnList(); + + StringBuilder str = new StringBuilder(); + str.append("CREATE TABLE `").append(SQLFilterKit.replaceSQL(tableName)) + .append("`").append(" ("); + + for (int i = 0; i < columnList.size(); i++) { + CreaterTableColumnModel tmp = columnList.get(i); + + // 字段名 + str.append("`").append( + SQLFilterKit.replaceSQL(tmp.getFieldName()) + ).append("`"); + + // 字段类型 + String fieldType = SQLFilterKit.replaceSQL(tmp.getFieldType()); + FieldTypeAttribute fieldAttr = MySQLSyncColumnType.INSTANCE.getAttr(fieldType); + str.append(" ").append(fieldType); + if(fieldAttr != null){ + // 字段有长度 + if(fieldAttr.isIzLength()){ + str.append("(").append(tmp.getFieldLength()); + // 字段有精度 + if(fieldAttr.isIzPrecision()){ + str.append(",").append(tmp.getFieldPrecision()); + } + str.append(")"); + } + } + + // 判断是否为主键 + if(YES == tmp.getIzPk()){ + str.append(" ").append("PRIMARY KEY"); + }else{ + // 判断是否非空 + if(YES == tmp.getIzNull()){ + str.append(" ").append("NOT NULL"); + } + } + + // 字段描述 + if(StringUtils.isNotEmpty(tmp.getFieldComments())){ + str.append(" ").append("COMMENT '") + .append( + SQLFilterKit.replaceSQL(tmp.getFieldComments()) + ) + .append("'"); + } + + if(i != columnList.size()-1){ + str.append(","); + } + } + + str.append(" )"); + str.append(" ENGINE=").append(ENGINE); + str.append(" DEFAULT"); + str.append(" CHARSET=").append(CHARSET); + str.append(" COMMENT='").append(SQLFilterKit.replaceSQL(model.getComments())) + .append("'"); + str.append(";"); + + return str.toString(); + } +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java new file mode 100644 index 0000000..26298ac --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java @@ -0,0 +1,25 @@ +package org.opsli.core.creater.strategy.sync; + +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.creater.strategy.sync + * @Author: Parker + * @CreateTime: 2020-11-18 11:47 + * @Description: 同步策略 + */ +public interface SyncStrategy { + + /** + * 获得分类 + * @return + */ + String getType(); + + /** + * 执行 同步操作 + */ + void execute(CreaterTableAndColumnModel model); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java new file mode 100644 index 0000000..7fd8938 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java @@ -0,0 +1,28 @@ +package org.opsli.core.creater.strategy.sync.mysql.entity; + + +import lombok.Data; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.creater.strategy.sync.mysql + * @Author: Parker + * @CreateTime: 2020-11-18 13:21 + * @Description: MySQL 字段类型 属性 + */ +@Data +public class FieldTypeAttribute { + + private boolean izLength; + + private boolean izPrecision; + + public FieldTypeAttribute() { + } + + public FieldTypeAttribute(boolean izLength, boolean izPrecision) { + this.izLength = izLength; + this.izPrecision = izPrecision; + } +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java new file mode 100644 index 0000000..5eff425 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java @@ -0,0 +1,54 @@ +package org.opsli.core.creater.strategy.sync.mysql.enums; + + + +import org.opsli.core.creater.strategy.sync.mysql.entity.FieldTypeAttribute; + +import java.util.HashMap; +import java.util.Map; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.creater.strategy.sync.mysql + * @Author: Parker + * @CreateTime: 2020-11-18 13:21 + * @Description: MySQL 字段类型 判断 + */ +public enum MySQLSyncColumnType { + + INSTANCE; + + private static final Map fieldTypeMap = new HashMap<>(); + + static { + fieldTypeMap.put("tinyint", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("smallint", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("mediumint", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("int", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("integer", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("bigint", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("real", new FieldTypeAttribute(true, true)); + fieldTypeMap.put("float", new FieldTypeAttribute(true, true)); + fieldTypeMap.put("double", new FieldTypeAttribute(true, true)); + fieldTypeMap.put("decimal", new FieldTypeAttribute(true, true)); + fieldTypeMap.put("numeric", new FieldTypeAttribute(true, true)); + fieldTypeMap.put("char", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("varchar", new FieldTypeAttribute(true, false)); + fieldTypeMap.put("date", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("time", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("timestamp", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("datetime", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("blob", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("mediumblob", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("longblob", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("tinytext", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("text", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("mediumtext", new FieldTypeAttribute(false, false)); + fieldTypeMap.put("longtext", new FieldTypeAttribute(false, false)); + } + + public FieldTypeAttribute getAttr(String fieldType){ + return fieldTypeMap.get(fieldType); + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/util/SQLSyncUtil.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/util/SQLSyncUtil.java new file mode 100644 index 0000000..c0536f8 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/util/SQLSyncUtil.java @@ -0,0 +1,81 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.strategy.sync.util; + +import cn.hutool.core.util.ClassUtil; +import lombok.extern.slf4j.Slf4j; +import org.opsli.core.creater.strategy.sync.SyncStrategy; +import org.opsli.core.utils.SpringContextHolder; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.lang.reflect.Modifier; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.plugins.redis.entity + * @Author: Parker + * @CreateTime: 2020-09-15 14:50 + * @Description: 数据库同步策略 工具类 + * + */ +@Slf4j +@Configuration +public class SQLSyncUtil { + + + /** 处理方法集合 */ + private static final ConcurrentMap HANDLER_MAP = new ConcurrentHashMap<>(); + + + @Bean + public void initSyncStrategy(){ + + // 拿到state包下 实现了 SystemEventState 接口的,所有子类 + Set> clazzSet = ClassUtil.scanPackageBySuper(SyncStrategy.class.getPackage().getName() + , SyncStrategy.class + ); + + for (Class aClass : clazzSet) { + // 位运算 去除抽象类 + if((aClass.getModifiers() & Modifier.ABSTRACT) != 0){ + continue; + } + + SyncStrategy handler = (SyncStrategy) SpringContextHolder.getBean(aClass); + // 加入集合 + HANDLER_MAP.put(handler.getType(),handler); + } + } + + /** + * 执行 + * @param model + */ + public static void execute(CreaterTableAndColumnModel model){ + if(model == null) return; + + SyncStrategy syncStrategy = HANDLER_MAP.get(model.getJdbcType()); + if(syncStrategy != null){ + syncStrategy.execute(model); + } + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java new file mode 100644 index 0000000..3e9e4eb --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java @@ -0,0 +1,81 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.column.entity; + +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-11-15 17:33 + * @Description: 代码生成器 - 表结构 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterTableColumn extends BaseEntity { + + /** 归属表ID */ + private String tableId; + + /** 字段名称 */ + private String fieldName; + + /** 字段类型 */ + private String fieldType; + + /** 字段长度 */ + private Integer fieldLength; + + /** 字段精度 */ + private Integer fieldPrecision; + + /** 字段描述 */ + private String fieldComments; + + /** 是否主键 */ + private Character izPk; + + /** 是否可为空 */ + private Character izNull; + + /** 是否列表字段 */ + private Character izShowList; + + /** 是否表单显示 */ + private Character izShowForm; + + /** Java字段类型 */ + private String javaType; + + /** 字段生成方案(文本框、文本域、字典选择) */ + private Character showType; + + /** 字典类型编号 */ + private String dictTypeCode; + + /** 排序(升序) */ + private Integer sort; + + /** 验证类别 */ + private String validateType; + + + // ======================================== + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/TableColumnMapper.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/TableColumnMapper.java new file mode 100644 index 0000000..1afd40b --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/TableColumnMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.column.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.creater.column.entity.CreaterTableColumn; +import org.opsli.modulars.creater.table.entity.CreaterTable; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 代码生成器 - 表结构 Mapper + */ +@Mapper +public interface TableColumnMapper extends BaseMapper { + + /** + * 唯一验证 + * @param entity + * @return + */ + Integer uniqueVerificationByFieldName(CreaterTableColumn entity); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/xml/TableColumnMapper.xml b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/xml/TableColumnMapper.xml new file mode 100644 index 0000000..fd5eca4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/mapper/xml/TableColumnMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/ITableColumnService.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/ITableColumnService.java new file mode 100644 index 0000000..0f6b249 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/ITableColumnService.java @@ -0,0 +1,54 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.column.service; + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.creater.column.entity.CreaterTableColumn; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; + +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 代码生成器 - 表结构 接口 + */ +public interface ITableColumnService extends CrudServiceInterface { + + /** + * 根据表ID 获得数据 + * @param tableId + * @return + */ + List getByTableId(String tableId); + + + /** + * 根据表ID 删除数据 + * @param tableId + * @return + */ + void delByTableId(String tableId); + + /** + * 根据表ID 删除数据 + * @param tableIds + * @return + */ + void delByTableIds(String[] tableIds); +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/impl/TableColumnServiceImpl.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/impl/TableColumnServiceImpl.java new file mode 100644 index 0000000..37efb86 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/service/impl/TableColumnServiceImpl.java @@ -0,0 +1,170 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.column.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; +import org.opsli.api.utils.ValidationUtil; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.creater.msg.CreaterMsg; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.modulars.creater.column.entity.CreaterTableColumn; +import org.opsli.modulars.creater.column.mapper.TableColumnMapper; +import org.opsli.modulars.creater.column.service.ITableColumnService; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 代码生成器 - 表结构 接口实现类 + */ +@Service +public class TableColumnServiceImpl extends CrudServiceImpl + implements ITableColumnService { + + @Autowired(required = false) + private TableColumnMapper mapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public CreaterTableColumnModel insert(CreaterTableColumnModel model) { + // 验证对象 + ValidationUtil.verify(model); + + if(model == null) return null; + + CreaterTableColumn entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByFieldName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT); + } + + return super.insert(model); + } + + /** + * 批量新增 + * @param models model 数据模型 + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean insertBatch(List models) { + + if(models == null || models.size() == 0) return false; + + for (CreaterTableColumnModel model : models) { + + // 验证对象合法性 + ValidationUtil.verify(model); + + // 唯一验证 + CreaterTableColumn entity = super.transformM2T(model); + Integer count = mapper.uniqueVerificationByFieldName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT); + } + + // 默认清空 创建人和修改人 + if(model.getIzManual() != null && !model.getIzManual()){ + model.setCreateBy(null); + model.setCreateTime(null); + model.setUpdateBy(null); + model.setUpdateTime(null); + model.setId(null); + } + } + + + List entitys = transformMs2Ts(models); + return super.saveBatch(entitys); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public CreaterTableColumnModel update(CreaterTableColumnModel model) { + // 验证对象 + ValidationUtil.verify(model); + + if(model == null) return null; + + CreaterTableColumn entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByFieldName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(CreaterMsg.EXCEPTION_TABLE_COLUMN_FIELD_NAME_REPEAT); + } + + return super.update(model); + } + + @Override + public List getByTableId(String tableId) { + if( StringUtils.isEmpty(tableId) ){ + return null; + } + + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("table_id", tableId); + wrapper.orderByAsc("sort"); + List tableColumnList = this.findList(wrapper); + + return super.transformTs2Ms(tableColumnList); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delByTableId(String tableId){ + + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("table_id", tableId); + super.remove(wrapper); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delByTableIds(String[] tableIds){ + if(tableIds != null){ + for (String tableId : tableIds) { + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("tableId", tableId); + super.remove(wrapper); + } + } + } +} + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java new file mode 100644 index 0000000..6e57d12 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java @@ -0,0 +1,163 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.column.wrapper; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 代码生成器 - 表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterTableColumnModel extends ApiWrapper { + + /** 归属表ID */ + @ApiModelProperty(value = "归属表ID") + @ExcelProperty(value = "归属表ID", order = 1) + @ExcelInfo + private String tableId; + + /** 字段名称 */ + @ApiModelProperty(value = "字段名称") + @ExcelProperty(value = "字段名称", order = 2) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String fieldName; + + /** 字段类型 */ + @ApiModelProperty(value = "字段类型") + @ExcelProperty(value = "字段类型", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String fieldType; + + /** 字段长度 */ + @ApiModelProperty(value = "字段长度") + @ExcelProperty(value = "字段长度", order = 4) + @ExcelInfo + @ValidationArgsLenMax(6) + private Integer fieldLength; + + /** 字段精度 */ + @ApiModelProperty(value = "字段精度") + @ExcelProperty(value = "字段精度", order = 5) + @ExcelInfo + @ValidationArgsLenMax(6) + private Integer fieldPrecision; + + /** 字段描述 */ + @ApiModelProperty(value = "字段描述") + @ExcelProperty(value = "字段描述", order = 6) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(200) + private String fieldComments; + + /** 是否主键 */ + @ApiModelProperty(value = "是否主键") + @ExcelProperty(value = "是否主键", order = 7) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izPk; + + /** 是否可为空 */ + @ApiModelProperty(value = "是否可为空") + @ExcelProperty(value = "是否可为空", order = 8) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izNull; + + /** 是否列表显示 */ + @ApiModelProperty(value = "是否列表显示") + @ExcelProperty(value = "是否列表显示", order = 9) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izShowList; + + /** 是否表单显示 */ + @ApiModelProperty(value = "是否表单显示") + @ExcelProperty(value = "是否表单显示", order = 10) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izShowForm; + + /** Java字段类型 */ + @ApiModelProperty(value = "Java字段类型") + @ExcelProperty(value = "Java字段类型", order = 11) + @ExcelInfo(dictType = "java_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(50) + private String javaType; + + /** 字段生成方案(文本框、文本域、字典选择) */ + @ApiModelProperty(value = "字段生成方案") + @ExcelProperty(value = "字段生成方案", order = 12) + @ExcelInfo(dictType = "show_type") + // 验证器 + @ValidationArgsLenMax(1) + private Character showType; + + /** 字典类型编号 */ + @ApiModelProperty(value = "字典类型编号") + @ExcelProperty(value = "字典类型编号", order = 13) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String dictTypeCode; + + /** 排序(升序) */ + @ApiModelProperty(value = "排序") + @ExcelProperty(value = "排序", order = 14) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(6) + private Integer sort; + + /** 验证类别 */ + @ApiModelProperty(value = "验证类别") + @ExcelProperty(value = "验证类别", order = 15) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(500) + private String validateType; + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/general/actuator/SQLActuator.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/general/actuator/SQLActuator.java new file mode 100644 index 0000000..f6e2a9e --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/general/actuator/SQLActuator.java @@ -0,0 +1,37 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.general.actuator; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Update; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 代码生成器 - SQL 执行器 + */ +@Mapper +public interface SQLActuator { + + /** + * 执行 + */ + @Update("${sql}") + void execute(String sql); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java new file mode 100644 index 0000000..b29fba1 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java @@ -0,0 +1,113 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.api; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 代码生成器 - 表 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface TableApi { + + /** 标题 */ + String TITLE = "代码生成器 - 表"; + + /** + * 租户 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(CreaterTableModel model); + + /** + * 租户 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 租户 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody CreaterTableAndColumnModel model); + + /** + * 租户 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody CreaterTableAndColumnModel model); + + /** + * 租户 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 租户 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * 同步到数据库 + * @param id ID + * @return ResultVo + */ + @PostMapping("/sync") + ResultVo sync(String id); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java new file mode 100644 index 0000000..feb02ab --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java @@ -0,0 +1,62 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.entity; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-11-15 17:33 + * @Description: 代码生成器 - 表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterTable extends BaseEntity { + + + /** 表名称 */ + private String tableName; + + /** 旧表名称 */ + private String oldTableName; + + /** 表类型 */ + private Character tableType; + + /** 数据库类型 */ + private String jdbcType; + + /** 描述 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String comments; + + /** 同步 */ + private Character izSync; + + /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String remark; + + + // ======================================== + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/TableMapper.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/TableMapper.java new file mode 100644 index 0000000..bef38bb --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/TableMapper.java @@ -0,0 +1,45 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.creater.table.entity.CreaterTable; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 代码生成器 - 表 Mapper + */ +@Mapper +public interface TableMapper extends BaseMapper { + + /** + * 唯一验证 + * @param entity + * @return + */ + Integer uniqueVerificationByTableName(CreaterTable entity); + + /** + * 更新同步状态 为 已同步 + * @param id + */ + void renewSyncState(String id); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/xml/TableMapper.xml b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/xml/TableMapper.xml new file mode 100644 index 0000000..f94f8dc --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/mapper/xml/TableMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + update creater_table + set iz_sync = '1' + where + id = #{id} + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/ITableService.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/ITableService.java new file mode 100644 index 0000000..da085a3 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/ITableService.java @@ -0,0 +1,66 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.service; + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.creater.table.entity.CreaterTable; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 代码生成器 - 表 接口 + */ +public interface ITableService extends CrudServiceInterface { + + /** + * 新增表数据 + * @param model + * @return + */ + void insertAny(CreaterTableAndColumnModel model); + + /** + * 修改表数据 + * @param model + * @return + */ + void updateAny(CreaterTableAndColumnModel model); + + /** + * 根据表ID 删除数据 + * @param id + * @return + */ + void removeByIdAny(String id) throws Exception; + + /** + * 根据表ID 删除数据 + * @param ids + * @return + */ + void removeByIdsAny(String[] ids) throws Exception; + + /** + * 更新同步状态 为 已同步 + * @param id + */ + void renewSyncState(String id); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java new file mode 100644 index 0000000..53f4011 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java @@ -0,0 +1,180 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.service.impl; + +import org.opsli.common.enums.DictType; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.creater.msg.CreaterMsg; +import org.opsli.modulars.creater.column.service.ITableColumnService; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.general.actuator.SQLActuator; +import org.opsli.modulars.creater.table.entity.CreaterTable; +import org.opsli.modulars.creater.table.mapper.TableMapper; +import org.opsli.modulars.creater.table.service.ITableService; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 代码生成器 - 表 接口实现类 + */ +@Service +public class TableServiceImpl extends CrudServiceImpl + implements ITableService { + + @Autowired(required = false) + private TableMapper mapper; + + @Autowired + private ITableColumnService iTableColumnService; + + @Autowired(required = false) + private SQLActuator sqlActuator; + + @Override + @Transactional(rollbackFor = Exception.class) + public CreaterTableModel insert(CreaterTableModel model) { + if(model == null) return null; + + CreaterTable entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByTableName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT); + } + + // 新增后 默认未同步 + model.setIzSync( + DictType.NO_YES_NO.getCode().charAt(0)); + + // 默认旧表名称为当前新增名称(用于删除表操作) + model.setOldTableName(model.getTableName()); + + return super.insert(model); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public CreaterTableModel update(CreaterTableModel model) { + if(model == null) return null; + + CreaterTable entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByTableName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(CreaterMsg.EXCEPTION_TABLE_NAME_REPEAT); + } + + CreaterTableModel oldModel = this.get(model.getId()); + + + // 修改后 默认未同步 + model.setIzSync( + DictType.NO_YES_NO.getCode().charAt(0)); + + // 默认旧表名称为 修改前表名 便于改表后删除操作 + model.setOldTableName(oldModel.getTableName()); + + return super.update(model); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public void insertAny(CreaterTableAndColumnModel model){ + CreaterTableModel tableModel = WrapperUtil.transformInstance(model, CreaterTableModel.class); + // 保存表头数据 + tableModel = this.insert(tableModel); + if(tableModel != null){ + // 删除旧字段 全部新增 + iTableColumnService.delByTableId(tableModel.getId()); + + // 保存 表结构数据 + List columnList = model.getColumnList(); + for (CreaterTableColumnModel tableColumnModel : columnList) { + tableColumnModel.setTableId(tableModel.getId()); + } + iTableColumnService.insertBatch(columnList); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateAny(CreaterTableAndColumnModel model){ + CreaterTableModel tableModel = WrapperUtil.transformInstance(model, CreaterTableModel.class); + // 保存表头数据 + tableModel = this.update(tableModel); + if(tableModel != null){ + // 删除旧字段 全部新增 + iTableColumnService.delByTableId(tableModel.getId()); + + // 保存 表结构数据 + List columnList = model.getColumnList(); + for (CreaterTableColumnModel tableColumnModel : columnList) { + tableColumnModel.setTableId(tableModel.getId()); + } + iTableColumnService.insertBatch(columnList); + } + + sqlActuator.execute("select * from sys_user"); + + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void removeByIdAny(String id) throws Exception{ + // 删除表头 + boolean delFlag = super.delete(id); + if(!delFlag){ + throw new Exception(); + } + // 删除字段 + iTableColumnService.delByTableId(id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void removeByIdsAny(String[] ids) throws Exception{ + // 删除表头 + boolean delFlag = super.deleteAll(ids); + if(!delFlag){ + throw new Exception(); + } + + // 删除字段 + iTableColumnService.delByTableIds(ids); + } + + @Override + public void renewSyncState(String id) { + mapper.renewSyncState(id); + } + +} + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/web/TableRestController.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/web/TableRestController.java new file mode 100644 index 0000000..34d195b --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/web/TableRestController.java @@ -0,0 +1,227 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.web; + +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.creater.strategy.sync.util.SQLSyncUtil; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.creater.column.service.ITableColumnService; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.table.api.TableApi; +import org.opsli.modulars.creater.table.entity.CreaterTable; +import org.opsli.modulars.creater.table.service.ITableService; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 代码生成器 - 表 + */ +@Slf4j +@ApiRestController("/creater/table") +public class TableRestController extends BaseRestController + implements TableApi { + + @Autowired + private ITableColumnService iTableColumnService; + + /** + * 表 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条表", notes = "获得单条表 - ID") + @RequiresPermissions("deve_creater_select") + @Override + public ResultVo get(CreaterTableModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + + CreaterTableAndColumnModel currModel = WrapperUtil.transformInstance( + model, CreaterTableAndColumnModel.class + ); + + if(currModel == null){ + return ResultVo.error("暂无数据"); + } + + List columnModelList = iTableColumnService. + getByTableId(currModel.getId()); + + currModel.setColumnList(columnModelList); + + return ResultVo.success(currModel); + } + + /** + * 表 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @RequiresPermissions("deve_creater_select") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(CreaterTable.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + /** + * 表 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增表", notes = "新增表") + @RequiresPermissions("deve_creater_insert") + @EnableLog + @Override + public ResultVo insert(CreaterTableAndColumnModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用新增方法 + IService.insertAny(model); + + return ResultVo.success("新增表成功"); + } + + /** + * 表 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改表", notes = "修改表") + @RequiresPermissions("deve_creater_update") + @EnableLog + @Override + public ResultVo update(CreaterTableAndColumnModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用修改方法 + IService.updateAny(model); + + return ResultVo.success("修改表成功"); + } + + + /** + * 表 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除表数据", notes = "删除表数据") + @RequiresPermissions("deve_creater_delete") + @EnableLog + @Override + public ResultVo del(String id){ + // 演示模式 不允许操作 + super.demoError(); + try { + IService.removeByIdAny(id); + } catch (ServiceException e){ + throw e; + } catch (Exception e){ + throw new ServiceException(CoreMsg.SQL_EXCEPTION_DELETE); + } + return ResultVo.success("删除表成功"); + } + + + /** + * 表 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除表数据", notes = "批量删除表数据") + @RequiresPermissions("deve_creater_delete") + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + + try { + IService.removeByIdsAny(ids); + } catch (ServiceException e){ + throw e; + } catch (Exception e){ + throw new ServiceException(CoreMsg.SQL_EXCEPTION_DELETE); + } + + return ResultVo.success("批量删除表成功"); + } + + /** + * 表 同步 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "同步数据库表", notes = "同步数据库表") + @RequiresPermissions("deve_creater_sync") + @EnableLog + @Override + public ResultVo sync(String id){ + // 演示模式 不允许操作 + super.demoError(); + + CreaterTableAndColumnModel currModel = WrapperUtil.transformInstance( + IService.get(id), CreaterTableAndColumnModel.class + ); + + if(currModel == null){ + return ResultVo.error("同步失败"); + } + + List columnModelList = iTableColumnService. + getByTableId(currModel.getId()); + + currModel.setColumnList(columnModelList); + + // 执行同步操作 + SQLSyncUtil.execute(currModel); + + return ResultVo.success("同步成功"); + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableAndColumnModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableAndColumnModel.java new file mode 100644 index 0000000..46c0bb4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableAndColumnModel.java @@ -0,0 +1,108 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.wrapper; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 代码生成器 - 表和表结构 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterTableAndColumnModel extends ApiWrapper { + + + /** 表名称 */ + @ApiModelProperty(value = "表名称") + @ExcelProperty(value = "表名称", order = 1) + @ExcelInfo + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String tableName; + + /** 旧表名称 */ + @ApiModelProperty(value = "旧表名称") + @ExcelIgnore + private String oldTableName; + + /** 表类型 */ + @ApiModelProperty(value = "表类型") + @ExcelProperty(value = "表类型", order = 2) + @ExcelInfo(dictType = "table_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(1) + private Character tableType; + + /** 数据库类型 */ + @ApiModelProperty(value = "数据库类型") + @ExcelProperty(value = "数据库类型", order = 3) + @ExcelInfo(dictType = "jdbc_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(30) + private String jdbcType; + + /** 描述 */ + @ApiModelProperty(value = "描述") + @ExcelProperty(value = "描述", order = 4) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(200) + private String comments; + + /** 同步 */ + @ApiModelProperty(value = "同步") + @ExcelProperty(value = "是否同步", order = 5) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izSync; + + /** 备注 */ + @ApiModelProperty(value = "备注") + @ExcelProperty(value = "备注", order = 6) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String remark; + + + /** 表结构 */ + @ApiModelProperty(value = "表结构") + @ExcelProperty(value = "表结构", order = 7) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + private List columnList; + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableModel.java new file mode 100644 index 0000000..256d3fd --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/wrapper/CreaterTableModel.java @@ -0,0 +1,98 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.table.wrapper; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 代码生成器 - 表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterTableModel extends ApiWrapper { + + + /** 表名称 */ + @ApiModelProperty(value = "表名称") + @ExcelProperty(value = "表名称", order = 1) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String tableName; + + /** 旧表名称 */ + @ApiModelProperty(value = "旧表名称") + @ExcelIgnore + private String oldTableName; + + /** 表类型 */ + @ApiModelProperty(value = "表类型") + @ExcelProperty(value = "表类型", order = 2) + @ExcelInfo(dictType = "table_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(1) + private Character tableType; + + /** 数据库类型 */ + @ApiModelProperty(value = "数据库类型") + @ExcelProperty(value = "数据库类型", order = 3) + @ExcelInfo(dictType = "jdbc_type") + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(30) + private String jdbcType; + + /** 描述 */ + @ApiModelProperty(value = "描述") + @ExcelProperty(value = "描述", order = 4) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(200) + private String comments; + + /** 同步 */ + @ApiModelProperty(value = "同步") + @ExcelProperty(value = "是否同步", order = 5) + @ExcelInfo(dictType = "no_yes") + // 验证器 + @ValidationArgsLenMax(1) + private Character izSync; + + /** 备注 */ + @ApiModelProperty(value = "备注") + @ExcelProperty(value = "备注", order = 6) + @ExcelInfo + // 验证器 + @ValidationArgsLenMax(255) + private String remark; + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/creater.yaml b/opsli-modulars/opsli-modulars-creater/src/main/resources/creater.yaml new file mode 100644 index 0000000..9ab2d25 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/creater.yaml @@ -0,0 +1,14 @@ +# 排除表 防止代码生成器直接 非法删除关键表 +opsli: + exclude-tables: + - creater_table + - creater_table_column + - sys_dict + - sys_dict_detail + - sys_logs + - sys_menu + - sys_role + - sys_role_menu_ref + - sys_tenant + - sys_user + - sys_user_role_ref diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index faa3176..4769eaf 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system; import org.opsli.common.base.msg.BaseMsg; @@ -11,25 +26,41 @@ import org.opsli.common.base.msg.BaseMsg; */ public enum SystemMsg implements BaseMsg { + /** + * 系统 + */ + EXCEPTION_LOCK_DATA(20000,"内置数据只有超级管理员可以更改"), + /** * 数据字典 */ - EXCEPTION_DICT_UNIQUE(20000,"字典编号重复,该字典已存在!"), - EXCEPTION_DICT_DETAIL_UNIQUE(20001,"字典名称或值重复,该字典已存在!"), + EXCEPTION_DICT_UNIQUE(20100,"字典编号重复,该字典已存在"), + EXCEPTION_DICT_DETAIL_UNIQUE(20101,"字典名称或值重复,该字典已存在"), /** * 角色 */ - EXCEPTION_ROLE_UNIQUE(20100,"角色编号重复,该角色已存在!"), + EXCEPTION_ROLE_UNIQUE(20200,"角色编号重复,该角色已存在!"), + EXCEPTION_ROLE_ID_NOT_NULL(20201,"角色Id不可为空"), + EXCEPTION_ROLE_PERMS_ERROR(20202,"角色权限设置失败"), + /** * 用户 */ - EXCEPTION_USER_UNIQUE(20200,"该用户已存在!"), - + EXCEPTION_USER_UNIQUE(20300,"该用户已存在"), + EXCEPTION_USER_PASSWORD_ERROR(20301,"旧密码不正确"), + EXCEPTION_USER_ID_NOT_NULL(20302,"用户Id不可为空"), + EXCEPTION_USER_ROLES_ERROR(20303,"用户角色设置失败"), + EXCEPTION_USER_MENU_NOT_NULL(20304,"用户暂无角色菜单,请设置后登录"), + EXCEPTION_USER_NO_UNIQUE(20305,"该工号已存在"), + /** + * 租户 + */ + EXCEPTION_TENANT_UNIQUE(20200,"租户名称重复,该租户已存在!"), ; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java index 5825604..170d658 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDict.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.entity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.Data; import lombok.EqualsAndHashCode; @@ -28,6 +45,7 @@ public class SysDict extends BaseEntity { private Character izLock; /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String remark; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java index d45b19b..3f89996 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/entity/SysDictDetail.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.entity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.Data; import lombok.EqualsAndHashCode; @@ -36,6 +53,7 @@ public class SysDictDetail extends BaseEntity { private Integer sortNo; /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String remark; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictDetailMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictDetailMapper.java index 24af614..e48f692 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictDetailMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictDetailMapper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictMapper.java index f423d24..a7d9c34 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/mapper/DictMapper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictDetailService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictDetailService.java index de20896..a90b793 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictDetailService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictDetailService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.service; import org.opsli.api.wrapper.system.dict.DictDetailModel; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictService.java index 8ea6177..a55cdc5 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/IDictService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.service; import org.opsli.api.wrapper.system.dict.DictModel; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java index b65e7ed..b94ac45 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/service/impl/DictDetailServiceImpl.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.service.impl; import cn.hutool.core.convert.Convert; @@ -78,11 +93,17 @@ public class DictDetailServiceImpl extends CrudServiceImpl + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.service.impl; import org.apache.commons.lang3.StringUtils; @@ -61,17 +76,20 @@ public class DictServiceImpl extends CrudServiceImpl listByTypeCode = null; - if(StringUtils.isNotEmpty(model.getTypeCode())){ - listByTypeCode = iDictDetailService.findListByTypeCode(model.getTypeCode()); - } - if(listByTypeCode != null && listByTypeCode.size() > 0){ - for (DictDetailModel dictDetailModel : listByTypeCode) { - dictDetailModel.setTypeCode(updateRet.getTypeCode()); - iDictDetailService.update(dictDetailModel); + if(updateRet != null){ + // 字典主表修改 子表跟着联动 (验证是否改了编号)/ 或者修改不允许改编号 + List listByTypeCode = null; + if(StringUtils.isNotEmpty(model.getTypeCode())){ + listByTypeCode = iDictDetailService.findListByTypeCode(dictModel.getTypeCode()); + } + if(listByTypeCode != null && listByTypeCode.size() > 0){ + for (DictDetailModel dictDetailModel : listByTypeCode) { + dictDetailModel.setTypeCode(updateRet.getTypeCode()); + iDictDetailService.update(dictDetailModel); + } } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictDetailRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictDetailRestController.java index c4f7369..a1ad29e 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictDetailRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictDetailRestController.java @@ -1,15 +1,40 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.web; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.dict.DictDetailApi; import org.opsli.api.wrapper.system.dict.DictDetailModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; import org.opsli.core.base.concroller.BaseRestController; import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.dict.entity.SysDictDetail; import org.opsli.modulars.system.dict.service.IDictDetailService; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -32,12 +57,15 @@ public class DictDetailRestController extends BaseRestController get(DictDetailModel model) { // 如果系统内部调用 则直接查数据库 @@ -71,12 +99,14 @@ public class DictDetailRestController extends BaseRestController insert(DictDetailModel model) { // 调用新增方法 IService.insert(model); - return ResultVo.success("新增字典数据成功"); + return ResultVo.success("新增字典明细数据成功"); } /** @@ -84,12 +114,27 @@ public class DictDetailRestController extends BaseRestController update(DictDetailModel model) { + + if(model != null){ + DictDetailModel dictDetailModel = IService.get(model.getId()); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == dictDetailModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + // 调用修改方法 IService.update(model); - return ResultVo.success("修改字典数据"); + return ResultVo.success("修改字典明细数据成功"); } @@ -99,10 +144,23 @@ public class DictDetailRestController extends BaseRestController del(String id){ + + DictDetailModel dictDetailModel = IService.get(id); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == dictDetailModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + IService.delete(id); - return ResultVo.success("删除字典数据成功"); + return ResultVo.success("删除字典数据明细成功"); } @@ -112,10 +170,31 @@ public class DictDetailRestController extends BaseRestController delAll(String[] ids){ + + if(ids != null){ + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + List idList = Convert.toList(String.class,ids); + + wrapper.in(MyBatisConstants.FIELD_ID, idList); + List dictList = IService.findList(wrapper); + for (SysDictDetail sysDictDetail : dictList) { + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == sysDictDetail.getIzLock() ){ + UserModel user = UserUtil.getUser(); + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + } + IService.deleteAll(ids); - return ResultVo.success("批量删除字典数据成功"); + return ResultVo.success("批量删除字典数据明细成功"); } @@ -126,6 +205,8 @@ public class DictDetailRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { QueryBuilder queryBuilder = new WebQueryBuilder<>(SysDictDetail.class, request.getParameterMap()); @@ -138,6 +219,8 @@ public class DictDetailRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { return super.excelImport(request); @@ -149,6 +232,7 @@ public class DictDetailRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(DictDetailApi.TITLE, response); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictRestController.java index c6a3f54..26a0dc1 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/dict/web/DictRestController.java @@ -1,22 +1,50 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.dict.web; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.dict.DictApi; import org.opsli.api.wrapper.system.dict.DictModel; +import org.opsli.api.wrapper.system.dict.DictWrapper; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; import org.opsli.common.api.TokenThreadLocal; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; import org.opsli.core.base.concroller.BaseRestController; import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.utils.DictUtil; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.dict.entity.SysDict; import org.opsli.modulars.system.dict.service.IDictService; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** @@ -31,20 +59,21 @@ import javax.servlet.http.HttpServletResponse; public class DictRestController extends BaseRestController implements DictApi { + /** 内置数据 */ + private static final char LOCK_DATA = '1'; /** * 数据字典 查一条 * @param model 模型 * @return ResultVo */ - @ApiOperation(value = "获得单条字典明细数据", notes = "获得单条字典明细数据 - ID") + @ApiOperation(value = "获得单条字典数据", notes = "获得单条字典数据 - ID") @Override public ResultVo get(DictModel model) { // 如果系统内部调用 则直接查数据库 if(model != null && model.getIzApi() != null && model.getIzApi()){ model = IService.get(model); } - System.out.println(TokenThreadLocal.get()); return ResultVo.success(model); } @@ -72,12 +101,14 @@ public class DictRestController extends BaseRestController insert(DictModel model) { // 调用新增方法 IService.insert(model); - return ResultVo.success("新增字典明细数据成功"); + return ResultVo.success("新增字典数据成功"); } /** @@ -85,12 +116,27 @@ public class DictRestController extends BaseRestController update(DictModel model) { + + if(model != null){ + DictModel dictModel = IService.get(model.getId()); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == dictModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + // 调用修改方法 IService.update(model); - return ResultVo.success("修改字典明细数据成功"); + return ResultVo.success("修改字典数据成功"); } @@ -99,11 +145,24 @@ public class DictRestController extends BaseRestController del(String id){ + + DictModel dictModel = IService.get(id); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == dictModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + IService.delete(id); - return ResultVo.success("删除字典明细数据成功"); + return ResultVo.success("删除字典数据成功"); } @@ -112,11 +171,32 @@ public class DictRestController extends BaseRestController delAll(String[] ids){ + + if(ids != null){ + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + List idList = Convert.toList(String.class,ids); + + wrapper.in(MyBatisConstants.FIELD_ID, idList); + List dictList = IService.findList(wrapper); + for (SysDict sysDict : dictList) { + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == sysDict.getIzLock() ){ + UserModel user = UserUtil.getUser(); + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + } + IService.deleteAll(ids); - return ResultVo.success("批量删除字典明细数据成功"); + return ResultVo.success("批量删除字典数据成功"); } @@ -127,6 +207,8 @@ public class DictRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { QueryBuilder queryBuilder = new WebQueryBuilder<>(SysDict.class, request.getParameterMap()); @@ -139,6 +221,8 @@ public class DictRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { return super.excelImport(request); @@ -150,9 +234,25 @@ public class DictRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(DictApi.TITLE, response); } + /** + * 根据字典类型编号 查询出所有字典 + * + * @param typeCode 字典类型编号 + * @return + */ + @ApiOperation(value = "根据字典类型编号 查询出所有字典", notes = "根据字典类型编号 查询出所有字典") + @Override + public ResultVo getDictListByCode(String typeCode) { + List dictList = DictUtil.getDictList(typeCode); + if(dictList == null){ + return ResultVo.error("暂无该字典"); + } + return ResultVo.success(dictList); + } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/entity/LoginForm.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/entity/LoginForm.java index deebff9..e39f34d 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/entity/LoginForm.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/entity/LoginForm.java @@ -1,5 +1,5 @@ /** - * + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com *

* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -13,12 +13,15 @@ * License for the specific language governing permissions and limitations under * the License. */ - package org.opsli.modulars.system.login.entity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.annotation.validation.ValidationArgsLenMin; +import org.opsli.common.enums.ValiArgsType; /** * 登录表单 @@ -32,18 +35,25 @@ public class LoginForm { /** 用户名 */ @ApiModelProperty(value = "用户名") + @ValidationArgs({ValiArgsType.IS_NOT_NULL,ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(50) private String username; /** 密码 */ @ApiModelProperty(value = "密码") + @ValidationArgs(ValiArgsType.IS_NOT_NULL) + @ValidationArgsLenMin(6) private String password; /** 验证码 */ @ApiModelProperty(value = "验证码") + @ValidationArgs(ValiArgsType.IS_NOT_NULL) + @ValidationArgsLenMax(30) private String captcha; /** UUID */ @ApiModelProperty(value = "UUID") + @ValidationArgs(ValiArgsType.IS_NOT_NULL) private String uuid; } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java index 7771297..2af2c83 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/login/web/LoginRestController.java @@ -1,26 +1,59 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.login.web; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.crypto.hash.Md5Hash; import org.apache.tomcat.util.http.fileupload.IOUtils; import org.opsli.api.base.result.ResultVo; import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.api.TokenThreadLocal; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.exception.TokenException; import org.opsli.core.msg.TokenMsg; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.utils.CaptchaUtil; import org.opsli.core.utils.UserTokenUtil; import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.login.entity.LoginForm; -import org.springframework.web.bind.annotation.*; +import org.opsli.modulars.system.tenant.entity.SysTenant; +import org.opsli.modulars.system.tenant.service.ITenantService; +import org.opsli.plugins.redis.RedisPlugin; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Date; +import java.util.List; /** * 登陆 / 登出 / 验证码 @@ -35,6 +68,23 @@ import java.io.IOException; @RestController public class LoginRestController { + /** 账号失败次数 */ + private static final String ACCOUNT_SLIP_COUNT_PREFIX = "opsli:account:slip:count:"; + /** 账号失败锁定KEY */ + private static final String ACCOUNT_SLIP_LOCK_PREFIX = "opsli:account:slip:lock:"; + + /** 失败阈值 */ + @Value("${opsli.login.slip-count}") + private int slipCount; + /** 锁定时间 */ + @Value("${opsli.login.slip-lock-speed}") + private int slipLockSpeed; + + @Autowired + private RedisPlugin redisPlugin; + @Autowired + private ITenantService iTenantService; + /** * 登录 @@ -45,23 +95,81 @@ public class LoginRestController { boolean captcha = CaptchaUtil.validate(form.getUuid(), form.getCaptcha()); // 验证码不正确 if(!captcha){ - return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_CAPTCHA.getMessage()); + return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_CAPTCHA.getCode(), + TokenMsg.EXCEPTION_LOGIN_CAPTCHA.getMessage()); + } + + // 判断账号是否临时锁定 + Long loseTimeMillis = (Long) redisPlugin.get(ACCOUNT_SLIP_LOCK_PREFIX + form.getUsername()); + if(loseTimeMillis != null){ + Date currDate = new Date(); + DateTime loseDate = DateUtil.date(loseTimeMillis); + // 偏移5分钟 + DateTime currLoseDate = DateUtil.offsetSecond(loseDate, slipLockSpeed); + + // 计算失效剩余时间( 分 ) + long betweenM = DateUtil.between(currLoseDate, currDate, DateUnit.MINUTE); + if(betweenM > 0){ + String msg = StrUtil.format(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCK.getMessage() + ,betweenM + "分钟"); + return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCK.getCode(), + msg); + }else{ + // 计算失效剩余时间( 秒 ) + long betweenS = DateUtil.between(currLoseDate, currDate, DateUnit.SECOND); + String msg = StrUtil.format(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCK.getMessage() + ,betweenS + "秒"); + return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCK.getCode(), + msg); + } } //用户信息 - UserModel user = UserUtil.getUserByUserName(form.getUsername());; + UserModel user = UserUtil.getUserByUserName(form.getUsername()); //账号不存在、密码错误 if(user == null || - !user.getPassword().equals(new Md5Hash(form.getPassword(), user.getSecretkey()).toHex())) { + !user.getPassword().equals(UserUtil.handlePassword(form.getPassword(), user.getSecretkey()))) { + + // 如果失败次数 超过阈值 则锁定账号 + Long slipNum = redisPlugin.increment(ACCOUNT_SLIP_COUNT_PREFIX + form.getUsername()); + // 设置失效时间为 5分钟 + redisPlugin.expire(ACCOUNT_SLIP_COUNT_PREFIX + form.getUsername(),slipLockSpeed); + + // 如果确认 都失败 则存入临时缓存 + if(slipNum >= slipCount){ + long currentTimeMillis = System.currentTimeMillis(); + // 存入Redis + redisPlugin.put(ACCOUNT_SLIP_LOCK_PREFIX + form.getUsername(), + currentTimeMillis, slipLockSpeed); + } + return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_NO.getMessage()); } + // 删除失败次数记录 + redisPlugin.del(ACCOUNT_SLIP_COUNT_PREFIX + form.getUsername()); + //账号锁定 if(user.getLocked() == 1){ return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_ACCOUNT_LOCKED.getMessage()); } + // 如果不是超级管理员 需要验证租户是否生效 + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq("id", user.getTenantId()) + .eq("iz_usable", "1"); + List tenants = iTenantService.findList(queryWrapper); + if(tenants == null || tenants.isEmpty()){ + return ResultVo.error(TokenMsg.EXCEPTION_LOGIN_TENANT_NOT_USABLE.getMessage()); + } + } + + // 删除验证过后验证码 + CaptchaUtil.delCaptcha(form.getUuid()); + //生成token,并保存到Redis return UserTokenUtil.createToken(user); } @@ -100,4 +208,10 @@ public class LoginRestController { } } + + public static void main(String[] args) { + String passwordStr = "Aa123456"; + String password = UserUtil.handlePassword(passwordStr, "system"); + System.out.println(password); + } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/api/README.md b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/api/README.md new file mode 100644 index 0000000..f2f9594 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/api/README.md @@ -0,0 +1 @@ +## 改造微服务时 将Feign 接口写在这里 \ No newline at end of file diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/entity/SysLogs.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/entity/SysLogs.java new file mode 100644 index 0000000..8114a29 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/entity/SysLogs.java @@ -0,0 +1,73 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.logs.entity; + +import com.alibaba.excel.annotation.ExcelIgnore; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 日志表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysLogs extends BaseEntity { + + + private static final long serialVersionUID = 1L; + + + + /** 日志类型(1:接入日志;2:错误日志) */ + private String type; + + /** 日志标题 */ + private String title; + + /** 操作用户的IP地址 */ + private String remoteAddr; + + /** 操作用户代理信息 */ + private String userAgent; + + /** 执行时间 */ + private Long timeout; + + /** 操作的URI */ + private String requestUri; + + /** 操作的方式 */ + private String method; + + /** 操作提交的数据 */ + private String params; + + /** 异常信息 */ + private String exception; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/LogsMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/LogsMapper.java new file mode 100644 index 0000000..f87c7c1 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/LogsMapper.java @@ -0,0 +1,41 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.logs.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.system.logs.entity.SysLogs; + +import java.util.Date; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.mapper + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 日志 Mapper + */ +@Mapper +public interface LogsMapper extends BaseMapper { + + /** + * 清空一个月之前的数据 + * @return + */ + boolean emptyByOneMonth(Date date); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/xml/LogsMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/xml/LogsMapper.xml new file mode 100644 index 0000000..a6d54f5 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/mapper/xml/LogsMapper.xml @@ -0,0 +1,11 @@ + + + + + + + DELETE FROM sys_logs + WHERE create_time < #{date} + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/ILogsService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/ILogsService.java new file mode 100644 index 0000000..7de664e --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/ILogsService.java @@ -0,0 +1,38 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.logs.service; + +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.system.logs.entity.SysLogs; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 角色 接口 + */ +public interface ILogsService extends CrudServiceInterface { + + /** + * 清空一个月之前的数据 + * @return + */ + boolean emptyByOneMonth(); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/impl/LogsServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/impl/LogsServiceImpl.java new file mode 100644 index 0000000..ef52bc2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/service/impl/LogsServiceImpl.java @@ -0,0 +1,63 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.logs.service.impl; + +import cn.hutool.core.date.DateUtil; +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.modulars.system.logs.entity.SysLogs; +import org.opsli.modulars.system.logs.mapper.LogsMapper; +import org.opsli.modulars.system.logs.service.ILogsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 日志 接口实现类 + */ +@Service +public class LogsServiceImpl extends CrudServiceImpl implements ILogsService { + + @Autowired(required = false) + private LogsMapper mapper; + + @Transactional(rollbackFor = Exception.class) + @Override + public LogsModel insert(LogsModel model) { + int count = super.count(); + // 如果日志存储量为10万 则自动清空上月前数据 + if(count > 10_0000){ + this.emptyByOneMonth(); + } + return super.insert(model); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean emptyByOneMonth() { + Date newDate = DateUtil.lastMonth(); + return mapper.emptyByOneMonth(newDate); + } +} + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/web/LogsRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/web/LogsRestController.java new file mode 100644 index 0000000..7454276 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/logs/web/LogsRestController.java @@ -0,0 +1,105 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.logs.web; + +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.logs.LogsApi; +import org.opsli.api.wrapper.system.logs.LogsModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.system.logs.entity.SysLogs; +import org.opsli.modulars.system.logs.service.ILogsService; + +import javax.servlet.http.HttpServletRequest; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 角色 + */ +@Slf4j +@ApiRestController("/sys/logs") +public class LogsRestController extends BaseRestController + implements LogsApi { + + + /** + * 日志 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条日志", notes = "获得单条日志 - ID") + @RequiresPermissions("devops_logs_select") + @Override + public ResultVo get(LogsModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 日志 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @RequiresPermissions("devops_logs_select") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysLogs.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + + /** + * 日志 清空一个月前的日志 + * @return ResultVo + */ + @ApiOperation(value = "清空一个月前的日志", notes = "清空一个月前的日志") + @RequiresPermissions("devops_logs_delete") + @EnableLog + @Override + public ResultVo emptyByOneMonth(){ + IService.emptyByOneMonth(); + return ResultVo.success("清空日志成功"); + } + + + @Override + public ResultVo insert(LogsModel model) { + IService.insert(model); + return ResultVo.success("新增日志成功"); + } +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java index 70f17a0..1007770 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/entity/SysMenu.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.menu.entity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.Data; import lombok.EqualsAndHashCode; @@ -27,14 +44,29 @@ public class SysMenu extends BaseEntity { private String menuName; /** 图标 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String icon; - /** 项目类型:1-菜单2-按钮3-链接4-表单 */ + /** 项目类型: 1-菜单 2-按钮3 -链接 */ private String type; /** url地址 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String url; + /** 组件 - vue 对应组件 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String component; + + /** 重定向 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String redirect; + + /** 排序 */ + private Integer sortNo; + + /** 是否隐藏 0为否 1为是 */ + private String hidden; // ======================================== diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/MenuMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/MenuMapper.java index bf0f24b..83ae093 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/MenuMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/MenuMapper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.menu.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/RoleMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/MenuMapper.xml similarity index 89% rename from opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/RoleMapper.xml rename to opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/MenuMapper.xml index 5798629..244cdbf 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/RoleMapper.xml +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/mapper/xml/MenuMapper.xml @@ -12,7 +12,11 @@ a.icon as icon, a.type as type, a.url as url, + a.component as component, + a.redirect as redirect, a.iz_lock as izLock, + a.hidden as hidden, + a.sort_no as sortNo, a.create_by as createBy, a.create_time as createTime, @@ -38,4 +42,5 @@ - \ No newline at end of file + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/IMenuService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/IMenuService.java index ce34a9e..d189cfb 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/IMenuService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/IMenuService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.menu.service; import org.opsli.api.wrapper.system.menu.MenuModel; @@ -15,4 +30,11 @@ import org.opsli.modulars.system.menu.entity.SysMenu; public interface IMenuService extends CrudServiceInterface { + /** + * 根据菜单编号 获得菜单 + * @param menuCode + * @return + */ + MenuModel getByCode(String menuCode); + } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java index c4d4dce..9838860 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java @@ -1,17 +1,43 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.menu.service.impl; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.exception.ServiceException; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.utils.MenuUtil; +import org.opsli.core.utils.UserUtil; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.menu.entity.SysMenu; import org.opsli.modulars.system.menu.mapper.MenuMapper; import org.opsli.modulars.system.menu.service.IMenuService; +import org.opsli.modulars.system.user.service.IUserRoleRefService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + /** * @BelongsProject: opsli-boot @@ -25,8 +51,23 @@ public class MenuServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq("menu_code", menuCode); + List sysMenus = super.findList(queryWrapper); + if(sysMenus != null && !sysMenus.isEmpty()){ + return transformT2M(sysMenus.get(0)); + } + return null; + } + + @Override + @Transactional(rollbackFor = Exception.class) public MenuModel insert(MenuModel model) { if(model == null) return null; @@ -38,6 +79,11 @@ public class MenuServiceImpl extends CrudServiceImpl userIdList = iUserRoleRefService.getUserIdListByMenuId(menuModel.getId()); + if(userIdList != null && !userIdList.isEmpty()){ + for (String userId : userIdList) { + // 清空当期用户缓存角色、权限、菜单 + UserUtil.refreshUserRoles(userId); + UserUtil.refreshUserAllPerms(userId); + UserUtil.refreshUserMenus(userId); + } + } + } + + return menuModel; + } + + @Override + public boolean delete(String id) { + MenuModel menuModel = super.get(id); + boolean ret = super.delete(id); + if(ret){ + // 清空编号缓存 + MenuUtil.refreshMenu(menuModel); + // 清空该菜单下 用户缓存 + List userIdList = iUserRoleRefService.getUserIdListByMenuId(id); + if(userIdList != null && !userIdList.isEmpty()){ + for (String userId : userIdList) { + // 清空当期用户缓存角色、权限、菜单 + UserUtil.refreshUserRoles(userId); + UserUtil.refreshUserAllPerms(userId); + UserUtil.refreshUserMenus(userId); + } + } + } + return ret; } + @Override + public boolean deleteAll(String[] ids) { + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids)); + List menuList = super.findList(queryWrapper); + + boolean ret = super.deleteAll(ids); + if(ret){ + // 清空编号缓存 + for (SysMenu sysMenu : menuList) { + MenuUtil.refreshMenu( + WrapperUtil.transformInstance(sysMenu, MenuModel.class) + ); + } + + for (String id : ids) { + // 清空该菜单下 用户缓存 + List userIdList = iUserRoleRefService.getUserIdListByMenuId(id); + if(userIdList != null && !userIdList.isEmpty()){ + for (String userId : userIdList) { + // 清空当期用户缓存角色、权限、菜单 + UserUtil.refreshUserRoles(userId); + UserUtil.refreshUserAllPerms(userId); + UserUtil.refreshUserMenus(userId); + } + } + } + } + return ret; + } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java index d9627d7..21b8e0a 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/web/MenuRestController.java @@ -1,21 +1,52 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.menu.web; +import cn.hutool.core.lang.tree.Tree; +import cn.hutool.core.lang.tree.TreeNodeConfig; +import cn.hutool.core.lang.tree.TreeUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Maps; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.menu.MenuApi; import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.general.StartPrint; import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.menu.entity.SysMenu; import org.opsli.modulars.system.menu.service.IMenuService; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; /** @@ -29,7 +60,220 @@ import javax.servlet.http.HttpServletResponse; @ApiRestController("/sys/menu") public class MenuRestController extends BaseRestController implements MenuApi { + /** + * 根据 获得用户 菜单 - 权限 + * @return ResultVo + */ + @ApiOperation(value = "根据 获得用户 菜单 - 权限", notes = "根据 获得用户 菜单 - 权限") + @Override + public ResultVo getMenuAndPermsTree() { + // 菜单集合 + List menuModelList = null; + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + // 判断是否是超级管理员,如果是 则显示全部菜单 否则显示有权限菜单 + UserModel user = UserUtil.getUser(); + + // 获得全量数据 + if(UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + List menuList = IService.findList(queryBuilder.build()); + menuModelList = WrapperUtil.transformInstance(menuList, MenuModel.class); + }else { + List menuListByUserId = UserUtil.getMenuListByUserId(user.getId()); + if(menuListByUserId != null){ + // 这里有 ehcache的坑 需要深克隆再操作 + menuModelList = WrapperUtil.cloneTransformInstance(menuListByUserId + ,MenuModel.class); + } + + List perms = UserUtil.getUserAllPermsByUserId(user.getId()); + if(perms != null){ + QueryWrapper wrapper = queryBuilder.build(); + wrapper.in("menu_code", perms); + List sysMenus = IService.findList(wrapper); + List menuModels = WrapperUtil.transformInstance(sysMenus, MenuModel.class); + if(menuModelList != null){ + menuModelList.addAll(menuModels); + } + } + } + if(menuModelList == null){ + return ResultVo.error("菜单为空"); + } + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("order"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(4); + + //转换器 + List> treeNodes = TreeUtil.build(menuModelList, "0", treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getMenuName()); + // 扩展属性 ... + // 不是外链 则处理组件 + if(!"3".equals(treeNode.getType())){ + tree.putExtra("component", treeNode.getComponent()); + } + tree.putExtra("type", treeNode.getType()); + tree.putExtra("path", treeNode.getUrl()); + tree.putExtra("redirect", treeNode.getRedirect()); + // 处理 meta + Map metaMap = Maps.newHashMapWithExpectedSize(3); + metaMap.put("title", treeNode.getMenuName()); + metaMap.put("icon", treeNode.getIcon()); + // 外链处理 + if("3".equals(treeNode.getType())){ + metaMap.put("target", "_blank"); + metaMap.put("badge", "New"); + } + tree.putExtra("meta", metaMap); + }); + + return ResultVo.success(treeNodes); + } + + /** + * 当前登陆用户菜单 + * @return ResultVo + */ + @ApiOperation(value = "当前登陆用户菜单", notes = "当前登陆用户菜单") + @Override + public ResultVo findMenuTree() { + UserModel user = UserUtil.getUser(); + + // 获得用户 对应菜单 + List menuList = UserUtil.getMenuListByUserId(user.getId()); + + if(menuList == null){ + return ResultVo.error( + SystemMsg.EXCEPTION_USER_MENU_NOT_NULL.getCode(), + SystemMsg.EXCEPTION_USER_MENU_NOT_NULL.getMessage()); + } + + // 这里有坑 如果 为 菜单数据 且 组件(Component)地址为空 不会跳转到主页 也不报错 + // 修复菜单问题导致无法跳转主页 + menuList.removeIf(menuModel -> "1".equals(menuModel.getType()) && + (StringUtils.isEmpty(menuModel.getComponent()) || + StringUtils.isEmpty(menuModel.getMenuCode()) || + StringUtils.isEmpty(menuModel.getUrl()) + )); + + // 处理系统根路径外链 + for (MenuModel menuModel : menuList) { + if(StringUtils.isNotEmpty(menuModel.getUrl())){ + + } + } + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("order"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(4); + + //转换器 + List> treeNodes = TreeUtil.build(menuList, "0", treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getMenuCode()); + // 扩展属性 ... + // 不是外链 则处理组件 + if(!"3".equals(treeNode.getType())){ + tree.putExtra("component", treeNode.getComponent()); + }else{ + // 如果是外链 则判断是否存在 BASE_PATH + // 设置BASE_PATH + if(StringUtils.isNotEmpty(treeNode.getUrl())){ + treeNode.setUrl(treeNode.getUrl().replace("${BASE_PATH}", + StartPrint.INSTANCE.getBasePath() + )); + } + } + tree.putExtra("path", treeNode.getUrl()); + tree.putExtra("type", treeNode.getType()); + tree.putExtra("redirect", treeNode.getRedirect()); + // 处理 meta + Map metaMap = Maps.newHashMapWithExpectedSize(3); + metaMap.put("title", treeNode.getMenuName()); + metaMap.put("icon", treeNode.getIcon()); + // 外链处理 + if("3".equals(treeNode.getType())){ + metaMap.put("target", "_blank"); + } + tree.putExtra("meta", metaMap); + }); + + return ResultVo.success(treeNodes); + } + + /** + * 获得菜单树 + * @return ResultVo + */ + @ApiOperation(value = "获得菜单树", notes = "获得菜单树") + @RequiresPermissions("system_menu_select") + @Override + public ResultVo findMenuTreePage(HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysMenu.class, + request.getParameterMap()); + + // 获得用户 对应菜单 + List menuList = IService.findList(queryBuilder.build()); + + //配置 + TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); + // 自定义属性名 都要默认值的 + treeNodeConfig.setWeightKey("sortNo"); + treeNodeConfig.setNameKey("menuName"); + // 最大递归深度 最多支持4层菜单 + treeNodeConfig.setDeep(4); + + //转换器 + List> treeNodes = TreeUtil.build(menuList, "0", treeNodeConfig, + (treeNode, tree) -> { + tree.setId(treeNode.getId()); + tree.setParentId(treeNode.getParentId()); + tree.setWeight(treeNode.getSortNo()); + tree.setName(treeNode.getMenuName()); + // 扩展属性 ... + // 不是外链 则处理组件 + tree.putExtra("menuCode", treeNode.getMenuCode()); + tree.putExtra("component", treeNode.getComponent()); + tree.putExtra("type", treeNode.getType()); + tree.putExtra("url", treeNode.getUrl()); + tree.putExtra("redirect", treeNode.getRedirect()); + tree.putExtra("icon", treeNode.getIcon()); + tree.putExtra("hidden", treeNode.getHidden()); + tree.putExtra("version", treeNode.getVersion()); + }); + + return ResultVo.success(treeNodes); + } + + /** + * 获得菜单List + * @return ResultVo + */ + @ApiOperation(value = "获得菜单List", notes = "获得菜单List") + @RequiresPermissions("system_menu_select") + @Override + public ResultVo> findList() { + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + // 菜单集合 + List menuList = IService.findList(queryBuilder.build()); + List menuModelList = WrapperUtil.transformInstance(menuList, MenuModel.class); + return ResultVo.success(menuModelList); + } /** * 菜单 查一条 @@ -37,6 +281,7 @@ public class MenuRestController extends BaseRestController get(MenuModel model) { // 如果系统内部调用 则直接查数据库 @@ -54,6 +299,7 @@ public class MenuRestController extends BaseRestController findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { @@ -71,6 +317,8 @@ public class MenuRestController extends BaseRestController insert(MenuModel model) { // 调用新增方法 @@ -84,8 +332,13 @@ public class MenuRestController extends BaseRestController update(MenuModel model) { + // 演示模式 不允许操作 + super.demoError(); + // 调用修改方法 IService.update(model); return ResultVo.success("修改菜单成功"); @@ -98,8 +351,13 @@ public class MenuRestController extends BaseRestController del(String id){ + // 演示模式 不允许操作 + super.demoError(); + IService.delete(id); return ResultVo.success("删除菜单成功"); } @@ -111,8 +369,13 @@ public class MenuRestController extends BaseRestController delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + IService.deleteAll(ids); return ResultVo.success("批量删除菜单成功"); } @@ -125,6 +388,8 @@ public class MenuRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { QueryBuilder queryBuilder = new WebQueryBuilder<>(SysMenu.class, request.getParameterMap()); @@ -137,6 +402,8 @@ public class MenuRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { return super.excelImport(request); @@ -148,9 +415,27 @@ public class MenuRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(MenuApi.TITLE, response); } + + // ================== + + /** + * 根据菜单编号 获得菜单 + * @param menuCode 菜单编号 + * @return ResultVo + */ + @Override + public ResultVo getByCode(String menuCode) { + MenuModel menu = IService.getByCode(menuCode); + if(menu == null){ + ResultVo.error("暂无数据"); + } + return ResultVo.success(menu); + } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java index fcb9b0b..cc0e911 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRole.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.role.entity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.Data; import lombok.EqualsAndHashCode; @@ -28,6 +45,7 @@ public class SysRole extends BaseEntity { private Character izLock; /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String remark; @@ -37,4 +55,7 @@ public class SysRole extends BaseEntity { @TableLogic private Integer deleted; + /** 多租户字段 */ + private String tenantId; + } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRoleMenuRef.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRoleMenuRef.java new file mode 100644 index 0000000..dc44fca --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/entity/SysRoleMenuRef.java @@ -0,0 +1,46 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.role.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 角色表 - 菜单表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysRoleMenuRef implements Serializable { + + /** ID */ + @TableId + private String id; + + /** 角色ID */ + private String roleId; + + /** 菜单ID */ + private String menuId; + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java index 69a5672..83ddc5e 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMapper.java @@ -1,9 +1,27 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.role.mapper; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.opsli.modulars.system.role.entity.SysRole; + /** * @BelongsProject: opsli-boot * @BelongsPackage: org.opsli.modulars.test.mapper @@ -17,8 +35,9 @@ public interface RoleMapper extends BaseMapper { /** * 唯一验证 * @param entity + * @param wrapper * @return */ - Integer uniqueVerificationByCode(SysRole entity); + Integer uniqueVerificationByCode(@Param("entity") SysRole entity, @Param("ew") Wrapper wrapper); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMenuRefMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMenuRefMapper.java new file mode 100644 index 0000000..25f2bc5 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/RoleMenuRefMapper.java @@ -0,0 +1,42 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.role.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.system.menu.entity.SysMenu; +import org.opsli.modulars.system.role.entity.SysRoleMenuRef; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.mapper + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 角色 Mapper + */ +@Mapper +public interface RoleMenuRefMapper extends BaseMapper { + + /** + * 根据角色ID 获得权限(包含菜单) + * @param roleId + * @return + */ + List queryAllPerms(String roleId); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml index d519a69..91fc299 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMapper.xml @@ -22,17 +22,19 @@ - select count(0) from sys_role a - where - a.role_code = #{roleCode} + + ${ew.sqlSegment} + and a.role_code = #{entity.roleCode} and a.deleted = 0 - - AND a.id != #{id} + + and a.id != #{entity.id} + - \ No newline at end of file + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMenuRefMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMenuRefMapper.xml new file mode 100644 index 0000000..033a6b4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/mapper/xml/RoleMenuRefMapper.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleMenuRefService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleMenuRefService.java new file mode 100644 index 0000000..c7e0909 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleMenuRefService.java @@ -0,0 +1,46 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.role.service; + +import org.opsli.modulars.system.menu.entity.SysMenu; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 角色-菜单 接口 + */ +public interface IRoleMenuRefService { + + /** + * 根据角色ID 获得权限(包含菜单) + * @param roleId + * @return + */ + List getPerms(String roleId); + + /** + * 保存权限 + * @param roleId + * @param permsIds + * @return + */ + boolean setPerms(String roleId,String[] permsIds); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleService.java index 3294bab..39352c0 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/IRoleService.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.role.service; import org.opsli.api.wrapper.system.role.RoleModel; diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleMenuRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleMenuRefServiceImpl.java new file mode 100644 index 0000000..dc5fdd1 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleMenuRefServiceImpl.java @@ -0,0 +1,96 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.role.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.menu.entity.SysMenu; +import org.opsli.modulars.system.role.entity.SysRoleMenuRef; +import org.opsli.modulars.system.role.mapper.RoleMenuRefMapper; +import org.opsli.modulars.system.role.service.IRoleMenuRefService; +import org.opsli.modulars.system.user.service.IUserRoleRefService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 角色 接口实现类 + */ +@Service +public class RoleMenuRefServiceImpl extends ServiceImpl implements IRoleMenuRefService { + + @Autowired(required = false) + private RoleMenuRefMapper mapper; + @Autowired + private IUserRoleRefService iUserRoleRefService; + + @Override + public List getPerms(String roleId) { + return mapper.queryAllPerms(roleId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean setPerms(String roleId, String[] permsIds) { + if(StringUtils.isEmpty(roleId)){ + throw new ServiceException(SystemMsg.EXCEPTION_ROLE_ID_NOT_NULL); + } + + // 删除已有权限 + String roleIdField = "role_id"; + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(roleIdField, roleId); + super.remove(wrapper); + + if(permsIds != null && permsIds.length > 0){ + List list = Lists.newArrayListWithCapacity(permsIds.length); + for (String permsId : permsIds) { + SysRoleMenuRef entity = new SysRoleMenuRef(); + entity.setRoleId(roleId); + entity.setMenuId(permsId); + list.add(entity); + } + super.saveBatch(list); + } + + // 清空该角色下 用户缓存 + List userIdList = iUserRoleRefService.getUserIdListByRoleId(roleId); + if(userIdList != null && !userIdList.isEmpty()){ + for (String userId : userIdList) { + // 清空当期用户缓存角色、权限、菜单 + UserUtil.refreshUserRoles(userId); + UserUtil.refreshUserAllPerms(userId); + UserUtil.refreshUserMenus(userId); + } + } + + return true; + } +} + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java index 19f4fcf..6cdbf9e 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/service/impl/RoleServiceImpl.java @@ -1,8 +1,27 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.role.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.opsli.api.wrapper.system.role.RoleModel; import org.opsli.common.exception.ServiceException; import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.chain.TenantHandler; import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.role.entity.SysRole; import org.opsli.modulars.system.role.mapper.RoleMapper; @@ -26,12 +45,17 @@ public class RoleServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); + // 多租户处理 + TenantHandler tenantHandler = new TenantHandler(); + QueryWrapper qWrapper = tenantHandler.handler(entityClazz, queryBuilder.build()); + Integer count = mapper.uniqueVerificationByCode(entity,qWrapper); if(count != null && count > 0){ // 重复 throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE); @@ -40,14 +64,18 @@ public class RoleServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); + // 多租户处理 + TenantHandler tenantHandler = new TenantHandler(); + QueryWrapper qWrapper = tenantHandler.handler(entityClazz, queryBuilder.build()); + Integer count = mapper.uniqueVerificationByCode(entity,qWrapper); if(count != null && count > 0){ // 重复 throw new ServiceException(SystemMsg.EXCEPTION_ROLE_UNIQUE); @@ -56,6 +84,7 @@ public class RoleServiceImpl extends CrudServiceImpl + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.role.web; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.role.RoleMenuRefApi; +import org.opsli.api.wrapper.system.role.RoleMenuRefModel; +import org.opsli.api.wrapper.system.role.RoleModel; +import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.menu.entity.SysMenu; +import org.opsli.modulars.system.role.service.IRoleMenuRefService; +import org.opsli.modulars.system.role.service.IRoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 角色 + */ +@Slf4j +@ApiRestController("/sys/role/perms") +public class RoleMenuRefRestController implements RoleMenuRefApi { + + /** 内置数据 */ + private static final char LOCK_DATA = '1'; + + @Value("${opsli.enable-demo}") + private boolean enableDemo; + + @Autowired + private IRoleService iRoleService; + @Autowired + private IRoleMenuRefService iRoleMenuRefService; + + /** + * 获得当前已有权限 + * @param model roleId 角色Id + * @return ResultVo + */ + @RequiresPermissions("system_role_setPerms") + @EnableLog + @Override + public ResultVo getPerms(RoleMenuRefModel model) { + if(model == null){ + return ResultVo.error(SystemMsg.EXCEPTION_ROLE_ID_NOT_NULL.getCode(), + SystemMsg.EXCEPTION_ROLE_ID_NOT_NULL.getMessage()); + } + + List perms = iRoleMenuRefService.getPerms(model.getRoleId()); + List permsIds = Lists.newArrayListWithCapacity(perms.size()); + if(!perms.isEmpty()){ + for (SysMenu perm : perms) { + permsIds.add(perm.getId()); + } + + // 按照parentId分组 + Map> groupMap = perms.stream() + .collect(Collectors.groupingBy(SysMenu::getParentId)); + + // 获得分组key 根据分组key 删除分组父ID + for (String key : groupMap.keySet()) { + permsIds.remove(key); + } + } + + return ResultVo.success(permsIds); + } + + /** + * 设置权限 + * @param model roleId 角色Id + * @param model permsIds 权限Id 数组 + * @return ResultVo + */ + @RequiresPermissions("system_role_setPerms") + @EnableLog + @Override + public ResultVo setPerms(RoleMenuRefModel model) { + // 演示模式 不允许操作 + this.demoError(); + + if(model == null) return ResultVo.error("设置权限失败"); + + RoleModel roleModel = iRoleService.get(model.getRoleId()); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == roleModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + + + boolean ret = iRoleMenuRefService.setPerms(model.getRoleId(), + model.getPermsIds()); + if(ret){ + return ResultVo.success(); + } + // 权限设置失败 + return ResultVo.error(SystemMsg.EXCEPTION_ROLE_PERMS_ERROR.getCode(), + SystemMsg.EXCEPTION_ROLE_PERMS_ERROR.getMessage() + ); + } + + + /** + * 演示模式 + */ + private void demoError(){ + UserModel user = UserUtil.getUser(); + // 演示模式 不允许操作 (超级管理员可以操作) + if(enableDemo && !UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO); + } + } + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/web/RoleRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/web/RoleRestController.java index 2b27589..afc5078 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/web/RoleRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/role/web/RoleRestController.java @@ -1,21 +1,47 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.role.web; +import cn.hutool.core.convert.Convert; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.role.RoleApi; import org.opsli.api.wrapper.system.role.RoleModel; +import org.opsli.api.wrapper.system.user.UserModel; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.constants.MyBatisConstants; +import org.opsli.common.exception.ServiceException; import org.opsli.core.base.concroller.BaseRestController; import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.role.entity.SysRole; import org.opsli.modulars.system.role.service.IRoleService; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.List; /** @@ -30,6 +56,8 @@ import javax.servlet.http.HttpServletResponse; public class RoleRestController extends BaseRestController implements RoleApi { + /** 内置数据 */ + private static final char LOCK_DATA = '1'; /** * 角色 查一条 @@ -37,6 +65,7 @@ public class RoleRestController extends BaseRestController get(RoleModel model) { // 如果系统内部调用 则直接查数据库 @@ -54,6 +83,7 @@ public class RoleRestController extends BaseRestController findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { @@ -71,6 +101,8 @@ public class RoleRestController extends BaseRestController insert(RoleModel model) { // 调用新增方法 @@ -84,8 +116,25 @@ public class RoleRestController extends BaseRestController update(RoleModel model) { + // 演示模式 不允许操作 + super.demoError(); + + if(model != null){ + RoleModel roleModel = IService.get(model.getId()); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == roleModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + // 调用修改方法 IService.update(model); return ResultVo.success("修改角色成功"); @@ -98,8 +147,22 @@ public class RoleRestController extends BaseRestController del(String id){ + // 演示模式 不允许操作 + super.demoError(); + + RoleModel roleModel = IService.get(id); + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == roleModel.getIzLock() ){ + UserModel user = UserUtil.getUser(); + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + IService.delete(id); return ResultVo.success("删除角色成功"); } @@ -111,8 +174,31 @@ public class RoleRestController extends BaseRestController delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + + if(ids != null){ + QueryBuilder queryBuilder = new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + List idList = Convert.toList(String.class,ids); + + wrapper.in(MyBatisConstants.FIELD_ID, idList); + List roleList = IService.findList(wrapper); + for (SysRole sysRole : roleList) { + // 内置数据 只有超级管理员可以修改 + if(LOCK_DATA == sysRole.getIzLock() ){ + UserModel user = UserUtil.getUser(); + if(!UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(SystemMsg.EXCEPTION_LOCK_DATA); + } + } + } + } + IService.deleteAll(ids); return ResultVo.success("批量删除角色成功"); } @@ -125,6 +211,8 @@ public class RoleRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { QueryBuilder queryBuilder = new WebQueryBuilder<>(SysRole.class, request.getParameterMap()); @@ -137,6 +225,8 @@ public class RoleRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { return super.excelImport(request); @@ -148,6 +238,8 @@ public class RoleRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(RoleApi.TITLE, response); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/api/README.md b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/api/README.md new file mode 100644 index 0000000..f2f9594 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/api/README.md @@ -0,0 +1 @@ +## 改造微服务时 将Feign 接口写在这里 \ No newline at end of file diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/entity/SysTenant.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/entity/SysTenant.java new file mode 100644 index 0000000..54377f2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/entity/SysTenant.java @@ -0,0 +1,54 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.tenant.entity; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 租户表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysTenant extends BaseEntity { + + + /** 租户名称 */ + private String tenantName; + + /** 是否启用 0是 1否*/ + private Character izUsable; + + /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String remark; + + + // ======================================== + + /** 逻辑删除字段 */ + @TableLogic + private Integer deleted; + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/TenantMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/TenantMapper.java new file mode 100644 index 0000000..ee8076b --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/TenantMapper.java @@ -0,0 +1,41 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.tenant.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.opsli.modulars.system.tenant.entity.SysTenant; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.mapper + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 租户 Mapper + */ +@Mapper +public interface TenantMapper extends BaseMapper { + + /** + * 唯一验证 + * @param entity + * @return + */ + Integer uniqueVerificationByName(SysTenant entity); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/xml/TenantMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/xml/TenantMapper.xml new file mode 100644 index 0000000..88048ce --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/mapper/xml/TenantMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java new file mode 100644 index 0000000..3b58a95 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/ITenantService.java @@ -0,0 +1,33 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.tenant.service; + +import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.system.tenant.entity.SysTenant; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.system.service + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 租户 接口 + */ +public interface ITenantService extends CrudServiceInterface { + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java new file mode 100644 index 0000000..20bfd2f --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/service/impl/TenantServiceImpl.java @@ -0,0 +1,78 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.tenant.service.impl; + +import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.tenant.entity.SysTenant; +import org.opsli.modulars.system.tenant.mapper.TenantMapper; +import org.opsli.modulars.system.tenant.service.ITenantService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.system.service + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 租户 接口实现类 + */ +@Service +public class TenantServiceImpl extends CrudServiceImpl implements ITenantService { + + @Autowired(required = false) + private TenantMapper mapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public TenantModel insert(TenantModel model) { + if(model == null) return null; + + SysTenant entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_TENANT_UNIQUE); + } + + return super.insert(model); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TenantModel update(TenantModel model) { + if(model == null) return null; + + SysTenant entity = super.transformM2T(model); + // 唯一验证 + Integer count = mapper.uniqueVerificationByName(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_TENANT_UNIQUE); + } + + return super.update(model); + } + + +} + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java new file mode 100644 index 0000000..e428773 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/tenant/web/TenantRestController.java @@ -0,0 +1,198 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.tenant.web; + +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.role.RoleApi; +import org.opsli.api.web.system.tenant.TenantApi; +import org.opsli.api.wrapper.system.tenant.TenantModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.system.tenant.entity.SysTenant; +import org.opsli.modulars.system.tenant.service.ITenantService; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.system.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 租户 + */ +@Slf4j +@ApiRestController("/sys/tenant") +public class TenantRestController extends BaseRestController + implements TenantApi { + + + /** + * 租户 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条租户", notes = "获得单条租户 - ID") + @RequiresPermissions("system_tenant_select") + @Override + public ResultVo get(TenantModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 租户 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @RequiresPermissions("system_tenant_select") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysTenant.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + /** + * 租户 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增租户", notes = "新增租户") + @RequiresPermissions("system_tenant_insert") + @EnableLog + @Override + public ResultVo insert(TenantModel model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增租户成功"); + } + + /** + * 租户 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改租户", notes = "修改租户") + @RequiresPermissions("system_tenant_update") + @EnableLog + @Override + public ResultVo update(TenantModel model) { + // 演示模式 不允许操作 + super.demoError(); + + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改租户成功"); + } + + + /** + * 租户 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除租户数据", notes = "删除租户数据") + @RequiresPermissions("system_tenant_delete") + @EnableLog + @Override + public ResultVo del(String id){ + // 演示模式 不允许操作 + super.demoError(); + + IService.delete(id); + return ResultVo.success("删除租户成功"); + } + + + /** + * 租户 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除租户数据", notes = "批量删除租户数据") + @RequiresPermissions("system_tenant_delete") + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + + IService.deleteAll(ids); + return ResultVo.success("批量删除租户成功"); + } + + + /** + * 租户 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissions("system_tenant_export") + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder queryBuilder = new WebQueryBuilder<>(SysTenant.class, request.getParameterMap()); + return super.excelExport(RoleApi.TITLE, queryBuilder.build(), response); + } + + /** + * 租户 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("system_tenant_import") + @EnableLog + @Override + public ResultVo excelImport(MultipartHttpServletRequest request) { + return super.excelImport(request); + } + + /** + * 租户 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissions("system_tenant_import") + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(RoleApi.TITLE, response); + } + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUser.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUser.java index 22edc55..5f9362c 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUser.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUser.java @@ -1,5 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.user.entity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.Data; import lombok.EqualsAndHashCode; @@ -33,9 +50,11 @@ public class SysUser extends BaseEntity { private String realName; /** 手机 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String mobile; /** 邮箱 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String email; /** 工号 */ @@ -48,8 +67,13 @@ public class SysUser extends BaseEntity { private String loginIp; /** 备注 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private String remark; + /** 签名 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String sign; + // ======================================== /** 逻辑删除字段 */ diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserRoleRef.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserRoleRef.java new file mode 100644 index 0000000..05ee04d --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUserRoleRef.java @@ -0,0 +1,46 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.user.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.entity + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 用户表 - 角色表 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class SysUserRoleRef implements Serializable { + + /** ID */ + @TableId + private String id; + + /** 用户ID */ + private String userId; + + /** 角色ID */ + private String roleId; + + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java index 7299a45..ddb6b56 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserMapper.java @@ -1,7 +1,24 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.user.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.opsli.api.wrapper.system.user.UserPassword; import org.opsli.modulars.system.menu.entity.SysMenu; import org.opsli.modulars.system.user.entity.SysUser; @@ -18,12 +35,19 @@ import java.util.List; public interface UserMapper extends BaseMapper { /** - * 唯一验证 + * 唯一验证 - 用户名 * @param entity * @return */ Integer uniqueVerificationByUsername(SysUser entity); + /** + * 唯一验证 - 工号 + * @param entity + * @return + */ + Integer uniqueVerificationByNo(SysUser entity); + /** * 根据用户ID 获得当前角色编码集合 @@ -32,6 +56,13 @@ public interface UserMapper extends BaseMapper { */ List getRoleCodeList(String userId); + /** + * 根据用户ID 获得当前角色Id集合 + * @param userId + * @return + */ + List getRoleIdList(String userId); + /** * 根据用户ID 获得权限 * @param userId @@ -45,4 +76,25 @@ public interface UserMapper extends BaseMapper { * @return */ List findMenuListByUserId(String userId); + + /** + * 修改密码 + * @param userPassword + * @return + */ + boolean updatePassword(UserPassword userPassword); + + /** + * 更新用户最后登录IP + * @param entity + * @return + */ + boolean updateLoginIp(SysUser entity); + + /** + * 更新用户头像 + * @param entity + * @return + */ + boolean updateAvatar(SysUser entity); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserRoleRefMapper.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserRoleRefMapper.java new file mode 100644 index 0000000..4711646 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/UserRoleRefMapper.java @@ -0,0 +1,47 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.user.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.system.user.entity.SysUserRoleRef; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.mapper + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 用户角色 Mapper + */ +@Mapper +public interface UserRoleRefMapper extends BaseMapper { + + /** + * 根据角色ID 获得当前用户Id集合 + * @param roleId + * @return + */ + List getUserIdListByRoleId(String roleId); + + /** + * 根据菜单ID 获得当前用户Id集合 + * @param menuId + * @return + */ + List getUserIdListByMenuId(String menuId); +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml index 35526e4..5018250 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserMapper.xml @@ -44,6 +44,19 @@ + + + + select c.id, - c.icon, + c.parent_Id, + c.menu_code, c.menu_name, + c.redirect, + c.type, + c.icon, c.url, - c.parent_Id + c.component, + c.sort_no from sys_user_role_ref a, sys_role_menu_ref b, @@ -87,8 +116,32 @@ and b.menu_id = c.id and c.parent_id != -1 and a.user_id = #{userId} - and c.type = '1' - order by c.id + + and c.type in ( '1', '3' ) + and c.deleted = '0' + and c.hidden = '0' - \ No newline at end of file + + update sys_user + set + password = #{newPassword}, + secret_key = #{salt} + where id = #{userId} + + + + update sys_user + set + login_ip = #{loginIp} + where id = #{id} + + + + update sys_user + set + avatar = #{avatar} + where id = #{id} + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserRoleRefMapper.xml b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserRoleRefMapper.xml new file mode 100644 index 0000000..9b98b0e --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/mapper/xml/UserRoleRefMapper.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserRoleRefService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserRoleRefService.java new file mode 100644 index 0000000..c62aad4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserRoleRefService.java @@ -0,0 +1,51 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.user.service; + +import java.util.List; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 用户-角色 接口 + */ +public interface IUserRoleRefService { + + /** + * 根据角色ID 获得当前用户Id集合 + * @param roleId + * @return + */ + List getUserIdListByRoleId(String roleId); + + /** + * 根据菜单ID 获得当前用户Id集合 + * @param roleId + * @return + */ + List getUserIdListByMenuId(String roleId); + + /** + * 保存角色 + * @param userId + * @param roleIds + * @return + */ + boolean setRoles(String userId,String[] roleIds); + +} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java index 75e31e5..7dde8d3 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java @@ -1,7 +1,23 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.user.service; import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserPassword; import org.opsli.core.base.service.interfaces.CrudServiceInterface; import org.opsli.modulars.system.user.entity.SysUser; @@ -31,6 +47,13 @@ public interface IUserService extends CrudServiceInterface { */ List getRoleCodeList(String userId); + /** + * 根据用户ID 获得当前角色Id集合 + * @param userId + * @return + */ + List getRoleIdList(String userId); + /** * 根据用户ID 获得权限 * @param userId @@ -45,4 +68,27 @@ public interface IUserService extends CrudServiceInterface { */ List getMenuListByUserId(String userId); + + /** + * 修改密码 + * @param userPassword + * @return + */ + boolean updatePassword(UserPassword userPassword); + + + /** + * 更新用户最后登录IP + * @param model + * @return + */ + boolean updateLoginIp(UserModel model); + + + /** + * 更新用户头像 + * @param model + * @return + */ + boolean updateAvatar(UserModel model); } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java new file mode 100644 index 0000000..63d51a3 --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserRoleRefServiceImpl.java @@ -0,0 +1,97 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.user.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.user.entity.SysUserRoleRef; +import org.opsli.modulars.system.user.mapper.UserRoleRefMapper; +import org.opsli.modulars.system.user.service.IUserRoleRefService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.service + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 角色 接口实现类 + */ +@Service +public class UserRoleRefServiceImpl extends ServiceImpl implements IUserRoleRefService { + + @Autowired(required = false) + private UserRoleRefMapper mapper; + + @Override + public List getUserIdListByRoleId(String roleId) { + List users = mapper.getUserIdListByRoleId(roleId); + // 去重 + return new ArrayList<>(new LinkedHashSet<>(users)); + } + + @Override + public List getUserIdListByMenuId(String roleId) { + List users = mapper.getUserIdListByMenuId(roleId); + // 去重 + return new ArrayList<>(new LinkedHashSet<>(users)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean setRoles(String userId, String[] roleIds) { + if(StringUtils.isEmpty(userId)){ + throw new ServiceException(SystemMsg.EXCEPTION_USER_ID_NOT_NULL); + } + + // 删除已有权限 + String userIdField = "user_id"; + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(userIdField, userId); + super.remove(wrapper); + + if(roleIds != null && roleIds.length > 0){ + List list = Lists.newArrayListWithCapacity(roleIds.length); + for (String roleId : roleIds) { + SysUserRoleRef entity = new SysUserRoleRef(); + entity.setUserId(userId); + entity.setRoleId(roleId); + list.add(entity); + } + super.saveBatch(list); + } + + // 清空当期用户缓存角色、权限、菜单 + UserUtil.refreshUserRoles(userId); + UserUtil.refreshUserAllPerms(userId); + UserUtil.refreshUserMenus(userId); + + return true; + } +} + + diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java index e9fe08e..0d1c819 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java @@ -1,12 +1,32 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.user.service.impl; +import cn.hutool.core.util.RandomUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserPassword; +import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.exception.ServiceException; import org.opsli.common.utils.HumpUtil; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.persistence.Page; import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.utils.UserUtil; @@ -19,6 +39,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; @@ -36,6 +58,7 @@ public class UserServiceImpl extends CrudServiceImpl 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_USER_NO_UNIQUE); + } + + // 防止非法操作 - 不允许直接操控到 关键数据 + // 需要注意的是 不要轻易改修改策略 + model.setLoginIp(null); + + // 新增可以直接设置密码 + if(StringUtils.isNotEmpty(model.getPassword())){ + // 设置随机新盐值 + model.setSecretkey( + RandomUtil.randomString(20) + ); + // 处理密码 + model.setPassword( + UserUtil.handlePassword(model.getPassword(), + model.getSecretkey()) + ); + } return super.insert(model); } - @Transactional(rollbackFor = Exception.class) @Override + @Transactional(rollbackFor = Exception.class) public UserModel update(UserModel model) { if(model == null) return null; SysUser entity = super.transformM2T(model); - // 唯一验证 + // 唯一验证 - 用户名 Integer count = mapper.uniqueVerificationByUsername(entity); if(count != null && count > 0){ // 重复 throw new ServiceException(SystemMsg.EXCEPTION_USER_UNIQUE); } + // 唯一验证 - 工号 + count = mapper.uniqueVerificationByNo(entity); + if(count != null && count > 0){ + // 重复 + throw new ServiceException(SystemMsg.EXCEPTION_USER_NO_UNIQUE); + } + + // 防止非法操作 - 不允许直接操控到 关键数据 + // 需要注意的是 不要轻易改修改策略 + model.setUsername(null); + model.setPassword(null); + model.setSecretkey(null); + model.setLoginIp(null); UserModel update = super.update(model); if(update != null){ @@ -84,12 +143,23 @@ public class UserServiceImpl extends CrudServiceImpl getRoleCodeList(String userId) { - return mapper.getRoleCodeList(userId); + List roles = mapper.getRoleCodeList(userId); + // 去重 + return new ArrayList<>(new LinkedHashSet<>(roles)); + } + + @Override + public List getRoleIdList(String userId) { + List roles = mapper.getRoleIdList(userId); + // 去重 + return new ArrayList<>(new LinkedHashSet<>(roles)); } @Override public List getAllPerms(String userId) { - return mapper.queryAllPerms(userId); + List perms = mapper.queryAllPerms(userId); + // 去重 + return new ArrayList<>(new LinkedHashSet<>(perms)); } @Override @@ -97,6 +167,92 @@ public class UserServiceImpl extends CrudServiceImpl menuList = mapper.findMenuListByUserId(userId); return WrapperUtil.transformInstance(menuList, MenuModel.class); } + + @Override + public Page findPage(Page page) { + UserModel currUser = UserUtil.getUser(); + // 如果不是超级管理员则 无法看到超级管理员账户 + if(!UserUtil.SUPER_ADMIN.equals(currUser.getUsername())){ + QueryWrapper queryWrapper = page.getQueryWrapper(); + queryWrapper.notIn("username", UserUtil.SUPER_ADMIN); + page.setQueryWrapper(queryWrapper); + } + return super.findPage(page); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updatePassword(UserPassword userPassword) { + UserModel userModel = super.get(userPassword.getUserId()); + // 如果为空则 不修改密码 + if(userModel == null){ + return false; + } + // 获得 处理后 老密码 + String orlPassword = UserUtil.handlePassword(userPassword.getOldPassword(), + userModel.getSecretkey()); + + // 判断老密码是否正确 + if(!userModel.getPassword().equals(orlPassword)){ + throw new ServiceException(SystemMsg.EXCEPTION_USER_PASSWORD_ERROR); + } + + // 设置随机新盐值 + userPassword.setSalt( + RandomUtil.randomString(20) + ); + // 处理密码 + userPassword.setNewPassword( + UserUtil.handlePassword(userPassword.getNewPassword(), + userPassword.getSalt()) + ); + + // 修改密码 + boolean ret = mapper.updatePassword(userPassword); + + if(ret){ + // 刷新用户缓存 + UserUtil.refreshUser(userModel); + } + + return ret; + } + + /** + * 更新用户最后登录IP + * @param model + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateLoginIp(UserModel model) { + if(model == null){ + return false; + } + + SysUser sysUser = new SysUser(); + sysUser.setId(model.getId()); + sysUser.setLoginIp(model.getLoginIp()); + return mapper.updateLoginIp(sysUser); + } + + /** + * 更新用户头像 + * @param model + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateAvatar(UserModel model) { + if(model == null){ + return false; + } + + SysUser sysUser = new SysUser(); + sysUser.setId(model.getId()); + sysUser.setAvatar(model.getAvatar()); + return mapper.updateAvatar(sysUser); + } } diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java index 09fc56d..b3411a3 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java @@ -1,22 +1,58 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.modulars.system.user.web; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.RandomUtil; +import com.alibaba.excel.util.CollectionUtils; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.user.UserApi; import org.opsli.api.wrapper.system.menu.MenuModel; +import org.opsli.api.wrapper.system.user.UserInfo; import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserPassword; import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.exception.TokenException; +import org.opsli.common.utils.IPUtil; +import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.msg.TokenMsg; import org.opsli.core.persistence.Page; import org.opsli.core.persistence.querybuilder.QueryBuilder; import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.user.entity.SysUser; import org.opsli.modulars.system.user.service.IUserService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.util.Iterator; import java.util.List; @@ -32,6 +68,153 @@ import java.util.List; public class UserRestController extends BaseRestController implements UserApi { + @Value("${opsli.web.upload-path}") + private String basedir; + + + /** + * 当前登陆用户信息 + * @return ResultVo + */ + @ApiOperation(value = "当前登陆用户信息", notes = "当前登陆用户信息") + @Override + public ResultVo getInfo(HttpServletRequest request) { + UserModel user = UserUtil.getUser(); + + // 保存用户最后登录IP + String clientIpAddress = IPUtil.getClientIpAddress(request); + user.setLoginIp(clientIpAddress); + IService.updateLoginIp(user); + UserUtil.refreshUser(user); + + return this.getInfoById(user.getId()); + } + + /** + * 当前登陆用户信息 By Id + * @return ResultVo + */ + @ApiOperation(value = "当前登陆用户信息 By Id", notes = "当前登陆用户信息 By Id") + @Override + public ResultVo getInfoById(String userId) { + UserModel user = UserUtil.getUser(userId); + if(user == null){ + throw new TokenException(TokenMsg.EXCEPTION_TOKEN_LOSE_EFFICACY); + } + + // 个人信息 清除敏感信息 + user.setPassword(null); + List userRolesByUserId = UserUtil.getUserRolesByUserId(user.getId()); + List userAllPermsByUserId = UserUtil.getUserAllPermsByUserId(user.getId()); + UserInfo userInfo = WrapperUtil.transformInstance(user, UserInfo.class); + userInfo.setRoles(userRolesByUserId); + userInfo.setPerms(userAllPermsByUserId); + + // 判断是否是超级管理员 + if(UserUtil.SUPER_ADMIN.equals(userInfo.getUsername())){ + userInfo.setIzSuperAdmin(true); + } + + return ResultVo.success(userInfo); + } + + + /** + * 根据 userId 获得用户角色Id集合 + * @param userId 用户Id + * @return ResultVo + */ + @ApiOperation(value = "根据 userId 获得用户角色Id集合", notes = "根据 userId 获得用户角色Id集合") + @Override + public ResultVo> getRoleIdsByUserId(String userId) { + List roleIdList = IService.getRoleIdList(userId); + return ResultVo.success(roleIdList); + } + + + + /** + * 修改密码 + * @return ResultVo + */ + @ApiOperation(value = "修改密码", notes = "修改密码") + @Override + public ResultVo updatePassword(UserPassword userPassword) { + // 演示模式 不允许操作 + super.demoError(); + + UserModel user = UserUtil.getUser(); + userPassword.setUserId(user.getId()); + IService.updatePassword(userPassword); + return ResultVo.success(); + } + + /** + * 上传头像 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "上传头像", notes = "上传头像") + @Override + public ResultVo updateAvatar(MultipartHttpServletRequest request) { + Iterator itr = request.getFileNames(); + String uploadedFile = itr.next(); + List files = request.getFiles(uploadedFile); + if (CollectionUtils.isEmpty(files)) { + // 请选择文件 + return ResultVo.error(CoreMsg.EXCEL_FILE_NULL.getCode(), + CoreMsg.EXCEL_FILE_NULL.getMessage()); + } + + try { + String staticPath = "/static/file"; + UserModel user = UserUtil.getUser(); + + String date = DateUtil.format(DateUtil.date(), "yyyyMMdd"); + String dateTime = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"); + String packageName = basedir + staticPath+"/"+date; + String fileName = dateTime+"-"+ RandomUtil.simpleUUID() +".jpg"; + File file = new File(packageName+"/"+fileName); + MultipartFile multipartFile = files.get(0); + FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file); + FileUtil.mkdir(packageName); + FileUtil.touch(file); + + // 更新头像至数据库 + UserModel userModel = new UserModel(); + userModel.setId(user.getId()); + userModel.setAvatar(staticPath + "/" +date+"/"+fileName); + IService.updateAvatar(userModel); + // 刷新用户信息 + UserUtil.refreshUser(user); + }catch (IOException e){ + log.error(e.getMessage(), e); + return ResultVo.error("更新头像失败,请稍后再试"); + } + + return ResultVo.success(); + } + + // ================================================== + + + /** + * 修改密码 + * @return ResultVo + */ + @ApiOperation(value = "修改密码", notes = "修改密码") + @RequiresPermissions("system_user_updatePassword") + @EnableLog + @Override + public ResultVo updatePasswordById(UserPassword userPassword) { + // 演示模式 不允许操作 + super.demoError(); + + IService.updatePassword(userPassword); + return ResultVo.success(); + } + + /** * 用户信息 查一条 @@ -39,6 +222,8 @@ public class UserRestController extends BaseRestController get(UserModel model) { // 如果系统内部调用 则直接查数据库 @@ -56,6 +241,7 @@ public class UserRestController extends BaseRestController findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { @@ -63,7 +249,11 @@ public class UserRestController extends BaseRestController page = new Page<>(pageNo, pageSize); page.setQueryWrapper(queryBuilder.build()); page = IService.findPage(page); - + // 密码防止分页泄露处理 + for (UserModel userModel : page.getList()) { + userModel.setSecretkey(null); + userModel.setPassword(null); + } return ResultVo.success(page.getBootstrapData()); } @@ -73,6 +263,8 @@ public class UserRestController extends BaseRestController insert(UserModel model) { // 调用新增方法 @@ -86,8 +278,13 @@ public class UserRestController extends BaseRestController update(UserModel model) { + // 演示模式 不允许操作 + super.demoError(); + // 调用修改方法 IService.update(model); return ResultVo.success("修改用户信息成功"); @@ -100,8 +297,13 @@ public class UserRestController extends BaseRestController del(String id){ + // 演示模式 不允许操作 + super.demoError(); + IService.delete(id); return ResultVo.success("删除用户信息成功"); } @@ -113,8 +315,13 @@ public class UserRestController extends BaseRestController delAll(String[] ids){ + // 演示模式 不允许操作 + super.demoError(); + IService.deleteAll(ids); return ResultVo.success("批量删除用户信息成功"); } @@ -127,6 +334,8 @@ public class UserRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { QueryBuilder queryBuilder = new WebQueryBuilder<>(SysUser.class, request.getParameterMap()); @@ -139,6 +348,8 @@ public class UserRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { return super.excelImport(request); @@ -150,6 +361,7 @@ public class UserRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(UserApi.TITLE, response); diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRoleRefRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRoleRefRestController.java new file mode 100644 index 0000000..bd83d6c --- /dev/null +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRoleRefRestController.java @@ -0,0 +1,86 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.system.user.web; + +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.user.UserRoleRefApi; +import org.opsli.api.wrapper.system.user.UserModel; +import org.opsli.api.wrapper.system.user.UserRoleRefModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.exception.ServiceException; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.utils.UserUtil; +import org.opsli.modulars.system.SystemMsg; +import org.opsli.modulars.system.user.service.IUserRoleRefService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 角色 + */ +@Slf4j +@ApiRestController("/sys/user/roles") +public class UserRoleRefRestController implements UserRoleRefApi { + + @Value("${opsli.enable-demo}") + private boolean enableDemo; + + @Autowired + private IUserRoleRefService iUserRoleRefService; + + + /** + * 设置角色 + * @param model userId 用户Id + * @param model roleIds 角色Id 数组 + * @return ResultVo + */ + @Override + @RequiresPermissions("system_user_setRole") + public ResultVo setRoles(UserRoleRefModel model) { + // 演示模式 不允许操作 + this.demoError(); + + boolean ret = iUserRoleRefService.setRoles(model.getUserId(), + model.getRoleIds()); + if(ret){ + return ResultVo.success(); + } + // 权限设置失败 + return ResultVo.error(SystemMsg.EXCEPTION_USER_ROLES_ERROR.getCode(), + SystemMsg.EXCEPTION_USER_ROLES_ERROR.getMessage() + ); + } + + + /** + * 演示模式 + */ + private void demoError(){ + UserModel user = UserUtil.getUser(); + // 演示模式 不允许操作 (超级管理员可以操作) + if(enableDemo && !UserUtil.SUPER_ADMIN.equals(user.getUsername())){ + throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO); + } + } +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java new file mode 100644 index 0000000..65df2a8 --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java @@ -0,0 +1,173 @@ +package org.opsli.modulars.test.web; + +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.api.web.system.role.RoleApi; +import org.opsli.api.web.test.TestRestApi; +import org.opsli.api.wrapper.test.TestModel; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.test.entity.TestEntity; +import org.opsli.modulars.test.service.ITestService; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 测试类 + */ +@Slf4j +@ApiRestController("/test") +public class TestRestController extends BaseRestController + implements TestRestApi { + + /** + * 测试 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条测试", notes = "获得单条测试 - ID") + @RequiresPermissions("modules_test_select") + @Override + public ResultVo get(TestModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 测试 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(TestEntity.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + /** + * 测试 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增测试", notes = "新增测试") + @RequiresPermissions("modules_test_insert") + @EnableLog + @Override + public ResultVo insert(TestModel model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增测试成功"); + } + + /** + * 测试 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改测试", notes = "修改测试") + @RequiresPermissions("modules_test_update") + @EnableLog + @Override + public ResultVo update(TestModel model) { + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改测试成功"); + } + + + /** + * 测试 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除测试数据", notes = "删除测试数据") + @RequiresPermissions("modules_test_delete") + @EnableLog + @Override + public ResultVo del(String id){ + IService.delete(id); + return ResultVo.success("删除测试成功"); + } + + + /** + * 测试 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除测试数据", notes = "批量删除测试数据") + @RequiresPermissions("modules_test_delete") + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + IService.deleteAll(ids); + return ResultVo.success("批量删除测试成功"); + } + + + /** + * 测试 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissions("modules_test_export") + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder queryBuilder = new WebQueryBuilder<>(TestEntity.class, request.getParameterMap()); + return super.excelExport(RoleApi.TITLE, queryBuilder.build(), response); + } + + /** + * 测试 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("modules_test_import") + @EnableLog + @Override + public ResultVo excelImport(MultipartHttpServletRequest request) { + return super.excelImport(request); + } + + /** + * 测试 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissions("modules_test_import") + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(RoleApi.TITLE, response); + } + + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController.java index dd2c6d7..d306e0b 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController.java @@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit; * @Description: 测试类 */ @Slf4j -@ApiRestController("/test") +//@ApiRestController("/test") public class TestRestRestController extends BaseRestController implements TestApi { diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController2.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController2.java index 3765c21..ecc73c4 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController2.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestRestController2.java @@ -22,7 +22,7 @@ import java.util.List; * @CreateTime: 2020-09-13 17:40 * @Description: 测试类 */ -@ApiRestController("/test2") +//@ApiRestController("/test2") public class TestRestRestController2{ @Autowired diff --git a/opsli-modulars/pom.xml b/opsli-modulars/pom.xml index bc5fc8c..4670d7e 100644 --- a/opsli-modulars/pom.xml +++ b/opsli-modulars/pom.xml @@ -18,6 +18,7 @@ opsli-modulars-test opsli-modulars-system + opsli-modulars-creater @@ -50,4 +51,4 @@ - \ No newline at end of file + diff --git a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/EhCachePlugin.java b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/EhCachePlugin.java index 5866631..30899e4 100644 --- a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/EhCachePlugin.java +++ b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/EhCachePlugin.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.cache; /** diff --git a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/conf/EhCacheConfig.java b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/conf/EhCacheConfig.java index 1b21434..d3e5b48 100644 --- a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/conf/EhCacheConfig.java +++ b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/conf/EhCacheConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.cache.conf; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -17,4 +32,4 @@ import org.springframework.context.annotation.Configuration; public class EhCacheConfig { -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/msg/EhCacheMsg.java b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/msg/EhCacheMsg.java index 2fd7f94..0735d50 100644 --- a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/msg/EhCacheMsg.java +++ b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/msg/EhCacheMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.cache.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/service/EhCachePluginImpl.java b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/service/EhCachePluginImpl.java index 60e3f3d..d20f274 100644 --- a/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/service/EhCachePluginImpl.java +++ b/opsli-plugins/opsli-plugins-ehcache/src/main/java/org/opsli/plugins/cache/service/EhCachePluginImpl.java @@ -1,6 +1,23 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.cache.service; +import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; +import org.opsli.common.utils.WrapperUtil; import org.opsli.plugins.cache.msg.EhCacheMsg; import org.springframework.cache.Cache; import org.opsli.plugins.cache.EhCachePlugin; @@ -49,7 +66,8 @@ public class EhCachePluginImpl implements EhCachePlugin { try { Cache cache = cacheManager.getCache(cacheName); if(cache != null){ - return cache.get(key); + // 深克隆数据 防止 ehcache在jvm数据串行 + return ObjectUtil.cloneByStream(cache.get(key)); } } catch (Exception e) { log.error(EhCacheMsg.EXCEPTION_GET.getMessage()+":{}",e.getMessage()); @@ -65,7 +83,9 @@ public class EhCachePluginImpl implements EhCachePlugin { try { Cache cache = cacheManager.getCache(cacheName); if(cache != null){ - return cache.get(key,vClass); + // 深克隆数据 防止 ehcache在jvm数据串行 + Object obj = ObjectUtil.cloneByStream(cache.get(key,vClass)); + return WrapperUtil.transformInstance(obj, vClass); } } catch (Exception e) { log.error(EhCacheMsg.EXCEPTION_GET.getMessage()+":{}", e.getMessage()); diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/ExcelPlugin.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/ExcelPlugin.java index b1d789d..a9dc262 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/ExcelPlugin.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/ExcelPlugin.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel; import cn.hutool.core.date.DateUtil; @@ -186,4 +201,4 @@ public class ExcelPlugin { public List getExtendsBeanList(List list,Class typeClazz){ return WrapperUtil.cloneTransformInstance(list,typeClazz); } -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellFontFormat.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellFontFormat.java index 2de34d3..413a743 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellFontFormat.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellFontFormat.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.annotation; import org.apache.poi.ss.usermodel.IndexedColors; diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellStyleFormat.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellStyleFormat.java index 527a175..ecfbe5b 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellStyleFormat.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/CellStyleFormat.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.annotation; import org.apache.poi.ss.usermodel.HorizontalAlignment; @@ -37,4 +52,4 @@ public @interface CellStyleFormat { */ IndexedColors fillBackgroundColor() default IndexedColors.WHITE; -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/ExcelInfo.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/ExcelInfo.java index 4058a11..acb6d5a 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/ExcelInfo.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/annotation/ExcelInfo.java @@ -1,7 +1,20 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.annotation; - - import java.lang.annotation.*; /** diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/exception/ExcelPluginException.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/exception/ExcelPluginException.java index 438b6d6..5e0b2c9 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/exception/ExcelPluginException.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/exception/ExcelPluginException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/factory/ExcelWriterFactory.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/factory/ExcelWriterFactory.java index 4a52a87..61746b2 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/factory/ExcelWriterFactory.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/factory/ExcelWriterFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.factory; import com.alibaba.excel.ExcelWriter; @@ -57,4 +72,4 @@ public class ExcelWriterFactory extends ExcelWriter { //do something } } -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/listener/ExcelListener.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/listener/ExcelListener.java index a4e41ec..a87ee40 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/listener/ExcelListener.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/listener/ExcelListener.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.listener; import com.alibaba.excel.annotation.ExcelProperty; @@ -62,4 +77,4 @@ public class ExcelListener extends AnalysisEventListener { public List getDataList() { return dataList; } -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/msg/ExcelMsg.java b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/msg/ExcelMsg.java index f6092a8..d1972ba 100644 --- a/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/msg/ExcelMsg.java +++ b/opsli-plugins/opsli-plugins-excel/src/main/java/org/opsli/plugins/excel/msg/ExcelMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.excel.msg; import org.opsli.common.base.msg.BaseMsg; @@ -7,7 +22,7 @@ import org.opsli.common.base.msg.BaseMsg; * @BelongsPackage: org.opsli.plugins.mail.msg * @Author: Parker * @CreateTime: 2020-09-13 19:54 - * @Description: Redis消息 + * @Description: Excel 消息 */ public enum ExcelMsg implements BaseMsg { diff --git a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/MailPlugin.java b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/MailPlugin.java index d3df2c2..0c6fb2b 100644 --- a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/MailPlugin.java +++ b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/MailPlugin.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.mail; import org.opsli.plugins.mail.model.MailModel; diff --git a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/exception/MailPluginException.java b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/exception/MailPluginException.java index 37e617b..752c5b6 100644 --- a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/exception/MailPluginException.java +++ b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/exception/MailPluginException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.mail.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/handler/MailPlugInImpl.java b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/handler/MailPlugInImpl.java index 7653a75..3106037 100644 --- a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/handler/MailPlugInImpl.java +++ b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/handler/MailPlugInImpl.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.mail.handler; import cn.hutool.core.lang.Validator; diff --git a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/model/MailModel.java b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/model/MailModel.java index bfefc00..6fa98df 100644 --- a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/model/MailModel.java +++ b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/model/MailModel.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.mail.model; import lombok.Data; diff --git a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/msg/MailMsg.java b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/msg/MailMsg.java index 62660e1..83e7b25 100644 --- a/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/msg/MailMsg.java +++ b/opsli-plugins/opsli-plugins-mail/src/main/java/org/opsli/plugins/mail/msg/MailMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.mail.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisLockPlugins.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisLockPlugins.java index 29dd78e..95aef23 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisLockPlugins.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisLockPlugins.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis; import org.opsli.plugins.redis.lock.RedisLock; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisPlugin.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisPlugin.java index e5c0e7d..4d76e7f 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisPlugin.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/RedisPlugin.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis; import lombok.extern.slf4j.Slf4j; @@ -259,7 +274,7 @@ public class RedisPlugin { /** * 递增 原子性++ increment - * + * * @param key Redis键 * @param by 增加 i * @return @@ -286,7 +301,7 @@ public class RedisPlugin { /** * 递减 原子性 -- decrement - * + * * @param key Redis键 * @param by 减少 i * @return diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/conf/RedisPluginConfig.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/conf/RedisPluginConfig.java index bcd0d78..496d7d2 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/conf/RedisPluginConfig.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/conf/RedisPluginConfig.java @@ -1,12 +1,29 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.conf; import cn.hutool.core.io.IoUtil; import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.opsli.plugins.redis.scripts.RedisScriptCache; import org.opsli.plugins.redis.scripts.enums.RedisScriptsEnum; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; @@ -14,6 +31,8 @@ import org.springframework.data.redis.serializer.RedisSerializer; import javax.annotation.Resource; import java.io.BufferedReader; import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; /** * @Author parker @@ -70,25 +89,21 @@ public class RedisPluginConfig { RedisScriptsEnum[] scriptEnums = RedisScriptsEnum.values(); for (RedisScriptsEnum scriptEnum : scriptEnums) { String path = scriptEnum.getPath(); - InputStream resourceAsStream = null; + try { - // IO流 读取lua脚本 存入缓存当中 提高访问效率 避免每次使用脚本还需要再开启IO流 - StringBuffer stb = new StringBuffer(); - resourceAsStream= RedisPluginConfig.class.getResourceAsStream(path); - BufferedReader br = IoUtil.getUtf8Reader(resourceAsStream); - String line = null; - while((line = br.readLine())!=null){ - stb.append(line); - stb.append("\n"); - } + ClassPathResource resource = new ClassPathResource(path); + InputStream inputStream = resource.getInputStream(); +// List readList = Lists.newArrayList(); +// IoUtil.readLines(inputStream, StandardCharsets.UTF_8, readList); +// StringBuilder stb = new StringBuilder(); +// for (String readLine : readList) { +// stb.append(readLine); +// stb.append("\n"); +// } + String read = IoUtil.read(inputStream, StandardCharsets.UTF_8); // 保存脚本到缓存中 - redisScriptCache.putScript(scriptEnum,stb.toString()); - br.close(); - }catch (Exception e){ - log.error(e.getMessage(),e); - }finally { - IoUtil.close(resourceAsStream); - } + redisScriptCache.putScript(scriptEnum,read); + }catch (Exception ignored){} } diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/exception/RedisPluginException.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/exception/RedisPluginException.java index 454c446..53e9a27 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/exception/RedisPluginException.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/exception/RedisPluginException.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.exception; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLock.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLock.java index 6ef9245..4fadd1d 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLock.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLock.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.lock; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLockImpl.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLockImpl.java index bb9f37a..d363f0a 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLockImpl.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/lock/RedisLockImpl.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.lock; import lombok.extern.slf4j.Slf4j; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/msg/RedisMsg.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/msg/RedisMsg.java index 006570c..673f21a 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/msg/RedisMsg.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/msg/RedisMsg.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.msg; import org.opsli.common.base.msg.BaseMsg; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/BaseSubMessage.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/BaseSubMessage.java index 7a20d01..4c76670 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/BaseSubMessage.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/BaseSubMessage.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.pushsub.entity; import com.alibaba.fastjson.JSONObject; @@ -43,4 +58,4 @@ public class BaseSubMessage implements RedisPushSubMessage{ this.channel = channel; } -} \ No newline at end of file +} diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/RedisPushSubMessage.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/RedisPushSubMessage.java index 17bf878..08e81fa 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/RedisPushSubMessage.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/pushsub/entity/RedisPushSubMessage.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.pushsub.entity; import java.io.Serializable; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/RedisScriptCache.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/RedisScriptCache.java index 74f6094..a6ffabf 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/RedisScriptCache.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/RedisScriptCache.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.scripts; import org.opsli.plugins.redis.scripts.enums.RedisScriptsEnum; diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/enums/RedisScriptsEnum.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/enums/RedisScriptsEnum.java index f2aa24b..b4f1cea 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/enums/RedisScriptsEnum.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/scripts/enums/RedisScriptsEnum.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.plugins.redis.scripts.enums; diff --git a/opsli-starter/pom.xml b/opsli-starter/pom.xml index c1b1c79..3ebd8f8 100644 --- a/opsli-starter/pom.xml +++ b/opsli-starter/pom.xml @@ -41,6 +41,12 @@ opsli-modulars-system ${modulars.version} + + + org.opsliframework.boot + opsli-modulars-creater + ${modulars.version} + org.opsliframework.boot @@ -66,4 +72,4 @@ - \ No newline at end of file + diff --git a/opsli-starter/src/main/java/org/opsli/OpsliApplication.java b/opsli-starter/src/main/java/org/opsli/OpsliApplication.java index 2047c36..71bdb69 100644 --- a/opsli-starter/src/main/java/org/opsli/OpsliApplication.java +++ b/opsli-starter/src/main/java/org/opsli/OpsliApplication.java @@ -1,9 +1,29 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; - +/** + * OPSLI 快速开发平台启动类 + * + * @author Parker + * @date 2020-09-09 + */ @SpringBootApplication() public class OpsliApplication { @@ -11,4 +31,4 @@ public class OpsliApplication { SpringApplication.run(OpsliApplication.class, args); } -} \ No newline at end of file +} diff --git a/opsli-starter/src/main/resources/application-beta.yaml b/opsli-starter/src/main/resources/application-beta.yaml index 2708cdf..530cb84 100644 --- a/opsli-starter/src/main/resources/application-beta.yaml +++ b/opsli-starter/src/main/resources/application-beta.yaml @@ -1,13 +1,8 @@ -## ---- 开发环境 ---- ## -opsli: - # 前缀 - prefix: api - # 版本 - version: v1 +## ---- 测试环境 ---- ## # 端口设置 server: - port: 8080 + port: 7000 spring: #redis 配置 @@ -38,22 +33,43 @@ spring: #primary: master datasource: master: - url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false + url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai username: root - password: 12345678 + password: MYSQL0p9o8i7u driver-class-name: com.mysql.jdbc.Driver - # 多数据源配置 - #slave-datasource: - #url: jdbc:mysql://localhost:3306/opsli-boot?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true - #username: root - #password: 12345678 - #driver-class-name: com.mysql.jdbc.Driver - -#Mybatis输出sql日志 -#logging: -# level: -# org.opsli.modulars.system.mapper : debug - -# swagger 配置 -swagger: - production: false \ No newline at end of file + # 多数据源配置 + #slave-datasource: + #url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai + #username: root + #password: 12345678 + #driver-class-name: com.mysql.jdbc.Driver + + +# knife4j 文档 配置 +knife4j: + basic: + ## 开启Swagger的Basic认证功能,默认是false + enable: false + ## Basic认证用户名 + username: admin + ## Basic认证密码 + password: 123456 + + # 是否生产环境 (生产环境默认屏蔽文档) + production: false + + + +# opsli 自定义配置 +opsli: + + # 演示模式 + enable-demo: true + + # web 上传文件路径 + web: + upload-path: /www/wwwroot/demo.opsli.com/files + +# 系统日志 +log: + path: /var/log diff --git a/opsli-starter/src/main/resources/application-dev.yaml b/opsli-starter/src/main/resources/application-dev.yaml index d1743cf..2ce6c0e 100644 --- a/opsli-starter/src/main/resources/application-dev.yaml +++ b/opsli-starter/src/main/resources/application-dev.yaml @@ -33,13 +33,13 @@ spring: #primary: master datasource: master: - url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false + url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai username: root password: 12345678 driver-class-name: com.mysql.jdbc.Driver # 多数据源配置 #slave-datasource: - #url: jdbc:mysql://localhost:3306/opsli-boot?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true + #url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai #username: root #password: 12345678 #driver-class-name: com.mysql.jdbc.Driver @@ -51,13 +51,23 @@ knife4j: ## 开启Swagger的Basic认证功能,默认是false enable: true ## Basic认证用户名 - username: doc + username: admin ## Basic认证密码 password: 123456 # 是否生产环境 (生产环境默认屏蔽文档) production: false +# opsli 自定义配置 +opsli: + # 演示模式 + enable-demo: false + # web 上传文件路径 + web: + upload-path: /Users/system/Documents/work/tmp/opsli +# 系统日志 +log: + path: /Users/system/Documents/脚本/opsli/var/log diff --git a/opsli-starter/src/main/resources/application-release.yaml b/opsli-starter/src/main/resources/application-release.yaml index 2708cdf..a9f22d6 100644 --- a/opsli-starter/src/main/resources/application-release.yaml +++ b/opsli-starter/src/main/resources/application-release.yaml @@ -1,9 +1,4 @@ -## ---- 开发环境 ---- ## -opsli: - # 前缀 - prefix: api - # 版本 - version: v1 +## ---- 生产环境 ---- ## # 端口设置 server: @@ -23,7 +18,7 @@ spring: druid: stat-view-servlet: # 数据库监控开关 - enabled: true + enabled: false # 登录用户名/密码 login-username: admin login-password: 123456 @@ -38,22 +33,42 @@ spring: #primary: master datasource: master: - url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false + url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai username: root password: 12345678 driver-class-name: com.mysql.jdbc.Driver # 多数据源配置 #slave-datasource: - #url: jdbc:mysql://localhost:3306/opsli-boot?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true + #url: jdbc:mysql://127.0.0.1:3306/opsli-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&serverTimezone=Asia/Shanghai #username: root #password: 12345678 #driver-class-name: com.mysql.jdbc.Driver -#Mybatis输出sql日志 -#logging: -# level: -# org.opsli.modulars.system.mapper : debug -# swagger 配置 -swagger: - production: false \ No newline at end of file +# knife4j 文档 配置 +knife4j: + basic: + ## 开启Swagger的Basic认证功能,默认是false + enable: false + ## Basic认证用户名 + username: admin + ## Basic认证密码 + password: 123456 + + # 是否生产环境 (生产环境默认屏蔽文档) + production: true + + +# opsli 自定义配置 +opsli: + + # 演示模式 + enable-demo: true + + # web 上传文件路径 + web: + upload-path: /Users/system/Documents/work/tmp/opsli + +# 系统日志 +log: + path: /var/log diff --git a/opsli-starter/src/main/resources/application.yaml b/opsli-starter/src/main/resources/application.yaml index aff526c..6efd464 100644 --- a/opsli-starter/src/main/resources/application.yaml +++ b/opsli-starter/src/main/resources/application.yaml @@ -1,7 +1,8 @@ # tomcat 配置 server: tomcat: - #basedir: /Users/xxx + # Tomcat 工作目录路径 + #basedir: # Tomcat 编码 uri-encoding: UTF-8 # 对于 Tomcat 头文件不限制大小 @@ -12,7 +13,6 @@ server: api: path: global-prefix: /api/v1 - compression: enabled: true min-response-size: 1024 @@ -33,6 +33,9 @@ spring: multipart: max-file-size: 10MB max-request-size: 10MB + #静态资源 + resources: + static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/,file:${opsli.web.upload-path} #json 时间戳统一转换 jackson: date-format: yyyy-MM-dd HH:mm:ss @@ -137,16 +140,46 @@ mybatis-plus: logic-delete-field: deleted # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) logic-delete-value: 1 # 逻辑已删除值(默认为 1) logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) - # 更新策略 - 防止更新 null 值到数据字段中 + # 更新策略 - 防止更新 null 值到数据字段中 空字符串可以更新 + # 不要改!!!如果想要非空修改 直接在对应字段上加注解 全局不允许 可空数据修改 update-strategy: not_empty configuration: map-underscore-to-camel-case: true cache-enabled: false call-setters-on-nulls: true # 打印SQL 开发测试使用 生产关闭 *** - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + + # opsli 自定义配置 opsli: + # Java 软防火墙 + waf: + # 开启防护 + enable: true + # 开启XSS 防护 + xss-filter: true + # 开启sql注入防护 (目前用不着sql防护 mybatis-plus就已经很完善了) + sql-filter: false + # 设置xss防护过滤器的优先级,值越小优先级越高(不要超过 shiroFilter) + order: 0 + # 设置xss防护的url拦截路径 + url-patterns: "/*" + # 排除过滤url + url-exclusion: + - "/doc.html" + - "/static/file" + + # 超级管理员账号 + superadmin: system # token 有效时间 (分钟) 2小时 token-effective-time: 120 + + # 登录设置 + login: + # 失败次数 + slip-count: 5 + # 失败锁定时间(秒) + slip-lock-speed: 300 + diff --git a/opsli-starter/src/main/resources/config/logback-spring.xml b/opsli-starter/src/main/resources/logback-spring.xml similarity index 100% rename from opsli-starter/src/main/resources/config/logback-spring.xml rename to opsli-starter/src/main/resources/logback-spring.xml diff --git a/pom.xml b/pom.xml index 259c0ca..c100071 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,7 @@ 0.0.9 1.6.0 3.1.0 - - - - + 1.27 @@ -106,31 +103,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - com.auth0 @@ -283,6 +255,14 @@ hutool-all ${hutool.version} + + + + org.yaml + snakeyaml + ${snakeyaml.version} + +