From 46872a311da9480d3edb19223aca2e0833fb1e31 Mon Sep 17 00:00:00 2001
From: hcong <1050828145@qq.com>
Date: 星期二, 17 十二月 2024 11:41:00 +0800
Subject: [PATCH] 1. 完成数据产品中间结果基本信息和具体信息入库 2. 修改ColInspectionInfo.kt 监管时间格式修改为yyyy-mm-dd 3. 新增数据产品类型枚举类 DataProductType 4. 修改BaseTemplate实现类通过重写genData方法生成Template相关数据 5. TODO 其他未涉及到的产品对象的中间结果对象

---
 src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt |  120 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 99 insertions(+), 21 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 f10a5be..0c8047d 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/BaseTemplate.kt
@@ -1,20 +1,22 @@
 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 cn.flightfeather.supervision.common.utils.UUIDGenerator
+import cn.flightfeather.supervision.domain.ds1.entity.DataProduct
 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.collections.ArrayList
+import kotlin.reflect.full.createInstance
 
 /**
  * excel鎶ュ憡妯℃澘鍩虹被
+ * 鍗曚釜鏁版嵁婧�
  */
 // FIXME: 2022/7/15 妯℃澘绠�鍖栵細鍙湁琛ㄥご浼氭秹鍙婂崟鍏冩牸鍚堝苟锛岄粯璁よ〃鍐呭涓病鏈夊悎骞�
-abstract class BaseTemplate(val dataSource: DataSource){
+abstract class BaseTemplate(val dataSource: DataSource) : BaseOutputInterface {
 
     //鍒楃粍鍚�
     abstract val cols: List<BaseCols>
@@ -22,22 +24,35 @@
     //妯℃澘鍚嶇О
     abstract val templateName: String
 
+    // 涓棿缁撴灉瀵硅薄 by hc 2024.12.5
+    abstract var resultObjects: MutableList<BaseTemplateResult>
+
+    // 涓棿缁撴灉鍩烘湰淇℃伅瀵瑰簲鏁版嵁搴撲腑鐨別ntity
+    var dataProduct = DataProduct()
+
+    // 涓棿缁撴灉鍏蜂綋淇℃伅瀵瑰簲鏁版嵁搴撲腑鐨別ntity
+    val entities = ArrayList<Any>()
+
+    // 鎵ц鐘舵�� 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()
         //鍚堟垚琛ㄥご
         cols.forEach {
-            it.combineHead(head,dataSource)
+            it.combineHead(head, dataSource)
         }
         //鍚堟垚鏁版嵁
         dataSource.loop { index, rowData ->
-            cols.forEach {col ->
+            cols.forEach { col ->
                 val r = col.getOneRow(rowData)
                 if (index >= contents.size) {
                     contents.add(mutableListOf())
@@ -47,20 +62,90 @@
         }
     }
 
-    fun toWorkBook(wb: HSSFWorkbook) {
+    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)
     }
 
-    fun toOutputStream(out: OutputStream, sheetName: String? = null) {
+    override fun toOutputStream(out: OutputStream, sheetName: String?) {
         val f = tableFormat()
         ExcelUtil.write2(out, f.first, f.second, sheetName ?: templateName)
     }
 
     /**
+     * 杈撳嚭鍒板璞�
+     * 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
+    }
+
+    /**
+     * 鐢熸垚涓棿缁撴灉鍏蜂綋淇℃伅entity
+     * by hc 2024.12.12
+     */
+    fun toDBEntity() {
+        entities.clear()
+        if (!isExecuted) {
+            execute()
+        }
+        // 鍏堟墽琛宼oObject鍚庡皢toObject鐨勭粨鏋滆浆鍖栦负DBEntity
+        toObject()
+        resultObjects.forEach {
+            entities.add(it.convertToDBEntity())
+        }
+    }
+
+    /**
+     * 鐢熸垚涓棿缁撴灉鍩烘湰淇℃伅entity
+     * by hc 2024.12.12
+     */
+    fun toDBBaseInfoEntity() {
+        dataProduct = DataProduct()
+        dataProduct.guid = UUIDGenerator.generate16ShortUUID()
+        dataProduct.townCode = dataSource.config.townCode
+        dataProduct.cityCode = dataSource.config.cityCode
+        dataProduct.districtCode = dataSource.config.districtCode
+        dataProduct.endTime = dataSource.config.endTime
+        dataProduct.startTime = dataSource.config.startTime
+        dataProduct.provinceCode = dataSource.config.provinceCode
+        dataProduct.sceneTypeId = dataSource.config.sceneType?.toByte() ?: -1
+        dataProduct.taskGuid = dataSource.config.topTaskGuid
+    }
+
+    /**
      * 杈撳嚭涓烘枃妗�
      */
-    fun toFile(path: String) {
+    override fun toFile(path: String) {
         val fileName = "${dataSource.areaName()}-${templateName}-${Date().time}.xls"
         val out = FileOutputStream(path + fileName)
         toOutputStream(out)
@@ -69,12 +154,13 @@
     /**
      * 琛ㄥご鍜岃〃鍐呭鏍煎紡杞寲
      */
-    private fun tableFormat(): Pair<MutableList<Array<Any>>, MutableList<Array<Any>>> {
+    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) {
@@ -91,11 +177,3 @@
         return Pair(h, c)
     }
 }
-
-//鍥哄畾鍒楃粍鍚�
-
-
-//鍩烘湰淇℃伅
-//闂鎵e垎鍒嗗竷
-
-

--
Gitblit v1.9.3