From 2ae8bf126599f68ba1ca721ff2acc1dd4461e9a5 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 12 九月 2023 11:05:47 +0800
Subject: [PATCH] 1. 整合了飞羽环境、徐汇油烟及金山扬尘两个数据库; 2. 优化重构自动评估模块逻辑; 3. 新增监测数据自动化统; 4. 将自动统计应用于自动评估中;

---
 src/main/kotlin/cn/flightfeather/supervision/datafetch/FetchNightConstruction.kt |  120 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/datafetch/FetchNightConstruction.kt b/src/main/kotlin/cn/flightfeather/supervision/datafetch/FetchNightConstruction.kt
index 76442a5..6c76816 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/datafetch/FetchNightConstruction.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/datafetch/FetchNightConstruction.kt
@@ -4,9 +4,14 @@
 import cn.flightfeather.supervision.domain.ds1.entity.NightConstruction
 import cn.flightfeather.supervision.domain.ds1.mapper.NightConstructionMapper
 import cn.flightfeather.supervision.common.utils.DateUtil
+import cn.flightfeather.supervision.domain.ds1.entity.Scense
+import cn.flightfeather.supervision.domain.ds1.entity.Userinfo
+import cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper
+import cn.flightfeather.supervision.domain.ds1.mapper.UserinfoMapper
 import com.github.pagehelper.PageHelper
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Component
+import org.springframework.transaction.annotation.Transactional
 import tk.mybatis.mapper.entity.Example
 import java.util.*
 import javax.annotation.PostConstruct
@@ -27,28 +32,37 @@
         private const val CITY_NAME = "涓婃捣甯�"
         private const val DISTRICT_NAME = "闈欏畨鍖�"
 
-        private const val DEFAULT_TIME = "2020-12-01 00:00:00"
+        private const val DEFAULT_TIME = "2022-01-01 00:00:00"
     }
 
     @Autowired
     lateinit var nightConstructionMapper: NightConstructionMapper
+
+    @Autowired
+    lateinit var scenseMapper: ScenseMapper
+
+    @Autowired
+    lateinit var userinfoMapper: UserinfoMapper
 
     private val dateUtil = DateUtil()
 
     @PostConstruct
     fun init() {
         instance = this
+        this.nightConstructionMapper = instance.nightConstructionMapper
+        this.scenseMapper = instance.scenseMapper
+        this.userinfoMapper = instance.userinfoMapper
     }
-
 
     override fun fetch() {
         PageHelper.startPage<NightConstruction>(1, 1)
-        nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
+        val res = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
             createCriteria().andEqualTo("ncProvinceCode", PROVINCE_CODE)
-                    .andEqualTo("ncCityCode", CITY_CODE)
-                    .andEqualTo("ncDistrictCode", DISTRICT_CODE)
+                .andEqualTo("ncCityCode", CITY_CODE)
+                .andEqualTo("ncDistrictCode", DISTRICT_CODE)
             orderBy("ncCreateTime").desc()
-        }).let {
+        })
+        res.let {
             val timeStr = if (it.isNotEmpty()) {
                 val cal = Calendar.getInstance().apply { time = it[0]?.ncCreateTime }
                 cal.add(Calendar.DAY_OF_MONTH, -1)
@@ -56,48 +70,72 @@
             } else {
                 DEFAULT_TIME
             }
+//            val timeStr = DEFAULT_TIME
 
-            NCHttpService.getFile(timeStr)?.forEach {e ->
-                if (e.isJsonObject) {
-                    val vo = e.asJsonObject
-                    val nightConstruction = NightConstruction().apply {
-                        ncNum = vo["nightallnum"].asString
-                        ncItemName = vo["itemName"].asString
-                        ncItemUnit = vo["itemUnit"].asString
-                        ncConstructionUnit = vo["constructionUnit"].asString
-                        ncPerson = vo["person"].asString
-                        ncApplyContent = vo["applyContent"].asString
-                        ncStartDate = dateUtil.StringToDate(vo["startDate"].asString)
-                        ncEndDate = dateUtil.StringToDate(vo["endDate"].asString)
-                        ncFileName = vo["filename"].asString
-                        ncCreateTime = dateUtil.StringToDate(vo["createtime"].asString)
-                        ncUrl = vo["url"].asString
 
-                        ncProvinceCode = PROVINCE_CODE
-                        ncProvinceName = PROVINCE_NAME
-                        ncCityCode = CITY_CODE
-                        ncCityName = CITY_NAME
-                        ncDistrictCode = DISTRICT_CODE
-                        ncDistrictName = DISTRICT_NAME
-                    }
-                    nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
-                        createCriteria().andEqualTo("ncNum", nightConstruction.ncNum)
-                    }).run {
-                        nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
-                            createCriteria().andEqualTo("ncItemName", nightConstruction.ncItemName)
-                        }).takeIf { l-> l.isNotEmpty() }?.get(0)?.let { r->
-                            nightConstruction.ncUserId = r.ncUserId
-                            nightConstruction.ncSceneId = r.ncSceneId
+            try {
+                NCHttpService.getFile(timeStr)?.forEach {e ->
+                    if (e.isJsonObject) {
+                        val vo = e.asJsonObject
+                        val nightConstruction = NightConstruction().apply {
+                            ncNum = vo["nightallnum"].asString
+                            ncItemName = vo["itemName"].asString
+                            ncItemUnit = vo["itemUnit"].asString
+                            ncConstructionUnit = vo["constructionUnit"].asString
+                            ncPerson = vo["person"].asString
+                            ncApplyContent = vo["applyContent"].asString
+                            ncStartDate = dateUtil.StringToDate(vo["startDate"].asString)
+                            ncEndDate = dateUtil.StringToDate(vo["endDate"].asString)
+                            ncFileName = vo["filename"].asString
+                            ncCreateTime = dateUtil.StringToDate(vo["createtime"].asString)
+                            ncUrl = vo["url"].asString
+
+                            ncProvinceCode = PROVINCE_CODE
+                            ncProvinceName = PROVINCE_NAME
+                            ncCityCode = CITY_CODE
+                            ncCityName = CITY_NAME
+                            ncDistrictCode = DISTRICT_CODE
+                            ncDistrictName = DISTRICT_NAME
                         }
-                        if (isEmpty()) {
-                            try {
-                                nightConstructionMapper.insert(nightConstruction)
-                            } catch (e: Exception) {
-                                e.printStackTrace()
+                        val history = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java)
+                            .apply {
+                                createCriteria().andEqualTo("ncNum", nightConstruction.ncNum)
+                            })
+                        // 鍒ゆ柇璇ュ鏂芥枃浠舵槸鍚﹀瓨鍦�
+                        if (history.isNotEmpty()) return@forEach
+
+                        var sceneId: String? = null
+                        var userId: String? = null
+                        // 鑾峰彇璇ュ鏂藉搴斾紒涓氱殑鍘嗗彶璁板綍
+                        val records = nightConstructionMapper.selectByExample(Example(NightConstruction::class.java)
+                            .apply {
+                                createCriteria().andEqualTo("ncItemName", nightConstruction.ncItemName)
+                            })
+                        if (records.isNotEmpty()) {
+                            sceneId = records[0]?.ncSceneId
+                            userId = records[0]?.ncUserId
+                        }
+                        // 鑻ユ棤鍘嗗彶璁板綍锛屾煡鎵惧満鏅〃锛屽垽鏂槸鍚︽湁鐩稿悓鍚嶇О鐨勫満鏅�
+                        else {
+                            val scenes = scenseMapper.selectByExample(Example(Scense::class.java).apply {
+                                createCriteria().andEqualTo("name", nightConstruction.ncItemName)
+                            })
+                            if (scenes.isNotEmpty()) {
+                                sceneId = scenes[0].guid
+                                val user = userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
+                                    createCriteria().andEqualTo("dGuid", sceneId)
+                                })
+                                if (user.isNotEmpty()) userId = user[0].guid
                             }
                         }
+                        nightConstruction.ncUserId = userId
+                        nightConstruction.ncSceneId = sceneId
+
+                        nightConstructionMapper.insert(nightConstruction)
                     }
                 }
+            } catch (e: Exception) {
+                e.printStackTrace()
             }
         }
     }

--
Gitblit v1.9.3