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 |   95 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 89 insertions(+), 6 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 fefb508..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,14 +1,15 @@
 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鎶ュ憡妯℃澘鍩虹被
@@ -23,14 +24,26 @@
     //妯℃澘鍚嶇О
     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()
         //鍚堟垚琛ㄥご
@@ -49,6 +62,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 +83,66 @@
     }
 
     /**
+     * 杈撳嚭鍒板璞�
+     * 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
+    }
+
+    /**
      * 杈撳嚭涓烘枃妗�
      */
     override fun toFile(path: String) {

--
Gitblit v1.9.3