道路线索应急巡查系统服务后台
feiyu02
2025-09-30 84569abda51ecf6c5549dec4cadee8d043422379
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
28
29
30
31
32
33
34
35
package com.flightfeather.grid.web
 
import com.flightfeather.grid.config.exception.BizException
import com.flightfeather.grid.vo.BaseResponse
import com.flightfeather.grid.vo.DataHead
import com.github.pagehelper.Page
 
 
/**
 * 包装接口返回结果
 */
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 ?: "")
    }
}
 
/**
 * 包装带有分页的返回结果
 */
fun <T> responsePack(p: Page<T>): Pair<DataHead, List<T?>> {
    return DataHead(p.pageNum, p.pages, p.total) to p.result
}