From 274bc2d0f7fe8fe7525196e4d7d6ece1cafe2c6c Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期日, 04 二月 2024 17:32:14 +0800 Subject: [PATCH] 1. 新增静安50分制评估结果转换逻辑; 2. 新增根据坐标圆心和半径查询范围内场景逻辑; --- src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt | 104 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 93 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..fefb508 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,96 @@ 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) : BaseOutputInterface { + + //鍒楃粍鍚� + 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) + } + } + } + + override fun toWorkBook(wb: HSSFWorkbook) { + val f = tableFormat() + ExcelUtil.write(f.first, f.second, wb, templateName) + } + + override fun toOutputStream(out: OutputStream, sheetName: String?) { + val f = tableFormat() + ExcelUtil.write2(out, f.first, f.second, sheetName ?: templateName) + } + + /** + * 杈撳嚭涓烘枃妗� + */ + override fun toFile(path: String) { + val fileName = "${dataSource.areaName()}-${templateName}-${Date().time}.xls" + val out = FileOutputStream(path + fileName) + toOutputStream(out) + } + + /** + * 琛ㄥご鍜岃〃鍐呭鏍煎紡杞寲 + */ + 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) + } +} -- Gitblit v1.9.3