feiyu02
2025-03-27 bde043c8fd1a076f44c402dd56c62d401afbfb16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.flightfeather.uav.lightshare.web
 
import com.flightfeather.uav.common.exception.BizException
import com.flightfeather.uav.lightshare.bean.BaseResponse
import com.flightfeather.uav.lightshare.bean.DataHead
 
 
/**
 * 包装接口返回结果
 */
fun resPack(service: () -> Any?): BaseResponse<Any> {
    return try {
        val res = service()
        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)
        }
    } catch (e: BizException) {
        BaseResponse(false, message = e.message ?: "")
    }
}