对比新文件 |
| | |
| | | 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() |
| | | } |
| | | } |
| | | // } |
| | | } |
| | | } |
| | | } |