package cn.flightfeather.supervision.bgtask
|
|
import cn.flightfeather.supervision.common.net.JinAnLianTongHttpService
|
import cn.flightfeather.supervision.domain.entity.LampDeviceData
|
import cn.flightfeather.supervision.domain.mapper.LampDeviceDataMapper
|
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
|
import cn.flightfeather.supervision.lightshare.vo.JinAnLampDeviceData
|
import com.github.pagehelper.PageHelper
|
import org.slf4j.Logger
|
import org.slf4j.LoggerFactory
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
import java.util.*
|
|
/**
|
* 获取静安油烟设备数据
|
*/
|
@Component
|
class TaskJinAnLampDeviceData(
|
private val lampDeviceDataMapper: LampDeviceDataMapper
|
) : BaseTimingTask() {
|
|
private val LOGGER: Logger? = LoggerFactory.getLogger(TaskJinAnLampDeviceData::class.java)
|
|
private var times = 0
|
|
//本任务每小时执行一次
|
override fun execute(localtime: LocalDateTime) {
|
if (localtime.minute == 0) {
|
doTask(localtime)
|
}
|
// println("=================check")
|
// if (times == 0) {
|
// doTask(localtime)
|
// println("=================TaskJinAnLampDeviceData")
|
// times++
|
// }
|
}
|
|
//不使用此参数
|
override val period: Long
|
get() = 1440L
|
|
override fun doTask(localtime: LocalDateTime) {
|
LOGGER?.info("===========开始执行静安油烟监测数据获取任务===============")
|
PageHelper.startPage<LampDeviceData>(1, 1)
|
val r = lampDeviceDataMapper.selectByExample(Example(LampDeviceData::class.java).apply {
|
orderBy("monitorTime").desc()
|
})
|
var smDate = if (r.isEmpty()) null else r[0]?.monitorTime
|
var emDate: Date? = null
|
smDate = Date.from(LocalDateTime.of(2023, 4, 1, 12, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant())
|
emDate = Date.from(LocalDateTime.of(2023, 4, 1, 13, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant())
|
var page = 1
|
var hasNextPage: Boolean
|
do {
|
val res = JinAnLianTongHttpService.getLampDeviceData(page, smDate, emDate)
|
println("page: $page, count: ${res.second.size}")
|
hasNextPage = res.first
|
page++
|
saveSiteInfo(res.second)
|
} while (hasNextPage)
|
|
}
|
|
/**
|
* 保存油烟监测点数据
|
*/
|
private fun saveSiteInfo(dataList:List<JinAnLampDeviceData>) {
|
dataList.forEach {d ->
|
if (d.monitorTime == null) return@forEach
|
val mStr = d.monitorTime!!.split(".")[0]
|
val mt = DateUtil.StringToDate(mStr)
|
val info = lampDeviceDataMapper.selectByExample(Example(LampDeviceData::class.java).apply {
|
createCriteria().andEqualTo("deviceCode", d.deviceCode)
|
.andEqualTo("monitorTime", mt)
|
})
|
if (info.isEmpty()) {
|
val b = LampDeviceData()
|
BeanUtils.copyProperties(d, b)
|
b.apply {
|
lampblackValue = d.lampblackValue?.toDouble()
|
monitorTime = mt
|
productionDate = d.productionDate?.let { DateUtil.StringToDate(it) }
|
}
|
lampDeviceDataMapper.insert(b)
|
}
|
}
|
}
|
}
|