package cn.flightfeather.supervision.bgtask
|
|
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.slf4j.Logger
|
import org.slf4j.LoggerFactory
|
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 TaskFetchVOC : BaseTimingTask() {
|
|
enum class Factor(val value: String, val des: String) {
|
Concentration("g29001", "浓度"),
|
Humidity("g18101", "湿度"),
|
Temperature("g18001", "温度"),
|
FanElectricity1("e70101", "风机电流1"),
|
FanElectricity2("e70102", "风机电流2"),
|
FanElectricity3("e70103", "风机电流3"),
|
FanElectricity4("e70104", "风机电流4"),
|
FanElectricity5("e70105", "风机电流5"),
|
FanElectricity6("e70106", "风机电流6"),
|
}
|
|
companion object {
|
private lateinit var instance: TaskFetchVOC
|
}
|
|
@Autowired
|
lateinit var deviceInfoMapper: DeviceInfoMapper
|
|
@Autowired
|
lateinit var vocHourValueMapper: VOCHourValueMapper
|
|
@PostConstruct
|
fun init() {
|
instance = this
|
}
|
|
private val LOGGER: Logger? = LoggerFactory.getLogger(TaskFetchVOC::class.java)
|
|
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)
|
.andEqualTo("diOnline", true)
|
}).forEach {
|
it?.let {
|
deviceCodeList.add(it.diCode)
|
}
|
}
|
|
val cal = Calendar.getInstance(Locale.CHINA).apply {
|
set(Calendar.MINUTE, 0)
|
set(Calendar.SECOND, 0)
|
}
|
var endTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: ""
|
cal.add(Calendar.HOUR_OF_DAY, -1)
|
var startTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: ""
|
|
// startTime = "2023-05-06 13:00:00"
|
// endTime = "2023-05-06 15:00:00"
|
val deviceInfo = VOCHttpService.DeviceInfo(deviceCodeList, startTime, endTime)
|
VOCHttpService.getVOCData(deviceInfo)?.run {
|
try {
|
if (this["code"].asInt == 200) {
|
val data = this["data"].asJsonObject
|
val unit = mutableMapOf<String, String>()
|
data["rtdMonitorFactorRespVOS"].asJsonArray.forEach { v ->
|
v.asJsonObject.let { o ->
|
if (o["factorCode"].asString.trim() == Factor.Concentration.value) {
|
try {
|
unit[o["deviceCode"].asString.trim()] = o["factorName"].asString.trim().split("-")[1]
|
} catch (e: IndexOutOfBoundsException) {
|
LOGGER?.error("获取VOC浓度单位失败", e)
|
}
|
}
|
}
|
}
|
data["rtdMinuteHourDayBeans"].asJsonArray.forEach { e ->
|
e.asJsonObject.let { o ->
|
val hourValueMap = mutableMapOf<String, VOCHourValue>()
|
|
val collectTime = DateUtil.StringToDate(o["collectTime"].asString)
|
|
o["minuteHourDayValueBeans"].asJsonArray.forEach { e1 ->
|
e1.asJsonObject.let { o1 ->
|
val deviceCode = o1["deviceCode"].asString.toUpperCase()
|
if (!hourValueMap.containsKey(deviceCode)) {
|
hourValueMap[deviceCode] = VOCHourValue().apply { vocCreateTime = Date() }
|
}
|
val hourValue = hourValueMap[deviceCode]!!
|
hourValue.vocStatCode = deviceCode
|
hourValue.vocDataTime = collectTime
|
hourValue.vocUnit = unit[deviceCode]
|
val avg = o1["factorAvg"].asString.toDouble()
|
when (o1["factorCode"].asString) {
|
Factor.FanElectricity1.value -> hourValue.vocFanElectricity1 = avg
|
Factor.FanElectricity2.value -> hourValue.vocFanElectricity2 = avg
|
Factor.FanElectricity3.value -> hourValue.vocFanElectricity3 = avg
|
Factor.FanElectricity4.value -> hourValue.vocFanElectricity4 = avg
|
Factor.FanElectricity5.value -> hourValue.vocFanElectricity5 = avg
|
Factor.FanElectricity6.value -> hourValue.vocFanElectricity6 = avg
|
Factor.Concentration.value -> hourValue.vocValue = avg
|
Factor.Temperature.value -> hourValue.vocTemperature = avg
|
Factor.Humidity.value -> hourValue.vocRh = avg
|
}
|
}
|
}
|
val r = vocHourValueMapper.selectByExample(Example(VOCHourValue::class.java).apply {
|
createCriteria().andEqualTo("vocDataTime", collectTime)
|
}).map { v ->
|
v?.vocStatCode
|
}
|
hourValueMap.forEach { (t, u) ->
|
if (!r.contains(t)) {
|
vocHourValueMapper.insertSelective(u)
|
}
|
}
|
}
|
}
|
}
|
} catch (e: Throwable) {
|
e.printStackTrace()
|
}
|
}
|
}
|
}
|