package cn.flightfeather.supervision.bgtask
|
|
import cn.flightfeather.supervision.common.net.JinAnLianTongHttpService
|
import cn.flightfeather.supervision.domain.entity.LampEnterBaseInfo
|
import cn.flightfeather.supervision.domain.mapper.LampEnterBaseInfoMapper
|
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
|
import cn.flightfeather.supervision.lightshare.vo.JinAnLampEnterBaseInfo
|
import org.springframework.beans.BeanUtils
|
import org.springframework.stereotype.Component
|
import java.time.LocalDateTime
|
|
/**
|
* 获取静安油烟监测企业
|
*/
|
@Component
|
class TaskJinAnLampEnterBaseInfo(
|
private val lampEnterBaseInfoMapper: LampEnterBaseInfoMapper
|
) : BaseTimingTask() {
|
|
//本任务每日执行一次
|
override fun execute(localtime: LocalDateTime) {
|
if (localtime.hour == 0 && localtime.minute == 0) {
|
doTask(localtime)
|
}
|
}
|
|
//不使用此参数
|
override val period: Long
|
get() = 1440L
|
|
override fun doTask(localtime: LocalDateTime) {
|
var page = 1
|
var hasNextPage: Boolean
|
do {
|
val res = JinAnLianTongHttpService.getLampEnterBaseInfo(page)
|
hasNextPage = res.first
|
page++
|
saveSiteInfo(res.second)
|
} while (hasNextPage)
|
|
}
|
|
/**
|
* 保存油烟监测企业数据
|
*/
|
private fun saveSiteInfo(dataList:List<JinAnLampEnterBaseInfo>) {
|
dataList.forEach {d ->
|
val info = lampEnterBaseInfoMapper.selectByPrimaryKey(d.enterId)
|
if (info == null) {
|
val b = LampEnterBaseInfo()
|
BeanUtils.copyProperties(d, b)
|
b.apply {
|
latitude = d.latitude?.toDouble()
|
longitude = d.longitude?.toDouble()
|
registDate = d.registDate?.let { DateUtil.StringToDate(it) }
|
}
|
lampEnterBaseInfoMapper.insert(b)
|
}
|
}
|
}
|
}
|