From aed297a5fbc8df9dab01b28da21f872ee546b43c Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期一, 13 十月 2025 16:15:11 +0800
Subject: [PATCH] 2025.10.13 1. 统一调整controller层的返回类型,通过添加全局响应增强器GlobalResponseAdvice来管理返回结果; 2. 新增mybatis-generator自定义插件,实现给数据库实体entity自动添加swagger注解@ApiModel和@ApiModelProperty

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt
index cd80b71..7672db8 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt
@@ -14,12 +14,16 @@
 data class BaseResponse<T>(
     @ApiModelProperty("璇锋眰鏄惁鎴愬姛")
     var success: Boolean,
+    @ApiModelProperty("璇锋眰杩斿洖鐘舵�佺爜")
+    var code: String = "200",
     @ApiModelProperty("璇锋眰杩斿洖娑堟伅")
     var message: String = "",
+    @ApiModelProperty("璇锋眰杩斿洖鏁版嵁澶�")
     val head: DataHead? = null,
     @ApiModelProperty("璇锋眰杩斿洖鏁版嵁")
     val data: T? = null,
-    var stackTrace: String = ""
+    @ApiModelProperty("璇锋眰杩斿洖寮傚父鏍堜俊鎭�")
+    var stackTrace: String = "",
 ) {
     init {
         if (message.isBlank()) {
@@ -30,4 +34,27 @@
             }
         }
     }
+
+    companion object {
+        fun success(res: Any?): BaseResponse<Any> {
+            return if (res is Pair<*, *>) {
+                val head = res.first
+                if (head is DataHead) {
+                    BaseResponse(true, head = head, data = res.second)
+                } else {
+                    BaseResponse(true, data = res)
+                }
+            } else {
+                BaseResponse(true, data = res)
+            }
+        }
+
+        fun <T> fail(code: String = "500", message: String = "璇锋眰澶辫触"): BaseResponse<T> {
+            return BaseResponse(false, code, message)
+        }
+
+        fun <T> fail(code: String = "500", e: Exception): BaseResponse<T> {
+            return BaseResponse(false, code, e.message ?: "", stackTrace = e.stackTraceToString())
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3