From 1a45c6fe9ea814e432cf90c0169be9b7d991a266 Mon Sep 17 00:00:00 2001
From: hcong <1050828145@qq.com>
Date: 星期二, 10 十二月 2024 13:51:00 +0800
Subject: [PATCH] 1. 新增 BaseExcel.kt 和 BaseTemplate.kt 的 toObject输出到对象方法 2. 新增 BaseTemplate 是否执行的状态属性 3. 在cn.flightfeather.supervision.business.report.bean包下新增 BaseTemplateResult.kt 结果对象抽象类 以及 ProAnalysisSummaryResult.kt 和 ProDetailSummaryResult.kt 对应实现:问题整改动态跟踪和分街镇问题整改分析的中间结果对象 注:除了问题整改动态跟踪和分街镇问题整改分析其他的汇总表对象中都没有对应中间结果对象,因此这里还有报错信息
---
src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProAnalysisSummaryResult.kt | 57 +++++++++++
src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProAnalysisSummary.kt | 5
src/main/kotlin/cn/flightfeather/supervision/business/report/bean/BaseTemplateResult.kt | 47 +++++++++
src/main/kotlin/cn/flightfeather/supervision/business/report/BaseExcel.kt | 19 +++
src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt | 53 +++++++++-
src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProDetailSummary.kt | 4
src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProDetailSummaryResult.kt | 94 ++++++++++++++++++
7 files changed, 269 insertions(+), 10 deletions(-)
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseExcel.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseExcel.kt
index e182a98..86d3475 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseExcel.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseExcel.kt
@@ -1,10 +1,10 @@
package cn.flightfeather.supervision.business.report
+import cn.flightfeather.supervision.business.report.bean.BaseTemplateResult
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
-import java.util.*
/**
* 鍚勬ā鏉垮悎骞惰緭鍑轰负鏁翠綋鏂囨。
@@ -16,10 +16,23 @@
abstract val fileName: String
+ // 涓棿缁撴灉瀵硅薄 by hc 2024.12.06
+ private val objectResults: MutableList<MutableList<BaseTemplateResult>> = mutableListOf()
+
// excel鏂囨。
private var workbook = HSSFWorkbook()
fun getReportName(): String = "${dataSource.areaName()}-${fileName}.xlsx"
+
+ // 杈撳嚭鍒板璞�
+ fun toObject() {
+ templates.forEach {
+ if (!it.isExecuted) {
+ it.execute()
+ }
+ objectResults.add(it.toObject())
+ }
+ }
fun toFile(path: String) {
val fileName = getReportName()
@@ -33,7 +46,9 @@
fun toOutputStream(out: OutputStream) {
templates.forEach {
- it.execute()
+ if (!it.isExecuted) {
+ it.execute()
+ }
it.toWorkBook(workbook)
}
workbook.write(out)
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 fefb508..a053d99 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,12 @@
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鎶ュ憡妯℃澘鍩虹被
@@ -23,14 +21,20 @@
//妯℃澘鍚嶇О
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()
//鍚堟垚琛ㄥご
@@ -49,6 +53,16 @@
}
}
+ open fun execute() {
+ try {
+ genData()
+ // 娌℃湁閿欒姝e父杩愯缁撴潫
+ isExecuted = true
+ } catch (e: Exception) {
+ // TODO: handle exception
+ }
+ }
+
override fun toWorkBook(wb: HSSFWorkbook) {
val f = tableFormat()
ExcelUtil.write(f.first, f.second, wb, templateName)
@@ -60,6 +74,33 @@
}
/**
+ * 杈撳嚭鍒板璞�
+ * hc 2024.12.06
+ */
+ fun toObject(): MutableList<BaseTemplateResult> {
+ if (!isExecuted) {
+ execute()
+ }
+ // 鑾峰緱鍜宼emplate瀵瑰簲鐨勪腑闂寸粨鏋滄暟鎹璞CLASS瀵硅薄
+ 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) {
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/BaseTemplateResult.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/BaseTemplateResult.kt
new file mode 100644
index 0000000..04826b8
--- /dev/null
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/BaseTemplateResult.kt
@@ -0,0 +1,47 @@
+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)
+
+ 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]
+ // 浠呬粎涓轰簡绠�鍐檝alues[index]
+ val v = values[index++]
+ // 浠嶮yCell瀵硅薄涓嬁鍑虹櫨鍒嗘瘮绫诲瀷
+ 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) {
+
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProAnalysisSummaryResult.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProAnalysisSummaryResult.kt
new file mode 100644
index 0000000..0711386
--- /dev/null
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProAnalysisSummaryResult.kt
@@ -0,0 +1,57 @@
+package cn.flightfeather.supervision.business.report.bean
+
+import java.math.BigDecimal
+
+/**
+ * 鍒嗚闀囬棶棰樻暣鏀瑰垎鏋愭眹鎬昏〃涓棿缁撴灉瀵硅薄
+ * hc 2024.12.06
+ */
+class ProAnalysisSummaryResult : BaseTemplateResult() {
+ @ExcelHead(1, "琛楅晣搴忓彿")
+ var formIndex: Int? = null
+
+ @ExcelHead(2, "琛楅晣/宸ヤ笟鍖�")
+ var sceneTownname: String? = null
+
+ @ExcelHead(3, "鍦烘櫙绫诲埆")
+ var sceneType: String? = null
+
+ @ExcelHead(4, "鍦烘櫙鏁�")
+ var sceneCount: Int? = null
+
+ @ExcelHead(5, "瀹屽伐銆佹湭鏂藉伐銆佸仠宸ユ垨鍋滀笟銆佸叧闂瓑")
+ var inactiveScenes: Int? = null
+
+ @ExcelHead(6, "鏂藉伐涓�佽繍钀ヤ腑鎬绘暟")
+ var activeScenes: Int? = null
+
+ @ExcelHead(7, "鏁存敼鍗曚綅鏁�")
+ var changeScenes: Int? = null
+
+ @ExcelHead(8, "鏁存敼鍗曚綅鍗犳瘮")
+ var changeScenePer: BigDecimal? = null
+
+ @ExcelHead(9, "闂鏁�")
+ var proNum: Int? = null
+
+ @ExcelHead(10, "闂鍗犳瘮")
+ var proPer: BigDecimal? = null
+
+ @ExcelHead(11, "鏁存敼鏁�")
+ var changeNum: Int? = null
+
+ @ExcelHead(12, "鏁存敼鐜�")
+ var changePer: BigDecimal? = null
+
+ @ExcelHead(13, "鏁存敼鍗曚綅姣旀帓鍚�")
+ var changeSceneRank: Int? = null
+
+ @ExcelHead(14, "闂鏁存敼鐜囨帓鍚�")
+ var proChangeRank: Int? = null
+
+ @ExcelHead(15, "鎷熷垪鍏ラ噸鐐圭洃绠℃暟")
+ var focusSceneNum: Int? = null
+
+ @ExcelHead(16, "鎷熷垪鍏ラ噸鐐圭洃绠″崰姣�")
+ var focusScenePer: BigDecimal? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProDetailSummaryResult.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProDetailSummaryResult.kt
new file mode 100644
index 0000000..209e29b
--- /dev/null
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/bean/ProDetailSummaryResult.kt
@@ -0,0 +1,94 @@
+package cn.flightfeather.supervision.business.report.bean
+
+import java.math.BigDecimal
+
+/**
+ * 闂涓庢暣鏀硅窡韪眹鎬昏〃涓棿缁撴灉瀵硅薄
+ * hc 2024.12.06
+ */
+class ProDetailSummaryResult : BaseTemplateResult() {
+
+ @ExcelHead(1, "琛ㄥ崟缂栧彿")
+ var formIndex: Int? = null
+
+ @ExcelHead(2, "鍞竴搴忓彿")
+ var sceneIndex: Int? = null
+
+ @ExcelHead(3, "鍦烘櫙绫诲瀷")
+ var sceneType: String? = null
+
+ @ExcelHead(4, "鍦烘櫙鍚嶇О")
+ var sceneName: String? = null
+
+ @ExcelHead(5, "鐩戠鏃堕棿")
+ var subTaskPlanstarttime: String? = null
+
+ @ExcelHead(6, "宸℃煡浜哄憳")
+ var subTaskExecutorrealtimes: String? = null
+
+ @ExcelHead(7, "闂绫诲瀷")
+ var problemTypename: String? = null
+
+ @ExcelHead(8, "闂鎻忚堪")
+ var problemDescription: String? = null
+
+ @ExcelHead(9, "闂浣嶇疆")
+ var problemLocation: String? = null
+
+ @ExcelHead(10, "闂鏁�")
+ var problemNum: Int? = null
+
+ @ExcelHead(11, "鏁存敼鏃堕棿")
+ var changeTime: String? = null
+
+ @ExcelHead(12, "鏁存敼鎯呭喌")
+ var problemChanged: String? = null
+
+ @ExcelHead(13, "鏁存敼闂")
+ var changedProblem: String? = null
+
+ @ExcelHead(14, "鏁存敼鏁�")
+ var changedNum: Int? = null
+
+ @ExcelHead(15, "鏈暣鏀归棶棰�")
+ var unchangedProblems: String? = null
+
+ @ExcelHead(16, "鏈暣鏀规暟")
+ var unChangedProblem: Int? = null
+
+ @ExcelHead(17, "闂鏁存敼鐜�")
+ var changePercent: BigDecimal? = null
+
+ @ExcelHead(18, "瀹℃牳鎯呭喌")
+ var checkStatus: String? = null
+
+ @ExcelHead(19, "闂瀹℃牳鏃堕棿")
+ var pCheckTime: String? = null
+
+ @ExcelHead(20, "鏁存敼瀹℃牳鏃堕棿")
+ var cCheckTime: String? = null
+
+ @ExcelHead(21, "闂瀹℃牳鏁�")
+ var pCheckNum: Int? = null
+
+ @ExcelHead(22, "闂瀹℃牳鍗犳瘮")
+ var pCheckPer: BigDecimal? = null
+
+ @ExcelHead(23, "鏁存敼瀹℃牳鏁�")
+ var cCheckNum: Int? = null
+
+ @ExcelHead(24, "鏁存敼瀹℃牳鍗犳瘮")
+ var cCheckPer: BigDecimal? = null
+
+ @ExcelHead(25, "鍙拌处鎻愪氦鐧惧垎姣�")
+ var ledgerPercent: BigDecimal? = null
+
+ @ExcelHead(26, "鍙拌处鎻愪氦鏃堕棿")
+ var ledgerSubmitdate: String? = null
+
+ @ExcelHead(27, "鍙拌处瀹℃牳鏃堕棿")
+ var ledgerCheckTime: String? = null
+
+ @ExcelHead(28, "鏁存敼璺熻釜鎻愰啋")
+ var changeTrackingReminder: String? = null
+}
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProAnalysisSummary.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProAnalysisSummary.kt
index fdec9ce..80914bc 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProAnalysisSummary.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProAnalysisSummary.kt
@@ -12,16 +12,19 @@
import cn.flightfeather.supervision.domain.ds1.entity.SceneMixingPlant
import cn.flightfeather.supervision.domain.ds1.entity.SceneStorageYard
import cn.flightfeather.supervision.domain.ds1.entity.SceneWharf
+import cn.flightfeather.supervision.business.report.bean.BaseTemplateResult
+import cn.flightfeather.supervision.business.report.bean.ProAnalysisSummaryResult
/**
* 鍒嗚闀囬棶棰樻暣鏀瑰垎鏋愭眹鎬昏〃
*/
class ProAnalysisSummary(dataSource: DataSource) : BaseTemplate(dataSource) {
+ override var resultObjects: MutableList<BaseTemplateResult> = mutableListOf(ProAnalysisSummaryResult())
override val cols: List<BaseCols> = listOf(ColInspectionInfo(), ColTotalGrade(), ColStrategy())
override val templateName: String = "鍒嗚闀囬棶棰樻暣鏀瑰垎鏋愭眹鎬昏〃"
- override fun execute() {
+ override fun genData() {
//鏁版嵁婧愰噸缃�
dataSource.reset()
diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProDetailSummary.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProDetailSummary.kt
index 8ad525b..737af42 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProDetailSummary.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/template/ProDetailSummary.kt
@@ -7,9 +7,11 @@
import cn.flightfeather.supervision.business.report.cols.ColLedger
import cn.flightfeather.supervision.business.report.cols.ColSceneName
import cn.flightfeather.supervision.business.report.cols.ColStrategy
+import cn.flightfeather.supervision.business.report.bean.BaseTemplateResult
+import cn.flightfeather.supervision.business.report.bean.ProDetailSummaryResult
class ProDetailSummary(dataSource: DataSource) : BaseTemplate(dataSource) {
override val cols: List<BaseCols> = listOf(ColSceneName(), ColInspectionInfo(), ColLedger(), ColStrategy())
-
+ override var resultObjects: MutableList<BaseTemplateResult> = mutableListOf(ProDetailSummaryResult())
override val templateName: String = "闂涓庢暣鏀硅窡韪眹鎬昏〃"
}
\ No newline at end of file
--
Gitblit v1.9.3