增加消息发送借口, 修订query对象名称

This commit is contained in:
2020-05-21 15:14:02 +08:00
parent 98b4dc639c
commit 2f0746b2c5
5 changed files with 38 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
package com.synebula.gaea.app package com.synebula.gaea.app
import org.springframework.http.HttpMessage import com.synebula.gaea.app.component.HttpMessage
/** /**
* 用户登入登出接口定义 * 用户登入登出接口定义

View File

@@ -15,9 +15,10 @@ import org.springframework.data.mongodb.core.query.Query
/** /**
* 实现IQuery的Mongo查询类 * 实现IQuery的Mongo查询类
* @param repo MongoRepo对象 * @param template MongoRepo对象
* @param logger 日志组件
*/ */
open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = null) : IQuery<TView, String> { open class MongoQuery<TView>(var template: MongoTemplate, var logger: ILogger? = null) : IQuery<TView, String> {
/** /**
* 查询的对象类 * 查询的对象类
*/ */
@@ -45,10 +46,10 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
* 构造方法 * 构造方法
* *
* @param clazz 视图对象类型 * @param clazz 视图对象类型
* @param repo MongoRepo对象 * @param query MongoRepo对象
*/ */
constructor(clazz: Class<TView>, repo: MongoTemplate) constructor(clazz: Class<TView>, query: MongoTemplate)
: this(repo) { : this(query) {
this.clazz = clazz this.clazz = clazz
} }
@@ -56,21 +57,22 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
* 构造方法 * 构造方法
* *
* @param collection 查询的集合名称 * @param collection 查询的集合名称
* @param repo MongoRepo对象 * @param query MongoRepo对象
*/ */
constructor(collection: String, repo: MongoTemplate) constructor(collection: String, query: MongoTemplate)
: this(repo) { : this(query) {
this.collection = collection this.collection = collection
} }
/** /**
* 构造方法 * 构造方法
* *
* @param collection 查询的集合名称
* @param clazz 视图对象类型 * @param clazz 视图对象类型
* @param repo MongoRepo对象 * @param query MongoRepo对象
*/ */
constructor(collection: String, clazz: Class<TView>, repo: MongoTemplate) constructor(collection: String, clazz: Class<TView>, query: MongoTemplate)
: this(clazz, repo) { : this(clazz, query) {
this.collection = collection this.collection = collection
} }
@@ -82,7 +84,7 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
val query = Query() val query = Query()
query.select(fields.toTypedArray()) query.select(fields.toTypedArray())
query.where(params) query.where(params)
this.repo.find(query, this.clazz!!, this.collection) this.template.find(query, this.clazz!!, this.collection)
} else listOf() } else listOf()
} }
@@ -90,7 +92,7 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
this.check() this.check()
return if (this.clazz != null) { return if (this.clazz != null) {
val query = Query() val query = Query()
this.repo.count(query.where(params), this.collection).toInt() this.template.count(query.where(params), this.collection).toInt()
} else 0 } else 0
} }
@@ -105,7 +107,7 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
query.select(fields.toTypedArray()) query.select(fields.toTypedArray())
query.with(order(params.orderBy)) query.with(order(params.orderBy))
query.skip(params.index).limit(params.size) 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 result
} else PagingData(1, 10) } else PagingData(1, 10)
} }
@@ -113,12 +115,12 @@ open class MongoQuery<TView>(var repo: MongoTemplate, var logger: ILogger? = nul
override fun get(key: String): TView? { override fun get(key: String): TView? {
this.check() this.check()
return if (this.clazz != null) { 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 view
} else null } else null
} }
private fun check() { protected fun check() {
if (this.clazz == null) if (this.clazz == null)
throw RuntimeException("[${this.javaClass.name}] 没有声明查询View的类型") throw RuntimeException("[${this.javaClass.name}] 没有声明查询View的类型")
if (this._collection.isEmpty()) if (this._collection.isEmpty())

View File

@@ -10,6 +10,13 @@ import java.util.*
* @tparam T 消息数据类型 * @tparam T 消息数据类型
*/ */
open class Message<T>(var status: Int = Status.Success) { open class Message<T>(var status: Int = Status.Success) {
/**
* 获取状态是否成功
*/
val success: Boolean
get() = this.status == Status.Success
/** /**
* 传递的业务数据 * 传递的业务数据
*/ */
@@ -38,6 +45,12 @@ open class Message<T>(var status: Int = Status.Success) {
this.message = message this.message = message
} }
/**
* 从另一对象中复制数据
*
* @param other 另一消息对象
*/
open fun from(other: Message<T>) { open fun from(other: Message<T>) {
this.status = other.status this.status = other.status
this.data = other.data this.data = other.data

View File

@@ -0,0 +1,5 @@
package com.synebula.gaea.io.messager
interface IEmailMessenger {
fun sendMessage(receivers: List<String>, subject: String, content: String)
}

View File

@@ -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())
}
}
}