重构Gaea服务, 升级版本

This commit is contained in:
2020-07-07 15:07:27 +08:00
parent 0d747f92b2
commit 66869fd34e
26 changed files with 139 additions and 409 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.IQueryTypedApp
import com.synebula.gaea.app.query.IQueryApp
import com.synebula.gaea.data.serialization.json.IJsonSerializer
import com.synebula.gaea.domain.service.ICommand
import com.synebula.gaea.domain.service.IService
@@ -17,13 +17,13 @@ import javax.annotation.Resource
* @param query 业务查询服务
* @param logger 日志组件
*/
open class UnionApp<TCommand : ICommand, TView, TKey>(
open class Application<TCommand : ICommand, TView, TKey>(
override var name: String,
override var clazz: Class<TView>,
override var service: IService<TKey>?,
override var query: IQuery?,
override var logger: ILogger)
: ICommandApp<TCommand, TKey>, IQueryTypedApp<TView, TKey> {
override var logger: ILogger?
) : ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {
@Resource
override var jsonSerializer: IJsonSerializer? = null

View File

@@ -14,7 +14,7 @@ interface IApplication {
/**
* 日志组件
*/
var logger: ILogger
var logger: ILogger?
/**
@@ -24,11 +24,11 @@ interface IApplication {
val msg = HttpMessage(Status.Success)
try {
process(msg)
logger.debug(this, "$name business execute success")
logger?.debug(this, "$name business execute success")
} catch (ex: Exception) {
msg.status = Status.Error
msg.message = if (error.isEmpty()) ex.message ?: "" else error
logger.error(this, ex, "$error: ${ex.message}")
logger?.error(this, ex, "$error: ${ex.message}")
}
return msg
}
@@ -40,9 +40,9 @@ interface IApplication {
val msg = HttpMessage(Status.Success)
try {
process(msg)
logger.debug(this, "$name business execute success")
logger?.debug(this, "$name business execute success")
} catch (ex: Exception) {
logger.error(this, ex, "$error。异常消息将抛出!: ${ex.message}")
logger?.error(this, ex, "$error。异常消息将抛出!: ${ex.message}")
throw RuntimeException(error, ex)
}
return msg

View File

@@ -1,25 +0,0 @@
package com.synebula.gaea.app
import com.synebula.gaea.app.component.HttpMessage
/**
* 用户登入登出接口定义
*/
interface ISignInOut {
/**
* 定义登录方法。
*
* @param name 登录名
* @param password 登录密码
* @return StatusMessage, data 内容为 map 其中 key account中存储用户账户名称
*/
fun signIn(name: String, password: String): HttpMessage
/**
* 登出
*
* @param user 登出的用户
*/
fun signOut(user: String): HttpMessage
}

View File

@@ -1,29 +0,0 @@
package com.synebula.gaea.app
import com.synebula.gaea.app.cmd.ICommandApp
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
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.IGenericQuery
import javax.annotation.Resource
/**
* 联合服务同时实现了ICommandApp和IQueryApp接口
*
* @param name 业务名称
* @param service 业务domain服务
* @param query 业务查询服务
* @param logger 日志组件
*/
open class UnionGenericApp<TCommand : ICommand, TView, TKey>(
override var name: String,
override var service: IService<TKey>?,
override var query: IGenericQuery<TView, TKey>?,
override var logger: ILogger
) : ICommandApp<TCommand, TKey>, IQueryGenericApp<TView, TKey> {
@Resource
override var jsonSerializer: IJsonSerializer? = null
}

View File

@@ -16,7 +16,7 @@ import javax.annotation.Resource
open class CommandApp<TCommand : ICommand, TKey>(
override var name: String,
override var service: IService<TKey>?,
override var logger: ILogger) : ICommandApp<TCommand, TKey> {
override var logger: ILogger?) : ICommandApp<TCommand, TKey> {
@Resource
override var jsonSerializer: IJsonSerializer? = null
}

View File

@@ -1,6 +1,5 @@
package com.synebula.gaea.app.component
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.data.message.Message
class HttpMessage() : Message<Any>() {

View File

@@ -2,50 +2,66 @@ 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.Params
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestParam
interface IQueryApp<TView, TKey> : IApplication {
/**
* 查询服务
*/
var query: IQuery?
/**
* 查询的View类型
*/
var clazz: Class<TView>
@GetMapping("/{key:.+}")
fun get(@PathVariable key: TKey): HttpMessage {
return this.doGet(key)
return this.doQuery("获取${this.name}数据失败") {
this.query!!.get(key, clazz)
}
}
@GetMapping
fun list(@RequestParam params: MutableMap<String, Any>): HttpMessage {
return this.doList(params)
return this.doQuery("获取${this.name}列表数据失败") {
this.query!!.list(params, clazz)
}
}
@GetMapping("/segments/{size}/pages/{page}")
fun paging(@PathVariable size: Int, @PathVariable page: Int, @RequestParam parameters: MutableMap<String, Any>): HttpMessage {
return this.doPaging(size, page, parameters)
fun paging(
@PathVariable size: Int,
@PathVariable page: Int,
@RequestParam parameters: MutableMap<String, Any>
): HttpMessage {
return this.doQuery("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
val data = Params(page, size)
data.parameters = parameters
this.query!!.paging(data, clazz)
}
}
/**
* 实际查询单条数据逻辑
* 抽取查询业务判断功能
*
* @param key 数据的主键
* @param error 错误消息
* @param biz 业务执行逻辑
*/
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
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

@@ -1,63 +0,0 @@
package com.synebula.gaea.app.query
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.Params
/**
* 应用类接口提供实现Query服务的接口.
* 依赖查询接口 @see IQueryTyped
*
* @author alex
* @version 0.1
* @since 2020-05-15
*/
interface IQueryTypedApp<TView, TKey> : IQueryApp<TView, TKey> {
/**
* 查询服务
*/
var query: IQuery?
/**
* 查询的View类型
*/
var clazz: Class<TView>
override fun doGet(key: TKey): HttpMessage {
return this.doQuery("获取${this.name}数据失败") {
this.query!!.get(key, clazz)
}
}
override fun doList(params: Map<String, Any>): HttpMessage {
return this.doQuery("获取${this.name}列表数据失败") {
this.query!!.list(params, clazz)
}
}
override fun doPaging(size: Int, page: Int, params: MutableMap<String, Any>): HttpMessage {
return this.doQuery("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
val data = Params(page, size)
data.parameters = params
this.query!!.paging(data, clazz)
}
}
/**
* 抽取查询业务判断功能
*
* @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

@@ -1,9 +1,13 @@
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.IGenericQuery
import com.synebula.gaea.query.ISpecificQuery
import com.synebula.gaea.query.Params
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestParam
/**
* 应用类接口提供实现Query服务的接口
@@ -13,50 +17,40 @@ import com.synebula.gaea.query.Params
* @version 0.1
* @since 2020-05-15
*/
interface IQueryGenericApp<TView, TKey> : IQueryApp<TView, TKey> {
interface ISpecificQueryApp<TView, TKey> : IApplication {
/**
* 查询服务
*/
var query: IGenericQuery<TView, TKey>?
var query: ISpecificQuery<TView, TKey>?
/**
* 实际查询单条数据逻辑
*
* @param key 数据的主键
*/
override fun doGet(key: TKey): HttpMessage {
@GetMapping("/{key:.+}")
fun get(@PathVariable key: TKey): HttpMessage {
return this.doQuery("获取${this.name}数据失败") {
this.query!!.get(key)
}
}
/**
* 实际查询列表逻辑
*
* @param params 查询参数
*/
override fun doList(params: Map<String, Any>): HttpMessage {
@GetMapping
fun list(@RequestParam params: MutableMap<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 {
@GetMapping("/segments/{size}/pages/{page}")
fun paging(
@PathVariable size: Int,
@PathVariable page: Int,
@RequestParam parameters: MutableMap<String, Any>
): HttpMessage {
return this.doQuery("获取${this.name}分页数据[条数:$size,页码:$page]失败") {
val data = Params(page, size)
data.parameters = params
data.parameters = parameters
this.query!!.paging(data)
}
}
/**
* 抽取查询业务判断功能
*
@@ -73,5 +67,4 @@ interface IQueryGenericApp<TView, TKey> : IQueryApp<TView, TKey> {
}
}
}
}

View File

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

View File

@@ -1,18 +0,0 @@
package com.synebula.gaea.app.query
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.IGenericQuery
/**
* 联合服务同时实现了ICommandApp和IQueryApp接口
*
* @param name 业务名称
* @param genericQuery 业务查询服务
* @param logger 日志组件
*/
open class QueryGenericApp<TView, TKey>(
override var name: String,
override var query: IGenericQuery<TView, TKey>?,
override var logger: ILogger
) : IQueryGenericApp<TView, TKey> {
}

View File

@@ -0,0 +1,17 @@
package com.synebula.gaea.app.query
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.ISpecificQuery
/**
* 联合服务同时实现了ICommandApp和IQueryApp接口
*
* @param name 业务名称
* @param query 业务查询服务
* @param logger 日志组件
*/
open class SpecificQueryApp<TView, TKey>(
override var name: String,
override var query: ISpecificQuery<TView, TKey>?,
override var logger: ILogger?
) : ISpecificQueryApp<TView, TKey>