From dee7694cc40f4440e85521fe1130ef87f7664aa1 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 25 May 2021 15:27:39 +0800 Subject: [PATCH] =?UTF-8?q?0.13.0=20=E4=BF=AE=E6=94=B9service=E3=80=81quer?= =?UTF-8?q?y=E5=BC=95=E7=94=A8=E4=B8=8D=E5=8F=AF=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=EF=BC=9B=E6=B8=85=E7=90=86=E4=BB=A3=E7=A0=81import=EF=BC=9B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E9=80=9A=E7=9F=A5=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=8C=E5=8F=AF=E5=AE=9A=E4=B9=89=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=BB=99=E7=94=A8=E6=88=B7=E7=9A=84=E5=BC=82=E5=B8=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../com/synebula/gaea/app/Application.kt | 4 +- .../com/synebula/gaea/app/cmd/CommandApp.kt | 7 ++-- .../com/synebula/gaea/app/cmd/ICommandApp.kt | 36 +++++----------- .../gaea/app/component/aop/AppAspect.kt | 28 ++++++++----- .../aop/handler/AnnotationHandler.kt | 1 - .../synebula/gaea/app/component/poi/Excel.kt | 5 ++- .../app/component/security/WebSecurity.kt | 1 - .../com/synebula/gaea/app/query/IQueryApp.kt | 41 +++++-------------- .../com/synebula/gaea/app/query/QueryApp.kt | 2 +- .../synebula/gaea/data/cache/CacheEntity.kt | 2 +- .../com/synebula/gaea/data/code/DateCode.kt | 2 +- .../gaea/data/code/FixedRandomCode.kt | 2 +- .../com/synebula/gaea/data/code/GUIDCode.kt | 2 +- .../com/synebula/gaea/data/date/Time.kt | 4 +- .../com/synebula/gaea/data/date/TimeSpan.kt | 3 -- .../synebula/gaea/domain/service/Command.kt | 2 - .../gaea/exception/NoticeUserException.kt | 6 +++ .../com/synebula/gaea/io/scan/ClassPath.kt | 3 +- .../com/synebula/gaea/io/scan/ClassScanner.kt | 4 +- 20 files changed, 62 insertions(+), 95 deletions(-) create mode 100644 src/gaea/src/main/kotlin/com/synebula/gaea/exception/NoticeUserException.kt diff --git a/build.gradle b/build.gradle index 1f62688..e75f351 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { subprojects { ext { - version '0.12.2' + version '0.13.0' spring_version = "2.3.0.RELEASE" } diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/Application.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/Application.kt index 329a7df..fdcbd6d 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/Application.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/Application.kt @@ -20,8 +20,8 @@ import javax.annotation.Resource open class Application( override var name: String, override var clazz: Class, - override var service: IService?, - override var query: IQuery?, + override var service: IService, + override var query: IQuery, override var logger: ILogger? ) : ICommandApp, IQueryApp { diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/CommandApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/CommandApp.kt index 94c82c7..78860e9 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/CommandApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/CommandApp.kt @@ -14,9 +14,10 @@ import javax.annotation.Resource * @param logger 日志组件 */ open class CommandApp( - override var name: String, - override var service: IService?, - override var logger: ILogger?) : ICommandApp { + override var name: String, + override var service: IService, + override var logger: ILogger? +) : ICommandApp { @Resource override var jsonSerializer: IJsonSerializer? = null } \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/ICommandApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/ICommandApp.kt index 4a4bf4b..e2ffca3 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/ICommandApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/cmd/ICommandApp.kt @@ -1,8 +1,8 @@ package com.synebula.gaea.app.cmd 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.struct.HttpMessage import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.serialization.json.IJsonSerializer import com.synebula.gaea.domain.service.ICommand @@ -19,33 +19,21 @@ import org.springframework.web.bind.annotation.* interface ICommandApp : IApplication { var jsonSerializer: IJsonSerializer? - var service: IService? + var service: IService @PostMapping @MethodName("添加") fun add(@RequestBody command: TCommand): HttpMessage { - val msg = HttpMessage() - if (this.service != null) { - msg.load(this.service!!.add(command)) - } else { - msg.status = Status.Error - msg.message = "没有对应服务,无法执行该操作" - } + val msg = HttpMessage(this.service.add(command)) return msg } @PutMapping("/{id:.+}") @MethodName("更新") fun update(@PathVariable id: TKey, @RequestBody command: TCommand): HttpMessage { - val msg = HttpMessage() - if (this.service != null) - this.service!!.update(id, command) - else { - msg.status = Status.Error - msg.message = "没有对应服务,无法执行该操作" - } - return msg + this.service.update(id, command) + return HttpMessage() } @@ -53,17 +41,13 @@ interface ICommandApp : IApplication { @MethodName("删除") fun remove(@PathVariable id: TKey): HttpMessage { val msg = HttpMessage() - if (this.service != null) - try { - msg.data = this.service!!.remove(id) - } catch (ex: IllegalStateException) { - msg.status = Status.Error - msg.message = ex.message ?: "" - } - else { + try { + msg.data = this.service.remove(id) + } catch (ex: IllegalStateException) { msg.status = Status.Error - msg.message = "没有对应服务,无法执行该操作" + msg.message = ex.message ?: "" } + return msg } } diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/AppAspect.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/AppAspect.kt index b0272db..0aa80b6 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/AppAspect.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/AppAspect.kt @@ -1,22 +1,19 @@ package com.synebula.gaea.app.component.aop -import com.fasterxml.jackson.databind.ObjectMapper import com.google.gson.Gson 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.MethodName 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.exception.NoticeUserException import com.synebula.gaea.log.ILogger -import org.aspectj.lang.JoinPoint import org.aspectj.lang.ProceedingJoinPoint -import org.aspectj.lang.annotation.AfterThrowing import org.aspectj.lang.annotation.Around import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.core.DefaultParameterNameDiscoverer -import org.springframework.web.multipart.MultipartFile abstract class AppAspect { private var paramDiscover = DefaultParameterNameDiscoverer() @@ -74,11 +71,20 @@ abstract class AppAspect { moduleName = name.value } } - val message = "$moduleName - $funcName 异常" - logger.error(ex, - "$message。Method args ${ - paramDiscover.getParameterNames(func)?.contentToString()} values is ${ - gson.toJson(point.args)}" + var message = "$moduleName - $funcName 异常" + if (ex is NoticeUserException) { + message = "$message: ${ex.message}" + } else { + message = "$message。如多次遇到,请联系开发人员。" + + } + logger.error( + ex, + "$message。Method args ${ + paramDiscover.getParameterNames(func)?.contentToString() + } values is ${ + gson.toJson(point.args) + }" ) return HttpMessage(Status.Error, message) } diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/handler/AnnotationHandler.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/handler/AnnotationHandler.kt index ea1c4aa..fbd2a37 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/handler/AnnotationHandler.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/aop/handler/AnnotationHandler.kt @@ -1,6 +1,5 @@ package com.synebula.gaea.app.component.aop.handler -import java.lang.Exception import java.lang.reflect.Method interface AnnotationHandler { diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/poi/Excel.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/poi/Excel.kt index 4714a41..b8e2626 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/poi/Excel.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/poi/Excel.kt @@ -2,6 +2,7 @@ package com.synebula.gaea.app.component.poi import com.synebula.gaea.app.struct.ExcelData import com.synebula.gaea.data.date.DateTime +import com.synebula.gaea.exception.NoticeUserException import org.apache.poi.hpsf.Decimal import org.apache.poi.hssf.usermodel.HSSFCell import org.apache.poi.hssf.usermodel.HSSFCellStyle @@ -214,7 +215,7 @@ object Excel { } ): List> { if (file.originalFilename?.endsWith(".xls") != true && file.originalFilename?.endsWith(".xlsx") != true) - throw RuntimeException("无法识别的文件格式[${file.originalFilename}]") + throw NoticeUserException("无法识别的文件格式[${file.originalFilename}]") val evaluator: BaseFormulaEvaluator val workbook = if (file.originalFilename?.endsWith(".xls") == true) { val wb = HSSFWorkbook(file.inputStream) @@ -250,7 +251,7 @@ object Excel { val value = getCellValue(cell, evaluator) rowData[title] = value.toString() } 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) diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/security/WebSecurity.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/security/WebSecurity.kt index 3efed1f..c0f6f3c 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/security/WebSecurity.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/security/WebSecurity.kt @@ -13,7 +13,6 @@ import org.springframework.stereotype.Component import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.CorsConfigurationSource import org.springframework.web.cors.UrlBasedCorsConfigurationSource -import java.util.* @Component diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/IQueryApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/IQueryApp.kt index c6e534a..ff5ded0 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/IQueryApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/IQueryApp.kt @@ -1,9 +1,8 @@ package com.synebula.gaea.app.query 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.data.message.Status +import com.synebula.gaea.app.struct.HttpMessage import com.synebula.gaea.query.IQuery import com.synebula.gaea.query.Params import org.springframework.web.bind.annotation.GetMapping @@ -14,7 +13,7 @@ interface IQueryApp : IApplication { /** * 查询服务 */ - var query: IQuery? + var query: IQuery /** * 查询的View类型 @@ -24,17 +23,17 @@ interface IQueryApp : IApplication { @MethodName("获取数据") @GetMapping("/{id:.+}") fun get(@PathVariable id: TKey): HttpMessage { - return this.doQuery { - this.query!!.get(id, clazz) - } + val data = this.query.get(id, clazz) + val msg = HttpMessage() + msg.data = data + return msg } @MethodName("获取列表数据") @GetMapping fun list(@RequestParam params: LinkedHashMap): HttpMessage { - return this.doQuery { - this.query!!.list(params, clazz) - } + val data = this.query.list(params, clazz) + return HttpMessage(data) } @MethodName("获取分页数据") @@ -44,26 +43,8 @@ interface IQueryApp : IApplication { @PathVariable page: Int, @RequestParam parameters: LinkedHashMap ): HttpMessage { - return this.doQuery { - val data = Params(page, size, parameters) - this.query!!.paging(data, clazz) - } - } - - - /** - * 抽取查询业务判断功能 - * - * @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 + val params = Params(page, size, parameters) + val data = this.query.paging(params, clazz) + return HttpMessage(data) } } \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/QueryApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/QueryApp.kt index d8760fc..7b1a295 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/QueryApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/query/QueryApp.kt @@ -13,6 +13,6 @@ import com.synebula.gaea.query.IQuery open class QueryApp( override var name: String, override var clazz: Class, - override var query: IQuery?, + override var query: IQuery, override var logger: ILogger? ) : IQueryApp \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/cache/CacheEntity.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/cache/CacheEntity.kt index 7d30454..3272bbf 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/cache/CacheEntity.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/cache/CacheEntity.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.data.cache -import java.util.Date +import java.util.* /** * diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/DateCode.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/DateCode.kt index 7d603a1..4afe5e4 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/DateCode.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/DateCode.kt @@ -1,7 +1,7 @@ package com.synebula.gaea.data.code import java.text.SimpleDateFormat -import java.util.Date +import java.util.* /** * @author alex diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/FixedRandomCode.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/FixedRandomCode.kt index 49a5562..001657b 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/FixedRandomCode.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/FixedRandomCode.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.data.code -import java.util.Random +import java.util.* /** * 固定长度随机编号生成。 diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/GUIDCode.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/GUIDCode.kt index a24406f..9aad658 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/GUIDCode.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/code/GUIDCode.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.data.code -import java.util.UUID +import java.util.* /** * 全球唯一编号生成。 diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/Time.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/Time.kt index 73a3543..5f676f7 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/Time.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/Time.kt @@ -1,10 +1,8 @@ package com.synebula.gaea.data.date -import java.math.BigDecimal import java.text.ParseException import java.text.SimpleDateFormat -import java.util.Calendar -import java.util.Date +import java.util.* /** diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/TimeSpan.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/TimeSpan.kt index bc2c2fe..6d8505b 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/TimeSpan.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/data/date/TimeSpan.kt @@ -6,9 +6,6 @@ */ package com.synebula.gaea.data.date -import java.math.BigDecimal -import java.util.* - /** * * @author whj diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Command.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Command.kt index b0f3e75..2c07161 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Command.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Command.kt @@ -1,7 +1,5 @@ package com.synebula.gaea.domain.service -import java.util.* - /** * 命令基础实现类,发给service的命令。 * diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/exception/NoticeUserException.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/exception/NoticeUserException.kt new file mode 100644 index 0000000..fff4d1a --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/exception/NoticeUserException.kt @@ -0,0 +1,6 @@ +package com.synebula.gaea.exception + +/** + * 需要通知给用户的异常 + */ +class NoticeUserException(message: String, cause: Exception? = null) : Exception(message, cause) \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassPath.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassPath.kt index a62caba..7aa60b5 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassPath.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassPath.kt @@ -2,8 +2,7 @@ package com.synebula.gaea.io.scan import java.io.IOException import java.net.URL -import java.util.Enumeration -import java.util.HashSet +import java.util.* /** * diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassScanner.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassScanner.kt index fb1b904..3b03ef0 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassScanner.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/io/scan/ClassScanner.kt @@ -5,9 +5,7 @@ import java.io.FileFilter import java.io.UnsupportedEncodingException import java.net.URLDecoder import java.nio.charset.Charset -import java.util.Collections -import java.util.HashSet -import java.util.LinkedList +import java.util.* import java.util.jar.JarFile /**