Browse Source

删除无用代码,更新注释

NorthLan 7 years ago
parent
commit
8aa8676649

+ 8 - 1
zen-orm/src/main/kotlin/com/gxzc/zen/Generator.kt

@@ -11,7 +11,7 @@ import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
 import java.io.File
 
 /**
- *
+ * 代码生成器
  * @author NorthLan
  * @date 2018/1/24
  * @url https://noahlan.me
@@ -34,6 +34,13 @@ fun main(args: Array<String>) {
     })
 }
 
+/**
+ * 代码生成器具体执行方法<br>
+ * @param isKotlin 是否生成kotlin代码
+ * @param author 作者
+ * @param pkgType 包类别 (sys/bus)
+ * @param dataSourceConfig 数据源配置
+ */
 fun generate(isKotlin: Boolean, author: String, pkgType: String, dataSourceConfig: DataSourceConfig) {
     val mpg = AutoGenerator()
 

+ 0 - 33
zen-orm/src/main/kotlin/com/gxzc/zen/orm/DataSourceSwitchMethodInterceptor.kt

@@ -1,33 +0,0 @@
-package com.gxzc.zen.orm
-
-import com.gxzc.zen.orm.annotation.DynamicDataSource
-import com.gxzc.zen.orm.contants.DSKey
-import org.aopalliance.intercept.MethodInterceptor
-import org.aopalliance.intercept.MethodInvocation
-import java.lang.reflect.Method
-
-/**
- *
- * @author NorthLan at 2018/1/31
- */
-class DataSourceSwitchMethodInterceptor : MethodInterceptor {
-    override fun invoke(invocation: MethodInvocation): Any {
-        val packageName = invocation.`this`::class.java.`package`.name
-        matchDataSource(invocation.method, packageName)
-        return invocation.proceed()
-    }
-
-    private fun matchDataSource(method: Method, packageName: String) {
-        DSKey.values()
-                .filter { it.pkgName in packageName }
-                .forEach { setDataSource(method, it.dsKey) }
-    }
-
-    /**
-     * 设置数据源key
-     */
-    private fun setDataSource(method: Method, defaultKey: String) {
-        val dynamicDataSource: DynamicDataSource? = method.getAnnotation(DynamicDataSource::class.java)
-        DynamicMultipleDataSource.setDataSource(dynamicDataSource?.value ?: defaultKey)
-    }
-}

+ 0 - 10
zen-orm/src/main/kotlin/com/gxzc/zen/orm/annotation/Test.java

@@ -1,10 +0,0 @@
-package com.gxzc.zen.orm.annotation;
-
-/**
- * @author NorthLan
- * @date 2018/2/3
- * @url https://noahlan.com
- */
-public @interface Test {
-    Class<? extends Throwable>[] rollbackFor() default {};
-}

+ 2 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/aop/DataSourceSwitchAspect.kt

@@ -8,6 +8,7 @@ import org.aspectj.lang.ProceedingJoinPoint
 import org.aspectj.lang.annotation.*
 import org.aspectj.lang.reflect.MethodSignature
 import org.slf4j.LoggerFactory
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.core.annotation.Order
 import org.springframework.stereotype.Component
 import java.lang.reflect.Method
@@ -21,6 +22,7 @@ import java.lang.reflect.Method
 @Aspect
 @Order(-1) // 保证先于事务执行
 @Component
+@ConditionalOnProperty(prefix = "orm", name = ["multi-datasource-enable"], havingValue = "true", matchIfMissing = true)
 class DataSourceSwitchAspect {
     companion object {
         private val logger = LoggerFactory.getLogger(DataSourceSwitchAspect::class.java)

+ 2 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/aop/MultiDataSourceAspect.kt

@@ -7,6 +7,7 @@ import org.aspectj.lang.annotation.Around
 import org.aspectj.lang.annotation.Aspect
 import org.aspectj.lang.reflect.MethodSignature
 import org.slf4j.LoggerFactory
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.stereotype.Component
 import org.springframework.transaction.jta.JtaTransactionManager
 import kotlin.reflect.KClass
@@ -18,6 +19,7 @@ import kotlin.reflect.KClass
 @Aspect
 @Suppress("unused")
 @Component
+@ConditionalOnProperty(prefix = "orm", name = ["multi-datasource-enable"], havingValue = "true", matchIfMissing = true)
 class MultiDataSourceAspect {
     companion object {
         private val logger = LoggerFactory.getLogger(MultiDataSourceAspect::class.java)

+ 2 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/config/MultipleDataSourceConfig.kt

@@ -10,6 +10,7 @@ import com.gxzc.zen.orm.DynamicMultipleDataSource
 import com.gxzc.zen.orm.contants.DSKey
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.beans.factory.annotation.Qualifier
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.boot.context.properties.ConfigurationProperties
 import org.springframework.boot.context.properties.EnableConfigurationProperties
 import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean
@@ -29,6 +30,7 @@ import javax.sql.XADataSource
  */
 @Configuration
 @EnableConfigurationProperties(MybatisPlusProperties::class)
+@ConditionalOnProperty(prefix = "orm", name = ["multi-datasource-enable"], havingValue = "true", matchIfMissing = true)
 class MultipleDataSourceConfig {
 
     @Autowired

+ 0 - 148
zen-orm/src/main/kotlin/com/gxzc/zen/orm/config/TransactionalConfig.kt

@@ -1,148 +0,0 @@
-//package com.gxzc.zen.orm.config
-//
-//import com.gxzc.zen.orm.DataSourceSwitchMethodInterceptor
-//import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor
-//import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
-//import org.springframework.beans.factory.annotation.Qualifier
-//import org.springframework.context.annotation.Bean
-//import org.springframework.context.annotation.Configuration
-//import org.springframework.transaction.PlatformTransactionManager
-//import org.springframework.transaction.TransactionDefinition
-//import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource
-//import org.springframework.transaction.interceptor.RollbackRuleAttribute
-//import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
-//import org.springframework.transaction.interceptor.TransactionInterceptor
-//
-//
-///**
-// * 事务配置 支持动态数据源
-// * @author NorthLan at 2018/1/31
-// */
-//@Configuration
-//class TransactionalConfig {
-//    companion object {
-//        private const val CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME = "customizeTransactionInterceptor"
-//        private const val DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME = "dataSourceSwitchMethodInterceptor"
-//        /**
-//         * 默认只对 "*Service" , "*ServiceImpl" Bean 进行事务处理,"*"表示模糊匹配, 比如 : userService,orderServiceImpl
-//         */
-//        private val DEFAULT_TRANSACTION_BEAN_NAMES = arrayOf("*Service", "*ServiceImpl", "*Mapper")
-//        /**
-//         * 可传播事务配置
-//         */
-//        private val DEFAULT_REQUIRED_METHOD_RULE_TRANSACTION_ATTRIBUTES = arrayOf(
-//                "add*",
-//                "save*",
-//                "insert*",
-//                "delete*",
-//                "update*",
-//                "edit*",
-//                "batch*",
-//                "create*",
-//                "remove*"
-//        )
-//        /**
-//         * 默认的只读事务
-//         */
-//        private val DEFAULT_READ_ONLY_METHOD_RULE_TRANSACTION_ATTRIBUTES = arrayOf(
-//                "get*",
-//                "count*",
-//                "find*",
-//                "query*",
-//                "select*",
-//                "list*",
-//                "*"
-//        )
-//    }
-//
-//    /**
-//     * 自定义事务 BeanName 拦截
-//     */
-//    private val customizeTransactionBeanNames = arrayOf<String>()
-//    /**
-//     * 自定义方法名的事务属性相关联,可以使用通配符(*)字符关联相同的事务属性的设置方法; 只读事务
-//     */
-//    private val customizeReadOnlyMethodRuleTransactionAttributes = arrayOf<String>()
-//    /**
-//     * 自定义方法名的事务属性相关联,可以使用通配符(*)字符关联相同的事务属性的设置方法;
-//     * 传播事务(默认的)[org.springframework.transaction.annotation.Propagation.REQUIRED]
-//     */
-//    private val customizeRequiredMethodRuleTransactionAttributes = arrayOf<String>()
-//
-//    /**
-//     * 配置事务拦截器
-//     * @param platformTransactionManager 事务管理器
-//     */
-//    @Bean(CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME)
-//    fun customizeTransactionInterceptor(platformTransactionManager: PlatformTransactionManager): TransactionInterceptor {
-//        val transactionAttributeSource = NameMatchTransactionAttributeSource()
-//        val readOnly = this.readOnlyTransactionRule()
-//        val required = this.requiredTransactionRule()
-//        // 默认的只读事务配置
-//        for (methodName in DEFAULT_READ_ONLY_METHOD_RULE_TRANSACTION_ATTRIBUTES) {
-//            transactionAttributeSource.addTransactionalMethod(methodName, readOnly)
-//        }
-//        // 默认的传播事务配置
-//        for (methodName in DEFAULT_REQUIRED_METHOD_RULE_TRANSACTION_ATTRIBUTES) {
-//            transactionAttributeSource.addTransactionalMethod(methodName, required)
-//        }
-//        // 定制的只读事务配置
-//        for (methodName in customizeReadOnlyMethodRuleTransactionAttributes) {
-//            transactionAttributeSource.addTransactionalMethod(methodName, readOnly)
-//        }
-//        // 定制的传播事务配置
-//        for (methodName in customizeRequiredMethodRuleTransactionAttributes) {
-//            transactionAttributeSource.addTransactionalMethod(methodName, required)
-//        }
-//        return TransactionInterceptor(platformTransactionManager, transactionAttributeSource)
-//    }
-//
-////    @Bean
-////    fun aspectJExpressionPointcutAdvisor(@Qualifier(CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME) transactionInterceptor: TransactionInterceptor): AspectJExpressionPointcutAdvisor {
-////        return AspectJExpressionPointcutAdvisor().also {
-////            it.advice = transactionInterceptor
-////            it.expression = "execution (* com.gxzc.zen.api..*Service.*(..))"
-////        }
-////    }
-//
-////    @Bean
-////    fun beanNameAutoProxyCreator(): BeanNameAutoProxyCreator {
-////        return BeanNameAutoProxyCreator().also {
-////            it.setInterceptorNames(DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME,
-////                    CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME)
-////            // 归集
-////            it.setBeanNames(*arrayListOf<String>().also {
-////                it.addAll(DEFAULT_TRANSACTION_BEAN_NAMES) // 默认
-////                it.addAll(customizeTransactionBeanNames) // 定制
-////            }.toTypedArray())
-////            it.isProxyTargetClass = true
-////        }
-////    }
-////
-////    @Bean(DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME)
-////    fun dataSourceSwitchMethodInterceptor(): DataSourceSwitchMethodInterceptor {
-////        return DataSourceSwitchMethodInterceptor()
-////    }
-//
-//    /**
-//     * 支持当前事务
-//     * 如果不存在创建一个新的
-//     */
-//    private fun requiredTransactionRule(): RuleBasedTransactionAttribute {
-//        return RuleBasedTransactionAttribute().also {
-//            it.rollbackRules = arrayListOf(RollbackRuleAttribute(Exception::class.java))
-//            it.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRED
-//            it.timeout = TransactionDefinition.TIMEOUT_DEFAULT
-//        }
-//    }
-//
-//    /**
-//     * 只读事务
-//     */
-//    private fun readOnlyTransactionRule(): RuleBasedTransactionAttribute {
-//        return RuleBasedTransactionAttribute().also {
-//            it.isReadOnly = true
-//            it.propagationBehavior = TransactionDefinition.PROPAGATION_NOT_SUPPORTED
-//        }
-//    }
-//}

+ 74 - 53
zen-orm/src/main/resources/application-orm-local.yml

@@ -1,76 +1,97 @@
-#spring:
-#  datasource:
-#    type: com.alibaba.druid.pool.DruidDataSource
-
-###################  mybatis-plus配置  ###################
-mybatis-plus:
-  mapper-locations: classpath*:mapping/**/*.xml
-#  type-aliases-package: com.gxzc.zen.api.bus.mapper,com.gxzc.zen.api.sys.mapper #,com.gxzc.zen.api.useage.mapper
-  global-config:
-    id-type: 0  #0:数据库ID自增   1:用户输入id  2:全局唯一id(IdWorker)  3:全局唯一ID(uuid)
-    db-column-underline: true
-    refresh-mapper: true
-    logic-delete-value: 0
-    logic-not-delete-value: 1
-    sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
-  configuration:
-    map-underscore-to-camel-case: true
-    cache-enabled: true #配置的缓存的全局开关
-    lazyLoadingEnabled: true #延时加载的开关
-    multipleResultSetsEnabled: true #延时加载一个属性时会加载该对象全部属性,否则按需加载属性
-    interceptors: com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
-    # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
-
+### 多数据源开关
+orm:
+  multi-datasource-enable: true
 
 ################## Alibaba Druid 配置 ##################
 spring:
   datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
     druid:
       stat-view-servlet:
         enabled: true
         login-username: root
         login-password: root
         reset-enable: false
+      ############ 以下是关闭多数据源时使用的默认数据源 ############
+      username: root
+      password: root
+      url: jdbc:mysql://127.0.0.1:3306/archives_sys?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
+      driver-class-name: com.mysql.jdbc.Driver
+      test-on-borrow: false
+      test-on-return: false
+      test-while-idle: true
+      validation-query: SELECT 1
+      async-init: false
+      name: system
+      filters: logback,log4j,wall,mergeStat
+      keep-alive: false
+      initial-size: 5
+      min-idle: 5
+      max-active: 20
+      time-between-eviction-runs-millis: 60000
+      min-evictable-idle-time-millis: 30000
 
+################## 数据源 配置 ##################
 datasource:
   sys:
-    name: archives_sys
+    name: system
     url: jdbc:mysql://127.0.0.1:3306/archives_sys?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
+    driver-class-name: com.mysql.jdbc.Driver
     username: root
     password: root
-    testWhileIdle: true
-    testOnBorrow: false
-    testOnReturn: false
-    validationQuery: SELECT 1
-    asyncInit: false # 异步初始化
-    filters: log4j,wall,mergeStat
-    keepAlive: false
-    driver-class-name: com.mysql.jdbc.Driver
-    initialize: false #指定初始化数据源,是否用data.sql来初始化,默认: true
-    initialSize: 5
-    minIdle: 5
-    maxActive: 20
-    timeBetweenEvictionRunsMillis: 60000
-    minEvictableIdleTimeMillis: 30000
+    test-on-borrow: false
+    test-on-return: false
+    test-while-idle: true
+    validation-query: SELECT 1
+    async-init: false
+    name: sys
+    filters: logback,log4j,wall,mergeStat
+    keep-alive: false
+    initial-size: 5
+    min-idle: 5
+    max-active: 20
+    time-between-eviction-runs-millis: 60000
+    min-evictable-idle-time-millis: 30000
   bus:
-    name: archives_bus
+    name: business
     url: jdbc:mysql://127.0.0.1:3306/archives_mgr?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
+    driver-class-name: com.mysql.jdbc.Driver
     username: root
     password: root
-    testWhileIdle: true
-    testOnBorrow: false
-    testOnReturn: false
-    validationQuery: SELECT 1
-    asyncInit: false # 异步初始化
-    filters: log4j,wall,mergeStat
-    keepAlive: false
-    driver-class-name: com.mysql.jdbc.Driver
-    initialize: false #指定初始化数据源,是否用data.sql来初始化,默认: true
-    initialSize: 5
-    minIdle: 5
-    maxActive: 20
-    timeBetweenEvictionRunsMillis: 60000
-    minEvictableIdleTimeMillis: 30000
+    test-on-borrow: false
+    test-on-return: false
+    test-while-idle: true
+    validation-query: SELECT 1
+    async-init: false
+    name: sys
+    filters: logback,log4j,wall,mergeStat
+    keep-alive: false
+    initial-size: 5
+    min-idle: 5
+    max-active: 20
+    time-between-eviction-runs-millis: 60000
+    min-evictable-idle-time-millis: 30000
+
+###################  mybatis-plus配置  ###################
+mybatis-plus:
+  mapper-locations: classpath*:mapping/**/*.xml
+  type-aliases-package: com.gxzc.zen.api.bus.mapper,com.gxzc.zen.api.sys.mapper
+  global-config:
+    id-type: 0  #0:数据库ID自增   1:用户输入id  2:全局唯一id(IdWorker)  3:全局唯一ID(uuid)
+    db-column-underline: true
+    refresh-mapper: true
+    # logic-delete-value: 0
+    # logic-not-delete-value: 1
+    sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
+    meta-object-handler: com.gxzc.zen.orm.CustomMetaObjectHandler
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: true #配置的缓存的全局开关
+    lazyLoadingEnabled: true #延时加载的开关
+    multipleResultSetsEnabled: true #延时加载一个属性时会加载该对象全部属性,否则按需加载属性
+    interceptors: com.baomidou.mybatisplus.plugins.OptimisticLockerInterceptor
+    # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
+
 
 ##sharding-jdbc
 #sharding:

+ 1 - 1
zen-umps/src/main/kotlin/com/gxzc/zen/ump/KissoAuthorization.kt → zen-umps/src/main/kotlin/com/gxzc/zen/umps/KissoAuthorization.kt

@@ -1,4 +1,4 @@
-package com.gxzc.zen.ump
+package com.gxzc.zen.umps
 
 import com.baomidou.kisso.SSOAuthorization
 import com.baomidou.kisso.security.token.SSOToken

+ 2 - 2
zen-umps/src/main/kotlin/com/gxzc/zen/ump/KissoWebAppConfigurer.kt → zen-umps/src/main/kotlin/com/gxzc/zen/umps/KissoWebAppConfigurer.kt

@@ -1,8 +1,7 @@
-package com.gxzc.zen.ump
+package com.gxzc.zen.umps
 
 import com.baomidou.kisso.web.interceptor.SSOPermissionInterceptor
 import com.baomidou.kisso.web.interceptor.SSOSpringInterceptor
-import org.springframework.context.annotation.Bean
 import org.springframework.context.annotation.Configuration
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@@ -22,6 +21,7 @@ class KissoWebAppConfigurer : WebMvcConfigurerAdapter() {
         //权限拦截
         registry.addInterceptor(SSOPermissionInterceptor().also { it.authorization = KissoAuthorization() })
                 .addPathPatterns("/**")
+                .excludePathPatterns("/login")
         super.addInterceptors(registry)
     }
 }

+ 17 - 0
zen-umps/src/main/kotlin/com/gxzc/zen/umps/contants/PERM.kt

@@ -0,0 +1,17 @@
+package com.gxzc.zen.umps.contants
+
+/**
+ * 权限列表
+ * @author NorthLan
+ * @date 2018/2/6
+ * @url https://noahlan.com
+ */
+object PERM {
+    private const val SEPERATOR = ":" // 分隔符
+    private const val SELECT = "select" // 查询
+    private const val CREATE = "create" // 新增
+    private const val DELETE = "delete" // 删除
+    private const val UPDATE = "update" // 修改
+    //////
+
+}

+ 3 - 0
zen-web/src/main/resources/application-platform.yml

@@ -0,0 +1,3 @@
+platform:
+  id: 1 # 平台ID(0:通用,1:系统,2:接收,3:保存,4:管理,5:利用)
+  name: 系统

+ 1 - 1
zen-web/src/test/kotlin/com/gxzc/zen/cache/TestCacheController.kt

@@ -1,7 +1,7 @@
 package com.gxzc.zen.cache
 
 import com.gxzc.zen.base.BaseTestKt
-import com.gxzc.zen.orm.annotation.Test
+import org.junit.Test
 import org.springframework.http.MediaType
 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
 import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content