NorthLan 7 жил өмнө
parent
commit
44cec30d1a

+ 5 - 5
zen-admin/src/main/kotlin/com/gxzc/zen/ExampleController.kt

@@ -12,14 +12,14 @@ import org.springframework.web.bind.annotation.RestController
 class ExampleController {
 
     @Autowired
-    private val service: TestService?=null
+    private val service: TestService? = null
 
     @RequestMapping("/")
-    fun home(model:Model): String {
+    fun home(model: Model): String {
 //        val one=service?.findOne(1)
-        val list=service?.findList(mapOf())
-        val html="size:"+list?.size
-        return "Hello World!"+html
+        val list = service?.findList(mapOf())
+        val html = "size:" + list?.size
+        return "Hello World!" + html
     }
 
     @RequestMapping("/hello/{myName}")

+ 1 - 1
zen-admin/src/main/kotlin/com/gxzc/zen/MainApplication.kt

@@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
 
 
 @SpringBootApplication
-class MainApplication
+open class MainApplication
 
 fun main(args:Array<String>){
     SpringApplication.run(MainApplication::class.java, *args)

+ 2 - 2
zen-admin/src/main/resources/application.yml

@@ -6,10 +6,10 @@ server:
 ###################  druid配置  ###################
 druid:
   view:
-#    enable: false无效
+    enable: false
     username: root
     password: 123456
-    slowsql: true
+    slowSql: true
   datasource-sys:
     url: jdbc:mysql://127.0.0.1:3306/zen-sys?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
     username: root

+ 1 - 1
zen-api/src/main/kotlin/com/gxzc/zen/sys/dao/TSysUserMapper.kt

@@ -1,6 +1,6 @@
 package com.gxzc.zen.sys.dao
 
-import com.gxzc.zen.persistence.ZenBaseMapper
+import com.gxzc.zen.common.base.persistence.ZenBaseMapper
 import com.gxzc.zen.sys.model.TSysUser
 import org.springframework.stereotype.Repository
 

+ 2 - 2
zen-api/src/main/kotlin/com/gxzc/zen/sys/model/TSysUser.kt

@@ -1,9 +1,9 @@
 package com.gxzc.zen.sys.model
 
-import com.gxzc.zen.persistence.ZenBaseModel
+import com.gxzc.zen.common.base.persistence.ZenBaseModel
 import java.util.*
 
-class TSysUser:ZenBaseModel(){
+class TSysUser: ZenBaseModel(){
     var account:String?=null
     var password:String?=null
     var userType:Date?=null

+ 2 - 2
zen-api/src/main/kotlin/com/gxzc/zen/sys/service/TSysUserService.kt

@@ -1,9 +1,9 @@
 package com.gxzc.zen.sys.service
 
-import com.gxzc.zen.persistence.ZenBaseService
+import com.gxzc.zen.common.base.persistence.ZenBaseService
 import com.gxzc.zen.sys.dao.TSysUserMapper
 import com.gxzc.zen.sys.model.TSysUser
 import org.springframework.stereotype.Service
 
 @Service
-class TSysUserService:ZenBaseService<TSysUser, TSysUserMapper>()
+class TSysUserService: ZenBaseService<TSysUser, TSysUserMapper>()

+ 1 - 1
zen-common/src/main/java/com/gxzc/zen/plug/Encodes.java → zen-common/src/main/java/com/gxzc/zen/common/plug/Encodes.java

@@ -1,7 +1,7 @@
 /**
  * Copyright (c) 2005-2012 springside.org.cn
  */
-package com.gxzc.zen.plug;
+package com.gxzc.zen.common.plug;
 
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Base64;

+ 1 - 1
zen-common/src/main/java/com/gxzc/zen/plug/IdGen.java → zen-common/src/main/java/com/gxzc/zen/common/plug/IdGen.java

@@ -1,7 +1,7 @@
 /**
  * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
  */
-package com.gxzc.zen.plug;
+package com.gxzc.zen.common.plug;
 
 import java.security.SecureRandom;
 import java.util.UUID;

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

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

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

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

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

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

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

@@ -1,4 +1,4 @@
-package com.gxzc.zen.persistence
+package com.gxzc.zen.common.base.persistence
 
 import com.baomidou.mybatisplus.mapper.BaseMapper
 import org.apache.ibatis.annotations.Param

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

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

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

@@ -1,4 +1,4 @@
-package com.gxzc.zen.persistence
+package com.gxzc.zen.common.base.persistence
 
 import com.baomidou.kisso.SSOHelper
 import com.baomidou.kisso.security.token.SSOToken

+ 67 - 68
zen-config/src/main/kotlin/com/gxzc/zen/config/DruidConfig.kt

@@ -5,6 +5,7 @@ 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
@@ -17,100 +18,98 @@ import javax.sql.DataSource
 @Configuration
 @ConfigurationProperties(prefix = "druid.datasource-sys")
 @MapperScan(basePackages = ["com.gxzc.zen.sys"])
-class SysDruidConfig:DruidConfig()
+open class SysDruidConfig : DruidConfig()
 
 
-
-
-
-/*-----------------druid数据源bean注册 */
+/**
+ * druid数据源bean注册
+ */
 open class DruidConfig {
-    var url:String?=null
-    var username:String?=null
-    var password:String?=null
-    var filters:String?=null
+    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 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?=null
-    var minEvictableIdleTimeMillis:Long?=null
-    var validationQuery:String?=null
-    var testWhileIdle:Boolean?=null
-    var testOnBorrow:Boolean?=null
-    var testOnReturn:Boolean?=null
+    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 val logger = LoggerFactory.getLogger(javaClass)
 
-    private var datasource:DruidDataSource?=null
-
-//    private val name=nm
+    private var datasource: DruidDataSource? = null
 
     @Bean
-    open fun druidDataSource(): DataSource {
-        datasource = DruidDataSource()
-        datasource?.url = url
-        datasource?.username = username
-        datasource?.password = password
-        datasource?.driverClassName = driverClassName
-        datasource?.initialSize = initialSize!!
-        datasource?.minIdle = minIdle!!
-        datasource?.maxActive = maxActive!!
-        datasource?.maxWait = maxWait!!
-        datasource?.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis!!
-        datasource?.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis!!
-        datasource?.validationQuery = validationQuery!!
-        datasource?.isTestWhileIdle = testWhileIdle!!
-        datasource?.isTestOnBorrow = testOnBorrow!!
-        datasource?.isTestOnReturn = testOnReturn!!
+    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!!
+        return datasource
     }
 
-    fun getDatasource():DruidDataSource{
-        return datasource!!
+    fun getDatasource(): DruidDataSource? {
+        return datasource
     }
 }
 
-
-
-
-/*-----------------配置druid显示界面 */
+/**
+ * 配置druid显示界面
+ */
 @Configuration
 @ConfigurationProperties(prefix = "druid.view")
-class DruidViewConfig{
-    var username:String?=null
-    var password:String?=null
-    var slowsql:String?=null
+@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
-    fun druidServlet(): ServletRegistrationBean {
-//        if(!enable!!)return throw Exception()
-        val reg = ServletRegistrationBean()
-        reg.setServlet(StatViewServlet())
-        reg.addUrlMappings("/druid/*")
-        reg.addInitParameter("loginUsername", username)
-        reg.addInitParameter("loginPassword", password)
-        reg.addInitParameter("logSlowSql", slowsql)
-        return reg
+    @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
-    fun filterRegistrationBean(): FilterRegistrationBean {
-//        if(!enable!!)return throw Exception()
-        val filterRegistrationBean = FilterRegistrationBean()
-        filterRegistrationBean.filter = WebStatFilter()
-        filterRegistrationBean.addUrlPatterns("/*")
-        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")
-        filterRegistrationBean.addInitParameter("profileEnable", "true")
-        return filterRegistrationBean
+    @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")
+        }
     }
 }

+ 65 - 55
zen-orm/src/main/kotlin/com/gxzc/zen/Generator.kt

@@ -14,67 +14,77 @@ import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
  * @date 2018/1/24
  * @url https://noahlan.me
  */
-fun main(args: Array<String>) {
-    val mpg = AutoGenerator()
+class Generator{
+    fun main(args: Array<String>) {
+        val mpg = AutoGenerator()
 
-    // 全局配置
-    val gc = GlobalConfig()
-    with(gc) {
-        outputDir = "D://Test"
-        isFileOverride = true
-        isActiveRecord = false
-        isEnableCache = false
-        isOpen = true
-        author = "NorthLan"
-        isKotlin = true
-        isBaseResultMap = true
-        mapperName = "%sDao"
-        xmlName = "%sDao"
-        serviceName = "I%sService"
-        serviceImplName = "%sServiceImpl"
-    }
-    mpg.globalConfig = gc
+        // 全局配置
+        val gc = GlobalConfig()
+        with(gc) {
+            outputDir = "D://Test" // 输出根目录
+            isFileOverride = true // 覆盖
+            isActiveRecord = false // ActiveRecord (不适用)
+            isOpen = true // 打开输出目录
+            author = "NorthLan" // 作者
+            isKotlin = true // 生成kotlin代码
 
-    // 数据源
-    val dataSource = DataSourceConfig()
-    with(dataSource) {
-        dbType = DbType.MYSQL
-        // typeConvert
-        driverName = "com.mysql.jdbc.Driver"
-        username = "root"
-        password = "root"
-        url = "jdbc:mysql://127.0.0.1:3306/rest?characterEncoding=utf8"
-    }
-    mpg.dataSource = dataSource
+            isEnableCache = false // xml二级缓存配置
+            isBaseResultMap = true // xml BaseResultMap
+            isBaseColumnList = false // xml ColumnList
+            mapperName = "%sMapper" // Mapper命名
+            xmlName = "%sMapper" // xml名
+            serviceName = "I%sService" // service名
+            serviceImplName = "%sServiceImpl" // service实现类名
+        }
+        mpg.globalConfig = gc
 
-    // 策略配置
-    val strategy = StrategyConfig()
-    with(strategy) {
-        setDbColumnUnderline(true)
-        isCapitalMode = false
-        naming = NamingStrategy.underline_to_camel
-        //            setTablePrefix()
-        superEntityClass = "com.gxzc.zen.persistence.BaseModel"
-        setSuperEntityColumns("id", "createBy", "createTime", "updateBy", "updateTime", "remark", "enable")
-        superMapperClass = "com.gxzc.zen.persistence.BaseMapper"
-        superServiceClass = "com.gxzc.zen.persistence.BaseService"
-        superServiceImplClass = "com.baomidou.mybatisplus.service.impl.ServiceImpl"
+        // 数据源
+        val dataSource = DataSourceConfig()
+        with(dataSource) {
+            dbType = DbType.MYSQL
+            // typeConvert
+            driverName = "com.mysql.jdbc.Driver"
+            username = "root"
+            password = "root"
+            url = "jdbc:mysql://127.0.0.1:3306/rest?characterEncoding=utf8"
+        }
+        mpg.dataSource = dataSource
+
+        // 策略配置
+        val strategy = StrategyConfig()
+        with(strategy) {
+            setDbColumnUnderline(true)
+            isCapitalMode = false
+            naming = NamingStrategy.underline_to_camel
+            //            setTablePrefix()
+            superEntityClass = "com.gxzc.zen.persistence.BaseModel"
+            setSuperEntityColumns("id", "createBy", "createTime", "updateBy", "updateTime", "remark", "enable")
+            superMapperClass = "com.gxzc.zen.persistence.BaseMapper"
+            superServiceClass = "com.gxzc.zen.persistence.BaseService"
+            superServiceImplClass = "com.baomidou.mybatisplus.service.impl.ServiceImpl"
 //            superControllerClass = ""
-        setInclude("user")
-        isEntityBooleanColumnRemoveIsPrefix = true
-        logicDeleteFieldName = "enable"
+            isEntityBooleanColumnRemoveIsPrefix = true
+            logicDeleteFieldName = "enable"
 //            setExclude("")
-    }
-    mpg.strategy = strategy
+            setInclude("user")
+        }
+        mpg.strategy = strategy
 
-    // 包配置
-    val pc = PackageConfig()
-    with(pc) {
-        parent = "com.gxzc.zen.persistence"
+        // 包配置
+        val pc = PackageConfig()
+        with(pc) {
+            parent = "com.gxzc.zen.persistence"
 //            moduleName = "test"
-        entity = "model"
-    }
-    mpg.packageInfo = pc
+            entity = "model"
+            mapper = "mapper"
+            service = "service"
+            serviceImpl = "service.impl"
+            controller = "controller"
+        }
+        mpg.packageInfo = pc
+
+        mpg.cfg
 
-    mpg.execute()
+        mpg.execute()
+    }
 }

+ 9 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/GeneratorMain.kt

@@ -0,0 +1,9 @@
+package com.gxzc.zen
+
+/**
+ * 代码生成器入口方法
+ * @author NorthLan at 2018/1/25
+ */
+fun main(args: Array<String>) {
+
+}