精简代码:删除Specific相关代码

修改mongo query获取字段范围值类型
This commit is contained in:
2020-11-02 23:50:40 +08:00
parent 227035fa78
commit 8f2f5fcb6d
7 changed files with 4 additions and 438 deletions

View File

@@ -1,100 +0,0 @@
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
import com.synebula.gaea.log.ILogger
/**
* 依赖了ISpecificRepository仓储借口的服务实现类 Service
* 该类依赖仓储接口 @see ISpecificRepository, 泛型类上指定了仓储实例的类型
*
* @param repository 仓储对象
* @param clazz 聚合根类对象
* @param converter 对象转换组件
* @param logger 日志组件
* @author alex
* @version 0.1
* @since 2020-05-15
*/
open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
protected var clazz: Class<TAggregateRoot>,
protected var repository: ISpecificRepository<TAggregateRoot, TKey>,
protected var converter: IObjectConverter,
override var logger: ILogger
) : IService<TKey> {
init {
this.repository.clazz = clazz
}
/**
* 删除对象前执行监听器。
*/
protected val beforeRemoveListeners = mutableMapOf<String, (id: TKey) -> Message>()
/**
* 添加一个删除对象前执行监听器。
* @param key 监听器标志。
* @param func 监听方法。
*/
override fun addBeforeRemoveListener(key: String, func: (id: TKey) -> Message) {
this.beforeRemoveListeners[key] = func
}
/**
* 移除一个删除对象前执行监听器。
* @param key 监听器标志。
*/
override fun removeBeforeRemoveListener(key: String) {
this.beforeRemoveListeners.remove(key)
}
override fun add(command: ICommand): DataMessage<TKey> {
val msg = DataMessage<TKey>()
val root = this.convert(command)
this.repository.add(root)
msg.data = root.id
return msg
}
override fun update(id: TKey, command: ICommand) {
val root = this.convert(command)
root.id = id
this.repository.update(root)
}
override fun remove(id: TKey) {
val functions = this.beforeRemoveListeners.values
var msg: Message
for (func in functions) {
msg = func(id)
if (!msg.success) {
throw java.lang.RuntimeException(msg.message)
}
}
this.repository.remove(id)
}
fun get(id: TKey): TAggregateRoot {
return this.repository.get(id)
}
/**
* 转换ICommand类型到聚合根类型默认实现根据需要进行覆写。
*
* @param command
* @return
*/
protected fun convert(command: ICommand): TAggregateRoot {
try {
return converter.convert(command, this.clazz)
} catch (ex: Exception) {
throw RuntimeException("command not match aggregate root", ex)
}
}
}

View File

@@ -1,42 +0,0 @@
package com.synebula.gaea.query
/**
* 查询基接口。
*
* @author alex
*/
interface ISpecificQuery<TView, TKey> {
/**
* 根据Key获取对象。
*
* @param key 对象Key。
* @return
*/
fun get(id: TKey): TView?
/**
* 根据实体类条件查询所有符合条件记录
*
* @param params 查询条件。
* @return list
*/
fun list(params: Map<String, Any>?): List<TView>
/**
* 根据条件查询符合条件记录的数量
*
* @param params 查询条件。
* @return int
*/
fun count(params: Map<String, Any>?): Int
/**
* 根据实体类条件查询所有符合条件记录(分页查询)
*
* @param param 分页条件
* @return 分页数据
*/
fun paging(param: Params): Page<TView>
}