From 2f0746b2c5758677af768f328e9bad63a76904c9 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 21 May 2020 15:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=80=9F=E5=8F=A3,=20=E4=BF=AE=E8=AE=A2query=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/synebula/gaea/app/ISignInOut.kt | 3 +- .../synebula/gaea/mongo/query/MongoQuery.kt | 34 ++++++++++--------- .../com/synebula/gaea/data/message/Message.kt | 13 +++++++ .../gaea/io/messager/IEmailMessenger.kt | 5 +++ .../synebula/gaea/test/CodeGenerateTest.kt | 14 -------- 5 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 src/gaea/src/main/kotlin/com/synebula/gaea/io/messager/IEmailMessenger.kt delete mode 100644 src/gaea/src/test/kotlin/com/synebula/gaea/test/CodeGenerateTest.kt diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ISignInOut.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ISignInOut.kt index 098ff75..33dd8a7 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ISignInOut.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ISignInOut.kt @@ -1,6 +1,7 @@ package com.synebula.gaea.app -import org.springframework.http.HttpMessage +import com.synebula.gaea.app.component.HttpMessage + /** * 用户登入登出接口定义 diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/query/MongoQuery.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/query/MongoQuery.kt index a8047a9..5790625 100644 --- a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/query/MongoQuery.kt +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/mongo/query/MongoQuery.kt @@ -15,9 +15,10 @@ import org.springframework.data.mongodb.core.query.Query /** * 实现IQuery的Mongo查询类 - * @param repo MongoRepo对象 + * @param template MongoRepo对象 + * @param logger 日志组件 */ -open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = null) : IQuery { +open class MongoQuery(var template: MongoTemplate, var logger: ILogger? = null) : IQuery { /** * 查询的对象类 */ @@ -45,10 +46,10 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul * 构造方法 * * @param clazz 视图对象类型 - * @param repo MongoRepo对象 + * @param query MongoRepo对象 */ - constructor(clazz: Class, repo: MongoTemplate) - : this(repo) { + constructor(clazz: Class, query: MongoTemplate) + : this(query) { this.clazz = clazz } @@ -56,21 +57,22 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul * 构造方法 * * @param collection 查询的集合名称 - * @param repo MongoRepo对象 + * @param query MongoRepo对象 */ - constructor(collection: String, repo: MongoTemplate) - : this(repo) { + constructor(collection: String, query: MongoTemplate) + : this(query) { this.collection = collection } /** * 构造方法 * + * @param collection 查询的集合名称 * @param clazz 视图对象类型 - * @param repo MongoRepo对象 + * @param query MongoRepo对象 */ - constructor(collection: String, clazz: Class, repo: MongoTemplate) - : this(clazz, repo) { + constructor(collection: String, clazz: Class, query: MongoTemplate) + : this(clazz, query) { this.collection = collection } @@ -82,7 +84,7 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul val query = Query() query.select(fields.toTypedArray()) query.where(params) - this.repo.find(query, this.clazz!!, this.collection) + this.template.find(query, this.clazz!!, this.collection) } else listOf() } @@ -90,7 +92,7 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul this.check() return if (this.clazz != null) { val query = Query() - this.repo.count(query.where(params), this.collection).toInt() + this.template.count(query.where(params), this.collection).toInt() } else 0 } @@ -105,7 +107,7 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul query.select(fields.toTypedArray()) query.with(order(params.orderBy)) query.skip(params.index).limit(params.size) - result.data = this.repo.find(query, this.clazz!!, this.collection) + result.data = this.template.find(query, this.clazz!!, this.collection) result } else PagingData(1, 10) } @@ -113,12 +115,12 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = nul override fun get(key: String): TView? { this.check() return if (this.clazz != null) { - val view = this.repo.findOne(whereId(key), this.clazz!!, this.collection) + val view = this.template.findOne(whereId(key), this.clazz!!, this.collection) view } else null } - private fun check() { + protected fun check() { if (this.clazz == null) throw RuntimeException("[${this.javaClass.name}] 没有声明查询View的类型") if (this._collection.isEmpty()) 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 d134eda..b6244c3 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 @@ -10,6 +10,13 @@ import java.util.* * @tparam T 消息数据类型 */ open class Message(var status: Int = Status.Success) { + + /** + * 获取状态是否成功 + */ + val success: Boolean + get() = this.status == Status.Success + /** * 传递的业务数据 */ @@ -38,6 +45,12 @@ open class Message(var status: Int = Status.Success) { this.message = message } + + /** + * 从另一对象中复制数据 + * + * @param other 另一消息对象 + */ open fun from(other: Message) { this.status = other.status this.data = other.data diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/io/messager/IEmailMessenger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/io/messager/IEmailMessenger.kt new file mode 100644 index 0000000..ae9fd4e --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/io/messager/IEmailMessenger.kt @@ -0,0 +1,5 @@ +package com.synebula.gaea.io.messager + +interface IEmailMessenger { + fun sendMessage(receivers: List, subject: String, content: String) +} \ No newline at end of file diff --git a/src/gaea/src/test/kotlin/com/synebula/gaea/test/CodeGenerateTest.kt b/src/gaea/src/test/kotlin/com/synebula/gaea/test/CodeGenerateTest.kt deleted file mode 100644 index 20954ab..0000000 --- a/src/gaea/src/test/kotlin/com/synebula/gaea/test/CodeGenerateTest.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.synebula.gaea.test - -import com.synebula.gaea.data.code.SnowflakeCode -import junit.framework.TestCase - -class CodeGenerateTest : TestCase() { - fun testSnowflake() { - val snowflakeCode = SnowflakeCode(1, 1) - for (i in 0..10) { - Thread.sleep(1000) - println(snowflakeCode.generate()) - } - } -} \ No newline at end of file