package cn.flightfeather.supervision.business.location
|
|
import cn.flightfeather.supervision.common.utils.ExcelUtil
|
import cn.flightfeather.supervision.domain.ds1.entity.Scense
|
import cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import kotlin.math.round
|
|
/**
|
* 距离计算
|
* @date 2024/10/24
|
* @author feiyu02
|
*/
|
@Component
|
class LocationDistance(private val scenseMapper: ScenseMapper) {
|
|
private val utilFile = UtilExcelDistance(mutableListOf(
|
listOf(
|
ExcelUtil.MyCell("监测点", colSpan = 1),
|
ExcelUtil.MyCell("距离(公里)", colSpan = 1),
|
ExcelUtil.MyCell("唯一序号", colSpan = 1),
|
ExcelUtil.MyCell("单位名称", colSpan = 1),
|
ExcelUtil.MyCell("类型", colSpan = 1),
|
ExcelUtil.MyCell("单位地址", colSpan = 1),
|
ExcelUtil.MyCell("经度", colSpan = 1),
|
ExcelUtil.MyCell("纬度", colSpan = 1),
|
ExcelUtil.MyCell("区县", colSpan = 1),
|
ExcelUtil.MyCell("街道", colSpan = 1),
|
ExcelUtil.MyCell("常用联系人", colSpan = 1),
|
ExcelUtil.MyCell("联系方式", colSpan = 1),
|
).toTypedArray()
|
))
|
|
fun searchList(pList: List<BasePlace>, districtName: String) {
|
utilFile.reset()
|
pList.forEach {
|
val sceneList = findScenes(districtName)
|
if (sceneList.isEmpty()) {
|
utilFile.addRow(listOf(it.name))
|
}
|
sceneList.forEachIndexed { index, s ->
|
var distance = CoordinateUtil.calculateDistance(
|
it.sP.first, it.sP.second,
|
s.longitude?.toDouble() ?: .0, s.latitude?.toDouble() ?: .0
|
)
|
distance = round(distance * 1000) / 1000
|
utilFile.parseRow(listOf<Any>(
|
"",
|
distance,
|
s.index?.toDouble() ?: "",
|
s.name ?: "",
|
s.type ?: "",
|
s.location ?: "",
|
s.longitude?.toDouble() ?: .0,
|
s.latitude?.toDouble() ?: .0,
|
s.districtname ?: "",
|
s.townname ?: "",
|
s.contacts ?: "",
|
s.contactst ?: ""
|
).toTypedArray())
|
if (index == 0) {
|
utilFile.updateLastRow(0, ExcelUtil.MyCell(it.name, sceneList.size))
|
}
|
}
|
utilFile.index = 1
|
}
|
utilFile.outPutToFile(districtName)
|
}
|
|
private fun findScenes(districtName: String): List<Scense> {
|
return scenseMapper.selectByExample(Example(Scense::class.java).apply {
|
createCriteria().andEqualTo("districtname", districtName)
|
and(createCriteria().orNotEqualTo("extension1", "0")
|
.orIsNull("extension1"))
|
})
|
}
|
}
|