From 90615ce702dde7f1d8fed373d8f3a96796ef1f2d Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 21 十一月 2024 09:23:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'supervision/hc-recheck-1114'

---
 src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt |  284 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 201 insertions(+), 83 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt b/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
index 77154e7..96f71fa 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
@@ -4,11 +4,17 @@
 import cn.flightfeather.supervision.common.utils.DateUtil
 import cn.flightfeather.supervision.domain.ds1.entity.*
 import cn.flightfeather.supervision.domain.ds1.mapper.*
+import cn.flightfeather.supervision.domain.ds2.entity.LedgerRecord
+import cn.flightfeather.supervision.domain.ds2.entity.LedgerSubType
+import cn.flightfeather.supervision.domain.ds2.entity.UserMap
+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.vo.ExcelConfigVo
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Component
 import tk.mybatis.mapper.entity.Example
-import javax.annotation.PostConstruct
+import java.time.LocalDateTime
+import java.time.ZoneId
 
 /**
  * 鎶ュ憡鎵�闇�婧愭暟鎹�
@@ -17,27 +23,33 @@
  */
 class DataSource(val config: ExcelConfigVo, val dbMapper: DbMapper){
 
-    private val dateUtil = DateUtil()
-
     private val sourceList = mutableListOf<Subtask>()
+
+    var year = 0
+
+    var month = 0
+
+    var area = ""
 
     val rowData = RowData()
 
     init {
-        if (config.districtCode == null) {
-            throw IllegalStateException("鍙傛暟缂哄皯鍖哄幙缂栫爜:[districtCode]")
-        }
-        if (config.sceneType == null) {
-            throw IllegalStateException("鍙傛暟缂哄皯鍦烘櫙绫诲瀷:[sceneType]")
-        }
+//        if (config.districtCode == null) {
+//            throw IllegalStateException("鍙傛暟缂哄皯鍖哄幙缂栫爜:[districtCode]")
+//        }
+//        if (config.sceneType == null) {
+//            throw IllegalStateException("鍙傛暟缂哄皯鍦烘櫙绫诲瀷:[sceneType]")
+//        }
         getSource(config)
     }
 
     fun loop(callback: (index:Int, rowData: RowData) -> Unit) {
-        reset()
+//        reset()
         for (i in sourceList.indices) {
-            rowData.clear()
+//            rowData.recordLastScene()
+            rowData.index = i
             rowData.subTask = sourceList[i]
+            rowData.clear()
             callback(i, rowData)
         }
     }
@@ -46,7 +58,8 @@
      * 閲嶇疆
      */
     fun reset() {
-        rowData.subTask = sourceList.first()
+        rowData.index = 0
+        rowData.subTask = if (sourceList.isEmpty()) null else sourceList.first()
         rowData.clear()
     }
 
@@ -55,52 +68,69 @@
      */
     fun areaName(): String {
         val t = dbMapper.taskMapper.selectByPrimaryKey(config.topTaskGuid)
-        return "${dateUtil.DateToString(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${Constant.ScenseType.getDes(config.sceneType)}"
+        return "${DateUtil.DateToString(config.startTime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${if (area != t.districtname) area else ""}${Constant.SceneType.getDes(config.sceneType)}"
     }
 
     /**
-     * 鑾峰彇鎶ュ憡鏁版嵁婧�
+     * 鑾峰彇鎶ュ憡鏁版嵁婧愶紙宸℃煡浠诲姟锛�
      */
     private fun getSource(config: ExcelConfigVo) {
-        if (config.sceneType == null) return
+//        if (config.sceneType == null) return
 
         val result = mutableListOf<Subtask>()
 
-        //1. 鏌ユ壘鐗瑰畾鐨勫贰鏌ヤ换鍔℃垨鑰呮墍鏈夌殑璁″垝宸℃煡浠诲姟
-        var taskSceneIdList = listOf<String>()
-        val subTaskList = if (config.subTaskIdList?.isNotEmpty() == true ||
-            (config.startTime != null || config.endTime != null)
-        ) {
-            dbMapper.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 = dbMapper.monitorobjectversionMapper.getSceneByType(config.topTaskGuid, config.sceneType)
-            dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
-                createCriteria().andIn("scenseid", taskSceneIdList)
-                    .andEqualTo("tguid", config.topTaskGuid)
-            })
+        if (config.townCode != null) {
+            dbMapper.townMapper.selectByExample(Example(Town::class.java).apply {
+                createCriteria().andEqualTo("towncode", config.townCode)
+            })?.takeIf { it.isNotEmpty() }?.get(0)?.let { area = it.townname ?: "" }
         }
 
-        if (taskSceneIdList.isNotEmpty()) {
-            taskSceneIdList.forEach {
-                var subtask: Subtask? = null
-                for (s in subTaskList) {
-                    if (s.scenseid == it) {
-                        subtask = s
-                        break
+        dbMapper.taskMapper.selectByPrimaryKey(config.topTaskGuid)?.let {
+            val time = LocalDateTime.ofInstant(it.starttime?.toInstant(), ZoneId.systemDefault())
+            this.year = time.year
+            this.month = time.monthValue
+            if (area.isBlank()) area = it.districtname ?: ""
+        }
+
+        // 缁熻鎬讳换鍔′笅鎵�鏈夊満鏅�
+        if (config.allScene) {
+            //1. 鏌ユ壘鐗瑰畾鐨勫贰鏌ヤ换鍔℃垨鑰呮墍鏈夌殑璁″垝宸℃煡浠诲姟
+            val taskSceneIdList = dbMapper.scenseMapper.getSceneByType(config.topTaskGuid, config.sceneType,
+                config.townCode).map { it.guid ?: "" }
+
+            val subTaskList = dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                createCriteria().apply {
+                    if (taskSceneIdList.isNotEmpty()) 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
+                            result.add(s)
+                        }
+                    }
+                    if (subtask == null) {
+                        result.add(Subtask().apply { scenseid = it })
                     }
                 }
-                if (subtask == null) subtask = Subtask().apply { scenseid = it }
-                result.add(subtask)
+            } else {
+                result.addAll(subTaskList)
             }
-        } else {
+        }
+        else {
+            val subTaskList = dbMapper.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) }
+                        config.districtCode?.let { andEqualTo("districtcode", it) }
+                        andEqualTo("tguid", config.topTaskGuid)
+                    }
+                })
             result.addAll(subTaskList)
         }
 
@@ -109,7 +139,11 @@
 
 
     inner class RowData(){
+        var index = 0
+
         var subTask: Subtask? = null
+
+        private var lastScene: Scense? = null
 
         //鍦烘櫙鍩烘湰淇℃伅
         val scene: Scense?
@@ -126,16 +160,16 @@
             get() {
                 if (_baseScene == null) {
                     _baseScene = when (this.scene?.typeid.toString()) {
-                        Constant.ScenseType.TYPE1.value -> {
+                        Constant.SceneType.TYPE1.value -> {
                             dbMapper.sceneConstructionSiteMapper.selectByPrimaryKey(scene?.guid)
                         }
-                        Constant.ScenseType.TYPE2.value -> {
+                        Constant.SceneType.TYPE2.value -> {
                             dbMapper.sceneWharfMapper.selectByPrimaryKey(scene?.guid)
                         }
-                        Constant.ScenseType.TYPE3.value -> {
+                        Constant.SceneType.TYPE3.value -> {
                             dbMapper.sceneMixingPlantMapper.selectByPrimaryKey(scene?.guid)
                         }
-                        Constant.ScenseType.TYPE14.value -> {
+                        Constant.SceneType.TYPE14.value -> {
                             dbMapper.sceneStorageYardMapper.selectByPrimaryKey(scene?.guid)
                         }
                         else -> null
@@ -146,20 +180,21 @@
         private var _baseScene: BaseScene? = null
 
         //鍏蜂綋鐨勯棶棰�
-        val problems: MutableList<Problemlist>
+        val problems: List<Problemlist>
             get() {
                 if (noRecord()) return mutableListOf()
 
-                if (_problems.isEmpty()) {
+                if (_problems == null) {
                     val r = dbMapper.problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
                         createCriteria().andEqualTo("stguid", subTask?.stguid)
                     })
-                    _problems.addAll(r)
+                    _problems = r
                 }
-                return _problems
+                return _problems ?: emptyList()
             }
-        private var _problems = mutableListOf<Problemlist>()
+        private var _problems: List<Problemlist>? = null
 
+        //璇勪及鎬诲垎
         val evaluation: Evaluation?
             get() {
                 if (_evaluation == null) {
@@ -173,42 +208,45 @@
             }
         private var _evaluation: Evaluation? = null
 
-        val itemevaluationList: MutableList<Itemevaluation>
+        //璇勪及缁嗗垯寰楀垎
+        val itemevaluationList: List<Itemevaluation>
             get() {
-                if (_itemevaluationList.isEmpty()) {
+                if (_itemevaluationList == null) {
                     val r = dbMapper.itemevaluationMapper.selectByExample(Example(Itemevaluation::class.java).apply {
                         createCriteria().andEqualTo("stguid", subTask?.stguid)
                     })
-                    _itemevaluationList.addAll(r)
+                    _itemevaluationList = r
                     println("-------------------itemevaluationList--------------------------------")
                 }
-                return _itemevaluationList
+                return _itemevaluationList ?: emptyList()
             }
-        private var _itemevaluationList = mutableListOf<Itemevaluation>()
+        private var _itemevaluationList: List<Itemevaluation>? = null
 
         //闂绫诲瀷
-        val problemTypes: MutableList<Problemtype>
+        val problemTypes: List<Problemtype>
             get() {
-                if (_problemTypes.isEmpty()) {
+                if (_problemTypes == null) {
                     val r = dbMapper.problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
-                        createCriteria().andEqualTo("scensetypeid", config.sceneType)
-                            .andEqualTo("districtcode", config.districtCode)
+                        createCriteria().andEqualTo("scensetypeid", scene?.typeid)
+                            .andEqualTo("districtcode", scene?.districtcode)
                         orderBy("extension1")
                     })
-                    _problemTypes.addAll(r)
+                    _problemTypes = r
                 }
-                return _problemTypes
+                return _problemTypes ?: emptyList()
             }
-        private var _problemTypes = mutableListOf<Problemtype>()
+        private var _problemTypes: List<Problemtype>? = null
 
         //鑷姩璇勫垎瑙勫垯涓�绾у垎绫�
-        val topItems: MutableList<Evaluationsubrule2>
+        val topItems: List<Evaluationsubrule2>
             get() {
-                if (_topItems.isEmpty()) {
+                if (_topItems == null) {
+                    val tempTopItems = mutableListOf<Evaluationsubrule2>()
+                    val secRules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
                     val rule = dbMapper.evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
                         createCriteria()
                             .andEqualTo("tasktypeid", 99)
-                            .andEqualTo("scensetypeid", config.sceneType)
+                            .andEqualTo("scensetypeid", scene?.typeid)
                     })
                     if (rule.isNotEmpty()) {
                         val ruleId = rule[0].guid
@@ -217,13 +255,13 @@
                         })
                         rules.forEach {
                             if (it.ertype == 2) {
-                                _topItems.add(it)
+                                tempTopItems.add(it)
                             }
                         }
-                        _topItems.sortBy { it.displayid }
+                        tempTopItems.sortBy { it.displayid }
 
                         var t = 0
-                        _topItems.forEach {
+                        tempTopItems.forEach {
                             t += it.maxscore ?: 0
                             val tempRules = mutableListOf<Evaluationsubrule2>()
                             for (i in rules) {
@@ -244,24 +282,90 @@
                                     }
                                 }
                                 tempSubRules.sortBy { ts -> ts.displayid }
-                                this._rules.add(Pair(temp, tempSubRules))
+                                secRules.add(Pair(temp, tempSubRules))
                             }
                         }
                     }
+                    this._rules = secRules
+                    _topItems = tempTopItems
                 }
-                return _topItems
+                return _topItems ?: emptyList()
             }
-        private var _topItems = mutableListOf<Evaluationsubrule2>()
+        private var _topItems: List<Evaluationsubrule2>? = null
 
         //鑷姩璇勫垎瑙勫垯浜岀骇鍜屼笁绾у垎绫�
-        val rules: MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>
+        val rules: List<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>
             get() {
-                if (_rules.isEmpty()) {
+                if (_rules == null) {
                     this.topItems
                 }
-                return _rules
+                return _rules ?: emptyList()
             }
-        private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
+        private var _rules: List<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>? = null
+
+        //蹇呭~鍙拌处鏁伴噺
+        val ledgerCount: Int
+            get() {
+                if (_ledgerCount == -1) {
+                    val tzSceneType = Constant.SceneType.typeMap(scene?.typeid)
+                    _ledgerCount = dbMapper.ledgerSubTypeMapper.selectCountByExample(Example(LedgerSubType::class.java).apply {
+                        createCriteria().andEqualTo("lScenetype", tzSceneType).andEqualTo("lNeedupdate", true)
+                    })
+                }
+                return _ledgerCount
+            }
+        private var _ledgerCount = -1
+
+        //鐢ㄦ埛瀹為檯鎻愪氦鍙拌处鏁伴噺
+        val ledgerRecords: List<LedgerRecord>
+            get() {
+                if (_ledgerRecordNum == null) {
+                    val userInfo = dbMapper.userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
+                        createCriteria().andEqualTo("dGuid", subTask?.scenseid)
+                    })?.takeIf { l -> l.isNotEmpty() }?.get(0)
+
+                    val tzUserId = dbMapper.userMapMapper.selectByExample(Example(UserMap::class.java).apply {
+                        createCriteria().andEqualTo("svUserId", userInfo?.guid)
+                    })?.takeIf { m-> m.isNotEmpty() }?.get(0)?.tzUserId
+
+                    if (tzUserId != null) {
+                        _ledgerRecordNum = dbMapper.ledgerRecordMapper.selectByExample(Example(LedgerRecord::class.java).apply {
+                            createCriteria().andEqualTo("lrYear", year)
+                                    .andEqualTo("lrMonth", month)
+                                    .andEqualTo("lrSubmitid", tzUserId)
+                        })
+                    }
+                }
+                return _ledgerRecordNum ?: emptyList()
+            }
+        private var _ledgerRecordNum: List<LedgerRecord>? = null
+
+        /**
+         * 鑾峰彇褰撳墠宸℃煡浠诲姟鐨勪笂鏈熷贰鏌ヨ褰�
+         */
+        fun lastOne(): RowData {
+            val last = RowData()
+            val r = dbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                createCriteria().andEqualTo("scenseid", subTask?.scenseid)
+                    .andLessThan("planstarttime", subTask?.planstarttime)
+                orderBy("planstarttime").desc()
+            })
+            if (r.isNotEmpty()) {
+                val thisMonth = LocalDateTime.ofInstant(subTask?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1).toLocalDate()
+                val lastMonth = LocalDateTime.ofInstant(r[0]?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1).toLocalDate()
+                if (lastMonth.plusMonths(1).isEqual(thisMonth)) {
+                    last.subTask = r[0]
+                }
+            }
+            return last
+        }
+
+        /**
+         * 璁板綍涓婁竴涓満鏅�
+         */
+        fun recordLastScene() {
+            lastScene = scene
+        }
 
         /**
          * 娓呯┖褰撳墠澶勭悊鐨勫璞$殑鐩稿叧鏁版嵁婧�
@@ -269,9 +373,17 @@
         fun clear() {
             _scene = null
             _baseScene = null
-            _problems.clear()
+            _problems = null
             _evaluation = null
-            _itemevaluationList.clear()
+            _itemevaluationList = null
+            _ledgerRecordNum = null
+            if (lastScene != null && lastScene?.typeid != scene?.typeid) {
+                _problemTypes = null
+                _topItems = null
+                _rules = null
+                _ledgerCount = -1
+            }
+            recordLastScene()
         }
 
         /**
@@ -281,6 +393,7 @@
     }
 }
 
+@Component
 data class DbMapper(
     val scenseMapper: ScenseMapper,
     val problemlistMapper: ProblemlistMapper,
@@ -295,5 +408,10 @@
     val evaluationruleMapper: EvaluationruleMapper,
     val evaluationsubruleMapper: EvaluationsubruleMapper2,
     val evaluationMapper: EvaluationMapper,
-    val itemevaluationMapper: ItemevaluationMapper
+    val itemevaluationMapper: ItemevaluationMapper,
+    val ledgerSubTypeMapper: LedgerSubTypeMapper,
+    val ledgerRecordMapper: LedgerRecordMapper,
+    val userinfoMapper: UserinfoMapper,
+    val userMapMapper: UserMapMapper,
+    val townMapper: TownMapper,
 )

--
Gitblit v1.9.3