| | |
| | | package cn.flightfeather.supervision.business.report |
| | | |
| | | import cn.flightfeather.supervision.common.utils.Constant |
| | | import cn.flightfeather.supervision.common.utils.DateUtil |
| | | import cn.flightfeather.supervision.common.utils.ExcelUtil |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Problemlist |
| | | import cn.flightfeather.supervision.business.report.bean.BaseTemplateResult |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.io.FileOutputStream |
| | | import java.io.OutputStream |
| | | import java.util.* |
| | | import kotlin.reflect.full.createInstance |
| | | |
| | | /** |
| | | * excel报告模板基类 |
| | |
| | | //模板名称 |
| | | abstract val templateName: String |
| | | |
| | | // 中间结果对象 by hc 2024.12.5 |
| | | abstract var resultObjects: MutableList<BaseTemplateResult> |
| | | |
| | | // 执行状态 by hc 2024.12.5 |
| | | var isExecuted: Boolean = false |
| | | |
| | | //表头 |
| | | val head = mutableListOf<MutableList<ExcelUtil.MyCell>>() |
| | | |
| | | //内容 |
| | | val contents = mutableListOf<MutableList<Any>>() |
| | | |
| | | |
| | | open fun execute() { |
| | | // 生成Template相关数据 by hc 2024.12.9 |
| | | open fun genData() { |
| | | //数据源重置 |
| | | dataSource.reset() |
| | | //合成表头 |
| | |
| | | } |
| | | } |
| | | |
| | | open fun execute() { |
| | | try { |
| | | genData() |
| | | // 没有错误正常运行结束 |
| | | isExecuted = true |
| | | } catch (e: Exception) { |
| | | // TODO: handle exception |
| | | } |
| | | } |
| | | |
| | | override fun toWorkBook(wb: HSSFWorkbook) { |
| | | val f = tableFormat() |
| | | ExcelUtil.write(f.first, f.second, wb, templateName) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 输出到对象 |
| | | * hc 2024.12.06 |
| | | */ |
| | | fun toObject(): MutableList<BaseTemplateResult> { |
| | | if (!isExecuted) { |
| | | execute() |
| | | } |
| | | // 获得和template对应的中间结果数据对象KCLASS对象 |
| | | val classType = resultObjects.first()::class |
| | | try { |
| | | // 清空数组 |
| | | resultObjects.clear() |
| | | contents.forEach { |
| | | // 创建对应的中间结果数据对象 |
| | | val resultObj = classType.createInstance() |
| | | resultObj.setProperties(it) |
| | | resultObjects.add(resultObj) |
| | | } |
| | | }catch (e: Exception) { |
| | | // 如果出现异常恢复到初始状态 避免下次调用toObject数据重复 |
| | | resultObjects.clear() |
| | | resultObjects.add(classType.createInstance()) |
| | | } |
| | | return resultObjects |
| | | } |
| | | |
| | | /** |
| | | * 输出为文档 |
| | | */ |
| | | override fun toFile(path: String) { |