package cn.flightfeather.supervision.datafetch
|
|
import cn.flightfeather.supervision.common.net.NCHttpService
|
import cn.flightfeather.supervision.domain.ds1.entity.NightConstruction
|
import cn.flightfeather.supervision.domain.ds1.mapper.NightConstructionMapper
|
import cn.flightfeather.supervision.common.utils.DateUtil
|
import com.github.pagehelper.PageHelper
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import java.util.*
|
import javax.annotation.PostConstruct
|
|
/**
|
* 获取静安区夜间施工许可证信息
|
*/
|
@Component
|
class FetchNightConstruction : FetchData() {
|
|
companion object {
|
private lateinit var instance: FetchNightConstruction
|
|
private const val PROVINCE_CODE = "31"
|
private const val CITY_CODE = "3100"
|
private const val DISTRICT_CODE = "310106"
|
private const val PROVINCE_NAME = "上海市"
|
private const val CITY_NAME = "上海市"
|
private const val DISTRICT_NAME = "静安区"
|
|
private const val DEFAULT_TIME = "2020-12-01 00:00:00"
|
}
|
|
@Autowired
|
lateinit var nightConstructionMapper: NightConstructionMapper
|
|
private val dateUtil = DateUtil()
|
|
@PostConstruct
|
fun init() {
|
instance = this
|
}
|
|
|
override fun fetch() {
|
PageHelper.startPage<NightConstruction>(1, 1)
|
nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
|
createCriteria().andEqualTo("ncProvinceCode", PROVINCE_CODE)
|
.andEqualTo("ncCityCode", CITY_CODE)
|
.andEqualTo("ncDistrictCode", DISTRICT_CODE)
|
orderBy("ncCreateTime").desc()
|
}).let {
|
val timeStr = if (it.isNotEmpty()) {
|
val cal = Calendar.getInstance().apply { time = it[0]?.ncCreateTime }
|
cal.add(Calendar.DAY_OF_MONTH, -1)
|
dateUtil.DateToString(cal.time, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS) ?: DEFAULT_TIME
|
} else {
|
DEFAULT_TIME
|
}
|
|
NCHttpService.getFile(timeStr)?.forEach {e ->
|
if (e.isJsonObject) {
|
val vo = e.asJsonObject
|
val nightConstruction = NightConstruction().apply {
|
ncNum = vo["nightallnum"].asString
|
ncItemName = vo["itemName"].asString
|
ncItemUnit = vo["itemUnit"].asString
|
ncConstructionUnit = vo["constructionUnit"].asString
|
ncPerson = vo["person"].asString
|
ncApplyContent = vo["applyContent"].asString
|
ncStartDate = dateUtil.StringToDate(vo["startDate"].asString)
|
ncEndDate = dateUtil.StringToDate(vo["endDate"].asString)
|
ncFileName = vo["filename"].asString
|
ncCreateTime = dateUtil.StringToDate(vo["createtime"].asString)
|
ncUrl = vo["url"].asString
|
|
ncProvinceCode = PROVINCE_CODE
|
ncProvinceName = PROVINCE_NAME
|
ncCityCode = CITY_CODE
|
ncCityName = CITY_NAME
|
ncDistrictCode = DISTRICT_CODE
|
ncDistrictName = DISTRICT_NAME
|
}
|
nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
|
createCriteria().andEqualTo("ncNum", nightConstruction.ncNum)
|
}).run {
|
nightConstructionMapper.selectByExample(Example(NightConstruction::class.java).apply {
|
createCriteria().andEqualTo("ncItemName", nightConstruction.ncItemName)
|
}).takeIf { l-> l.isNotEmpty() }?.get(0)?.let { r->
|
nightConstruction.ncUserId = r.ncUserId
|
nightConstruction.ncSceneId = r.ncSceneId
|
}
|
if (isEmpty()) {
|
try {
|
nightConstructionMapper.insert(nightConstruction)
|
} catch (e: Exception) {
|
e.printStackTrace()
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|