修改简化命名,分离message和data message
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.synebula.gaea.app.component
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
|
||||
class HttpMessage() : Message<Any>() {
|
||||
class HttpMessage() : DataMessage<Any>() {
|
||||
|
||||
constructor(data: Any) : this() {
|
||||
this.data = data
|
||||
@@ -17,7 +17,7 @@ class HttpMessage() : Message<Any>() {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
fun load(msg: Message<*>) {
|
||||
fun load(msg: DataMessage<*>) {
|
||||
this.status = msg.status
|
||||
this.message = msg.message
|
||||
this.data = msg.data
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.mongo.query
|
||||
|
||||
import com.synebula.gaea.extension.fieldNames
|
||||
import com.synebula.gaea.extension.firstCharLowerCase
|
||||
import com.synebula.gaea.ext.fieldNames
|
||||
import com.synebula.gaea.ext.firstCharLowerCase
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.mongo.order
|
||||
import com.synebula.gaea.mongo.select
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.mongo.query
|
||||
|
||||
import com.synebula.gaea.extension.fieldNames
|
||||
import com.synebula.gaea.extension.firstCharLowerCase
|
||||
import com.synebula.gaea.ext.fieldNames
|
||||
import com.synebula.gaea.ext.firstCharLowerCase
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.mongo.order
|
||||
import com.synebula.gaea.mongo.select
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.synebula.gaea.data.message
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* 用来统一Http返回消息类型,通常使用json格式传递
|
||||
*
|
||||
* @param T 消息数据类型
|
||||
*/
|
||||
open class DataMessage<T>() : Message() {
|
||||
|
||||
/**
|
||||
* 传递的业务数据
|
||||
*/
|
||||
var data: T? = null
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
val timestamp: Long = Date().time
|
||||
|
||||
constructor(data: T) : this() {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
constructor(status: Int, message: String) : this() {
|
||||
this.status = status
|
||||
this.message = message
|
||||
}
|
||||
|
||||
constructor(status: Int, data: T, message: String) : this(status, message) {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从另一对象中复制数据
|
||||
*
|
||||
* @param other 另一消息对象
|
||||
*/
|
||||
open fun from(other: DataMessage<T>) {
|
||||
this.status = other.status
|
||||
this.data = other.data
|
||||
this.message = other.message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
package com.synebula.gaea.data.message
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* 用来统一Http返回消息类型,通常使用json格式传递
|
||||
*
|
||||
* @tparam T 消息数据类型
|
||||
*/
|
||||
open class Message<T>() {
|
||||
|
||||
open class Message {
|
||||
/**
|
||||
* 状态。200成功,400错误,500异常
|
||||
*/
|
||||
@@ -21,44 +12,10 @@ open class Message<T>() {
|
||||
val success: Boolean
|
||||
get() = this.status == Status.Success
|
||||
|
||||
/**
|
||||
* 传递的业务数据
|
||||
*/
|
||||
var data: T? = null
|
||||
|
||||
/**
|
||||
* 附带提示消息
|
||||
*/
|
||||
var message = ""
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
val timestamp: Long = Date().time
|
||||
|
||||
constructor(data: T) : this() {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
constructor(status: Int, message: String) : this() {
|
||||
this.status = status
|
||||
this.message = message
|
||||
}
|
||||
|
||||
constructor(status: Int, data: T, message: String) : this(status, message) {
|
||||
this.data = data
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从另一对象中复制数据
|
||||
*
|
||||
* @param other 另一消息对象
|
||||
*/
|
||||
open fun from(other: Message<T>) {
|
||||
this.status = other.status
|
||||
this.data = other.data
|
||||
this.message = other.message
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ interface IService<TKey> {
|
||||
*/
|
||||
var logger: ILogger
|
||||
|
||||
fun add(command: ICommand): Message<TKey>
|
||||
fun add(command: ICommand): DataMessage<TKey>
|
||||
|
||||
fun update(id: TKey, command: ICommand)
|
||||
|
||||
@@ -28,7 +28,7 @@ interface IService<TKey> {
|
||||
* @param key 监听器标志。
|
||||
* @param func 监听方法。
|
||||
*/
|
||||
fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>)
|
||||
fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message)
|
||||
|
||||
/**
|
||||
* 移除一个删除对象前执行监听器。
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
import com.synebula.gaea.domain.repository.IRepository
|
||||
@@ -29,14 +30,14 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
/**
|
||||
* 删除对象前执行监听器。
|
||||
*/
|
||||
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message<String>>()
|
||||
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message>()
|
||||
|
||||
/**
|
||||
* 添加一个删除对象前执行监听器。
|
||||
* @param key 监听器标志。
|
||||
* @param func 监听方法。
|
||||
*/
|
||||
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>) {
|
||||
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message) {
|
||||
this.beforeRemoveListeners[key] = func
|
||||
}
|
||||
|
||||
@@ -48,8 +49,8 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
this.beforeRemoveListeners.remove(key)
|
||||
}
|
||||
|
||||
override fun add(command: ICommand): Message<TKey> {
|
||||
val msg = Message<TKey>()
|
||||
override fun add(command: ICommand): DataMessage<TKey> {
|
||||
val msg = DataMessage<TKey>()
|
||||
val root = this.convert(command)
|
||||
this.repository.add(root, this.clazz)
|
||||
msg.data = root.id
|
||||
@@ -64,11 +65,11 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
|
||||
override fun remove(id: TKey) {
|
||||
val functions = this.beforeRemoveListeners.values
|
||||
var msg: Message<String>
|
||||
var msg: Message
|
||||
for (func in functions) {
|
||||
msg = func(id)
|
||||
if (!msg.success) {
|
||||
throw java.lang.RuntimeException(msg.data)
|
||||
throw java.lang.RuntimeException(msg.message)
|
||||
}
|
||||
}
|
||||
this.repository.remove(id, this.clazz)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
import com.synebula.gaea.domain.repository.ISpecificRepository
|
||||
@@ -33,14 +34,14 @@ open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
/**
|
||||
* 删除对象前执行监听器。
|
||||
*/
|
||||
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message<String>>()
|
||||
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message>()
|
||||
|
||||
/**
|
||||
* 添加一个删除对象前执行监听器。
|
||||
* @param key 监听器标志。
|
||||
* @param func 监听方法。
|
||||
*/
|
||||
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>) {
|
||||
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message) {
|
||||
this.beforeRemoveListeners[key] = func
|
||||
}
|
||||
|
||||
@@ -52,8 +53,8 @@ open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
this.beforeRemoveListeners.remove(key)
|
||||
}
|
||||
|
||||
override fun add(command: ICommand): Message<TKey> {
|
||||
val msg = Message<TKey>()
|
||||
override fun add(command: ICommand): DataMessage<TKey> {
|
||||
val msg = DataMessage<TKey>()
|
||||
val root = this.convert(command)
|
||||
this.repository.add(root)
|
||||
msg.data = root.id
|
||||
@@ -68,11 +69,11 @@ open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
|
||||
override fun remove(id: TKey) {
|
||||
val functions = this.beforeRemoveListeners.values
|
||||
var msg: Message<String>
|
||||
var msg: Message
|
||||
for (func in functions) {
|
||||
msg = func(id)
|
||||
if (!msg.success) {
|
||||
throw java.lang.RuntimeException(msg.data)
|
||||
throw java.lang.RuntimeException(msg.message)
|
||||
}
|
||||
}
|
||||
this.repository.remove(id)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.extension
|
||||
package com.synebula.gaea.ext
|
||||
|
||||
/**
|
||||
* 获取对象字段信息字符串列表。
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.extension
|
||||
package com.synebula.gaea.ext
|
||||
|
||||
import com.synebula.gaea.data.date.TimeSpan
|
||||
import java.util.*
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.gaea.extension
|
||||
package com.synebula.gaea.ext
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.security.MessageDigest
|
||||
Reference in New Issue
Block a user