From 027bf7da7a012fa36f8835b2419c74da8b2f1c28 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 15 十一月 2022 11:00:21 +0800
Subject: [PATCH] 2022.11.15

---
 src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt b/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt
new file mode 100644
index 0000000..5e4c86b
--- /dev/null
+++ b/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt
@@ -0,0 +1,113 @@
+package cn.flightfeather.supervision.timingtask
+
+import cn.flightfeather.supervision.common.net.VOCHttpService
+import cn.flightfeather.supervision.domain.entity.DeviceInfo
+import cn.flightfeather.supervision.domain.entity.VOCHourValue
+import cn.flightfeather.supervision.domain.enumeration.DistrictType
+import cn.flightfeather.supervision.domain.enumeration.SceneType
+import cn.flightfeather.supervision.domain.mapper.DeviceInfoMapper
+import cn.flightfeather.supervision.domain.mapper.VOCHourValueMapper
+import cn.flightfeather.supervision.infrastructure.utils.DateUtil
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Component
+import tk.mybatis.mapper.entity.Example
+import java.time.LocalDateTime
+import java.util.*
+import javax.annotation.PostConstruct
+
+/**
+ * 鑾峰彇voc鐩戞祴鏁版嵁
+ */
+@Component
+class FetchVOC : BaseTimingTask() {
+    companion object {
+        private lateinit var instance: FetchVOC
+    }
+
+    @Autowired
+    lateinit var deviceInfoMapper: DeviceInfoMapper
+
+    @Autowired
+    lateinit var vocHourValueMapper: VOCHourValueMapper
+
+    @PostConstruct
+    fun init() {
+        instance = this
+    }
+
+    override val period: Long
+        get() = 15L
+
+    override fun doTask(localtime:LocalDateTime) {
+        getVOCData()
+    }
+
+    private fun getVOCData() {
+        val deviceCodeList = mutableListOf<String>()
+        deviceInfoMapper.selectByExample(Example(DeviceInfo::class.java).apply {
+            createCriteria().andEqualTo("diProvinceCode", "31")
+                .andEqualTo("diCityCode", "3100")
+                .andEqualTo("diDistrictCode", DistrictType.XuHui.code)
+                .andEqualTo("diSceneTypeId", SceneType.VehicleRepair.value)
+                .andEqualTo("diDeviceTypeId", 1)
+        }).forEach {
+            it?.let {
+                deviceCodeList.add(it.diCode)
+            }
+        }
+
+        val cal = Calendar.getInstance(Locale.CHINA).apply {
+            set(Calendar.MINUTE, 0)
+            set(Calendar.SECOND, 0)
+        }
+        val endTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: ""
+        cal.add(Calendar.HOUR_OF_DAY, -1)
+        val startTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: ""
+
+        deviceCodeList.forEach {
+            val deviceInfo = VOCHttpService.DeviceInfo(listOf(it), startTime, endTime)
+//            threadPoo?.execute {
+                VOCHttpService.getVOCData(deviceInfo)?.run {
+                    try {
+                        if (this["code"].asInt == 200) {
+                            val data = this["data"].asJsonObject
+                            data["rtdMinuteHourDayBeans"].asJsonArray.forEach {e ->
+                                e.asJsonObject.let { o->
+                                    val hourValue = VOCHourValue()
+
+                                    hourValue.vocStatCode = o["deviceCode"].asString
+
+                                    val collectTime = o["collectTime"].asString
+                                    hourValue.vocDataTime = DateUtil.StringToDate(collectTime)
+
+                                    o["minuteHourDayValueBeans"].asJsonArray.forEach {e1 ->
+                                        e1.asJsonObject.let {o1 ->
+                                            when (o1["factorCode"].asString) {
+                                                "e70201" -> hourValue.vocFanElectricity1 = o1["factorAvg"].asDouble
+                                                "e70202" -> hourValue.vocFanElectricity2 = o1["factorAvg"].asDouble
+                                                "e70203" -> hourValue.vocFanElectricity3 = o1["factorAvg"].asDouble
+                                                "e70204" -> hourValue.vocFanElectricity4 = o1["factorAvg"].asDouble
+                                                "e70205" -> hourValue.vocFanElectricity5 = o1["factorAvg"].asDouble
+                                                "e70206" -> hourValue.vocFanElectricity6 = o1["factorAvg"].asDouble
+                                                "g29001" -> hourValue.vocValue = o1["factorAvg"].asDouble
+                                            }
+                                        }
+                                    }
+                                    val r = vocHourValueMapper.selectByExample(Example(VOCHourValue::class.java).apply {
+                                        createCriteria().andEqualTo("vocDataTime", hourValue.vocDataTime)
+                                                .andEqualTo("vocStatCode", it)
+                                    })
+                                    if (r.isEmpty()) {
+                                        vocHourValueMapper.insertSelective(hourValue)
+                                    }
+                                }
+                            }
+                        }
+                    } catch (e: Throwable) {
+                        e.printStackTrace()
+                    }
+                }
+//            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3