0.13.0 修改service、query引用不可为空;清理代码import;增加用户通知异常,可定义通知给用户的异常信息
This commit is contained in:
@@ -21,7 +21,7 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
ext {
|
||||
version '0.12.2'
|
||||
version '0.13.0'
|
||||
spring_version = "2.3.0.RELEASE"
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import javax.annotation.Resource
|
||||
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 service: IService<TKey>,
|
||||
override var query: IQuery,
|
||||
override var logger: ILogger?
|
||||
) : ICommandApp<TCommand, TKey>, IQueryApp<TView, TKey> {
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@ import javax.annotation.Resource
|
||||
* @param logger 日志组件
|
||||
*/
|
||||
open class CommandApp<TCommand : ICommand, TKey>(
|
||||
override var name: String,
|
||||
override var service: IService<TKey>?,
|
||||
override var logger: ILogger?) : ICommandApp<TCommand, TKey> {
|
||||
override var name: String,
|
||||
override var service: IService<TKey>,
|
||||
override var logger: ILogger?
|
||||
) : ICommandApp<TCommand, TKey> {
|
||||
@Resource
|
||||
override var jsonSerializer: IJsonSerializer? = null
|
||||
}
|
||||
@@ -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<TCommand : ICommand, TKey> : IApplication {
|
||||
var jsonSerializer: IJsonSerializer?
|
||||
|
||||
var service: IService<TKey>?
|
||||
var service: IService<TKey>
|
||||
|
||||
|
||||
@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<TCommand : ICommand, TKey> : 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.synebula.gaea.app.component.aop.handler
|
||||
|
||||
import java.lang.Exception
|
||||
import java.lang.reflect.Method
|
||||
|
||||
interface AnnotationHandler {
|
||||
|
||||
@@ -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<Map<String, String>> {
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<TView, TKey> : IApplication {
|
||||
/**
|
||||
* 查询服务
|
||||
*/
|
||||
var query: IQuery?
|
||||
var query: IQuery
|
||||
|
||||
/**
|
||||
* 查询的View类型
|
||||
@@ -24,17 +23,17 @@ interface IQueryApp<TView, TKey> : 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<String, Any>): 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<TView, TKey> : IApplication {
|
||||
@PathVariable page: Int,
|
||||
@RequestParam parameters: LinkedHashMap<String, Any>
|
||||
): 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)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ import com.synebula.gaea.query.IQuery
|
||||
open class QueryApp<TView, TKey>(
|
||||
override var name: String,
|
||||
override var clazz: Class<TView>,
|
||||
override var query: IQuery?,
|
||||
override var query: IQuery,
|
||||
override var logger: ILogger?
|
||||
) : IQueryApp<TView, TKey>
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.data.cache
|
||||
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.data.code
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author alex
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.data.code
|
||||
|
||||
import java.util.Random
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 固定长度随机编号生成。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.data.code
|
||||
|
||||
import java.util.UUID
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 全球唯一编号生成。
|
||||
|
||||
@@ -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.*
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
*/
|
||||
package com.synebula.gaea.data.date
|
||||
|
||||
import java.math.BigDecimal
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
*
|
||||
* @author whj
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 命令基础实现类,发给service的命令。
|
||||
*
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.synebula.gaea.exception
|
||||
|
||||
/**
|
||||
* 需要通知给用户的异常
|
||||
*/
|
||||
class NoticeUserException(message: String, cause: Exception? = null) : Exception(message, cause)
|
||||
@@ -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.*
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user