Browse Source

修改平台id获取方式,自捕获异常返回0

NorthLan 6 years ago
parent
commit
e9a174f380
1 changed files with 15 additions and 8 deletions
  1. 15 8
      zen-core/src/main/kotlin/com/gxzc/zen/common/util/PlatformUtil.kt

+ 15 - 8
zen-core/src/main/kotlin/com/gxzc/zen/common/util/PlatformUtil.kt

@@ -2,6 +2,7 @@ package com.gxzc.zen.common.util
 
 import com.gxzc.zen.common.contants.PLATFORM
 import com.gxzc.zen.common.properties.PlatformProperties
+import org.slf4j.LoggerFactory
 
 /**
  * 平台工具类
@@ -10,13 +11,23 @@ import com.gxzc.zen.common.properties.PlatformProperties
  * @url https://noahlan.com
  */
 object PlatformUtil {
-    private var properties = SpringContextHolder.getBean(PlatformProperties::class.java)
+    private val logger = LoggerFactory.getLogger(PlatformUtil::class.java)
+
+    var properties: PlatformProperties? = null
+        get() {
+            if (field == null) {
+                field = SpringContextHolder.getBean(PlatformProperties::class.java)
+            }
+            return field
+        }
 
     fun getPlatformId(): Int {
-        if (properties == null) {
-            properties = SpringContextHolder.getBean(PlatformProperties::class.java)
+        return try {
+            properties!!.id!!
+        } catch (e: Throwable) {
+            logger.warn("error get platform properties, cause", e)
+            0
         }
-        return properties!!.id!!
     }
 
     fun getPlatform(id: Int): PLATFORM {
@@ -30,8 +41,4 @@ object PlatformUtil {
     fun getPlatform(properties: PlatformProperties): PLATFORM {
         return getPlatform(properties.id!!)
     }
-
-    fun getProperties(): PlatformProperties? {
-        return properties
-    }
 }