重构Gaea服务, 升级版本
This commit is contained in:
@@ -6,10 +6,14 @@ import java.util.*
|
||||
*
|
||||
* 用来统一Http返回消息类型,通常使用json格式传递
|
||||
*
|
||||
* @param status http编码。200成功,400错误,500异常
|
||||
* @tparam T 消息数据类型
|
||||
*/
|
||||
open class Message<T>(var status: Int = Status.Success) {
|
||||
open class Message<T>() {
|
||||
|
||||
/**
|
||||
* 状态。200成功,400错误,500异常
|
||||
*/
|
||||
var status: Int = Status.Success
|
||||
|
||||
/**
|
||||
* 获取状态是否成功
|
||||
@@ -32,17 +36,17 @@ open class Message<T>(var status: Int = Status.Success) {
|
||||
*/
|
||||
val timestamp: Long = Date().time
|
||||
|
||||
constructor(data: T) : this(Status.Success) {
|
||||
constructor(data: T) : this() {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
constructor(status: Int, message: String) : this(status) {
|
||||
constructor(status: Int, message: String) : this() {
|
||||
this.status = status
|
||||
this.message = message
|
||||
}
|
||||
|
||||
constructor(status: Int, data: T, message: String) : this(status) {
|
||||
constructor(status: Int, data: T, message: String) : this(status, message) {
|
||||
this.data = data
|
||||
this.message = message
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,30 +4,21 @@ package com.synebula.gaea.query
|
||||
* 分页数据。
|
||||
* 真实数据行无后台遍历需求,直接使用object类型表示即可.
|
||||
*
|
||||
* @param page 页码,从1开始。
|
||||
* @param size 每页数据量。
|
||||
* @author alex
|
||||
*/
|
||||
class Page<T> {
|
||||
/**
|
||||
* 页码,从1开始。
|
||||
*/
|
||||
var page: Int = 0
|
||||
|
||||
/**
|
||||
* 每页数据量。
|
||||
*/
|
||||
|
||||
var size: Int = 0
|
||||
data class Page<T>(var page: Int = 0, var size: Int = 0) {
|
||||
|
||||
/**
|
||||
* 总数据量。
|
||||
*/
|
||||
|
||||
var total: Int = 0
|
||||
|
||||
/**
|
||||
* 数据索引,从0开始。表示数据在总量的第几条。(index = (page - 1) * size )
|
||||
*/
|
||||
var index: Int
|
||||
val index: Int
|
||||
get() = (page - 1) * size
|
||||
|
||||
/**
|
||||
@@ -36,18 +27,6 @@ class Page<T> {
|
||||
var data = listOf<T>()
|
||||
|
||||
|
||||
/**
|
||||
* 数据构造。
|
||||
*
|
||||
* @param page 页码,从1开始。
|
||||
* @param size 每页数据量。
|
||||
*/
|
||||
constructor(page: Int, size: Int) : super() {
|
||||
this.page = page
|
||||
this.size = size
|
||||
this.index = (page - 1) * size + 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据构造。
|
||||
*
|
||||
@@ -57,11 +36,10 @@ class Page<T> {
|
||||
* @param data 结果数据。
|
||||
*/
|
||||
|
||||
constructor(page: Int, size: Int, total: Int, data: List<T>) : super() {
|
||||
constructor(page: Int, size: Int, total: Int, data: List<T>) : this(page, size) {
|
||||
this.page = page
|
||||
this.size = size
|
||||
this.total = total
|
||||
this.index = (page - 1) * size + 1
|
||||
this.data = data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.synebula.gaea.query
|
||||
|
||||
import com.synebula.gaea.query.type.Order
|
||||
|
||||
/**
|
||||
* class 分页参数信息
|
||||
*
|
||||
@@ -19,7 +21,7 @@ data class Params(var page: Int = 1, var size: Int = 10) {
|
||||
/**
|
||||
* 排序条件。
|
||||
*/
|
||||
var orders: MutableMap<String, OrderType> = hashMapOf()
|
||||
var orders: MutableMap<String, Order> = hashMapOf()
|
||||
|
||||
/**
|
||||
* 查询条件。
|
||||
@@ -37,7 +39,7 @@ data class Params(var page: Int = 1, var size: Int = 10) {
|
||||
/**
|
||||
* 添加排序条件
|
||||
*/
|
||||
fun addOrderBy(field: String, type: OrderType = OrderType.ASC): Params {
|
||||
fun addOrderBy(field: String, type: Order = Order.ASC): Params {
|
||||
orders[field] = type
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.synebula.gaea.query
|
||||
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class Where(val operator: Operator)
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.synebula.gaea.query.annotation
|
||||
|
||||
annotation class Table(val name: String = "")
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.synebula.gaea.query.annotation
|
||||
|
||||
import com.synebula.gaea.query.type.Operator
|
||||
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
annotation class Where(val operator: Operator)
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.query
|
||||
package com.synebula.gaea.query.type
|
||||
|
||||
enum class Operator {
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.query
|
||||
package com.synebula.gaea.query.type
|
||||
|
||||
/**
|
||||
* class OrderType
|
||||
@@ -7,7 +7,7 @@ package com.synebula.gaea.query
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
enum class OrderType {
|
||||
enum class Order {
|
||||
/**
|
||||
* 升序排列
|
||||
*/
|
||||
Reference in New Issue
Block a user