feiyu02
2025-09-04 707b00a0ca6604c249a110b376ac1e44e408e624
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
package com.flightfeather.uav.domain.repository
 
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.SceneInfo
import com.flightfeather.uav.domain.mapper.SceneInfoMapper
import com.flightfeather.uav.lightshare.bean.AreaVo
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
 
/**
 * 场景信息数据库相关操作
 */
@Repository
class SceneInfoRep(private val sceneInfoMapper: SceneInfoMapper) {
 
    fun findByArea(areaVo: AreaVo): List<SceneInfo?> {
        return sceneInfoMapper.selectByExample(Example(SceneInfo::class.java).apply {
            createCriteria().andEqualTo("provinceCode", areaVo.provinceCode)
                .andEqualTo("provinceName", areaVo.provinceName)
                .andEqualTo("cityCode", areaVo.cityCode)
                .andEqualTo("cityName", areaVo.cityName)
                .andEqualTo("districtCode", areaVo.districtCode)
                .andEqualTo("districtName", areaVo.districtName)
                .andEqualTo("townCode", areaVo.townCode)
                .andEqualTo("townName", areaVo.townName)
                .andEqualTo("areaCode", areaVo.areaCode)
                .andEqualTo("area", areaVo.area)
                .andEqualTo("managementCompanyId", areaVo.managementCompanyId)
                .andEqualTo("managementCompany", areaVo.managementCompany)
                .andEqualTo("typeId", areaVo.sceneTypeId)
        })
    }
 
    /**
     * 根据经纬度范围筛选场景
     */
    fun findByCoordinateRange(range: List<Double>):List<SceneInfo?>{
        return sceneInfoMapper.selectByExample(Example(SceneInfo::class.java).apply {
            createCriteria().andGreaterThanOrEqualTo("longitude", range[0])
                .andLessThanOrEqualTo("longitude", range[1])
                .andGreaterThanOrEqualTo("latitude", range[2])
                .andLessThanOrEqualTo("latitude", range[3])
        })
    }
 
    /**
     * 根据多边形筛选场景
     * @param polygon 多边形坐标列表,顺序为顺时针或逆时针(要求使用火星坐标系)
     * @return 多边形内的场景列表
     */
    fun findByPolygon(polygon: List<Pair<Double, Double>>): List<SceneInfo?> {
        // 计算多边形四至范围
        val bounds = MapUtil.calFourBoundaries(polygon)
        val sceneList = findByCoordinateRange(bounds)
        // 筛选是否在反向溯源区域多边形内部
        return sceneList.filter { scene ->
            scene ?: false
            val point = scene!!.longitude.toDouble() to scene.latitude.toDouble()
            MapUtil.isPointInPolygon(point, polygon)
        }
    }
 
    fun findBySceneTypes(sceneTypes: List<Int>): List<SceneInfo?> {
        if (sceneTypes.isEmpty()){
            return emptyList()
        }
        return sceneInfoMapper.selectByExample(Example(SceneInfo::class.java).apply {
            createCriteria().andIn("typeId", sceneTypes)
        })
    }
}