From 16b961c2210fe29fd494ac1f9d830dd93503961f Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 02 八月 2024 17:25:17 +0800
Subject: [PATCH] 1. 新增监测设备的管理功能

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SearchServiceImpl.kt |  734 +++++++++++++------------------------------------------
 1 files changed, 180 insertions(+), 554 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SearchServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SearchServiceImpl.kt
index 1025cf9..2a55953 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SearchServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SearchServiceImpl.kt
@@ -6,21 +6,28 @@
 import cn.flightfeather.supervision.business.report.file.ReportThree
 import cn.flightfeather.supervision.business.report.file.ReportTwo
 import cn.flightfeather.supervision.business.report.template.*
+import cn.flightfeather.supervision.common.exception.BizException
 import cn.flightfeather.supervision.common.utils.*
 import cn.flightfeather.supervision.domain.ds1.entity.*
 import cn.flightfeather.supervision.domain.ds1.mapper.*
+import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRep
+import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRuleRep
+import cn.flightfeather.supervision.domain.ds1.repository.SceneRep
 import cn.flightfeather.supervision.domain.ds2.mapper.LedgerRecordMapper
 import cn.flightfeather.supervision.domain.ds2.mapper.LedgerSubTypeMapper
 import cn.flightfeather.supervision.domain.ds2.mapper.UserMapMapper
 import cn.flightfeather.supervision.lightshare.service.SearchService
+import cn.flightfeather.supervision.lightshare.service.TaskService
 import cn.flightfeather.supervision.lightshare.vo.*
 import com.github.pagehelper.PageHelper
 import org.springframework.beans.BeanUtils
+import org.springframework.beans.factory.annotation.Value
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
 import java.io.File
 import java.io.FileInputStream
 import java.io.FileOutputStream
+import java.net.URLEncoder
 import java.nio.charset.StandardCharsets
 import java.util.*
 import javax.servlet.http.HttpServletResponse
@@ -31,33 +38,37 @@
  */
 @Service
 class SearchServiceImpl(
-        val userinfoMapper: UserinfoMapper,
-        val subtaskMapper: SubtaskMapper,
-        val scenseMapper: ScenseMapper,
-        val sceneConstructionSiteMapper: SceneConstructionSiteMapper,
-        val sceneMixingPlantMapper: SceneMixingPlantMapper,
-        val sceneStorageYardMapper: SceneStorageYardMapper,
-        val sceneWharfMapper: SceneWharfMapper,
-        val problemlistMapper: ProblemlistMapper,
-        val problemtypeMapper: ProblemtypeMapper,
-        val townMapper: TownMapper,
-        val mediafileMapper: MediafileMapper,
-        val scoreMapper: ScoreMapper,
-        val inspectionMapper: InspectionMapper,
-        val taskMapper: TaskMapper,
-        val monitorobjectversionMapper: MonitorobjectversionMapper,
-        val evaluationruleMapper: EvaluationruleMapper,
-        val evaluationsubruleMapper: EvaluationsubruleMapper2,
-        val evaluationMapper: EvaluationMapper,
-        val itemevaluationMapper: ItemevaluationMapper,
-        val ledgerSubTypeMapper: LedgerSubTypeMapper,
-        val ledgerRecordMapper: LedgerRecordMapper,
-        val userMapMapper: UserMapMapper,
+    val userinfoMapper: UserinfoMapper,
+    val subtaskMapper: SubtaskMapper,
+    val scenseMapper: ScenseMapper,
+    val sceneConstructionSiteMapper: SceneConstructionSiteMapper,
+    val sceneMixingPlantMapper: SceneMixingPlantMapper,
+    val sceneStorageYardMapper: SceneStorageYardMapper,
+    val sceneWharfMapper: SceneWharfMapper,
+    val problemlistMapper: ProblemlistMapper,
+    val problemtypeMapper: ProblemtypeMapper,
+    val townMapper: TownMapper,
+    val mediafileMapper: MediafileMapper,
+    val scoreMapper: ScoreMapper,
+    val inspectionMapper: InspectionMapper,
+    val taskMapper: TaskMapper,
+    val monitorobjectversionMapper: MonitorobjectversionMapper,
+    val evaluationruleMapper: EvaluationruleMapper,
+    val evaluationsubruleMapper: EvaluationsubruleMapper2,
+    val evaluationMapper: EvaluationMapper,
+    val itemevaluationMapper: ItemevaluationMapper,
+    val ledgerSubTypeMapper: LedgerSubTypeMapper,
+    val ledgerRecordMapper: LedgerRecordMapper,
+    val userMapMapper: UserMapMapper,
+    val taskService: TaskService,
+    private val evaluationRep: EvaluationRep,
+    private val evaluationRuleRep: EvaluationRuleRep,
+    private val sceneRep: SceneRep,
+    @Value("\${filePath}") var filePath: String,
+    @Value("\${imgPath}") var imgPath: String,
 ) : SearchService {
 
-    private val dateUtil = DateUtil()
-
-    override fun writeToFile(config: ExcelConfigVo, mode:Int) {
+    override fun writeToFile(config: ExcelConfigVo, mode: Int) {
         val dbMapper = DbMapper(
             scenseMapper,
             problemlistMapper,
@@ -70,29 +81,10 @@
             sceneWharfMapper,
             taskMapper,
             evaluationruleMapper, evaluationsubruleMapper, evaluationMapper, itemevaluationMapper,
-                ledgerSubTypeMapper, ledgerRecordMapper, userinfoMapper, userMapMapper, townMapper
+            ledgerSubTypeMapper, ledgerRecordMapper, userinfoMapper, userMapMapper, townMapper
         )
         val dataSource = DataSource(config, dbMapper)
         val t = when (mode) {
-//            //闂涓庢暣鏀硅窡韪眹鎬昏〃
-//            0 -> ProDetailSummary(dataSource)
-//            //鍒嗚闀囬棶棰樻暣鏀瑰垎鏋愭眹鎬昏〃
-//            1 -> ProAnalysisSummary(dataSource)
-//
-//            //瑙勮寖鎬ц瘎浼拌鎯呰〃
-//            2 -> ScoreDetailSummary(dataSource)
-//            //鍒嗚闀囪鑼冩�у垎鏋愯〃
-//            3 -> ScoreAnalysisSummary(dataSource)
-//
-//            //闂涓庢暣鏀瑰垎绫荤粺璁¤〃
-//            4 -> ProTypeDetailSummary(dataSource)
-//            //闂涓庢暣鏀瑰垎绫绘帓鍚�
-//            5 -> ProTypeRankSummary(dataSource)
-//            //鏈堝害涓昏鎴栧吀鍨嬮棶棰樺垎鏋愯〃
-//            6 -> ProTypeRankMainSummary(dataSource)
-//            //宸ュ湴鏂藉伐闃舵闂鍒嗙被鍒嗘瀽琛�
-//            7 -> ProTypeStatusSummary(dataSource)
-
             8 -> ReportOne(dataSource)
             9 -> ReportTwo(dataSource)
             10 -> ReportThree(dataSource)
@@ -103,32 +95,84 @@
         t?.toFile("target/")
     }
 
-    override fun getExcel(config: ExcelConfigVo, response: HttpServletResponse): HttpServletResponse {
+    override fun getExcel(config: ExcelConfigVo, response: HttpServletResponse): Boolean {
+        val dbMapper = DbMapper(
+            scenseMapper,
+            problemlistMapper,
+            problemtypeMapper,
+            subtaskMapper,
+            monitorobjectversionMapper,
+            sceneConstructionSiteMapper,
+            sceneMixingPlantMapper,
+            sceneStorageYardMapper,
+            sceneWharfMapper,
+            taskMapper,
+            evaluationruleMapper, evaluationsubruleMapper, evaluationMapper, itemevaluationMapper,
+            ledgerSubTypeMapper, ledgerRecordMapper, userinfoMapper, userMapMapper, townMapper
+        )
+        val dataSource = DataSource(config, dbMapper)
+        val t = when (config.mode) {
+            1 -> ReportOne(dataSource)
+            2 -> ReportTwo(dataSource)
+            3 -> ReportThree(dataSource)
 
-        val fileName = "${dateUtil.DateToString(Date(), "yyyy-MM-dd hh:mm:ss")}.xls"
+            else -> ReportOne(dataSource)
+        }
+        val fileName = t.getReportName()
+        val fName = URLEncoder.encode(fileName, "UTF-8")
         response.apply {
-            setHeader("Content-Disposition", "attachment;filename=$fileName")
-            setHeader("fileName", fileName)
+            setHeader("Content-Disposition", "attachment;filename=$fName")
+            setHeader("fileName", fName)
+            addHeader("Access-Control-Expose-Headers", "fileName")
             contentType = "application/vnd.ms-excel;charset=UTF-8"
             setHeader("Pragma", "no-cache")
             setHeader("Cache-Control", "no-cache")
             setDateHeader("Expires", 0)
         }
 
-//        val heads = getTableTitles(config.sceneType, config.districtCode)
-//        val contents = getTableContents(config, heads.size)
-        val r = getTable(1, config)
-        val out = response.outputStream
-        ExcelUtil.write2(out, r.first, r.second)
+        val p = "$filePath/autoscore/"
+        val file = File(p + fileName)
+        if (config.forceUpdate || !file.exists()) {
+            t.toFile(p)
+        }
+        response.outputStream.write(file.readBytes())
 
-        return response
+        return true
     }
 
     override fun getSubTaskDetail(config: ExcelConfigVo): SubTaskTableVo {
-        val titles = getTableTitles(config.sceneType, config.districtCode)
-        val content = getTableContents(config, titles.size)
+        val dbMapper = DbMapper(
+            scenseMapper,
+            problemlistMapper,
+            problemtypeMapper,
+            subtaskMapper,
+            monitorobjectversionMapper,
+            sceneConstructionSiteMapper,
+            sceneMixingPlantMapper,
+            sceneStorageYardMapper,
+            sceneWharfMapper,
+            taskMapper,
+            evaluationruleMapper, evaluationsubruleMapper, evaluationMapper, itemevaluationMapper,
+            ledgerSubTypeMapper, ledgerRecordMapper, userinfoMapper, userMapMapper, townMapper
+        )
+//        val dataSource = DataSource(config, dbMapper)
+//        val t = when (config.mode) {
+////            1 -> ReportOne(dataSource)
+////            2 -> ReportTwo(dataSource)
+////            3 -> ReportThree(dataSource)
+//            4->DailyReportSummary()
+//            else -> ReportOne(dataSource)
+//        }
+//        val fileName = t.getReportName()
+//        val fName = URLEncoder.encode(fileName, "UTF-8")
+//
+//        val p = Constant.DEFAULT_FILE_PATH + "/files/autoscore/"
+//        val file = File(p + fileName)
+//        if (config.forceUpdate || !file.exists()) {
+//            t.toFile(p)
+//        }
 
-        return SubTaskTableVo(titles, content)
+        return SubTaskTableVo(emptyList(), emptyList())
     }
 
     override fun downloadPic(config: ExcelConfigVo, response: HttpServletResponse): HttpServletResponse {
@@ -177,7 +221,7 @@
 
             //鏍规嵁鍦烘櫙鏉′欢绛涢��
             val need = if (config.sceneType != null) {
-                scene.typeid == config.sceneType.toByte()
+                scene.typeid == config.sceneType?.toByte()
             } else {
                 true
             }
@@ -212,8 +256,9 @@
         }
 
         //寤虹珛绗竴灞傜洰褰曪紝鍖呭惈鎵�鏈夌殑浠诲姟
-        val time = dateUtil.DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
-        var basePath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + time
+        val time = DateUtil.DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
+        var basePath =
+            Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + time
         var file = File(basePath)
         var i = 1
         while (file.exists() && i <= 100) {
@@ -264,7 +309,8 @@
                 mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
                     createCriteria().andEqualTo("businessguid", p.guid)
                 }).forEach { m ->
-                    val picPath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + m.extension1 + m.guid + ".jpg"
+                    val picPath =
+                        Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + m.extension1 + m.guid + ".jpg"
                     val fromFile = File(picPath)
                     val picName = p.problemname + "_" + p.location + "($y).jpg"
                     val toFile = File(pPath + File.separator + picName)
@@ -303,8 +349,9 @@
     override fun downloadPic2(sceneType: Int, topTaskId: String, response: HttpServletResponse): HttpServletResponse {
         //寤虹珛绗竴灞傜洰褰曪紝鍖呭惈鎵�鏈夌殑浠诲姟
         val topTask = taskMapper.selectByPrimaryKey(topTaskId)
-        val time = dateUtil.DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
-        val basePath = Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + topTask.name
+        val time = DateUtil.DateToString(Date(), "yyyy-MM-dd_HH-mm-ss")
+        val basePath =
+            Constant.DEFAULT_FILE_PATH + File.separator + "images" + File.separator + "temp" + File.separator + topTask.name
         val file = File(basePath)
         if (!file.exists()) {
             file.mkdirs()
@@ -323,7 +370,7 @@
 
                 //寤虹珛涓�涓瓙浠诲姟鏂囦欢澶�
                 var subTaskFilePath = "${basePath}${File.separator}(${
-                    dateUtil.DateToString(
+                    DateUtil.DateToString(
                         it.planstarttime,
                         DateUtil.DateStyle.YYYY_MM_DD_CN
                     )
@@ -413,7 +460,13 @@
         return response
     }
 
-    override fun searchScore4JingAn(token: String, year: Int, month: Int, page: Int?, perPage: Int?): BaseResponse<List<ScoreVo>> {
+    override fun searchScore4JingAn(
+        token: String,
+        year: Int,
+        month: Int,
+        page: Int?,
+        perPage: Int?,
+    ): BaseResponse<List<ScoreVo>> {
         if (token != "jingan") {
             return BaseResponse(false)
         }
@@ -436,7 +489,12 @@
         return BaseResponse(true, head = DataHead(p.pageNum, p.pages), data = result)
     }
 
-    override fun searchSubTaskByKeyword(userId: String, keyword: String, page: Int, perPage: Int): BaseResponse<List<SubtaskVo>> {
+    override fun searchSubTaskByKeyword(
+        userId: String,
+        keyword: String,
+        page: Int,
+        perPage: Int,
+    ): BaseResponse<List<SubtaskVo>> {
         val userInfo = userinfoMapper.selectByPrimaryKey(userId)
         if (userInfo.usertypeid?.toInt() == 3) return BaseResponse(false, "浼佷笟鐢ㄦ埛鏃犳煡璇㈡潈闄�")//浼佷笟鐢ㄦ埛鏃犳硶鏌ヨ
         val result = mutableListOf<SubtaskVo>()
@@ -461,501 +519,69 @@
         return BaseResponse(true, head = DataHead(pageInfo.pageNum, pageInfo.pages), data = result)
     }
 
+    override fun getDailyReport(config: ExcelConfigVo): BaseTableVo {
+        if (config.districtCode == null || config.startTime == null) return BaseTableVo(emptyList(), emptyList())
 
-    private fun getTable(mode: Int, config: ExcelConfigVo): Pair<MutableList<Array<Any>>, MutableList<Array<Any>>> {
-        //鏁版嵁婧�
-        val dataList = getTableDataSource(config)
-        //鐢熸垚琛ㄦ牸
-        val head = mutableListOf<MutableList<Any>>()
-        val contents = mutableListOf<MutableList<Any>>()
+        val dbMapper = DbMapper(
+            scenseMapper,
+            problemlistMapper,
+            problemtypeMapper,
+            subtaskMapper,
+            monitorobjectversionMapper,
+            sceneConstructionSiteMapper,
+            sceneMixingPlantMapper,
+            sceneStorageYardMapper,
+            sceneWharfMapper,
+            taskMapper,
+            evaluationruleMapper, evaluationsubruleMapper, evaluationMapper, itemevaluationMapper,
+            ledgerSubTypeMapper, ledgerRecordMapper, userinfoMapper, userMapMapper, townMapper
+        )
+        val task =
+            taskService.getByDistrictCode(config.districtCode, config.startTime)?.takeIf { it.isNotEmpty() }?.get(0)
+        config.topTaskGuid = task?.tguid ?: ""
+        val dataSource = mutableListOf<DataSource>()
+        config.sceneType = Constant.SceneType.TYPE1.value.toInt()
+        dataSource.add(DataSource(config, dbMapper))
 
-        getSceneName(head, contents, dataList)
+//        val config2 = config.copy(sceneType = Constant.ScenseType.TYPE2.value.toInt())
+//        dataSource.add(DataSource(config2, dbMapper))
+//
+//        val config3 = config.copy(sceneType = Constant.ScenseType.TYPE3.value.toInt())
+//        dataSource.add(DataSource(config3, dbMapper))
+//
+//        val config4 = config.copy(sceneType = Constant.ScenseType.TYPE14.value.toInt())
+//        dataSource.add(DataSource(config4, dbMapper))
 
-        when (mode) {
-            // 闂鍒嗗竷
-            1 -> {
-                getProblemDistribution(head, contents, dataList, config)
-            }
-            2 -> {
-                getInspectionInfo(head, contents, dataList, config)
-            }
-            3 -> {
+        val t = DailyReportSummary(dataSource)
+        t.execute()
+        val result = t.toTableRows()
 
-            }
-        }
-        val h = mutableListOf<Array<Any>>()
-        val c = mutableListOf<Array<Any>>()
-        head.forEach { h.add(it.toTypedArray()) }
-        contents.forEach { c.add(it.toTypedArray()) }
-        c.sortBy {
-            it[0] as Int
-        }
-
-        return Pair(h, c)
+        return BaseTableVo(result.first, result.second)
     }
 
-    // 琛ㄥご锛氬満鏅悕
-    private fun getSceneName(head: MutableList<MutableList<Any>>, contents: MutableList<MutableList<Any>>, dataList: List<Subtask>) {
-        head.add(mutableListOf(ExcelUtil.MyCell("琛ㄥ崟缂栧彿"), ExcelUtil.MyCell("鍞竴搴忓彿"), ExcelUtil.MyCell("鍦烘櫙鍚嶇О")))
-        dataList.forEach {subtask ->
-            val row = mutableListOf<Any>()
-            //鏌ヨ璇ヤ换鍔″搴旂殑鍦烘櫙
-            val scene = scenseMapper.selectByPrimaryKey(subtask.scenseid)
-            row.apply {
-                add(scene.index ?: -99)
-                add(scene.extension2 ?: "")
-                add(scene.name ?: "")
-            }
-            contents.add(row)
+    override fun getScoreDetail(subTaskId: String): ScoreDetail {
+        //鍦烘櫙淇℃伅
+        val scene = sceneRep.findBySubTask(subTaskId)
+        //鎬诲垎
+        val evaluation = evaluationRep.findBySubtask(subTaskId)
+        //瀛愯鍒欓�愭潯寰楀垎
+        val subRuleScores = evaluationRep.findItemEvaluation(subTaskId)
+        if (subRuleScores.isEmpty()) throw BizException("鏃犺瘎浼拌褰�")
+        //璇勫垎鎬昏鍒�
+        val rule = evaluationRuleRep.findAutoEvaluationRule(subTaskId) ?: throw BizException("鏈壘鍒扮浉鍏宠嚜鍔ㄨ瘎浼拌鍒�")
+        //鎬昏鍒欏搴旂殑璇勫垎瀛愯鍒�
+        val subRules = evaluationRuleRep.findSubRule(rule.guid)
+        //鏌ヨ缁撴灉
+        val result = ScoreDetail()
+        result.status = if (scene?.extension1.equals("1")) "鍦ㄥ缓" else "瀹屽伐"
+
+        result.updateTime = evaluation?.updatedate
+        subRules.forEach {
+            it.ertype ?: return@forEach
+            result.addDetail(result.details, it, it.ertype!! - 1, subRuleScores, true)
         }
-    }
-
-    // 琛ㄥご锛氬叿浣撻棶棰樺垎甯�
-    private fun getProblemDistribution(head: MutableList<MutableList<Any>>, contents: MutableList<MutableList<Any>>,
-                                       dataList: List<Subtask>, config: ExcelConfigVo) {
-        val h1 = mutableListOf<ExcelUtil.MyCell>()
-        val h2 = mutableListOf<Any>()
-        currentProblemType.clear()
-        currentProblemHead.clear()
-
-        // 闂鍒嗕负涓ゅ眰锛屾柊澧炰竴琛岃〃澶�
-        problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", config.sceneType)
-                .andEqualTo("districtcode", config.districtCode)
-            orderBy("extension1")
-        }).forEach {
-            if (!currentProblemHead.contains(it.typename)) {
-                currentProblemHead.add(it.typename ?: "")
-                h1.add(ExcelUtil.MyCell(it.typename ?: "", colSpan = 0))
-            }
-            currentProblemType[it.guid ?: ""] = it.description ?: ""
-            if (currentProblemHead.contains(it.typename)) {
-                h2.add(it.description ?: "")
-                h1.last().colSpan++
-
-                h2.add("鏄惁鏁存敼")
-                h1.last().colSpan++
-            }
-        }
-
-        //闂鍒嗗竷
-        for (i in dataList.indices) {
-            val subtask = dataList[i]
-
-            val pDis = mutableListOf<Any>()//鍏蜂綋闂鍒嗗竷鍙婃暣鏀规儏鍐�
-            repeat(h2.size) { pDis.add("")}
-            if (subtask.stguid != null) {
-                problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
-                    createCriteria().andEqualTo("stguid", subtask.stguid)
-                }).forEach problemType@{ p ->
-                    val des = currentProblemType[p.ptguid]
-
-                    //鍏蜂綋闂鍒嗗竷
-                    for (t in h2.indices) {
-                        if (des == h2[t]) {
-                            //鍏蜂綋闂杩欎竴鍒楁坊鍔犳枃鏈紝琛ㄧず闂瀛樺湪
-                            pDis[t] = 1
-                            //闂鍒楃殑涓嬩竴鍒楁槸璇ラ棶棰樼殑鏁存敼鎯呭喌
-                            pDis[t + 1] = if (p.ischanged == true) 1 else 0
-                            break
-                        }
-                    }
-                }
-            }
-
-            contents[i].addAll(pDis)
-        }
-
-        //鍘熸湁鐨勭涓�琛岃〃澶村鍔�1琛岃璺ㄥ害,鍚屾椂鏂扮殑绗簩琛岃〃澶存坊鍔犵┖浣�
-        head[0].forEach {
-            (it as ExcelUtil.MyCell).rowSpan++
-//            h2.add(0, "")
-        }
-        //鍚堝苟琛ㄥご
-        head[0].addAll(h1)
-        head.add(h2)
-    }
-
-    // 琛ㄥご锛氬贰鏌ユ儏鍐靛強闂銆佹暣鏀圭粺璁�
-    private fun getInspectionInfo(head: MutableList<MutableList<Any>>, contents: MutableList<MutableList<Any>>, dataList: List<Subtask>, config: ExcelConfigVo) {
-        val h1 = listOf("鐩戠鏃堕棿", "闂绫诲瀷", "闂鎻忚堪", "闂浣嶇疆", "闂鏁�", "鏁存敼鎯呭喌", "鏁存敼闂", "鏁存敼鏁�", "鏈暣鏀归棶棰�", "鏈暣鏀规暟", "瀹℃牳鎯呭喌")
-
-        for (i in dataList.indices) {
-            val subtask = dataList[i]
-
-            val row = mutableListOf<Any>()
-            if (subtask.stguid == null) {
-                repeat(h1.size) { row.add("")}
-            } else {
-                row.apply {
-                    // 琛ㄥご锛氬贰鏌ユ儏鍐靛強闂銆佹暣鏀圭粺璁�
-                    add(dateUtil.DateToString(subtask.planstarttime, DateUtil.DateStyle.MM_DD) ?: "")//鐩戠鏃堕棿
-                    //鏌ヨ瀛愪换鍔″搴旂殑闂锛屽苟涓旀牴鎹潯浠惰繘琛岀瓫閫�
-                    var y = 1
-                    var pType = ""//闂绫诲瀷
-                    var pDes = ""//闂鎻忚堪
-                    var pLoc = ""//闂浣嶇疆
-                    var pNum = 0//闂鏁�
-                    var pChanged = ""//鏁存敼鎯呭喌
-                    var changedProblem = ""//鏁存敼闂
-                    var cNum = 0//鏁存敼鏁�
-                    var unChangedProblem = ""//鏈暣鏀归棶棰�
-                    var unChangeNum = 0//鏈暣鏀规暟
-                    var checkStatus = ""//瀹℃牳鎯呭喌
-                    problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
-                        createCriteria().andEqualTo("stguid", subtask.stguid)
-                    }).forEach problemType@{ p ->
-                        val problemType = problemtypeMapper.selectByPrimaryKey(p.ptguid)
-                        val typeName = if (problemType == null) {
-                            val a = ""
-                            a
-                        } else {
-                            problemType.typename
-                        }
-                        val lr = if (y > 1) "\n" else ""
-                        //宸℃煡鎯呭喌鍙婇棶棰樸�佹暣鏀圭粺璁�
-                        pType += "${lr}$y銆�${typeName}"
-                        pDes += "${lr}$y銆�${p.problemname}"
-                        pLoc += "${lr}$y銆�${p.location}"
-                        pNum++
-                        pChanged += "${lr}$y銆�${if (p.ischanged == true) "鉁�" else "脳"}"
-                        if (p.ischanged == true) {
-                            if (changedProblem.isNotBlank()) {
-                                changedProblem += "\n"
-                            }
-                            changedProblem += "$y銆�${p.problemname}"
-                            cNum++
-                        } else {
-                            if (unChangedProblem.isNotBlank()) {
-                                unChangedProblem += "\n"
-                            }
-                            unChangedProblem += "$y銆�${p.problemname}"
-                            unChangeNum++
-                        }
-                        val status = when (p.extension3) {
-                            Constant.PROBLEM_CHECK_PASS -> "闂瀹℃牳閫氳繃"//
-                            Constant.PROBLEM_CHECK_FAIL -> "闂瀹℃牳鏈�氳繃"//
-                            Constant.PROBLEM_UNCHECKED -> "闂鏈鏍�"//
-                            Constant.CHANGE_UNCHECKED -> "鏁存敼鏈鏍�"//
-                            Constant.CHANGE_CHECK_PASS -> "鏁存敼瀹℃牳閫氳繃"//
-                            Constant.CHANGE_CHECK_FAIL -> "鏁存敼瀹℃牳鏈�氳繃"//
-                            else -> "闂鏈鏍�"
-                        }
-                        checkStatus += "${lr}$y銆�${status}"
-                        y++
-                    }
-                    addAll(listOf(pType, pDes, pLoc, pNum, pChanged, changedProblem, cNum, unChangedProblem, unChangeNum, checkStatus))
-                }
-            }
-
-            contents[i].addAll(row)
-        }
-
-        head[0].addAll(h1)
-    }
-
-
-
-    private fun getTableTitles(sceneType: Int?, districtCode: String?): List<String> {
-        if (sceneType == null || districtCode == null) return emptyList()
-        val heads = mutableListOf<String>()
-        heads.run {
-            addAll(getSceneName())
-            addAll(getLocation())
-            addAll(getBaseInfo(sceneType))
-            addAll(getContactInfo(sceneType))
-            addAll(getRealTimeStatus(sceneType))
-            addAll(getInspectionInfo(sceneType))
-            addAll(getProblemDistribution(sceneType, districtCode))
-        }
-
-        return heads
-    }
-
-    // 琛ㄥご锛氬満鏅悕
-    private fun getSceneName() = listOf("琛ㄥ崟缂栧彿", "鍞竴搴忓彿", "鍦烘櫙鍚嶇О")
-
-    // 琛ㄥご锛氬満鏅湴鐞嗕綅缃�
-    private fun getLocation(): List<String> = listOf(
-        "琛楅晣", "鍦板潃"
-    )
-
-    // 琛ㄥご锛氬満鏅笓灞炲熀纭�淇℃伅
-    private fun getBaseInfo(sceneType: Int): List<String> = when (sceneType.toString()) {
-        Constant.ScenseType.TYPE1.value -> listOf("涓氫富鍗曚綅", "鏂藉伐鍗曚綅", "寤虹瓚闈㈢Н(m虏)", "鏂藉伐璧峰鏃堕棿", "鏂藉伐缁撴潫鏃堕棿", "鏂藉伐闃舵", "宸ョ▼绫诲瀷")
-        Constant.ScenseType.TYPE2.value -> listOf("涓氫富鍗曚綅", "绉熻祦鍗曚綅", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��", "绫诲瀷")
-        Constant.ScenseType.TYPE3.value -> listOf("涓氫富鍗曚綅", "鏂囨槑鍦虹珯", "缁胯壊鐜繚绔欏巶", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��")
-        Constant.ScenseType.TYPE14.value -> listOf("涓氫富鍗曚綅", "绉熻祦鍗曚綅", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��", "绫诲瀷")
-        else -> listOf()
-    }
-
-    // 琛ㄥご锛氬満鏅仈绯绘柟寮�
-    private fun getContactInfo(sceneType: Int): List<String> = when (sceneType) {
-        else -> listOf("鑱旂郴浜�", "鑱旂郴鏂瑰紡")
-    }
-
-    // 琛ㄥご锛氬満鏅幇鍦烘儏鍐�
-    private fun getRealTimeStatus(sceneType: Int): List<String> = when (sceneType) {
-        else -> listOf()
-    }
-
-    // 琛ㄥご锛氬贰鏌ユ儏鍐靛強闂銆佹暣鏀圭粺璁�
-    private fun getInspectionInfo(sceneType: Int): List<String> = when (sceneType) {
-        else -> listOf("鐩戠鏃堕棿", "闃叉不鑰冩牳璇勫垎", "闃叉不瑙勮寖鎬�", "鎵e垎椤�","闂绫诲瀷", "闂鎻忚堪", "闂浣嶇疆", "闂鏁�", "鏁存敼鎯呭喌", "鏁存敼鏁�", "瀹℃牳鎯呭喌")
-    }
-
-    // 琛ㄥご锛氬叿浣撻棶棰樺垎甯�
-    private val currentProblemType = mutableMapOf<String, String>()
-    private val currentProblemHead = mutableListOf<String>()
-    private fun getProblemDistribution(sceneType: Int, districtCode: String): List<String> {
-        val heads = mutableListOf<String>()
-        currentProblemType.clear()
-        currentProblemHead.clear()
-
-        problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
-            createCriteria().andEqualTo("scensetypeid", sceneType)
-                .andEqualTo("districtcode", districtCode)
-            orderBy("typeid")
-        }).forEach {
-            if (!heads.contains(it.typename)) {
-                heads.add(it.typename ?: "")
-            }
-            currentProblemType[it.guid ?: ""] = it.typename ?: ""
-        }
-        currentProblemHead.addAll(heads)
-        return heads
-    }
-
-
-    /**
-     * 鑾峰彇琛ㄦ牸鏁版嵁婧�
-     */
-    private fun getTableDataSource(config: ExcelConfigVo): List<Subtask> {
-        if (config.sceneType == null) return emptyList()
-
-        val result = mutableListOf<Subtask>()
-
-        //1. 鏌ユ壘鐗瑰畾鐨勫贰鏌ヤ换鍔℃垨鑰呮墍鏈夌殑璁″垝宸℃煡浠诲姟
-        var taskSceneIdList = listOf<String>()
-        val subTaskList = if (config.subTaskIdList?.isNotEmpty() == true ||
-            (config.startTime != null || config.endTime != null)
-        ) {
-            subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-                createCriteria().apply {
-                    if (config.subTaskIdList?.isNotEmpty() == true) {
-                        andIn("stguid", config.subTaskIdList)
-                    }
-                    config.startTime?.let { andGreaterThanOrEqualTo("planstarttime", it) }
-                    config.endTime?.let { andLessThanOrEqualTo("planendtime", it) }
-                }
-            })
-        } else {
-            taskSceneIdList = monitorobjectversionMapper.getSceneByType(config.topTaskGuid, config.sceneType)
-            subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-                createCriteria().andIn("scenseid", taskSceneIdList)
-                    .andEqualTo("tguid", config.topTaskGuid)
-            })
-        }
-
-        if (taskSceneIdList.isNotEmpty()) {
-            taskSceneIdList.forEach {
-                var subtask: Subtask? = null
-                for (s in subTaskList) {
-                    if (s.scenseid == it) {
-                        subtask = s
-                        break
-                    }
-                }
-                if (subtask == null) subtask = Subtask().apply { scenseid = it }
-                result.add(subtask)
-            }
-        } else {
-            result.addAll(subTaskList)
-        }
+        result.calScore()
 
         return result
-    }
-
-    private fun getTableContents(config: ExcelConfigVo, colCounts: Int = 0): List<Array<Any>> {
-        if (config.sceneType == null) return emptyList()
-
-        //1. 鏌ユ壘鐗瑰畾鐨勫贰鏌ヤ换鍔℃垨鑰呮墍鏈夌殑璁″垝宸℃煡浠诲姟
-        var taskSceneIdList = listOf<String>()
-        val subTaskList = if (config.subTaskIdList?.isNotEmpty() == true ||
-            (config.startTime != null || config.endTime != null)
-        ) {
-            subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-                createCriteria().apply {
-                    if (config.subTaskIdList?.isNotEmpty() == true) {
-                        andIn("stguid", config.subTaskIdList)
-                    }
-                    config.startTime?.let { andGreaterThanOrEqualTo("planstarttime", it) }
-                    config.endTime?.let { andLessThanOrEqualTo("planendtime", it) }
-                }
-            })
-        } else {
-            taskSceneIdList = monitorobjectversionMapper.getSceneByType(config.topTaskGuid, config.sceneType)
-            subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-                createCriteria().andIn("scenseid", taskSceneIdList)
-                    .andEqualTo("tguid", config.topTaskGuid)
-            })
-        }
-
-        val contents = mutableListOf<Array<Any>>()
-        val subTasks = mutableListOf<Subtask>()
-
-        if (taskSceneIdList.isNotEmpty()) {
-            taskSceneIdList.forEach {
-                val rowContent = mutableListOf<Any>()
-
-                var subtask: Subtask? = null
-                for (s in subTaskList) {
-                    if (s.scenseid == it) {
-                        subtask = s
-                        break
-                    }
-                }
-                //璇ュ満鏅湭宸℃煡
-                if (subtask == null) {
-                    val scene = scenseMapper.selectByPrimaryKey(it)
-                    rowContent.apply {
-                        add(scene.index?.toString() ?: "")
-                        add(scene.extension2 ?: "")
-                        add(scene.name ?: "")
-                    }
-                    val left = colCounts - getSceneName().size
-                    repeat(left) {
-                        rowContent.add("")
-                    }
-                } else {
-                    rowContent.addAll(tableContent(subtask))
-                }
-
-                contents.add(rowContent.toTypedArray())
-            }
-        } else {
-            subTaskList.forEach {
-                val c = tableContent(it)
-                contents.add(c)
-            }
-        }
-
-        return contents
-    }
-
-    private fun tableContent(subtask: Subtask): Array<Any> {
-
-        val row = mutableListOf<Any>()
-        //鏌ヨ璇ヤ换鍔″搴旂殑鍦烘櫙
-        val scene = scenseMapper.selectByPrimaryKey(subtask.scenseid)
-
-        row.apply {
-            // 琛ㄥご锛氬満鏅悕
-            add(scene.index?.toString() ?: "")
-            add(scene.extension2 ?: "")
-            add(scene.name ?: "")
-            // 琛ㄥご锛氬満鏅湴鐞嗕綅缃�
-            add(scene.townname ?: "")
-            add(scene.location ?: "")
-            // 琛ㄥご锛氬満鏅笓灞炲熀纭�淇℃伅
-            addAll(when (scene.typeid.toString()) {
-                Constant.ScenseType.TYPE1.value -> {
-//                    listOf("涓氫富鍗曚綅", "鏂藉伐鍗曚綅", "寤虹瓚闈㈢Н(m虏)", "鏂藉伐璧峰鏃堕棿", "鏂藉伐缁撴潫鏃堕棿", "鏂藉伐闃舵", "宸ョ▼绫诲瀷")
-                    var r = listOf("-", "-", "-", "-", "-", "-", "-")
-                    sceneConstructionSiteMapper.selectByPrimaryKey(scene.guid)?.let {
-                        r = listOf(it.csEmployerUnit?:"", it.csConstructionUnit?:"", it.csFloorSpace?:"",
-                            it.csStartTime?:"", it.csEndTime?:"", it.csStatus?:"", it.csProjectType?:"")
-                    }
-                    r
-                }
-                Constant.ScenseType.TYPE2.value -> {
-//                    listOf("涓氫富鍗曚綅", "绉熻祦鍗曚綅", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��", "绫诲瀷")
-                    var r = listOf("-", "-", "-", "-", "-")
-                    sceneWharfMapper.selectByPrimaryKey(scene.guid)?.let {
-                        r = listOf(it.getwEmployerUnit()?:"", it.getwRentUnit()?:"", it.getwFloorSpace()?:"", it.getwStatus()?:"",
-                            it.getwProjectType()?:"")
-                    }
-                    r
-                }
-                Constant.ScenseType.TYPE3.value -> {
-//                    listOf("涓氫富鍗曚綅", "鏂囨槑鍦虹珯", "缁胯壊鐜繚绔欏巶", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��")
-                    var r = listOf("-", "-", "-", "-", "-")
-                    sceneMixingPlantMapper.selectByPrimaryKey(scene.guid)?.let {
-                        r = listOf(
-                            it.mpEmployerUnit?:"", if (it.mpCivillyPlant == true) "鏄�" else "鍚�", if (it.mpGreenPlant == true) "鏄�" else "鍚�",
-                            it.mpFloorSpace?:"", it.mpStatus?:""
-                        )
-                    }
-                    r
-                }
-                Constant.ScenseType.TYPE14.value -> {
-//                    listOf("涓氫富鍗曚綅", "绉熻祦鍗曚綅", "鍗犲湴闈㈢Н(m虏)", "钀ヨ繍鐘舵��", "绫诲瀷")
-                    var r = listOf("-", "-", "-", "-", "-")
-                    sceneStorageYardMapper.selectByPrimaryKey(scene.guid)?.let {
-                        r = listOf(it.syEmployerUnit?:"", it.syRentUnit?:"", it.syFloorSpace?:"", it.syStatus?:"", it.syProjectType?:"")
-                    }
-                    r
-                }
-                else -> listOf()
-            })
-            // 琛ㄥご锛氬満鏅仈绯绘柟寮�
-            add(scene.contacts ?: "")
-            add(scene.contactst ?: "")
-            // 琛ㄥご锛氬満鏅幇鍦烘儏鍐�
-            // TODO: 2022/7/10 鏆傛棤
-            // 琛ㄥご锛氬贰鏌ユ儏鍐靛強闂銆佹暣鏀圭粺璁� 鍜� 琛ㄥご锛氬叿浣撻棶棰樺垎甯�
-            listOf("鐩戠鏃堕棿", "闃叉不鑰冩牳璇勫垎", "闃叉不瑙勮寖鎬�", "鎵e垎椤�","闂绫诲瀷", "闂鎻忚堪", "闂浣嶇疆", "闂鏁�", "鏁存敼鎯呭喌", "鏁存敼鏁�", "瀹℃牳鎯呭喌")
-            add(dateUtil.DateToString(subtask.planstarttime, DateUtil.DateStyle.MM_DD) ?: "")
-            add("")
-            add("")
-            add("")
-            //鏌ヨ瀛愪换鍔″搴旂殑闂锛屽苟涓旀牴鎹潯浠惰繘琛岀瓫閫�
-            var y = 1
-            var pType = ""//闂绫诲瀷
-            var pDes = ""//闂鎻忚堪
-            var pLoc = ""//闂浣嶇疆
-            var pNum = 0//闂鏁�
-            var pChanged = ""//鏁存敼鎯呭喌
-            var cNum = 0//鏁存敼鏁�
-            var checkStatus = ""//瀹℃牳鎯呭喌
-            var pDis = mutableListOf<String>()//鍏蜂綋闂鍒嗗竷
-            repeat(currentProblemHead.size) { pDis.add("")}
-            problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
-                createCriteria().andEqualTo("stguid", subtask.stguid)
-            }).forEach problemType@{ p ->
-                val typeName = currentProblemType[p.ptguid]
-                val lr = if (y > 1) "\n" else ""
-                //宸℃煡鎯呭喌鍙婇棶棰樸�佹暣鏀圭粺璁�
-                pType += "${lr}$y銆�${typeName}"
-                pDes += "${lr}$y銆�${p.problemname}"
-                pLoc += "${lr}$y銆�${p.location}"
-                pNum++
-                pChanged += "${lr}$y銆�${if (p.ischanged == true) "鉁�" else "脳"}"
-                if (p.ischanged == true) cNum++
-                val status = when (p.extension3) {
-                    Constant.PROBLEM_CHECK_PASS -> "闂瀹℃牳閫氳繃"//
-                    Constant.PROBLEM_CHECK_FAIL -> "闂瀹℃牳鏈�氳繃"//
-                    Constant.PROBLEM_UNCHECKED -> "闂鏈鏍�"//
-                    Constant.CHANGE_UNCHECKED -> "鏁存敼鏈鏍�"//
-                    Constant.CHANGE_CHECK_PASS -> "鏁存敼瀹℃牳閫氳繃"//
-                    Constant.CHANGE_CHECK_FAIL -> "鏁存敼瀹℃牳鏈�氳繃"//
-                    else -> "闂鏈鏍�"
-                }
-                checkStatus += "${lr}$y銆�${status}"
-                y++
-
-                //鍏蜂綋闂鍒嗗竷
-                for (t in currentProblemHead.indices) {
-                    if (typeName == currentProblemHead[t]) {
-                        pDis[t] = if (p.ischanged == true) "1" else "0"
-                        break
-                    }
-                }
-            }
-            addAll(listOf(pType, pDes, pLoc, pNum, pChanged, cNum, checkStatus))
-            addAll(pDis)
-        }
-
-        return row.toTypedArray()
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3