From 39e208b6b0482a25c77e53590087c02d9d937563 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 20 七月 2022 09:04:48 +0800
Subject: [PATCH] 1. 巡查汇总报告功能编写完成

---
 src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt |   78 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 2 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..cea8933 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/business/report/DataSource.kt
@@ -4,10 +4,18 @@
 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 java.time.LocalDateTime
+import java.time.ZoneId
 import javax.annotation.PostConstruct
 
 /**
@@ -20,6 +28,12 @@
     private val dateUtil = DateUtil()
 
     private val sourceList = mutableListOf<Subtask>()
+
+    var year = 0
+
+    var month = 0
+
+    var area = ""
 
     val rowData = RowData()
 
@@ -36,6 +50,7 @@
     fun loop(callback: (index:Int, rowData: RowData) -> Unit) {
         reset()
         for (i in sourceList.indices) {
+            rowData.index = i
             rowData.clear()
             rowData.subTask = sourceList[i]
             callback(i, rowData)
@@ -46,6 +61,7 @@
      * 閲嶇疆
      */
     fun reset() {
+        rowData.index = 0
         rowData.subTask = sourceList.first()
         rowData.clear()
     }
@@ -55,7 +71,7 @@
      */
     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(t.starttime, DateUtil.DateStyle.YYYY_MM_CN)}${t.districtname}${if (area != t.districtname) area else ""}${Constant.ScenseType.getDes(config.sceneType)}"
     }
 
     /**
@@ -65,6 +81,19 @@
         if (config.sceneType == null) return
 
         val result = mutableListOf<Subtask>()
+
+        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 ?: "" }
+        }
+
+        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 ?: ""
+        }
 
         //1. 鏌ユ壘鐗瑰畾鐨勫贰鏌ヤ换鍔℃垨鑰呮墍鏈夌殑璁″垝宸℃煡浠诲姟
         var taskSceneIdList = listOf<String>()
@@ -109,6 +138,8 @@
 
 
     inner class RowData(){
+        var index = 0
+
         var subTask: Subtask? = null
 
         //鍦烘櫙鍩烘湰淇℃伅
@@ -263,6 +294,43 @@
             }
         private var _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
 
+        //蹇呭~鍙拌处鏁伴噺
+        val ledgerCount: Int
+            get() {
+                if (_ledgerCount == -1) {
+                    val tzSceneType = Constant.ScenseType.typeMap(config.sceneType?.toByte())
+                    _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
+
         /**
          * 娓呯┖褰撳墠澶勭悊鐨勫璞$殑鐩稿叧鏁版嵁婧�
          */
@@ -272,6 +340,7 @@
             _problems.clear()
             _evaluation = null
             _itemevaluationList.clear()
+            _ledgerRecordNum = null
         }
 
         /**
@@ -295,5 +364,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