repo增加count方法

修改before remove的监听器返回值类型
This commit is contained in:
2020-10-27 23:37:18 +08:00
parent d1c843cbae
commit ca13018c9f
10 changed files with 63 additions and 27 deletions

View File

@@ -4,15 +4,15 @@ object Status {
/**
* 成功
*/
val Success = 200
const val Success = 200
/**
* 失败
*/
val Failure = 400
const val Failure = 400
/**
* 错误
*/
val Error = 500
const val Error = 500
}

View File

@@ -39,4 +39,13 @@ interface IRepository {
* @return 聚合根
*/
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<TAggregateRoot>): TAggregateRoot
/**
* 根据条件查询符合条件记录的数量
*
* @param params 查询条件。
* @return int
*/
fun <TAggregateRoot> count(params: Map<String, Any>?, clazz: Class<TAggregateRoot>): Int
}

View File

@@ -58,4 +58,13 @@ interface ISpecificRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
*/
fun <T : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<T>): T
/**
* 根据条件查询符合条件记录的数量
*
* @param params 查询条件。
* @return int
*/
fun <TAggregateRoot> count(params: Map<String, Any>?): Int
}

View File

@@ -28,7 +28,7 @@ interface IService<TKey> {
* @param key 监听器标志。
* @param func 监听方法。
*/
fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Boolean)
fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>)
/**
* 移除一个删除对象前执行监听器。

View File

@@ -29,14 +29,14 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
/**
* 删除对象前执行监听器。
*/
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Boolean>()
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message<String>>()
/**
* 添加一个删除对象前执行监听器。
* @param key 监听器标志。
* @param func 监听方法。
*/
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Boolean) {
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>) {
this.beforeRemoveListeners[key] = func
}
@@ -63,14 +63,15 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
}
override fun remove(id: TKey) {
var exec = true
val functions = this.beforeRemoveListeners.values
var msg: Message<String>
for (func in functions) {
exec = func(id)
if (!exec) break
msg = func(id)
if (!msg.success) {
throw java.lang.RuntimeException(msg.data)
}
}
if (exec)
this.repository.remove(id, this.clazz)
this.repository.remove(id, this.clazz)
}
/**

View File

@@ -33,14 +33,14 @@ open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
/**
* 删除对象前执行监听器。
*/
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Boolean>()
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message<String>>()
/**
* 添加一个删除对象前执行监听器。
* @param key 监听器标志。
* @param func 监听方法。
*/
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Boolean) {
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message<String>) {
this.beforeRemoveListeners[key] = func
}
@@ -67,14 +67,15 @@ open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
}
override fun remove(id: TKey) {
var exec = true
val functions = this.beforeRemoveListeners.values
var msg: Message<String>
for (func in functions) {
exec = func(id)
if (!exec) break
msg = func(id)
if (!msg.success) {
throw java.lang.RuntimeException(msg.data)
}
}
if (exec)
this.repository.remove(id)
this.repository.remove(id)
}
fun get(id: TKey): TAggregateRoot {