From 3f61afa70f599407ea4c14f5dda64473522bae4d Mon Sep 17 00:00:00 2001 From: zhouhao Date: Fri, 6 Jan 2017 18:10:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E4=BD=93=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/authorization/Authorize.java | 11 + .../web/authorization/UserSubject.java | 1 - .../web/commons/beans/CloneableBean.java | 10 - .../web/controller/CrudController.java | 5 +- ...ller.java => GenericEntityController.java} | 10 +- .../hsweb-commons-dao-api/pom.xml | 2 +- .../org/hswebframework/web/dao/CrudDao.java | 4 +- .../web/dao/dynamic/DeleteByBeanDao.java | 4 +- .../web/dao/dynamic/QueryByBeanDao.java | 6 +- ...eByBeanDao.java => UpdateByEntityDao.java} | 6 +- .../pom.xml | 2 +- .../web/commons/entity/CloneableEntity.java | 10 + .../web/commons/entity/Entity.java} | 4 +- .../web/commons/entity/GenericEntity.java} | 17 +- .../web/commons/entity}/PagerResult.java | 4 +- .../web/commons/entity/SharedEntity.java} | 8 +- .../commons/entity/SimpleGenericEntity.java} | 6 +- .../commons/entity/SimpleSharedEntity.java} | 8 +- .../web/commons/entity}/SortSupport.java | 4 +- .../entity/TreeSortSupportEntity.java} | 6 +- .../web/commons/entity}/TreeSupport.java | 4 +- .../entity/factory/EntityFactory.java} | 20 +- .../entity/factory/MapperEntityFactory.java} | 64 +++-- .../entity/param/DeleteParamEntity.java} | 16 +- .../entity/param/QueryParamEntity.java} | 18 +- .../entity/param/UpdateParamEntity.java} | 22 +- ...nService.java => CreateEntityService.java} | 6 +- .../web/service/CrudService.java | 8 +- ...Service.java => QueryByEntityService.java} | 7 +- .../hswebframework/web/service/Validator.java | 14 + .../web/service/AbstractService.java | 107 ++++++++ .../web/service/DefaultDSLDeleteService.java | 14 +- .../web/service/DefaultDSLQueryService.java | 12 +- .../web/service/DefaultDSLUpdateService.java | 18 +- ....java => DefaultQueryByEntityService.java} | 24 +- .../web/service/GenericBeanService.java | 147 ----------- .../web/service/GenericEntityService.java | 93 +++++++ .../web/service/GenericService.java | 6 +- .../web/service/dsl/DSLQuery.java | 4 +- .../web/service/dsl/SimpleDSLQuery.java | 10 +- .../web/service/dsl/SimpleFieldCondition.java | 10 +- hsweb-commons/hsweb-commons-service/pom.xml | 2 +- hsweb-commons/pom.xml | 2 +- .../web/validate/ValidationException.java | 7 +- hsweb-message/README.md | 2 +- hsweb-message/hsweb-message-api/pom.xml | 14 + .../hswebframework/web/message/Message.java | 11 + .../web/message/MessageListener.java | 10 + .../web/message/MessageManager.java | 17 ++ hsweb-message/hsweb-message-jms/pom.xml | 37 +++ .../web/message/jms/JmsMessageManager.java | 35 +++ .../web/message/jms/AmqpTests.java | 55 ++++ .../web/message/jms/Consumer.java | 26 ++ .../web/message/jms/Consumer2.java | 15 ++ .../jms/SampleActiveMQApplication.java | 31 +++ .../src/test/resources/application.yml | 15 ++ hsweb-message/pom.xml | 5 + hsweb-system/README.md | 2 +- .../pom.xml | 26 ++ .../web/dao/authorization/PermissionDao.java | 13 + .../dao/authorization/PermissionRoleDao.java | 25 ++ .../web/dao/authorization/RoleDao.java | 12 + .../web/dao/authorization/UserDao.java | 12 + .../web/dao/authorization/UserRoleDao.java | 23 ++ .../pom.xml | 43 +++ .../authorization/PermissionMapper.xml | 66 +++++ .../authorization/PermissionRoleMapper.xml | 67 +++++ .../mappers/authorization/RoleMapper.xml | 65 +++++ .../mappers/authorization/UserMapper.xml | 70 +++++ .../mappers/authorization/UserRoleMapper.xml | 56 ++++ .../hsweb-system-authorization-dao/pom.xml | 19 ++ .../pom.xml | 4 +- .../entity/authorization/ActionEntity.java | 17 ++ .../entity/authorization/Authorization.java | 18 ++ .../authorization/PermissionEntity.java | 24 ++ .../authorization/PermissionReadEntity.java | 22 ++ .../authorization/PermissionRoleEntity.java | 20 ++ .../PermissionRoleReadEntity.java | 19 ++ .../web/entity/authorization/RoleEntity.java | 23 ++ .../authorization/SimpleActionEntity.java | 62 +++++ .../authorization/SimplePermissionEntity.java | 70 +++++ .../SimplePermissionRoleEntity.java | 57 ++++ .../authorization/SimpleRoleEntity.java | 53 ++++ .../authorization/SimpleUserEntity.java | 111 ++++++++ .../authorization/SimpleUserRoleEntity.java | 41 +++ .../web/entity/authorization/UserEntity.java} | 27 +- .../entity/authorization/UserReadEntity.java | 27 ++ .../entity/authorization/UserRoleEntity.java | 19 ++ .../authorization/WebPermissionEntity.java | 17 ++ .../bind/BindPermissionRoleEntity.java | 17 ++ .../bind/BindRoleUserEntity.java | 16 ++ .../bind/SimpleBindPermissionRoleEntity.java | 38 +++ .../bind/SimpleBindRoleUserEntity.java | 43 +++ .../pom.xml | 26 ++ .../PasswordStrengthValidator.java | 11 + .../authorization/PermissionService.java | 15 ++ .../service/authorization/RoleService.java | 28 ++ .../service/authorization/UserService.java | 42 +++ .../authorization/UsernameValidator.java | 11 + .../pom.xml | 32 +++ .../simple/SimpleAuthorization.java | 146 ++++++++++ .../simple/SimplePermissionService.java | 27 ++ .../simple/SimpleRoleService.java | 106 ++++++++ .../simple/SimpleUserService.java | 249 ++++++++++++++++++ .../pom.xml | 18 ++ .../pom.xml | 78 ++++++ .../src/main/resources/hsweb-starter.js | 92 +++++++ .../authorization/PermissionTests.java | 78 ++++++ .../web/starter/authorization/UserTests.java | 165 ++++++++++++ .../src/test/resources/application.yml | 13 + .../hsweb-system-authorization/pom.xml | 5 +- .../web/bean/config/ConfigQueryBean.java | 15 -- .../controller/config/ConfigController.java | 13 +- .../hsweb-system-config-dao-api/pom.xml | 2 +- .../web/dao/config/ConfigDao.java | 4 +- .../hsweb-system-config-dao-mybatis/pom.xml | 5 + .../mybatis/mappers/config/ConfigMapper.xml | 12 +- .../pom.xml | 4 +- .../web/entity}/config/ConfigContent.java | 10 +- .../web/entity/config/ConfigEntity.java} | 8 +- .../entity/config/SimpleConfigEntity.java} | 15 +- .../hsweb-system-config-service-api/pom.xml | 2 +- .../ConfigService.java | 6 +- .../config/simple/SimpleConfigService.java | 10 +- .../service/config/ConfigServiceTests.java | 2 +- .../web/starter/config/ConfigTests.java | 27 +- .../src/test/resources/application.yml | 2 +- hsweb-system/hsweb-system-config/pom.xml | 2 +- hsweb-system/hsweb-system-document/pom.xml | 15 ++ hsweb-system/pom.xml | 1 + .../web/tests/SimpleWebApplicationTests.java | 14 +- pom.xml | 2 +- 132 files changed, 3168 insertions(+), 425 deletions(-) delete mode 100644 hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/CloneableBean.java rename hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/{GenericBeanController.java => GenericEntityController.java} (79%) rename hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/{UpdateByBeanDao.java => UpdateByEntityDao.java} (86%) rename hsweb-commons/{hsweb-commons-beans => hsweb-commons-entity}/pom.xml (97%) create mode 100644 hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/CloneableEntity.java rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/Bean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/Entity.java} (88%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/GenericBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/GenericEntity.java} (73%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity}/PagerResult.java (93%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SharedBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SharedEntity.java} (81%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleGenericBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleGenericEntity.java} (90%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleSharedBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleSharedEntity.java} (80%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity}/SortSupport.java (88%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSortSupportBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSortSupportEntity.java} (90%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity}/TreeSupport.java (96%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/BeanFactory.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/EntityFactory.java} (72%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/MapperBeanFactory.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java} (54%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/DeleteParamBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/DeleteParamEntity.java} (52%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/QueryParamBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/QueryParamEntity.java} (63%) rename hsweb-commons/{hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/UpdateParamBean.java => hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/UpdateParamEntity.java} (61%) rename hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/{CreateBeanService.java => CreateEntityService.java} (89%) rename hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/{QueryByBeanService.java => QueryByEntityService.java} (82%) create mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/Validator.java create mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java rename hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/{DefaultQueryByBeanService.java => DefaultQueryByEntityService.java} (81%) delete mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericBeanService.java create mode 100644 hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java create mode 100644 hsweb-message/hsweb-message-api/pom.xml create mode 100644 hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Message.java create mode 100644 hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java create mode 100644 hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java create mode 100644 hsweb-message/hsweb-message-jms/pom.xml create mode 100644 hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java create mode 100644 hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/AmqpTests.java create mode 100644 hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer.java create mode 100644 hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer2.java create mode 100644 hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/SampleActiveMQApplication.java create mode 100644 hsweb-message/hsweb-message-jms/src/test/resources/application.yml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionRoleDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/RoleDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionRoleMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/RoleMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserRoleMapper.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/pom.xml rename hsweb-system/hsweb-system-authorization/{hsweb-system-authorization-bean => hsweb-system-authorization-entity}/pom.xml (92%) create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/Authorization.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionReadEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleReadEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/RoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleActionEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserRoleEntity.java rename hsweb-system/hsweb-system-authorization/{hsweb-system-authorization-bean/src/main/java/org/hswebframework/web/bean/authorization/UserBean.java => hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserEntity.java} (61%) create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserReadEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/WebPermissionEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindPermissionRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindRoleUserEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindPermissionRoleEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindRoleUserEntity.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PasswordStrengthValidator.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PermissionService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/RoleService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UsernameValidator.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorization.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimplePermissionService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleRoleService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/PermissionTests.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/UserTests.java create mode 100644 hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/resources/application.yml delete mode 100644 hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigQueryBean.java rename hsweb-system/hsweb-system-config/{hsweb-system-config-bean => hsweb-system-config-entity}/pom.xml (92%) rename hsweb-system/hsweb-system-config/{hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean => hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity}/config/ConfigContent.java (83%) rename hsweb-system/hsweb-system-config/{hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigBean.java => hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigEntity.java} (89%) rename hsweb-system/hsweb-system-config/{hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/SimpleConfigBean.java => hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/SimpleConfigEntity.java} (86%) create mode 100644 hsweb-system/hsweb-system-document/pom.xml diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authorize.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authorize.java index b2e39cb92..faefe32f1 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authorize.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authorize.java @@ -25,6 +25,7 @@ import java.lang.annotation.*; */ @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) +@Inherited @Documented public @interface Authorize { @@ -49,8 +50,18 @@ public @interface Authorize { */ String[] action() default {}; + /** + * 验证是否为指定user + * + * @return + */ String[] user() default {}; + /** + * 验证失败时返回的消息 + * + * @return + */ String message() default "{unauthorized}"; /** diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/UserSubject.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/UserSubject.java index 069014fbd..ae32a71b8 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/UserSubject.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/UserSubject.java @@ -23,7 +23,6 @@ import java.util.Set; /** * @author zhouhao */ -@Authorize(user = "{data.creatorId}") public interface UserSubject { String getUsername(); diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/CloneableBean.java b/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/CloneableBean.java deleted file mode 100644 index 1ab98a265..000000000 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/CloneableBean.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.hswebframework.web.commons.beans; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public interface CloneableBean extends Bean, Cloneable { - CloneableBean clone(); -} diff --git a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CrudController.java b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CrudController.java index 366a0b11c..f45270265 100644 --- a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CrudController.java +++ b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/CrudController.java @@ -19,12 +19,11 @@ package org.hswebframework.web.controller; import org.hswebframework.web.authorization.Authorize; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; import org.hswebframework.web.controller.message.ResponseMessage; import org.hswebframework.web.logging.AccessLogger; import org.hswebframework.web.service.CrudService; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import static org.hswebframework.web.controller.message.ResponseMessage.ok; @@ -34,7 +33,7 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok; * * @author zhouhao */ -public interface CrudController { +public interface CrudController { CrudService getService(); diff --git a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericBeanController.java b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericEntityController.java similarity index 79% rename from hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericBeanController.java rename to hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericEntityController.java index 9119bb7c4..836bb926d 100644 --- a/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericBeanController.java +++ b/hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericEntityController.java @@ -18,8 +18,8 @@ package org.hswebframework.web.controller; -import org.hswebframework.web.commons.beans.GenericBean; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.commons.entity.GenericEntity; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.controller.message.ResponseMessage; import org.hswebframework.web.service.CrudService; import org.springframework.web.bind.annotation.PathVariable; @@ -32,10 +32,10 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok; * * @author zhouhao */ -public interface GenericBeanController, PK> - extends CrudController { +public interface GenericEntityController, PK> + extends CrudController { - CrudService getService(); + CrudService getService(); @Override default ResponseMessage updateByPrimaryKey(@PathVariable PK id, @RequestBody B data) { diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml index 92e80b0f8..b06adc228 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/pom.xml @@ -32,7 +32,7 @@ org.hswebframework.web - hsweb-commons-beans + hsweb-commons-entity ${project.version} diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/CrudDao.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/CrudDao.java index be6731077..37f31f6ae 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/CrudDao.java +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/CrudDao.java @@ -18,7 +18,7 @@ package org.hswebframework.web.dao; -import org.hswebframework.web.dao.dynamic.UpdateByBeanDao; +import org.hswebframework.web.dao.dynamic.UpdateByEntityDao; import org.hswebframework.web.dao.dynamic.DeleteByBeanDao; import org.hswebframework.web.dao.dynamic.QueryByBeanDao; @@ -31,6 +31,6 @@ public interface CrudDao extends InsertDao, DeleteDao, DeleteByBeanDao, - UpdateByBeanDao, + UpdateByEntityDao, QueryByBeanDao { } diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/DeleteByBeanDao.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/DeleteByBeanDao.java index 01f42ecfc..d9a487435 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/DeleteByBeanDao.java +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/DeleteByBeanDao.java @@ -18,7 +18,7 @@ package org.hswebframework.web.dao.dynamic; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * TODO 完成注释 @@ -27,5 +27,5 @@ import org.hswebframework.web.commons.beans.Bean; * @since 3.0 */ public interface DeleteByBeanDao { - int delete(Bean bean); + int delete(Entity entity); } diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/QueryByBeanDao.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/QueryByBeanDao.java index 9324a60a0..14c877808 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/QueryByBeanDao.java +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/QueryByBeanDao.java @@ -18,7 +18,7 @@ package org.hswebframework.web.dao.dynamic; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; import java.util.List; @@ -29,7 +29,7 @@ import java.util.List; * @since 3.0 */ public interface QueryByBeanDao { - List query(Bean queryBean); + List query(Entity queryEntity); - int count(Bean queryBean); + int count(Entity queryEntity); } diff --git a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByBeanDao.java b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByEntityDao.java similarity index 86% rename from hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByBeanDao.java rename to hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByEntityDao.java index e02f39111..dcb29e99c 100644 --- a/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByBeanDao.java +++ b/hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByEntityDao.java @@ -18,7 +18,7 @@ package org.hswebframework.web.dao.dynamic; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * TODO 完成注释 @@ -26,6 +26,6 @@ import org.hswebframework.web.commons.beans.Bean; * @author zhouhao * @since 3.0 */ -public interface UpdateByBeanDao { - int update(Bean bean); +public interface UpdateByEntityDao { + int update(Entity entity); } diff --git a/hsweb-commons/hsweb-commons-beans/pom.xml b/hsweb-commons/hsweb-commons-entity/pom.xml similarity index 97% rename from hsweb-commons/hsweb-commons-beans/pom.xml rename to hsweb-commons/hsweb-commons-entity/pom.xml index 5409960e3..f52ba2284 100644 --- a/hsweb-commons/hsweb-commons-beans/pom.xml +++ b/hsweb-commons/hsweb-commons-entity/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - hsweb-commons-beans + hsweb-commons-entity diff --git a/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/CloneableEntity.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/CloneableEntity.java new file mode 100644 index 000000000..bcb2761b6 --- /dev/null +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/CloneableEntity.java @@ -0,0 +1,10 @@ +package org.hswebframework.web.commons.entity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface CloneableEntity extends Entity, Cloneable { + T clone(); +} diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/Bean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/Entity.java similarity index 88% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/Bean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/Entity.java index f30eea509..7d088c75a 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/Bean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/Entity.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import java.io.Serializable; @@ -25,5 +25,5 @@ import java.io.Serializable; * * @author zhouhao */ -public interface Bean extends Serializable{ +public interface Entity extends Serializable{ } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/GenericBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/GenericEntity.java similarity index 73% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/GenericBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/GenericEntity.java index 6ecb45987..94a685aa3 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/GenericBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/GenericEntity.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import java.util.LinkedHashMap; import java.util.Map; @@ -25,7 +25,7 @@ import java.util.Map; * @author zhouhao * @since 3.0 */ -public interface GenericBean extends CloneableBean { +public interface GenericEntity extends CloneableEntity { String id = "id"; String properties = "properties"; @@ -57,4 +57,17 @@ public interface GenericBean extends CloneableBean { map.put(propertyName, value); } + default Map cloneProperties() { + Map target = new LinkedHashMap<>(); + Map old = getProperties(); + if (old == null || old.isEmpty()) return target; + old.forEach((k, v) -> { + if (v instanceof CloneableEntity) { + target.put(k, ((CloneableEntity) v).clone()); + } else { + target.put(k, v); + } + }); + return target; + } } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/PagerResult.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/PagerResult.java similarity index 93% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/PagerResult.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/PagerResult.java index d114383e0..5164a8d75 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/PagerResult.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/PagerResult.java @@ -16,12 +16,12 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import java.util.List; -public class PagerResult implements Bean { +public class PagerResult implements Entity { private static final long serialVersionUID = -6171751136953308027L; private int total; diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SharedBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SharedEntity.java similarity index 81% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SharedBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SharedEntity.java index aac2c11cb..575aa15ea 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SharedBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SharedEntity.java @@ -16,23 +16,23 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; /** * TODO 完成注释 * * @author zhouhao */ -public interface SharedBean extends Bean { +public interface SharedEntity extends Entity { String creatorId = "creatorId"; String shareCode = "shareCode"; String getCreatorId(); - SharedBean setCreatorId(String creatorId); + SharedEntity setCreatorId(String creatorId); String getShareCode(); - SharedBean setShareCode(String shareCode); + SharedEntity setShareCode(String shareCode); } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleGenericBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleGenericEntity.java similarity index 90% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleGenericBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleGenericEntity.java index 000a50585..00932a13f 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleGenericBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleGenericEntity.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import java.util.LinkedHashMap; import java.util.Map; @@ -25,7 +25,7 @@ import java.util.Map; * @author zhouhao * @since 3.0 */ -public abstract class SimpleGenericBean implements GenericBean { +public abstract class SimpleGenericEntity implements GenericEntity { private PK id; @@ -70,5 +70,5 @@ public abstract class SimpleGenericBean implements GenericBean { } @Override - public abstract SimpleGenericBean clone(); + public abstract SimpleGenericEntity clone(); } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleSharedBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleSharedEntity.java similarity index 80% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleSharedBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleSharedEntity.java index c905c2c54..4e1c53f0b 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SimpleSharedBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleSharedEntity.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import org.hibernate.validator.constraints.NotBlank; @@ -26,7 +26,7 @@ import org.hibernate.validator.constraints.NotBlank; * * @author zhouhao */ -public abstract class SimpleSharedBean extends SimpleGenericBean implements SharedBean { +public abstract class SimpleSharedEntity extends SimpleGenericEntity implements SharedEntity { @NotBlank private String creatorId; @@ -39,7 +39,7 @@ public abstract class SimpleSharedBean extends SimpleGenericBean impleme } @Override - public SimpleSharedBean setCreatorId(String creatorId) { + public SimpleSharedEntity setCreatorId(String creatorId) { this.creatorId = creatorId; return this; } @@ -50,7 +50,7 @@ public abstract class SimpleSharedBean extends SimpleGenericBean impleme } @Override - public SimpleSharedBean setShareCode(String shareCode) { + public SimpleSharedEntity setShareCode(String shareCode) { this.shareCode = shareCode; return this; } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SortSupport.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SortSupport.java similarity index 88% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SortSupport.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SortSupport.java index e6f41d58a..4e4cc9dba 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/SortSupport.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SortSupport.java @@ -16,9 +16,9 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; -public interface SortSupport extends Comparable { +public interface SortSupport extends Comparable, Entity { long getSortIndex(); diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSortSupportBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSortSupportEntity.java similarity index 90% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSortSupportBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSortSupportEntity.java index 8965cb1f5..a3f5c3c7e 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSortSupportBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSortSupportEntity.java @@ -16,14 +16,14 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import org.hswebframework.web.Describe; /** * 支持树形结构,排序的实体类,要使用树形结构,排序功能的实体类直接继承该类 */ -public abstract class TreeSortSupportBean extends SimpleGenericBean implements TreeSupport, SortSupport { +public abstract class TreeSortSupportEntity extends SimpleGenericEntity implements TreeSupport, SortSupport { /** * 父级类别 @@ -70,7 +70,7 @@ public abstract class TreeSortSupportBean extends SimpleGenericBean impl } @Override - public TreeSortSupportBean setSortIndex(long sortIndex) { + public TreeSortSupportEntity setSortIndex(long sortIndex) { this.sortIndex = sortIndex; return this; } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSupport.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupport.java similarity index 96% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSupport.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupport.java index 784707fff..7ffa532f1 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/TreeSupport.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupport.java @@ -16,7 +16,7 @@ * */ -package org.hswebframework.web.commons.beans; +package org.hswebframework.web.commons.entity; import org.hswebframework.web.id.IDGenerator; @@ -25,7 +25,7 @@ import org.hswebframwork.utils.StringUtils; import java.util.List; -public interface TreeSupport { +public interface TreeSupport extends Entity { String getId(); void setId(String id); diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/BeanFactory.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/EntityFactory.java similarity index 72% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/BeanFactory.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/EntityFactory.java index 3d01c1468..7b895e446 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/BeanFactory.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/EntityFactory.java @@ -16,26 +16,26 @@ * */ -package org.hswebframework.web.commons.beans.factory; +package org.hswebframework.web.commons.entity.factory; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * 实体工厂接口,系统各个地方使用此接口来创建实体,在实际编码中也应该使用此接口来创建实体,而不是使用new方式来创建 * * @author zhouhao - * @see Bean + * @see Entity * @since 3.0 */ -public interface BeanFactory { +public interface EntityFactory { /** - * 根据类型创建实体,类型必须为{@link Bean}的子类。 + * 根据类型创建实体,类型必须为{@link Entity}的子类。 * - * @param beanClass 类型 - * @param 泛型,需实现{@link Bean} + * @param entityClass 类型 + * @param 泛型,需实现{@link Entity} * @return 实体 */ - T newInstance(Class beanClass); + T newInstance(Class entityClass); /** * 根据类型获取实体的真实的实体类型, @@ -44,9 +44,9 @@ public interface BeanFactory { * factory.getInstanceType(MyBeanInterface.class); -> class SimpleMyBeanInterface * * - * @param beanClass 类型 + * @param entityClass 类型 * @param 泛型 * @return 实体类型 */ - Class getInstanceType(Class beanClass); + Class getInstanceType(Class entityClass); } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/MapperBeanFactory.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java similarity index 54% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/MapperBeanFactory.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java index 2b40ed33f..1dc44d14d 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/factory/MapperBeanFactory.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java @@ -16,9 +16,10 @@ * */ -package org.hswebframework.web.commons.beans.factory; +package org.hswebframework.web.commons.entity.factory; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.NotFoundException; +import org.hswebframework.web.commons.entity.Entity; import java.lang.reflect.Modifier; import java.util.HashMap; @@ -31,35 +32,44 @@ import java.util.function.Supplier; * @author zhouhao * @since 3.0 */ -public class MapperBeanFactory implements BeanFactory { +public class MapperEntityFactory implements EntityFactory { private Map realTypeMapper = new HashMap<>(); - @Override - @SuppressWarnings("unchecked") - public T newInstance(Class beanClass) { - Mapper mapper = realTypeMapper.get(beanClass); - if (mapper != null) return mapper.getInstanceGetter().get(); - Class realType = null; - if (!Modifier.isInterface(beanClass.getModifiers()) && !Modifier.isAbstract(beanClass.getModifiers())) { - realType = beanClass; - } - //尝试使用 Simple类,如: package.SimpleUserBean - if (realType == null) { - String simpleClassName = beanClass.getPackage().getName().concat(".Simple").concat(beanClass.getSimpleName()); - try { - realType = (Class) Class.forName(simpleClassName); - mapper = new Mapper<>(realType, new DefaultInstanceGetter(realType)); - realTypeMapper.put(beanClass, mapper); - return mapper.getInstanceGetter().get(); - } catch (ClassNotFoundException e) { - } - } - return null; + public MapperEntityFactory addMapping(Class target, Mapper mapper) { + realTypeMapper.put(target, mapper); + return this; } @Override @SuppressWarnings("unchecked") - public Class getInstanceType(Class beanClass) { + public T newInstance(Class beanClass) { + Mapper mapper = realTypeMapper.get(beanClass); + if (mapper != null) return mapper.getInstanceGetter().get(); + synchronized (beanClass) { + mapper = realTypeMapper.get(beanClass); + if (mapper != null) return mapper.getInstanceGetter().get(); + Class realType = null; + if (!Modifier.isInterface(beanClass.getModifiers()) && !Modifier.isAbstract(beanClass.getModifiers())) { + realType = beanClass; + } + //尝试使用 Simple类,如: package.SimpleUserBean + if (realType == null) { + String simpleClassName = beanClass.getPackage().getName().concat(".Simple").concat(beanClass.getSimpleName()); + try { + realType = (Class) Class.forName(simpleClassName); + mapper = new Mapper<>(realType, new DefaultInstanceGetter(realType)); + realTypeMapper.put(beanClass, mapper); + return mapper.getInstanceGetter().get(); + } catch (ClassNotFoundException e) { + } + } + } + throw new NotFoundException("can't create instance for " + beanClass); + } + + @Override + @SuppressWarnings("unchecked") + public Class getInstanceType(Class beanClass) { Mapper mapper = realTypeMapper.get(beanClass); if (null != mapper) { return mapper.getTarget(); @@ -67,7 +77,7 @@ public class MapperBeanFactory implements BeanFactory { return null; } - public static class Mapper { + public static class Mapper { Class target; Supplier instanceGetter; @@ -85,7 +95,7 @@ public class MapperBeanFactory implements BeanFactory { } } - class DefaultInstanceGetter implements Supplier { + class DefaultInstanceGetter implements Supplier { Class type; public DefaultInstanceGetter(Class type) { diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/DeleteParamBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/DeleteParamEntity.java similarity index 52% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/DeleteParamBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/DeleteParamEntity.java index dd948a381..fb21c759f 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/DeleteParamBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/DeleteParamEntity.java @@ -1,27 +1,27 @@ -package org.hswebframework.web.commons.beans.param; +package org.hswebframework.web.commons.entity.param; import org.hsweb.ezorm.core.param.Param; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * 查询参数实体,使用easyorm进行动态查询参数构建
* 可通过静态方法创建:
- * {@link DeleteParamBean#build()}
+ * {@link DeleteParamEntity#build()}
* * @author zhouhao * @see Param - * @see Bean + * @see Entity * @since 3.0 */ -public class DeleteParamBean extends Param implements Bean { +public class DeleteParamEntity extends Param implements Entity { /** * 创建一个无条件的删除条件实体 - * 创建后需自行指定条件({@link DeleteParamBean#where(String, Object)}) + * 创建后需自行指定条件({@link DeleteParamEntity#where(String, Object)}) * 否则可能无法执行更新(dao实现应该禁止无条件的删除) * * @return */ - public static DeleteParamBean build() { - return new DeleteParamBean(); + public static DeleteParamEntity build() { + return new DeleteParamEntity(); } } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/QueryParamBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/QueryParamEntity.java similarity index 63% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/QueryParamBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/QueryParamEntity.java index 6ea6151bb..dcbb55333 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/QueryParamBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/QueryParamEntity.java @@ -1,13 +1,13 @@ -package org.hswebframework.web.commons.beans.param; +package org.hswebframework.web.commons.entity.param; import org.hsweb.ezorm.core.param.QueryParam; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * 查询参数实体,使用easyorm进行动态查询参数构建
* 可通过静态方法创建:
- * {@link QueryParamBean#empty()}
- * {@link QueryParamBean#single(String, Object)}
+ * {@link QueryParamEntity#empty()}
+ * {@link QueryParamEntity#single(String, Object)}
* 如: * * QueryParamBean.single("id",id); @@ -15,18 +15,18 @@ import org.hswebframework.web.commons.beans.Bean; * * @author zhouhao * @see QueryParam - * @see Bean + * @see Entity * @since 3.0 */ -public class QueryParamBean extends QueryParam implements Bean { +public class QueryParamEntity extends QueryParam implements Entity { /** * 创建一个空的查询参数实体,该实体无任何参数. * * @return 无条件的参数实体 */ - public static QueryParamBean empty() { - return new QueryParamBean(); + public static QueryParamEntity empty() { + return new QueryParamEntity(); } /** @@ -37,7 +37,7 @@ public class QueryParamBean extends QueryParam implements Bean { * @return 单个条件的参数实体 * @see QueryParam#where(String, Object) */ - public static QueryParamBean single(String field, Object value) { + public static QueryParamEntity single(String field, Object value) { return empty().where(field, value); } } diff --git a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/UpdateParamBean.java b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/UpdateParamEntity.java similarity index 61% rename from hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/UpdateParamBean.java rename to hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/UpdateParamEntity.java index 7b6a0e753..0f8113f07 100644 --- a/hsweb-commons/hsweb-commons-beans/src/main/java/org/hswebframework/web/commons/beans/param/UpdateParamBean.java +++ b/hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/param/UpdateParamEntity.java @@ -1,35 +1,35 @@ -package org.hswebframework.web.commons.beans.param; +package org.hswebframework.web.commons.entity.param; import org.hsweb.ezorm.core.param.UpdateParam; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * 修改参数实体,使用easyorm进行动态参数构建 * * @author zhouhao * @see UpdateParam - * @see Bean + * @see Entity * @since 3.0 */ -public class UpdateParamBean extends UpdateParam implements Bean { - public UpdateParamBean() { +public class UpdateParamEntity extends UpdateParam implements Entity { + public UpdateParamEntity() { } - public UpdateParamBean(T data) { + public UpdateParamEntity(T data) { super(data); } /** * 创建一个无任何条件并指定数据的更新参数实体 - * 创建后需自行指定条件({@link UpdateParamBean#where(String, Object)}) + * 创建后需自行指定条件({@link UpdateParamEntity#where(String, Object)}) * 否则可能无法执行更新(dao实现应该禁止无条件的更新) * * @param data 要更新的数据 * @param 数据泛型 * @return 更新参数实体 */ - public static UpdateParamBean build(T data) { - return new UpdateParamBean<>(data); + public static UpdateParamEntity build(T data) { + return new UpdateParamEntity<>(data); } /** @@ -47,7 +47,7 @@ public class UpdateParamBean extends UpdateParam implements Bean { * @param 数据泛型 * @return 更新参数实体 */ - public static UpdateParamBean build(T data, String field, Object value) { - return new UpdateParamBean<>(data).where(field, value); + public static UpdateParamEntity build(T data, String field, Object value) { + return new UpdateParamEntity<>(data).where(field, value); } } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateBeanService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateEntityService.java similarity index 89% rename from hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateBeanService.java rename to hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateEntityService.java index c8f151e70..7d249dc9c 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateBeanService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CreateEntityService.java @@ -22,17 +22,17 @@ package org.hswebframework.web.service; * 实体创建服务接口,通过此接口创建实体.在创建实体类时,建议使用此接口进行创建,而不是使用new * 如: * - * YourBean bean = service.createBean(); + * YourBean bean = service.createEntity(); * * * @author zhouhao * @since 3.0 */ -public interface CreateBeanService { +public interface CreateEntityService { /** * 创建实体 * * @return 实体 */ - B createBean(); + B createEntity(); } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CrudService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CrudService.java index 8ead0303f..221bc4a7e 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CrudService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CrudService.java @@ -18,7 +18,7 @@ package org.hswebframework.web.service; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; /** * 通用Service,实现增删改查 @@ -26,12 +26,12 @@ import org.hswebframework.web.commons.beans.Bean; * @author zhouhao * @since 3.0 */ -public interface CrudService extends - QueryByBeanService, +public interface CrudService extends + QueryByEntityService, UpdateService, InsertService, DeleteService, - CreateBeanService { + CreateEntityService { B selectByPk(PK id); } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByBeanService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByEntityService.java similarity index 82% rename from hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByBeanService.java rename to hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByEntityService.java index 31b022845..82c4a063d 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByBeanService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/QueryByEntityService.java @@ -18,12 +18,12 @@ package org.hswebframework.web.service; -import org.hswebframework.web.commons.beans.Bean; -import org.hswebframework.web.commons.beans.PagerResult; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.commons.entity.PagerResult; import java.util.List; -public interface QueryByBeanService extends Service { +public interface QueryByEntityService extends Service { PagerResult selectPager(Q param); List select(Q param); @@ -33,5 +33,4 @@ public interface QueryByBeanService extends Service { int count(Q param); B selectSingle(Q param); - } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/Validator.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/Validator.java new file mode 100644 index 000000000..0b8186979 --- /dev/null +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/Validator.java @@ -0,0 +1,14 @@ +package org.hswebframework.web.service; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface Validator { + boolean validate(T data); + + default String getErrorMessage() { + return "{validation_fail}"; + } +} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java new file mode 100644 index 000000000..588b0cce6 --- /dev/null +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/AbstractService.java @@ -0,0 +1,107 @@ +package org.hswebframework.web.service; + +import org.hswebframework.web.NotFoundException; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.commons.entity.factory.EntityFactory; +import org.hswebframework.web.validate.SimpleValidateResults; +import org.hswebframework.web.validate.ValidationException; +import org.hswebframwork.utils.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.validation.Validator; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public abstract class AbstractService implements CreateEntityService, Service { + protected Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired(required = false) + protected Validator validator; + + @Autowired(required = false) + protected EntityFactory entityFactory; + + private Class beanType; + private Class primaryKeyType; + + @SuppressWarnings("unchecked") + public AbstractService() { + primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1); + beanType = (Class) ClassUtils.getGenericType(this.getClass(), 0); + } + + protected boolean entityFactoryIsEnabled() { + if (entityFactory == null) { + logger.warn("entityFactory is null!"); + } + return null != entityFactory; + } + + protected Class getEntityRealType() { + return entityFactory.getInstanceType(getEntityType()); + } + + protected Class getEntityType() { + return beanType; + } + + protected Class getPrimaryKeyType() { + return primaryKeyType; + } + + @Override + public B createEntity() { + if (!entityFactoryIsEnabled()) { + throw new UnsupportedOperationException("{unsupported_operation}"); + } + return entityFactory.newInstance(getEntityType()); + } + + protected void tryValidateProperty(org.hswebframework.web.service.Validator validator, String property, T value) { + if (validator != null) { + if (!validator.validate(value)) { + throw new ValidationException(validator.getErrorMessage(), property); + } + } + } + + protected void tryValidateProperty(org.hswebframework.web.service.Validator validator, String property, T value, String message) { + if (validator != null) { + if (!validator.validate(value)) { + throw new ValidationException(message, property); + } + } + } + + protected void tryValidateProperty(boolean success, String property, String message) { + if (!success) { + throw new ValidationException(message, property); + } + } + + protected void tryValidate(B bean) { + if (validator == null) { + logger.warn("validator is null!"); + return; + } + SimpleValidateResults results = new SimpleValidateResults(); + validator.validate(bean).forEach(violation -> results.addResult(violation.getPropertyPath().toString(), violation.getMessage())); + if (!results.isSuccess()) + throw new ValidationException(results); + } + + public void assertNotNull(Object data) { + assertNotNull(data, "{data_not_found}"); + } + + public void assertNotNull(Object data, String message) { + if (null == data) throw new NotFoundException(message); + } + + +} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLDeleteService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLDeleteService.java index a602fdccf..c89ff3bc3 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLDeleteService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLDeleteService.java @@ -19,7 +19,7 @@ package org.hswebframework.web.service; import org.hsweb.ezorm.core.dsl.Delete; -import org.hswebframework.web.commons.beans.param.DeleteParamBean; +import org.hswebframework.web.commons.entity.param.DeleteParamEntity; import org.hswebframework.web.dao.dynamic.DeleteByBeanDao; /** @@ -28,14 +28,14 @@ import org.hswebframework.web.dao.dynamic.DeleteByBeanDao; public interface DefaultDSLDeleteService extends DefaultDeleteService { DeleteByBeanDao getDao(); - default Delete createDelete() { - Delete delete = new Delete<>(new DeleteParamBean()); + default Delete createDelete() { + Delete delete = new Delete<>(new DeleteParamEntity()); delete.setExecutor(getDao()::delete); return delete; } - static Delete createDelete(DeleteByBeanDao deleteDao) { - Delete update = new Delete<>(new DeleteParamBean()); + static Delete createDelete(DeleteByBeanDao deleteDao) { + Delete update = new Delete<>(new DeleteParamEntity()); update.setExecutor(deleteDao::delete); return update; } @@ -47,8 +47,8 @@ public interface DefaultDSLDeleteService extends DefaultDeleteService { * @return {@link Delete} * @since 3.0 */ - static Delete createDelete(Delete.Executor executor) { - Delete update = new Delete<>(new DeleteParamBean()); + static Delete createDelete(Delete.Executor executor) { + Delete update = new Delete<>(new DeleteParamEntity()); update.setExecutor(executor); return update; } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLQueryService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLQueryService.java index bcadcc1d8..f03e20e1f 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLQueryService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLQueryService.java @@ -19,13 +19,13 @@ package org.hswebframework.web.service; import org.hsweb.ezorm.core.dsl.Query; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.dao.dynamic.QueryByBeanDao; import java.util.List; public interface DefaultDSLQueryService - extends DefaultQueryByBeanService { + extends DefaultQueryByEntityService { /** * 创建本服务的dsl查询操作对象 @@ -39,8 +39,8 @@ public interface DefaultDSLQueryService * @see org.hsweb.ezorm.core.Conditional * @since 3.0 */ - default Query createQuery() { - Query query = Query.empty(new QueryParamBean()); + default Query createQuery() { + Query query = Query.empty(new QueryParamEntity()); query.setListExecutor(this::select); query.setTotalExecutor(this::count); query.setSingleExecutor(this::selectSingle); @@ -61,8 +61,8 @@ public interface DefaultDSLQueryService * @see org.hsweb.ezorm.core.Conditional * @since 3.0 */ - static Query createQuery(QueryByBeanDao dao) { - Query query = new Query<>(new QueryParamBean()); + static Query createQuery(QueryByBeanDao dao) { + Query query = new Query<>(new QueryParamEntity()); query.setListExecutor(dao::query); query.setTotalExecutor(dao::count); query.setSingleExecutor((param) -> { diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLUpdateService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLUpdateService.java index d82fd73c3..78acf72bc 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLUpdateService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultDSLUpdateService.java @@ -19,8 +19,8 @@ package org.hswebframework.web.service; import org.hsweb.ezorm.core.dsl.Update; -import org.hswebframework.web.dao.dynamic.UpdateByBeanDao; -import org.hswebframework.web.commons.beans.param.UpdateParamBean; +import org.hswebframework.web.dao.dynamic.UpdateByEntityDao; +import org.hswebframework.web.commons.entity.param.UpdateParamEntity; /** * TODO 完成注释 @@ -29,9 +29,17 @@ import org.hswebframework.web.commons.beans.param.UpdateParamBean; */ public interface DefaultDSLUpdateService extends UpdateService { - UpdateByBeanDao getDao(); + UpdateByEntityDao getDao(); - default Update> createUpdate(PO data) { - return Update.build(getDao()::update, new UpdateParamBean<>(data)); + default Update> createUpdate(PO data) { + return Update.build(getDao()::update, new UpdateParamEntity<>(data)); + } + + static Update> createUpdate(UpdateByEntityDao dao) { + return Update.build(dao::update, new UpdateParamEntity<>()); + } + + static Update> createUpdate(UpdateByEntityDao dao, PO data) { + return Update.build(dao::update, new UpdateParamEntity<>(data)); } } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByBeanService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByEntityService.java similarity index 81% rename from hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByBeanService.java rename to hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByEntityService.java index 3903c37c9..d9eb8278d 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByBeanService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/DefaultQueryByEntityService.java @@ -20,20 +20,20 @@ package org.hswebframework.web.service; import org.hsweb.ezorm.core.dsl.Query; import org.hsweb.ezorm.core.param.QueryParam; -import org.hswebframework.web.commons.beans.PagerResult; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.commons.entity.PagerResult; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.dao.dynamic.QueryByBeanDao; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; -public interface DefaultQueryByBeanService - extends QueryByBeanService { +public interface DefaultQueryByEntityService + extends QueryByEntityService { QueryByBeanDao getDao(); @Override - default PagerResult selectPager(QueryParamBean param) { + default PagerResult selectPager(QueryParamEntity param) { PagerResult pagerResult = new PagerResult<>(); param.setPaging(false); int total = getDao().count(param); @@ -49,7 +49,7 @@ public interface DefaultQueryByBeanService } /** - * 分页进行查询数据,查询条件同 {@link DefaultQueryByBeanService#select} + * 分页进行查询数据,查询条件同 {@link DefaultQueryByEntityService#select} * * @param param 查询参数 * @return 分页结果 @@ -65,7 +65,7 @@ public interface DefaultQueryByBeanService */ @Override @Transactional(readOnly = true) - default List select(QueryParamBean param) { + default List select(QueryParamEntity param) { return getDao().query(param); } @@ -77,18 +77,18 @@ public interface DefaultQueryByBeanService @Override @Transactional(readOnly = true) default List select() { - return getDao().query(new QueryParamBean()); + return getDao().query(new QueryParamEntity()); } /** - * 查询记录总数,用于分页等操作。查询条件同 {@link DefaultQueryByBeanService#select} + * 查询记录总数,用于分页等操作。查询条件同 {@link DefaultQueryByEntityService#select} * * @param param 查询参数 * @return 查询结果,实现mapper中的sql应指定默认值,否则可能抛出异常 */ @Override @Transactional(readOnly = true) - default int count(QueryParamBean param) { + default int count(QueryParamEntity param) { return getDao().count(param); } @@ -97,11 +97,11 @@ public interface DefaultQueryByBeanService * * @param param 查询条件 * @return 单个结果 - * @see this#select(QueryParamBean) + * @see this#select(QueryParamEntity) */ @Override @Transactional(readOnly = true) - default B selectSingle(QueryParamBean param) { + default B selectSingle(QueryParamEntity param) { param.doPaging(0, 1); List list = this.select(param); if (list.size() == 0) return null; diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericBeanService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericBeanService.java deleted file mode 100644 index b3b392b73..000000000 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericBeanService.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * - * * Copyright 2016 http://www.hswebframework.org - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * - */ - -package org.hswebframework.web.service; - -import org.hswebframework.web.commons.beans.GenericBean; -import org.hswebframework.web.commons.beans.factory.BeanFactory; -import org.hswebframework.web.NotFoundException; -import org.hswebframework.web.dao.CrudDao; -import org.hswebframework.web.validate.SimpleValidateResults; -import org.hswebframework.web.validate.ValidationException; -import org.hswebframwork.utils.ClassUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import javax.validation.Validator; -import java.util.List; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -@Transactional(rollbackFor = Throwable.class) -public abstract class GenericBeanService, PK> implements GenericService { - - protected Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired(required = false) - private Validator validator; - - @Autowired(required = false) - private BeanFactory beanFactory; - - private Class beanType; - private Class primaryKeyType; - - @SuppressWarnings("unchecked") - public GenericBeanService(){ - primaryKeyType = (Class) ClassUtils.getGenericType(this.getClass(), 1); - beanType = (Class) ClassUtils.getGenericType(this.getClass(), 0); - } - - @Override - public abstract CrudDao getDao(); - - private boolean beanFactoryIsEnabled() { - if (beanFactory == null) { - logger.warn("beanFactory is null!"); - } - return null != beanFactory; - } - - protected Class getBeanRealType() { - return beanFactory.getInstanceType(getBeanType()); - } - - protected Class getBeanType() { - return beanType; - } - - protected Class getPrimaryKeyType() { - return primaryKeyType; - } - - @Override - public B createBean() { - if (!beanFactoryIsEnabled()) { - throw new UnsupportedOperationException("{unsupported_operation}"); - } - return beanFactory.newInstance(getBeanType()); - } - - public void tryValidate(B bean) { - if (validator == null) { - logger.warn("validator is null!"); - return; - } - SimpleValidateResults results = new SimpleValidateResults(); - validator.validate(bean).forEach(violation -> results.addResult(violation.getPropertyPath().toString(), violation.getMessage())); - if (!results.isSuccess()) - throw new ValidationException(results); - } - - @Override - public int deleteByPk(PK pk) { - return createDelete().where(GenericBean.id, pk).exec(); - } - - @Override - public int updateByPk(B data) { - tryValidate(data); - return createUpdate(data).where(GenericBean.id, data.getId()).exec(); - } - - @Override - public int updateByPk(List data) { - return data.stream().map(this::updateByPk).reduce(Math::addExact).orElse(0); - } - - @Override - public int saveOrUpdate(B po) { - if (null != po.getId()) { - return updateByPk(po); - } else { - insert(po); - } - return 1; - } - - @Override - public PK insert(B data) { - tryValidate(data); - getDao().insert(data); - return data.getId(); - } - - @Override - public B selectByPk(PK id) { - return createQuery().where(GenericBean.id, id).single(); - } - - public void assertNotNull(Object data) { - assertNotNull(data, "{data_not_found}"); - } - - public void assertNotNull(Object data, String message) { - if (null == data) throw new NotFoundException(message); - } -} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java new file mode 100644 index 000000000..06cca880b --- /dev/null +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java @@ -0,0 +1,93 @@ +/* + * + * * Copyright 2016 http://www.hswebframework.org + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package org.hswebframework.web.service; + +import org.hswebframework.web.commons.entity.GenericEntity; +import org.hswebframework.web.commons.entity.factory.EntityFactory; +import org.hswebframework.web.NotFoundException; +import org.hswebframework.web.dao.CrudDao; +import org.hswebframework.web.validate.SimpleValidateResults; +import org.hswebframework.web.validate.ValidationException; +import org.hswebframwork.utils.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import javax.validation.Validator; +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +@Transactional(rollbackFor = Throwable.class) +public abstract class GenericEntityService, PK> + extends AbstractService + implements GenericService { + + @SuppressWarnings("unchecked") + public GenericEntityService() { + super(); + } + + @Override + public abstract CrudDao getDao(); + + @Override + public int deleteByPk(PK pk) { + return createDelete().where(GenericEntity.id, pk).exec(); + } + + @Override + public int updateByPk(B data) { + tryValidate(data); + return createUpdate(data).where(GenericEntity.id, data.getId()).exec(); + } + + @Override + public int updateByPk(List data) { + return data.stream().map(this::updateByPk).reduce(Math::addExact).orElse(0); + } + + @Override + public int saveOrUpdate(B po) { + if (null != po.getId()) { + return updateByPk(po); + } else { + insert(po); + } + return 1; + } + + @Override + public PK insert(B data) { + tryValidateProperty(null != data.getId(), GenericEntity.id, "id {not_be_null}"); + tryValidate(data); + getDao().insert(data); + return data.getId(); + } + + @Override + @Transactional(readOnly = true) + public B selectByPk(PK id) { + return createQuery().where(GenericEntity.id, id).single(); + } +} diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericService.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericService.java index 996297fb5..d4bcf9c92 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericService.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericService.java @@ -19,7 +19,7 @@ package org.hswebframework.web.service; import org.hswebframework.web.dao.CrudDao; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.springframework.transaction.annotation.Transactional; /** @@ -30,14 +30,14 @@ import org.springframework.transaction.annotation.Transactional; * @see DefaultDSLUpdateService * @see DefaultDSLDeleteService * @see CrudService - * @see QueryParamBean + * @see QueryParamEntity * @see CrudDao */ public interface GenericService extends DefaultDSLQueryService, DefaultDSLUpdateService, DefaultDSLDeleteService, - CrudService { + CrudService { @Override @Transactional CrudDao getDao(); diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/DSLQuery.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/DSLQuery.java index 6ca274d40..af8c45602 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/DSLQuery.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/DSLQuery.java @@ -1,7 +1,7 @@ package org.hswebframework.web.service.dsl; -import org.hswebframework.web.commons.beans.Bean; +import org.hswebframework.web.commons.entity.Entity; import java.util.List; @@ -10,7 +10,7 @@ import java.util.List; * * @author zhouhao */ -public interface DSLQuery extends Bean { +public interface DSLQuery extends Entity { List list(); List list(int pageIndex, int pageSize); diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleDSLQuery.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleDSLQuery.java index 79b4d0bd3..a87cd6087 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleDSLQuery.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleDSLQuery.java @@ -1,8 +1,8 @@ package org.hswebframework.web.service.dsl; import org.hsweb.ezorm.core.dsl.Query; -import org.hswebframework.web.commons.beans.param.QueryParamBean; -import org.hswebframework.web.service.DefaultQueryByBeanService; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.service.DefaultQueryByEntityService; import java.util.List; @@ -12,15 +12,15 @@ import java.util.List; * @author zhouhao */ public class SimpleDSLQuery implements DSLQuery { - protected Query query = Query.empty(new QueryParamBean()); + protected Query query = Query.empty(new QueryParamEntity()); - public SimpleDSLQuery(DefaultQueryByBeanService service) { + public SimpleDSLQuery(DefaultQueryByEntityService service) { query.setListExecutor(service::select); query.setTotalExecutor(service::count); query.setSingleExecutor(service::selectSingle); } - public Query dynamic() { + public Query dynamic() { return query; } diff --git a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleFieldCondition.java b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleFieldCondition.java index ee8e968c5..5512ae6dd 100644 --- a/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleFieldCondition.java +++ b/hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/dsl/SimpleFieldCondition.java @@ -1,7 +1,7 @@ package org.hswebframework.web.service.dsl; import org.hsweb.ezorm.core.dsl.Query; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import java.util.Collection; @@ -11,11 +11,11 @@ import java.util.Collection; * @author zhouhao */ public class SimpleFieldCondition> implements FieldCondition { - Query query; - R proxy; - String filed; + Query query; + R proxy; + String filed; - public SimpleFieldCondition(Query query, R proxy, String filed) { + public SimpleFieldCondition(Query query, R proxy, String filed) { this.query = query; this.proxy = proxy; this.filed = filed; diff --git a/hsweb-commons/hsweb-commons-service/pom.xml b/hsweb-commons/hsweb-commons-service/pom.xml index 524af748d..9c69cbc19 100644 --- a/hsweb-commons/hsweb-commons-service/pom.xml +++ b/hsweb-commons/hsweb-commons-service/pom.xml @@ -41,7 +41,7 @@
org.hswebframework.web - hsweb-commons-beans + hsweb-commons-entity ${project.version}
diff --git a/hsweb-commons/pom.xml b/hsweb-commons/pom.xml index f0b14f7b7..78233ee08 100644 --- a/hsweb-commons/pom.xml +++ b/hsweb-commons/pom.xml @@ -30,7 +30,7 @@ hsweb-commons pom - hsweb-commons-beans + hsweb-commons-entity hsweb-commons-dao hsweb-commons-service hsweb-commons-controller diff --git a/hsweb-core/src/main/java/org/hswebframework/web/validate/ValidationException.java b/hsweb-core/src/main/java/org/hswebframework/web/validate/ValidationException.java index a4cc80957..ba6278427 100644 --- a/hsweb-core/src/main/java/org/hswebframework/web/validate/ValidationException.java +++ b/hsweb-core/src/main/java/org/hswebframework/web/validate/ValidationException.java @@ -28,12 +28,17 @@ public class ValidationException extends BusinessException { super(message, 400); } + public ValidationException(String message, String field) { + super(message, 400); + results = new SimpleValidateResults().addResult(field, message); + } + public ValidationException(ValidateResults results) { super(results.toString(), 400); this.results = results; } - public Object getResults() { + public ValidateResults getResults() { return results; } } diff --git a/hsweb-message/README.md b/hsweb-message/README.md index 374ba7b92..a67da5236 100644 --- a/hsweb-message/README.md +++ b/hsweb-message/README.md @@ -1 +1 @@ -## 消息模块,整合jms,email,sms等消息首发功能 \ No newline at end of file +## 消息模块,整合jms,email,sms等消息收发功能 \ No newline at end of file diff --git a/hsweb-message/hsweb-message-api/pom.xml b/hsweb-message/hsweb-message-api/pom.xml new file mode 100644 index 000000000..e4e6bc0f0 --- /dev/null +++ b/hsweb-message/hsweb-message-api/pom.xml @@ -0,0 +1,14 @@ + + + + hsweb-message + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-message-api + + \ No newline at end of file diff --git a/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Message.java b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Message.java new file mode 100644 index 000000000..9b62edc9a --- /dev/null +++ b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/Message.java @@ -0,0 +1,11 @@ +package org.hswebframework.web.message; + +import java.io.Serializable; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface Message extends Serializable { +} diff --git a/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java new file mode 100644 index 000000000..9f391f99e --- /dev/null +++ b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageListener.java @@ -0,0 +1,10 @@ +package org.hswebframework.web.message; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface MessageListener { + void onMessage(T message); +} diff --git a/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java new file mode 100644 index 000000000..4a7c324a5 --- /dev/null +++ b/hsweb-message/hsweb-message-api/src/main/java/org/hswebframework/web/message/MessageManager.java @@ -0,0 +1,17 @@ +package org.hswebframework.web.message; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface MessageManager { + + void send(String toUser,String destination, Message message); + + void publish(String topic, Message message); + + void subscribe(String topic, MessageListener listener); + + void deSubscribe(String topic); +} diff --git a/hsweb-message/hsweb-message-jms/pom.xml b/hsweb-message/hsweb-message-jms/pom.xml new file mode 100644 index 000000000..cd74e4440 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/pom.xml @@ -0,0 +1,37 @@ + + + + hsweb-message + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-message-jms + + + + org.hswebframework.web + hsweb-message-api + ${project.version} + + + org.springframework.boot + spring-boot-starter-activemq + + + org.hswebframework.web + hsweb-tests + ${project.version} + test + + + com.h2database + h2 + test + + + + \ No newline at end of file diff --git a/hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java b/hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java new file mode 100644 index 000000000..79d0e44d5 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/main/java/org/hswebframework/web/message/jms/JmsMessageManager.java @@ -0,0 +1,35 @@ +package org.hswebframework.web.message.jms; + +import org.hswebframework.web.message.Message; +import org.hswebframework.web.message.MessageListener; +import org.hswebframework.web.message.MessageManager; +import org.springframework.jms.core.JmsTemplate; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class JmsMessageManager implements MessageManager { + JmsTemplate jmsTemplate; + + @Override + public void send(String toUser,String destination, Message message) { + + } + + @Override + public void publish(String topic, Message message) { + + } + + @Override + public void subscribe(String topic, MessageListener listener) { + + } + + @Override + public void deSubscribe(String topic) { + + } +} diff --git a/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/AmqpTests.java b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/AmqpTests.java new file mode 100644 index 000000000..cf6a1d098 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/AmqpTests.java @@ -0,0 +1,55 @@ +package org.hswebframework.web.message.jms; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jms.annotation.EnableJms; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * @author zhouhao + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SampleActiveMQApplication.class, properties = "application.yml") +@EnableJms +public class AmqpTests { + + @Autowired + private JmsTemplate template; + + @Test + public void testSend() throws InterruptedException { + new Thread(() -> { + while (true) { + try { + Object obj = template.receiveAndConvert("test4"); + System.out.println("----" + obj); + } catch (Exception e) { + break; + } + } + }).start(); + new Thread(() -> { + while (true) { + try { + Object obj = template.receiveAndConvert("test4"); + System.out.println("----222" + obj); + } catch (Exception e) { + break; + } + } + }).start(); + Thread.sleep(100); + int i = 0; + while (i < 10) { + template.convertAndSend("test4", "aaa" + i++); + Thread.sleep(1000); + } + Thread.sleep(1000); + + } + +} diff --git a/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer.java b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer.java new file mode 100644 index 000000000..50d356b06 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer.java @@ -0,0 +1,26 @@ +package org.hswebframework.web.message.jms; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.messaging.simp.annotation.SubscribeMapping; +import org.springframework.stereotype.Component; + +@Component +public class Consumer { + + @JmsListener(destination = "test") + public void receiveQueue(String text) { + System.out.println("3:" + text); + } + + @JmsListener(destination = "test") + public void receiveQueue4(String text) { + System.out.println("4:" + text); + } + + @JmsListener(destination = "test2", subscription = "test2") + public void receiveQueue3(String text) { + System.out.println("1:" + text); + } + + +} \ No newline at end of file diff --git a/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer2.java b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer2.java new file mode 100644 index 000000000..d0348cb12 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/Consumer2.java @@ -0,0 +1,15 @@ +package org.hswebframework.web.message.jms; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class Consumer2 { + + + @JmsListener(destination = "test2", subscription = "test2") + public void receiveQueue4(String text) { + System.out.println("2:" + text); + } + +} \ No newline at end of file diff --git a/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/SampleActiveMQApplication.java b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/SampleActiveMQApplication.java new file mode 100644 index 000000000..5789a1e18 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/test/java/org/hswebframework/web/message/jms/SampleActiveMQApplication.java @@ -0,0 +1,31 @@ +package org.hswebframework.web.message.jms; + +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTopic; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.jms.annotation.EnableJms; +import org.springframework.jms.listener.MessageListenerContainer; +import org.springframework.jms.listener.SimpleMessageListenerContainer; +import org.springframework.jms.listener.adapter.MessageListenerAdapter; + +import javax.jms.*; + +@SpringBootApplication +@EnableJms +public class SampleActiveMQApplication { + + +// @Bean +// public Queue queue() { +// return new ActiveMQQueue("test"); +// } +// +// @Bean +// public Topic topic() { +// ActiveMQTopic topic = new ActiveMQTopic("test2"); +// return topic; +// } + +} \ No newline at end of file diff --git a/hsweb-message/hsweb-message-jms/src/test/resources/application.yml b/hsweb-message/hsweb-message-jms/src/test/resources/application.yml new file mode 100644 index 000000000..a635bd383 --- /dev/null +++ b/hsweb-message/hsweb-message-jms/src/test/resources/application.yml @@ -0,0 +1,15 @@ +spring: + activemq: + in-memory: true + datasource: + url : jdbc:h2:mem:test_mem + username : sa + password : + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name : org.h2.Driver + jms: + pub-sub-domain: true +hsweb: + app: + name: jms测试 + version: 3.0.0 \ No newline at end of file diff --git a/hsweb-message/pom.xml b/hsweb-message/pom.xml index 25a093381..164030036 100644 --- a/hsweb-message/pom.xml +++ b/hsweb-message/pom.xml @@ -10,6 +10,11 @@ 4.0.0 hsweb-message + pom + + hsweb-message-api + hsweb-message-jms + \ No newline at end of file diff --git a/hsweb-system/README.md b/hsweb-system/README.md index a8df1289c..656977c95 100644 --- a/hsweb-system/README.md +++ b/hsweb-system/README.md @@ -4,7 +4,7 @@ 如: ```text -----hsweb-system-config - |------hsweb-system-config-bean + |------hsweb-system-config-entity |------hsweb-system-config-service |----------hsweb-system-config-service-api |----------hsweb-system-config-service-simple diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/pom.xml new file mode 100644 index 000000000..d90f67593 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/pom.xml @@ -0,0 +1,26 @@ + + + + hsweb-system-authorization-dao + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-dao-api + + + + org.hswebframework.web + hsweb-commons-dao-api + ${project.version} + + + org.hswebframework.web + hsweb-system-authorization-entity + ${project.version} + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionDao.java new file mode 100644 index 000000000..9cd5fc3ee --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionDao.java @@ -0,0 +1,13 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.dao.CrudDao; +import org.hswebframework.web.entity.authorization.ActionEntity; +import org.hswebframework.web.entity.authorization.PermissionEntity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionDao extends CrudDao,String> { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionRoleDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionRoleDao.java new file mode 100644 index 000000000..3c084b2f1 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/PermissionRoleDao.java @@ -0,0 +1,25 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.entity.authorization.PermissionRoleEntity; +import org.hswebframework.web.dao.Dao; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionRoleDao extends Dao { + int insert(PermissionRoleEntity permissionRoleBean); + + List selectByRoleId(String roleId); + + List selectByRoleIdList(List roleIds); + + List selectByPermissionId(String roleId); + + int deleteByRoleId(String roleId); + + int deleteByPermissionId(String permissionId); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/RoleDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/RoleDao.java new file mode 100644 index 000000000..ccd243b67 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/RoleDao.java @@ -0,0 +1,12 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.dao.CrudDao; +import org.hswebframework.web.entity.authorization.RoleEntity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface RoleDao extends CrudDao { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserDao.java new file mode 100644 index 000000000..c51a6ab25 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserDao.java @@ -0,0 +1,12 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.entity.authorization.UserEntity; +import org.hswebframework.web.dao.CrudDao; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UserDao extends CrudDao { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java new file mode 100644 index 000000000..b1d9e16bc --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-api/src/main/java/org/hswebframework/web/dao/authorization/UserRoleDao.java @@ -0,0 +1,23 @@ +package org.hswebframework.web.dao.authorization; + +import org.hswebframework.web.dao.Dao; +import org.hswebframework.web.entity.authorization.UserRoleEntity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UserRoleDao extends Dao { + int deleteByUserId(String userId); + + int deleteByRoleId(String roleId); + + void insert(UserRoleEntity userRoleBean); + + List selectByUserId(String userId); + + List selectByRoleId(String roleId); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/pom.xml new file mode 100644 index 000000000..eb86d03d9 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/pom.xml @@ -0,0 +1,43 @@ + + + + + + hsweb-system-authorization-dao + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-dao-mybatis + + + + org.hswebframework.web + hsweb-system-authorization-dao-api + ${project.version} + + + org.hswebframework.web + hsweb-commons-dao-mybatis + ${project.version} + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml new file mode 100644 index 000000000..aaa72aa89 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionMapper.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + delete from s_permission where u_id =#{id} + + + + + + + + + + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionRoleMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionRoleMapper.xml new file mode 100644 index 000000000..3207ed9a1 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/PermissionRoleMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + delete from s_permission_role where role_id =#{id} + + + + delete from s_permission_role where permission_id =#{id} + + + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/RoleMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/RoleMapper.xml new file mode 100644 index 000000000..da223fda8 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/RoleMapper.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + delete from s_role where u_id =#{id} + + + + + + + + + + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserMapper.xml new file mode 100644 index 000000000..620d95818 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserMapper.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + delete from s_user where u_id =#{id} + + + + + + + + + + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserRoleMapper.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserRoleMapper.xml new file mode 100644 index 000000000..77ccaed8a --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/hsweb-system-authorization-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/authorization/UserRoleMapper.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + delete from s_user_role where role_id =#{id} + + + + delete from s_user_role where user_id =#{id} + + + + + + + diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/pom.xml new file mode 100644 index 000000000..afb1620c4 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-dao/pom.xml @@ -0,0 +1,19 @@ + + + + hsweb-system-authorization + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-dao + pom + + hsweb-system-authorization-dao-api + hsweb-system-authorization-dao-mybatis + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/pom.xml similarity index 92% rename from hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/pom.xml rename to hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/pom.xml index 1a08a0a28..95c3f9a54 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/pom.xml +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/pom.xml @@ -27,12 +27,12 @@ 4.0.0 - hsweb-system-authorization-bean + hsweb-system-authorization-entity org.hswebframework.web - hsweb-commons-beans + hsweb-commons-entity ${project.version} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java new file mode 100644 index 000000000..c969fcfc2 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/ActionEntity.java @@ -0,0 +1,17 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.CloneableEntity; + +public interface ActionEntity extends CloneableEntity { + String getAction(); + + void setAction(String action); + + String getDescribe(); + + void setDescribe(String describe); + + boolean isDefaultCheck(); + + void setDefaultCheck(boolean defaultCheck); +} \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/Authorization.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/Authorization.java new file mode 100644 index 000000000..373df199c --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/Authorization.java @@ -0,0 +1,18 @@ +package org.hswebframework.web.entity.authorization; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface Authorization { + + UserReadEntity getUser(); + + List getRoles(); + + List> getPermissions(); + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionEntity.java new file mode 100644 index 000000000..51aa6bf3c --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionEntity.java @@ -0,0 +1,24 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.GenericEntity; +import org.hswebframework.web.commons.entity.SortSupport; +import org.hswebframework.web.commons.entity.TreeSupport; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionEntity extends GenericEntity, + PermissionReadEntity{ + void setName(String name); + + void setDescribe(String comment); + + void setStatus(byte status); + + void setActions(List actions); + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionReadEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionReadEntity.java new file mode 100644 index 000000000..e6d8d5465 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionReadEntity.java @@ -0,0 +1,22 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.Entity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionReadEntity extends Entity{ + String getId(); + + String getName(); + + String getDescribe(); + + byte getStatus(); + + List getActions(); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleEntity.java new file mode 100644 index 000000000..2ebc0b60e --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleEntity.java @@ -0,0 +1,20 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.CloneableEntity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionRoleEntity extends PermissionRoleReadEntity, CloneableEntity { + + void setRoleId(String roleId); + + void setPermissionId(String permissionId); + + void setActions(List actions); + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleReadEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleReadEntity.java new file mode 100644 index 000000000..3d2453980 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/PermissionRoleReadEntity.java @@ -0,0 +1,19 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.Entity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionRoleReadEntity extends Entity { + + String getRoleId(); + + String getPermissionId(); + + List getActions(); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/RoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/RoleEntity.java new file mode 100644 index 000000000..005811a9c --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/RoleEntity.java @@ -0,0 +1,23 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.GenericEntity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface RoleEntity extends GenericEntity { + + String getName(); + + void setName(String name); + + String getDescribe(); + + void setDescribe(String describe); + + void setEnabled(boolean enabled); + + boolean isEnabled(); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleActionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleActionEntity.java new file mode 100644 index 000000000..538ee8320 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleActionEntity.java @@ -0,0 +1,62 @@ +package org.hswebframework.web.entity.authorization; + + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleActionEntity implements ActionEntity { + + private String action; + + private String describe; + + private boolean defaultCheck; + + public SimpleActionEntity() { + } + + public SimpleActionEntity(String action) { + this.action = action; + } + + @Override + public String getAction() { + return action; + } + + @Override + public void setAction(String action) { + this.action = action; + } + + @Override + public String getDescribe() { + return describe; + } + + @Override + public void setDescribe(String describe) { + this.describe = describe; + } + + @Override + public boolean isDefaultCheck() { + return defaultCheck; + } + + @Override + public void setDefaultCheck(boolean defaultCheck) { + this.defaultCheck = defaultCheck; + } + + @Override + public SimpleActionEntity clone() { + SimpleActionEntity target = new SimpleActionEntity(); + target.setAction(getAction()); + target.setDescribe(getDescribe()); + target.setDefaultCheck(isDefaultCheck()); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionEntity.java new file mode 100644 index 000000000..d44caa7e3 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionEntity.java @@ -0,0 +1,70 @@ +package org.hswebframework.web.entity.authorization; + +import org.hibernate.validator.constraints.NotBlank; +import org.hswebframework.web.commons.entity.SimpleGenericEntity; + +import java.util.ArrayList; +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimplePermissionEntity extends SimpleGenericEntity implements PermissionEntity { + @NotBlank + private String name; + + private String describe; + + private byte status = 1; + + //可选事件 + private List actions; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescribe() { + return describe; + } + + public void setDescribe(String describe) { + this.describe = describe; + } + + public byte getStatus() { + return status; + } + + public void setStatus(byte status) { + this.status = status; + } + + @Override + public List getActions() { + return actions; + } + + @Override + public void setActions(List actions) { + this.actions = actions; + } + + @Override + public SimplePermissionEntity clone() { + SimplePermissionEntity target = new SimplePermissionEntity(); + target.setId(getId()); + if (actions != null) + target.setActions(new ArrayList<>(getActions())); + target.setDescribe(getDescribe()); + target.setStatus(getStatus()); + return target; + } + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionRoleEntity.java new file mode 100644 index 000000000..fad7324ab --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimplePermissionRoleEntity.java @@ -0,0 +1,57 @@ +package org.hswebframework.web.entity.authorization; + +import java.util.ArrayList; +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimplePermissionRoleEntity implements PermissionRoleEntity { + private String roleId; + + private String permissionId; + + private List actions; + + @Override + public String getRoleId() { + return roleId; + } + + @Override + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + @Override + public String getPermissionId() { + return permissionId; + } + + @Override + public void setPermissionId(String permissionId) { + this.permissionId = permissionId; + } + + @Override + public List getActions() { + return actions; + } + + @Override + public void setActions(List actions) { + this.actions = actions; + } + + @Override + public SimplePermissionRoleEntity clone() { + SimplePermissionRoleEntity target = new SimplePermissionRoleEntity(); + if (actions != null) + target.setActions(new ArrayList<>(getActions())); + target.setPermissionId(getPermissionId()); + target.setRoleId(getRoleId()); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleRoleEntity.java new file mode 100644 index 000000000..ee57ad3c5 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleRoleEntity.java @@ -0,0 +1,53 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.SimpleGenericEntity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleRoleEntity extends SimpleGenericEntity implements RoleEntity { + private String name; + + private String describe; + + private boolean enabled; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescribe() { + return describe; + } + + public void setDescribe(String describe) { + this.describe = describe; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public SimpleGenericEntity clone() { + SimpleRoleEntity target = new SimpleRoleEntity(); + target.setId(getId()); + target.setName(getName()); + target.setDescribe(getDescribe()); + target.setProperties(cloneProperties()); + target.setEnabled(isEnabled()); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserEntity.java new file mode 100644 index 000000000..9e065b6c8 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserEntity.java @@ -0,0 +1,111 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.SimpleGenericEntity; + +import java.util.Date; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleUserEntity extends SimpleGenericEntity implements UserEntity { + private String name; + + private String username; + + private String password; + + private String salt; + + private Date createDate; + + private Date lastLoginDate; + + private boolean enabled; + + private String lastLoginIp; + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String getSalt() { + return salt; + } + + public void setSalt(String salt) { + this.salt = salt; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getLastLoginDate() { + return lastLoginDate; + } + + public void setLastLoginDate(Date lastLoginDate) { + this.lastLoginDate = lastLoginDate; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getLastLoginIp() { + return lastLoginIp; + } + + public void setLastLoginIp(String lastLoginIp) { + this.lastLoginIp = lastLoginIp; + } + + @Override + public SimpleUserEntity clone() { + SimpleUserEntity target = new SimpleUserEntity(); + target.setId(getId()); + target.setName(getName()); + target.setUsername(getUsername()); + target.setPassword(getPassword()); + target.setCreateDate(getCreateDate()); + target.setEnabled(isEnabled()); + target.setLastLoginDate(getLastLoginDate()); + target.setLastLoginIp(getLastLoginIp()); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserRoleEntity.java new file mode 100644 index 000000000..30243a0f53 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/SimpleUserRoleEntity.java @@ -0,0 +1,41 @@ +package org.hswebframework.web.entity.authorization; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleUserRoleEntity implements UserRoleEntity { + + private String userId; + + private String roleId; + + @Override + public String getUserId() { + return userId; + } + + @Override + public void setUserId(String userId) { + this.userId = userId; + } + + @Override + public String getRoleId() { + return roleId; + } + + @Override + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + @Override + public SimpleUserRoleEntity clone() { + SimpleUserRoleEntity target = new SimpleUserRoleEntity(); + target.setRoleId(getRoleId()); + target.setUserId(getUserId()); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/src/main/java/org/hswebframework/web/bean/authorization/UserBean.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserEntity.java similarity index 61% rename from hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/src/main/java/org/hswebframework/web/bean/authorization/UserBean.java rename to hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserEntity.java index 0c04626a0..9b887be7a 100644 --- a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-bean/src/main/java/org/hswebframework/web/bean/authorization/UserBean.java +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserEntity.java @@ -16,9 +16,9 @@ * */ -package org.hswebframework.web.bean.authorization; +package org.hswebframework.web.entity.authorization; -import org.hswebframework.web.commons.beans.GenericBean; +import org.hswebframework.web.commons.entity.GenericEntity; import java.util.Date; @@ -27,24 +27,25 @@ import java.util.Date; * * @author zhouhao */ -public interface UserBean extends GenericBean { - String username = "username"; - String password = "password"; - String name = "name"; - String salt = "salt"; +public interface UserEntity extends UserReadEntity, GenericEntity { + void setName(String name); - String getUsername(); + void setUsername(String username); + + void setPassword(String password); + + void setSalt(String salt); String getPassword(); - String getName(); - String getSalt(); - Date createTime(); + void setCreateDate(Date createDate); - Date lastLoginTime(); + void setLastLoginDate(Date lastLoginDate); - boolean isEnabled(); + void setEnabled(boolean enabled); + + void setLastLoginIp(String lastLoginIp); } diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserReadEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserReadEntity.java new file mode 100644 index 000000000..1723ad36b --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserReadEntity.java @@ -0,0 +1,27 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.Entity; + +import java.util.Date; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UserReadEntity extends Entity { + + String getId(); + + String getName(); + + String getUsername(); + + Date getCreateDate(); + + Date getLastLoginDate(); + + boolean isEnabled(); + + String getLastLoginIp(); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserRoleEntity.java new file mode 100644 index 000000000..19edc6e0f --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/UserRoleEntity.java @@ -0,0 +1,19 @@ +package org.hswebframework.web.entity.authorization; + +import org.hswebframework.web.commons.entity.CloneableEntity; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UserRoleEntity extends CloneableEntity { + + String getUserId(); + + void setUserId(String userId); + + String getRoleId(); + + void setRoleId(String roleId); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/WebPermissionEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/WebPermissionEntity.java new file mode 100644 index 000000000..9c54f619f --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/WebPermissionEntity.java @@ -0,0 +1,17 @@ +package org.hswebframework.web.entity.authorization; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface WebPermissionEntity extends PermissionEntity { + String getUri(); + + void setUri(String uri); + + String getIcon(); + + void setIcon(String icon); + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindPermissionRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindPermissionRoleEntity.java new file mode 100644 index 000000000..8b0949de9 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindPermissionRoleEntity.java @@ -0,0 +1,17 @@ +package org.hswebframework.web.entity.authorization.bind; + +import org.hswebframework.web.entity.authorization.PermissionRoleEntity; +import org.hswebframework.web.entity.authorization.RoleEntity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface BindPermissionRoleEntity extends RoleEntity { + List getPermissions(); + + void setPermissions(List permissions); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindRoleUserEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindRoleUserEntity.java new file mode 100644 index 000000000..a73c27f04 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/BindRoleUserEntity.java @@ -0,0 +1,16 @@ +package org.hswebframework.web.entity.authorization.bind; + +import org.hswebframework.web.entity.authorization.UserEntity; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface BindRoleUserEntity extends UserEntity { + List getRoles(); + + void setRoles(List roles); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindPermissionRoleEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindPermissionRoleEntity.java new file mode 100644 index 000000000..c171707dd --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindPermissionRoleEntity.java @@ -0,0 +1,38 @@ +package org.hswebframework.web.entity.authorization.bind; + +import org.hswebframework.web.entity.authorization.SimplePermissionRoleEntity; +import org.hswebframework.web.entity.authorization.SimpleRoleEntity; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleBindPermissionRoleEntity extends SimpleRoleEntity implements BindPermissionRoleEntity { + private List permissions; + + @Override + public List getPermissions() { + return permissions; + } + + @Override + public void setPermissions(List permissions) { + this.permissions = permissions; + } + + @Override + public SimpleBindPermissionRoleEntity clone() { + SimpleBindPermissionRoleEntity target = new SimpleBindPermissionRoleEntity(); + target.setId(getId()); + target.setName(getName()); + target.setDescribe(getDescribe()); + if (permissions != null && !permissions.isEmpty()) { + target.permissions = permissions.stream().map(SimplePermissionRoleEntity::clone).collect(Collectors.toList()); + } + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindRoleUserEntity.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindRoleUserEntity.java new file mode 100644 index 000000000..debb0b5ed --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-entity/src/main/java/org/hswebframework/web/entity/authorization/bind/SimpleBindRoleUserEntity.java @@ -0,0 +1,43 @@ +package org.hswebframework.web.entity.authorization.bind; + +import org.hswebframework.web.entity.authorization.SimpleUserEntity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class SimpleBindRoleUserEntity extends SimpleUserEntity implements BindRoleUserEntity { + + private List roles; + + @Override + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + @Override + public SimpleBindRoleUserEntity clone() { + SimpleBindRoleUserEntity target = new SimpleBindRoleUserEntity(); + target.setId(getId()); + target.setName(getName()); + target.setCreateDate(getCreateDate()); + target.setEnabled(isEnabled()); + target.setLastLoginIp(getLastLoginIp()); + target.setLastLoginDate(getLastLoginDate()); + target.setSalt(getSalt()); + if (roles != null) + target.setRoles(new ArrayList<>(getRoles())); + if (getProperties() != null) + target.setProperties(new HashMap<>(getProperties())); + return target; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/pom.xml new file mode 100644 index 000000000..c12bacc99 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/pom.xml @@ -0,0 +1,26 @@ + + + + hsweb-system-authorization-service + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-service-api + + + + org.hswebframework.web + hsweb-commons-service-api + ${project.version} + + + org.hswebframework.web + hsweb-system-authorization-dao-api + ${project.version} + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PasswordStrengthValidator.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PasswordStrengthValidator.java new file mode 100644 index 000000000..0b8cb2f1d --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PasswordStrengthValidator.java @@ -0,0 +1,11 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.service.Validator; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PasswordStrengthValidator extends Validator { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PermissionService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PermissionService.java new file mode 100644 index 000000000..3630d3532 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/PermissionService.java @@ -0,0 +1,15 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.entity.authorization.ActionEntity; +import org.hswebframework.web.entity.authorization.PermissionEntity; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.service.CrudService; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface PermissionService extends CrudService, String, Q> { + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/RoleService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/RoleService.java new file mode 100644 index 000000000..19813b615 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/RoleService.java @@ -0,0 +1,28 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.entity.authorization.PermissionRoleEntity; +import org.hswebframework.web.entity.authorization.RoleEntity; +import org.hswebframework.web.entity.authorization.bind.BindPermissionRoleEntity; +import org.hswebframework.web.service.CreateEntityService; +import org.hswebframework.web.service.QueryByEntityService; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface RoleService extends + CreateEntityService, + QueryByEntityService { + String add(BindPermissionRoleEntity roleEntity); + + boolean enable(String roleId); + + boolean disable(String roleId); + + boolean update(BindPermissionRoleEntity roleEntity); + + RoleEntity selectById(String roleId); + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java new file mode 100644 index 000000000..dd2d59505 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UserService.java @@ -0,0 +1,42 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.entity.authorization.Authorization; +import org.hswebframework.web.entity.authorization.UserEntity; +import org.hswebframework.web.entity.authorization.bind.BindRoleUserEntity; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.service.CreateEntityService; +import org.hswebframework.web.service.QueryByEntityService; + +import java.util.Date; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UserService extends + CreateEntityService, + QueryByEntityService { + + String add(UserEntity userBean); + + boolean enable(String userId); + + boolean disable(String userId); + + void update(UserEntity userBean); + + UserEntity selectByUsername(String username); + + UserEntity selectById(String id); + + String encodePassword(String password, String salt); + + void updateLoginInfo(String userId, String ip, Date loginTime); + + void updatePassword(String userId, String oldPassword, String newPassword); + + Authorization initUserAuthorization(String userId); + + Authorization initAdminAuthorization(String userId); +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UsernameValidator.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UsernameValidator.java new file mode 100644 index 000000000..e16957d3a --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-api/src/main/java/org/hswebframework/web/service/authorization/UsernameValidator.java @@ -0,0 +1,11 @@ +package org.hswebframework.web.service.authorization; + +import org.hswebframework.web.service.Validator; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public interface UsernameValidator extends Validator { +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/pom.xml new file mode 100644 index 000000000..a88bd7973 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/pom.xml @@ -0,0 +1,32 @@ + + + + hsweb-system-authorization-service + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-service-simple + + + + + org.hswebframework + hsweb-expands-security + 3.0.0-SNAPSHOT + + + org.hswebframework.web + hsweb-commons-service-simple + ${project.version} + + + org.hswebframework.web + hsweb-system-authorization-service-api + ${project.version} + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorization.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorization.java new file mode 100644 index 000000000..129bd54e7 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleAuthorization.java @@ -0,0 +1,146 @@ +/* + * Copyright 2016 http://www.hswebframework.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.hswebframework.web.service.authorization.simple; + +import org.hswebframework.web.entity.authorization.*; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +class SimpleAuthorization implements Authorization { + private UserReadEntity userReadEntity; + private List permissionRoleReadEntities; + private List> permissionReadEntities; + + public SimpleAuthorization(UserEntity user, + List permissionRoleEntities, + List> permissionReadEntities) { + final String userId = user.getId(); + final String name = user.getName(); + final String userName = user.getUsername(); + final Date createDate = user.getCreateDate(); + final Date lastLoginDate = user.getLastLoginDate(); + final String lastLoginIp = user.getLastLoginIp(); + final boolean enabled = user.isEnabled(); + this.userReadEntity = new UserReadEntity() { + @Override + public String getId() { + return userId; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getUsername() { + return userName; + } + + public Date getCreateDate() { + return createDate; + } + + public Date getLastLoginDate() { + return lastLoginDate; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public String getLastLoginIp() { + return lastLoginIp; + } + }; + this.permissionRoleReadEntities = permissionRoleEntities.stream() + .map(permissionRoleEntity -> + new PermissionRoleReadEntity() { + @Override + public String getRoleId() { + return permissionRoleEntity.getRoleId(); + } + + @Override + public String getPermissionId() { + return permissionRoleEntity.getPermissionId(); + } + + @Override + public List getActions() { + return new ArrayList<>(permissionRoleEntity.getActions()); + } + } + ).collect(Collectors.toList()); + + this.permissionReadEntities = permissionReadEntities.stream() + .map(permission -> new PermissionReadEntity() { + @Override + public String getId() { + return permission.getId(); + } + + @Override + public String getName() { + return permission.getName(); + } + + @Override + public String getDescribe() { + return permission.getDescribe(); + } + + @Override + public byte getStatus() { + return permission.getStatus(); + } + + @Override + public List getActions() { + return new ArrayList<>(permission.getActions()); + } + }) + .collect(Collectors.toList()); + } + + @Override + public UserReadEntity getUser() { + return userReadEntity; + } + + @Override + public List getRoles() { + return permissionRoleReadEntities; + } + + @Override + public List> getPermissions() { + return permissionReadEntities; + } + +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimplePermissionService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimplePermissionService.java new file mode 100644 index 000000000..ab5dfc065 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimplePermissionService.java @@ -0,0 +1,27 @@ +package org.hswebframework.web.service.authorization.simple; + +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.dao.authorization.PermissionDao; +import org.hswebframework.web.entity.authorization.ActionEntity; +import org.hswebframework.web.entity.authorization.PermissionEntity; +import org.hswebframework.web.service.GenericEntityService; +import org.hswebframework.web.service.authorization.PermissionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +@Service("permissionService") +public class SimplePermissionService extends GenericEntityService, String> + implements PermissionService { + @Autowired + private PermissionDao permissionDao; + + @Override + public PermissionDao getDao() { + return permissionDao; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleRoleService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleRoleService.java new file mode 100644 index 000000000..7d363e229 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleRoleService.java @@ -0,0 +1,106 @@ +/* + * Copyright 2016 http://www.hswebframework.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.hswebframework.web.service.authorization.simple; + +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.dao.authorization.PermissionRoleDao; +import org.hswebframework.web.dao.authorization.RoleDao; +import org.hswebframework.web.entity.authorization.PermissionRoleEntity; +import org.hswebframework.web.entity.authorization.RoleEntity; +import org.hswebframework.web.entity.authorization.bind.BindPermissionRoleEntity; +import org.hswebframework.web.service.AbstractService; +import org.hswebframework.web.service.DefaultDSLQueryService; +import org.hswebframework.web.service.DefaultDSLUpdateService; +import org.hswebframework.web.service.authorization.RoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +@Transactional(rollbackFor = Throwable.class) +@Service("roleService") +public class SimpleRoleService extends AbstractService + implements RoleService, DefaultDSLQueryService { + + @Autowired + private RoleDao roleDao; + + @Autowired + private PermissionRoleDao permissionRoleDao; + + @Override + public RoleDao getDao() { + return roleDao; + } + + protected void syncPermissions(String roleId, List permissionRoleEntities) { + if (permissionRoleEntities == null) return; + permissionRoleEntities.forEach(permission -> { + permission.setRoleId(roleId); + permissionRoleDao.insert(permission); + }); + } + + @Override + public String add(BindPermissionRoleEntity roleEntity) { + tryValidateProperty(!StringUtils.hasLength(roleEntity.getId()), RoleEntity.id, "id {not_be_null}"); + tryValidateProperty(null != selectById(roleEntity.getId()), RoleEntity.id, "{role_exists}"); + tryValidate(roleEntity); + roleDao.insert(roleEntity); + syncPermissions(roleEntity.getId(), roleEntity.getPermissions()); + return roleEntity.getId(); + } + + @Override + public boolean enable(String roleId) { + return DefaultDSLUpdateService.createUpdate(getDao()).set("enabled", true).where(RoleEntity.id, roleId).exec() > 0; + } + + @Override + public boolean disable(String roleId) { + return DefaultDSLUpdateService.createUpdate(getDao()).set("enabled", false).where(RoleEntity.id, roleId).exec() > 0; + } + + @Override + public RoleEntity selectById(String roleId) { + return createQuery().where(RoleEntity.id, roleId).single(); + } + + @Override + public boolean update(BindPermissionRoleEntity roleEntity) { + tryValidateProperty(!StringUtils.hasLength(roleEntity.getId()), RoleEntity.id, "id {not_be_null}"); + tryValidateProperty(null == selectById(roleEntity.getId()), RoleEntity.id, "{role_not_exists}"); + tryValidate(roleEntity); + DefaultDSLUpdateService.createUpdate(roleDao) + .set("name", roleEntity.getName()) + .set("describe", roleEntity.getDescribe()) + .where(RoleEntity.id, roleEntity.getId()).exec(); + if (roleEntity.getProperties() != null) { + permissionRoleDao.deleteByRoleId(roleEntity.getId()); + syncPermissions(roleEntity.getId(), roleEntity.getPermissions()); + } + return true; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java new file mode 100644 index 000000000..8148a1c09 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/SimpleUserService.java @@ -0,0 +1,249 @@ +package org.hswebframework.web.service.authorization.simple; + +import org.apache.commons.codec.digest.DigestUtils; +import org.hswebframework.web.BusinessException; +import org.hswebframework.web.commons.entity.GenericEntity; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.dao.authorization.*; +import org.hswebframework.web.entity.authorization.*; +import org.hswebframework.web.entity.authorization.bind.BindRoleUserEntity; +import org.hswebframework.web.id.IDGenerator; +import org.hswebframework.web.service.AbstractService; +import org.hswebframework.web.service.DefaultDSLQueryService; +import org.hswebframework.web.service.DefaultDSLUpdateService; +import org.hswebframework.web.service.authorization.PasswordStrengthValidator; +import org.hswebframework.web.service.authorization.UserService; +import org.hswebframework.web.service.authorization.UsernameValidator; +import org.hswebframework.web.validate.ValidationException; +import org.hswebframwork.utils.ListUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +@Transactional(rollbackFor = Throwable.class) +@Service("userService") +public class SimpleUserService extends AbstractService + implements DefaultDSLQueryService, + UserService { + + @Autowired(required = false) + private PasswordStrengthValidator passwordStrengthValidator; + + @Autowired(required = false) + private UsernameValidator usernameValidator; + + @Autowired + private UserDao userDao; + + @Autowired + private UserRoleDao userRoleDao; + + @Autowired + private PermissionRoleDao permissionRoleDao; + + @Autowired + private PermissionDao permissionDao; + + @Override + public String encodePassword(String password, String salt) { + return DigestUtils.md5Hex(String.format("hsweb.%s.framework.%s", password, salt)); + } + + @Override + public void updateLoginInfo(String userId, String ip, Date loginTime) { + Assert.notNull(userId, "userId:{not_be_null}"); + Assert.notNull(ip, "ip:{not_be_null}"); + Assert.notNull(loginTime, "loginTime:{not_be_null}"); + DefaultDSLUpdateService.createUpdate(getDao()) + .set("lastLoginIp", ip) + .set("lastLoginDate", loginTime) + .where(GenericEntity.id, userId) + .exec(); + } + + @Override + @Transactional(readOnly = true) + public UserEntity selectByUsername(String username) { + Assert.notNull(username, "username:{not_be_null}"); + return createQuery().where("username", username).single(); + } + + @Override + @Transactional(readOnly = true) + public UserEntity selectById(String id) { + Assert.notNull(id, "id:{not_be_null}"); + return createQuery().where(GenericEntity.id, id).single(); + } + + @Override + public String add(UserEntity userEntity) { + //判断用户是否已经存在 + tryValidateProperty(null == selectByUsername(userEntity.getUsername()), "username", "{username_exists}"); + //用户名合法性验证 + tryValidateProperty(usernameValidator, "username", userEntity.getUsername()); + //密码强度验证 + tryValidateProperty(passwordStrengthValidator, "password", userEntity.getPassword()); + userEntity.setCreateDate(new Date()); + userEntity.setId(IDGenerator.MD5.generate()); + userEntity.setSalt(IDGenerator.RANDOM.generate()); + userEntity.setEnabled(true); + //验证其他属性 + tryValidate(userEntity); + //密码MD5 + userEntity.setPassword(encodePassword(userEntity.getPassword(), userEntity.getSalt())); + //创建用户 + userDao.insert(userEntity); + if (userEntity instanceof BindRoleUserEntity) { + BindRoleUserEntity bindRoleUserEntity = ((BindRoleUserEntity) userEntity); + //插入权限信息 + if (!ListUtils.isNullOrEmpty(bindRoleUserEntity.getRoles())) { + trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles()); + } + } + return userEntity.getId(); + } + + protected void trySyncUserRole(final String userId, final List roleIdList) { + new HashSet<>(roleIdList).stream() + .map(roleId -> { + UserRoleEntity roleEntity = entityFactory.newInstance(UserRoleEntity.class); + roleEntity.setRoleId(roleId); + roleEntity.setUserId(userId); + return roleEntity; + }) + .forEach(userRoleDao::insert); + } + + @Override + public void update(UserEntity userEntity) { + //判断用户是否存在 + boolean userExists = createQuery().where() + .is("username", userEntity.getUsername()) + .and().not(GenericEntity.id, userEntity.getId()) + .total() > 0; + tryValidateProperty(!userExists, GenericEntity.id, "{username_exists}"); + List updateProperties = Arrays.asList("name"); + //修改密码 + if (!StringUtils.hasLength(userEntity.getPassword())) { + //密码强度验证 + tryValidateProperty(usernameValidator, "password", userEntity.getPassword()); + //密码MD5 + userEntity.setPassword(encodePassword(userEntity.getPassword(), userEntity.getSalt())); + updateProperties.add("password"); + } + //修改数据 + DefaultDSLUpdateService.createUpdate(getDao(), userEntity) + .includes(updateProperties.toArray(new String[updateProperties.size()])) + .where(GenericEntity.id, userEntity.getId()) + .exec(); + if (userEntity instanceof BindRoleUserEntity) { + BindRoleUserEntity bindRoleUserEntity = ((BindRoleUserEntity) userEntity); + //删除旧的数据 + userRoleDao.deleteByUserId(bindRoleUserEntity.getId()); + //同步角色信息 + trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles()); + } + } + + @Override + public boolean enable(String userId) { + return DefaultDSLUpdateService.createUpdate(getDao()) + .set("enabled", true) + .where(GenericEntity.id, userId) + .exec() > 0; + } + + @Override + public boolean disable(String userId) { + return DefaultDSLUpdateService.createUpdate(getDao()) + .set("enabled", false) + .where(GenericEntity.id, userId) + .exec() > 0; + } + + @Override + public void updatePassword(String userId, String oldPassword, String newPassword) { + UserEntity userEntity = selectById(userId); + assertNotNull(userEntity); + oldPassword = encodePassword(oldPassword, userEntity.getSalt()); + if (!userEntity.getPassword().equals(oldPassword)) { + throw new ValidationException("{old_password_error}", "password"); + } + newPassword = encodePassword(newPassword, userEntity.getSalt()); + DefaultDSLUpdateService.createUpdate(getDao()) + .set("password", newPassword) + .where(GenericEntity.id, userId) + .exec(); + } + + @Override + public Authorization initUserAuthorization(String userId) { + UserEntity userEntity = selectById(userId); + assertNotNull(userEntity); + //用户持有的角色 + List roleEntities = userRoleDao.selectByUserId(userId); + if (ListUtils.isNullOrEmpty(roleEntities)) { + return new SimpleAuthorization(userEntity, new ArrayList<>(), new ArrayList<>()); + } + List roleIdList = roleEntities.stream().map(UserRoleEntity::getRoleId).collect(Collectors.toList()); + //权限角色关联信息 + List permissionRoleEntities = permissionRoleDao.selectByRoleIdList(roleIdList); + List permissionIdList = permissionRoleEntities.stream().map(PermissionRoleEntity::getPermissionId).collect(Collectors.toList()); + //权限信息 + List> permissionEntities = DefaultDSLQueryService + .createQuery(permissionDao).where().in(GenericEntity.id, permissionIdList).noPaging().list(); + return new SimpleAuthorization(userEntity, permissionRoleEntities, permissionEntities); + } + + @Override + public Authorization initAdminAuthorization(String userId) { + UserEntity userEntity = selectById(userId); + assertNotNull(userEntity); + //获取所有角色信息 +// List roleEntities = DefaultDSLQueryService +// .createQuery(roleDao) +// .noPaging().list() +// .stream().map(role -> { +// UserRoleEntity roleEntity = entityFactoryIsEnabled() +// ? entityFactory.newInstance(UserRoleEntity.class) +// : new SimpleUserRoleEntity(); +// roleEntity.setRoleId(role.getId()); +// roleEntity.setUserId(userId); +// return roleEntity; +// }).collect(Collectors.toList()); + + //所有权限信息 + List> permissionEntities = DefaultDSLQueryService + .createQuery(permissionDao).noPaging().list(); + List permissionRoleEntities = permissionEntities + .stream().map(permission -> { + PermissionRoleEntity entity = entityFactoryIsEnabled() + ? entityFactory.newInstance(PermissionRoleEntity.class) + : new SimplePermissionRoleEntity(); + entity.setRoleId("admin"); //always admin + entity.setPermissionId(permission.getId()); + entity.setActions(permission.getActions() + .stream() + .map(ActionEntity::getAction) + .collect(Collectors.toList())); + return entity; + }).collect(Collectors.toList()); + + return new SimpleAuthorization(userEntity, permissionRoleEntities, permissionEntities); + } + + @Override + public UserDao getDao() { + return userDao; + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/pom.xml new file mode 100644 index 000000000..379243e3b --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/pom.xml @@ -0,0 +1,18 @@ + + + + hsweb-system-authorization + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-service + pom + + hsweb-system-authorization-service-api + hsweb-system-authorization-service-simple + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml new file mode 100644 index 000000000..ef30a083a --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/pom.xml @@ -0,0 +1,78 @@ + + + + + + hsweb-system-authorization + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-authorization-starter + + + + + + src/main/resources + true + + + + + + + org.hswebframework.web + hsweb-system-authorization-service-simple + ${project.version} + + + org.hswebframework.web + hsweb-system-authorization-dao-mybatis + ${project.version} + + + + com.h2database + h2 + test + + + com.alibaba + druid + 1.0.26 + test + + + + org.hswebframework.web + hsweb-spring-boot-starter + ${project.version} + test + + + org.hswebframework.web + hsweb-tests + ${project.version} + test + + + \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js new file mode 100644 index 000000000..b64193175 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/main/resources/hsweb-starter.js @@ -0,0 +1,92 @@ +/* + * Copyright 2016 http://www.hswebframework.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +//组件信息 +var info = { + groupId: "${project.groupId}", + artifactId: "${project.artifactId}", + version: "${project.version}", + website: "http://github.com/hs-web/hsweb-framework", + author: "zh.sqy@qq.com", + comment: "权限管理" +}; + +//版本更新信息 +var versions = [ + // { + // version: "3.0.0", + // upgrade: function (context) { + // java.lang.System.out.println("更新到3.0.2了"); + // } + // } +]; +var JDBCType = java.sql.JDBCType; +function install(context) { + var database = context.database; + database.createOrAlter("s_user") + .addColumn().name("u_id").varchar(32).notNull().primaryKey().comment("uid").commit() + .addColumn().name("name").varchar(128).notNull().comment("姓名").commit() + .addColumn().name("username").varchar(128).notNull().comment("用户名").commit() + .addColumn().name("password").varchar(128).notNull().comment("密码").commit() + .addColumn().name("salt").varchar(128).notNull().comment("密码盐").commit() + .addColumn().name("enabled").number(1).notNull().comment("是否启用").commit() + .addColumn().name("create_date").datetime().notNull().comment("创建时间").commit() + .addColumn().name("last_login_ip").varchar(128).comment("上一次登录的ip地址").commit() + .addColumn().name("last_login_date").datetime().comment("上一次登录时间").commit() + .comment("用户表").commit(); + + database.createOrAlter("s_role") + .addColumn().name("u_id").varchar(32).notNull().primaryKey().comment("uid").commit() + .addColumn().name("name").varchar(128).notNull().comment("角色名称").commit() + .addColumn().name("describe").varchar(128).comment("说明").commit() + .addColumn().name("enabled").number(1).notNull().comment("是否启用").commit() + .comment("角色表").commit(); + + database.createOrAlter("s_permission") + .addColumn().name("u_id").varchar(32).notNull().primaryKey().comment("uid").commit() + .addColumn().name("name").varchar(128).notNull().comment("角色名称").commit() + .addColumn().name("describe").varchar(128).comment("说明").commit() + .addColumn().name("status").number(4).notNull().comment("状态").commit() + .addColumn().name("actions").clob().notNull().comment("可选操作(按钮)").commit() + .comment("权限表").commit(); + + database.createOrAlter("s_permission_role") + .addColumn().name("role_id").varchar(32).notNull().comment("角色ID").commit() + .addColumn().name("permission_id").varchar(32).notNull().comment("权限ID").commit() + .addColumn().name("actions").clob().notNull().comment("可选操作").commit() + .comment("权限与角色关联表").commit(); + + database.createOrAlter("s_user_role") + .addColumn().name("role_id").varchar(32).notNull().comment("角色ID").commit() + .addColumn().name("user_id").varchar(32).notNull().comment("用户ID").commit() + .addColumn().name("actions").clob().notNull().comment("可选操作").commit() + .comment("用户与角色关联表").commit(); + +} + +//设置依赖 +dependency.setup(info) + .onInstall(install) + .onUpgrade(function (context) { //更新时执行 + var upgrader = context.upgrader; + upgrader.filter(versions) + .upgrade(function (newVer) { + newVer.upgrade(context); + }); + }) + .onUninstall(function (context) { //卸载时执行 + + }); \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/PermissionTests.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/PermissionTests.java new file mode 100644 index 000000000..ecf01df5d --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/PermissionTests.java @@ -0,0 +1,78 @@ +/* + * Copyright 2016 http://www.hswebframework.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.hswebframework.web.starter.authorization; + +import org.hsweb.ezorm.rdb.executor.SqlExecutor; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.entity.authorization.ActionEntity; +import org.hswebframework.web.entity.authorization.PermissionEntity; +import org.hswebframework.web.entity.authorization.SimpleActionEntity; +import org.hswebframework.web.service.authorization.PermissionService; +import org.hswebframework.web.tests.SimpleWebApplicationTests; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.sql.SQLException; +import java.util.Arrays; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class PermissionTests extends SimpleWebApplicationTests { + + @Autowired + private PermissionService permissionService; + + @Autowired + private SqlExecutor sqlExecutor; + + @After + public void clear() throws SQLException { + sqlExecutor.delete("delete from s_permission"); + } + + @Test + public void testCRUD() throws Exception { + Assert.assertTrue(sqlExecutor.tableExists("s_permission")); + + PermissionEntity entity = permissionService.createEntity(); + entity.setStatus((byte) 1); + entity.setName("测试"); + entity.setActions(Arrays.asList(new SimpleActionEntity("C"))); + entity.setId("test"); + String id = permissionService.insert(entity); + Assert.assertNotNull(id); + + PermissionEntity data = permissionService.selectByPk("test"); + Assert.assertEquals(data.getId(), entity.getId()); + Assert.assertEquals(data.getName(), entity.getName()); + Assert.assertEquals(data.getStatus(), entity.getStatus()); + + data.setName("测试修改"); + permissionService.updateByPk(data); + PermissionEntity data2 = permissionService.selectByPk("test"); + Assert.assertEquals(data2.getName(), data.getName()); + + permissionService.deleteByPk("test"); + Assert.assertTrue(permissionService.selectByPk("test") == null); + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/UserTests.java b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/UserTests.java new file mode 100644 index 000000000..4d23c4985 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/java/org/hswebframework/web/starter/authorization/UserTests.java @@ -0,0 +1,165 @@ +/* + * Copyright 2016 http://www.hswebframework.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.hswebframework.web.starter.authorization; + +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.entity.authorization.Authorization; +import org.hswebframework.web.entity.authorization.UserEntity; +import org.hswebframework.web.service.authorization.PasswordStrengthValidator; +import org.hswebframework.web.service.authorization.UserService; +import org.hswebframework.web.service.authorization.UsernameValidator; +import org.hswebframework.web.tests.SimpleWebApplicationTests; +import org.hswebframework.web.validate.ValidationException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.sql.SQLException; +import java.util.Date; + +/** + * TODO 完成注释 + * + * @author zhouhao + */ +public class UserTests extends SimpleWebApplicationTests { + + @Configuration + public static class Config { + @Bean + public PasswordStrengthValidator passwordStrengthValidator() { + return new PasswordStrengthValidator() { + @Override + public boolean validate(String data) { + return data.length() >= 4; + } + + @Override + public String getErrorMessage() { + return "密码强度太弱"; + } + }; + } + + @Bean + public UsernameValidator usernameValidator() { + return (username) -> username.length() >= 4; + } + } + + @Autowired + private UserService userService; + + @After + public void clear() throws SQLException { + sqlExecutor.delete("delete from s_user"); + } + + public UserEntity createTestUser() { + UserEntity userEntity = userService.createEntity(); + userEntity.setName("测试"); + userEntity.setUsername("test"); + userEntity.setPassword("password_1234"); + userService.add(userEntity); + return userEntity; + } + + @Test + public void testInitAuth() { + UserEntity entity = createTestUser(); + Authorization authorization = userService.initAdminAuthorization(entity.getId()); + Assert.assertNotNull(authorization); + Assert.assertEquals(authorization.getUser().getUsername(), entity.getUsername()); + authorization = userService.initUserAuthorization(entity.getId()); + Assert.assertNotNull(authorization); + Assert.assertEquals(authorization.getUser().getUsername(), entity.getUsername()); + } + + @Test + public void testCRUD() { + UserEntity userEntity = userService.createEntity(); + userEntity.setName("测试"); + userEntity.setUsername("test"); + userEntity.setPassword("123"); + try { + userService.add(userEntity); + Assert.assertTrue(false); + } catch (ValidationException e) { + Assert.assertEquals(e.getResults().getResults().get(0).getMessage(), "密码强度太弱"); + } + userEntity.setPassword("password_1234"); + String id = userService.add(userEntity); + + UserEntity newUserEntity = userEntity.clone(); + newUserEntity.setUsername("test2"); + String antherId = userService.add(newUserEntity); + + Assert.assertNotNull(id); + Assert.assertEquals(userEntity.getPassword().length(), 32); + + UserEntity entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertEquals(entityInDb.isEnabled(), true); + Assert.assertNotNull(entityInDb.getCreateDate()); + Assert.assertTrue(entityInDb.getLastLoginDate() == null); + Assert.assertTrue(entityInDb.getLastLoginIp() == null); + + Assert.assertEquals(entityInDb.getPassword(), userService.encodePassword("password_1234", entityInDb.getSalt())); + + userService.updateLoginInfo(id, "127.0.0.1", new Date()); + entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertEquals(entityInDb.isEnabled(), true); + Assert.assertNotNull(entityInDb.getCreateDate()); + Assert.assertNotNull(entityInDb.getLastLoginDate()); + Assert.assertNotNull(entityInDb.getLastLoginIp()); + try { + userService.updatePassword(id, "test", "test"); + Assert.assertTrue(false); + } catch (ValidationException e) { + Assert.assertEquals(e.getResults().getResults().get(0).getMessage(), "{old_password_error}"); + } + userService.updatePassword(id, "password_1234", "password_2345"); + entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertEquals(entityInDb.getPassword(), userService.encodePassword("password_2345", entityInDb.getSalt())); + + entityInDb.setId(antherId); + entityInDb.setName("新名字"); + try { + userService.update(entityInDb); + Assert.assertTrue(false); + } catch (ValidationException e) { + Assert.assertEquals(e.getResults().getResults().get(0).getMessage(), "{username_exists}"); + } + entityInDb.setId(id); + userService.update(entityInDb); + entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertEquals("新名字", entityInDb.getName()); + + + userService.disable(id); + entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertFalse(entityInDb.isEnabled()); + + userService.enable(id); + entityInDb = userService.selectByUsername(userEntity.getUsername()); + Assert.assertTrue(entityInDb.isEnabled()); + + } +} diff --git a/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/resources/application.yml b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/resources/application.yml new file mode 100644 index 000000000..51b167135 --- /dev/null +++ b/hsweb-system/hsweb-system-authorization/hsweb-system-authorization-starter/src/test/resources/application.yml @@ -0,0 +1,13 @@ +spring: + aop: + auto: true + datasource: + url : jdbc:h2:mem:permission_test_mem + username : sa + password : + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name : org.h2.Driver +hsweb: + app: + name: 权限管理测试 + version: 3.0.0 \ No newline at end of file diff --git a/hsweb-system/hsweb-system-authorization/pom.xml b/hsweb-system/hsweb-system-authorization/pom.xml index d2c4210ad..c18ac51b3 100644 --- a/hsweb-system/hsweb-system-authorization/pom.xml +++ b/hsweb-system/hsweb-system-authorization/pom.xml @@ -12,7 +12,10 @@ hsweb-system-authorization pom - hsweb-system-authorization-bean + hsweb-system-authorization-entity + hsweb-system-authorization-dao + hsweb-system-authorization-service + hsweb-system-authorization-starter diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigQueryBean.java b/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigQueryBean.java deleted file mode 100644 index 32863c202..000000000 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigQueryBean.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.hswebframework.web.bean.config; - -import org.hsweb.ezorm.core.dsl.ConditionalBuilder; -import org.hswebframework.web.commons.beans.Bean; - -/** - * TODO 完成注释 - * - * @author zhouhao - */ -public interface ConfigQueryBean extends Bean { - ConditionalBuilder name = ConditionalBuilder.build("name"); - - -} diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-controller/src/main/java/org/hswebframework/web/controller/config/ConfigController.java b/hsweb-system/hsweb-system-config/hsweb-system-config-controller/src/main/java/org/hswebframework/web/controller/config/ConfigController.java index 892b6b3d3..4f5ad202d 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-controller/src/main/java/org/hswebframework/web/controller/config/ConfigController.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-controller/src/main/java/org/hswebframework/web/controller/config/ConfigController.java @@ -19,10 +19,9 @@ package org.hswebframework.web.controller.config; import org.hswebframework.web.authorization.Authorize; -import org.hswebframework.web.bean.config.ConfigBean; -import org.hswebframework.web.bean.config.SimpleConfigBean; -import org.hswebframework.web.commons.beans.param.QueryParamBean; -import org.hswebframework.web.controller.GenericBeanController; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; +import org.hswebframework.web.controller.GenericEntityController; +import org.hswebframework.web.entity.config.SimpleConfigEntity; import org.hswebframework.web.logging.AccessLogger; import org.hswebframework.web.service.config.ConfigService; import org.springframework.beans.factory.annotation.Autowired; @@ -38,14 +37,14 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("${hsweb.web.mappings.config:config}") @Authorize(module = "config") @AccessLogger("配置管理") -public class ConfigController implements GenericBeanController { +public class ConfigController implements GenericEntityController { @Autowired - private ConfigService configService; + private ConfigService configService; @Override + @SuppressWarnings("unchecked") public ConfigService getService() { return configService; } - } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/pom.xml index 4b7a03cdc..467f764b1 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/pom.xml @@ -32,7 +32,7 @@ org.hswebframework.web - hsweb-system-config-bean + hsweb-system-config-entity ${project.version} diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/src/main/java/org/hswebframework/web/dao/config/ConfigDao.java b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/src/main/java/org/hswebframework/web/dao/config/ConfigDao.java index aa23deaa0..928682009 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/src/main/java/org/hswebframework/web/dao/config/ConfigDao.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-api/src/main/java/org/hswebframework/web/dao/config/ConfigDao.java @@ -18,7 +18,7 @@ package org.hswebframework.web.dao.config; -import org.hswebframework.web.bean.config.ConfigBean; +import org.hswebframework.web.entity.config.ConfigEntity; import org.hswebframework.web.dao.CrudDao; /** @@ -26,5 +26,5 @@ import org.hswebframework.web.dao.CrudDao; * * @author zhouhao */ -public interface ConfigDao extends CrudDao { +public interface ConfigDao extends CrudDao { } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/pom.xml index 5e16f8d4b..32a4b6209 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/pom.xml @@ -30,6 +30,11 @@ hsweb-system-config-dao-mybatis + + org.hswebframework.web + hsweb-system-config-entity + ${project.version} + org.hswebframework.web hsweb-commons-dao-mybatis diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/config/ConfigMapper.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/config/ConfigMapper.xml index 622e11b8e..b7017b05d 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/config/ConfigMapper.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-dao/hsweb-system-config-dao-mybatis/src/main/resources/org/hswebframework/web/dao/mybatis/mappers/config/ConfigMapper.xml @@ -4,7 +4,7 @@ "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -20,7 +20,7 @@ - + @@ -29,22 +29,22 @@ delete from s_config where u_id =#{id} - + - + - - diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/pom.xml similarity index 92% rename from hsweb-system/hsweb-system-config/hsweb-system-config-bean/pom.xml rename to hsweb-system/hsweb-system-config/hsweb-system-config-entity/pom.xml index 6038bd4aa..cfcd5223a 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - hsweb-system-config-bean + hsweb-system-config-entity @@ -36,7 +36,7 @@ org.hswebframework.web - hsweb-commons-beans + hsweb-commons-entity ${project.version} diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigContent.java b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigContent.java similarity index 83% rename from hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigContent.java rename to hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigContent.java index e0e634fed..2b34fa258 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigContent.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigContent.java @@ -1,10 +1,10 @@ -package org.hswebframework.web.bean.config; +package org.hswebframework.web.entity.config; -import org.hswebframework.web.commons.beans.CloneableBean; +import org.hswebframework.web.commons.entity.CloneableEntity; import java.math.BigDecimal; -public class ConfigContent implements CloneableBean { +public class ConfigContent implements CloneableEntity { private String key; private Object value; @@ -62,8 +62,8 @@ public class ConfigContent implements CloneableBean { @Override public ConfigContent clone() { Object val = value; - if (val instanceof CloneableBean) - val = ((CloneableBean) val).clone(); + if (val instanceof CloneableEntity) + val = ((CloneableEntity) val).clone(); return new ConfigContent(key, val, comment); } } \ No newline at end of file diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigBean.java b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigEntity.java similarity index 89% rename from hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigBean.java rename to hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigEntity.java index 09e407172..cf7467b40 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/ConfigBean.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/ConfigEntity.java @@ -16,10 +16,10 @@ * */ -package org.hswebframework.web.bean.config; +package org.hswebframework.web.entity.config; -import org.hswebframework.web.commons.beans.GenericBean; +import org.hswebframework.web.commons.entity.GenericEntity; import java.util.Date; import java.util.List; @@ -29,7 +29,7 @@ import java.util.List; * * @author zhouhao */ -public interface ConfigBean extends GenericBean { +public interface ConfigEntity extends GenericEntity { String getCreatorId(); @@ -105,7 +105,7 @@ public interface ConfigBean extends GenericBean { */ void setClassifiedId(String classifiedId); - ConfigBean addContent(String key, Object value, String comment); + ConfigEntity addContent(String key, Object value, String comment); ConfigContent get(String key); } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/SimpleConfigBean.java b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/SimpleConfigEntity.java similarity index 86% rename from hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/SimpleConfigBean.java rename to hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/SimpleConfigEntity.java index 9e4e3e309..37a89801d 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-bean/src/main/java/org/hswebframework/web/bean/config/SimpleConfigBean.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-entity/src/main/java/org/hswebframework/web/entity/config/SimpleConfigEntity.java @@ -16,11 +16,10 @@ * */ -package org.hswebframework.web.bean.config; +package org.hswebframework.web.entity.config; -import org.hswebframework.web.commons.beans.CloneableBean; -import org.hswebframework.web.commons.beans.SimpleGenericBean; +import org.hswebframework.web.commons.entity.SimpleGenericEntity; import javax.validation.constraints.NotNull; import java.util.*; @@ -31,7 +30,7 @@ import java.util.stream.Collectors; * * @author zhouhao */ -public class SimpleConfigBean extends SimpleGenericBean implements ConfigBean { +public class SimpleConfigEntity extends SimpleGenericEntity implements ConfigEntity { //备注 private String remark; @@ -80,9 +79,9 @@ public class SimpleConfigBean extends SimpleGenericBean implements Confi } @Override - public ConfigBean addContent(String key, Object value, String comment) { + public ConfigEntity addContent(String key, Object value, String comment) { if (content == null) content = new ArrayList<>(); - content.add(new org.hswebframework.web.bean.config.ConfigContent(key, value, comment)); + content.add(new ConfigContent(key, value, comment)); return this; } @@ -138,8 +137,8 @@ public class SimpleConfigBean extends SimpleGenericBean implements Confi } @Override - public SimpleConfigBean clone() { - SimpleConfigBean cloned = new SimpleConfigBean(); + public SimpleConfigEntity clone() { + SimpleConfigEntity cloned = new SimpleConfigEntity(); cloned.setId(getId()); cloned.setCreatorId(getCreatorId()); cloned.setCreateDate(getCreateDate()); diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/pom.xml b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/pom.xml index ae5fa2df6..a541ab347 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/pom.xml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/pom.xml @@ -32,7 +32,7 @@ org.hswebframework.web - hsweb-system-config-bean + hsweb-system-config-entity ${project.version} diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/src/main/java/org.hswebframework.web.service.config/ConfigService.java b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/src/main/java/org.hswebframework.web.service.config/ConfigService.java index eb566d026..db1e983ae 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/src/main/java/org.hswebframework.web.service.config/ConfigService.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-api/src/main/java/org.hswebframework.web.service.config/ConfigService.java @@ -18,8 +18,8 @@ package org.hswebframework.web.service.config; -import org.hswebframework.web.commons.beans.Bean; -import org.hswebframework.web.bean.config.ConfigBean; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.entity.config.ConfigEntity; import org.hswebframework.web.service.CrudService; /** @@ -27,6 +27,6 @@ import org.hswebframework.web.service.CrudService; * * @author zhouhao */ -public interface ConfigService extends CrudService { +public interface ConfigService extends CrudService { } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/main/java/org/hswebframework/web/service/config/simple/SimpleConfigService.java b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/main/java/org/hswebframework/web/service/config/simple/SimpleConfigService.java index fd283e345..6d14e11a1 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/main/java/org/hswebframework/web/service/config/simple/SimpleConfigService.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/main/java/org/hswebframework/web/service/config/simple/SimpleConfigService.java @@ -18,10 +18,10 @@ package org.hswebframework.web.service.config.simple; -import org.hswebframework.web.bean.config.ConfigBean; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.entity.config.ConfigEntity; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.dao.config.ConfigDao; -import org.hswebframework.web.service.GenericBeanService; +import org.hswebframework.web.service.GenericEntityService; import org.hswebframework.web.service.config.ConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -32,8 +32,8 @@ import org.springframework.stereotype.Service; * @author zhouhao */ @Service("configService") -public class SimpleConfigService extends GenericBeanService - implements ConfigService { +public class SimpleConfigService extends GenericEntityService + implements ConfigService { @Autowired private ConfigDao configDao; diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/test/java/org/hswebframework/web/service/config/ConfigServiceTests.java b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/test/java/org/hswebframework/web/service/config/ConfigServiceTests.java index 153a8968a..ee8c2475f 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/test/java/org/hswebframework/web/service/config/ConfigServiceTests.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-service/hsweb-system-config-service-simple/src/test/java/org/hswebframework/web/service/config/ConfigServiceTests.java @@ -10,6 +10,6 @@ import org.hswebframework.web.service.config.simple.SimpleConfigService; public class ConfigServiceTests { public static void main(String[] args) { SimpleConfigService configService =new SimpleConfigService(); - System.out.println(new SimpleConfigService().createBean()); +// System.out.println(new SimpleConfigService().createEntity()); } } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/java/org/hswebframework/web/starter/config/ConfigTests.java b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/java/org/hswebframework/web/starter/config/ConfigTests.java index 2c974a8d8..6fd7b1164 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/java/org/hswebframework/web/starter/config/ConfigTests.java +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/java/org/hswebframework/web/starter/config/ConfigTests.java @@ -3,9 +3,9 @@ package org.hswebframework.web.starter.config; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.hsweb.ezorm.rdb.executor.SqlExecutor; -import org.hswebframework.web.bean.config.ConfigBean; -import org.hswebframework.web.bean.config.SimpleConfigBean; -import org.hswebframework.web.commons.beans.param.QueryParamBean; +import org.hswebframework.web.entity.config.ConfigEntity; +import org.hswebframework.web.entity.config.SimpleConfigEntity; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.id.IDGenerator; import org.hswebframework.web.service.config.ConfigService; import org.hswebframework.web.tests.SimpleWebApplicationTests; @@ -29,7 +29,7 @@ public class ConfigTests extends SimpleWebApplicationTests { private SqlExecutor executor; @Autowired - private ConfigService configService; + private ConfigService configService; @After public void clear() throws SQLException { @@ -39,8 +39,8 @@ public class ConfigTests extends SimpleWebApplicationTests { @Test public void testMvc() throws Exception { //创建bean - ConfigBean configBean = configService.createBean(); - Assert.assertEquals(configBean.getClass(), SimpleConfigBean.class); + ConfigEntity configBean = configService.createEntity(); + Assert.assertEquals(configBean.getClass(), SimpleConfigEntity.class); configBean.setId(IDGenerator.RANDOM.generate()); configBean.addContent("test", 1, "测试"); configBean.setCreateDate(new Date()); @@ -52,17 +52,18 @@ public class ConfigTests extends SimpleWebApplicationTests { .contentType(MediaType.APPLICATION_JSON) .content(jsonStr)) .exec().resultAsJson(); + //{data:id,code:200} Assert.assertEquals(jsonObject.getString("data"), configBean.getId()); JSONObject getRes = testGet("/config/" + configBean.getId()).exec().resultAsJson(); Assert.assertEquals(getRes - .getObject("data", SimpleConfigBean.class) + .getObject("data", SimpleConfigEntity.class) .get("test") .getNumber(0).intValue(), 1); getRes = testGet("/config").exec().resultAsJson(); Assert.assertEquals(getRes.getJSONObject("data").getJSONArray("data") - .getObject(0, SimpleConfigBean.class) + .getObject(0, SimpleConfigEntity.class) .get("test") .getNumber(0).intValue(), 1); } @@ -73,8 +74,8 @@ public class ConfigTests extends SimpleWebApplicationTests { boolean installSuccess = executor.tableExists("s_config"); Assert.assertTrue(installSuccess); //创建bean - ConfigBean configBean = configService.createBean(); - Assert.assertEquals(configBean.getClass(), SimpleConfigBean.class); + ConfigEntity configBean = configService.createEntity(); + Assert.assertEquals(configBean.getClass(), SimpleConfigEntity.class); configBean.setId(IDGenerator.RANDOM.generate()); configBean.addContent("test", 1, "测试"); configBean.setCreateDate(new Date()); @@ -82,15 +83,15 @@ public class ConfigTests extends SimpleWebApplicationTests { //test insert configService.insert(configBean); Assert.assertEquals(configBean.get("test").getNumber(0), 1); - configBean = configService.selectSingle(QueryParamBean.empty()); + configBean = configService.selectSingle(QueryParamEntity.empty()); configBean.addContent("test2", "2", ""); //test update Assert.assertEquals(configService.updateByPk(configBean), 1); Assert.assertEquals(configBean.get("test2").getNumber(0).intValue(), 2); - configBean = configService.selectSingle(QueryParamBean.empty()); + configBean = configService.selectSingle(QueryParamEntity.empty()); //test delete configService.deleteByPk(configBean.getId()); - Assert.assertEquals(configService.count(QueryParamBean.empty()), 0); + Assert.assertEquals(configService.count(QueryParamEntity.empty()), 0); } } diff --git a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/resources/application.yml b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/resources/application.yml index b4db0c5c0..051171eb9 100644 --- a/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/resources/application.yml +++ b/hsweb-system/hsweb-system-config/hsweb-system-config-starter/src/test/resources/application.yml @@ -2,7 +2,7 @@ spring: aop: auto: true datasource: - url : jdbc:h2:mem:test_mem + url : jdbc:h2:mem:config_test_mem username : sa password : type: com.alibaba.druid.pool.DruidDataSource diff --git a/hsweb-system/hsweb-system-config/pom.xml b/hsweb-system/hsweb-system-config/pom.xml index a221eebf6..aed0a556f 100644 --- a/hsweb-system/hsweb-system-config/pom.xml +++ b/hsweb-system/hsweb-system-config/pom.xml @@ -33,7 +33,7 @@ hsweb-system-config-dao hsweb-system-config-service hsweb-system-config-controller - hsweb-system-config-bean + hsweb-system-config-entity hsweb-system-config-starter diff --git a/hsweb-system/hsweb-system-document/pom.xml b/hsweb-system/hsweb-system-document/pom.xml new file mode 100644 index 000000000..447d3eccb --- /dev/null +++ b/hsweb-system/hsweb-system-document/pom.xml @@ -0,0 +1,15 @@ + + + + hsweb-system + org.hswebframework.web + 3.0-SNAPSHOT + + 4.0.0 + + hsweb-system-document + + + \ No newline at end of file diff --git a/hsweb-system/pom.xml b/hsweb-system/pom.xml index 143ee0691..2ad754c33 100644 --- a/hsweb-system/pom.xml +++ b/hsweb-system/pom.xml @@ -28,6 +28,7 @@ hsweb-system-script hsweb-system-history hsweb-system-dictionary + hsweb-system-document hsweb-system diff --git a/hsweb-tests/src/main/java/org/hswebframework/web/tests/SimpleWebApplicationTests.java b/hsweb-tests/src/main/java/org/hswebframework/web/tests/SimpleWebApplicationTests.java index e5953115e..47e75e28f 100644 --- a/hsweb-tests/src/main/java/org/hswebframework/web/tests/SimpleWebApplicationTests.java +++ b/hsweb-tests/src/main/java/org/hswebframework/web/tests/SimpleWebApplicationTests.java @@ -20,12 +20,14 @@ package org.hswebframework.web.tests; import org.hsweb.ezorm.rdb.executor.AbstractJdbcSqlExecutor; import org.hsweb.ezorm.rdb.executor.SqlExecutor; -import org.hswebframework.web.commons.beans.factory.BeanFactory; -import org.hswebframework.web.commons.beans.factory.MapperBeanFactory; +import org.hswebframework.web.commons.entity.Entity; +import org.hswebframework.web.commons.entity.factory.EntityFactory; +import org.hswebframework.web.commons.entity.factory.MapperEntityFactory; import org.hswebframework.web.dao.datasource.DataSourceHolder; import org.hswebframework.web.dao.datasource.DatabaseType; import org.junit.Before; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.test.context.SpringBootTest; @@ -41,7 +43,6 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde import org.springframework.web.context.WebApplicationContext; import javax.annotation.Resource; -import javax.servlet.http.HttpSession; import javax.sql.DataSource; import javax.validation.Validation; import javax.validation.Validator; @@ -67,6 +68,9 @@ public class SimpleWebApplicationTests { protected MockHttpSession session; + @Autowired + protected SqlExecutor sqlExecutor; + @Before public void setup() throws Exception { this.mvc = webAppContextSetup(this.wac).build(); @@ -127,8 +131,8 @@ public class SimpleWebApplicationTests { } @Bean - public BeanFactory beanFactory() { - return new MapperBeanFactory(); + public EntityFactory beanFactory() { + return new MapperEntityFactory(); } @Bean diff --git a/pom.xml b/pom.xml index fed6c7f84..6f2ae047e 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ 5.1.1.Final 3.0.0-SNAPSHOT - 3.0.2 + 3.0.0-SNAPSHOT 3.0.0-SNAPSHOT