Browse Source

修复多数据源/全局自动注入 情况下数据源切换失败的问题

NorthLan 7 years ago
parent
commit
631b604e86

+ 4 - 0
zen-orm/src/main/kotlin/com/gxzc/zen/orm/DynamicMultipleDataSource.kt

@@ -24,6 +24,10 @@ class DynamicMultipleDataSource : AbstractRoutingDataSource() {
             DATA_SOURCE_KEY.set(key)
         }
 
+        fun getDataSource(): String {
+            return DATA_SOURCE_KEY.get()
+        }
+
         fun clear() {
             DATA_SOURCE_KEY.remove()
         }

+ 4 - 0
zen-web/src/main/kotlin/com/gxzc/zen/orm/CustomMetaObjectHandler.kt

@@ -20,6 +20,7 @@ class CustomMetaObjectHandler : MetaObjectHandler() {
     }
 
     override fun insertFill(metaObject: MetaObject?) {
+        val temp = DynamicMultipleDataSource.getDataSource()
         logger.debug("公共字段自动填充: insertFill ${SSOUtil.getCurUser()?.account}")
         if (getFieldValByName("createBy", metaObject) == null) {
             setFieldValByName("createBy", SSOUtil.getCurUser()?.account, metaObject)
@@ -27,13 +28,16 @@ class CustomMetaObjectHandler : MetaObjectHandler() {
         if (getFieldValByName("createTime", metaObject) == null) {
             setFieldValByName("createTime", Date(), metaObject)
         }
+        DynamicMultipleDataSource.setDataSource(temp)
     }
 
     override fun updateFill(metaObject: MetaObject?) {
+        val temp = DynamicMultipleDataSource.getDataSource()
         logger.debug("公共字段自动填充: updateFill ${SSOUtil.getCurUser()?.account}")
         if (getFieldValByName("updateBy", metaObject) == null) {
             setFieldValByName("updateBy", SSOUtil.getCurUser()?.account, metaObject)
         }
         setFieldValByName("updateTime", Date(), metaObject)
+        DynamicMultipleDataSource.setDataSource(temp)
     }
 }

+ 16 - 0
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/DeptController.kt

@@ -0,0 +1,16 @@
+package com.gxzc.zen.web.sys.controller
+
+import com.gxzc.zen.common.base.BaseController
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+
+/**
+ * 部门 控制器
+ * @author NorthLan
+ * @date 2018/3/24
+ * @url https://noahlan.com
+ */
+@RestController
+@RequestMapping("dept")
+class DeptController : BaseController() {
+}

+ 27 - 0
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/RoleController.kt

@@ -0,0 +1,27 @@
+package com.gxzc.zen.web.sys.controller
+
+import com.gxzc.zen.common.base.BaseController
+import org.slf4j.LoggerFactory
+import org.springframework.http.ResponseEntity
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+
+/**
+ * 角色 控制器
+ * @author NorthLan
+ * @date 2018/3/24
+ * @url https://noahlan.com
+ */
+@RestController
+@RequestMapping("role")
+class RoleController : BaseController() {
+    companion object {
+        private val logger = LoggerFactory.getLogger(RoleController::class.java)
+    }
+
+    @GetMapping("list")
+    fun list(): ResponseEntity<*> {
+        return ResponseEntity.ok(null)
+    }
+}