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
|
}
|