From 85ef942e7195abeb71466b7159c3ee30161e1e54 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 07 四月 2026 08:51:01 +0800
Subject: [PATCH] 2026.4.7

---
 src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt |  160 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 118 insertions(+), 42 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt b/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt
index 71e8712..a11e82e 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt
@@ -3,8 +3,11 @@
 import cn.flightfeather.supervision.common.exception.BizException
 import cn.flightfeather.supervision.common.utils.Constant
 import cn.flightfeather.supervision.common.utils.ExcelUtil
-import cn.flightfeather.supervision.domain.ds1.entity.Scense
+import cn.flightfeather.supervision.domain.ds1.entity.*
 import cn.flightfeather.supervision.domain.ds1.repository.RegionRep
+import cn.flightfeather.supervision.lightshare.vo.SceneDetail
+import com.google.gson.Gson
+import org.apache.poi.ss.usermodel.Cell
 import org.apache.poi.ss.usermodel.CellType
 import org.springframework.stereotype.Component
 import java.io.InputStream
@@ -17,9 +20,10 @@
 class SceneImport(
     private val regionRep: RegionRep,
 ) {
+    // 鍦烘櫙鍏辨湁淇℃伅
     private val headers =
         listOf(
-            ExcelUtil.MyHeader("缂栧彿锛堣嫢涓嶅~鍐欙紝鍒欐寜鐓ч『搴忚嚜鍔ㄦ坊鍔狅級", CellType.NUMERIC),
+            ExcelUtil.MyHeader("缂栧彿锛堝彲鐪佺暐锛�", CellType.NUMERIC, true),
             ExcelUtil.MyHeader("鍚嶇О", CellType.STRING),
             ExcelUtil.MyHeader("绫诲瀷", CellType.STRING),
             ExcelUtil.MyHeader("鍦板潃", CellType.STRING),
@@ -33,56 +37,116 @@
             ExcelUtil.MyHeader("鑱旂郴鐢佃瘽", CellType.STRING)
         )
 
+    // 宸ュ湴淇℃伅
+    private val headersType1 = listOf(
+        ExcelUtil.MyHeader("宸ョ▼绫诲瀷", CellType.STRING),
+        ExcelUtil.MyHeader("寤鸿鐘舵��", CellType.STRING),
+        ExcelUtil.MyHeader("鏂藉伐闃舵", CellType.STRING),
+        ExcelUtil.MyHeader("寮�宸ユ椂闂�", CellType.STRING),
+        ExcelUtil.MyHeader("瀹屽伐鏃堕棿", CellType.STRING),
+        ExcelUtil.MyHeader("鍓╀綑宸ユ湡", CellType.STRING),
+        ExcelUtil.MyHeader("鍗犲湴闈㈢Н", CellType.NUMERIC),
+        ExcelUtil.MyHeader("鏂藉伐闈㈢Н", CellType.NUMERIC),
+        ExcelUtil.MyHeader("姣忔湀鏂藉伐闈㈢Н", CellType.NUMERIC),
+        ExcelUtil.MyHeader("涓氫富鍗曚綅", CellType.STRING),
+        ExcelUtil.MyHeader("涓氫富鍗曚綅鑱旂郴浜�", CellType.STRING),
+        ExcelUtil.MyHeader("涓氫富鍗曚綅鑱旂郴鐢佃瘽", CellType.STRING),
+        ExcelUtil.MyHeader("鏂藉伐鍗曚綅", CellType.STRING),
+        ExcelUtil.MyHeader("鏂藉伐鍗曚綅鑱旂郴浜�", CellType.STRING),
+        ExcelUtil.MyHeader("鏂藉伐鍗曚綅鑱旂郴鐢佃瘽", CellType.STRING),
+        ExcelUtil.MyHeader("瀹夊叏鍛�", CellType.STRING),
+        ExcelUtil.MyHeader("瀹夊叏鍛樼數璇�", CellType.STRING),
+    )
+
     /**
      * 閫氳繃鏂囦欢璇诲彇鍦烘櫙淇℃伅
      */
-    fun readFromFile(file: InputStream): List<Scense> {
-        val result = mutableListOf<Scense>()
+    fun readFromFile(file: InputStream): List<SceneDetail> {
+        val result = mutableListOf<SceneDetail>()
         try {
             ExcelUtil.readXLXS(file, headers) {
-                val data = Scense().apply {
-                    guid = null
-                    name = it.getCell(1)?.stringCellValue?.trim()
-                    typeid = null
-                    type = it.getCell(2)?.stringCellValue?.trim()
-                    scensesubtypeid = null
-                    scensesubtype = null
-                    location = it.getCell(3)?.stringCellValue?.trim()
-                    longitude = it.getCell(4)?.numericCellValue?.toBigDecimal()
-                    latitude = it.getCell(5)?.numericCellValue?.toBigDecimal()
-                    provincecode = null
-                    provincename = it.getCell(6)?.stringCellValue?.trim()
-                    citycode = null
-                    cityname = it.getCell(7)?.stringCellValue?.trim()
-                    districtcode = null
-                    districtname = it.getCell(8)?.stringCellValue?.trim()
-                    towncode = null
-                    townname = it.getCell(9)?.stringCellValue?.trim()
-                    contactst = it.getCell(11)?.stringCellValue?.trim()
-                    contactswx = null
-                    contacts = it.getCell(10)?.stringCellValue?.trim()
-                    createdate = Date()
-                    updatedate = Date()
-                    extension1 = "1"
-                    extension2 = null
-                    index = it.getCell(5)?.stringCellValue?.trim()?.toInt()
-                    remark = null
+                val data = SceneDetail().apply {
+                    scense = Scense().apply {
+                        guid = null
+                        name = it.getCell(1)?.stringCellValue?.trim()
+                        typeid = null
+                        type = it.getCell(2)?.stringCellValue?.trim()
+                        scensesubtypeid = null
+                        scensesubtype = null
+                        location = it.getCell(3)?.stringCellValue?.trim()
+                        longitude = it.getCell(4)?.numericCellValue?.toBigDecimal()
+                        latitude = it.getCell(5)?.numericCellValue?.toBigDecimal()
+                        provincecode = null
+                        provincename = it.getCell(6)?.stringCellValue?.trim()
+                        citycode = null
+                        cityname = it.getCell(7)?.stringCellValue?.trim()
+                        districtcode = null
+                        districtname = it.getCell(8)?.stringCellValue?.trim()
+                        towncode = null
+                        townname = it.getCell(9)?.stringCellValue?.trim()
+                        contactst = it.getCell(11)?.stringCellValue?.trim()
+                        contactswx = null
+                        contacts = it.getCell(10)?.stringCellValue?.trim()
+                        createdate = Date()
+                        updatedate = Date()
+                        extension1 = "1"
+                        extension2 = null
+                        index = it.getCell(0)?.numericCellValue?.toInt()
+                        remark = null
+                    }
+                    if (scense?.name.isNullOrBlank()) throw BizException(errorStr(it.rowNum + 1, 2, "鍦烘櫙鍚嶇О涓嶈兘绌虹櫧"))
+                    scense?.typeid = Constant.SceneType.getByName(scense?.type)?.value?.toByte()
+                        ?: throw BizException(errorStr(it.rowNum + 1, 3, "鍦烘櫙绫诲瀷涓嶅瓨鍦�"))
+                    if (scense?.location.isNullOrBlank()) throw BizException(errorStr(it.rowNum + 1, 4, "鍦烘櫙鍦板潃涓嶈兘绌虹櫧"))
+                    scense?.longitude ?: throw BizException(errorStr(it.rowNum + 1, 5, "缁忓害涓嶈兘绌虹櫧"))
+                    scense?.latitude ?: throw BizException(errorStr(it.rowNum + 1, 6, "绾害涓嶈兘绌虹櫧"))
+                    scense?.provincecode = regionRep.findProvince(scense?.provincename)?.provincecode
+                        ?: throw BizException(errorStr(it.rowNum + 1, 7, "鐪佷唤閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
+                    scense?.citycode = regionRep.findCity(scense?.cityname)?.citycode
+                        ?: throw BizException(errorStr(it.rowNum + 1, 8, "鍩庡競閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
+                    scense?.districtcode = regionRep.findDistrict(scense?.districtname)?.districtcode
+                        ?: throw BizException(errorStr(it.rowNum + 1, 9, "鍖哄幙閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
+                    scense?.towncode = regionRep.findTown(scense?.townname)?.towncode
+                        ?: throw BizException(errorStr(it.rowNum + 1, 10, "琛楅晣閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
+
+                    when (scense?.typeid.toString()) {
+                        Constant.SceneType.TYPE1.value -> {
+                            subScene = SceneConstructionSite().apply {
+                                csProjectType = getCellValueToString(it.getCell(12))
+                                csStatus = getCellValueToString(it.getCell(13))
+                                siExtension1 = getCellValueToString(it.getCell(14))
+                                csStartTime = getCellValueToString(it.getCell(15))
+                                csEndTime = getCellValueToString(it.getCell(16))
+                                csLeftTime = getCellValueToString(it.getCell(17))
+                                csFloorSpace = getCellValueToString(it.getCell(18))
+                                csConstructionArea = getCellValueToString(it.getCell(19))
+                                csConstructionAreaPerMonth = getCellValueToString(it.getCell(20))
+                                csEmployerUnit = getCellValueToString(it.getCell(21))
+                                csEmployerContacts = getCellValueToString(it.getCell(22))
+                                csEmployerContactsTel = getCellValueToString(it.getCell(23))
+                                csConstructionUnit = getCellValueToString(it.getCell(24))
+                                csConstructionContacts = getCellValueToString(it.getCell(25))
+                                csConstructionContactsTel = getCellValueToString(it.getCell(26))
+                                csSecurityOfficer = getCellValueToString(it.getCell(27))
+                                csSecurityOfficerTel = getCellValueToString(it.getCell(28))
+                            }
+                        }
+                        Constant.SceneType.TYPE2.value -> {
+
+                        }
+                        Constant.SceneType.TYPE3.value -> {
+
+                        }
+                        Constant.SceneType.TYPE14.value -> {
+
+                        }
+                    }
                 }
-                data.typeid = Constant.SceneType.getByName(data.type)?.value?.toByte()
-                    ?: throw BizException(errorStr(it.rowNum + 1, 2, "鍦烘櫙绫诲瀷涓嶅瓨鍦�"))
-                data.provincecode = regionRep.findProvince(data.provincename)?.provincecode
-                    ?: throw BizException(errorStr(it.rowNum + 1, 6, "鐪佷唤閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
-                data.citycode = regionRep.findCity(data.cityname)?.citycode
-                    ?: throw BizException(errorStr(it.rowNum + 1, 7, "鍩庡競閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
-                data.districtcode = regionRep.findDistrict(data.districtname)?.districtcode
-                    ?: throw BizException(errorStr(it.rowNum + 1, 8, "鍖哄幙閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
-                data.towncode = regionRep.findTown(data.townname)?.towncode
-                    ?: throw BizException(errorStr(it.rowNum + 1, 9, "琛楅晣閿欒鎴栫郴缁熸湭鏇鹃厤缃�"))
 
                 result.add(data)
             }
         } catch (e: IllegalStateException) {
-            throw BizException("excel鏂囦欢鍐呭閿欒锛屾暟鎹浆鎹㈠け璐ワ紒", e)
+            throw BizException(e.message, e)
         }
         return result
     }
@@ -90,4 +154,16 @@
     private fun errorStr(row: Int, col: Int, str: String): String {
         return "绗�${row}琛岋紝绗�${col}鍒楀崟鍏冩牸閿欒锛�${str}"
     }
+
+    private fun getCellValueToString(cell: Cell?): String {
+        cell ?: return ""
+        return when (cell.cellType) {
+            CellType.STRING -> cell.stringCellValue.trim()
+            CellType.NUMERIC -> cell.numericCellValue.toString().trim()
+            CellType.BLANK -> cell.stringCellValue.trim()
+            CellType.BOOLEAN -> cell.booleanCellValue.toString().trim()
+            CellType.ERROR -> cell.errorCellValue.toString().trim()
+            else -> throw BizException(errorStr(cell.rowIndex + 1, cell.columnIndex + 1, "鍗曞厓鏍兼牸寮忎笉鏄父瑙佹牸寮忥紝鏃犳硶璇嗗埆"))
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3