From 0d747f92b225320632a91634aa95eb6c31bb3ee4 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 7 Jul 2020 15:06:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84Gaea=E6=9C=8D=E5=8A=A1,=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaea/app/component/HttpMessage.kt | 16 +++++++++- .../com/synebula/gaea/mongo/Collection.kt | 3 -- .../com/synebula/gaea/mongo/MongoExt.kt | 8 ++--- .../com/synebula/gaea/data/message/Message.kt | 16 ++++++---- .../kotlin/com/synebula/gaea/query/Page.kt | 32 +++---------------- .../kotlin/com/synebula/gaea/query/Params.kt | 6 ++-- .../kotlin/com/synebula/gaea/query/Where.kt | 4 --- .../synebula/gaea/query/annotation/Table.kt | 3 ++ .../synebula/gaea/query/annotation/Where.kt | 6 ++++ .../gaea/query/{ => type}/Operator.kt | 2 +- .../query/{OrderType.kt => type/Order.kt} | 4 +-- 11 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/Collection.kt delete mode 100644 src/gaea/src/main/kotlin/com/synebula/gaea/query/Where.kt create mode 100644 src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Table.kt create mode 100644 src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Where.kt rename src/gaea/src/main/kotlin/com/synebula/gaea/query/{ => type}/Operator.kt (92%) rename src/gaea/src/main/kotlin/com/synebula/gaea/query/{OrderType.kt => type/Order.kt} (75%) diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt index 3b4b34f..eabe604 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt @@ -3,7 +3,21 @@ package com.synebula.gaea.app.component import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Message -class HttpMessage(status: Int = Status.Success) : Message(status) { +class HttpMessage() : Message() { + + constructor(data: Any) : this() { + this.data = data + } + + constructor(status: Int, message: String) : this() { + this.status = status + this.message = message + } + + constructor(status: Int, data: Any, message: String) : this(status, message) { + this.data = data + } + fun load(msg: Message<*>) { this.status = msg.status this.message = msg.message diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/Collection.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/Collection.kt deleted file mode 100644 index c0fb9c2..0000000 --- a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/Collection.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.synebula.gaea.mongo - -annotation class Collection(val name: String = "") \ No newline at end of file diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/MongoExt.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/MongoExt.kt index 9469d19..020983c 100644 --- a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/MongoExt.kt +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/MongoExt.kt @@ -30,9 +30,9 @@ fun Query.select(fields: Array): Query { * @param onWhere 获取字段查询方式的方法 */ fun Query.where( - params: Map?, - onWhere: ((v: String) -> Operator) = { Operator.default }, - onFieldType: ((v: String) -> Class<*>?) = { null } + params: Map?, + onWhere: ((v: String) -> Operator) = { Operator.default }, + onFieldType: ((v: String) -> Class<*>?) = { null } ): Query { val list = arrayListOf() if (params != null) { @@ -106,7 +106,7 @@ fun whereId(id: TKey): Query = Query.query(Criteria.where("_id").`is`(id) * * @param orders 排序条件字段 */ -fun order(orders: Map?): Sort { +fun order(orders: Map?): Sort { val orderList = mutableListOf() orders?.forEach { orderList.add(Sort.Order(Sort.Direction.valueOf(it.value.name), it.key)) diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/message/Message.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/message/Message.kt index b6244c3..9f5367a 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/message/Message.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/message/Message.kt @@ -6,10 +6,14 @@ import java.util.* * * 用来统一Http返回消息类型,通常使用json格式传递 * - * @param status http编码。200成功,400错误,500异常 * @tparam T 消息数据类型 */ -open class Message(var status: Int = Status.Success) { +open class Message() { + + /** + * 状态。200成功,400错误,500异常 + */ + var status: Int = Status.Success /** * 获取状态是否成功 @@ -32,17 +36,17 @@ open class Message(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 } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Page.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/Page.kt index 0555ce3..69fca7d 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Page.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/Page.kt @@ -4,30 +4,21 @@ package com.synebula.gaea.query * 分页数据。 * 真实数据行无后台遍历需求,直接使用object类型表示即可. * + * @param page 页码,从1开始。 + * @param size 每页数据量。 * @author alex */ -class Page { - /** - * 页码,从1开始。 - */ - var page: Int = 0 - - /** - * 每页数据量。 - */ - - var size: Int = 0 +data class Page(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 { var data = listOf() - /** - * 数据构造。 - * - * @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 { * @param data 结果数据。 */ - constructor(page: Int, size: Int, total: Int, data: List) : super() { + constructor(page: Int, size: Int, total: Int, data: List) : this(page, size) { this.page = page this.size = size this.total = total - this.index = (page - 1) * size + 1 this.data = data } } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Params.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/Params.kt index d370fbb..cf623cb 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Params.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/Params.kt @@ -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 = hashMapOf() + var orders: MutableMap = 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 } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Where.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/Where.kt deleted file mode 100644 index d7834e4..0000000 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Where.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.synebula.gaea.query - -@Target(AnnotationTarget.FIELD) -annotation class Where(val operator: Operator) \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Table.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Table.kt new file mode 100644 index 0000000..00d7922 --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Table.kt @@ -0,0 +1,3 @@ +package com.synebula.gaea.query.annotation + +annotation class Table(val name: String = "") \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Where.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Where.kt new file mode 100644 index 0000000..dfeb52c --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/annotation/Where.kt @@ -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) \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Operator.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Operator.kt similarity index 92% rename from src/gaea/src/main/kotlin/com/synebula/gaea/query/Operator.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Operator.kt index 523cf30..e3ece94 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/query/Operator.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Operator.kt @@ -1,4 +1,4 @@ -package com.synebula.gaea.query +package com.synebula.gaea.query.type enum class Operator { /** diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/OrderType.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Order.kt similarity index 75% rename from src/gaea/src/main/kotlin/com/synebula/gaea/query/OrderType.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Order.kt index cf4f6be..35cd05f 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/query/OrderType.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/type/Order.kt @@ -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 { /** * 升序排列 */