feiyu02
2025-08-14 f373bbf83d9d2a7e5f96118d7dcd658c9fea8bc8
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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"))
        })
    }
}