Jelajahi Sumber

配置一堆东西

NorthLan 7 tahun lalu
induk
melakukan
3ee08e0c42
32 mengubah file dengan 569 tambahan dan 236 penghapusan
  1. 2 2
      .gitignore
  2. 3 6
      build.gradle
  3. 2 1
      zen-admin/build.gradle
  4. 2 4
      zen-admin/src/main/kotlin/com/gxzc/zen/MainApplication.kt
  5. 41 0
      zen-admin/src/main/kotlin/com/gxzc/zen/controller/ExampleController.kt
  6. 0 19
      zen-admin/src/main/kotlin/com/gxzc/zen/persistence/controller/ExampleController.kt
  7. 5 30
      zen-admin/src/main/resources/application.yml
  8. 0 28
      zen-admin/src/test/kotlin/com/gxzc/zen/Test.kt
  9. 12 0
      zen-api/build.gradle
  10. 14 0
      zen-api/src/main/kotlin/com/gxzc/zen/api/rec/mapper/SysDicDao.kt
  11. 26 0
      zen-api/src/main/kotlin/com/gxzc/zen/api/rec/model/SysDic.kt
  12. 14 0
      zen-api/src/main/kotlin/com/gxzc/zen/api/rec/service/ISysDicService.kt
  13. 20 0
      zen-api/src/main/kotlin/com/gxzc/zen/api/rec/service/impl/SysDicServiceImpl.kt
  14. 2 2
      zen-api/src/main/kotlin/com/gxzc/zen/api/sys/mapper/SysDeptDao.kt
  15. 3 3
      zen-api/src/main/kotlin/com/gxzc/zen/api/sys/model/SysDept.kt
  16. 2 2
      zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/ISysDeptService.kt
  17. 4 4
      zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysDeptServiceImpl.kt
  18. 0 0
      zen-api/src/main/resources/2312313.txt
  19. 19 0
      zen-api/src/main/resources/mapping/rec/SysDicDao.xml
  20. 2 2
      zen-api/src/main/resources/mapping/sys/SysDeptDao.xml
  21. 1 1
      zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseMapper.kt
  22. 1 1
      zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseModel.kt
  23. 1 1
      zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseService.kt
  24. 0 115
      zen-config/src/main/kotlin/com/gxzc/zen/config/DruidConfig.kt
  25. 1 0
      zen-orm/build.gradle
  26. 14 15
      zen-orm/src/main/kotlin/com/gxzc/zen/Generator.kt
  27. 121 0
      zen-orm/src/main/kotlin/com/gxzc/zen/orm/DruidConfig.kt
  28. 46 0
      zen-orm/src/main/kotlin/com/gxzc/zen/orm/DruidViewConfig.kt
  29. 66 0
      zen-orm/src/main/kotlin/com/gxzc/zen/orm/RecDataSourceConfig.kt
  30. 71 0
      zen-orm/src/main/kotlin/com/gxzc/zen/orm/SysDataSourceConfig.kt
  31. 23 0
      zen-orm/src/main/kotlin/com/gxzc/zen/orm/base/BaseDataSourceProperties.kt
  32. 51 0
      zen-orm/src/main/resources/application-orm.yml

+ 2 - 2
.gitignore

@@ -114,8 +114,6 @@ local.properties
 
 ## Plugin-specific files:
 
-# IntelliJ
-/out/
 
 # mpeltonen/sbt-idea plugin
 .idea_modules/
@@ -144,6 +142,8 @@ logs/
 *.iml
 .idea/
 .gradle/
+/out/
+
 
 # Gradle
 /build/

+ 3 - 6
build.gradle

@@ -1,4 +1,4 @@
-group 'com.gxzc.pro'
+group 'com.gxzc.zen'
 version '1.0-SNAPSHOT'
 
 buildscript {
@@ -18,10 +18,8 @@ buildscript {
         ehcache_core_version = '2.6.11'
         mysql_connector_version = '5.1.45'
         alidruid_version = '1.1.6'
-        mybatis_version = '3.4.5'
-        mybatiss_version = '1.3.1'
-        mybatis_plus_version = '2.1.7'
-        mybatis_plus_boot_version = '1.0.4'
+        mybatis_plus_version = '2.1.8'
+        mybatis_plus_boot_version = '1.0.5'
         activiti_version = '7-201712-EA'
         rabbitmq_version = '5.1.2'
         xxljob_version = '1.9.0'
@@ -39,7 +37,6 @@ buildscript {
     }
 }
 
-
 allprojects {}
 
 

+ 2 - 1
zen-admin/build.gradle

@@ -1,6 +1,7 @@
 apply plugin: 'war'
 
 dependencies {
-    compile project(":zen-api")
     compile project(":zen-ui")
+    compile project(":zen-orm")
+    compile project(":zen-api")
 }

+ 2 - 4
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/MainApplication.kt → zen-admin/src/main/kotlin/com/gxzc/zen/MainApplication.kt

@@ -1,6 +1,5 @@
-package com.gxzc.zen.persistence
+package com.gxzc.zen
 
-import org.mybatis.spring.annotation.MapperScan
 import org.springframework.boot.SpringApplication
 import org.springframework.boot.autoconfigure.SpringBootApplication
 import org.springframework.boot.builder.SpringApplicationBuilder
@@ -8,13 +7,12 @@ import org.springframework.boot.web.support.SpringBootServletInitializer
 
 
 @SpringBootApplication
-@MapperScan("com.gxzc.zen.*.mapper")
 class MainApplication : SpringBootServletInitializer() {
     override fun configure(builder: SpringApplicationBuilder?): SpringApplicationBuilder? {
         return builder?.sources(MainApplication::class.java)
     }
 }
 
-fun main(args:Array<String>){
+fun main(args: Array<String>) {
     SpringApplication.run(MainApplication::class.java, *args)
 }

+ 41 - 0
zen-admin/src/main/kotlin/com/gxzc/zen/controller/ExampleController.kt

@@ -0,0 +1,41 @@
+package com.gxzc.zen.controller
+
+import com.gxzc.zen.api.rec.model.SysDic
+import com.gxzc.zen.api.rec.service.ISysDicService
+import com.gxzc.zen.api.sys.model.SysDept
+import com.gxzc.zen.api.sys.service.ISysDeptService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Controller
+import org.springframework.web.bind.annotation.RequestMapping
+
+
+@Controller
+@RequestMapping("example")
+class ExampleController {
+    @Autowired
+    lateinit var sysDeptService: ISysDeptService
+
+//    @Autowired
+//    val sysDicService: ISysDicService?= null
+
+    @RequestMapping("/test")
+    fun test() {
+        val dept = SysDept().also {
+            it.deptName = "test"
+            it.principal = "create"
+            it.sort = 1
+        }
+        sysDeptService.insert(dept)
+    }
+
+    @RequestMapping("/test2")
+    fun test2(){
+        val sysDic = SysDic().also {
+            it.key = "hehe"
+            it.value = "hehe"
+            it.sort = 1
+        }
+
+//        sysDicService?.insert(sysDic)
+    }
+}

+ 0 - 19
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/controller/ExampleController.kt

@@ -1,19 +0,0 @@
-package com.gxzc.zen.persistence.controller
-
-import com.gxzc.zen.persistence.service.ISysDeptService
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.stereotype.Controller
-import org.springframework.web.bind.annotation.RequestMapping
-
-
-@Controller
-@RequestMapping("example")
-class ExampleController {
-    @Autowired
-    lateinit var sysDeptService: ISysDeptService
-
-    @RequestMapping("/test")
-    fun test() {
-
-    }
-}

+ 5 - 30
zen-admin/src/main/resources/application.yml

@@ -1,35 +1,10 @@
-
 server:
   port: 8081
 
-
-###################  druid配置  ###################
-druid:
-  view:
-    enable: false
-    username: root
-    password: 123456
-    slowSql: true
-  datasource-sys:
-    url: jdbc:mysql://192.168.1.124:3307/archives_sys?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
-    username: archives
-    password: archives
-    filters: log4j,wall,mergeStat
-    driver-class-name: com.mysql.jdbc.Driver
-    initialSize: 5
-    minIdle: 5
-    maxActive: 20
-    timeBetweenEvictionRunsMillis: 60000
-    minEvictableIdleTimeMillis: 30000
-    validationQuery: SELECT 1 FROM DUAL
-    testWhileIdle: true
-    testOnBorrow: false
-    testOnReturn: false
-
 ###################  mybatis-plus配置  ###################
 mybatis-plus:
-  mapper-locations: classpath*:com/gxzc/zen/*/mapper/*/*.xml
-  typeAliasesPackage: com.gxzc.zen.*.mapper
+  mapper-locations: classpath:mapping/*/*.xml
+  typeAliasesPackage: com.gxzc.zen.api.sys.mapper, com.gxzc.zen.api.rec.mapper
   global-config:
     id-type: 0  #0:数据库ID自增   1:用户输入id  2:全局唯一id(IdWorker)  3:全局唯一ID(uuid)
     db-column-underline: true
@@ -41,13 +16,14 @@ mybatis-plus:
     cache-enabled: true #配置的缓存的全局开关
     lazyLoadingEnabled: true #延时加载的开关
     multipleResultSetsEnabled: true #开启的话,延时加载一个属性时会加载该对象全部属性,否则按需加载属性
-#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
 
 
 ###################  spring配置  ###################
 spring:
   profiles:
     active: dev
+    include: orm
 #  redis:
 #    host: localhost
 #    port: 6379
@@ -59,5 +35,4 @@ spring:
       max-request-size: 100MB #最大请求大小
       max-file-size: 100MB #最大文件大小
   aop:
-    proxy-target-class: true #false为启用jdk默认动态代理,true为cglib动态代理
-
+    proxy-target-class: true #false为启用jdk默认动态代理,true为cglib动态代理

+ 0 - 28
zen-admin/src/test/kotlin/com/gxzc/zen/Test.kt

@@ -1,28 +0,0 @@
-package com.gxzc.zen
-
-import com.gxzc.zen.base.BaseTestKt
-import org.junit.Test
-import org.springframework.beans.factory.annotation.Autowired
-
-/**
- *
- * @author NorthLan
- * @date 2018/1/26
- * @url https://noahlan.com
- */
-class Test: BaseTestKt() {
-
-    @Autowired
-    private lateinit var iSysDicService: ISysDicService
-
-
-    @Test
-    fun test(){
-        val sysDic = SysDic().also {
-            it.key = "haha"
-            it.value = "hehe"
-            it.sort = Integer(1)
-        }
-        iSysDicService.insert(sysDic)
-    }
-}

+ 12 - 0
zen-api/build.gradle

@@ -2,3 +2,15 @@ dependencies {
     compile project(":zen-umps")
     compile project(":zen-orm")
 }
+
+jar{
+    from("src/main/kotlin") {
+        include("**/*.xml")
+    }
+}
+
+processResources {
+    from("src/main/kotlin") {
+        include("**/*.xml")
+    }
+}

+ 14 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/rec/mapper/SysDicDao.kt

@@ -0,0 +1,14 @@
+package com.gxzc.zen.api.rec.mapper;
+
+import com.gxzc.zen.api.rec.model.SysDic;
+import com.gxzc.zen.common.base.BaseMapper;
+
+/**
+ * <p>
+ * 字典表 Mapper 接口
+ * </p>
+ *
+ * @author NorthLan123
+ * @since 2018-01-27
+ */
+interface SysDicDao : BaseMapper<SysDic>

+ 26 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/rec/model/SysDic.kt

@@ -0,0 +1,26 @@
+package com.gxzc.zen.api.rec.model;
+
+import com.gxzc.zen.common.base.BaseModel;
+
+/**
+ * <p>
+ * 字典表
+ * </p>
+ *
+ * @author NorthLan123
+ * @since 2018-01-27
+ */
+data class SysDic(
+        /**
+         * 字典代码
+         */
+        var key: String? = null,
+        /**
+         * 字典值
+         */
+        var value: String? = null,
+        /**
+         * 排序号
+         */
+        var sort: Int? = null
+) : BaseModel()

+ 14 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/rec/service/ISysDicService.kt

@@ -0,0 +1,14 @@
+package com.gxzc.zen.api.rec.service;
+
+import com.gxzc.zen.api.rec.model.SysDic;
+import com.gxzc.zen.common.base.BaseService;
+
+/**
+ * <p>
+ * 字典表 服务类
+ * </p>
+ *
+ * @author NorthLan123
+ * @since 2018-01-27
+ */
+interface ISysDicService : BaseService<SysDic>

+ 20 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/rec/service/impl/SysDicServiceImpl.kt

@@ -0,0 +1,20 @@
+package com.gxzc.zen.api.rec.service.impl;
+
+import com.gxzc.zen.api.rec.model.SysDic;
+import com.gxzc.zen.api.rec.mapper.SysDicDao;
+import com.gxzc.zen.api.rec.service.ISysDicService;
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 字典表 服务实现类
+ * </p>
+ *
+ * @author NorthLan123
+ * @since 2018-01-27
+ */
+//@Service
+open class SysDicServiceImpl : ServiceImpl<SysDicDao, SysDic>(), ISysDicService {
+
+}

+ 2 - 2
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/mapper/SysDeptDao.kt → zen-api/src/main/kotlin/com/gxzc/zen/api/sys/mapper/SysDeptDao.kt

@@ -1,7 +1,7 @@
-package com.gxzc.zen.persistence.mapper;
+package com.gxzc.zen.api.sys.mapper;
 
 import com.baomidou.mybatisplus.mapper.BaseMapper
-import com.gxzc.zen.persistence.model.SysDept
+import com.gxzc.zen.api.sys.model.SysDept
 import org.springframework.stereotype.Repository
 
 /**

+ 3 - 3
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/model/SysDept.kt → zen-api/src/main/kotlin/com/gxzc/zen/api/sys/model/SysDept.kt

@@ -1,7 +1,7 @@
-package com.gxzc.zen.persistence.model
+package com.gxzc.zen.api.sys.model
 
 import com.baomidou.mybatisplus.annotations.TableName
-import com.gxzc.zen.persistence.BaseModel
+import com.gxzc.zen.common.base.BaseModel
 
 /**
  * <p>
@@ -25,4 +25,4 @@ data class SysDept(
          * 排序号
          */
         var sort: Int? = null
-) : BaseModel()
+) : BaseModel()

+ 2 - 2
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/service/ISysDeptService.kt → zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/ISysDeptService.kt

@@ -1,7 +1,7 @@
-package com.gxzc.zen.persistence.service;
+package com.gxzc.zen.api.sys.service;
 
 import com.baomidou.mybatisplus.service.IService
-import com.gxzc.zen.persistence.model.SysDept
+import com.gxzc.zen.api.sys.model.SysDept
 
 /**
  * <p>

+ 4 - 4
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/service/impl/SysDeptServiceImpl.kt → zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysDeptServiceImpl.kt

@@ -1,9 +1,9 @@
-package com.gxzc.zen.persistence.service.impl;
+package com.gxzc.zen.api.sys.service.impl;
 
 import com.baomidou.mybatisplus.service.impl.ServiceImpl
-import com.gxzc.zen.persistence.mapper.SysDeptDao
-import com.gxzc.zen.persistence.model.SysDept
-import com.gxzc.zen.persistence.service.ISysDeptService
+import com.gxzc.zen.api.sys.mapper.SysDeptDao
+import com.gxzc.zen.api.sys.model.SysDept
+import com.gxzc.zen.api.sys.service.ISysDeptService
 import org.springframework.stereotype.Service
 
 /**

+ 0 - 0
zen-api/src/main/resources/2312313.txt


+ 19 - 0
zen-api/src/main/resources/mapping/rec/SysDicDao.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gxzc.zen.api.rec.mapper.SysDicDao">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.gxzc.zen.api.rec.model.SysDic">
+    <result column="id" property="id" />
+    <result column="enable" property="enable" />
+    <result column="remark" property="remark" />
+    <result column="create_time" property="createTime" />
+    <result column="create_by" property="createBy" />
+    <result column="update_time" property="updateTime" />
+    <result column="update_by" property="updateBy" />
+        <result column="key" property="key" />
+        <result column="value" property="value" />
+        <result column="sort" property="sort" />
+    </resultMap>
+
+</mapper>

+ 2 - 2
zen-admin/src/main/kotlin/com/gxzc/zen/persistence/mapper/xml/SysDeptDao.xml → zen-api/src/main/resources/mapping/sys/SysDeptDao.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.gxzc.zen.persistence.mapper.SysDeptDao">
+<mapper namespace="com.gxzc.zen.api.sys.mapper.SysDeptDao">
 
     <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.gxzc.zen.persistence.model.SysDept">
+    <resultMap id="BaseResultMap" type="com.gxzc.zen.api.sys.model.SysDept">
         <result column="id" property="id"/>
         <result column="enable" property="enable"/>
         <result column="remark" property="remark"/>

+ 1 - 1
zen-common/src/main/kotlin/com/gxzc/zen/common/base/persistence/BaseMapper.kt → zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseMapper.kt

@@ -1,4 +1,4 @@
-package com.gxzc.zen.common.base.persistence
+package com.gxzc.zen.common.base
 
 import com.baomidou.mybatisplus.mapper.BaseMapper
 

+ 1 - 1
zen-common/src/main/kotlin/com/gxzc/zen/common/base/persistence/BaseModel.kt → zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseModel.kt

@@ -1,4 +1,4 @@
-package com.gxzc.zen.common.base.persistence
+package com.gxzc.zen.common.base
 
 import com.baomidou.mybatisplus.annotations.TableField
 import com.baomidou.mybatisplus.annotations.TableId

+ 1 - 1
zen-common/src/main/kotlin/com/gxzc/zen/common/base/persistence/BaseService.kt → zen-common/src/main/kotlin/com/gxzc/zen/common/base/BaseService.kt

@@ -1,4 +1,4 @@
-package com.gxzc.zen.common.base.persistence
+package com.gxzc.zen.common.base
 
 import com.baomidou.mybatisplus.service.IService
 

+ 0 - 115
zen-config/src/main/kotlin/com/gxzc/zen/config/DruidConfig.kt

@@ -1,115 +0,0 @@
-package com.gxzc.zen.config
-
-import com.alibaba.druid.pool.DruidDataSource
-import com.alibaba.druid.support.http.StatViewServlet
-import com.alibaba.druid.support.http.WebStatFilter
-import org.mybatis.spring.annotation.MapperScan
-import org.slf4j.LoggerFactory
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
-import org.springframework.boot.context.properties.ConfigurationProperties
-import org.springframework.boot.web.servlet.FilterRegistrationBean
-import org.springframework.boot.web.servlet.ServletRegistrationBean
-import org.springframework.context.annotation.Bean
-import org.springframework.context.annotation.Configuration
-import java.sql.SQLException
-import javax.sql.DataSource
-
-
-@Configuration
-@ConfigurationProperties(prefix = "druid.datasource-sys")
-@MapperScan(basePackages = ["com.gxzc.zen.sys"])
-open class SysDruidConfig : DruidConfig()
-
-
-/**
- * druid数据源bean注册
- */
-open class DruidConfig {
-    var url: String? = null
-    var username: String? = null
-    var password: String? = null
-    var filters: String? = null
-
-    var driverClassName: String? = "com.mysql.jdbc.Driver"
-    var initialSize: Int = 5
-    var minIdle: Int = 5
-    var maxActive: Int = 20
-    var maxWait: Long = 60000
-
-    var timeBetweenEvictionRunsMillis: Long = 60000
-    var minEvictableIdleTimeMillis: Long = 30000
-    var validationQuery: String? = null
-    var testWhileIdle: Boolean = true
-    var testOnBorrow: Boolean = false
-    var testOnReturn: Boolean = false
-
-    private val logger = LoggerFactory.getLogger(javaClass)
-
-    private var datasource: DruidDataSource? = null
-
-    @Bean
-    open fun druidDataSource(): DataSource? {
-        datasource = DruidDataSource().also {
-            it.url = url
-            it.username = username
-            it.password = password
-            it.driverClassName = driverClassName
-            it.initialSize = initialSize
-            it.minIdle = minIdle
-            it.maxActive = maxActive
-            it.maxWait = maxWait
-            it.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis
-            it.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis
-            it.validationQuery = validationQuery
-            it.isTestWhileIdle = testWhileIdle
-            it.isTestOnBorrow = testOnBorrow
-            it.isTestOnReturn = testOnReturn
-        }
-        try {
-            datasource?.setFilters(filters)
-        } catch (e: SQLException) {
-            logger.error("druid configuration initialization filter", e)
-        }
-
-        return datasource
-    }
-
-    fun getDatasource(): DruidDataSource? {
-        return datasource
-    }
-}
-
-/**
- * 配置druid显示界面
- */
-@Configuration
-@ConfigurationProperties(prefix = "druid.view")
-@ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
-open class DruidViewConfig {
-    var username: String? = null
-    var password: String? = null
-    var slowSql: String? = null
-
-    @Bean
-    @ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
-    open fun druidServlet(): ServletRegistrationBean {
-        return ServletRegistrationBean().also {
-            it.setServlet(StatViewServlet())
-            it.addUrlMappings("/druid/*")
-            it.addInitParameter("loginUsername", username)
-            it.addInitParameter("loginPassword", password)
-            it.addInitParameter("logSlowSql", slowSql)
-        }
-    }
-
-    @Bean
-    @ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
-    open fun filterRegistrationBean(): FilterRegistrationBean {
-        return FilterRegistrationBean().also {
-            it.filter = WebStatFilter()
-            it.addUrlPatterns("/*")
-            it.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")
-            it.addInitParameter("profileEnable", "true")
-        }
-    }
-}

+ 1 - 0
zen-orm/build.gradle

@@ -2,4 +2,5 @@ dependencies {
     compile project(":zen-common")
     compile project(":zen-config")
     compile project(":zen-log")
+    compile project(":zen-api")
 }

+ 14 - 15
zen-orm/src/main/kotlin/com/gxzc/zen/Generator.kt

@@ -1,15 +1,11 @@
 package com.gxzc.zen
 
 import com.baomidou.mybatisplus.generator.AutoGenerator
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig
-import com.baomidou.mybatisplus.generator.config.GlobalConfig
-import com.baomidou.mybatisplus.generator.config.ITypeConvert
-import com.baomidou.mybatisplus.generator.config.PackageConfig
-import com.baomidou.mybatisplus.generator.config.StrategyConfig
+import com.baomidou.mybatisplus.generator.config.*
+import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert
 import com.baomidou.mybatisplus.generator.config.rules.DbColumnType
 import com.baomidou.mybatisplus.generator.config.rules.DbType
 import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
-import com.gxzc.zen.persistence.BaseModel
 import java.io.File
 
 /**
@@ -45,15 +41,18 @@ fun main(args: Array<String>) {
     val dataSource = DataSourceConfig()
     with(dataSource) {
         dbType = DbType.MYSQL
-//        typeConvert = object: ITypeConvert {
+//        typeConvert = object :MySqlTypeConvert(){
 //            override fun processTypeConvert(fieldType: String?): DbColumnType {
-//
+//                if(fieldType == "tinyint"){
+//                    return DbColumnType.BOOLEAN
+//                }
+//                return super.processTypeConvert(fieldType)
 //            }
 //        }
         driverName = "com.mysql.jdbc.Driver"
-        username = "archives"
-        password = "archives"
-        url = "jdbc:mysql://192.168.1.124:3307/archives_sys?characterEncoding=utf8"
+        username = "root"
+        password = "root"
+        url = "jdbc:mysql://127.0.0.1:3306/archives_rec?characterEncoding=utf8"
     }
     mpg.dataSource = dataSource
 
@@ -64,10 +63,10 @@ fun main(args: Array<String>) {
         isCapitalMode = false
         naming = NamingStrategy.underline_to_camel
         //            setTablePrefix()
-        superEntityClass = "com.gxzc.zen.persistence.BaseModel"
+        superEntityClass = "com.gxzc.zen.common.base.BaseModel"
         setSuperEntityColumns("id", "create_by", "create_time", "update_by", "update_time", "remark", "enable")
-        superMapperClass = "com.gxzc.zen.persistence.BaseMapper"
-        superServiceClass = "com.gxzc.zen.persistence.BaseService"
+        superMapperClass = "com.gxzc.zen.common.base.BaseMapper"
+        superServiceClass = "com.gxzc.zen.common.base.BaseService"
         superServiceImplClass = "com.baomidou.mybatisplus.service.impl.ServiceImpl"
 //            superControllerClass = ""
 //        setInclude("user")
@@ -80,7 +79,7 @@ fun main(args: Array<String>) {
     // 包配置
     val pc = PackageConfig()
     with(pc) {
-        parent = "com.gxzc.zen.sys.persistence"
+        parent = "com.gxzc.zen.api.rec"
 //        moduleName = "zen-orm"
         entity = "model"
     }

+ 121 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/DruidConfig.kt

@@ -0,0 +1,121 @@
+//package com.gxzc.zen.orm
+//
+///**
+// *
+// * @author NorthLan at 2018/1/27
+// */
+//import com.alibaba.druid.pool.DruidDataSource
+//import com.alibaba.druid.support.http.StatViewServlet
+//import com.alibaba.druid.support.http.WebStatFilter
+//import org.mybatis.spring.annotation.MapperScan
+//import org.slf4j.LoggerFactory
+//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+//import org.springframework.boot.context.properties.ConfigurationProperties
+//import org.springframework.boot.web.servlet.FilterRegistrationBean
+//import org.springframework.boot.web.servlet.ServletRegistrationBean
+//import org.springframework.context.annotation.Bean
+//import org.springframework.context.annotation.Configuration
+//import java.sql.SQLException
+//import javax.sql.DataSource
+//
+//
+//@Configuration
+//@ConfigurationProperties(prefix = "druid.datasource.sys")
+//@MapperScan(basePackages = ["com.gxzc.zen.api.sys.mapper"])
+//class SysDruidConfig : DruidConfig()
+//
+//
+////@Configuration
+////@ConfigurationProperties(prefix = "druid.datasource.rec")
+////@MapperScan(basePackages = ["com.gxzc.zen.api.rec.mapper"])
+////class RecDruidConfig : DruidConfig()
+///**
+// * druid数据源bean注册
+// */
+//open class DruidConfig {
+//    var url: String? = null
+//    var username: String? = null
+//    var password: String? = null
+//    var filters: String? = null
+//
+//    var driverClassName: String? = "com.mysql.jdbc.Driver"
+//    var initialSize: Int = 5
+//    var minIdle: Int = 5
+//    var maxActive: Int = 20
+//    var maxWait: Long = 60000
+//
+//    var timeBetweenEvictionRunsMillis: Long = 60000
+//    var minEvictableIdleTimeMillis: Long = 30000
+//    var validationQuery: String? = null
+//    var testWhileIdle: Boolean = true
+//    var testOnBorrow: Boolean = false
+//    var testOnReturn: Boolean = false
+//
+//    private val logger = LoggerFactory.getLogger(javaClass)
+//
+//    private var datasource: DruidDataSource? = null
+//
+//    @Bean
+//    open fun druidDataSource(): DataSource? {
+//        datasource = DruidDataSource().also {
+//            it.url = url
+//            it.username = username
+//            it.password = password
+//            it.driverClassName = driverClassName
+//            it.initialSize = initialSize
+//            it.minIdle = minIdle
+//            it.maxActive = maxActive
+//            it.maxWait = maxWait
+//            it.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis
+//            it.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis
+//            it.validationQuery = validationQuery
+//            it.isTestWhileIdle = testWhileIdle
+//            it.isTestOnBorrow = testOnBorrow
+//            it.isTestOnReturn = testOnReturn
+//        }
+//        try {
+//            datasource?.setFilters(filters)
+//        } catch (e: SQLException) {
+//            logger.error("druid configuration initialization filter", e)
+//        }
+//
+//        return datasource
+//    }
+//
+//    fun getDatasource(): DruidDataSource? {
+//        return datasource
+//    }
+//}
+//
+///**
+// * 配置druid显示界面
+// */
+//@Configuration
+//@ConfigurationProperties(prefix = "druid.view")
+//@ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
+//open class DruidViewConfig {
+//    var username: String? = null
+//    var password: String? = null
+//    var slowSql: String? = null
+//
+//    @Bean
+//    open fun druidServlet(): ServletRegistrationBean {
+//        return ServletRegistrationBean().also {
+//            it.setServlet(StatViewServlet())
+//            it.addUrlMappings("/druid/*")
+//            it.addInitParameter("loginUsername", username)
+//            it.addInitParameter("loginPassword", password)
+//            it.addInitParameter("logSlowSql", slowSql)
+//        }
+//    }
+//
+//    @Bean
+//    open fun filterRegistrationBean(): FilterRegistrationBean {
+//        return FilterRegistrationBean().also {
+//            it.filter = WebStatFilter()
+//            it.addUrlPatterns("/*")
+//            it.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")
+//            it.addInitParameter("profileEnable", "true")
+//        }
+//    }
+//}

+ 46 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/DruidViewConfig.kt

@@ -0,0 +1,46 @@
+package com.gxzc.zen.orm
+
+import com.alibaba.druid.support.http.StatViewServlet
+import com.alibaba.druid.support.http.WebStatFilter
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.boot.context.properties.ConfigurationProperties
+import org.springframework.boot.web.servlet.FilterRegistrationBean
+import org.springframework.boot.web.servlet.ServletRegistrationBean
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+
+/**
+ *
+ * @author NorthLan at 2018/1/26
+ */
+@Configuration
+@ConfigurationProperties(prefix = "druid.view")
+@ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
+class DruidViewConfig {
+    var username: String? = null
+    var password: String? = null
+    var slowSql: String? = null
+
+    @Bean
+//    @ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
+    fun druidServlet(): ServletRegistrationBean {
+        return ServletRegistrationBean().also {
+            it.setServlet(StatViewServlet())
+            it.addUrlMappings("/druid/*")
+            it.addInitParameter("loginUsername", username)
+            it.addInitParameter("loginPassword", password)
+            it.addInitParameter("logSlowSql", slowSql)
+        }
+    }
+
+    @Bean
+//    @ConditionalOnProperty(prefix = "druid.view", name = ["enable"], havingValue = "true", matchIfMissing = true)
+    fun filterRegistrationBean(): FilterRegistrationBean {
+        return FilterRegistrationBean().also {
+            it.filter = WebStatFilter()
+            it.addUrlPatterns("/*")
+            it.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")
+            it.addInitParameter("profileEnable", "true")
+        }
+    }
+}

+ 66 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/RecDataSourceConfig.kt

@@ -0,0 +1,66 @@
+package com.gxzc.zen.orm
+
+import com.alibaba.druid.pool.DruidDataSource
+import com.gxzc.zen.orm.base.BaseDataSourceProperties
+import org.apache.ibatis.session.SqlSessionFactory
+import org.mybatis.spring.SqlSessionFactoryBean
+import org.mybatis.spring.SqlSessionTemplate
+import org.mybatis.spring.annotation.MapperScan
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Qualifier
+import org.springframework.boot.context.properties.ConfigurationProperties
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver
+import org.springframework.jdbc.datasource.DataSourceTransactionManager
+import javax.sql.DataSource
+
+/**
+ * Sys 数据源配置<br>
+ * 扫描路径为 com.gxzc.zen.*.sys
+ * @author NorthLan at 2018/1/26
+ */
+@Configuration
+@MapperScan(basePackages = ["com.gxzc.zen.api.rec.mapper"])
+class RecDataSourceConfig {
+    companion object {
+        const val DATASOURCE_NAME: String = "recDataSource"
+        const val TRANSACTION_MANAGER_NAME: String = "recTransactionManager"
+        const val SQL_SESSION_FACTORY_NAME: String = "recSqlSessionFactory"
+        const val SQL_SESSION_TEMPLATE_NAME: String = "recSqlSessionTemplate"
+        val logger: Logger = LoggerFactory.getLogger(RecDataSourceConfig::class.java)
+    }
+
+    @Bean(name = ["recDataSourceProperties"])
+    @ConfigurationProperties(prefix = "druid.datasource.rec")
+    fun properties(): BaseDataSourceProperties {
+        return BaseDataSourceProperties()
+    }
+
+    @Bean(DATASOURCE_NAME)
+    @ConfigurationProperties(prefix = "druid.datasource.rec")
+    fun dataSource(@Qualifier("recDataSourceProperties") properties: BaseDataSourceProperties): DataSource {
+        return DruidDataSource()
+    }
+
+    @Bean(TRANSACTION_MANAGER_NAME)
+    fun transactionManager(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): DataSourceTransactionManager {
+        return DataSourceTransactionManager(dataSource)
+    }
+
+//    @Bean(SQL_SESSION_FACTORY_NAME)
+//    fun sqlSessionFactory(@Qualifier(DATASOURCE_NAME) dataSource: DataSource, @Qualifier("recDataSourceProperties") properties: BaseDataSourceProperties): SqlSessionFactory {
+//        return SqlSessionFactoryBean().let {
+//            it.setDataSource(dataSource)
+//            it.setMapperLocations(PathMatchingResourcePatternResolver().getResources(properties.mapperLocation))
+//            it.`object`
+//        }
+//    }
+//
+//    @Bean(SQL_SESSION_TEMPLATE_NAME)
+////    @Order(-1)
+//    fun sqlSessionTemplate(@Qualifier(SQL_SESSION_FACTORY_NAME) sqlSessionFactory: SqlSessionFactory): SqlSessionTemplate {
+//        return SqlSessionTemplate(sqlSessionFactory)
+//    }
+}

+ 71 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/SysDataSourceConfig.kt

@@ -0,0 +1,71 @@
+package com.gxzc.zen.orm
+
+import com.alibaba.druid.pool.DruidDataSource
+import com.gxzc.zen.orm.base.BaseDataSourceProperties
+import org.apache.ibatis.session.SqlSessionFactory
+import org.mybatis.spring.SqlSessionFactoryBean
+import org.mybatis.spring.SqlSessionTemplate
+import org.mybatis.spring.annotation.MapperScan
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Qualifier
+import org.springframework.boot.context.properties.ConfigurationProperties
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.context.annotation.Primary
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver
+import org.springframework.jdbc.datasource.DataSourceTransactionManager
+import javax.sql.DataSource
+
+/**
+ * Sys 数据源配置<br>
+ * 扫描路径为 com.gxzc.zen.*.sys
+ * @author NorthLan at 2018/1/26
+ */
+@Configuration
+@MapperScan(basePackages = ["com.gxzc.zen.api.sys.mapper"])
+class SysDataSourceConfig {
+    companion object {
+        const val DATASOURCE_NAME: String = "sysDataSource"
+        const val TRANSACTION_MANAGER_NAME: String = "sysTransactionManager"
+        const val SQL_SESSION_FACTORY_NAME: String = "sysSqlSessionFactory"
+        const val SQL_SESSION_TEMPLATE_NAME: String = "sysSqlSessionTemplate"
+        val logger: Logger = LoggerFactory.getLogger(SysDataSourceConfig::class.java)
+    }
+
+    @Bean(name = ["sysDataSourceProperties"])
+    @ConfigurationProperties(prefix = "druid.datasource.sys")
+    @Primary
+    fun properties(): BaseDataSourceProperties {
+        return BaseDataSourceProperties()
+    }
+
+    @Bean(DATASOURCE_NAME)
+    @ConfigurationProperties(prefix = "druid.datasource.sys")
+    @Primary
+    fun dataSource(@Qualifier("sysDataSourceProperties") properties: BaseDataSourceProperties): DataSource {
+        return DruidDataSource()
+    }
+
+    @Bean(TRANSACTION_MANAGER_NAME)
+    @Primary
+    fun transactionManager(@Qualifier(DATASOURCE_NAME) dataSource: DataSource): DataSourceTransactionManager {
+        return DataSourceTransactionManager(dataSource)
+    }
+
+//    @Bean(SQL_SESSION_FACTORY_NAME)
+//    @Primary
+//    fun sqlSessionFactory(@Qualifier(DATASOURCE_NAME) dataSource: DataSource, @Qualifier("sysDataSourceProperties") properties: BaseDataSourceProperties): SqlSessionFactory {
+//        return SqlSessionFactoryBean().let {
+//            it.setDataSource(dataSource)
+//            it.setMapperLocations(PathMatchingResourcePatternResolver().getResources(properties.mapperLocation))
+//            it.`object`
+//        }
+//    }
+//
+//    @Bean(SQL_SESSION_TEMPLATE_NAME)
+//    @Primary
+//    fun sqlSessionTemplate(@Qualifier(SQL_SESSION_FACTORY_NAME) sqlSessionFactory: SqlSessionFactory): SqlSessionTemplate {
+//        return SqlSessionTemplate(sqlSessionFactory)
+//    }
+}

+ 23 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/base/BaseDataSourceProperties.kt

@@ -0,0 +1,23 @@
+package com.gxzc.zen.orm.base
+
+import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
+
+/**
+ * 数据源配置基类
+ * @author NorthLan at 2018/1/27
+ */
+open class BaseDataSourceProperties : DataSourceProperties() {
+    var prefix: String = "datasource"
+    var mapperLocation: String = ""
+    var initialSize: Int = 5
+    var minIdle: Int = 5
+    var maxActive: Int = 20
+    var maxWait: Long = 60000
+
+    var timeBetweenEvictionRunsMillis: Long = 60000
+    var minEvictableIdleTimeMillis: Long = 30000
+    var validationQuery: String? = null
+    var testWhileIdle: Boolean = true
+    var testOnBorrow: Boolean = false
+    var testOnReturn: Boolean = false
+}

+ 51 - 0
zen-orm/src/main/resources/application-orm.yml

@@ -0,0 +1,51 @@
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+
+druid:
+  view:
+    enable: true
+    username: root
+    password: root
+    slowSql: true
+  datasource:
+    sys:
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.jdbc.Driver
+      initialize: false #指定初始化数据源,是否用data.sql来初始化,默认: true
+      mapper-location: classpath:mapping/sys/*.xml
+      name: archives_sys
+      prefix: sys
+      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
+      username: root
+      password: root
+      filters: log4j,wall,mergeStat
+      initialSize: 5
+      minIdle: 5
+      maxActive: 20
+      timeBetweenEvictionRunsMillis: 60000
+      minEvictableIdleTimeMillis: 30000
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+    rec:
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.jdbc.Driver
+      initialize: false #指定初始化数据源,是否用data.sql来初始化,默认: true
+      mapper-location: classpath:mapping/rec/*.xml
+      name: archives_rec
+      prefix: rec
+      url: jdbc:mysql://127.0.0.1:3306/archives_rec?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
+      username: root
+      password: root
+      filters: log4j,wall,mergeStat
+      initialSize: 5
+      minIdle: 5
+      maxActive: 20
+      timeBetweenEvictionRunsMillis: 60000
+      minEvictableIdleTimeMillis: 30000
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false