0.13.0 修改service、query引用不可为空;清理代码import;增加用户通知异常,可定义通知给用户的异常信息

This commit is contained in:
2021-05-25 15:27:39 +08:00
parent 162a627315
commit dee7694cc4
20 changed files with 62 additions and 95 deletions

View File

@@ -21,7 +21,7 @@ allprojects {
subprojects { subprojects {
ext { ext {
version '0.12.2' version '0.13.0'
spring_version = "2.3.0.RELEASE" spring_version = "2.3.0.RELEASE"
} }

View File

@@ -20,8 +20,8 @@ import javax.annotation.Resource
open class Application<TCommand : ICommand, TView, TKey>( open class Application<TCommand : ICommand, TView, TKey>(
override var name: String, override var name: String,
override var clazz: Class<TView>, override var clazz: Class<TView>,
override var service: IService<TKey>?, override var service: IService<TKey>,
override var query: IQuery?, override var query: IQuery,
override var logger: ILogger? override var logger: ILogger?
) : ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> { ) : ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {

View File

@@ -14,9 +14,10 @@ import javax.annotation.Resource
* @param logger 日志组件 * @param logger 日志组件
*/ */
open class CommandApp<TCommand : ICommand, TKey>( open class CommandApp<TCommand : ICommand, TKey>(
override var name: String, override var name: String,
override var service: IService<TKey>?, override var service: IService<TKey>,
override var logger: ILogger?) : ICommandApp<TCommand, TKey> { override var logger: ILogger?
) : ICommandApp<TCommand, TKey> {
@Resource @Resource
override var jsonSerializer: IJsonSerializer? = null override var jsonSerializer: IJsonSerializer? = null
} }

View File

@@ -1,8 +1,8 @@
package com.synebula.gaea.app.cmd package com.synebula.gaea.app.cmd
import com.synebula.gaea.app.IApplication import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.app.component.aop.annotation.MethodName import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Status
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
@@ -19,33 +19,21 @@ import org.springframework.web.bind.annotation.*
interface ICommandApp<TCommand : ICommand, TKey> : IApplication { interface ICommandApp<TCommand : ICommand, TKey> : IApplication {
var jsonSerializer: IJsonSerializer? var jsonSerializer: IJsonSerializer?
var service: IService<TKey>? var service: IService<TKey>
@PostMapping @PostMapping
@MethodName("添加") @MethodName("添加")
fun add(@RequestBody command: TCommand): HttpMessage { fun add(@RequestBody command: TCommand): HttpMessage {
val msg = HttpMessage() val msg = HttpMessage(this.service.add(command))
if (this.service != null) {
msg.load(this.service!!.add(command))
} else {
msg.status = Status.Error
msg.message = "没有对应服务,无法执行该操作"
}
return msg return msg
} }
@PutMapping("/{id:.+}") @PutMapping("/{id:.+}")
@MethodName("更新") @MethodName("更新")
fun update(@PathVariable id: TKey, @RequestBody command: TCommand): HttpMessage { fun update(@PathVariable id: TKey, @RequestBody command: TCommand): HttpMessage {
val msg = HttpMessage() this.service.update(id, command)
if (this.service != null) return HttpMessage()
this.service!!.update(id, command)
else {
msg.status = Status.Error
msg.message = "没有对应服务,无法执行该操作"
}
return msg
} }
@@ -53,17 +41,13 @@ interface ICommandApp<TCommand : ICommand, TKey> : IApplication {
@MethodName("删除") @MethodName("删除")
fun remove(@PathVariable id: TKey): HttpMessage { fun remove(@PathVariable id: TKey): HttpMessage {
val msg = HttpMessage() val msg = HttpMessage()
if (this.service != null) try {
try { msg.data = this.service.remove(id)
msg.data = this.service!!.remove(id) } catch (ex: IllegalStateException) {
} catch (ex: IllegalStateException) {
msg.status = Status.Error
msg.message = ex.message ?: ""
}
else {
msg.status = Status.Error msg.status = Status.Error
msg.message = "没有对应服务,无法执行该操作" msg.message = ex.message ?: ""
} }
return msg return msg
} }
} }

View File

@@ -1,22 +1,19 @@
package com.synebula.gaea.app.component.aop package com.synebula.gaea.app.component.aop
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.gson.Gson import com.google.gson.Gson
import com.synebula.gaea.app.IApplication import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.component.aop.annotation.Handler import com.synebula.gaea.app.component.aop.annotation.Handler
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.component.aop.annotation.ModuleName import com.synebula.gaea.app.component.aop.annotation.ModuleName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Status
import com.synebula.gaea.exception.NoticeUserException
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.AfterThrowing
import org.aspectj.lang.annotation.Around import org.aspectj.lang.annotation.Around
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContext
import org.springframework.core.DefaultParameterNameDiscoverer import org.springframework.core.DefaultParameterNameDiscoverer
import org.springframework.web.multipart.MultipartFile
abstract class AppAspect { abstract class AppAspect {
private var paramDiscover = DefaultParameterNameDiscoverer() private var paramDiscover = DefaultParameterNameDiscoverer()
@@ -74,11 +71,20 @@ abstract class AppAspect {
moduleName = name.value moduleName = name.value
} }
} }
val message = "$moduleName - $funcName 异常" var message = "$moduleName - $funcName 异常"
logger.error(ex, if (ex is NoticeUserException) {
"$message。Method args ${ message = "$message: ${ex.message}"
paramDiscover.getParameterNames(func)?.contentToString()} values is ${ } else {
gson.toJson(point.args)}" message = "$message。如多次遇到,请联系开发人员。"
}
logger.error(
ex,
"$message。Method args ${
paramDiscover.getParameterNames(func)?.contentToString()
} values is ${
gson.toJson(point.args)
}"
) )
return HttpMessage(Status.Error, message) return HttpMessage(Status.Error, message)
} }

View File

@@ -1,6 +1,5 @@
package com.synebula.gaea.app.component.aop.handler package com.synebula.gaea.app.component.aop.handler
import java.lang.Exception
import java.lang.reflect.Method import java.lang.reflect.Method
interface AnnotationHandler { interface AnnotationHandler {

View File

@@ -2,6 +2,7 @@ package com.synebula.gaea.app.component.poi
import com.synebula.gaea.app.struct.ExcelData import com.synebula.gaea.app.struct.ExcelData
import com.synebula.gaea.data.date.DateTime import com.synebula.gaea.data.date.DateTime
import com.synebula.gaea.exception.NoticeUserException
import org.apache.poi.hpsf.Decimal import org.apache.poi.hpsf.Decimal
import org.apache.poi.hssf.usermodel.HSSFCell import org.apache.poi.hssf.usermodel.HSSFCell
import org.apache.poi.hssf.usermodel.HSSFCellStyle import org.apache.poi.hssf.usermodel.HSSFCellStyle
@@ -214,7 +215,7 @@ object Excel {
} }
): List<Map<String, String>> { ): List<Map<String, String>> {
if (file.originalFilename?.endsWith(".xls") != true && file.originalFilename?.endsWith(".xlsx") != true) if (file.originalFilename?.endsWith(".xls") != true && file.originalFilename?.endsWith(".xlsx") != true)
throw RuntimeException("无法识别的文件格式[${file.originalFilename}]") throw NoticeUserException("无法识别的文件格式[${file.originalFilename}]")
val evaluator: BaseFormulaEvaluator val evaluator: BaseFormulaEvaluator
val workbook = if (file.originalFilename?.endsWith(".xls") == true) { val workbook = if (file.originalFilename?.endsWith(".xls") == true) {
val wb = HSSFWorkbook(file.inputStream) val wb = HSSFWorkbook(file.inputStream)
@@ -250,7 +251,7 @@ object Excel {
val value = getCellValue(cell, evaluator) val value = getCellValue(cell, evaluator)
rowData[title] = value.toString() rowData[title] = value.toString()
} catch (ex: Exception) { } catch (ex: Exception) {
throw RuntimeException("解析EXCEL文件${file.originalFilename}${r + 1}行第${c + 1}列出错", ex) throw NoticeUserException("解析EXCEL文件${file.originalFilename}${r + 1}行第${c + 1}列出错", ex)
} }
} }
data.add(rowData) data.add(rowData)

View File

@@ -13,7 +13,6 @@ import org.springframework.stereotype.Component
import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource import org.springframework.web.cors.CorsConfigurationSource
import org.springframework.web.cors.UrlBasedCorsConfigurationSource import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import java.util.*
@Component @Component

View File

@@ -1,9 +1,8 @@
package com.synebula.gaea.app.query package com.synebula.gaea.app.query
import com.synebula.gaea.app.IApplication import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.app.component.aop.annotation.MethodName import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.data.message.Status import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.query.IQuery import com.synebula.gaea.query.IQuery
import com.synebula.gaea.query.Params import com.synebula.gaea.query.Params
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
@@ -14,7 +13,7 @@ interface IQueryApp<TView, TKey> : IApplication {
/** /**
* 查询服务 * 查询服务
*/ */
var query: IQuery? var query: IQuery
/** /**
* 查询的View类型 * 查询的View类型
@@ -24,17 +23,17 @@ interface IQueryApp<TView, TKey> : IApplication {
@MethodName("获取数据") @MethodName("获取数据")
@GetMapping("/{id:.+}") @GetMapping("/{id:.+}")
fun get(@PathVariable id: TKey): HttpMessage { fun get(@PathVariable id: TKey): HttpMessage {
return this.doQuery { val data = this.query.get(id, clazz)
this.query!!.get(id, clazz) val msg = HttpMessage()
} msg.data = data
return msg
} }
@MethodName("获取列表数据") @MethodName("获取列表数据")
@GetMapping @GetMapping
fun list(@RequestParam params: LinkedHashMap<String, Any>): HttpMessage { fun list(@RequestParam params: LinkedHashMap<String, Any>): HttpMessage {
return this.doQuery { val data = this.query.list(params, clazz)
this.query!!.list(params, clazz) return HttpMessage(data)
}
} }
@MethodName("获取分页数据") @MethodName("获取分页数据")
@@ -44,26 +43,8 @@ interface IQueryApp<TView, TKey> : IApplication {
@PathVariable page: Int, @PathVariable page: Int,
@RequestParam parameters: LinkedHashMap<String, Any> @RequestParam parameters: LinkedHashMap<String, Any>
): HttpMessage { ): HttpMessage {
return this.doQuery { val params = Params(page, size, parameters)
val data = Params(page, size, parameters) val data = this.query.paging(params, clazz)
this.query!!.paging(data, clazz) return HttpMessage(data)
}
}
/**
* 抽取查询业务判断功能
*
* @param biz 业务执行逻辑
*/
fun doQuery(biz: (() -> Any?)): HttpMessage {
val msg = HttpMessage()
if (this.query != null) {
msg.data = biz()
} else {
msg.status = Status.Error
msg.message = "没有对应服务,无法执行该操作"
}
return msg
} }
} }

View File

@@ -13,6 +13,6 @@ import com.synebula.gaea.query.IQuery
open class QueryApp<TView, TKey>( open class QueryApp<TView, TKey>(
override var name: String, override var name: String,
override var clazz: Class<TView>, override var clazz: Class<TView>,
override var query: IQuery?, override var query: IQuery,
override var logger: ILogger? override var logger: ILogger?
) : IQueryApp<TView, TKey> ) : IQueryApp<TView, TKey>

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.data.cache package com.synebula.gaea.data.cache
import java.util.Date import java.util.*
/** /**
* *

View File

@@ -1,7 +1,7 @@
package com.synebula.gaea.data.code package com.synebula.gaea.data.code
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.*
/** /**
* @author alex * @author alex

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.data.code package com.synebula.gaea.data.code
import java.util.Random import java.util.*
/** /**
* 固定长度随机编号生成。 * 固定长度随机编号生成。

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.data.code package com.synebula.gaea.data.code
import java.util.UUID import java.util.*
/** /**
* 全球唯一编号生成。 * 全球唯一编号生成。

View File

@@ -1,10 +1,8 @@
package com.synebula.gaea.data.date package com.synebula.gaea.data.date
import java.math.BigDecimal
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.*
import java.util.Date
/** /**

View File

@@ -6,9 +6,6 @@
*/ */
package com.synebula.gaea.data.date package com.synebula.gaea.data.date
import java.math.BigDecimal
import java.util.*
/** /**
* *
* @author whj * @author whj

View File

@@ -1,7 +1,5 @@
package com.synebula.gaea.domain.service package com.synebula.gaea.domain.service
import java.util.*
/** /**
* 命令基础实现类发给service的命令。 * 命令基础实现类发给service的命令。
* *

View File

@@ -0,0 +1,6 @@
package com.synebula.gaea.exception
/**
* 需要通知给用户的异常
*/
class NoticeUserException(message: String, cause: Exception? = null) : Exception(message, cause)

View File

@@ -2,8 +2,7 @@ package com.synebula.gaea.io.scan
import java.io.IOException import java.io.IOException
import java.net.URL import java.net.URL
import java.util.Enumeration import java.util.*
import java.util.HashSet
/** /**
* *

View File

@@ -5,9 +5,7 @@ import java.io.FileFilter
import java.io.UnsupportedEncodingException import java.io.UnsupportedEncodingException
import java.net.URLDecoder import java.net.URLDecoder
import java.nio.charset.Charset import java.nio.charset.Charset
import java.util.Collections import java.util.*
import java.util.HashSet
import java.util.LinkedList
import java.util.jar.JarFile import java.util.jar.JarFile
/** /**