From 7aaa6700b3cc082ff2b75628dfb239f67870a1b5 Mon Sep 17 00:00:00 2001 From: weihongyang <1075331873@qq.com> Date: Mon, 20 Jun 2022 16:26:51 +0800 Subject: [PATCH] commit init --- .gitignore | 25 ++ pom.xml | 227 ++++++++++++++++++ ym-admin/pom.xml | 44 ++++ .../admin/Expression/SGExpressionRoot.java | 28 +++ .../cnbm/admin/annotation/LogOperation.java | 16 ++ .../cnbm/admin/aspect/LogOperationAspect.java | 105 ++++++++ .../com/cnbm/admin/config/CorsConfig.java | 30 +++ .../com/cnbm/admin/config/SecurityConfig.java | 74 ++++++ .../admin/controller/LoginController.java | 43 ++++ .../admin/controller/SysDeptController.java | 90 +++++++ .../controller/SysDictDataController.java | 102 ++++++++ .../controller/SysDictTypeController.java | 112 +++++++++ .../controller/SysLogErrorController.java | 61 +++++ .../controller/SysLogOperationController.java | 62 +++++ .../admin/controller/SysMenuController.java | 136 +++++++++++ .../admin/controller/SysParamsController.java | 116 +++++++++ .../admin/controller/SysRoleController.java | 125 ++++++++++ .../admin/controller/SysUserController.java | 163 +++++++++++++ .../java/com/cnbm/admin/dao/LoginDao.java | 14 ++ .../java/com/cnbm/admin/dao/SysDeptDao.java | 33 +++ .../com/cnbm/admin/dao/SysDictDataDao.java | 22 ++ .../com/cnbm/admin/dao/SysDictTypeDao.java | 23 ++ .../com/cnbm/admin/dao/SysLogErrorDao.java | 15 ++ .../cnbm/admin/dao/SysLogOperationDao.java | 15 ++ .../java/com/cnbm/admin/dao/SysMenuDao.java | 52 ++++ .../java/com/cnbm/admin/dao/SysParamsDao.java | 37 +++ .../java/com/cnbm/admin/dao/SysRoleDao.java | 16 ++ .../cnbm/admin/dao/SysRoleDataScopeDao.java | 32 +++ .../com/cnbm/admin/dao/SysRoleMenuDao.java | 34 +++ .../com/cnbm/admin/dao/SysRoleUserDao.java | 36 +++ .../java/com/cnbm/admin/dao/SysUserDao.java | 36 +++ .../main/java/com/cnbm/admin/dao/UserDao.java | 14 ++ .../java/com/cnbm/admin/dto/PasswordDTO.java | 28 +++ .../java/com/cnbm/admin/dto/SysDeptDTO.java | 102 ++++++++ .../com/cnbm/admin/dto/SysDictDataDTO.java | 58 +++++ .../com/cnbm/admin/dto/SysDictTypeDTO.java | 55 +++++ .../com/cnbm/admin/dto/SysLogErrorDTO.java | 37 +++ .../cnbm/admin/dto/SysLogOperationDTO.java | 53 ++++ .../java/com/cnbm/admin/dto/SysMenuDTO.java | 148 ++++++++++++ .../java/com/cnbm/admin/dto/SysParamsDTO.java | 51 ++++ .../java/com/cnbm/admin/dto/SysRoleDTO.java | 50 ++++ .../java/com/cnbm/admin/dto/SysUserDTO.java | 84 +++++++ .../java/com/cnbm/admin/entity/DictData.java | 17 ++ .../java/com/cnbm/admin/entity/DictType.java | 20 ++ .../java/com/cnbm/admin/entity/LoginUser.java | 83 +++++++ .../com/cnbm/admin/entity/SysDeptEntity.java | 55 +++++ .../cnbm/admin/entity/SysDictDataEntity.java | 52 ++++ .../cnbm/admin/entity/SysDictTypeEntity.java | 48 ++++ .../cnbm/admin/entity/SysLogErrorEntity.java | 44 ++++ .../admin/entity/SysLogOperationEntity.java | 55 +++++ .../com/cnbm/admin/entity/SysMenuEntity.java | 67 ++++++ .../cnbm/admin/entity/SysParamsEntity.java | 50 ++++ .../admin/entity/SysRoleDataScopeEntity.java | 28 +++ .../com/cnbm/admin/entity/SysRoleEntity.java | 46 ++++ .../cnbm/admin/entity/SysRoleMenuEntity.java | 27 +++ .../cnbm/admin/entity/SysRoleUserEntity.java | 29 +++ .../com/cnbm/admin/entity/SysUserEntity.java | 80 ++++++ .../com/cnbm/admin/enums/MenuTypeEnum.java | 27 +++ .../cnbm/admin/enums/OperationStatusEnum.java | 27 +++ .../com/cnbm/admin/enums/SuperAdminEnum.java | 21 ++ .../admin/exception/RenExceptionHandler.java | 87 +++++++ .../cnbm/admin/execl/SysLogErrorExcel.java | 28 +++ .../admin/execl/SysLogOperationExcel.java | 36 +++ .../com/cnbm/admin/execl/SysParamsExcel.java | 20 ++ .../com/cnbm/admin/execl/SysUserExcel.java | 34 +++ .../filter/JwtAuthenticationTokenFilter.java | 65 +++++ .../handler/AccessDeniedHandlerImpl.java | 30 +++ .../handler/AuthenticationEntryPointImpl.java | 30 +++ .../com/cnbm/admin/params/LoginParam.java | 36 +++ .../com/cnbm/admin/redis/SysParamsRedis.java | 36 +++ .../cnbm/admin/service/CaptchaService.java | 9 + .../com/cnbm/admin/service/LoginService.java | 16 ++ .../cnbm/admin/service/SysDeptService.java | 32 +++ .../admin/service/SysDictDataService.java | 27 +++ .../admin/service/SysDictTypeService.java | 34 +++ .../admin/service/SysLogErrorService.java | 24 ++ .../admin/service/SysLogOperationService.java | 23 ++ .../cnbm/admin/service/SysMenuService.java | 48 ++++ .../cnbm/admin/service/SysParamsService.java | 50 ++++ .../service/SysRoleDataScopeService.java | 32 +++ .../admin/service/SysRoleMenuService.java | 38 +++ .../cnbm/admin/service/SysRoleService.java | 30 +++ .../admin/service/SysRoleUserService.java | 39 +++ .../cnbm/admin/service/SysUserService.java | 49 ++++ .../admin/service/impl/LoginServiceImpl.java | 51 ++++ .../service/impl/SysDeptServiceImpl.java | 165 +++++++++++++ .../service/impl/SysDictDataServiceImpl.java | 80 ++++++ .../service/impl/SysDictTypeServiceImpl.java | 98 ++++++++ .../service/impl/SysLogErrorServiceImpl.java | 55 +++++ .../impl/SysLogOperationServiceImpl.java | 60 +++++ .../service/impl/SysMenuServiceImpl.java | 136 +++++++++++ .../service/impl/SysParamsServiceImpl.java | 133 ++++++++++ .../impl/SysRoleDataScopeServiceImpl.java | 53 ++++ .../service/impl/SysRoleMenuServiceImpl.java | 60 +++++ .../service/impl/SysRoleServiceImpl.java | 132 ++++++++++ .../service/impl/SysRoleUserServiceImpl.java | 56 +++++ .../service/impl/SysUserServiceImpl.java | 154 ++++++++++++ .../service/impl/UserDetailsServiceImpl.java | 57 +++++ .../java/com/cnbm/admin/utils/JwtUtil.java | 115 +++++++++ .../com/cnbm/admin/utils/PasswordUtils.java | 43 ++++ .../com/cnbm/admin/utils/ResponseResult.java | 64 +++++ .../java/com/cnbm/admin/utils/WebUtils.java | 34 +++ .../src/main/resources/mapper/LoginDao.xml | 6 + .../src/main/resources/mapper/SysDeptDao.xml | 32 +++ .../main/resources/mapper/SysDictDataDao.xml | 10 + .../main/resources/mapper/SysDictTypeDao.xml | 10 + .../main/resources/mapper/SysLogErrorDao.xml | 6 + .../resources/mapper/SysLogOperationDao.xml | 6 + .../src/main/resources/mapper/SysMenuDao.xml | 46 ++++ .../main/resources/mapper/SysParamsDao.xml | 23 ++ .../src/main/resources/mapper/SysRoleDao.xml | 7 + .../resources/mapper/SysRoleDataScopeDao.xml | 22 ++ .../main/resources/mapper/SysRoleMenuDao.xml | 20 ++ .../main/resources/mapper/SysRoleUserDao.xml | 24 ++ .../src/main/resources/mapper/SysUserDao.xml | 50 ++++ ym-barcode/pom.xml | 27 +++ .../listener/GlobalKeyListenerExample.java | 91 +++++++ ym-basic/pom.xml | 19 ++ ym-common/pom.xml | 19 ++ .../com/cnbm/common/aspect/RedisAspect.java | 41 ++++ .../com/cnbm/common/constant/Constant.java | 119 +++++++++ .../cnbm/common/convert/DateConverter.java | 71 ++++++ .../java/com/cnbm/common/dao/BaseDao.java | 12 + .../com/cnbm/common/entity/BaseEntity.java | 33 +++ .../com/cnbm/common/exception/ErrorCode.java | 34 +++ .../cnbm/common/exception/ExceptionUtils.java | 45 ++++ .../cnbm/common/exception/RenException.java | 65 +++++ .../java/com/cnbm/common/page/PageData.java | 35 +++ .../com/cnbm/common/redis/RedisConfig.java | 49 ++++ .../java/com/cnbm/common/redis/RedisKeys.java | 58 +++++ .../com/cnbm/common/redis/RedisUtils.java | 118 +++++++++ .../com/cnbm/common/service/BaseService.java | 108 +++++++++ .../com/cnbm/common/service/CrudService.java | 27 +++ .../common/service/impl/BaseServiceImpl.java | 212 ++++++++++++++++ .../common/service/impl/CrudServiceImpl.java | 72 ++++++ .../com/cnbm/common/utils/ConvertUtils.java | 52 ++++ .../java/com/cnbm/common/utils/DateUtils.java | 174 ++++++++++++++ .../com/cnbm/common/utils/ExcelUtils.java | 70 ++++++ .../cnbm/common/utils/HttpContextUtils.java | 54 +++++ .../java/com/cnbm/common/utils/IpUtils.java | 49 ++++ .../java/com/cnbm/common/utils/JsonUtils.java | 67 ++++++ .../com/cnbm/common/utils/MessageUtils.java | 24 ++ .../java/com/cnbm/common/utils/Result.java | 89 +++++++ .../cnbm/common/utils/SpringContextUtils.java | 47 ++++ .../java/com/cnbm/common/utils/TreeNode.java | 50 ++++ .../java/com/cnbm/common/utils/TreeUtils.java | 69 ++++++ .../cnbm/common/validator/AssertUtils.java | 88 +++++++ .../cnbm/common/validator/ValidatorUtils.java | 47 ++++ .../cnbm/common/validator/group/AddGroup.java | 9 + .../common/validator/group/DefaultGroup.java | 9 + .../cnbm/common/validator/group/Group.java | 12 + .../common/validator/group/UpdateGroup.java | 9 + .../main/resources/i18n/messages.properties | 26 ++ .../main/resources/i18n/validation.properties | 67 ++++++ ym-gateway/pom.xml | 42 ++++ .../main/java/com/cnbm/AdminApplication.java | 17 ++ .../src/main/resources/application-dev.yml | 40 +++ ym-gateway/src/main/resources/application.yml | 75 ++++++ ym-gateway/src/main/resources/banner.txt | 11 + ym-generator/pom.xml | 70 ++++++ .../cnbm/generator/build/CodeGenerator.java | 148 ++++++++++++ .../com/cnbm/generator/config/DataConfig.java | 16 ++ .../engine/EnhanceVelocityTemplateEngine.java | 55 +++++ .../src/main/resources/templates/DTO.java.vm | 32 +++ .../main/resources/templates/Excel.java.vm | 24 ++ .../resources/templates/controller.java.vm | 116 +++++++++ .../main/resources/templates/entity.java.vm | 120 +++++++++ .../main/resources/templates/mapper.java.vm | 16 ++ .../main/resources/templates/mapper.xml.vm | 39 +++ .../main/resources/templates/service.java.vm | 15 ++ .../resources/templates/serviceImpl.java.vm | 34 +++ 171 files changed, 9178 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 ym-admin/pom.xml create mode 100644 ym-admin/src/main/java/com/cnbm/admin/Expression/SGExpressionRoot.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/annotation/LogOperation.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/aspect/LogOperationAspect.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/LoginController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysDeptController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/LoginDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysDeptDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysDictDataDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysDictTypeDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysLogErrorDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysLogOperationDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysMenuDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysParamsDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDataScopeDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleMenuDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleUserDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/SysUserDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dao/UserDao.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/PasswordDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysDeptDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysDictDataDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysDictTypeDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysLogErrorDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysLogOperationDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysMenuDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysParamsDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysRoleDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/SysUserDTO.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/DictData.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/DictType.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysDeptEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysDictDataEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysDictTypeEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysLogErrorEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysLogOperationEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysMenuEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysParamsEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleDataScopeEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleMenuEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleUserEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/entity/SysUserEntity.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/enums/MenuTypeEnum.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/enums/OperationStatusEnum.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/enums/SuperAdminEnum.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/execl/SysLogErrorExcel.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/execl/SysLogOperationExcel.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/execl/SysParamsExcel.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/execl/SysUserExcel.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/filter/JwtAuthenticationTokenFilter.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/handler/AccessDeniedHandlerImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/handler/AuthenticationEntryPointImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/params/LoginParam.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/redis/SysParamsRedis.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/CaptchaService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/LoginService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysDeptService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysDictDataService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysDictTypeService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysLogErrorService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysLogOperationService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysMenuService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysParamsService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysRoleDataScopeService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysRoleMenuService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysRoleService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysRoleUserService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/SysUserService.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDeptServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictDataServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictTypeServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogErrorServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogOperationServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysMenuServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysParamsServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleDataScopeServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleMenuServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleUserServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/SysUserServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/utils/JwtUtil.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/utils/PasswordUtils.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/utils/ResponseResult.java create mode 100644 ym-admin/src/main/java/com/cnbm/admin/utils/WebUtils.java create mode 100644 ym-admin/src/main/resources/mapper/LoginDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysDeptDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysDictDataDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysDictTypeDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysLogErrorDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysLogOperationDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysMenuDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysParamsDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysRoleDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysRoleDataScopeDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysRoleMenuDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysRoleUserDao.xml create mode 100644 ym-admin/src/main/resources/mapper/SysUserDao.xml create mode 100644 ym-barcode/pom.xml create mode 100644 ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java create mode 100644 ym-basic/pom.xml create mode 100644 ym-common/pom.xml create mode 100644 ym-common/src/main/java/com/cnbm/common/aspect/RedisAspect.java create mode 100644 ym-common/src/main/java/com/cnbm/common/constant/Constant.java create mode 100644 ym-common/src/main/java/com/cnbm/common/convert/DateConverter.java create mode 100644 ym-common/src/main/java/com/cnbm/common/dao/BaseDao.java create mode 100644 ym-common/src/main/java/com/cnbm/common/entity/BaseEntity.java create mode 100644 ym-common/src/main/java/com/cnbm/common/exception/ErrorCode.java create mode 100644 ym-common/src/main/java/com/cnbm/common/exception/ExceptionUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/exception/RenException.java create mode 100644 ym-common/src/main/java/com/cnbm/common/page/PageData.java create mode 100644 ym-common/src/main/java/com/cnbm/common/redis/RedisConfig.java create mode 100644 ym-common/src/main/java/com/cnbm/common/redis/RedisKeys.java create mode 100644 ym-common/src/main/java/com/cnbm/common/redis/RedisUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/service/BaseService.java create mode 100644 ym-common/src/main/java/com/cnbm/common/service/CrudService.java create mode 100644 ym-common/src/main/java/com/cnbm/common/service/impl/BaseServiceImpl.java create mode 100644 ym-common/src/main/java/com/cnbm/common/service/impl/CrudServiceImpl.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/ConvertUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/DateUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/ExcelUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/HttpContextUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/IpUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/JsonUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/MessageUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/Result.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/SpringContextUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/TreeNode.java create mode 100644 ym-common/src/main/java/com/cnbm/common/utils/TreeUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/AssertUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/ValidatorUtils.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/group/AddGroup.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/group/DefaultGroup.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/group/Group.java create mode 100644 ym-common/src/main/java/com/cnbm/common/validator/group/UpdateGroup.java create mode 100644 ym-common/src/main/resources/i18n/messages.properties create mode 100644 ym-common/src/main/resources/i18n/validation.properties create mode 100644 ym-gateway/pom.xml create mode 100644 ym-gateway/src/main/java/com/cnbm/AdminApplication.java create mode 100644 ym-gateway/src/main/resources/application-dev.yml create mode 100644 ym-gateway/src/main/resources/application.yml create mode 100644 ym-gateway/src/main/resources/banner.txt create mode 100644 ym-generator/pom.xml create mode 100644 ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java create mode 100644 ym-generator/src/main/java/com/cnbm/generator/config/DataConfig.java create mode 100644 ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java create mode 100644 ym-generator/src/main/resources/templates/DTO.java.vm create mode 100644 ym-generator/src/main/resources/templates/Excel.java.vm create mode 100644 ym-generator/src/main/resources/templates/controller.java.vm create mode 100644 ym-generator/src/main/resources/templates/entity.java.vm create mode 100644 ym-generator/src/main/resources/templates/mapper.java.vm create mode 100644 ym-generator/src/main/resources/templates/mapper.xml.vm create mode 100644 ym-generator/src/main/resources/templates/service.java.vm create mode 100644 ym-generator/src/main/resources/templates/serviceImpl.java.vm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..631d03f --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ +target + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar +*.iml +.idea + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5cb407c --- /dev/null +++ b/pom.xml @@ -0,0 +1,227 @@ + + + 4.0.0 + + com.cnbm + ym-pass + 1.0-SNAPSHOT + + ym-common + ym-admin + ym-generator + ym-gateway + ym-barcode + ym-basic + + pom + + ym-pass + 轻工业自动化研究所springboot框架 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.0 + + + + UTF-8 + UTF-8 + 1.8 + 4.13.2 + 4.2.2 + + 3.5.1 + 4.0 + 11.2.0.3 + 3.12.0 + 1.4 + 2.11.0 + 1.15 + 31.0-jre + 2.10.14 + 5.7.22 + 2.9.0 + 1.14.3 + 2.0.2 + 1.18.24 + 1.1.1 + 4.4.0 + + + + + + junit + junit + ${junit.version} + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework + spring-context-support + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-configuration-processor + true + + + redis.clients + jedis + ${jedis.version} + + + + mysql + mysql-connector-java + + + + com.oracle + ojdbc6 + ${oracle.version} + + + + com.microsoft.sqlserver + sqljdbc4 + ${sqlserver.version} + + + + org.postgresql + postgresql + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + + cn.afterturn + easypoi-base + ${easypoi.version} + + + cn.afterturn + easypoi-web + ${easypoi.version} + + + com.baomidou + mybatis-plus-boot-starter + ${mybatisplus.version} + + + com.baomidou + mybatis-plus-generator + + + + + org.apache.commons + commons-lang3 + ${commons.lang.version} + + + commons-fileupload + commons-fileupload + ${commons.fileupload.version} + + + commons-io + commons-io + ${commons.io.version} + + + commons-codec + commons-codec + ${commons.codec.version} + + + com.google.guava + guava + ${guava.version} + + + joda-time + joda-time + ${joda.time.version} + + + com.google.code.gson + gson + ${gson.version} + + + cn.hutool + hutool-all + ${hutool.version} + + + org.jsoup + jsoup + ${jsoup.version} + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + + + org.projectlombok + lombok + ${lombok.version} + + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public/ + + true + + + + + + public + aliyun nexus + https://maven.aliyun.com/repository/public/ + + true + + + false + + + + + \ No newline at end of file diff --git a/ym-admin/pom.xml b/ym-admin/pom.xml new file mode 100644 index 0000000..c937493 --- /dev/null +++ b/ym-admin/pom.xml @@ -0,0 +1,44 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-admin + jar + + + 2.3.2 + 1.9.0 + 1.6.2 + 4.1.0 + 7.2.27 + 2.8.3 + 3.2.2 + 5.4.4 + + + + + org.springframework.boot + spring-boot-starter-security + + + io.jsonwebtoken + jjwt + 0.9.0 + + + com.cnbm + ym-common + 1.0-SNAPSHOT + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/Expression/SGExpressionRoot.java b/ym-admin/src/main/java/com/cnbm/admin/Expression/SGExpressionRoot.java new file mode 100644 index 0000000..2ebde41 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/Expression/SGExpressionRoot.java @@ -0,0 +1,28 @@ +package com.cnbm.admin.Expression; + +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysMenuEntity; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author weihongyang + * @Date 2022/6/13 8:29 AM + * @Version 1.0 + */ +@Component("ex") +public class SGExpressionRoot { + + public boolean hasAuthority(String authority){ + //获取当前用户的权限 + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + List permissions = loginUser.getPermissions(); + //判断用户权限集合中是否存在authority + return permissions.contains(authority); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/annotation/LogOperation.java b/ym-admin/src/main/java/com/cnbm/admin/annotation/LogOperation.java new file mode 100644 index 0000000..e4a7e31 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/annotation/LogOperation.java @@ -0,0 +1,16 @@ +package com.cnbm.admin.annotation; + +import java.lang.annotation.*; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:40 AM + * @Version 1.0 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface LogOperation { + + String value() default ""; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/aspect/LogOperationAspect.java b/ym-admin/src/main/java/com/cnbm/admin/aspect/LogOperationAspect.java new file mode 100644 index 0000000..619c43f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/aspect/LogOperationAspect.java @@ -0,0 +1,105 @@ +package com.cnbm.admin.aspect; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysLogOperationEntity; +import com.cnbm.admin.enums.OperationStatusEnum; +import com.cnbm.admin.service.SysLogOperationService; +import com.cnbm.common.utils.HttpContextUtils; +import com.cnbm.common.utils.IpUtils; +import com.cnbm.common.utils.JsonUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:41 AM + * @Version 1.0 + */ +@Aspect +@Component +public class LogOperationAspect { + + @Autowired + private SysLogOperationService sysLogOperationService; + + @Pointcut("@annotation(com.cnbm.admin.annotation.LogOperation)") + public void logPointCut() { + + } + + @Around("logPointCut()") + public Object around(ProceedingJoinPoint point) throws Throwable { + long beginTime = System.currentTimeMillis(); + try { + //执行方法 + Object result = point.proceed(); + + //执行时长(毫秒) + long time = System.currentTimeMillis() - beginTime; + //保存日志 + saveLog(point, time, OperationStatusEnum.SUCCESS.value()); + + return result; + }catch(Exception e) { + //执行时长(毫秒) + long time = System.currentTimeMillis() - beginTime; + //保存日志 + saveLog(point, time, OperationStatusEnum.FAIL.value()); + + throw e; + } + } + + private void saveLog(ProceedingJoinPoint joinPoint, long time, Integer status) throws Exception { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); + LogOperation annotation = method.getAnnotation(LogOperation.class); + + SysLogOperationEntity log = new SysLogOperationEntity(); + if(annotation != null){ + //注解上的描述 + log.setOperation(annotation.value()); + } + + //登录用户信息 + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + if(loginUser != null){ + log.setCreatorName(loginUser.getUsername()); + } + + log.setStatus(status); + log.setRequestTime((int)time); + + //请求相关信息 + HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); + log.setIp(IpUtils.getIpAddr(request)); + log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); + log.setRequestUri(request.getRequestURI()); + log.setRequestMethod(request.getMethod()); + + //请求参数 + Object[] args = joinPoint.getArgs(); + try{ + String params = JsonUtils.toJsonString(args[0]); + log.setRequestParams(params); + }catch (Exception e){ + + } + + //保存到DB + sysLogOperationService.save(log); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java new file mode 100644 index 0000000..55e40e5 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/config/CorsConfig.java @@ -0,0 +1,30 @@ +package com.cnbm.admin.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * @Author weihongyang + * @Date 2022/6/8 10:47 AM + * @Version 1.0 + */ +@Configuration +public class CorsConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + // 设置允许跨域的路径 + registry.addMapping("/**") + // 设置允许跨域请求的域名 + .allowedOriginPatterns("*") + // 是否允许cookie + .allowCredentials(true) + // 设置允许的请求方式 + .allowedMethods("GET", "POST", "DELETE", "PUT") + // 设置允许的header属性 + .allowedHeaders("*") + // 跨域允许时间 + .maxAge(3600); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java new file mode 100644 index 0000000..3c66bed --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java @@ -0,0 +1,74 @@ +package com.cnbm.admin.config; + +import com.cnbm.admin.filter.JwtAuthenticationTokenFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +/** + * @Author weihongyang + * @Date 2022/6/8 1:51 PM + * @Version 1.0 + */ +@Configuration +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + //创建BCryptPasswordEncoder注入容器 + @Bean + public PasswordEncoder passwordEncoder(){ + return new BCryptPasswordEncoder(); + } + @Autowired + private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter; + + + @Autowired + private AuthenticationEntryPoint authenticationEntryPoint; + + @Autowired + private AccessDeniedHandler accessDeniedHandler; + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + //关闭csrf + .csrf().disable() + //不通过Session获取SecurityContext + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + .authorizeRequests() + // 对于登录接口 允许匿名访问 + .antMatchers("/login").anonymous() +// .antMatchers("/testCors").hasAuthority("system:dept:list222") + // 除上面外的所有请求全部需要鉴权认证 + .anyRequest().authenticated(); + + //添加过滤器 + http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); + + //配置异常处理器 + http.exceptionHandling() + //配置认证失败处理器 + .authenticationEntryPoint(authenticationEntryPoint) + .accessDeniedHandler(accessDeniedHandler); + + //允许跨域 + http.cors(); + } + + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/LoginController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/LoginController.java new file mode 100644 index 0000000..39e020b --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/LoginController.java @@ -0,0 +1,43 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.params.LoginParam; +import com.cnbm.admin.service.LoginService; +import com.cnbm.admin.utils.ResponseResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:55 PM + * @Version 1.0 + */ +@RestController +@Api(tags="登录管理") +@Log4j2 +public class LoginController { + + @Autowired + private LoginService loginService; + + @RequestMapping("/hello") + @PreAuthorize("@ex.hasAuthority('sys:user:page')") + public String hello(){ + log.info("hello"); + return "hello"; + } + + @PostMapping("/login") + @ApiOperation(value = "登录") + public ResponseResult login(HttpServletRequest request, @RequestBody LoginParam loginParam) { + return loginService.login(request,loginParam); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDeptController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDeptController.java new file mode 100644 index 0000000..89c8bd8 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDeptController.java @@ -0,0 +1,90 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysDeptDTO; +import com.cnbm.admin.service.SysDeptService; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:40 PM + * @Version 1.0 + */ +@RestController +@RequestMapping("/sys/dept") +@Api(tags="部门管理") +public class SysDeptController { + @Autowired + private SysDeptService sysDeptService; + + @GetMapping("list") + @ApiOperation("列表") + @PreAuthorize("@ex.hasAuthority('sys:dept:list')") + public Result> list(){ + List list = sysDeptService.list(new HashMap<>(1)); + + return new Result>().ok(list); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:dept:info')") + public Result get(@PathVariable("id") Long id){ + SysDeptDTO data = sysDeptService.get(id); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:dept:save')") + public Result save(@RequestBody SysDeptDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + + sysDeptService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:dept:update')") + public Result update(@RequestBody SysDeptDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysDeptService.update(dto); + + return new Result(); + } + + @DeleteMapping("{id}") + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:dept:delete')") + public Result delete(@PathVariable("id") Long id){ + //效验数据 + AssertUtils.isNull(id, "id"); + + sysDeptService.delete(id); + + return new Result(); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java new file mode 100644 index 0000000..3f799cd --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictDataController.java @@ -0,0 +1,102 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysDictDataDTO; +import com.cnbm.admin.service.SysDictDataService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:55 AM + * @Version 1.0 + */ +@RestController +@RequestMapping("sys/dict/data") +@Api(tags="字典数据") +public class SysDictDataController { + @Autowired + private SysDictDataService sysDictDataService; + + @GetMapping("page") + @ApiOperation("字典数据") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "dictLabel", value = "字典标签", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "dictValue", value = "字典值", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('sys:dept:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + //字典类型 + PageData page = sysDictDataService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:dict:info')") + public Result get(@PathVariable("id") Long id){ + SysDictDataDTO data = sysDictDataService.get(id); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:dict:save')") + public Result save(@RequestBody SysDictDataDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, DefaultGroup.class); + + sysDictDataService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:dict:update')") + public Result update(@RequestBody SysDictDataDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysDictDataService.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:dict:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + sysDictDataService.delete(ids); + + return new Result(); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java new file mode 100644 index 0000000..222fcff --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysDictTypeController.java @@ -0,0 +1,112 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysDictTypeDTO; +import com.cnbm.admin.entity.DictType; +import com.cnbm.admin.service.SysDictTypeService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:55 AM + * @Version 1.0 + */ +@RestController +@RequestMapping("sys/dict/type") +@Api(tags="字典类型") +public class SysDictTypeController { + @Autowired + private SysDictTypeService sysDictTypeService; + + @GetMapping("page") + @ApiOperation("字典类型") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "dictType", value = "字典类型", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "dictName", value = "字典名称", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('sys:dict:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + //字典类型 + PageData page = sysDictTypeService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:dict:info')") + public Result get(@PathVariable("id") Long id){ + SysDictTypeDTO data = sysDictTypeService.get(id); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:dict:save')") + public Result save(@RequestBody SysDictTypeDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, DefaultGroup.class); + + sysDictTypeService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:dict:update')") + public Result update(@RequestBody SysDictTypeDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysDictTypeService.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:dict:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + sysDictTypeService.delete(ids); + + return new Result(); + } + + @GetMapping("all") + @ApiOperation("所有字典数据") + public Result> all(){ + List list = sysDictTypeService.getAllList(); + + return new Result>().ok(list); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java new file mode 100644 index 0000000..6aef1ec --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogErrorController.java @@ -0,0 +1,61 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysLogErrorDTO; +import com.cnbm.admin.execl.SysLogErrorExcel; +import com.cnbm.admin.service.SysLogErrorService; +import com.cnbm.common.utils.ExcelUtils; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:06 PM + * @Version 1.0 + */ +@RestController +@RequestMapping("sys/log/error") +@Api(tags="异常日志") +public class SysLogErrorController { + @Autowired + private SysLogErrorService sysLogErrorService; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") + }) + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysLogErrorService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("export") + @ApiOperation("导出") + @LogOperation("导出") + public void export(@ApiIgnore @RequestParam Map params, HttpServletResponse response) throws Exception { + List list = sysLogErrorService.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, SysLogErrorExcel.class); + } + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java new file mode 100644 index 0000000..6034d18 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogOperationController.java @@ -0,0 +1,62 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysLogOperationDTO; +import com.cnbm.admin.execl.SysLogOperationExcel; +import com.cnbm.admin.service.SysLogOperationService; +import com.cnbm.common.utils.ExcelUtils; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:51 AM + * @Version 1.0 + */ +@RestController +@RequestMapping("sys/log/operation") +@Api(tags="操作日志") +public class SysLogOperationController { + @Autowired + private SysLogOperationService sysLogOperationService; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "status", value = "状态 0:失败 1:成功", paramType = "query", dataType="int") + }) + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysLogOperationService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("export") + @ApiOperation("导出") + @LogOperation("导出") + public void export(@ApiIgnore @RequestParam Map params, HttpServletResponse response) throws Exception { + List list = sysLogOperationService.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, SysLogOperationExcel.class); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java new file mode 100644 index 0000000..dcea161 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysMenuController.java @@ -0,0 +1,136 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysMenuDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.enums.MenuTypeEnum; +import com.cnbm.admin.service.SysMenuService; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.DefaultGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:32 PM + * @Version 1.0 + */ +@RestController +@RequestMapping("/sys/menu") +@Api(tags="菜单管理") +public class SysMenuController { + @Autowired + private SysMenuService sysMenuService; + + + @GetMapping("nav") + @ApiOperation("导航") + public Result> nav(){ + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + List list = sysMenuService.getUserMenuList(user, MenuTypeEnum.MENU.value()); + + return new Result>().ok(list); + } + + @GetMapping("permissions") + @ApiOperation("权限标识") + public Result> permissions(){ + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + Set set = sysMenuService.getUserPermissions(user); + return new Result>().ok(set); + } + + @GetMapping("list") + @ApiOperation("列表") + @ApiImplicitParam(name = "type", value = "菜单类型 0:菜单 1:按钮 null:全部", paramType = "query", dataType="int") + @PreAuthorize("@ex.hasAuthority('sys:menu:list')") + public Result> list(Integer type){ + List list = sysMenuService.getAllMenuList(type); + + return new Result>().ok(list); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:menu:info')") + public Result get(@PathVariable("id") Long id){ + SysMenuDTO data = sysMenuService.get(id); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:menu:save')") + public Result save(@RequestBody SysMenuDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, DefaultGroup.class); + + sysMenuService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:menu:update')") + public Result update(@RequestBody SysMenuDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, DefaultGroup.class); + + sysMenuService.update(dto); + + return new Result(); + } + + @DeleteMapping("{id}") + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:menu:delete')") + public Result delete(@PathVariable("id") Long id){ + //效验数据 + AssertUtils.isNull(id, "id"); + + //判断是否有子菜单或按钮 + List list = sysMenuService.getListPid(id); + if(list.size() > 0){ + return new Result().error(ErrorCode.SUB_MENU_EXIST); + } + + sysMenuService.delete(id); + + return new Result(); + } + + @GetMapping("select") + @ApiOperation("角色菜单权限") + @PreAuthorize("@ex.hasAuthority('sys:menu:select')") + public Result> select(){ + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + List list = sysMenuService.getUserMenuList(user, null); + + return new Result>().ok(list); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java new file mode 100644 index 0000000..cfa9adb --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysParamsController.java @@ -0,0 +1,116 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysParamsDTO; +import com.cnbm.admin.execl.SysParamsExcel; +import com.cnbm.admin.service.SysParamsService; +import com.cnbm.common.utils.ExcelUtils; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:20 AM + * @Version 1.0 + */ +@RestController +@RequestMapping("sys/params") +@Api(tags="参数管理") +public class SysParamsController { + @Autowired + private SysParamsService sysParamsService; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('sys:params:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysParamsService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:params:info')") + public Result get(@PathVariable("id") Long id){ + SysParamsDTO data = sysParamsService.get(id); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:params:save')") + public Result save(@RequestBody SysParamsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + + sysParamsService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:params:update')") + public Result update(@RequestBody SysParamsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysParamsService.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:params:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + sysParamsService.delete(ids); + + return new Result(); + } + + @GetMapping("export") + @ApiOperation("导出") + @LogOperation("导出") + @ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String") + @PreAuthorize("@ex.hasAuthority('sys:params:export')") + public void export(@ApiIgnore @RequestParam Map params, HttpServletResponse response) throws Exception { + List list = sysParamsService.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, SysParamsExcel.class); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java new file mode 100644 index 0000000..5e87715 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysRoleController.java @@ -0,0 +1,125 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.SysRoleDTO; +import com.cnbm.admin.service.SysRoleDataScopeService; +import com.cnbm.admin.service.SysRoleMenuService; +import com.cnbm.admin.service.SysRoleService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:04 AM + * @Version 1.0 + */ +@RestController +@RequestMapping("/sys/role") +@Api(tags="角色管理") +public class SysRoleController { + @Autowired + private SysRoleService sysRoleService; + @Autowired + private SysRoleMenuService sysRoleMenuService; + @Autowired + private SysRoleDataScopeService sysRoleDataScopeService; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "name", value = "角色名", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('sys:role:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysRoleService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("list") + @ApiOperation("列表") + @PreAuthorize("@ex.hasAuthority('sys:role:list')") + public Result> list(){ + List data = sysRoleService.list(new HashMap<>(1)); + + return new Result>().ok(data); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:role:info')") + public Result get(@PathVariable("id") Long id){ + SysRoleDTO data = sysRoleService.get(id); + + //查询角色对应的菜单 + List menuIdList = sysRoleMenuService.getMenuIdList(id); + data.setMenuIdList(menuIdList); + + //查询角色对应的数据权限 + List deptIdList = sysRoleDataScopeService.getDeptIdList(id); + data.setDeptIdList(deptIdList); + + return new Result().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:role:save')") + public Result save(@RequestBody SysRoleDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + + sysRoleService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:role:update')") + public Result update(@RequestBody SysRoleDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysRoleService.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:role:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + sysRoleService.delete(ids); + + return new Result(); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java new file mode 100644 index 0000000..8bf9bc1 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysUserController.java @@ -0,0 +1,163 @@ +package com.cnbm.admin.controller; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.admin.dto.PasswordDTO; +import com.cnbm.admin.dto.SysUserDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.execl.SysUserExcel; +import com.cnbm.admin.service.SysRoleUserService; +import com.cnbm.admin.service.SysUserService; +import com.cnbm.common.utils.ExcelUtils; +import com.cnbm.admin.utils.PasswordUtils; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.ConvertUtils; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:23 PM + * @Version 1.0 + */ +@RestController +@RequestMapping("/sys/user") +@Api(tags="用户管理") +public class SysUserController { + @Autowired + private SysUserService sysUserService; + @Autowired + private SysRoleUserService sysRoleUserService; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") , + @ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "gender", value = "性别", paramType = "query", dataType="String"), + @ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('sys:user:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysUserService.page(params); + + return new Result>().ok(page); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('sys:user:info')") + public Result get(@PathVariable("id") Long id){ + SysUserDTO data = sysUserService.get(id); + + //用户角色列表 + List roleIdList = sysRoleUserService.getRoleIdList(id); + data.setRoleIdList(roleIdList); + + return new Result().ok(data); + } + + @GetMapping("info") + @ApiOperation("登录用户信息") + public Result info(){ + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserDTO data = ConvertUtils.sourceToTarget(loginUser.getSysUserEntity(), SysUserDTO.class); + return new Result().ok(data); + } + + @PutMapping("password") + @ApiOperation("修改密码") + @LogOperation("修改密码") + public Result password(@RequestBody PasswordDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto); + + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + + //原密码不正确 + if(!PasswordUtils.matches(dto.getPassword(), user.getPassword())){ + return new Result().error(ErrorCode.PASSWORD_ERROR); + } + + sysUserService.updatePassword(user.getId(), dto.getNewPassword()); + + return new Result(); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('sys:user:save')") + public Result save(@RequestBody SysUserDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + + sysUserService.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('sys:user:update')") + public Result update(@RequestBody SysUserDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + sysUserService.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('sys:user:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + sysUserService.deleteBatchIds(Arrays.asList(ids)); + + return new Result(); + } + + @GetMapping("export") + @ApiOperation("导出") + @LogOperation("导出") + @ApiImplicitParam(name = "username", value = "用户名", paramType = "query", dataType="String") + @PreAuthorize("@ex.hasAuthority('sys:user:export')") + public void export(@ApiIgnore @RequestParam Map params, HttpServletResponse response) throws Exception { + List list = sysUserService.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, SysUserExcel.class); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/LoginDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/LoginDao.java new file mode 100644 index 0000000..94ea897 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/LoginDao.java @@ -0,0 +1,14 @@ +package com.cnbm.admin.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.cnbm.admin.entity.SysUserEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/8 9:20 AM + * @Version 1.0 + */ +@Mapper +public interface LoginDao extends BaseMapper { +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysDeptDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDeptDao.java new file mode 100644 index 0000000..a325fe9 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDeptDao.java @@ -0,0 +1,33 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysDeptEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:40 PM + * @Version 1.0 + */ +@Mapper +public interface SysDeptDao extends BaseDao { + + List getList(Map params); + + SysDeptEntity getById(Long id); + + /** + * 获取所有部门的id、pid列表 + */ + List getIdAndPidList(); + + /** + * 根据部门ID,获取所有子部门ID列表 + * @param id 部门ID + */ + List getSubDeptIdList(String id); + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictDataDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictDataDao.java new file mode 100644 index 0000000..d1b207d --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictDataDao.java @@ -0,0 +1,22 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.DictData; +import com.cnbm.admin.entity.SysDictDataEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:56 AM + * @Version 1.0 + */ +@Mapper +public interface SysDictDataDao extends BaseDao { + + /** + * 字典数据列表 + */ + List getDictDataList(); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictTypeDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictTypeDao.java new file mode 100644 index 0000000..5aa0d9e --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysDictTypeDao.java @@ -0,0 +1,23 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.DictType; +import com.cnbm.admin.entity.SysDictTypeEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:56 AM + * @Version 1.0 + */ +@Mapper +public interface SysDictTypeDao extends BaseDao { + + /** + * 字典类型列表 + */ + List getDictTypeList(); + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogErrorDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogErrorDao.java new file mode 100644 index 0000000..81a6a54 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogErrorDao.java @@ -0,0 +1,15 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysLogErrorEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:07 PM + * @Version 1.0 + */ +@Mapper +public interface SysLogErrorDao extends BaseDao { + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogOperationDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogOperationDao.java new file mode 100644 index 0000000..c5879d6 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogOperationDao.java @@ -0,0 +1,15 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysLogOperationEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:54 AM + * @Version 1.0 + */ +@Mapper +public interface SysLogOperationDao extends BaseDao { + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysMenuDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysMenuDao.java new file mode 100644 index 0000000..ea264bf --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysMenuDao.java @@ -0,0 +1,52 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysMenuEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:33 PM + * @Version 1.0 + */ +@Mapper +public interface SysMenuDao extends BaseDao { + + SysMenuEntity getById(@Param("id") Long id); + + /** + * 查询所有菜单列表 + * + * @param type 菜单类型 + */ + List getMenuList(@Param("type") Integer type); + + /** + * 查询用户菜单列表 + * + * @param userId 用户ID + * @param type 菜单类型 + */ + List getUserMenuList(@Param("userId") Long userId, @Param("type") Integer type); + + /** + * 查询用户权限列表 + * @param userId 用户ID + */ + List getUserPermissionsList(Long userId); + + /** + * 查询所有权限列表 + */ + List getPermissionsList(); + + /** + * 根据父菜单,查询子菜单 + * @param pid 父菜单ID + */ + List getListPid(Long pid); + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysParamsDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysParamsDao.java new file mode 100644 index 0000000..1b0e290 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysParamsDao.java @@ -0,0 +1,37 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysParamsEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:21 AM + * @Version 1.0 + */ +@Mapper +public interface SysParamsDao extends BaseDao { + /** + * 根据参数编码,查询value + * @param paramCode 参数编码 + * @return 参数值 + */ + String getValueByCode(String paramCode); + + /** + * 获取参数编码列表 + * @param ids ids + * @return 返回参数编码列表 + */ + List getParamCodeList(Long[] ids); + + /** + * 根据参数编码,更新value + * @param paramCode 参数编码 + * @param paramValue 参数值 + */ + int updateValueByCode(@Param("paramCode") String paramCode, @Param("paramValue") String paramValue); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDao.java new file mode 100644 index 0000000..463d4bf --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDao.java @@ -0,0 +1,16 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysRoleEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:05 AM + * @Version 1.0 + */ +@Mapper +public interface SysRoleDao extends BaseDao { + + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDataScopeDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDataScopeDao.java new file mode 100644 index 0000000..62639b7 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleDataScopeDao.java @@ -0,0 +1,32 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysRoleDataScopeEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:15 AM + * @Version 1.0 + */ +@Mapper +public interface SysRoleDataScopeDao extends BaseDao { + + /** + * 根据角色ID,获取部门ID列表 + */ + List getDeptIdList(Long roleId); + + /** + * 获取用户的部门数据权限列表 + */ + List getDataScopeList(Long userId); + + /** + * 根据角色id,删除角色数据权限关系 + * @param roleIds 角色ids + */ + void deleteByRoleIds(Long[] roleIds); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleMenuDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleMenuDao.java new file mode 100644 index 0000000..c9aedd7 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleMenuDao.java @@ -0,0 +1,34 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysRoleMenuEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:15 PM + * @Version 1.0 + */ +@Mapper +public interface SysRoleMenuDao extends BaseDao { + + /** + * 根据角色ID,获取菜单ID列表 + */ + List getMenuIdList(Long roleId); + + /** + * 根据角色id,删除角色菜单关系 + * @param roleIds 角色ids + */ + void deleteByRoleIds(Long[] roleIds); + + /** + * 根据菜单id,删除角色菜单关系 + * @param menuId 菜单id + */ + void deleteByMenuId(Long menuId); +} + diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleUserDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleUserDao.java new file mode 100644 index 0000000..a45d1e2 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysRoleUserDao.java @@ -0,0 +1,36 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysRoleUserEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:35 PM + * @Version 1.0 + */ +@Mapper +public interface SysRoleUserDao extends BaseDao { + + /** + * 根据角色ids,删除角色用户关系 + * @param roleIds 角色ids + */ + void deleteByRoleIds(Long[] roleIds); + + /** + * 根据用户id,删除角色用户关系 + * @param userIds 用户ids + */ + void deleteByUserIds(Long[] userIds); + + /** + * 角色ID列表 + * @param userId 用户ID + * + * @return + */ + List getRoleIdList(Long userId); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysUserDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysUserDao.java new file mode 100644 index 0000000..9b43a8f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysUserDao.java @@ -0,0 +1,36 @@ +package com.cnbm.admin.dao; + +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.common.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:27 PM + * @Version 1.0 + */ +@Mapper +public interface SysUserDao extends BaseDao { + + List getList(Map params); + + SysUserEntity getById(Long id); + + SysUserEntity getByUsername(String username); + + int updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword); + + /** + * 根据部门ID,查询用户数 + */ + int getCountByDeptId(Long deptId); + + /** + * 根据部门ID,查询用户ID列表 + */ + List getUserIdListByDeptId(List deptIdList); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/UserDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/UserDao.java new file mode 100644 index 0000000..608f18d --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/UserDao.java @@ -0,0 +1,14 @@ +package com.cnbm.admin.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.cnbm.admin.entity.SysUserEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/9 8:57 AM + * @Version 1.0 + */ +@Mapper +public interface UserDao extends BaseMapper { +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/PasswordDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/PasswordDTO.java new file mode 100644 index 0000000..49951df --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/PasswordDTO.java @@ -0,0 +1,28 @@ +package com.cnbm.admin.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:59 PM + * @Version 1.0 + */ +@Data +@ApiModel(value = "修改密码") +public class PasswordDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "原密码") + @NotBlank(message="{sysuser.password.require}") + private String password; + + @ApiModelProperty(value = "新密码") + @NotBlank(message="{sysuser.password.require}") + private String newPassword; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysDeptDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDeptDTO.java new file mode 100644 index 0000000..699c065 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDeptDTO.java @@ -0,0 +1,102 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.utils.TreeNode; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:39 PM + * @Version 1.0 + */ +@ApiModel(value = "部门管理") +public class SysDeptDTO extends TreeNode implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "上级ID") + @NotNull(message="{sysdept.pid.require}", groups = DefaultGroup.class) + private Long pid; + + @ApiModelProperty(value = "部门名称") + @NotBlank(message="{sysdept.name.require}", groups = DefaultGroup.class) + private String name; + + @ApiModelProperty(value = "排序") + @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) + private Integer sort; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "上级部门名称") + private String parentName; + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public Long getPid() { + return pid; + } + + @Override + public void setPid(Long pid) { + this.pid = pid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictDataDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictDataDTO.java new file mode 100644 index 0000000..998b055 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictDataDTO.java @@ -0,0 +1,58 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:57 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "字典数据") +public class SysDictDataDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "字典类型ID") + @NotNull(message="{sysdict.type.require}", groups = DefaultGroup.class) + private Long dictTypeId; + + @ApiModelProperty(value = "字典标签") + @NotBlank(message="{sysdict.label.require}", groups = DefaultGroup.class) + private String dictLabel; + + @ApiModelProperty(value = "字典值") + private String dictValue; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "排序") + @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) + private Integer sort; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "更新时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date updateDate; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictTypeDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictTypeDTO.java new file mode 100644 index 0000000..2492798 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysDictTypeDTO.java @@ -0,0 +1,55 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:57 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "字典类型") +public class SysDictTypeDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "字典类型") + @NotBlank(message="{sysdict.type.require}", groups = DefaultGroup.class) + private String dictType; + + @ApiModelProperty(value = "字典名称") + @NotBlank(message="{sysdict.name.require}", groups = DefaultGroup.class) + private String dictName; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "排序") + @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) + private Integer sort; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "更新时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date updateDate; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogErrorDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogErrorDTO.java new file mode 100644 index 0000000..729b5d7 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogErrorDTO.java @@ -0,0 +1,37 @@ +package com.cnbm.admin.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:07 PM + * @Version 1.0 + */ +@Data +@ApiModel(value = "异常日志") +public class SysLogErrorDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + private Long id; + @ApiModelProperty(value = "请求URI") + private String requestUri; + @ApiModelProperty(value = "请求方式") + private String requestMethod; + @ApiModelProperty(value = "请求参数") + private String requestParams; + @ApiModelProperty(value = "用户代理") + private String userAgent; + @ApiModelProperty(value = "操作IP") + private String ip; + @ApiModelProperty(value = "异常信息") + private String errorInfo; + @ApiModelProperty(value = "创建时间") + private Date createDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogOperationDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogOperationDTO.java new file mode 100644 index 0000000..3bdc9f6 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogOperationDTO.java @@ -0,0 +1,53 @@ +package com.cnbm.admin.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:53 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "操作日志") +public class SysLogOperationDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "用户操作") + private String operation; + + @ApiModelProperty(value = "请求URI") + private String requestUri; + + @ApiModelProperty(value = "请求方式") + private String requestMethod; + + @ApiModelProperty(value = "请求参数") + private String requestParams; + + @ApiModelProperty(value = "请求时长(毫秒)") + private Integer requestTime; + + @ApiModelProperty(value = "用户代理") + private String userAgent; + + @ApiModelProperty(value = "操作IP") + private String ip; + + @ApiModelProperty(value = "状态 0:失败 1:成功") + private Integer status; + + @ApiModelProperty(value = "用户名") + private String creatorName; + + @ApiModelProperty(value = "创建时间") + private Date createDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysMenuDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysMenuDTO.java new file mode 100644 index 0000000..fcc41c2 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysMenuDTO.java @@ -0,0 +1,148 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.utils.TreeNode; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:33 PM + * @Version 1.0 + */ +@ApiModel(value = "菜单管理") +public class SysMenuDTO extends TreeNode implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "上级ID") + @NotNull(message="{sysmenu.pid.require}", groups = DefaultGroup.class) + private Long pid; + + @ApiModelProperty(value = "菜单名称") + @NotBlank(message="{sysmenu.name.require}", groups = DefaultGroup.class) + private String name; + + @ApiModelProperty(value = "菜单URL") + private String url; + + @ApiModelProperty(value = "类型 0:菜单 1:按钮") + @Range(min=0, max=1, message = "{sysmenu.type.range}", groups = DefaultGroup.class) + private Integer type; + + @ApiModelProperty(value = "菜单图标") + private String icon; + + @ApiModelProperty(value = "授权(多个用逗号分隔,如:sys:user:list,sys:user:save)") + private String permissions; + + @ApiModelProperty(value = "排序") + @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) + private Integer sort; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "上级菜单名称") + private String parentName; + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + @Override + public Long getPid() { + return pid; + } + + @Override + public void setPid(Long pid) { + this.pid = pid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getPermissions() { + return permissions; + } + + public void setPermissions(String permissions) { + this.permissions = permissions; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public String getParentName() { + return parentName; + } + + public void setParentName(String parentName) { + this.parentName = parentName; + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysParamsDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysParamsDTO.java new file mode 100644 index 0000000..46c2245 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysParamsDTO.java @@ -0,0 +1,51 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:21 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "参数管理") +public class SysParamsDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "参数编码") + @NotBlank(message="{sysparams.paramcode.require}", groups = DefaultGroup.class) + private String paramCode; + + @ApiModelProperty(value = "参数值") + @NotBlank(message="{sysparams.paramvalue.require}", groups = DefaultGroup.class) + private String paramValue; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "更新时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date updateDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysRoleDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysRoleDTO.java new file mode 100644 index 0000000..e69f7a5 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysRoleDTO.java @@ -0,0 +1,50 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:06 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "角色管理") +public class SysRoleDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "角色名称") + @NotBlank(message="{sysrole.name.require}", groups = DefaultGroup.class) + private String name; + + @ApiModelProperty(value = "备注") + private String remark; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "菜单ID列表") + private List menuIdList; + + @ApiModelProperty(value = "部门ID列表") + private List deptIdList; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysUserDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysUserDTO.java new file mode 100644 index 0000000..14f1a99 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysUserDTO.java @@ -0,0 +1,84 @@ +package com.cnbm.admin.dto; + +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:26 PM + * @Version 1.0 + */ +@Data +@ApiModel(value = "用户管理") +public class SysUserDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @Null(message="{id.null}", groups = AddGroup.class) + @NotNull(message="{id.require}", groups = UpdateGroup.class) + private Long id; + + @ApiModelProperty(value = "用户名", required = true) + @NotBlank(message="{sysuser.username.require}", groups = DefaultGroup.class) + private String username; + + @ApiModelProperty(value = "密码") + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @NotBlank(message="{sysuser.password.require}", groups = AddGroup.class) + private String password; + + @ApiModelProperty(value = "姓名", required = true) + @NotBlank(message="{sysuser.realname.require}", groups = DefaultGroup.class) + private String realName; + + @ApiModelProperty(value = "头像") + private String headUrl; + + @ApiModelProperty(value = "性别 0:男 1:女 2:保密", required = true) + @Range(min=0, max=2, message = "{sysuser.gender.range}", groups = DefaultGroup.class) + private Integer gender; + + @ApiModelProperty(value = "邮箱") + @Email(message="{sysuser.email.error}", groups = DefaultGroup.class) + private String email; + + @ApiModelProperty(value = "手机号") + private String mobile; + + @ApiModelProperty(value = "部门ID", required = true) + @NotNull(message="{sysuser.deptId.require}", groups = DefaultGroup.class) + private Long deptId; + + @ApiModelProperty(value = "状态 0:停用 1:正常", required = true) + @Range(min=0, max=1, message = "{sysuser.status.range}", groups = DefaultGroup.class) + private Integer status; + + @ApiModelProperty(value = "创建时间") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Date createDate; + + @ApiModelProperty(value = "超级管理员 0:否 1:是") + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private Integer superAdmin; + + @ApiModelProperty(value = "角色ID列表") + private List roleIdList; + + @ApiModelProperty(value = "部门名称") + private String deptName; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/DictData.java b/ym-admin/src/main/java/com/cnbm/admin/entity/DictData.java new file mode 100644 index 0000000..e629104 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/DictData.java @@ -0,0 +1,17 @@ +package com.cnbm.admin.entity; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +/** + * @Author weihongyang + * @Date 2022/6/12 11:01 AM + * @Version 1.0 + */ +@Data +public class DictData { + @JsonIgnore + private Long dictTypeId; + private String dictLabel; + private String dictValue; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/DictType.java b/ym-admin/src/main/java/com/cnbm/admin/entity/DictType.java new file mode 100644 index 0000000..37ddd23 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/DictType.java @@ -0,0 +1,20 @@ +package com.cnbm.admin.entity; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 11:00 AM + * @Version 1.0 + */ +@Data +public class DictType { + @JsonIgnore + private Long id; + private String dictType; + private List dataList = new ArrayList<>(); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java b/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java new file mode 100644 index 0000000..6729ecd --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java @@ -0,0 +1,83 @@ +package com.cnbm.admin.entity; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author weihongyang + * @Date 2022/6/8 1:56 PM + * @Version 1.0 + */ +@Data +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class LoginUser implements UserDetails { + + private SysUserEntity sysUserEntity; + + private List permissions; + + public LoginUser(SysUserEntity sysUserEntity, List permissions) { + this.sysUserEntity = sysUserEntity; + this.permissions = permissions; + } + + @JsonIgnore + private List authorities; + @Override + public Collection getAuthorities() { + if(authorities!=null){ + return authorities; + } + //把permissions中String类型的权限信息封装成SimpleGrantedAuthority对象 +// authorities = new ArrayList<>(); +// for (String permission : permissions) { +// SimpleGrantedAuthority authority = new SimpleGrantedAuthority(permission); +// authorities.add(authority); +// } + authorities = permissions.stream() + .map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()); + return authorities; + } + + @Override + public String getPassword() { + return sysUserEntity.getPassword(); + } + + @Override + public String getUsername() { + return sysUserEntity.getUsername(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } +} + diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysDeptEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDeptEntity.java new file mode 100644 index 0000000..436cbbf --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDeptEntity.java @@ -0,0 +1,55 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:39 PM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_dept") +public class SysDeptEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 上级ID + */ + private Long pid; + /** + * 所有上级ID,用逗号分开 + */ + private String pids; + /** + * 部门名称 + */ + private String name; + /** + * 排序 + */ + private Integer sort; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + /** + * 上级部门名称 + */ + @TableField(exist = false) + private String parentName; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictDataEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictDataEntity.java new file mode 100644 index 0000000..2726cce --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictDataEntity.java @@ -0,0 +1,52 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:57 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_dict_data") +public class SysDictDataEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + /** + * 字典类型ID + */ + private Long dictTypeId; + /** + * 字典标签 + */ + private String dictLabel; + /** + * 字典值 + */ + private String dictValue; + /** + * 备注 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictTypeEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictTypeEntity.java new file mode 100644 index 0000000..103054e --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysDictTypeEntity.java @@ -0,0 +1,48 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:58 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_dict_type") +public class SysDictTypeEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + /** + * 字典类型 + */ + private String dictType; + /** + * 字典名称 + */ + private String dictName; + /** + * 备注 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogErrorEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogErrorEntity.java new file mode 100644 index 0000000..f2cbc59 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogErrorEntity.java @@ -0,0 +1,44 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:08 PM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_log_error") +public class SysLogErrorEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 请求URI + */ + private String requestUri; + /** + * 请求方式 + */ + private String requestMethod; + /** + * 请求参数 + */ + private String requestParams; + /** + * 用户代理 + */ + private String userAgent; + /** + * 操作IP + */ + private String ip; + /** + * 异常信息 + */ + private String errorInfo; + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogOperationEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogOperationEntity.java new file mode 100644 index 0000000..98cd9dc --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogOperationEntity.java @@ -0,0 +1,55 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:49 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_log_operation") +public class SysLogOperationEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 用户操作 + */ + private String operation; + /** + * 请求URI + */ + private String requestUri; + /** + * 请求方式 + */ + private String requestMethod; + /** + * 请求参数 + */ + private String requestParams; + /** + * 请求时长(毫秒) + */ + private Integer requestTime; + /** + * 用户代理 + */ + private String userAgent; + /** + * 操作IP + */ + private String ip; + /** + * 状态 0:失败 1:成功 + */ + private Integer status; + /** + * 用户名 + */ + private String creatorName; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysMenuEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysMenuEntity.java new file mode 100644 index 0000000..3843d0a --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysMenuEntity.java @@ -0,0 +1,67 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:28 PM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_menu") +public class SysMenuEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 父菜单ID,一级菜单为0 + */ + private Long pid; + /** + * 菜单名称 + */ + private String name; + /** + * 菜单URL + */ + private String url; + /** + * 授权(多个用逗号分隔,如:sys:user:list,sys:user:save) + */ + private String permissions; + /** + * 类型 0:菜单 1:按钮 + */ + private Integer type; + /** + * 菜单图标 + */ + private String icon; + /** + * 排序 + */ + private Integer sort; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + /** + * 上级菜单名称 + */ + @TableField(exist = false) + private String parentName; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysParamsEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysParamsEntity.java new file mode 100644 index 0000000..67aafbc --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysParamsEntity.java @@ -0,0 +1,50 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:22 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_params") +public class SysParamsEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 参数编码 + */ + private String paramCode; + /** + * 参数值 + */ + private String paramValue; + /** + * 类型 0:系统参数 1:非系统参数 + */ + private Integer paramType; + /** + * 备注 + */ + private String remark; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleDataScopeEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleDataScopeEntity.java new file mode 100644 index 0000000..7e73287 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleDataScopeEntity.java @@ -0,0 +1,28 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:14 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_role_data_scope") +public class SysRoleDataScopeEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + private Long roleId; + /** + * 部门ID + */ + private Long deptId; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleEntity.java new file mode 100644 index 0000000..b96a570 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleEntity.java @@ -0,0 +1,46 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:06 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_role") +public class SysRoleEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 角色名称 + */ + private String name; + /** + * 备注 + */ + private String remark; + /** + * 部门ID + */ + @TableField(fill = FieldFill.INSERT) + private Long deptId; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleMenuEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleMenuEntity.java new file mode 100644 index 0000000..caf8b8b --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleMenuEntity.java @@ -0,0 +1,27 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:16 PM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_role_menu") +public class SysRoleMenuEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + /** + * 角色ID + */ + private Long roleId; + /** + * 菜单ID + */ + private Long menuId; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleUserEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleUserEntity.java new file mode 100644 index 0000000..fd748f8 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysRoleUserEntity.java @@ -0,0 +1,29 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:34 PM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_role_user") +public class SysRoleUserEntity extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + private Long roleId; + /** + * 用户ID + */ + private Long userId; + +} + diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysUserEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysUserEntity.java new file mode 100644 index 0000000..22d9eef --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysUserEntity.java @@ -0,0 +1,80 @@ +package com.cnbm.admin.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.cnbm.common.entity.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/8 9:19 AM + * @Version 1.0 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("sys_user") +public class SysUserEntity extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户名 + */ + private String username; + /** + * 密码 + */ + private String password; + /** + * 姓名 + */ + private String realName; + /** + * 头像 + */ + private String headUrl; + /** + * 性别 0:男 1:女 2:保密 + */ + private Integer gender; + /** + * 邮箱 + */ + private String email; + /** + * 手机号 + */ + private String mobile; + /** + * 部门ID + */ + private Long deptId; + /** + * 超级管理员 0:否 1:是 + */ + private Integer superAdmin; + /** + * 状态 0:停用 1:正常 + */ + private Integer status; + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updater; + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateDate; + /** + * 部门名称 + */ + @TableField(exist=false) + private String deptName; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/enums/MenuTypeEnum.java b/ym-admin/src/main/java/com/cnbm/admin/enums/MenuTypeEnum.java new file mode 100644 index 0000000..2851fd5 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/enums/MenuTypeEnum.java @@ -0,0 +1,27 @@ +package com.cnbm.admin.enums; + +/** + * @Author weihongyang + * @Date 2022/6/10 3:01 PM + * @Version 1.0 + */ +public enum MenuTypeEnum { + /** + * 菜单 + */ + MENU(0), + /** + * 按钮 + */ + BUTTON(1); + + private int value; + + MenuTypeEnum(int value) { + this.value = value; + } + + public int value() { + return this.value; + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/enums/OperationStatusEnum.java b/ym-admin/src/main/java/com/cnbm/admin/enums/OperationStatusEnum.java new file mode 100644 index 0000000..032fc80 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/enums/OperationStatusEnum.java @@ -0,0 +1,27 @@ +package com.cnbm.admin.enums; + +/** + * @Author weihongyang + * @Date 2022/6/10 10:10 AM + * @Version 1.0 + */ +public enum OperationStatusEnum { + /** + * 失败 + */ + FAIL(0), + /** + * 成功 + */ + SUCCESS(1); + + private int value; + + OperationStatusEnum(int value) { + this.value = value; + } + + public int value() { + return this.value; + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/enums/SuperAdminEnum.java b/ym-admin/src/main/java/com/cnbm/admin/enums/SuperAdminEnum.java new file mode 100644 index 0000000..bde5082 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/enums/SuperAdminEnum.java @@ -0,0 +1,21 @@ +package com.cnbm.admin.enums; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:02 PM + * @Version 1.0 + */ +public enum SuperAdminEnum { + YES(1), + NO(0); + + private int value; + + SuperAdminEnum(int value) { + this.value = value; + } + + public int value() { + return this.value; + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java b/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java new file mode 100644 index 0000000..3c2b5d8 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/exception/RenExceptionHandler.java @@ -0,0 +1,87 @@ +package com.cnbm.admin.exception; + +import cn.hutool.core.map.MapUtil; +import com.cnbm.admin.entity.SysLogErrorEntity; +import com.cnbm.admin.service.SysLogErrorService; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.ExceptionUtils; +import com.cnbm.common.exception.RenException; +import com.cnbm.common.utils.HttpContextUtils; +import com.cnbm.common.utils.IpUtils; +import com.cnbm.common.utils.JsonUtils; +import com.cnbm.common.utils.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:05 PM + * @Version 1.0 + */ +//@RestControllerAdvice +//public class RenExceptionHandler { +// private static final Logger logger = LoggerFactory.getLogger(RenExceptionHandler.class); +// +// @Autowired +// private SysLogErrorService sysLogErrorService; +// +// /** +// * 处理自定义异常 +// */ +// @ExceptionHandler(RenException.class) +// public Result handleRenException(RenException ex){ +// Result result = new Result(); +// result.error(ex.getCode(), ex.getMsg()); +// +// return result; +// } +// +// @ExceptionHandler(DuplicateKeyException.class) +// public Result handleDuplicateKeyException(DuplicateKeyException ex){ +// Result result = new Result(); +// result.error(ErrorCode.DB_RECORD_EXISTS); +// +// return result; +// } +// +// @ExceptionHandler(Exception.class) +// public Result handleException(Exception ex){ +// logger.error(ex.getMessage(), ex); +// +// saveLog(ex); +// +// return new Result().error(); +// } +// +// /** +// * 保存异常日志 +// */ +// private void saveLog(Exception ex){ +// SysLogErrorEntity log = new SysLogErrorEntity(); +// +// //请求相关信息 +// HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); +// log.setIp(IpUtils.getIpAddr(request)); +// log.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); +// log.setRequestUri(request.getRequestURI()); +// log.setRequestMethod(request.getMethod()); +// Map params = HttpContextUtils.getParameterMap(request); +// if(MapUtil.isNotEmpty(params)){ +// log.setRequestParams(JsonUtils.toJsonString(params)); +// } +// +// //异常信息 +// log.setErrorInfo(ExceptionUtils.getErrorStackTrace(ex)); +// +// //保存 +// sysLogErrorService.save(log); +// } +//} diff --git a/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogErrorExcel.java b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogErrorExcel.java new file mode 100644 index 0000000..4cfbb17 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogErrorExcel.java @@ -0,0 +1,28 @@ +package com.cnbm.admin.execl; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:14 PM + * @Version 1.0 + */ +@Data +public class SysLogErrorExcel { + @Excel(name = "请求URI") + private String requestUri; + @Excel(name = "请求方式") + private String requestMethod; + @Excel(name = "请求参数") + private String requestParams; + @Excel(name = "User-Agent") + private String userAgent; + @Excel(name = "操作IP") + private String ip; + @Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss") + private Date createDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogOperationExcel.java b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogOperationExcel.java new file mode 100644 index 0000000..2431fd0 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogOperationExcel.java @@ -0,0 +1,36 @@ +package com.cnbm.admin.execl; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 10:06 AM + * @Version 1.0 + */ +@Data +public class SysLogOperationExcel { + @Excel(name = "用户操作") + private String operation; + @Excel(name = "请求URI") + private String requestUri; + @Excel(name = "请求方式") + private String requestMethod; + @Excel(name = "请求参数") + private String requestParams; + @Excel(name = "请求时长(毫秒)") + private Integer requestTime; + @Excel(name = "User-Agent") + private String userAgent; + @Excel(name = "操作IP") + private String ip; + @Excel(name = "状态", replace = {"失败_0", "成功_1"}) + private Integer status; + @Excel(name = "用户名") + private String creatorName; + @Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss") + private Date createDate; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/execl/SysParamsExcel.java b/ym-admin/src/main/java/com/cnbm/admin/execl/SysParamsExcel.java new file mode 100644 index 0000000..19e250e --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/execl/SysParamsExcel.java @@ -0,0 +1,20 @@ +package com.cnbm.admin.execl; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:26 AM + * @Version 1.0 + */ +@Data +public class SysParamsExcel { + @Excel(name = "参数编码") + private String paramCode; + @Excel(name = "参数值") + private String paramValue; + @Excel(name = "备注") + private String remark; + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/execl/SysUserExcel.java b/ym-admin/src/main/java/com/cnbm/admin/execl/SysUserExcel.java new file mode 100644 index 0000000..36aa0e1 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/execl/SysUserExcel.java @@ -0,0 +1,34 @@ +package com.cnbm.admin.execl; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:25 PM + * @Version 1.0 + */ +@Data +public class SysUserExcel { + @Excel(name = "用户名") + private String username; + @Excel(name = "姓名") + private String realName; + @Excel(name = "性别", replace = {"男_0", "女_1", "保密_2"}) + private Integer gender; + @Excel(name = "邮箱") + private String email; + @Excel(name = "手机号") + private String mobile; + @Excel(name = "部门名称") + private String deptName; + @Excel(name = "状态", replace = {"停用_0", "正常_1"}) + private Integer status; + @Excel(name = "备注") + private String remark; + @Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss") + private Date createDate; + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/filter/JwtAuthenticationTokenFilter.java b/ym-admin/src/main/java/com/cnbm/admin/filter/JwtAuthenticationTokenFilter.java new file mode 100644 index 0000000..3730eb8 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/filter/JwtAuthenticationTokenFilter.java @@ -0,0 +1,65 @@ +package com.cnbm.admin.filter; + +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.utils.JwtUtil; +import io.jsonwebtoken.Claims; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Objects; + +/** + * @Author weihongyang + * @Date 2022/6/8 1:51 PM + * @Version 1.0 + */ +@Component +public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { + + @Autowired + private RedisTemplate redisTemplate; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + //获取token +// String token = request.getHeader("Authorization"); + String token = request.getHeader("token"); + if (!StringUtils.hasText(token)) { + //放行 + filterChain.doFilter(request, response); + return; + } + //解析token + String userid; + try { + Claims claims = JwtUtil.parseJWT(token); + userid = claims.getSubject(); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("token非法"); + } + //从redis中获取用户信息 + String redisKey = "login:" + userid; + LoginUser loginUser = (LoginUser) redisTemplate.opsForValue().get(redisKey); + if(Objects.isNull(loginUser)){ + throw new RuntimeException("用户未登录"); + } + //存入SecurityContextHolder + //TODO 获取权限信息封装到Authentication中 + UsernamePasswordAuthenticationToken authenticationToken = + new UsernamePasswordAuthenticationToken(loginUser,null,loginUser.getAuthorities()); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + //放行 + filterChain.doFilter(request, response); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/handler/AccessDeniedHandlerImpl.java b/ym-admin/src/main/java/com/cnbm/admin/handler/AccessDeniedHandlerImpl.java new file mode 100644 index 0000000..45d58b0 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/handler/AccessDeniedHandlerImpl.java @@ -0,0 +1,30 @@ +package com.cnbm.admin.handler; + +import com.cnbm.admin.utils.ResponseResult; +import com.cnbm.admin.utils.WebUtils; +import com.cnbm.common.utils.JsonUtils; +import org.springframework.http.HttpStatus; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @Author weihongyang + * @Date 2022/6/9 11:55 AM + * @Version 1.0 + */ +@Component +public class AccessDeniedHandlerImpl implements AccessDeniedHandler { + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + ResponseResult result = new ResponseResult(HttpStatus.FORBIDDEN.value(),"您的权限不足"); + String json = JsonUtils.toJsonString(result); + //处理异常 + WebUtils.renderString(response,json); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/handler/AuthenticationEntryPointImpl.java b/ym-admin/src/main/java/com/cnbm/admin/handler/AuthenticationEntryPointImpl.java new file mode 100644 index 0000000..e982cae --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/handler/AuthenticationEntryPointImpl.java @@ -0,0 +1,30 @@ +package com.cnbm.admin.handler; + +import com.cnbm.admin.utils.ResponseResult; +import com.cnbm.admin.utils.WebUtils; +import com.cnbm.common.utils.JsonUtils; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @Author weihongyang + * @Date 2022/6/9 1:27 PM + * @Version 1.0 + */ +@Component +public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint { + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { + ResponseResult result = new ResponseResult(HttpStatus.UNAUTHORIZED.value(),"用户认证失败请查询登录"); + String json = JsonUtils.toJsonString(result); + //处理异常 + WebUtils.renderString(response,json); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/params/LoginParam.java b/ym-admin/src/main/java/com/cnbm/admin/params/LoginParam.java new file mode 100644 index 0000000..9f6ad5f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/params/LoginParam.java @@ -0,0 +1,36 @@ +package com.cnbm.admin.params; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author weihongyang + * @Date 2022/6/8 9:29 AM + * @Version 1.0 + */ +@Data +@ApiModel(value = "登录表单") +public class LoginParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "用户名", required = true) + @NotBlank(message="用户名不能为空") + private String username; + + @ApiModelProperty(value = "密码" , required = true) + @NotBlank(message="密码不能为空") + private String password; + + @ApiModelProperty(value = "验证码" , required = true) + @NotBlank(message="验证码不能为空") + private String captcha; + + @ApiModelProperty(value = "唯一标识" , required = true) + @NotBlank(message="uuid不能为空") + private String uuid; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/redis/SysParamsRedis.java b/ym-admin/src/main/java/com/cnbm/admin/redis/SysParamsRedis.java new file mode 100644 index 0000000..8914741 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/redis/SysParamsRedis.java @@ -0,0 +1,36 @@ +package com.cnbm.admin.redis; + +import com.cnbm.common.redis.RedisKeys; +import com.cnbm.common.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:48 AM + * @Version 1.0 + */ +@Component +public class SysParamsRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] paramCodes) { + String key = RedisKeys.getSysParamsKey(); + redisUtils.hDel(key, paramCodes); + } + + public void set(String paramCode, String paramValue){ + if(paramValue == null){ + return ; + } + String key = RedisKeys.getSysParamsKey(); + redisUtils.hSet(key, paramCode, paramValue); + } + + public String get(String paramCode){ + String key = RedisKeys.getSysParamsKey(); + return (String)redisUtils.hGet(key, paramCode); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/CaptchaService.java b/ym-admin/src/main/java/com/cnbm/admin/service/CaptchaService.java new file mode 100644 index 0000000..5415ece --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/CaptchaService.java @@ -0,0 +1,9 @@ +package com.cnbm.admin.service; + +/** + * @Author weihongyang + * @Date 2022/6/8 8:55 AM + * @Version 1.0 + */ +public interface CaptchaService { +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/LoginService.java b/ym-admin/src/main/java/com/cnbm/admin/service/LoginService.java new file mode 100644 index 0000000..2dfce88 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/LoginService.java @@ -0,0 +1,16 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.params.LoginParam; +import com.cnbm.admin.utils.ResponseResult; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Author weihongyang + * @Date 2022/6/8 9:17 AM + * @Version 1.0 + */ +public interface LoginService { + + ResponseResult login(HttpServletRequest request, LoginParam loginParam); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysDeptService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysDeptService.java new file mode 100644 index 0000000..9021e99 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysDeptService.java @@ -0,0 +1,32 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysDeptDTO; +import com.cnbm.admin.entity.SysDeptEntity; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:38 PM + * @Version 1.0 + */ +public interface SysDeptService extends BaseService { + + List list(Map params); + + SysDeptDTO get(Long id); + + void save(SysDeptDTO dto); + + void update(SysDeptDTO dto); + + void delete(Long id); + + /** + * 根据部门ID,获取本部门及子部门ID列表 + * @param id 部门ID + */ + List getSubDeptIdList(Long id); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysDictDataService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysDictDataService.java new file mode 100644 index 0000000..d0fb717 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysDictDataService.java @@ -0,0 +1,27 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysDictDataDTO; +import com.cnbm.admin.entity.SysDictDataEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:58 AM + * @Version 1.0 + */ +public interface SysDictDataService extends BaseService { + + PageData page(Map params); + + SysDictDataDTO get(Long id); + + void save(SysDictDataDTO dto); + + void update(SysDictDataDTO dto); + + void delete(Long[] ids); + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysDictTypeService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysDictTypeService.java new file mode 100644 index 0000000..d2c329f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysDictTypeService.java @@ -0,0 +1,34 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysDictTypeDTO; +import com.cnbm.admin.entity.DictType; +import com.cnbm.admin.entity.SysDictTypeEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:58 AM + * @Version 1.0 + */ +public interface SysDictTypeService extends BaseService { + + PageData page(Map params); + + SysDictTypeDTO get(Long id); + + void save(SysDictTypeDTO dto); + + void update(SysDictTypeDTO dto); + + void delete(Long[] ids); + + /** + * 获取所有字典 + */ + List getAllList(); + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysLogErrorService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogErrorService.java new file mode 100644 index 0000000..f4f9647 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogErrorService.java @@ -0,0 +1,24 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysLogErrorDTO; +import com.cnbm.admin.entity.SysLogErrorEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:08 PM + * @Version 1.0 + */ +public interface SysLogErrorService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + void save(SysLogErrorEntity entity); + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysLogOperationService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogOperationService.java new file mode 100644 index 0000000..c228281 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogOperationService.java @@ -0,0 +1,23 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysLogOperationDTO; +import com.cnbm.admin.entity.SysLogOperationEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:52 AM + * @Version 1.0 + */ +public interface SysLogOperationService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + void save(SysLogOperationEntity entity); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysMenuService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysMenuService.java new file mode 100644 index 0000000..5c32120 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysMenuService.java @@ -0,0 +1,48 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysMenuDTO; +import com.cnbm.admin.entity.SysMenuEntity; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Set; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:34 PM + * @Version 1.0 + */ +public interface SysMenuService extends BaseService { + + SysMenuDTO get(Long id); + + void save(SysMenuDTO dto); + + void update(SysMenuDTO dto); + + void delete(Long id); + + /** + * 菜单列表 + * + * @param type 菜单类型 + */ + List getAllMenuList(Integer type); + + /** + * 用户菜单列表 + * + * @param user 用户 + * @param type 菜单类型 + */ + List getUserMenuList(SysUserEntity user, Integer type); + + /** + * 根据父菜单,查询子菜单 + * @param pid 父菜单ID + */ + List getListPid(Long pid); + + Set getUserPermissions(SysUserEntity user); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysParamsService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysParamsService.java new file mode 100644 index 0000000..bbc247c --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysParamsService.java @@ -0,0 +1,50 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysParamsDTO; +import com.cnbm.admin.entity.SysParamsEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:23 AM + * @Version 1.0 + */ +public interface SysParamsService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + SysParamsDTO get(Long id); + + void save(SysParamsDTO dto); + + void update(SysParamsDTO dto); + + void delete(Long[] ids); + + /** + * 根据参数编码,获取参数的value值 + * + * @param paramCode 参数编码 + */ + String getValue(String paramCode); + + /** + * 根据参数编码,获取value的Object对象 + * @param paramCode 参数编码 + * @param clazz Object对象 + */ + T getValueObject(String paramCode, Class clazz); + + /** + * 根据参数编码,更新value + * @param paramCode 参数编码 + * @param paramValue 参数值 + */ + int updateValueByCode(String paramCode, String paramValue); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleDataScopeService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleDataScopeService.java new file mode 100644 index 0000000..d980065 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleDataScopeService.java @@ -0,0 +1,32 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.entity.SysRoleDataScopeEntity; +import com.cnbm.common.service.BaseService; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:13 AM + * @Version 1.0 + */ +public interface SysRoleDataScopeService extends BaseService { + + /** + * 根据角色ID,获取部门ID列表 + */ + List getDeptIdList(Long roleId); + + /** + * 保存或修改 + * @param roleId 角色ID + * @param deptIdList 部门ID列表 + */ + void saveOrUpdate(Long roleId, List deptIdList); + + /** + * 根据角色id,删除角色数据权限关系 + * @param roleId 角色ids + */ + void deleteByRoleIds(Long[] roleId); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleMenuService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleMenuService.java new file mode 100644 index 0000000..cc7c5c0 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleMenuService.java @@ -0,0 +1,38 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.entity.SysRoleMenuEntity; +import com.cnbm.common.service.BaseService; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 3:02 PM + * @Version 1.0 + */ +public interface SysRoleMenuService extends BaseService { + + /** + * 根据角色ID,获取菜单ID列表 + */ + List getMenuIdList(Long roleId); + + /** + * 保存或修改 + * @param roleId 角色ID + * @param menuIdList 菜单ID列表 + */ + void saveOrUpdate(Long roleId, List menuIdList); + + /** + * 根据角色id,删除角色菜单关系 + * @param roleIds 角色ids + */ + void deleteByRoleIds(Long[] roleIds); + + /** + * 根据菜单id,删除角色菜单关系 + * @param menuId 菜单id + */ + void deleteByMenuId(Long menuId); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleService.java new file mode 100644 index 0000000..0969dad --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleService.java @@ -0,0 +1,30 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysRoleDTO; +import com.cnbm.admin.entity.SysRoleEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:07 AM + * @Version 1.0 + */ +public interface SysRoleService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + SysRoleDTO get(Long id); + + void save(SysRoleDTO dto); + + void update(SysRoleDTO dto); + + void delete(Long[] ids); + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleUserService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleUserService.java new file mode 100644 index 0000000..e6c2c85 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysRoleUserService.java @@ -0,0 +1,39 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.entity.SysRoleUserEntity; +import com.cnbm.common.service.BaseService; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:33 PM + * @Version 1.0 + */ +public interface SysRoleUserService extends BaseService { + + /** + * 保存或修改 + * @param userId 用户ID + * @param roleIdList 角色ID列表 + */ + void saveOrUpdate(Long userId, List roleIdList); + + /** + * 根据角色ids,删除角色用户关系 + * @param roleIds 角色ids + */ + void deleteByRoleIds(Long[] roleIds); + + /** + * 根据用户id,删除角色用户关系 + * @param userIds 用户ids + */ + void deleteByUserIds(Long[] userIds); + + /** + * 角色ID列表 + * @param userId 用户ID + */ + List getRoleIdList(Long userId); +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysUserService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysUserService.java new file mode 100644 index 0000000..cb0ec28 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysUserService.java @@ -0,0 +1,49 @@ +package com.cnbm.admin.service; + +import com.cnbm.admin.dto.SysUserDTO; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:24 PM + * @Version 1.0 + */ +public interface SysUserService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + SysUserDTO get(Long id); + + SysUserDTO getByUsername(String username); + + void save(SysUserDTO dto); + + void update(SysUserDTO dto); + + void delete(Long[] ids); + + /** + * 修改密码 + * @param id 用户ID + * @param newPassword 新密码 + */ + void updatePassword(Long id, String newPassword); + + /** + * 根据部门ID,查询用户数 + */ + int getCountByDeptId(Long deptId); + + /** + * 根据部门ID,查询用户Id列表 + */ + List getUserIdListByDeptId(List deptIdList); + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..8425e2e --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java @@ -0,0 +1,51 @@ +package com.cnbm.admin.service.impl; + +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.params.LoginParam; +import com.cnbm.admin.utils.JwtUtil; +import com.cnbm.admin.service.LoginService; +import com.cnbm.admin.utils.ResponseResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * @Author weihongyang + * @Date 2022/6/8 9:17 AM + * @Version 1.0 + */ +@Service +public class LoginServiceImpl implements LoginService { + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private AuthenticationManager authenticationManager; + + @Override + public ResponseResult login(HttpServletRequest request, LoginParam loginParam) { + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginParam.getUsername(),loginParam.getPassword()); + Authentication authenticate = authenticationManager.authenticate(authenticationToken); + if (Objects.isNull(authenticate)) { + throw new RuntimeException("登录失败"); + } + //如果认证通过了,使用userid生成一个jwt jwt存入ResponseResult返回 + LoginUser loginUser = (LoginUser) authenticate.getPrincipal(); + String userid = loginUser.getSysUserEntity().getId().toString(); + String jwt = JwtUtil.createJWT(userid); + Map map = new HashMap<>(); + map.put("token",jwt); + //把完整的用户信息存入redis userid作为key + redisTemplate.opsForValue().set("login:"+userid,loginUser); + return new ResponseResult(200,"登录成功",map); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDeptServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDeptServiceImpl.java new file mode 100644 index 0000000..0e85c02 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,165 @@ +package com.cnbm.admin.service.impl; + +import com.cnbm.admin.dao.SysDeptDao; +import com.cnbm.admin.dao.SysUserDao; +import com.cnbm.admin.dto.SysDeptDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysDeptEntity; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.enums.SuperAdminEnum; +import com.cnbm.admin.service.SysDeptService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.RenException; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import com.cnbm.common.utils.TreeUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:38 PM + * @Version 1.0 + */ +@Service +public class SysDeptServiceImpl extends BaseServiceImpl implements SysDeptService { + @Autowired + private SysUserDao sysUserDao; + + @Override + public List list(Map params) { + //普通管理员,只能查询所属部门及子部门的数据 + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", getSubDeptIdList(user.getDeptId())); + } + + //查询部门列表 + List entityList = baseDao.getList(params); + + List dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class); + + return TreeUtils.build(dtoList); + } + + @Override + public SysDeptDTO get(Long id) { + //超级管理员,部门ID为null + if(id == null){ + return null; + } + + SysDeptEntity entity = baseDao.getById(id); + + return ConvertUtils.sourceToTarget(entity, SysDeptDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysDeptDTO dto) { + SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); + + entity.setPids(getPidList(entity.getPid())); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysDeptDTO dto) { + SysDeptEntity entity = ConvertUtils.sourceToTarget(dto, SysDeptEntity.class); + + //上级部门不能为自身 + if(entity.getId().equals(entity.getPid())){ + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } + + //上级部门不能为下级部门 + List subDeptList = getSubDeptIdList(entity.getId()); + if(subDeptList.contains(entity.getPid())){ + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } + + entity.setPids(getPidList(entity.getPid())); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + //判断是否有子部门 + List subList = getSubDeptIdList(id); + if(subList.size() > 1){ + throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); + } + + //判断部门下面是否有用户 + int count = sysUserDao.getCountByDeptId(id); + if(count > 0){ + throw new RenException(ErrorCode.DEPT_USER_DELETE_ERROR); + } + + //删除 + baseDao.deleteById(id); + } + + @Override + public List getSubDeptIdList(Long id) { + List deptIdList = baseDao.getSubDeptIdList("%" + id + "%"); + deptIdList.add(id); + + return deptIdList; + } + + /** + * 获取所有上级部门ID + * @param pid 上级ID + */ + private String getPidList(Long pid){ + //顶级部门,无上级部门 + if(Constant.DEPT_ROOT.equals(pid)){ + return Constant.DEPT_ROOT + ""; + } + + //所有部门的id、pid列表 + List deptList = baseDao.getIdAndPidList(); + + //list转map + Map map = new HashMap<>(deptList.size()); + for(SysDeptEntity entity : deptList){ + map.put(entity.getId(), entity); + } + + //递归查询所有上级部门ID列表 + List pidList = new ArrayList<>(); + getPidTree(pid, map, pidList); + + return StringUtils.join(pidList, ","); + } + + private void getPidTree(Long pid, Map map, List pidList) { + //顶级部门,无上级部门 + if(Constant.DEPT_ROOT.equals(pid)){ + return ; + } + + //上级部门存在 + SysDeptEntity parent = map.get(pid); + if(parent != null){ + getPidTree(parent.getPid(), map, pidList); + } + + pidList.add(pid); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictDataServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictDataServiceImpl.java new file mode 100644 index 0000000..f3b62ae --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictDataServiceImpl.java @@ -0,0 +1,80 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysDictDataDao; +import com.cnbm.admin.dto.SysDictDataDTO; +import com.cnbm.admin.entity.SysDictDataEntity; +import com.cnbm.admin.service.SysDictDataService; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:59 AM + * @Version 1.0 + */ +@Service +public class SysDictDataServiceImpl extends BaseServiceImpl implements SysDictDataService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, "sort", true), + getWrapper(params) + ); + + return getPageData(page, SysDictDataDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String dictTypeId = (String) params.get("dictTypeId"); + String dictLabel = (String) params.get("dictLabel"); + String dictValue = (String) params.get("dictValue"); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("dict_type_id", dictTypeId); + wrapper.like(StringUtils.isNotBlank(dictLabel), "dict_label", dictLabel); + wrapper.like(StringUtils.isNotBlank(dictValue), "dict_value", dictValue); + + return wrapper; + } + + @Override + public SysDictDataDTO get(Long id) { + SysDictDataEntity entity = baseDao.selectById(id); + + return ConvertUtils.sourceToTarget(entity, SysDictDataDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysDictDataDTO dto) { + SysDictDataEntity entity = ConvertUtils.sourceToTarget(dto, SysDictDataEntity.class); + + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysDictDataDTO dto) { + SysDictDataEntity entity = ConvertUtils.sourceToTarget(dto, SysDictDataEntity.class); + + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除 + deleteBatchIds(Arrays.asList(ids)); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictTypeServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictTypeServiceImpl.java new file mode 100644 index 0000000..110d858 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysDictTypeServiceImpl.java @@ -0,0 +1,98 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysDictDataDao; +import com.cnbm.admin.dao.SysDictTypeDao; +import com.cnbm.admin.dto.SysDictTypeDTO; +import com.cnbm.admin.entity.DictData; +import com.cnbm.admin.entity.DictType; +import com.cnbm.admin.entity.SysDictTypeEntity; +import com.cnbm.admin.service.SysDictTypeService; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:59 AM + * @Version 1.0 + */ +@Service +public class SysDictTypeServiceImpl extends BaseServiceImpl implements SysDictTypeService { + @Autowired + private SysDictDataDao sysDictDataDao; + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, "sort", true), + getWrapper(params) + ); + + return getPageData(page, SysDictTypeDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String dictType = (String) params.get("dictType"); + String dictName = (String) params.get("dictName"); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StringUtils.isNotBlank(dictType), "dict_type", dictType); + wrapper.like(StringUtils.isNotBlank(dictName), "dict_name", dictName); + + return wrapper; + } + + @Override + public SysDictTypeDTO get(Long id) { + SysDictTypeEntity entity = baseDao.selectById(id); + + return ConvertUtils.sourceToTarget(entity, SysDictTypeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysDictTypeDTO dto) { + SysDictTypeEntity entity = ConvertUtils.sourceToTarget(dto, SysDictTypeEntity.class); + + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysDictTypeDTO dto) { + SysDictTypeEntity entity = ConvertUtils.sourceToTarget(dto, SysDictTypeEntity.class); + + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除 + deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public List getAllList() { + List typeList = baseDao.getDictTypeList(); + List dataList = sysDictDataDao.getDictDataList(); + for(DictType type : typeList){ + for(DictData data : dataList){ + if(type.getId().equals(data.getDictTypeId())){ + type.getDataList().add(data); + } + } + } + return typeList; + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogErrorServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogErrorServiceImpl.java new file mode 100644 index 0000000..80cee15 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogErrorServiceImpl.java @@ -0,0 +1,55 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysLogErrorDao; +import com.cnbm.admin.dto.SysLogErrorDTO; +import com.cnbm.admin.entity.SysLogErrorEntity; +import com.cnbm.admin.service.SysLogErrorService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:09 PM + * @Version 1.0 + */ +@Service +public class SysLogErrorServiceImpl extends BaseServiceImpl implements SysLogErrorService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); + + return getPageData(page, SysLogErrorDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, SysLogErrorDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + QueryWrapper wrapper = new QueryWrapper<>(); + return wrapper; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysLogErrorEntity entity) { + insert(entity); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogOperationServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogOperationServiceImpl.java new file mode 100644 index 0000000..0059927 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogOperationServiceImpl.java @@ -0,0 +1,60 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysLogOperationDao; +import com.cnbm.admin.dto.SysLogOperationDTO; +import com.cnbm.admin.entity.SysLogOperationEntity; +import com.cnbm.admin.service.SysLogOperationService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:52 AM + * @Version 1.0 + */ +@Service +public class SysLogOperationServiceImpl extends BaseServiceImpl implements SysLogOperationService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); + + return getPageData(page, SysLogOperationDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, SysLogOperationDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String status = (String) params.get("status"); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(status), "status", status); + + return wrapper; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysLogOperationEntity entity) { + insert(entity); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysMenuServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysMenuServiceImpl.java new file mode 100644 index 0000000..b07c7f7 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysMenuServiceImpl.java @@ -0,0 +1,136 @@ +package com.cnbm.admin.service.impl; + +import com.cnbm.admin.dao.SysMenuDao; +import com.cnbm.admin.dto.SysMenuDTO; +import com.cnbm.admin.entity.SysMenuEntity; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.enums.SuperAdminEnum; +import com.cnbm.admin.service.SysMenuService; +import com.cnbm.admin.service.SysRoleMenuService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.RenException; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import com.cnbm.common.utils.TreeUtils; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:35 PM + * @Version 1.0 + */ +@Service +@Log4j2 +public class SysMenuServiceImpl extends BaseServiceImpl implements SysMenuService { + @Autowired + private SysRoleMenuService sysRoleMenuService; + + @Autowired + private SysMenuDao sysMenuDao; + + @Override + public SysMenuDTO get(Long id) { + SysMenuEntity entity = baseDao.getById(id); + + SysMenuDTO dto = ConvertUtils.sourceToTarget(entity, SysMenuDTO.class); + + return dto; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysMenuDTO dto) { + SysMenuEntity entity = ConvertUtils.sourceToTarget(dto, SysMenuEntity.class); + + //保存菜单 + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysMenuDTO dto) { + SysMenuEntity entity = ConvertUtils.sourceToTarget(dto, SysMenuEntity.class); + + //上级菜单不能为自身 + if(entity.getId().equals(entity.getPid())){ + throw new RenException(ErrorCode.SUPERIOR_MENU_ERROR); + } + + //更新菜单 + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long id) { + //删除菜单 + deleteById(id); + + //删除角色菜单关系 + sysRoleMenuService.deleteByMenuId(id); + } + + @Override + public List getAllMenuList(Integer type) { + List menuList = baseDao.getMenuList(type); + + List dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class); + + return TreeUtils.build(dtoList, Constant.MENU_ROOT); + } + + @Override + public List getUserMenuList(SysUserEntity user, Integer type) { + List menuList = new ArrayList<>(); + + + + //系统管理员,拥有最高权限 + if(!Objects.isNull(user.getSuperAdmin()) && user.getSuperAdmin() == SuperAdminEnum.YES.value()){ + menuList = baseDao.getMenuList(type); + }else { + menuList = baseDao.getUserMenuList(user.getId(), type); + } + + List dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class); + + return TreeUtils.build(dtoList); + } + + @Override + public List getListPid(Long pid) { + List menuList = baseDao.getListPid(pid); + + return ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class); + } + + @Override + public Set getUserPermissions(SysUserEntity user) { + //系统管理员,拥有最高权限 + List permissionsList; + if(user.getSuperAdmin() == SuperAdminEnum.YES.value()) { + permissionsList = sysMenuDao.getPermissionsList(); + }else{ + permissionsList = sysMenuDao.getUserPermissionsList(user.getId()); + } + + //用户权限列表 + Set permsSet = new HashSet<>(); + for(String permissions : permissionsList){ + if(StringUtils.isBlank(permissions)){ + continue; + } + permsSet.addAll(Arrays.asList(permissions.trim().split(","))); + } + + return permsSet; + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysParamsServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysParamsServiceImpl.java new file mode 100644 index 0000000..de99d16 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysParamsServiceImpl.java @@ -0,0 +1,133 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysParamsDao; +import com.cnbm.admin.dto.SysParamsDTO; +import com.cnbm.admin.entity.SysParamsEntity; +import com.cnbm.admin.redis.SysParamsRedis; +import com.cnbm.admin.service.SysParamsService; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.RenException; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import com.cnbm.common.utils.JsonUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:24 AM + * @Version 1.0 + */ +@Service +public class SysParamsServiceImpl extends BaseServiceImpl implements SysParamsService { + @Autowired + private SysParamsRedis sysParamsRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); + + return getPageData(page, SysParamsDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, SysParamsDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String paramCode = (String) params.get("paramCode"); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("param_type", 1); + wrapper.like(StringUtils.isNotBlank(paramCode), "param_code", paramCode); + + return wrapper; + } + + @Override + public SysParamsDTO get(Long id) { + SysParamsEntity entity = baseDao.selectById(id); + + return ConvertUtils.sourceToTarget(entity, SysParamsDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysParamsDTO dto) { + SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class); + insert(entity); + + sysParamsRedis.set(entity.getParamCode(), entity.getParamValue()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysParamsDTO dto) { + SysParamsEntity entity = ConvertUtils.sourceToTarget(dto, SysParamsEntity.class); + updateById(entity); + + sysParamsRedis.set(entity.getParamCode(), entity.getParamValue()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除Redis数据 + List paramCodeList = baseDao.getParamCodeList(ids); + String[] paramCodes = paramCodeList.toArray(new String[paramCodeList.size()]); + sysParamsRedis.delete(paramCodes); + + //删除 + deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public String getValue(String paramCode) { + String paramValue = sysParamsRedis.get(paramCode); + if(paramValue == null){ + paramValue = baseDao.getValueByCode(paramCode); + + sysParamsRedis.set(paramCode, paramValue); + } + return paramValue; + } + + @Override + public T getValueObject(String paramCode, Class clazz) { + String paramValue = getValue(paramCode); + if(StringUtils.isNotBlank(paramValue)){ + return JsonUtils.parseObject(paramValue, clazz); + } + + try { + return clazz.newInstance(); + } catch (Exception e) { + throw new RenException(ErrorCode.PARAMS_GET_ERROR); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int updateValueByCode(String paramCode, String paramValue) { + int count = baseDao.updateValueByCode(paramCode, paramValue); + sysParamsRedis.set(paramCode, paramValue); + return count; + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleDataScopeServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleDataScopeServiceImpl.java new file mode 100644 index 0000000..1c7c21f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleDataScopeServiceImpl.java @@ -0,0 +1,53 @@ +package com.cnbm.admin.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.cnbm.admin.dao.SysRoleDataScopeDao; +import com.cnbm.admin.entity.SysRoleDataScopeEntity; +import com.cnbm.admin.service.SysRoleDataScopeService; +import com.cnbm.common.service.impl.BaseServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:13 AM + * @Version 1.0 + */ +@Service +public class SysRoleDataScopeServiceImpl extends BaseServiceImpl + implements SysRoleDataScopeService { + + @Override + public List getDeptIdList(Long roleId) { + return baseDao.getDeptIdList(roleId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveOrUpdate(Long roleId, List deptIdList) { + //先删除角色数据权限关系 + deleteByRoleIds(new Long[]{roleId}); + + //角色没有一个数据权限的情况 + if(CollUtil.isEmpty(deptIdList)){ + return ; + } + + //保存角色数据权限关系 + for(Long deptId : deptIdList){ + SysRoleDataScopeEntity sysRoleDataScopeEntity = new SysRoleDataScopeEntity(); + sysRoleDataScopeEntity.setDeptId(deptId); + sysRoleDataScopeEntity.setRoleId(roleId); + + //保存 + insert(sysRoleDataScopeEntity); + } + } + + @Override + public void deleteByRoleIds(Long[] roleIds) { + baseDao.deleteByRoleIds(roleIds); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleMenuServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleMenuServiceImpl.java new file mode 100644 index 0000000..5a81e26 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleMenuServiceImpl.java @@ -0,0 +1,60 @@ +package com.cnbm.admin.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.cnbm.admin.dao.SysRoleMenuDao; +import com.cnbm.admin.entity.SysRoleMenuEntity; +import com.cnbm.admin.service.SysRoleMenuService; +import com.cnbm.common.service.impl.BaseServiceImpl; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 3:04 PM + * @Version 1.0 + */ +@Service +public class SysRoleMenuServiceImpl extends BaseServiceImpl implements SysRoleMenuService { + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveOrUpdate(Long roleId, List menuIdList) { + //先删除角色菜单关系 + deleteByRoleIds(new Long[]{roleId}); + + //角色没有一个菜单权限的情况 + if(CollUtil.isEmpty(menuIdList)){ + return ; + } + + //保存角色菜单关系 + for(Long menuId : menuIdList){ + SysRoleMenuEntity sysRoleMenuEntity = new SysRoleMenuEntity(); + sysRoleMenuEntity.setMenuId(menuId); + sysRoleMenuEntity.setRoleId(roleId); + + //保存 + insert(sysRoleMenuEntity); + } + } + + @Override + public List getMenuIdList(Long roleId){ + return baseDao.getMenuIdList(roleId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByRoleIds(Long[] roleIds) { + baseDao.deleteByRoleIds(roleIds); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByMenuId(Long menuId) { + baseDao.deleteByMenuId(menuId); + } + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleServiceImpl.java new file mode 100644 index 0000000..c0671b2 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,132 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysRoleDao; +import com.cnbm.admin.dto.SysRoleDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysRoleEntity; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.enums.SuperAdminEnum; +import com.cnbm.admin.service.*; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @Author weihongyang + * @Date 2022/6/12 10:08 AM + * @Version 1.0 + */ +@Service +public class SysRoleServiceImpl extends BaseServiceImpl implements SysRoleService { + @Autowired + private SysRoleMenuService sysRoleMenuService; + @Autowired + private SysRoleDataScopeService sysRoleDataScopeService; + @Autowired + private SysRoleUserService sysRoleUserService; + @Autowired + private SysDeptService sysDeptService; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); + + return getPageData(page, SysRoleDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, SysRoleDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String name = (String)params.get("name"); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StringUtils.isNotBlank(name), "name", name); + + //普通管理员,只能查询所属部门及子部门的数据 + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + if(!Objects.isNull(user.getSuperAdmin()) && user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + List deptIdList = sysDeptService.getSubDeptIdList(user.getDeptId()); + wrapper.in(deptIdList != null, "dept_id", deptIdList); + } + + return wrapper; + } + + @Override + public SysRoleDTO get(Long id) { + SysRoleEntity entity = baseDao.selectById(id); + + return ConvertUtils.sourceToTarget(entity, SysRoleDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysRoleDTO dto) { + SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); + + //保存角色 + insert(entity); + + //保存角色菜单关系 + sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); + + //保存角色数据权限关系 + sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysRoleDTO dto) { + SysRoleEntity entity = ConvertUtils.sourceToTarget(dto, SysRoleEntity.class); + + //更新角色 + updateById(entity); + + //更新角色菜单关系 + sysRoleMenuService.saveOrUpdate(entity.getId(), dto.getMenuIdList()); + + //更新角色数据权限关系 + sysRoleDataScopeService.saveOrUpdate(entity.getId(), dto.getDeptIdList()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + //删除角色 + baseDao.deleteBatchIds(Arrays.asList(ids)); + + //删除角色用户关系 + sysRoleUserService.deleteByRoleIds(ids); + + //删除角色菜单关系 + sysRoleMenuService.deleteByRoleIds(ids); + + //删除角色数据权限关系 + sysRoleDataScopeService.deleteByRoleIds(ids); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleUserServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleUserServiceImpl.java new file mode 100644 index 0000000..c130619 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysRoleUserServiceImpl.java @@ -0,0 +1,56 @@ +package com.cnbm.admin.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.cnbm.admin.dao.SysRoleUserDao; +import com.cnbm.admin.entity.SysRoleUserEntity; +import com.cnbm.admin.service.SysRoleUserService; +import com.cnbm.common.service.impl.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:34 PM + * @Version 1.0 + */ +@Service +public class SysRoleUserServiceImpl extends BaseServiceImpl implements SysRoleUserService { + + @Override + public void saveOrUpdate(Long userId, List roleIdList) { + //先删除角色用户关系 + deleteByUserIds(new Long[]{userId}); + + //用户没有一个角色权限的情况 + if(CollUtil.isEmpty(roleIdList)){ + return ; + } + + //保存角色用户关系 + for(Long roleId : roleIdList){ + SysRoleUserEntity sysRoleUserEntity = new SysRoleUserEntity(); + sysRoleUserEntity.setUserId(userId); + sysRoleUserEntity.setRoleId(roleId); + + //保存 + insert(sysRoleUserEntity); + } + } + + @Override + public void deleteByRoleIds(Long[] roleIds) { + baseDao.deleteByRoleIds(roleIds); + } + + @Override + public void deleteByUserIds(Long[] userIds) { + baseDao.deleteByUserIds(userIds); + } + + @Override + public List getRoleIdList(Long userId) { + + return baseDao.getRoleIdList(userId); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysUserServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..f5380ed --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysUserServiceImpl.java @@ -0,0 +1,154 @@ +package com.cnbm.admin.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.cnbm.admin.dao.SysUserDao; +import com.cnbm.admin.dto.SysUserDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.enums.SuperAdminEnum; +import com.cnbm.admin.service.SysDeptService; +import com.cnbm.admin.service.SysRoleUserService; +import com.cnbm.admin.service.SysUserService; +import com.cnbm.admin.utils.PasswordUtils; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.impl.BaseServiceImpl; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:24 PM + * @Version 1.0 + */ +@Service +public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { + @Autowired + private SysRoleUserService sysRoleUserService; + @Autowired + private SysDeptService sysDeptService; + + @Override + public PageData page(Map params) { + //转换成like + paramsToLike(params, "username"); + + //分页 + IPage page = getPage(params, Constant.CREATE_DATE, false); + + //普通管理员,只能查询所属部门及子部门的数据 + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); + } + + //查询 + List list = baseDao.getList(params); + + return getPageData(list, page.getTotal(), SysUserDTO.class); + } + + @Override + public List list(Map params) { + //普通管理员,只能查询所属部门及子部门的数据 + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + SysUserEntity user = loginUser.getSysUserEntity(); + if(user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", sysDeptService.getSubDeptIdList(user.getDeptId())); + } + + List entityList = baseDao.getList(params); + + return ConvertUtils.sourceToTarget(entityList, SysUserDTO.class); + } + + @Override + public SysUserDTO get(Long id) { + SysUserEntity entity = baseDao.getById(id); + + return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); + } + + @Override + public SysUserDTO getByUsername(String username) { + SysUserEntity entity = baseDao.getByUsername(username); + return ConvertUtils.sourceToTarget(entity, SysUserDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(SysUserDTO dto) { + SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); + + //密码加密 + String password = PasswordUtils.encode(entity.getPassword()); + entity.setPassword(password); + + //保存用户 + entity.setSuperAdmin(SuperAdminEnum.NO.value()); + insert(entity); + + //保存角色用户关系 + sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(SysUserDTO dto) { + SysUserEntity entity = ConvertUtils.sourceToTarget(dto, SysUserEntity.class); + + //密码加密 + if(StringUtils.isBlank(dto.getPassword())){ + entity.setPassword(null); + }else{ + String password = PasswordUtils.encode(entity.getPassword()); + entity.setPassword(password); + } + + //更新用户 + updateById(entity); + + //更新角色用户关系 + sysRoleUserService.saveOrUpdate(entity.getId(), dto.getRoleIdList()); + } + + @Override + public void delete(Long[] ids) { + //删除用户 + baseDao.deleteBatchIds(Arrays.asList(ids)); + + //删除角色用户关系 + sysRoleUserService.deleteByUserIds(ids); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updatePassword(Long id, String newPassword) { + newPassword = PasswordUtils.encode(newPassword); + + baseDao.updatePassword(id, newPassword); + } + + @Override + public int getCountByDeptId(Long deptId) { + return baseDao.getCountByDeptId(deptId); + } + + @Override + public List getUserIdListByDeptId(List deptIdList) { + return baseDao.getUserIdListByDeptId(deptIdList); + } + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java new file mode 100644 index 0000000..a71bb7c --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/UserDetailsServiceImpl.java @@ -0,0 +1,57 @@ +package com.cnbm.admin.service.impl; + +import com.cnbm.admin.dao.UserDao; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.cnbm.admin.dto.SysMenuDTO; +import com.cnbm.admin.dto.SysUserDTO; +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.entity.SysMenuEntity; +import com.cnbm.admin.entity.SysUserEntity; +import com.cnbm.admin.service.SysMenuService; +import com.cnbm.common.utils.ConvertUtils; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @Author weihongyang + * @Date 2022/6/8 8:57 AM + * @Version 1.0 + */ +@Service +@Log4j2 +public class UserDetailsServiceImpl implements UserDetailsService { + + @Autowired + private UserDao userDao; + + @Autowired + private SysMenuService sysMenuService; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(SysUserEntity::getUsername,username); + SysUserEntity sysUserEntity = userDao.selectOne(lambdaQueryWrapper); + if (Objects.isNull(sysUserEntity)) { + throw new UsernameNotFoundException("用户名不存在"); + } + log.info("sysUserEntity的值是"+sysUserEntity.toString()); + log.info("sysUserEntity.getSuperAdmin()=="+sysUserEntity.getSuperAdmin()); + Set userPermissions = sysMenuService.getUserPermissions(sysUserEntity); + + List list = userPermissions.stream().collect(Collectors.toList()); + log.info("list==="+list.toString()); + return new LoginUser(sysUserEntity,list); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/utils/JwtUtil.java b/ym-admin/src/main/java/com/cnbm/admin/utils/JwtUtil.java new file mode 100644 index 0000000..f895449 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/utils/JwtUtil.java @@ -0,0 +1,115 @@ +package com.cnbm.admin.utils; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import java.util.Base64; +import java.util.Date; +import java.util.UUID; + +/** + * @Author weihongyang + * @Date 2022/6/8 1:43 PM + * @Version 1.0 + */ +public class JwtUtil { + + //有效期为 + public static final Long JWT_TTL = 60 * 60 *1000L;// 60 * 60 *1000 一个小时 + //设置秘钥明文 + public static final String JWT_KEY = "why"; + + public static String getUUID(){ + String token = UUID.randomUUID().toString().replaceAll("-", ""); + return token; + } + + /** + * 生成jtw + * @param subject token中要存放的数据(json格式) + * @return + */ + public static String createJWT(String subject) { + JwtBuilder builder = getJwtBuilder(subject, null, getUUID());// 设置过期时间 + return builder.compact(); + } + + /** + * 生成jtw + * @param subject token中要存放的数据(json格式) + * @param ttlMillis token超时时间 + * @return + */ + public static String createJWT(String subject, Long ttlMillis) { + JwtBuilder builder = getJwtBuilder(subject, ttlMillis, getUUID());// 设置过期时间 + return builder.compact(); + } + + private static JwtBuilder getJwtBuilder(String subject, Long ttlMillis, String uuid) { + SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; + SecretKey secretKey = generalKey(); + long nowMillis = System.currentTimeMillis(); + Date now = new Date(nowMillis); + if(ttlMillis==null){ + ttlMillis=JwtUtil.JWT_TTL; + } + long expMillis = nowMillis + ttlMillis; + Date expDate = new Date(expMillis); + return Jwts.builder() + .setId(uuid) //唯一的ID + .setSubject(subject) // 主题 可以是JSON数据 + .setIssuer("why") // 签发者 + .setIssuedAt(now) // 签发时间 + .signWith(signatureAlgorithm, secretKey) //使用HS256对称加密算法签名, 第二个参数为秘钥 + .setExpiration(expDate); + } + + /** + * 创建token + * @param id + * @param subject + * @param ttlMillis + * @return + */ + public static String createJWT(String id, String subject, Long ttlMillis) { + JwtBuilder builder = getJwtBuilder(subject, ttlMillis, id);// 设置过期时间 + return builder.compact(); + } + + public static void main(String[] args) throws Exception { +// String jwt = createJWT("123"); + Claims claims = parseJWT("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI5OWNhNGJhMjg5ZjU0OTVjODE5YTM0N2ExZmNlZjc0YSIsInN1YiI6IjEyMyIsImlzcyI6IndoeSIsImlhdCI6MTY1NDc1OTg5NiwiZXhwIjoxNjU0NzYzNDk2fQ.CTgS6yQjfXSGPJUTu-_rqjkh_KB_F9SzPThFfnvB5yg"); + String subject = claims.getSubject(); + System.out.println(subject); +// System.out.println(claims); + } + + /** + * 生成加密后的秘钥 secretKey + * @return + */ + public static SecretKey generalKey() { + byte[] encodedKey = Base64.getDecoder().decode(JwtUtil.JWT_KEY); + SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); + return key; + } + + /** + * 解析 + * + * @param jwt + * @return + * @throws Exception + */ + public static Claims parseJWT(String jwt) throws Exception { + SecretKey secretKey = generalKey(); + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(jwt) + .getBody(); + } +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/utils/PasswordUtils.java b/ym-admin/src/main/java/com/cnbm/admin/utils/PasswordUtils.java new file mode 100644 index 0000000..f129d00 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/utils/PasswordUtils.java @@ -0,0 +1,43 @@ +package com.cnbm.admin.utils; + +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +/** + * @Author weihongyang + * @Date 2022/6/10 1:57 PM + * @Version 1.0 + */ +public class PasswordUtils { + private static PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + + /** + * 加密 + * @param str 字符串 + * @return 返回加密字符串 + */ + public static String encode(String str){ + return passwordEncoder.encode(str); + } + + + /** + * 比较密码是否相等 + * @param str 明文密码 + * @param password 加密后密码 + * @return true:成功 false:失败 + */ + public static boolean matches(String str, String password){ + return passwordEncoder.matches(str, password); + } + + + public static void main(String[] args) { + String str = "admin"; + String password = encode(str); + + System.out.println(password); + System.out.println(matches(str, password)); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/utils/ResponseResult.java b/ym-admin/src/main/java/com/cnbm/admin/utils/ResponseResult.java new file mode 100644 index 0000000..e4f66ee --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/utils/ResponseResult.java @@ -0,0 +1,64 @@ +package com.cnbm.admin.utils; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * @Author weihongyang + * @Date 2022/6/9 1:27 PM + * @Version 1.0 + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ResponseResult { + /** + * 状态码 + */ + private Integer code; + /** + * 提示信息,如果有错误时,前端可以获取该字段进行提示 + */ + private String msg; + /** + * 查询到的结果数据, + */ + private T data; + + public ResponseResult(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + public ResponseResult(Integer code, T data) { + this.code = code; + this.data = data; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public ResponseResult(Integer code, String msg, T data) { + this.code = code; + this.msg = msg; + this.data = data; + } +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/utils/WebUtils.java b/ym-admin/src/main/java/com/cnbm/admin/utils/WebUtils.java new file mode 100644 index 0000000..3acda2f --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/utils/WebUtils.java @@ -0,0 +1,34 @@ +package com.cnbm.admin.utils; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * @Author weihongyang + * @Date 2022/6/9 1:29 PM + * @Version 1.0 + */ +public class WebUtils +{ + /** + * 将字符串渲染到客户端 + * + * @param response 渲染对象 + * @param string 待渲染的字符串 + * @return null + */ + public static String renderString(HttpServletResponse response, String string) { + try + { + response.setStatus(200); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + response.getWriter().print(string); + } + catch (IOException e) + { + e.printStackTrace(); + } + return null; + } +} diff --git a/ym-admin/src/main/resources/mapper/LoginDao.xml b/ym-admin/src/main/resources/mapper/LoginDao.xml new file mode 100644 index 0000000..ffd0a6f --- /dev/null +++ b/ym-admin/src/main/resources/mapper/LoginDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysDeptDao.xml b/ym-admin/src/main/resources/mapper/SysDeptDao.xml new file mode 100644 index 0000000..a558f10 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysDeptDao.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysDictDataDao.xml b/ym-admin/src/main/resources/mapper/SysDictDataDao.xml new file mode 100644 index 0000000..fa2f89f --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysDictDataDao.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysDictTypeDao.xml b/ym-admin/src/main/resources/mapper/SysDictTypeDao.xml new file mode 100644 index 0000000..0698e4e --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysDictTypeDao.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysLogErrorDao.xml b/ym-admin/src/main/resources/mapper/SysLogErrorDao.xml new file mode 100644 index 0000000..5fc9c2c --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysLogErrorDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysLogOperationDao.xml b/ym-admin/src/main/resources/mapper/SysLogOperationDao.xml new file mode 100644 index 0000000..256499c --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysLogOperationDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysMenuDao.xml b/ym-admin/src/main/resources/mapper/SysMenuDao.xml new file mode 100644 index 0000000..94922c6 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysMenuDao.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysParamsDao.xml b/ym-admin/src/main/resources/mapper/SysParamsDao.xml new file mode 100644 index 0000000..3ada3b6 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysParamsDao.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + update sys_params set param_value = #{paramValue} where param_code = #{paramCode} + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysRoleDao.xml b/ym-admin/src/main/resources/mapper/SysRoleDao.xml new file mode 100644 index 0000000..1aafba2 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysRoleDao.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysRoleDataScopeDao.xml b/ym-admin/src/main/resources/mapper/SysRoleDataScopeDao.xml new file mode 100644 index 0000000..e01c48a --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysRoleDataScopeDao.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + delete from sys_role_data_scope where role_id in + + #{roleId} + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysRoleMenuDao.xml b/ym-admin/src/main/resources/mapper/SysRoleMenuDao.xml new file mode 100644 index 0000000..aa4261a --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysRoleMenuDao.xml @@ -0,0 +1,20 @@ + + + + + + + + + delete from sys_role_menu where role_id in + + #{roleId} + + + + + delete from sys_role_menu where menu_id = #{value} + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysRoleUserDao.xml b/ym-admin/src/main/resources/mapper/SysRoleUserDao.xml new file mode 100644 index 0000000..1ece0b5 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysRoleUserDao.xml @@ -0,0 +1,24 @@ + + + + + + + delete from sys_role_user where role_id in + + #{roleId} + + + + + delete from sys_role_user where user_id in + + #{userId} + + + + + + \ No newline at end of file diff --git a/ym-admin/src/main/resources/mapper/SysUserDao.xml b/ym-admin/src/main/resources/mapper/SysUserDao.xml new file mode 100644 index 0000000..c305412 --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysUserDao.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + update sys_user set password = #{newPassword} where id = #{id} + + + + + + + \ No newline at end of file diff --git a/ym-barcode/pom.xml b/ym-barcode/pom.xml new file mode 100644 index 0000000..6a46802 --- /dev/null +++ b/ym-barcode/pom.xml @@ -0,0 +1,27 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-barcode + + + 8 + 8 + + + + + com.github.kwhat + jnativehook + 2.2.2 + + + + \ No newline at end of file diff --git a/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java b/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java new file mode 100644 index 0000000..ddff3ec --- /dev/null +++ b/ym-barcode/src/main/java/com/cnbm/barcode/listener/GlobalKeyListenerExample.java @@ -0,0 +1,91 @@ +package com.cnbm.barcode.listener; + +import com.github.kwhat.jnativehook.GlobalScreen; +import com.github.kwhat.jnativehook.NativeHookException; +import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent; +import com.github.kwhat.jnativehook.keyboard.NativeKeyListener; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * @Author weihongyang + * @Date 2022/6/20 4:08 PM + * @Version 1.0 + */ +@Log4j2 +@Component +public class GlobalKeyListenerExample implements NativeKeyListener { + + static { + try { + GlobalScreen.registerNativeHook(); + } catch (NativeHookException e) { + throw new RuntimeException(e); + } + GlobalScreen.addNativeKeyListener(new GlobalKeyListenerExample()); + } + protected final static LinkedBlockingQueue queue = new LinkedBlockingQueue(); + + + public void nativeKeyPressed(NativeKeyEvent e) { + log.info("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode())); + + try { + queue.put(e.getKeyCode()); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + int[] hotKeyArray1 = {NativeKeyEvent.VC_X, NativeKeyEvent.VC_Y,NativeKeyEvent.VC_Z}; + if (queue.size() == 5 && e.getKeyCode() == NativeKeyEvent.VC_ENTER && judgeCombinationKey(hotKeyArray1)){ + String result = ""; + List collect = queue.stream().map(n -> { + return NativeKeyEvent.getKeyText(n); + }).collect(Collectors.toList()); + + for (String s : collect) { + result = result + s; + } + log.info("符合标准的扫码是:"+ result); + queue.clear(); + } + if (queue.size() == 6){ + queue.poll(); + } + + if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) { + try { + GlobalScreen.unregisterNativeHook(); + } catch (NativeHookException nativeHookException) { + nativeHookException.printStackTrace(); + } + } + } + protected Boolean judgeCombinationKey(int[] hotKeyArray){ + Object[] queueKey = queue.toArray(); + + Predicate keyArrayPredicateOne = hotKeies -> (int)queueKey[0] == hotKeies[0] + && (int)queueKey[1] == hotKeies[1] + && (int)queueKey[2] == hotKeies[2]; + + Predicate keyArrayPredicateTwo = hotKeies -> (int)queueKey[1] == hotKeies[0] + && (int)queueKey[2] == hotKeies[1] + && (int)queueKey[3] == hotKeies[2]; + + return queue.size() == 3 ? keyArrayPredicateOne.test(hotKeyArray) : + keyArrayPredicateOne.or(keyArrayPredicateTwo).test(hotKeyArray); + + } + + public void nativeKeyReleased(NativeKeyEvent e) { + log.info("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode())); + } + + public void nativeKeyTyped(NativeKeyEvent e) { + log.info("Key Typed: " + e.getKeyText(e.getKeyCode())); + } +} diff --git a/ym-basic/pom.xml b/ym-basic/pom.xml new file mode 100644 index 0000000..e6ea20b --- /dev/null +++ b/ym-basic/pom.xml @@ -0,0 +1,19 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-basic + + + 8 + 8 + + + \ No newline at end of file diff --git a/ym-common/pom.xml b/ym-common/pom.xml new file mode 100644 index 0000000..e71100a --- /dev/null +++ b/ym-common/pom.xml @@ -0,0 +1,19 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-common + jar + + + ${project.artifactId} + + + \ No newline at end of file diff --git a/ym-common/src/main/java/com/cnbm/common/aspect/RedisAspect.java b/ym-common/src/main/java/com/cnbm/common/aspect/RedisAspect.java new file mode 100644 index 0000000..001767a --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/aspect/RedisAspect.java @@ -0,0 +1,41 @@ +package com.cnbm.common.aspect; + +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.RenException; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:58 PM + * @Version 1.0 + */ +@Aspect +@Component +public class RedisAspect { + private Logger logger = LoggerFactory.getLogger(getClass()); + /** + * 是否开启redis缓存 true开启 false关闭 + */ + @Value("${renren.redis.open: false}") + private boolean open; + + @Around("execution(* com.cnbm.common.redis.RedisUtils.*(..))") + public Object around(ProceedingJoinPoint point) throws Throwable { + Object result = null; + if(open){ + try{ + result = point.proceed(); + }catch (Exception e){ + logger.error("redis error", e); + throw new RenException(ErrorCode.REDIS_ERROR); + } + } + return result; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/constant/Constant.java b/ym-common/src/main/java/com/cnbm/common/constant/Constant.java new file mode 100644 index 0000000..f5f55d2 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/constant/Constant.java @@ -0,0 +1,119 @@ +package com.cnbm.common.constant; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:57 PM + * @Version 1.0 + */ +public interface Constant { + /** + * 成功 + */ + int SUCCESS = 1; + /** + * 失败 + */ + int FAIL = 0; + /** + * 菜单根节点标识 + */ + Long MENU_ROOT = 0L; + /** + * 部门根节点标识 + */ + Long DEPT_ROOT = 0L; + /** + * 升序 + */ + String ASC = "asc"; + /** + * 降序 + */ + String DESC = "desc"; + /** + * 创建时间字段名 + */ + String CREATE_DATE = "create_date"; + + /** + * 数据权限过滤 + */ + String SQL_FILTER = "sqlFilter"; + /** + * 当前页码 + */ + String PAGE = "page"; + /** + * 每页显示记录数 + */ + String LIMIT = "limit"; + /** + * 排序字段 + */ + String ORDER_FIELD = "orderField"; + /** + * 排序方式 + */ + String ORDER = "order"; + /** + * token header + */ + String TOKEN_HEADER = "token"; + + /** + * 云存储配置KEY + */ + String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY"; + + /** + * 定时任务状态 + */ + enum ScheduleStatus { + /** + * 暂停 + */ + PAUSE(0), + /** + * 正常 + */ + NORMAL(1); + + private int value; + + ScheduleStatus(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + + /** + * 云服务商 + */ + enum CloudService { + /** + * 七牛云 + */ + QINIU(1), + /** + * 阿里云 + */ + ALIYUN(2), + /** + * 腾讯云 + */ + QCLOUD(3); + + private int value; + + CloudService(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/convert/DateConverter.java b/ym-common/src/main/java/com/cnbm/common/convert/DateConverter.java new file mode 100644 index 0000000..4a165b9 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/convert/DateConverter.java @@ -0,0 +1,71 @@ +package com.cnbm.common.convert; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:57 PM + * @Version 1.0 + */ +@Component +public class DateConverter implements Converter { + private static final Logger logger = LoggerFactory.getLogger(DateConverter.class); + private static List formatList = new ArrayList<>(5); + static { + formatList.add("yyyy-MM"); + formatList.add("yyyy-MM-dd"); + formatList.add("yyyy-MM-dd hh:mm"); + formatList.add("yyyy-MM-dd hh:mm:ss"); + formatList.add("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + } + + @Override + public Date convert(String source) { + String value = source.trim(); + if (StringUtils.isEmpty(value)) { + return null; + } + + if(source.matches("^\\d{4}-\\d{1,2}$")){ + return parseDate(source, formatList.get(0)); + }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")){ + return parseDate(source, formatList.get(1)); + }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")){ + return parseDate(source, formatList.get(2)); + }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")){ + return parseDate(source, formatList.get(3)); + }else if(source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}.*T.*\\d{1,2}:\\d{1,2}:\\d{1,2}.*..*$")){ + return parseDate(source, formatList.get(4)); + } else { + throw new IllegalArgumentException("Invalid boolean value '" + source + "'"); + } + } + + /** + * 格式化日期 + * @param dateStr String 字符型日期 + * @param format String 格式 + * @return Date 日期 + */ + public Date parseDate(String dateStr, String format) { + Date date = null; + try { + DateFormat dateFormat = new SimpleDateFormat(format); + date = dateFormat.parse(dateStr); + } catch (Exception e) { + logger.error("Formatted date with date: {} and format : {} ", dateStr, format); + } + return date; + } + +} diff --git a/ym-common/src/main/java/com/cnbm/common/dao/BaseDao.java b/ym-common/src/main/java/com/cnbm/common/dao/BaseDao.java new file mode 100644 index 0000000..4fd4120 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/dao/BaseDao.java @@ -0,0 +1,12 @@ +package com.cnbm.common.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:02 PM + * @Version 1.0 + */ +public interface BaseDao extends BaseMapper { +} diff --git a/ym-common/src/main/java/com/cnbm/common/entity/BaseEntity.java b/ym-common/src/main/java/com/cnbm/common/entity/BaseEntity.java new file mode 100644 index 0000000..4190a44 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/entity/BaseEntity.java @@ -0,0 +1,33 @@ +package com.cnbm.common.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:03 PM + * @Version 1.0 + */ +@Data +public abstract class BaseEntity implements Serializable { + /** + * id + */ + @TableId + private Long id; + /** + * 创建者 + */ + @TableField(fill = FieldFill.INSERT) + private Long creator; + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createDate; +} diff --git a/ym-common/src/main/java/com/cnbm/common/exception/ErrorCode.java b/ym-common/src/main/java/com/cnbm/common/exception/ErrorCode.java new file mode 100644 index 0000000..59f12f9 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/exception/ErrorCode.java @@ -0,0 +1,34 @@ +package com.cnbm.common.exception; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:45 PM + * @Version 1.0 + */ +public interface ErrorCode { + int INTERNAL_SERVER_ERROR = 500; + int UNAUTHORIZED = 401; + + int NOT_NULL = 10001; + int DB_RECORD_EXISTS = 10002; + int PARAMS_GET_ERROR = 10003; + int ACCOUNT_PASSWORD_ERROR = 10004; + int ACCOUNT_DISABLE = 10005; + int IDENTIFIER_NOT_NULL = 10006; + int CAPTCHA_ERROR = 10007; + int SUB_MENU_EXIST = 10008; + int PASSWORD_ERROR = 10009; + int SUPERIOR_DEPT_ERROR = 10011; + int SUPERIOR_MENU_ERROR = 10012; + int DATA_SCOPE_PARAMS_ERROR = 10013; + int DEPT_SUB_DELETE_ERROR = 10014; + int DEPT_USER_DELETE_ERROR = 10015; + int UPLOAD_FILE_EMPTY = 10019; + int TOKEN_NOT_EMPTY = 10020; + int TOKEN_INVALID = 10021; + int ACCOUNT_LOCK = 10022; + int OSS_UPLOAD_FILE_ERROR = 10024; + int REDIS_ERROR = 10027; + int JOB_ERROR = 10028; + int INVALID_SYMBOL = 10029; +} diff --git a/ym-common/src/main/java/com/cnbm/common/exception/ExceptionUtils.java b/ym-common/src/main/java/com/cnbm/common/exception/ExceptionUtils.java new file mode 100644 index 0000000..8783b33 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/exception/ExceptionUtils.java @@ -0,0 +1,45 @@ +package com.cnbm.common.exception; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * @Author weihongyang + * @Date 2022/6/10 2:12 PM + * @Version 1.0 + */ +public class ExceptionUtils { + + /** + * 获取异常信息 + * @param ex 异常 + * @return 返回异常信息 + */ + public static String getErrorStackTrace(Exception ex){ + StringWriter sw = null; + PrintWriter pw = null; + try { + sw = new StringWriter(); + pw = new PrintWriter(sw, true); + ex.printStackTrace(pw); + }finally { + try { + if(pw != null) { + pw.close(); + } + } catch (Exception e) { + + } + try { + if(sw != null) { + sw.close(); + } + } catch (IOException e) { + + } + } + + return sw.toString(); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/exception/RenException.java b/ym-common/src/main/java/com/cnbm/common/exception/RenException.java new file mode 100644 index 0000000..eb04be2 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/exception/RenException.java @@ -0,0 +1,65 @@ +package com.cnbm.common.exception; + +import com.cnbm.common.utils.MessageUtils; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:54 PM + * @Version 1.0 + */ +public class RenException extends RuntimeException{ + private static final long serialVersionUID = 1L; + + private int code; + private String msg; + + public RenException(int code) { + this.code = code; + this.msg = MessageUtils.getMessage(code); + } + + public RenException(int code, String... params) { + this.code = code; + this.msg = MessageUtils.getMessage(code, params); + } + + public RenException(int code, Throwable e) { + super(e); + this.code = code; + this.msg = MessageUtils.getMessage(code); + } + + public RenException(int code, Throwable e, String... params) { + super(e); + this.code = code; + this.msg = MessageUtils.getMessage(code, params); + } + + public RenException(String msg) { + super(msg); + this.code = ErrorCode.INTERNAL_SERVER_ERROR; + this.msg = msg; + } + + public RenException(String msg, Throwable e) { + super(msg, e); + this.code = ErrorCode.INTERNAL_SERVER_ERROR; + this.msg = msg; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/page/PageData.java b/ym-common/src/main/java/com/cnbm/common/page/PageData.java new file mode 100644 index 0000000..c490150 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/page/PageData.java @@ -0,0 +1,35 @@ +package com.cnbm.common.page; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:05 PM + * @Version 1.0 + */ +@Data +@ApiModel(value = "分页数据") +public class PageData implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "总记录数") + private int total; + + @ApiModelProperty(value = "列表数据") + private List list; + + /** + * 分页 + * @param list 列表数据 + * @param total 总记录数 + */ + public PageData(List list, long total) { + this.list = list; + this.total = (int)total; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/redis/RedisConfig.java b/ym-common/src/main/java/com/cnbm/common/redis/RedisConfig.java new file mode 100644 index 0000000..ef0ea45 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/redis/RedisConfig.java @@ -0,0 +1,49 @@ +package com.cnbm.common.redis; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; +import lombok.extern.log4j.Log4j2; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import javax.annotation.Resource; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:00 PM + * @Version 1.0 + */ +@Configuration +@Log4j2 +public class RedisConfig { + @Resource + private RedisConnectionFactory factory; + + @Bean + public Jackson2JsonRedisSerializer jackson2JsonRedisSerializer(){ + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL); + jackson2JsonRedisSerializer.setObjectMapper(objectMapper); + + return jackson2JsonRedisSerializer; + } + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(jackson2JsonRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer()); + redisTemplate.setConnectionFactory(factory); + return redisTemplate; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/redis/RedisKeys.java b/ym-common/src/main/java/com/cnbm/common/redis/RedisKeys.java new file mode 100644 index 0000000..8a725b8 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/redis/RedisKeys.java @@ -0,0 +1,58 @@ +package com.cnbm.common.redis; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:01 PM + * @Version 1.0 + */ +public class RedisKeys { + /** + * 系统参数Key + */ + public static String getSysParamsKey(){ + return "sys:params"; + } + + /** + * 验证码Key + */ + public static String getCaptchaKey(String uuid){ + return "sys:captcha:" + uuid; + } + + /** + * 登录用户Key + */ + public static String getSecurityUserKey(Long id){ + return "sys:security:user:" + id; + } + + /** + * 系统日志Key + */ + public static String getSysLogKey(){ + return "sys:log"; + } + + /** + * 系统资源Key + */ + public static String getSysResourceKey(){ + return "sys:resource"; + } + + /** + * 用户菜单导航Key + */ + public static String getUserMenuNavKey(Long userId){ + return "sys:user:nav:" + userId; + } + + /** + * 用户权限标识Key + */ + public static String getUserPermissionsKey(Long userId){ + return "sys:user:permissions:" + userId; + } +} + diff --git a/ym-common/src/main/java/com/cnbm/common/redis/RedisUtils.java b/ym-common/src/main/java/com/cnbm/common/redis/RedisUtils.java new file mode 100644 index 0000000..9b4bd98 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/redis/RedisUtils.java @@ -0,0 +1,118 @@ +package com.cnbm.common.redis; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:00 PM + * @Version 1.0 + */ +@Component +public class RedisUtils { + @Autowired + private RedisTemplate redisTemplate; + + /** 默认过期时长为24小时,单位:秒 */ + public final static long DEFAULT_EXPIRE = 60 * 60 * 24L; + /** 过期时长为1小时,单位:秒 */ + public final static long HOUR_ONE_EXPIRE = 60 * 60 * 1L; + /** 过期时长为6小时,单位:秒 */ + public final static long HOUR_SIX_EXPIRE = 60 * 60 * 6L; + /** 不设置过期时长 */ + public final static long NOT_EXPIRE = -1L; + + public void set(String key, Object value, long expire){ + redisTemplate.opsForValue().set(key, value); + if(expire != NOT_EXPIRE){ + expire(key, expire); + } + } + + public void set(String key, Object value){ + set(key, value, DEFAULT_EXPIRE); + } + + public Object get(String key, long expire) { + Object value = redisTemplate.opsForValue().get(key); + if(expire != NOT_EXPIRE){ + expire(key, expire); + } + return value; + } + + public Object get(String key) { + return get(key, NOT_EXPIRE); + } + + public void delete(String key) { + redisTemplate.delete(key); + } + + public void delete(Collection keys) { + redisTemplate.delete(keys); + } + + public Object hGet(String key, String field) { + return redisTemplate.opsForHash().get(key, field); + } + + public Map hGetAll(String key){ + HashOperations hashOperations = redisTemplate.opsForHash(); + return hashOperations.entries(key); + } + + public void hMSet(String key, Map map){ + hMSet(key, map, DEFAULT_EXPIRE); + } + + public void hMSet(String key, Map map, long expire){ + redisTemplate.opsForHash().putAll(key, map); + + if(expire != NOT_EXPIRE){ + expire(key, expire); + } + } + + public void hSet(String key, String field, Object value) { + hSet(key, field, value, DEFAULT_EXPIRE); + } + + public void hSet(String key, String field, Object value, long expire) { + redisTemplate.opsForHash().put(key, field, value); + + if(expire != NOT_EXPIRE){ + expire(key, expire); + } + } + + public void expire(String key, long expire){ + redisTemplate.expire(key, expire, TimeUnit.SECONDS); + } + + public void hDel(String key, Object... fields){ + redisTemplate.opsForHash().delete(key, fields); + } + + public void leftPush(String key, Object value){ + leftPush(key, value, DEFAULT_EXPIRE); + } + + public void leftPush(String key, Object value, long expire){ + redisTemplate.opsForList().leftPush(key, value); + + if(expire != NOT_EXPIRE){ + expire(key, expire); + } + } + + public Object rightPop(String key){ + return redisTemplate.opsForList().rightPop(key); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/service/BaseService.java b/ym-common/src/main/java/com/cnbm/common/service/BaseService.java new file mode 100644 index 0000000..d82d583 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/service/BaseService.java @@ -0,0 +1,108 @@ +package com.cnbm.common.service; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; + +import java.io.Serializable; +import java.util.Collection; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:06 PM + * @Version 1.0 + */ +public interface BaseService { + Class currentModelClass(); + + /** + *

+ * 插入一条记录(选择字段,策略插入) + *

+ * + * @param entity 实体对象 + */ + boolean insert(T entity); + + /** + *

+ * 插入(批量),该方法不支持 Oracle、SQL Server + *

+ * + * @param entityList 实体对象集合 + */ + boolean insertBatch(Collection entityList); + + /** + *

+ * 插入(批量),该方法不支持 Oracle、SQL Server + *

+ * + * @param entityList 实体对象集合 + * @param batchSize 插入批次数量 + */ + boolean insertBatch(Collection entityList, int batchSize); + + /** + *

+ * 根据 ID 选择修改 + *

+ * + * @param entity 实体对象 + */ + boolean updateById(T entity); + + /** + *

+ * 根据 whereEntity 条件,更新记录 + *

+ * + * @param entity 实体对象 + * @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper} + */ + boolean update(T entity, Wrapper updateWrapper); + + /** + *

+ * 根据ID 批量更新 + *

+ * + * @param entityList 实体对象集合 + */ + boolean updateBatchById(Collection entityList); + + /** + *

+ * 根据ID 批量更新 + *

+ * + * @param entityList 实体对象集合 + * @param batchSize 更新批次数量 + */ + boolean updateBatchById(Collection entityList, int batchSize); + + /** + *

+ * 根据 ID 查询 + *

+ * + * @param id 主键ID + */ + T selectById(Serializable id); + + /** + *

+ * 根据 ID 删除 + *

+ * + * @param id 主键ID + */ + boolean deleteById(Serializable id); + + /** + *

+ * 删除(根据ID 批量删除) + *

+ * + * @param idList 主键ID列表 + */ + boolean deleteBatchIds(Collection idList); +} \ No newline at end of file diff --git a/ym-common/src/main/java/com/cnbm/common/service/CrudService.java b/ym-common/src/main/java/com/cnbm/common/service/CrudService.java new file mode 100644 index 0000000..9b8a006 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/service/CrudService.java @@ -0,0 +1,27 @@ +package com.cnbm.common.service; + +import com.cnbm.common.page.PageData; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:06 PM + * @Version 1.0 + */ +public interface CrudService extends BaseService { + + PageData page(Map params); + + List list(Map params); + + D get(Long id); + + void save(D dto); + + void update(D dto); + + void delete(Long[] ids); + +} diff --git a/ym-common/src/main/java/com/cnbm/common/service/impl/BaseServiceImpl.java b/ym-common/src/main/java/com/cnbm/common/service/impl/BaseServiceImpl.java new file mode 100644 index 0000000..3e99bb1 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/service/impl/BaseServiceImpl.java @@ -0,0 +1,212 @@ +package com.cnbm.common.service.impl; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.enums.SqlMethod; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.BaseService; +import com.cnbm.common.utils.ConvertUtils; +import org.apache.ibatis.binding.MapperMethod; +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.logging.LogFactory; +import org.apache.ibatis.session.SqlSession; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:10 PM + * @Version 1.0 + */ +public abstract class BaseServiceImpl, T> implements BaseService { + @Autowired + protected M baseDao; + protected Log log = LogFactory.getLog(getClass()); + + /** + * 获取分页对象 + * + * @param params 分页查询参数 + * @param defaultOrderField 默认排序字段 + * @param isAsc 排序方式 + */ + protected IPage getPage(Map params, String defaultOrderField, boolean isAsc) { + //分页参数 + long curPage = 1; + long limit = 10; + + if (params.get(Constant.PAGE) != null) { + curPage = Long.parseLong((String) params.get(Constant.PAGE)); + } + if (params.get(Constant.LIMIT) != null) { + limit = Long.parseLong((String) params.get(Constant.LIMIT)); + } + + //分页对象 + Page page = new Page<>(curPage, limit); + + //分页参数 + params.put(Constant.PAGE, page); + + //排序字段 + String orderField = (String) params.get(Constant.ORDER_FIELD); + String order = (String) params.get(Constant.ORDER); + + //前端字段排序 + if (StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)) { + if (Constant.ASC.equalsIgnoreCase(order)) { + return page.addOrder(OrderItem.asc(orderField)); + } else { + return page.addOrder(OrderItem.desc(orderField)); + } + } + + //没有排序字段,则不排序 + if (StringUtils.isBlank(defaultOrderField)) { + return page; + } + + //默认排序 + if (isAsc) { + page.addOrder(OrderItem.asc(defaultOrderField)); + } else { + page.addOrder(OrderItem.desc(defaultOrderField)); + } + + return page; + } + + protected PageData getPageData(List list, long total, Class target) { + List targetList = ConvertUtils.sourceToTarget(list, target); + + return new PageData<>(targetList, total); + } + + protected PageData getPageData(IPage page, Class target) { + return getPageData(page.getRecords(), page.getTotal(), target); + } + + protected void paramsToLike(Map params, String... likes) { + for (String like : likes) { + String val = (String) params.get(like); + if (StringUtils.isNotBlank(val)) { + params.put(like, "%" + val + "%"); + } else { + params.put(like, null); + } + } + } + + /** + *

+ * 判断数据库操作是否成功 + *

+ *

+ * 注意!! 该方法为 Integer 判断,不可传入 int 基本类型 + *

+ * + * @param result 数据库操作返回影响条数 + * @return boolean + */ + protected static boolean retBool(Integer result) { + return SqlHelper.retBool(result); + } + + protected Class currentMapperClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseServiceImpl.class, 0); + } + + @Override + public Class currentModelClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseServiceImpl.class, 1); + } + + protected String getSqlStatement(SqlMethod sqlMethod) { + return SqlHelper.getSqlStatement(this.currentMapperClass(), sqlMethod); + } + + @Override + public boolean insert(T entity) { + return BaseServiceImpl.retBool(baseDao.insert(entity)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean insertBatch(Collection entityList) { + return insertBatch(entityList, 100); + } + + /** + * 批量插入 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean insertBatch(Collection entityList, int batchSize) { + String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE); + return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); + } + + /** + * 执行批量操作 + */ + protected boolean executeBatch(Collection list, int batchSize, BiConsumer consumer) { + return SqlHelper.executeBatch(this.currentModelClass(), this.log, list, batchSize, consumer); + } + + + @Override + public boolean updateById(T entity) { + return BaseServiceImpl.retBool(baseDao.updateById(entity)); + } + + @Override + public boolean update(T entity, Wrapper updateWrapper) { + return BaseServiceImpl.retBool(baseDao.update(entity, updateWrapper)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateBatchById(Collection entityList) { + return updateBatchById(entityList, 30); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateBatchById(Collection entityList, int batchSize) { + String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID); + return executeBatch(entityList, batchSize, (sqlSession, entity) -> { + MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); + param.put(Constants.ENTITY, entity); + sqlSession.update(sqlStatement, param); + }); + } + + @Override + public T selectById(Serializable id) { + return baseDao.selectById(id); + } + + @Override + public boolean deleteById(Serializable id) { + return SqlHelper.retBool(baseDao.deleteById(id)); + } + + @Override + public boolean deleteBatchIds(Collection idList) { + return SqlHelper.retBool(baseDao.deleteBatchIds(idList)); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/service/impl/CrudServiceImpl.java b/ym-common/src/main/java/com/cnbm/common/service/impl/CrudServiceImpl.java new file mode 100644 index 0000000..c376d8b --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/service/impl/CrudServiceImpl.java @@ -0,0 +1,72 @@ +package com.cnbm.common.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; +import com.cnbm.common.page.PageData; +import com.cnbm.common.service.CrudService; +import com.cnbm.common.utils.ConvertUtils; +import org.springframework.beans.BeanUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:11 PM + * @Version 1.0 + */ +public abstract class CrudServiceImpl, T, D> extends BaseServiceImpl implements CrudService { + + protected Class currentDtoClass() { + return (Class) ReflectionKit.getSuperClassGenericType(getClass(), CrudServiceImpl.class, 2); + } + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, null, false), + getWrapper(params) + ); + + return getPageData(page, currentDtoClass()); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, currentDtoClass()); + } + + public abstract QueryWrapper getWrapper(Map params); + + @Override + public D get(Long id) { + T entity = baseDao.selectById(id); + + return ConvertUtils.sourceToTarget(entity, currentDtoClass()); + } + + @Override + public void save(D dto) { + T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); + insert(entity); + + //copy主键值到dto + BeanUtils.copyProperties(entity, dto); + } + + @Override + public void update(D dto) { + T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); + updateById(entity); + } + + @Override + public void delete(Long[] ids) { + baseDao.deleteBatchIds(Arrays.asList(ids)); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/ConvertUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/ConvertUtils.java new file mode 100644 index 0000000..26f6277 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/ConvertUtils.java @@ -0,0 +1,52 @@ +package com.cnbm.common.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:48 PM + * @Version 1.0 + */ +public class ConvertUtils { + private static Logger logger = LoggerFactory.getLogger(ConvertUtils.class); + + public static T sourceToTarget(Object source, Class target){ + if(source == null){ + return null; + } + T targetObject = null; + try { + targetObject = target.newInstance(); + BeanUtils.copyProperties(source, targetObject); + } catch (Exception e) { + logger.error("convert error ", e); + } + + return targetObject; + } + + public static List sourceToTarget(Collection sourceList, Class target){ + if(sourceList == null){ + return null; + } + + List targetList = new ArrayList<>(sourceList.size()); + try { + for(Object source : sourceList){ + T targetObject = target.newInstance(); + BeanUtils.copyProperties(source, targetObject); + targetList.add(targetObject); + } + }catch (Exception e){ + logger.error("convert error ", e); + } + + return targetList; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/DateUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/DateUtils.java new file mode 100644 index 0000000..63fc900 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/DateUtils.java @@ -0,0 +1,174 @@ +package com.cnbm.common.utils; + +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:47 PM + * @Version 1.0 + */ +public class DateUtils { + /** 时间格式(yyyy-MM-dd) */ + public final static String DATE_PATTERN = "yyyy-MM-dd"; + /** 时间格式(yyyy-MM-dd HH:mm:ss) */ + public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; + + /** + * 日期格式化 日期格式为:yyyy-MM-dd + * @param date 日期 + * @return 返回yyyy-MM-dd格式日期 + */ + public static String format(Date date) { + return format(date, DATE_PATTERN); + } + + /** + * 日期格式化 日期格式为:yyyy-MM-dd + * @param date 日期 + * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN + * @return 返回yyyy-MM-dd格式日期 + */ + public static String format(Date date, String pattern) { + if(date != null){ + SimpleDateFormat df = new SimpleDateFormat(pattern); + return df.format(date); + } + return null; + } + + /** + * 日期解析 + * @param date 日期 + * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN + * @return 返回Date + */ + public static Date parse(String date, String pattern) { + try { + return new SimpleDateFormat(pattern).parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 字符串转换成日期 + * @param strDate 日期字符串 + * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN + */ + public static Date stringToDate(String strDate, String pattern) { + if (StringUtils.isBlank(strDate)){ + return null; + } + + DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); + return fmt.parseLocalDateTime(strDate).toDate(); + } + + /** + * 根据周数,获取开始日期、结束日期 + * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周 + * @return 返回date[0]开始日期、date[1]结束日期 + */ + public static Date[] getWeekStartAndEnd(int week) { + DateTime dateTime = new DateTime(); + LocalDate date = new LocalDate(dateTime.plusWeeks(week)); + + date = date.dayOfWeek().withMinimumValue(); + Date beginDate = date.toDate(); + Date endDate = date.plusDays(6).toDate(); + return new Date[]{beginDate, endDate}; + } + + /** + * 对日期的【秒】进行加/减 + * + * @param date 日期 + * @param seconds 秒数,负数为减 + * @return 加/减几秒后的日期 + */ + public static Date addDateSeconds(Date date, int seconds) { + DateTime dateTime = new DateTime(date); + return dateTime.plusSeconds(seconds).toDate(); + } + + /** + * 对日期的【分钟】进行加/减 + * + * @param date 日期 + * @param minutes 分钟数,负数为减 + * @return 加/减几分钟后的日期 + */ + public static Date addDateMinutes(Date date, int minutes) { + DateTime dateTime = new DateTime(date); + return dateTime.plusMinutes(minutes).toDate(); + } + + /** + * 对日期的【小时】进行加/减 + * + * @param date 日期 + * @param hours 小时数,负数为减 + * @return 加/减几小时后的日期 + */ + public static Date addDateHours(Date date, int hours) { + DateTime dateTime = new DateTime(date); + return dateTime.plusHours(hours).toDate(); + } + + /** + * 对日期的【天】进行加/减 + * + * @param date 日期 + * @param days 天数,负数为减 + * @return 加/减几天后的日期 + */ + public static Date addDateDays(Date date, int days) { + DateTime dateTime = new DateTime(date); + return dateTime.plusDays(days).toDate(); + } + + /** + * 对日期的【周】进行加/减 + * + * @param date 日期 + * @param weeks 周数,负数为减 + * @return 加/减几周后的日期 + */ + public static Date addDateWeeks(Date date, int weeks) { + DateTime dateTime = new DateTime(date); + return dateTime.plusWeeks(weeks).toDate(); + } + + /** + * 对日期的【月】进行加/减 + * + * @param date 日期 + * @param months 月数,负数为减 + * @return 加/减几月后的日期 + */ + public static Date addDateMonths(Date date, int months) { + DateTime dateTime = new DateTime(date); + return dateTime.plusMonths(months).toDate(); + } + + /** + * 对日期的【年】进行加/减 + * + * @param date 日期 + * @param years 年数,负数为减 + * @return 加/减几年后的日期 + */ + public static Date addDateYears(Date date, int years) { + DateTime dateTime = new DateTime(date); + return dateTime.plusYears(years).toDate(); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/ExcelUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/ExcelUtils.java new file mode 100644 index 0000000..54373d5 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/ExcelUtils.java @@ -0,0 +1,70 @@ +package com.cnbm.common.utils; + +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import com.cnbm.common.utils.DateUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.BeanUtils; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/10 9:57 AM + * @Version 1.0 + */ +public class ExcelUtils { + + /** + * Excel导出 + * + * @param response response + * @param fileName 文件名 + * @param list 数据List + * @param pojoClass 对象Class + */ + public static void exportExcel(HttpServletResponse response, String fileName, Collection list, + Class pojoClass) throws IOException { + if(StringUtils.isBlank(fileName)){ + //当前日期 + fileName = DateUtils.format(new Date()); + } + + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), pojoClass, list); + response.setCharacterEncoding("UTF-8"); + response.setHeader("content-Type", "application/vnd.ms-excel"); + response.setHeader("Content-Disposition", + "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xls"); + ServletOutputStream out = response.getOutputStream(); + workbook.write(out); + out.flush(); + } + + /** + * Excel导出,先sourceList转换成List,再导出 + * + * @param response response + * @param fileName 文件名 + * @param sourceList 原数据List + * @param targetClass 目标对象Class + */ + public static void exportExcelToTarget(HttpServletResponse response, String fileName, Collection sourceList, + Class targetClass) throws Exception { + List targetList = new ArrayList<>(sourceList.size()); + for(Object source : sourceList){ + Object target = targetClass.newInstance(); + BeanUtils.copyProperties(source, target); + targetList.add(target); + } + + exportExcel(response, fileName, targetList, targetClass); + } +} \ No newline at end of file diff --git a/ym-common/src/main/java/com/cnbm/common/utils/HttpContextUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/HttpContextUtils.java new file mode 100644 index 0000000..5982def --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/HttpContextUtils.java @@ -0,0 +1,54 @@ +package com.cnbm.common.utils; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpHeaders; +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.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:49 PM + * @Version 1.0 + */ +public class HttpContextUtils { + public static HttpServletRequest getHttpServletRequest() { + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + if(requestAttributes == null){ + return null; + } + + return ((ServletRequestAttributes) requestAttributes).getRequest(); + } + + public static Map getParameterMap(HttpServletRequest request) { + Enumeration parameters = request.getParameterNames(); + + Map params = new HashMap<>(); + while (parameters.hasMoreElements()) { + String parameter = parameters.nextElement(); + String value = request.getParameter(parameter); + if (StringUtils.isNotBlank(value)) { + params.put(parameter, value); + } + } + + return params; + } + + public static String getDomain(){ + HttpServletRequest request = getHttpServletRequest(); + StringBuffer url = request.getRequestURL(); + return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); + } + + public static String getOrigin(){ + HttpServletRequest request = getHttpServletRequest(); + return request.getHeader(HttpHeaders.ORIGIN); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/IpUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/IpUtils.java new file mode 100644 index 0000000..7544bc4 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/IpUtils.java @@ -0,0 +1,49 @@ +package com.cnbm.common.utils; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:50 PM + * @Version 1.0 + */ +public class IpUtils { + private static Logger logger = LoggerFactory.getLogger(IpUtils.class); + + /** + * 获取IP地址 + * + * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址 + * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址 + */ + public static String getIpAddr(HttpServletRequest request) { + String unknown = "unknown"; + String ip = null; + try { + ip = request.getHeader("x-forwarded-for"); + if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (StringUtils.isEmpty(ip) || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + } catch (Exception e) { + logger.error("IPUtils ERROR ", e); + } + + return ip; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/JsonUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/JsonUtils.java new file mode 100644 index 0000000..89d6d0c --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/JsonUtils.java @@ -0,0 +1,67 @@ +package com.cnbm.common.utils; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:50 PM + * @Version 1.0 + */ +public class JsonUtils { + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static String toJsonString(Object object) { + try { + return objectMapper.writeValueAsString(object); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static T parseObject(String text, Class clazz) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + return objectMapper.readValue(text, clazz); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static T parseObject(byte[] bytes, Class clazz) { + if (ArrayUtil.isEmpty(bytes)) { + return null; + } + try { + return objectMapper.readValue(bytes, clazz); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static T parseObject(String text, TypeReference typeReference) { + try { + return objectMapper.readValue(text, typeReference); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static List parseArray(String text, Class clazz) { + if (StrUtil.isEmpty(text)) { + return new ArrayList<>(); + } + try { + return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/MessageUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/MessageUtils.java new file mode 100644 index 0000000..d932e64 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/MessageUtils.java @@ -0,0 +1,24 @@ +package com.cnbm.common.utils; + +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:42 PM + * @Version 1.0 + */ +public class MessageUtils { + private static MessageSource messageSource; + static { + messageSource = (MessageSource)SpringContextUtils.getBean("messageSource"); + } + + public static String getMessage(int code){ + return getMessage(code, new String[0]); + } + + public static String getMessage(int code, String... params){ + return messageSource.getMessage(code+"", params, LocaleContextHolder.getLocale()); + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/Result.java b/ym-common/src/main/java/com/cnbm/common/utils/Result.java new file mode 100644 index 0000000..8d77c14 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/Result.java @@ -0,0 +1,89 @@ +package com.cnbm.common.utils; + +import com.cnbm.common.exception.ErrorCode; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:41 PM + * @Version 1.0 + */ +@ApiModel(value = "响应") +public class Result implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 编码:0表示成功,其他值表示失败 + */ + @ApiModelProperty(value = "编码:0表示成功,其他值表示失败") + private int code = 0; + /** + * 消息内容 + */ + @ApiModelProperty(value = "消息内容") + private String msg = "success"; + /** + * 响应数据 + */ + @ApiModelProperty(value = "响应数据") + private T data; + + public Result ok(T data) { + this.setData(data); + return this; + } + + public boolean success(){ + return code == 0; + } + + public Result error() { + this.code = ErrorCode.INTERNAL_SERVER_ERROR; + this.msg = MessageUtils.getMessage(this.code); + return this; + } + + public Result error(int code) { + this.code = code; + this.msg = MessageUtils.getMessage(this.code); + return this; + } + + public Result error(int code, String msg) { + this.code = code; + this.msg = msg; + return this; + } + + public Result error(String msg) { + this.code = ErrorCode.INTERNAL_SERVER_ERROR; + this.msg = msg; + return this; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/SpringContextUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/SpringContextUtils.java new file mode 100644 index 0000000..553757b --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/SpringContextUtils.java @@ -0,0 +1,47 @@ +package com.cnbm.common.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:43 PM + * @Version 1.0 + */ +@Component +public class SpringContextUtils implements ApplicationContextAware { + public static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { + SpringContextUtils.applicationContext = applicationContext; + } + + public static Object getBean(String name) { + return applicationContext.getBean(name); + } + + public static T getBean(Class requiredType) { + return applicationContext.getBean(requiredType); + } + + public static T getBean(String name, Class requiredType) { + return applicationContext.getBean(name, requiredType); + } + + public static boolean containsBean(String name) { + return applicationContext.containsBean(name); + } + + public static boolean isSingleton(String name) { + return applicationContext.isSingleton(name); + } + + public static Class getType(String name) { + return applicationContext.getType(name); + } + +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/TreeNode.java b/ym-common/src/main/java/com/cnbm/common/utils/TreeNode.java new file mode 100644 index 0000000..f0bb805 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/TreeNode.java @@ -0,0 +1,50 @@ +package com.cnbm.common.utils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:51 PM + * @Version 1.0 + */ +public class TreeNode implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 主键 + */ + private Long id; + /** + * 上级ID + */ + private Long pid; + /** + * 子节点列表 + */ + private List children = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getPid() { + return pid; + } + + public void setPid(Long pid) { + this.pid = pid; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/utils/TreeUtils.java b/ym-common/src/main/java/com/cnbm/common/utils/TreeUtils.java new file mode 100644 index 0000000..348d47c --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/utils/TreeUtils.java @@ -0,0 +1,69 @@ +package com.cnbm.common.utils; + +import com.cnbm.common.validator.AssertUtils; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:52 PM + * @Version 1.0 + */ +public class TreeUtils { + /** + * 根据pid,构建树节点 + */ + public static List build(List treeNodes, Long pid) { + //pid不能为空 + AssertUtils.isNull(pid, "pid"); + + List treeList = new ArrayList<>(); + for(T treeNode : treeNodes) { + if (pid.equals(treeNode.getPid())) { + treeList.add(findChildren(treeNodes, treeNode)); + } + } + + return treeList; + } + + /** + * 查找子节点 + */ + private static T findChildren(List treeNodes, T rootNode) { + for(T treeNode : treeNodes) { + if(rootNode.getId().equals(treeNode.getPid())) { + rootNode.getChildren().add(findChildren(treeNodes, treeNode)); + } + } + return rootNode; + } + + /** + * 构建树节点 + */ + public static List build(List treeNodes) { + List result = new ArrayList<>(); + + //list转map + Map nodeMap = new LinkedHashMap<>(treeNodes.size()); + for(T treeNode : treeNodes){ + nodeMap.put(treeNode.getId(), treeNode); + } + + for(T node : nodeMap.values()) { + T parent = nodeMap.get(node.getPid()); + if(parent != null && !(node.getId().equals(parent.getId()))){ + parent.getChildren().add(node); + continue; + } + + result.add(node); + } + + return result; + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/AssertUtils.java b/ym-common/src/main/java/com/cnbm/common/validator/AssertUtils.java new file mode 100644 index 0000000..1e2513d --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/AssertUtils.java @@ -0,0 +1,88 @@ +package com.cnbm.common.validator; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ArrayUtil; +import com.cnbm.common.exception.ErrorCode; +import com.cnbm.common.exception.RenException; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/7 2:53 PM + * @Version 1.0 + */ +public class AssertUtils { + public static void isBlank(String str, String... params) { + isBlank(str, ErrorCode.NOT_NULL, params); + } + + public static void isBlank(String str, Integer code, String... params) { + if(code == null){ + throw new RenException(ErrorCode.NOT_NULL, "code"); + } + + if (StringUtils.isBlank(str)) { + throw new RenException(code, params); + } + } + + public static void isNull(Object object, String... params) { + isNull(object, ErrorCode.NOT_NULL, params); + } + + public static void isNull(Object object, Integer code, String... params) { + if(code == null){ + throw new RenException(ErrorCode.NOT_NULL, "code"); + } + + if (object == null) { + throw new RenException(code, params); + } + } + + public static void isArrayEmpty(Object[] array, String... params) { + isArrayEmpty(array, ErrorCode.NOT_NULL, params); + } + + public static void isArrayEmpty(Object[] array, Integer code, String... params) { + if(code == null){ + throw new RenException(ErrorCode.NOT_NULL, "code"); + } + + if(ArrayUtil.isEmpty(array)){ + throw new RenException(code, params); + } + } + + public static void isListEmpty(List list, String... params) { + isListEmpty(list, ErrorCode.NOT_NULL, params); + } + + public static void isListEmpty(List list, Integer code, String... params) { + if(code == null){ + throw new RenException(ErrorCode.NOT_NULL, "code"); + } + + if(CollUtil.isEmpty(list)){ + throw new RenException(code, params); + } + } + + public static void isMapEmpty(Map map, String... params) { + isMapEmpty(map, ErrorCode.NOT_NULL, params); + } + + public static void isMapEmpty(Map map, Integer code, String... params) { + if(code == null){ + throw new RenException(ErrorCode.NOT_NULL, "code"); + } + + if(MapUtil.isEmpty(map)){ + throw new RenException(code, params); + } + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/ValidatorUtils.java b/ym-common/src/main/java/com/cnbm/common/validator/ValidatorUtils.java new file mode 100644 index 0000000..fa9e448 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/ValidatorUtils.java @@ -0,0 +1,47 @@ +package com.cnbm.common.validator; + +import com.cnbm.common.exception.RenException; +import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import java.util.Locale; +import java.util.Set; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:15 PM + * @Version 1.0 + */ +public class ValidatorUtils { + + private static ResourceBundleMessageSource getMessageSource() { + ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource(); + bundleMessageSource.setDefaultEncoding("UTF-8"); + bundleMessageSource.setBasenames("i18n/validation"); + return bundleMessageSource; + } + + /** + * 校验对象 + * @param object 待校验对象 + * @param groups 待校验的组 + */ + public static void validateEntity(Object object, Class... groups) + throws RenException { + Locale.setDefault(LocaleContextHolder.getLocale()); + Validator validator = Validation.byDefaultProvider().configure().messageInterpolator( + new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource()))) + .buildValidatorFactory().getValidator(); + + Set> constraintViolations = validator.validate(object, groups); + if (!constraintViolations.isEmpty()) { + ConstraintViolation constraint = constraintViolations.iterator().next(); + throw new RenException(constraint.getMessage()); + } + } +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/group/AddGroup.java b/ym-common/src/main/java/com/cnbm/common/validator/group/AddGroup.java new file mode 100644 index 0000000..b389039 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/group/AddGroup.java @@ -0,0 +1,9 @@ +package com.cnbm.common.validator.group; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:16 PM + * @Version 1.0 + */ +public interface AddGroup { +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/group/DefaultGroup.java b/ym-common/src/main/java/com/cnbm/common/validator/group/DefaultGroup.java new file mode 100644 index 0000000..ae67309 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/group/DefaultGroup.java @@ -0,0 +1,9 @@ +package com.cnbm.common.validator.group; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:16 PM + * @Version 1.0 + */ +public interface DefaultGroup { +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/group/Group.java b/ym-common/src/main/java/com/cnbm/common/validator/group/Group.java new file mode 100644 index 0000000..3e5465f --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/group/Group.java @@ -0,0 +1,12 @@ +package com.cnbm.common.validator.group; + +import javax.validation.GroupSequence; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:16 PM + * @Version 1.0 + */ +@GroupSequence({AddGroup.class, UpdateGroup.class}) +public interface Group { +} diff --git a/ym-common/src/main/java/com/cnbm/common/validator/group/UpdateGroup.java b/ym-common/src/main/java/com/cnbm/common/validator/group/UpdateGroup.java new file mode 100644 index 0000000..35172e2 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/validator/group/UpdateGroup.java @@ -0,0 +1,9 @@ +package com.cnbm.common.validator.group; + +/** + * @Author weihongyang + * @Date 2022/6/7 3:16 PM + * @Version 1.0 + */ +public interface UpdateGroup { +} diff --git a/ym-common/src/main/resources/i18n/messages.properties b/ym-common/src/main/resources/i18n/messages.properties new file mode 100644 index 0000000..e4c723f --- /dev/null +++ b/ym-common/src/main/resources/i18n/messages.properties @@ -0,0 +1,26 @@ +#Default +500=\u670D\u52A1\u5668\u5185\u90E8\u5F02\u5E38 +401=\u672A\u6388\u6743 +10001={0}\u4E0D\u80FD\u4E3A\u7A7A +10002=\u6570\u636E\u5E93\u4E2D\u5DF2\u5B58\u5728\u8BE5\u8BB0\u5F55 +10003=\u83B7\u53D6\u53C2\u6570\u5931\u8D25 +10004=\u8D26\u53F7\u6216\u5BC6\u7801\u9519\u8BEF +10005=\u8D26\u53F7\u5DF2\u88AB\u505C\u7528 +10006=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A +10007=\u9A8C\u8BC1\u7801\u4E0D\u6B63\u786E +10008=\u5148\u5220\u9664\u5B50\u83DC\u5355\u6216\u6309\u94AE +10009=\u539F\u5BC6\u7801\u4E0D\u6B63\u786E +10010=\u8D26\u53F7\u4E0D\u5B58\u5728 +10011=\u4E0A\u7EA7\u90E8\u95E8\u9009\u62E9\u9519\u8BEF +10012=\u4E0A\u7EA7\u83DC\u5355\u4E0D\u80FD\u4E3A\u81EA\u8EAB +10013=\u6570\u636E\u6743\u9650\u63A5\u53E3\uFF0C\u53EA\u80FD\u662FMap\u7C7B\u578B\u53C2\u6570 +10014=\u8BF7\u5148\u5220\u9664\u4E0B\u7EA7\u90E8\u95E8 +10015=\u8BF7\u5148\u5220\u9664\u90E8\u95E8\u4E0B\u7684\u7528\u6237 +10019=\u8BF7\u4E0A\u4F20\u6587\u4EF6 +10020=token\u4E0D\u80FD\u4E3A\u7A7A +10021=token\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55 +10022=\u8D26\u53F7\u5DF2\u88AB\u9501\u5B9A +10024=\u4E0A\u4F20\u6587\u4EF6\u5931\u8D25{0} +10027=Redis\u670D\u52A1\u5F02\u5E38 +10028=\u5B9A\u65F6\u4EFB\u52A1\u5931\u8D25 +10029=\u4E0D\u80FD\u5305\u542B\u975E\u6CD5\u5B57\u7B26 \ No newline at end of file diff --git a/ym-common/src/main/resources/i18n/validation.properties b/ym-common/src/main/resources/i18n/validation.properties new file mode 100644 index 0000000..e2c400d --- /dev/null +++ b/ym-common/src/main/resources/i18n/validation.properties @@ -0,0 +1,67 @@ +#\u7B80\u4F53\u4E2D\u6587 +id.require=ID\u4E0D\u80FD\u4E3A\u7A7A +id.null=ID\u5FC5\u987B\u4E3A\u7A7A +pid.require=\u4E0A\u7EA7ID\uFF0C\u4E0D\u80FD\u4E3A\u7A7A +sort.number=\u6392\u5E8F\u503C\u4E0D\u80FD\u5C0F\u4E8E0 + +sysparams.paramcode.require=\u53C2\u6570\u7F16\u7801\u4E0D\u80FD\u4E3A\u7A7A +sysparams.paramvalue.require=\u53C2\u6570\u503C\u4E0D\u80FD\u4E3A\u7A7A + +sysuser.username.require=\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A +sysuser.password.require=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A +sysuser.realname.require=\u59D3\u540D\u4E0D\u80FD\u4E3A\u7A7A +sysuser.gender.range=\u6027\u522B\u53D6\u503C\u8303\u56F40~2 +sysuser.email.require=\u90AE\u7BB1\u4E0D\u80FD\u4E3A\u7A7A +sysuser.email.error=\u90AE\u7BB1\u683C\u5F0F\u4E0D\u6B63\u786E +sysuser.mobile.require=\u624B\u673A\u53F7\u4E0D\u80FD\u4E3A\u7A7A +sysuser.deptId.require=\u90E8\u95E8\u4E0D\u80FD\u4E3A\u7A7A +sysuser.superadmin.range=\u8D85\u7EA7\u7BA1\u7406\u5458\u53D6\u503C\u8303\u56F40~1 +sysuser.status.range=\u72B6\u6001\u53D6\u503C\u8303\u56F40~1 +sysuser.captcha.require=\u9A8C\u8BC1\u7801\u4E0D\u80FD\u4E3A\u7A7A +sysuser.uuid.require=\u552F\u4E00\u6807\u8BC6\u4E0D\u80FD\u4E3A\u7A7A + +sysmenu.pid.require=\u8BF7\u9009\u62E9\u4E0A\u7EA7\u83DC\u5355 +sysmenu.name.require=\u83DC\u5355\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A +sysmenu.type.range=\u83DC\u5355\u7C7B\u578B\u53D6\u503C\u8303\u56F40~1 + +sysdept.pid.require=\u8BF7\u9009\u62E9\u4E0A\u7EA7\u90E8\u95E8 +sysdept.name.require=\u90E8\u95E8\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A + +sysrole.name.require=\u89D2\u8272\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A + +sysdict.type.require=\u5B57\u5178\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A +sysdict.name.require=\u5B57\u5178\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A +sysdict.label.require=\u5B57\u5178\u6807\u7B7E\u4E0D\u80FD\u4E3A\u7A7A + +schedule.status.range=\u72B6\u6001\u53D6\u503C\u8303\u56F40~1 +schedule.cron.require=cron\u8868\u8FBE\u5F0F\u4E0D\u80FD\u4E3A\u7A7A +schedule.bean.require=bean\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A + +oss.type.range=\u7C7B\u578B\u53D6\u503C\u8303\u56F41~3 + +aliyun.accesskeyid.require=\u963F\u91CC\u4E91AccessKeyId\u4E0D\u80FD\u4E3A\u7A7A +aliyun.accesskeysecret.require=\u963F\u91CC\u4E91AccessKeySecret\u4E0D\u80FD\u4E3A\u7A7A +aliyun.signname.require=\u963F\u91CC\u4E91\u77ED\u4FE1\u7B7E\u540D\u4E0D\u80FD\u4E3A\u7A7A +aliyun.templatecode.require=\u963F\u91CC\u4E91\u77ED\u4FE1\u6A21\u677F\u4E0D\u80FD\u4E3A\u7A7A +aliyun.domain.require=\u963F\u91CC\u4E91\u7ED1\u5B9A\u7684\u57DF\u540D\u4E0D\u80FD\u4E3A\u7A7A +aliyun.domain.url=\u963F\u91CC\u4E91\u7ED1\u5B9A\u7684\u57DF\u540D\u683C\u5F0F\u4E0D\u6B63\u786E +aliyun.endPoint.require=\u963F\u91CC\u4E91EndPoint\u4E0D\u80FD\u4E3A\u7A7A +aliyun.bucketname.require=\u963F\u91CC\u4E91BucketName\u4E0D\u80FD\u4E3A\u7A7A + +qcloud.appid.require=\u817E\u8BAF\u4E91AppId\u4E0D\u80FD\u4E3A\u7A7A +qcloud.appkey.require=\u817E\u8BAF\u4E91AppKey\u4E0D\u80FD\u4E3A\u7A7A +qcloud.secretId.require=\u817E\u8BAF\u4E91SecretId\u4E0D\u80FD\u4E3A\u7A7A +qcloud.secretkey.require=\u817E\u8BAF\u4E91SecretKey\u4E0D\u80FD\u4E3A\u7A7A +qcloud.signname.require=\u817E\u8BAF\u4E91\u77ED\u4FE1\u7B7E\u540D\u4E0D\u80FD\u4E3A\u7A7A +qcloud.templateid.require=\u817E\u8BAF\u4E91\u77ED\u4FE1\u6A21\u677FID\u4E0D\u80FD\u4E3A\u7A7A +qcloud.domain.require=\u817E\u8BAF\u4E91\u7ED1\u5B9A\u7684\u57DF\u540D\u4E0D\u80FD\u4E3A\u7A7A +qcloud.domain.url=\u817E\u8BAF\u4E91\u7ED1\u5B9A\u7684\u57DF\u540D\u683C\u5F0F\u4E0D\u6B63\u786E +qcloud.bucketname.require=\u817E\u8BAF\u4E91BucketName\u4E0D\u80FD\u4E3A\u7A7A +qcloud.region.require=\u6240\u5C5E\u5730\u533A\u4E0D\u80FD\u4E3A\u7A7A + +qiniu.domain.require=\u4E03\u725B\u7ED1\u5B9A\u7684\u57DF\u540D\u4E0D\u80FD\u4E3A\u7A7A +qiniu.domain.url=\u4E03\u725B\u7ED1\u5B9A\u7684\u57DF\u540D\u683C\u5F0F\u4E0D\u6B63\u786E +qiniu.accesskey.require=\u4E03\u725BAccessKey\u4E0D\u80FD\u4E3A\u7A7A +qiniu.secretkey.require=\u4E03\u725BSecretKey\u4E0D\u80FD\u4E3A\u7A7A +qiniu.bucketname.require=\u4E03\u725B\u7A7A\u95F4\u540D\u4E0D\u80FD\u4E3A\u7A7A +qiniu.templateId.require=\u4E03\u725B\u6A21\u677FID\u4E0D\u80FD\u4E3A\u7A7A diff --git a/ym-gateway/pom.xml b/ym-gateway/pom.xml new file mode 100644 index 0000000..2d44c76 --- /dev/null +++ b/ym-gateway/pom.xml @@ -0,0 +1,42 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-gateway + + + 8 + 8 + + + + + com.cnbm + ym-common + 1.0-SNAPSHOT + + + com.cnbm + ym-admin + 1.0-SNAPSHOT + + + com.cnbm + ym-barcode + 1.0-SNAPSHOT + + + com.cnbm + ym-basic + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/ym-gateway/src/main/java/com/cnbm/AdminApplication.java b/ym-gateway/src/main/java/com/cnbm/AdminApplication.java new file mode 100644 index 0000000..afa4a80 --- /dev/null +++ b/ym-gateway/src/main/java/com/cnbm/AdminApplication.java @@ -0,0 +1,17 @@ +package com.cnbm; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @Author weihongyang + * @Date 2022/6/7 4:02 PM + * @Version 1.0 + */ +@SpringBootApplication + +public class AdminApplication { + public static void main(String[] args) { + SpringApplication.run(AdminApplication.class,args); + } +} diff --git a/ym-gateway/src/main/resources/application-dev.yml b/ym-gateway/src/main/resources/application-dev.yml new file mode 100644 index 0000000..609c59e --- /dev/null +++ b/ym-gateway/src/main/resources/application-dev.yml @@ -0,0 +1,40 @@ +spring: + datasource: + #MySQL + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://mysql.picaiba.com:30307/ym_pass?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true + username: root + password: 1qaz@WSX3edc$RFV + # #Oracle + # driver-class-name: oracle.jdbc.OracleDriver + # url: jdbc:oracle:thin:@192.168.10.10:1521:xe + # username: renren_security + # password: 123456 + # #SQLServer + # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + # url: jdbc:sqlserver://localhost:1433;DatabaseName=renren_security + # username: sa + # password: 123456 + # #postgresql + # driver-class-name: org.postgresql.Driver + # url: jdbc:postgresql://192.168.10.10:5432/postgres + # username: postgres + # password: 123456 + hikari: + pool-name: GrowUpHikariCP + minimum-idle: 1 + maximum-pool-size: 10 + +##多数据源的配置,需要引用renren-dynamic-datasource +#dynamic: +# datasource: +# slave1: +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver +# url: jdbc:sqlserver://123456:1433;DatabaseName=renren_security +# username: sa +# password: 123456 +# slave2: +# driver-class-name: org.postgresql.Driver +# url: jdbc:postgresql://123456:5432/renren_security +# username: postgres +# password: 123456 \ No newline at end of file diff --git a/ym-gateway/src/main/resources/application.yml b/ym-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..84fb44c --- /dev/null +++ b/ym-gateway/src/main/resources/application.yml @@ -0,0 +1,75 @@ +# Tomcat +server: + tomcat: + uri-encoding: UTF-8 + threads: + max: 1000 + min-spare: 30 + port: 8080 + servlet: + context-path: /ym-admin + session: + cookie: + http-only: true + +spring: + application: + name: ym-admin + # 环境 dev|test|prod + profiles: + active: dev + messages: + encoding: UTF-8 + basename: i18n/messages + mvc: + pathmatch: + matching-strategy: ANT_PATH_MATCHER + servlet: + multipart: + max-file-size: 100MB + max-request-size: 100MB + enabled: true + redis: + database: 0 + host: 124.221.241.144 + port: 6379 + password: why123456 # 密码(默认为空) + timeout: 6000ms # 连接超时时长(毫秒) + jedis: + pool: + max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) + max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-idle: 10 # 连接池中的最大空闲连接 + min-idle: 5 # 连接池中的最小空闲连接 + +# 是否开启redis缓存 true开启 false关闭 +renren: + redis: + open: false + +#mybatis +mybatis-plus: + mapper-locations: classpath*:/mapper/*.xml + #实体扫描,多个package用逗号或者分号分隔 + typeAliasesPackage: com.cnbm.admin.*.entity + global-config: + #数据库相关配置 + db-config: + #主键类型 + id-type: ASSIGN_ID + banner: false + #原生配置 + configuration: + map-underscore-to-camel-case: true + cache-enabled: false + call-setters-on-nulls: true + jdbc-type-for-null: 'null' + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + configuration-properties: + prefix: + blobType: BLOB + boolValue: TRUE + +logging: + level: + com.cnbm.admin.dao: DEBUG \ No newline at end of file diff --git a/ym-gateway/src/main/resources/banner.txt b/ym-gateway/src/main/resources/banner.txt new file mode 100644 index 0000000..ca33953 --- /dev/null +++ b/ym-gateway/src/main/resources/banner.txt @@ -0,0 +1,11 @@ +==================================================================================================================== +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} + _________ _______ __________ _____ + \_ ___ \ \ \\______ \ / \ + / \ \/ / | \| | _/ / \ / \ + \ \____/ | \ | \/ Y \ + \______ /\____|__ /______ /\____|__ / + \/ \/ \/ \/ + +==================================================================================================================== \ No newline at end of file diff --git a/ym-generator/pom.xml b/ym-generator/pom.xml new file mode 100644 index 0000000..bdce567 --- /dev/null +++ b/ym-generator/pom.xml @@ -0,0 +1,70 @@ + + + + ym-pass + com.cnbm + 1.0-SNAPSHOT + + 4.0.0 + + ym-generator + + + 8 + 8 + + + + + com.cnbm + ym-common + 1.0-SNAPSHOT + + + com.cnbm + ym-admin + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-security + + + com.baomidou + mybatis-plus-generator + 3.5.1 + + + com.baomidou + mybatis-plus-boot-starter + 3.5.1 + + + org.freemarker + freemarker + 2.3.29 + + + org.springframework.boot + spring-boot-starter-freemarker + + + org.junit.jupiter + junit-jupiter-api + + + org.jetbrains + annotations + 13.0 + + + + org.apache.velocity + velocity-engine-core + 2.3 + + + + \ No newline at end of file diff --git a/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java b/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java new file mode 100644 index 0000000..c4d11fc --- /dev/null +++ b/ym-generator/src/main/java/com/cnbm/generator/build/CodeGenerator.java @@ -0,0 +1,148 @@ +package com.cnbm.generator.build; + +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; +import com.baomidou.mybatisplus.generator.function.ConverterFileName; +import com.cnbm.generator.config.DataConfig; +import com.cnbm.generator.engine.EnhanceVelocityTemplateEngine; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.*; + +import static com.baomidou.mybatisplus.generator.config.ConstVal.MODULE_NAME; + +/** + * @Author weihongyang + * @Date 2022/6/14 8:47 AM + * @Version 1.0 + */ +public class CodeGenerator { + + + @Test + public void test(){ + mybatisPlusGenerator(new String[]{"sys_user"}); + } + + public static void mybatisPlusGenerator(String[] include){ + File file = new File(""); + String path = file.getAbsolutePath(); + Map customFile = new HashMap<>(); + customFile.put("DTO","/templates/DTO.java.vm"); + customFile.put("Excel","/templates/Excel.java.vm"); + +// customFile.put("Excel","/templates/excel.java.vm"); +// new TemplateConfig.Builder().serviceImpl("/templates/serviceImpl.java"); + FastAutoGenerator.create(DataConfig.url,DataConfig.username,DataConfig.password) + .globalConfig(builder -> { + builder.author("why") + .enableSwagger() + .fileOverride() + .outputDir(path+"/src/main/java"); + }) + .packageConfig(builder -> { + //设置父包名 + builder.parent("com.cnbm") + .moduleName("generator") + .service("service") + .serviceImpl("service.impl") + .entity("entity") + .mapper("mapper") + .controller("controller") + .xml("mapper"); + }) + .strategyConfig(builder -> { + //设置需要生成的表名 + builder.addInclude(include) + //设置过滤表前缀 + .addTablePrefix("sys_") +// .entityBuilder().formatFileName("%sEntity") +// .mapperBuilder().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper") +// .controllerBuilder().formatFileName("%sController").enableRestStyle() +// .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl") + ; + }) + .injectionConfig(consumer -> { + + consumer.customFile(customFile); + }) + .templateEngine(new EnhanceVelocityTemplateEngine()) +// .templateEngine(new VelocityTemplateEngine(){ +// @Override +// protected void outputCustomFile(@NotNull Map customFile, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { +// //存放取出的实体名称,用于生成路由 +// List entityNames = new ArrayList<>(); +// +// if (!entityNames.contains(tableInfo.getEntityName())) { +// entityNames.add(tableInfo.getEntityName()); +// } +// +// customFile.forEach((key, value) -> { +// String fileName = String.format(path + "/src/main/resources/static/" + tableInfo.getEntityName() + File.separator + tableInfo.getEntityName() + "%s", key); +// this.outputFile(new File(fileName), objectMap, ""); +// }); +// +// // 生成路由部分 +// Map routers = new HashMap<>(); +// routers.put("author", "why"); +// routers.put("date", new Date()); +// routers.put("entities", entityNames); +// +// // 使用 freemarker 模板引擎,路由页面路径 +// String templateRoutesPath = "/templates/DTO.java.vm"; +// +// // 生成的路由页面路径 +// File templateRoutesOutFile = new File(path + "/src/main/java/com/cnbm/generator/engine/"+tableInfo.getEntityName() +"DTO.java"); +// try { +// this.writer(routers, templateRoutesPath, templateRoutesOutFile); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// }) + + +// .templateEngine(new FreemarkerTemplateEngine(){ +// @Override +// protected void outputCustomFile(@NotNull Map customFile, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { +// //存放取出的实体名称,用于生成路由 +// List entityNames = new ArrayList<>(); +// +// if (!entityNames.contains(tableInfo.getEntityName())) { +// entityNames.add(tableInfo.getEntityName()); +// } +// +// customFile.forEach((key, value) -> { +// String fileName = String.format(path + "/src/main/resources/static/" + tableInfo.getEntityName() + File.separator + tableInfo.getEntityName() + "%s", key); +// this.outputFile(new File(fileName), objectMap, ""); +// }); +// +// // 生成路由部分 +// Map routers = new HashMap<>(); +// routers.put("author", "why"); +// routers.put("date", new Date()); +// routers.put("entities", entityNames); +// +// // 使用 freemarker 模板引擎,路由页面路径 +// String templateRoutesPath = "/templates/excel.java.ftl"; +// +// // 生成的路由页面路径 +// File templateRoutesOutFile = new File(path + "/src/main/java/com/cnbm/generator/engine/excel.java"); +// try { +// this.writer(routers, templateRoutesPath, templateRoutesOutFile); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// +// }) + .execute(); + } + +} diff --git a/ym-generator/src/main/java/com/cnbm/generator/config/DataConfig.java b/ym-generator/src/main/java/com/cnbm/generator/config/DataConfig.java new file mode 100644 index 0000000..6258ed3 --- /dev/null +++ b/ym-generator/src/main/java/com/cnbm/generator/config/DataConfig.java @@ -0,0 +1,16 @@ +package com.cnbm.generator.config; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * @Author weihongyang + * @Date 2022/6/14 1:28 PM + * @Version 1.0 + */ +public class DataConfig { + public static final String url = "jdbc:mysql://mysql.picaiba.com:30307/ym_pass?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true"; + public static final String username = "root"; + public static final String password = "1qaz@WSX3edc$RFV"; +} diff --git a/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java b/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java new file mode 100644 index 0000000..5dc7229 --- /dev/null +++ b/ym-generator/src/main/java/com/cnbm/generator/engine/EnhanceVelocityTemplateEngine.java @@ -0,0 +1,55 @@ +package com.cnbm.generator.engine; + +import com.baomidou.mybatisplus.generator.config.OutputFile; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.Map; + +/** + * @Author weihongyang + * @Date 2022/6/17 10:27 AM + * @Version 1.0 + */ +public class EnhanceVelocityTemplateEngine extends VelocityTemplateEngine { + @Override + protected void outputCustomFile(@NotNull Map customFile, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { + String entityName = tableInfo.getEntityName(); + System.out.println(entityName); +// String otherPath = this.getPathInfo(OutputFile.other); + File file = new File(""); + String path = file.getAbsolutePath(); + customFile.forEach((key, value) -> { + String fileName = ""; + if ("DTO".equals(key)) { + fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "dto" + File.separator + entityName + "%s" + ".java"), key); + } + if ("Excel".equals(key)) { + fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "excel" + File.separator + entityName + "%s" + ".java"), key); + } + this.outputFile(new File(fileName), objectMap, value); + }); + } + +// @Override +// public void writer(Map objectMap, String templatePath, File outputFile) throws Exception { +// // 获取table +// TableInfo tableInfo = (TableInfo) objectMap.get("table"); +// // 取出Service接口的名字,进行首字母小写处理 +// String serviceNameFirstWord = tableInfo.getServiceName().substring(0,1).toLowerCase(); +// String serviceNameFirstWordToLower = serviceNameFirstWord + tableInfo.getServiceName().substring(1); +// objectMap.put("serviceNameFirstWordToLower", serviceNameFirstWordToLower); +// +// // 取出mapper接口的名字,进行首字母小写处理 +// String mapperNameFirstWord = tableInfo.getMapperName().substring(0, 1).toLowerCase(); +// String mapperNameFirstWordToLower = mapperNameFirstWord + tableInfo.getMapperName().substring(1); +// objectMap.put("mapperNameFirstWordToLower", mapperNameFirstWordToLower); +// +// // 对Form、VO文件的处理 +//// new FormHandler().handler(objectMap); +// super.writer(objectMap, templatePath, outputFile); +// } + +} diff --git a/ym-generator/src/main/resources/templates/DTO.java.vm b/ym-generator/src/main/resources/templates/DTO.java.vm new file mode 100644 index 0000000..8daa30e --- /dev/null +++ b/ym-generator/src/main/resources/templates/DTO.java.vm @@ -0,0 +1,32 @@ +package ${package.Parent}.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +#if(${hasBigDecimal}) +import java.math.BigDecimal; +#end + +/** + * ${table.comment} + * + * @author ${author} + * @since ${date} + */ +@Data +@ApiModel(value = "${table.comment}DTO对象") +public class ${entity}DTO implements Serializable { + private static final long serialVersionUID = 1L; + + +#foreach($field in ${table.fields}) + + @ApiModelProperty(value = "${field.comment}") + private ${field.propertyType} ${field.propertyName}; +#end + +} \ No newline at end of file diff --git a/ym-generator/src/main/resources/templates/Excel.java.vm b/ym-generator/src/main/resources/templates/Excel.java.vm new file mode 100644 index 0000000..df69096 --- /dev/null +++ b/ym-generator/src/main/resources/templates/Excel.java.vm @@ -0,0 +1,24 @@ +package ${package.Parent}.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +#if(${hasBigDecimal}) +import java.math.BigDecimal; +#end +import java.util.Date; + +/** + * ${table.comment} + * + * @author ${author} + * @since ${date} + */ +@Data +public class ${entity}Excel { +#foreach($field in ${table.fields}) + @Excel(name = "$!field.comment") + private ${field.propertyType} ${field.propertyName}; +#end + +} \ No newline at end of file diff --git a/ym-generator/src/main/resources/templates/controller.java.vm b/ym-generator/src/main/resources/templates/controller.java.vm new file mode 100644 index 0000000..f4e622c --- /dev/null +++ b/ym-generator/src/main/resources/templates/controller.java.vm @@ -0,0 +1,116 @@ +package ${package.Controller}; + +import com.cnbm.admin.annotation.LogOperation; +import com.cnbm.common.constant.Constant; +import com.cnbm.common.page.PageData; +import com.cnbm.common.utils.ExcelUtils; +import com.cnbm.common.utils.Result; +import com.cnbm.common.validator.AssertUtils; +import com.cnbm.common.validator.ValidatorUtils; +import com.cnbm.common.validator.group.AddGroup; +import com.cnbm.common.validator.group.DefaultGroup; +import com.cnbm.common.validator.group.UpdateGroup; +import ${package.Parent}.dto.${entity}DTO; +import ${package.Parent}.excel.${entity}Excel; +import ${package.Service}.${table.serviceName}; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * ${table.comment} 前端控制器 + * + * @author ${author} + * @since ${date} + */ +@RestController +@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") +@Api(tags="${table.comment}") +public class ${table.controllerName} { + @Autowired + private ${table.serviceName} ${table.entityPath}Service; + + @GetMapping("page") + @ApiOperation("分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") + }) + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:page')") + public Result> page(@ApiIgnore @RequestParam Map params){ + PageData<${entity}DTO> page = ${table.entityPath}Service.page(params); + + return new Result>().ok(page); + } + + @GetMapping("{id}") + @ApiOperation("信息") + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:info')") + public Result<${entity}DTO> get(@PathVariable("id") Long id){ + ${entity}DTO data = ${table.entityPath}Service.get(id); + + return new Result<${entity}DTO>().ok(data); + } + + @PostMapping + @ApiOperation("保存") + @LogOperation("保存") + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:save')") + public Result save(@RequestBody ${entity}DTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + + ${table.entityPath}Service.save(dto); + + return new Result(); + } + + @PutMapping + @ApiOperation("修改") + @LogOperation("修改") + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:update')") + public Result update(@RequestBody ${entity}DTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + + ${table.entityPath}Service.update(dto); + + return new Result(); + } + + @DeleteMapping + @ApiOperation("删除") + @LogOperation("删除") + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:delete')") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + ${table.entityPath}Service.delete(ids); + + return new Result(); + } + + @GetMapping("export") + @ApiOperation("导出") + @LogOperation("导出") + @PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:export')") + public void export(@ApiIgnore @RequestParam Map params, HttpServletResponse response) throws Exception { + List<${entity}DTO> list = ${table.entityPath}Service.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, ${entity}Excel.class); + } + +} \ No newline at end of file diff --git a/ym-generator/src/main/resources/templates/entity.java.vm b/ym-generator/src/main/resources/templates/entity.java.vm new file mode 100644 index 0000000..ef0d834 --- /dev/null +++ b/ym-generator/src/main/resources/templates/entity.java.vm @@ -0,0 +1,120 @@ +package ${package.Entity}; + +#foreach($pkg in ${table.importPackages}) +import ${pkg}; +#end +#if(${swagger}) +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +#end +#if(${entityLombokModel}) +import lombok.Getter; +import lombok.Setter; +#if(${chainModel}) +import lombok.experimental.Accessors; +#end +#end +import lombok.Data; + +/** + *

+ * $!{table.comment} + *

+ * + * @author ${author} + * @since ${date} + */ +@Data +#if(${entityLombokModel}) +@Getter +@Setter + #if(${chainModel}) +@Accessors(chain = true) + #end +#end +#if(${table.convert}) +@TableName("${schemaName}${table.name}") +#end +#if(${swagger}) +@ApiModel(value = "${entity}对象", description = "$!{table.comment}") +#end +#if(${superEntityClass}) +public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end { +#elseif(${activeRecord}) +public class ${entity} extends Model<${entity}> { +#elseif(${entitySerialVersionUID}) +public class ${entity} implements Serializable { +#else +public class ${entity} { +#end +#if(${entitySerialVersionUID}) + + private static final long serialVersionUID = 1L; +#end +## ---------- BEGIN 字段循环遍历 ---------- +#foreach($field in ${table.fields}) + +#if(${field.keyFlag}) +#set($keyPropertyName=${field.propertyName}) +#end +#if("$!field.comment" != "") + #if(${swagger}) + @ApiModelProperty("${field.comment}") + #else + /** + * ${field.comment} + */ + #end +#end +#if(${field.keyFlag}) +## 主键 + #if(${field.keyIdentityFlag}) + @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) + #elseif(!$null.isNull(${idType}) && "$!idType" != "") + @TableId(value = "${field.annotationColumnName}", type = IdType.${idType}) + #elseif(${field.convert}) + @TableId("${field.annotationColumnName}") + #end +## 普通字段 +#elseif(${field.fill}) +## ----- 存在字段填充设置 ----- + #if(${field.convert}) + @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) + #else + @TableField(fill = FieldFill.${field.fill}) + #end +#elseif(${field.convert}) + @TableField("${field.annotationColumnName}") +#end +## 乐观锁注解 +#if(${field.versionField}) + @Version +#end +## 逻辑删除注解 +#if(${field.logicDeleteField}) + @TableLogic +#end + private ${field.propertyType} ${field.propertyName}; +#end +## ---------- END 字段循环遍历 ---------- + +## --end of #if(!${entityLombokModel})-- + +#if(${entityColumnConstant}) + #foreach($field in ${table.fields}) + public static final String ${field.name.toUpperCase()} = "${field.name}"; + + #end +#end +#if(${activeRecord}) + @Override + public Serializable pkVal() { + #if(${keyPropertyName}) + return this.${keyPropertyName}; + #else + return null; + #end + } + +#end +} diff --git a/ym-generator/src/main/resources/templates/mapper.java.vm b/ym-generator/src/main/resources/templates/mapper.java.vm new file mode 100644 index 0000000..1075311 --- /dev/null +++ b/ym-generator/src/main/resources/templates/mapper.java.vm @@ -0,0 +1,16 @@ +package ${package.Mapper}; + +import com.cnbm.common.dao.BaseDao; +import ${package.Entity}.${table.entityName}; +import org.apache.ibatis.annotations.Mapper; + +/** + * ${table.comment} + * + * @author ${author} + * @since ${date} + */ +@Mapper +public interface ${table.mapperName} extends BaseDao<${entity}> { + +} \ No newline at end of file diff --git a/ym-generator/src/main/resources/templates/mapper.xml.vm b/ym-generator/src/main/resources/templates/mapper.xml.vm new file mode 100644 index 0000000..b0909e8 --- /dev/null +++ b/ym-generator/src/main/resources/templates/mapper.xml.vm @@ -0,0 +1,39 @@ + + + + +#if(${enableCache}) + + + +#end +#if(${baseResultMap}) + + +#foreach($field in ${table.fields}) +#if(${field.keyFlag})##生成主键排在第一位 + +#end +#end +#foreach($field in ${table.commonFields})##生成公共字段 + +#end +#foreach($field in ${table.fields}) +#if(!${field.keyFlag})##生成普通字段 + +#end +#end + + +#end +#if(${baseColumnList}) + + +#foreach($field in ${table.commonFields}) + ${field.columnName}, +#end + ${table.fieldNames} + + +#end + diff --git a/ym-generator/src/main/resources/templates/service.java.vm b/ym-generator/src/main/resources/templates/service.java.vm new file mode 100644 index 0000000..7c15d95 --- /dev/null +++ b/ym-generator/src/main/resources/templates/service.java.vm @@ -0,0 +1,15 @@ +package ${package.Service}; + +import com.cnbm.common.service.CrudService; +import ${package.Parent}.dto.${table.entityName}DTO; +import ${package.Entity}.${table.entityName}; + +/** + * ${table.comment} + * + * @author ${author} + * @since ${date} + */ +public interface ${table.serviceName} extends CrudService<${table.entityName}, ${table.entityName}DTO> { + +} \ No newline at end of file diff --git a/ym-generator/src/main/resources/templates/serviceImpl.java.vm b/ym-generator/src/main/resources/templates/serviceImpl.java.vm new file mode 100644 index 0000000..7e5cb38 --- /dev/null +++ b/ym-generator/src/main/resources/templates/serviceImpl.java.vm @@ -0,0 +1,34 @@ +package ${package.ServiceImpl}; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.cnbm.common.service.impl.CrudServiceImpl; +import ${package.Parent}.dto.${table.entityName}DTO; +import ${package.Mapper}.${table.mapperName}; +import ${package.Entity}.${table.entityName}; +import ${package.Service}.${table.serviceName}; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * ${table.comment} + * + * @author ${author} + * @since ${date} + */ +@Service +public class ${table.serviceImplName} extends CrudServiceImpl<${table.mapperName}, ${table.entityName}, ${entity}DTO> implements ${table.serviceName} { + + @Override + public QueryWrapper<${entity}> getWrapper(Map params){ + String id = (String)params.get("id"); + + QueryWrapper<${entity}> wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), "id", id); + + return wrapper; + } + + +} \ No newline at end of file