拆分query typed两种类型
This commit is contained in:
@@ -28,8 +28,7 @@ interface IApplication {
|
||||
} catch (ex: Exception) {
|
||||
msg.status = Status.Error
|
||||
msg.message = if (error.isEmpty()) ex.message ?: "" else error
|
||||
msg.data = ex.message
|
||||
logger.error(this, "$error: ${ex.message}")
|
||||
logger.error(this, ex, "$error: ${ex.message}")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
|
||||
/**
|
||||
* 应用类接口,提供向Query服务的接口
|
||||
* 应用类接口,提供实现Query服务的接口
|
||||
* 依赖查询接口 @see IQuery
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.gaea.query.IQueryTyped
|
||||
import com.synebula.gaea.query.PagingParam
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
|
||||
/**
|
||||
* 应用类接口,提供实现Query服务的接口.
|
||||
* 依赖查询接口 @see IQueryTyped
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2018 18-2-8
|
||||
*/
|
||||
interface IQueryTypedApp<TView, TKey> : IApplication {
|
||||
/**
|
||||
* 查询服务
|
||||
*/
|
||||
var query: IQueryTyped?
|
||||
|
||||
var viewClass: Class<TView>
|
||||
|
||||
@GetMapping("/{key:.+}")
|
||||
fun get(@PathVariable key: TKey): HttpMessage {
|
||||
return this.safeExecute("${this.name}获取数据失败") {
|
||||
if (this.query != null)
|
||||
it.data = this.query!!.get(key, viewClass)
|
||||
else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
fun list(@RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
||||
return this.safeExecute("${this.name}获取数据失败") {
|
||||
if (this.query != null)
|
||||
it.data = this.query!!.list<TView, TKey>(parameters, viewClass)
|
||||
else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/split/{size}/pages/{page}")
|
||||
fun paging(@PathVariable page: Int, @PathVariable size: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
||||
return this.safeExecute("${this.name}获取分页数据失败") {
|
||||
if (this.query != null) {
|
||||
val params = PagingParam(page, size)
|
||||
params.parameters = parameters
|
||||
it.data = this.query!!.paging<TView, TKey>(params, viewClass)
|
||||
} else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.gaea.query.IQueryTyped
|
||||
|
||||
/**
|
||||
* 联合服务,同时实现了ICommandApp和IQueryApp接口
|
||||
*
|
||||
* @param name 业务名称
|
||||
* @param query 业务查询服务
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class QueryTypedApp<TView, TKey>(
|
||||
override var name: String,
|
||||
override var viewClass: Class<TView>,
|
||||
override var query: IQueryTyped?,
|
||||
override var logger: ILogger) : IQueryTypedApp<TView, TKey> {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.gaea.query.IQueryTyped
|
||||
|
||||
/**
|
||||
* 联合服务,同时实现了ICommandApp和IQueryApp接口
|
||||
*
|
||||
* @param name 业务名称
|
||||
* @param service 业务domain服务
|
||||
* @param query 业务查询服务
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class UnionTypedApp<TCommand : ICommand, TView, TKey>(
|
||||
override var name: String,
|
||||
override var viewClass: Class<TView>,
|
||||
override var service: IService<TKey>?,
|
||||
override var query: IQueryTyped?,
|
||||
override var logger: ILogger)
|
||||
: ICommandApp<TCommand, TKey>, IQueryTypedApp<TView, TKey> {
|
||||
}
|
||||
Reference in New Issue
Block a user