feiyu02
2025-08-14 f373bbf83d9d2a7e5f96118d7dcd658c9fea8bc8
src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt
@@ -3,8 +3,10 @@
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.CellType
import org.springframework.stereotype.Component
import java.io.InputStream
@@ -17,9 +19,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,14 +36,36 @@
            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 {
                val data = SceneDetail().apply {
                    scense = Scense().apply {
                    guid = null
                    name = it.getCell(1)?.stringCellValue?.trim()
                    typeid = null
@@ -65,19 +90,53 @@
                    updatedate = Date()
                    extension1 = "1"
                    extension2 = null
                    index = it.getCell(5)?.stringCellValue?.trim()?.toInt()
                        index = it.getCell(0)?.numericCellValue?.toInt()
                    remark = null
                }
                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, "街镇错误或系统未曾配置"))
                    scense?.typeid = Constant.SceneType.getByName(scense?.type)?.value?.toByte()
                        ?: throw BizException(errorStr(it.rowNum + 1, 3, "场景类型不存在"))
                    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 = it.getCell(12)?.stringCellValue?.trim()
                                csStatus = it.getCell(13)?.stringCellValue?.trim()
                                siExtension1 = it.getCell(14)?.stringCellValue?.trim()
                                csStartTime = it.getCell(15)?.stringCellValue?.trim()
                                csEndTime = it.getCell(16)?.stringCellValue?.trim()
                                csLeftTime = it.getCell(17)?.stringCellValue?.trim()
                                csFloorSpace = it.getCell(18)?.numericCellValue?.toString()
                                csConstructionArea = it.getCell(19)?.numericCellValue?.toString()
                                csConstructionAreaPerMonth = it.getCell(20)?.numericCellValue?.toString()
                                csEmployerUnit = it.getCell(21)?.stringCellValue?.trim()
                                csEmployerContacts = it.getCell(22)?.stringCellValue?.trim()
                                csEmployerContactsTel = it.getCell(23)?.stringCellValue?.trim()
                                csConstructionUnit = it.getCell(24)?.stringCellValue?.trim()
                                csConstructionContacts = it.getCell(25)?.stringCellValue?.trim()
                                csConstructionContactsTel = it.getCell(26)?.stringCellValue?.trim()
                                csSecurityOfficer = it.getCell(27)?.stringCellValue?.trim()
                                csSecurityOfficerTel = it.getCell(28)?.stringCellValue?.trim()
                            }
                        }
                        Constant.SceneType.TYPE2.value -> {
                        }
                        Constant.SceneType.TYPE3.value -> {
                        }
                        Constant.SceneType.TYPE14.value -> {
                        }
                    }
                }
                result.add(data)
            }