更新接口名称,重构App层实现
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package com.synebula.gaea.app
|
package com.synebula.gaea.app
|
||||||
|
|
||||||
import com.synebula.gaea.app.cmd.ICommandApp
|
import com.synebula.gaea.app.cmd.ICommandApp
|
||||||
import com.synebula.gaea.app.query.IQueryApp
|
import com.synebula.gaea.app.query.IQueryGenericApp
|
||||||
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
||||||
import com.synebula.gaea.domain.service.ICommand
|
import com.synebula.gaea.domain.service.ICommand
|
||||||
import com.synebula.gaea.domain.service.IService
|
import com.synebula.gaea.domain.service.IService
|
||||||
@@ -22,7 +22,7 @@ open class UnionApp<TCommand : ICommand, TView, TKey>(
|
|||||||
override var service: IService<TKey>?,
|
override var service: IService<TKey>?,
|
||||||
override var query: IQuery<TView, TKey>?,
|
override var query: IQuery<TView, TKey>?,
|
||||||
override var logger: ILogger)
|
override var logger: ILogger)
|
||||||
: ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {
|
: ICommandApp<TCommand, TKey>, IQueryGenericApp<TView, TKey> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
override var jsonSerializer: IJsonSerializer? = null
|
override var jsonSerializer: IJsonSerializer? = null
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.synebula.gaea.app
|
package com.synebula.gaea.app
|
||||||
|
|
||||||
import com.synebula.gaea.app.cmd.ICommandApp
|
import com.synebula.gaea.app.cmd.ICommandApp
|
||||||
|
import com.synebula.gaea.app.query.IQueryGenericApp
|
||||||
import com.synebula.gaea.app.query.IQueryTypedApp
|
import com.synebula.gaea.app.query.IQueryTypedApp
|
||||||
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
||||||
import com.synebula.gaea.domain.service.ICommand
|
import com.synebula.gaea.domain.service.ICommand
|
||||||
import com.synebula.gaea.domain.service.IService
|
import com.synebula.gaea.domain.service.IService
|
||||||
import com.synebula.gaea.log.ILogger
|
import com.synebula.gaea.log.ILogger
|
||||||
|
import com.synebula.gaea.query.IQuery
|
||||||
import com.synebula.gaea.query.IQueryTyped
|
import com.synebula.gaea.query.IQueryTyped
|
||||||
import javax.annotation.Resource
|
import javax.annotation.Resource
|
||||||
|
|
||||||
|
|||||||
@@ -2,64 +2,50 @@ package com.synebula.gaea.app.query
|
|||||||
|
|
||||||
import com.synebula.gaea.app.IApplication
|
import com.synebula.gaea.app.IApplication
|
||||||
import com.synebula.gaea.app.component.HttpMessage
|
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.PagingParam
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
import org.springframework.web.bind.annotation.PathVariable
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用类接口,提供实现Query服务的接口
|
|
||||||
* 依赖查询接 return this.safeExecute("获取${this.name}数据失败") {
|
|
||||||
口 @see IQuery
|
|
||||||
*
|
|
||||||
* @author alex
|
|
||||||
* @version 0.1
|
|
||||||
* @since 2020-05-15
|
|
||||||
*/
|
|
||||||
interface IQueryApp<TView, TKey> : IApplication {
|
interface IQueryApp<TView, TKey> : IApplication {
|
||||||
/**
|
|
||||||
* 查询服务
|
|
||||||
*/
|
|
||||||
var query: IQuery<TView, TKey>?
|
|
||||||
|
|
||||||
@GetMapping("/{key:.+}")
|
@GetMapping("/{key:.+}")
|
||||||
fun get(@PathVariable key: TKey): HttpMessage {
|
fun get(@PathVariable key: TKey): HttpMessage {
|
||||||
return this.safeExecute("获取${this.name}数据失败") {
|
return this.doGet(key)
|
||||||
if (this.query != null)
|
|
||||||
it.data = this.query!!.get(key)
|
|
||||||
else {
|
|
||||||
it.status = Status.Error
|
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun list(@RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
fun list(@RequestParam params: MutableMap<String, Any>): HttpMessage {
|
||||||
return this.safeExecute("获取${this.name}列表数据失败") {
|
return this.doList(params)
|
||||||
if (this.query != null)
|
|
||||||
it.data = this.query!!.list(parameters)
|
|
||||||
else {
|
|
||||||
it.status = Status.Error
|
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/segments/{size}/pages/{page}")
|
@GetMapping("/segments/{size}/pages/{page}")
|
||||||
fun paging(@PathVariable size: Int, @PathVariable page: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
fun paging(@PathVariable size: Int, @PathVariable page: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
||||||
return this.safeExecute("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
|
return this.doPaging(size, page, parameters)
|
||||||
if (this.query != null) {
|
|
||||||
val params = PagingParam(page, size)
|
|
||||||
params.parameters = parameters
|
|
||||||
it.data = this.query!!.paging(params)
|
|
||||||
} else {
|
|
||||||
it.status = Status.Error
|
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 实际查询单条数据逻辑
|
||||||
|
*
|
||||||
|
* @param key 数据的主键
|
||||||
|
*/
|
||||||
|
fun doGet(key: TKey): HttpMessage
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际查询列表逻辑
|
||||||
|
*
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
fun doList(params: Map<String, Any>): HttpMessage
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际分页逻辑
|
||||||
|
*
|
||||||
|
* @param size 单页数量
|
||||||
|
* @param page 分页页码
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
fun doPaging(size: Int, page: Int, params: MutableMap<String, Any>): HttpMessage
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.synebula.gaea.app.query
|
||||||
|
|
||||||
|
import com.synebula.gaea.app.IApplication
|
||||||
|
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.PagingParam
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用类接口,提供实现Query服务的接口
|
||||||
|
* 依赖查询接口 @see IQuery
|
||||||
|
*
|
||||||
|
* @author alex
|
||||||
|
* @version 0.1
|
||||||
|
* @since 2020-05-15
|
||||||
|
*/
|
||||||
|
interface IQueryGenericApp<TView, TKey> : IQueryApp<TView, TKey> {
|
||||||
|
/**
|
||||||
|
* 查询服务
|
||||||
|
*/
|
||||||
|
var query: IQuery<TView, TKey>?
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际查询单条数据逻辑
|
||||||
|
*
|
||||||
|
* @param key 数据的主键
|
||||||
|
*/
|
||||||
|
override fun doGet(key: TKey): HttpMessage {
|
||||||
|
return this.doQuery("获取${this.name}数据失败") {
|
||||||
|
this.query!!.get(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际查询列表逻辑
|
||||||
|
*
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
override fun doList(params: Map<String, Any>): HttpMessage {
|
||||||
|
return this.doQuery("获取${this.name}列表数据失败") {
|
||||||
|
this.query!!.list(params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际分页逻辑
|
||||||
|
*
|
||||||
|
* @param size 单页数量
|
||||||
|
* @param page 分页页码
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
override fun doPaging(size: Int, page: Int, params: MutableMap<String, Any>): HttpMessage {
|
||||||
|
return this.doQuery("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
|
||||||
|
val data = PagingParam(page, size)
|
||||||
|
data.parameters = params
|
||||||
|
this.query!!.paging(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽取查询业务判断功能
|
||||||
|
*
|
||||||
|
* @param error 错误消息
|
||||||
|
* @param biz 业务执行逻辑
|
||||||
|
*/
|
||||||
|
fun doQuery(error: String, biz: (() -> Any?)): HttpMessage {
|
||||||
|
return this.safeExecute(error) {
|
||||||
|
if (this.query != null) {
|
||||||
|
it.data = biz()
|
||||||
|
} else {
|
||||||
|
it.status = Status.Error
|
||||||
|
it.message = "没有对应服务,无法执行该操作"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,9 +5,6 @@ import com.synebula.gaea.app.component.HttpMessage
|
|||||||
import com.synebula.gaea.data.message.Status
|
import com.synebula.gaea.data.message.Status
|
||||||
import com.synebula.gaea.query.IQueryTyped
|
import com.synebula.gaea.query.IQueryTyped
|
||||||
import com.synebula.gaea.query.PagingParam
|
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服务的接口.
|
* 应用类接口,提供实现Query服务的接口.
|
||||||
@@ -17,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam
|
|||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @since 2020-05-15
|
* @since 2020-05-15
|
||||||
*/
|
*/
|
||||||
interface IQueryTypedApp<TView, TKey> : IApplication {
|
interface IQueryTypedApp<TView, TKey> : IApplication, IQueryApp<TView, TKey> {
|
||||||
/**
|
/**
|
||||||
* 查询服务
|
* 查询服务
|
||||||
*/
|
*/
|
||||||
@@ -28,42 +25,40 @@ interface IQueryTypedApp<TView, TKey> : IApplication {
|
|||||||
*/
|
*/
|
||||||
var viewClass: Class<TView>
|
var viewClass: Class<TView>
|
||||||
|
|
||||||
@GetMapping("/{key:.+}")
|
override fun doGet(key: TKey): HttpMessage {
|
||||||
fun get(@PathVariable key: TKey): HttpMessage {
|
return this.doQuery("获取${this.name}数据失败") {
|
||||||
return this.safeExecute("获取${this.name}数据失败") {
|
this.query!!.get(key, viewClass)
|
||||||
if (this.query != null)
|
|
||||||
it.data = this.query!!.get(key, viewClass)
|
|
||||||
else {
|
|
||||||
it.status = Status.Error
|
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
override fun doList(params: Map<String, Any>): HttpMessage {
|
||||||
fun list(@RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
return this.doQuery("获取${this.name}列表数据失败") {
|
||||||
return this.safeExecute("获取${this.name}列表数据失败") {
|
this.query!!.list(params, viewClass)
|
||||||
if (this.query != null)
|
|
||||||
it.data = this.query!!.list(parameters, viewClass)
|
|
||||||
else {
|
|
||||||
it.status = Status.Error
|
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/split/{size}/pages/{page}")
|
override fun doPaging(size: Int, page: Int, params: MutableMap<String, Any>): HttpMessage {
|
||||||
fun paging(@PathVariable page: Int, @PathVariable size: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
|
return this.doQuery("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
|
||||||
return this.safeExecute("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
|
val data = PagingParam(page, size)
|
||||||
|
data.parameters = params
|
||||||
|
this.query!!.paging(data, viewClass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽取查询业务判断功能
|
||||||
|
*
|
||||||
|
* @param error 错误消息
|
||||||
|
* @param biz 业务执行逻辑
|
||||||
|
*/
|
||||||
|
fun doQuery(error: String, biz: (() -> Any?)): HttpMessage {
|
||||||
|
return this.safeExecute(error) {
|
||||||
if (this.query != null) {
|
if (this.query != null) {
|
||||||
val params = PagingParam(page, size)
|
it.data = biz()
|
||||||
params.parameters = parameters
|
|
||||||
it.data = this.query!!.paging(params, viewClass)
|
|
||||||
} else {
|
} else {
|
||||||
it.status = Status.Error
|
it.status = Status.Error
|
||||||
it.message = "没有对应服务,无法执行该操作"
|
it.message = "没有对应服务,无法执行该操作"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import com.synebula.gaea.query.IQuery
|
|||||||
* @param query 业务查询服务
|
* @param query 业务查询服务
|
||||||
* @param logger 日志组件
|
* @param logger 日志组件
|
||||||
*/
|
*/
|
||||||
open class QueryApp<TView, TKey>(
|
open class QueryGenericApp<TView, TKey>(
|
||||||
override var name: String,
|
override var name: String,
|
||||||
override var query: IQuery<TView, TKey>?,
|
override var query: IQuery<TView, TKey>?,
|
||||||
override var logger: ILogger) : IQueryApp<TView, TKey> {
|
override var logger: ILogger) : IQueryGenericApp<TView, TKey> {
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user