0.2.1 增加gaea.app gaea.mongo模块功能
This commit is contained in:
18
src/gaea.app/build.gradle
Normal file
18
src/gaea.app/build.gradle
Normal file
@@ -0,0 +1,18 @@
|
||||
dependencies {
|
||||
compile project(":src:gaea")
|
||||
compile("org.springframework.boot:spring-boot-starter-web:$spring_version")
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
||||
compile group: 'net.sf.dozer', name: 'dozer', version: '5.5.1'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
group 'com.synebula'
|
||||
artifactId 'gaea.app'
|
||||
version "$version"
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
interface IApplication {
|
||||
|
||||
/**
|
||||
* 业务名称
|
||||
*/
|
||||
var name: String
|
||||
|
||||
/**
|
||||
* 日志组件
|
||||
*/
|
||||
var logger: ILogger
|
||||
|
||||
|
||||
/**
|
||||
* 安全执行
|
||||
*/
|
||||
fun safeExecute(error: String, process: ((msg: HttpMessage) -> Unit)): HttpMessage {
|
||||
val msg = HttpMessage(Status.Success)
|
||||
try {
|
||||
process(msg)
|
||||
logger.debug("$name business execute success")
|
||||
} catch (ex: Exception) {
|
||||
msg.status = Status.Error
|
||||
msg.message = if (error.isEmpty()) ex.message ?: "" else error
|
||||
msg.data = ex.message
|
||||
logger.error(ex, "$error: ${ex.message}")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
/**
|
||||
* 可抛出自定义异常信息的安全controller实现了异常捕获和消息组成。
|
||||
*/
|
||||
fun throwExecute(error: String, process: ((msg: HttpMessage) -> Unit)): HttpMessage {
|
||||
val msg = HttpMessage(Status.Success)
|
||||
try {
|
||||
process(msg)
|
||||
logger.debug("$name business execute success")
|
||||
} catch (ex: Exception) {
|
||||
logger.error(ex, "$error。异常消息将抛出!: ${ex.message}")
|
||||
throw RuntimeException(error, ex)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
/**
|
||||
* 应用类接口,提供向Command服务的接口
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2018 18-2-8
|
||||
*/
|
||||
interface ICommandApp<TCommand : ICommand, TKey> : IApplication {
|
||||
|
||||
var service: IService<TKey>?
|
||||
|
||||
@PostMapping
|
||||
fun add(@RequestBody command: TCommand): HttpMessage {
|
||||
return this.throwExecute("${this.name}添加失败") {
|
||||
if (this.service != null) {
|
||||
val msg = this.service!!.add(command)
|
||||
it.load(msg)
|
||||
} else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{key:.+}")
|
||||
fun remove(@PathVariable key: TKey): HttpMessage {
|
||||
return this.throwExecute("${this.name}删除失败") {
|
||||
if (this.service != null)
|
||||
it.data = this.service!!.remove(key)
|
||||
else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{key:.+}")
|
||||
fun update(@PathVariable key: TKey, @RequestBody command: TCommand): HttpMessage {
|
||||
return this.throwExecute("${this.name}更新失败") {
|
||||
if (this.service != null)
|
||||
this.service!!.update(key, command)
|
||||
else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ILogin.kt
Normal file
15
src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ILogin.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
|
||||
|
||||
interface ILogin {
|
||||
/**
|
||||
* 定义登录方法。
|
||||
*
|
||||
* @param name 登录名
|
||||
* @param password 登录密码
|
||||
* @return StatusMessage, data 内容为 map 其中 key account中存储用户账户名称
|
||||
*/
|
||||
fun login(name: String, password: String): Message<Any>
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.app.components.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服务的接口
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2018 18-2-8
|
||||
*/
|
||||
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 = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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(params)
|
||||
} else {
|
||||
it.status = Status.Error
|
||||
it.message = "没有对应服务,无法执行该操作"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.synebula.gaea.app.components
|
||||
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.data.message.Message
|
||||
|
||||
class HttpMessage(status: Int = Status.Success) : Message<Any>(status) {
|
||||
fun load(msg: Message<*>) {
|
||||
this.status = msg.status
|
||||
this.message = msg.message
|
||||
this.data = msg.data
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user