feiyu02
2025-09-30 6904763f0e74d9a9fa4dbc39f635d2aee39416c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)
            }
        }
    }
}