package cn.flightfeather.supervision.business.report.bean
|
|
import cn.flightfeather.supervision.common.utils.ExcelUtil
|
import kotlin.reflect.KMutableProperty
|
import kotlin.reflect.full.declaredMemberProperties
|
import kotlin.reflect.full.findAnnotation
|
|
/**
|
* excel报告模板中间结果对象基类
|
* hc 2024.12.06
|
*/
|
abstract class BaseTemplateResult {
|
// 定义注解
|
annotation class ExcelHead(val index: Int, val des: String)
|
|
/**
|
* 转换为数据库表对应的实体类对象
|
*/
|
abstract fun convertToDBEntity(): Any
|
|
fun setProperties(values: MutableList<Any>) {
|
// 遍历所有属性并赋值
|
var index = 0
|
this::class.declaredMemberProperties.sortedBy { it.findAnnotation<ExcelHead>()?.index }.forEach { property ->
|
// 检查属性是否可以设置值
|
if (property is KMutableProperty<*>) {
|
try {
|
// 暂存最后的属性值的变量 默认就是values[index]
|
var c: Any = values[index]
|
// 仅仅为了简写values[index]
|
val v = values[index++]
|
// 从MyCell对象中拿出百分比类型
|
if (v is ExcelUtil.MyCell) {
|
if (v.isPercent) {
|
val percent = v.text.toBigDecimalOrNull()
|
if (percent != null) {
|
percent.setScale(2)
|
c = percent
|
}else {
|
c = ""
|
}
|
}
|
}
|
// 向属性中赋值
|
property.setter.call(this, c)
|
} catch (e: Exception) {
|
|
}
|
}
|
}
|
}
|
}
|