From b041775dae4438e428d2b70d2b22cfe8c49844fe Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 19 七月 2022 16:22:36 +0800 Subject: [PATCH] 1. 巡查汇总报告功能编写基本完成 --- src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt | 109 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 98 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt index 5e0d3d4..f10a5be 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt @@ -1,14 +1,101 @@ package cn.flightfeather.supervision.business.report -/** - * 鎶ュ憡妯℃澘鍩虹被 - */ -abstract class BaseTemplate { +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 org.apache.poi.hssf.usermodel.HSSFWorkbook +import tk.mybatis.mapper.entity.Example +import java.io.FileOutputStream +import java.io.OutputStream +import java.util.* - //鍥哄畾鍒楃粍鍚� - //鍚嶇О - //鍩烘湰淇℃伅 - //闂鎵e垎鍒嗗竷 - //闂鏁存敼鍒嗗竷 - //鐩戠璇︽儏 -} \ No newline at end of file +/** + * excel鎶ュ憡妯℃澘鍩虹被 + */ +// FIXME: 2022/7/15 妯℃澘绠�鍖栵細鍙湁琛ㄥご浼氭秹鍙婂崟鍏冩牸鍚堝苟锛岄粯璁よ〃鍐呭涓病鏈夊悎骞� +abstract class BaseTemplate(val dataSource: DataSource){ + + //鍒楃粍鍚� + abstract val cols: List<BaseCols> + + //妯℃澘鍚嶇О + abstract val templateName: String + + //琛ㄥご + val head = mutableListOf<MutableList<ExcelUtil.MyCell>>() + //鍐呭 + val contents = mutableListOf<MutableList<Any>>() + + + open fun execute() { + //鏁版嵁婧愰噸缃� + dataSource.reset() + //鍚堟垚琛ㄥご + cols.forEach { + it.combineHead(head,dataSource) + } + //鍚堟垚鏁版嵁 + dataSource.loop { index, rowData -> + cols.forEach {col -> + val r = col.getOneRow(rowData) + if (index >= contents.size) { + contents.add(mutableListOf()) + } + contents[index].addAll(r) + } + } + } + + fun toWorkBook(wb: HSSFWorkbook) { + val f = tableFormat() + ExcelUtil.write(f.first, f.second, wb, templateName) + } + + fun toOutputStream(out: OutputStream, sheetName: String? = null) { + val f = tableFormat() + ExcelUtil.write2(out, f.first, f.second, sheetName ?: templateName) + } + + /** + * 杈撳嚭涓烘枃妗� + */ + fun toFile(path: String) { + val fileName = "${dataSource.areaName()}-${templateName}-${Date().time}.xls" + val out = FileOutputStream(path + fileName) + toOutputStream(out) + } + + /** + * 琛ㄥご鍜岃〃鍐呭鏍煎紡杞寲 + */ + private fun tableFormat(): Pair<MutableList<Array<Any>>, MutableList<Array<Any>>> { + val h = mutableListOf<Array<Any>>() + val c = mutableListOf<Array<Any>>() + head.forEach { h.add(it.toTypedArray()) } + contents.forEach { c.add(it.toTypedArray()) } + val index = c[0][0] + if (index is Int) { + c.sortBy { + if (it[0] is Int) { + it[0] as Int + } else { + 0 + } + } + } else { + c.sortBy { + it[0].toString() + } + } + return Pair(h, c) + } +} + +//鍥哄畾鍒楃粍鍚� + + +//鍩烘湰淇℃伅 +//闂鎵e垎鍒嗗竷 + + -- Gitblit v1.9.3