更新接口名称,重构App层实现

This commit is contained in:
2020-05-20 17:06:34 +08:00
parent 4894bc315e
commit 648a2384c4
6 changed files with 141 additions and 77 deletions

View File

@@ -1,7 +1,7 @@
package com.synebula.gaea.app
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.domain.service.ICommand
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 query: IQuery<TView, TKey>?,
override var logger: ILogger)
: ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {
: ICommandApp<TCommand, TKey>, IQueryGenericApp<TView, TKey> {
@Resource
override var jsonSerializer: IJsonSerializer? = null

View File

@@ -1,11 +1,13 @@
package com.synebula.gaea.app
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.data.serialization.json.IJsonSerializer
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
import javax.annotation.Resource

View File

@@ -2,64 +2,50 @@ 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服务的接口
* 依赖查询接 return this.safeExecute("获取${this.name}数据失败") {
口 @see IQuery
*
* @author alex
* @version 0.1
* @since 2020-05-15
*/
interface IQueryApp<TView, TKey> : IApplication {
/**
* 查询服务
*/
var query: IQuery<TView, TKey>?
@GetMapping("/{key:.+}")
fun get(@PathVariable key: TKey): HttpMessage {
return this.safeExecute("获取${this.name}数据失败") {
if (this.query != null)
it.data = this.query!!.get(key)
else {
it.status = Status.Error
it.message = "没有对应服务,无法执行该操作"
}
}
return this.doGet(key)
}
@GetMapping
fun list(@RequestParam parameters: MutableMap<String, Any>): HttpMessage {
return this.safeExecute("获取${this.name}列表数据失败") {
if (this.query != null)
it.data = this.query!!.list(parameters)
else {
it.status = Status.Error
it.message = "没有对应服务,无法执行该操作"
}
}
fun list(@RequestParam params: MutableMap<String, Any>): HttpMessage {
return this.doList(params)
}
@GetMapping("/segments/{size}/pages/{page}")
fun paging(@PathVariable size: Int, @PathVariable page: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
return this.safeExecute("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
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 = "没有对应服务,无法执行该操作"
}
}
return this.doPaging(size, page, parameters)
}
}
/**
* 实际查询单条数据逻辑
*
* @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
}

View File

@@ -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 = "没有对应服务,无法执行该操作"
}
}
}
}

View File

@@ -5,9 +5,6 @@ import com.synebula.gaea.app.component.HttpMessage
import com.synebula.gaea.data.message.Status
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服务的接口.
@@ -17,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam
* @version 0.1
* @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>
@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 = "没有对应服务,无法执行该操作"
}
override fun doGet(key: TKey): HttpMessage {
return this.doQuery("获取${this.name}数据失败") {
this.query!!.get(key, viewClass)
}
}
@GetMapping
fun list(@RequestParam parameters: MutableMap<String, Any>): HttpMessage {
return this.safeExecute("获取${this.name}列表数据失败") {
if (this.query != null)
it.data = this.query!!.list(parameters, viewClass)
else {
it.status = Status.Error
it.message = "没有对应服务,无法执行该操作"
}
override fun doList(params: Map<String, Any>): HttpMessage {
return this.doQuery("获取${this.name}列表数据失败") {
this.query!!.list(params, viewClass)
}
}
@GetMapping("/split/{size}/pages/{page}")
fun paging(@PathVariable page: Int, @PathVariable size: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
return this.safeExecute("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
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, viewClass)
}
}
/**
* 抽取查询业务判断功能
*
* @param error 错误消息
* @param biz 业务执行逻辑
*/
fun doQuery(error: String, biz: (() -> Any?)): HttpMessage {
return this.safeExecute(error) {
if (this.query != null) {
val params = PagingParam(page, size)
params.parameters = parameters
it.data = this.query!!.paging(params, viewClass)
it.data = biz()
} else {
it.status = Status.Error
it.message = "没有对应服务,无法执行该操作"
}
}
}
}

View File

@@ -10,8 +10,8 @@ import com.synebula.gaea.query.IQuery
* @param query 业务查询服务
* @param logger 日志组件
*/
open class QueryApp<TView, TKey>(
open class QueryGenericApp<TView, TKey>(
override var name: String,
override var query: IQuery<TView, TKey>?,
override var logger: ILogger) : IQueryApp<TView, TKey> {
override var logger: ILogger) : IQueryGenericApp<TView, TKey> {
}