feiyu02
2025-01-23 698f8f0f22af4c66581ce284407e986ca036aec6
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.flightfeather.uav.domain.repository
 
import com.flightfeather.uav.domain.entity.*
import com.flightfeather.uav.domain.mapper.GridAodDetailMapper
import com.flightfeather.uav.domain.mapper.GridAodMapper
import com.flightfeather.uav.domain.mapper.GridCellMapper
import com.flightfeather.uav.domain.mapper.GridDataDetailMapper
import com.flightfeather.uav.domain.mapper.GridDataMapper
import com.flightfeather.uav.domain.mapper.GridGroupMapper
import com.flightfeather.uav.lightshare.bean.AreaVo
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
 
/**
 * 卫星网格遥测数据库相关操作
 * @date 2024/12/11
 * @author feiyu02
 */
@Repository
class SatelliteGridRep(
    private val gridGroupMapper: GridGroupMapper,
    private val gridCellMapper: GridCellMapper,
    private val gridDataMapper: GridDataMapper,
    private val gridDataDetailMapper: GridDataDetailMapper,
    private val gridAodMapper: GridAodMapper,
    private val gridAodDetailMapper: GridAodDetailMapper,
) {
 
    fun fetchGridGroup(areaVo: AreaVo): List<GridGroup?> {
        return gridGroupMapper.selectByExample(Example(GridGroup::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)
        })
    }
 
    fun fetchGridGroup(id: Int): GridGroup? {
        return gridGroupMapper.selectByPrimaryKey(id)
    }
 
    fun fetchGridGroup(gridGroup: GridGroup): List<GridGroup?> {
        return gridGroupMapper.select(gridGroup)
    }
 
    fun fetchGridCell(groupId: Int): List<GridCell?> {
        return gridCellMapper.selectByExample(Example(GridCell::class.java).apply {
            createCriteria().andEqualTo("groupId", groupId)
            orderBy("id")
        })
    }
 
    fun fetchGridData(groupId: Int, dataTime: LocalDateTime?, type: Int?): List<GridData?> {
        return gridDataMapper.selectByExample(Example(GridData::class.java).apply {
            createCriteria().andEqualTo("groupId", groupId)
                .andEqualTo("dataTime", dataTime)
                .andEqualTo("type", type)
        })
    }
 
    fun fetchGridData(gridData: GridData): List<GridData?> {
        return gridDataMapper.select(gridData)
    }
 
    fun fetchGridDataDetail(dataId: Int, groupId: Int?, cellId: Int?): List<GridDataDetail?> {
        return gridDataDetailMapper.selectByExample(Example(GridDataDetail::class.java).apply {
            createCriteria().andEqualTo("dataId", dataId)
                .andEqualTo("groupId", groupId)
                .andEqualTo("cellId", cellId)
            orderBy("cellId")
        })
    }
 
    fun insertGridDataAndDetail(data: GridData, gridDataDetails: List<GridDataDetail>) {
        gridDataMapper.insert(data)
        gridDataDetails.forEach {
            it.dataId = data.id
            it.groupId = data.groupId
        }
        gridDataDetailMapper.insertList(gridDataDetails)
    }
 
    fun updatePM25Batch(gridDataDetails: List<GridDataDetail>) {
        gridDataDetailMapper.updatePM25Batch(gridDataDetails)
    }
 
 
    //    aod 相关操作
    fun fetchGridAod(groupId: Int, dataTime: LocalDateTime?): List<GridAod?> {
        return gridAodMapper.selectByExample(Example(GridAod::class.java).apply {
            createCriteria().andEqualTo("groupId", groupId)
                .andEqualTo("dataTime", dataTime)
        })
    }
 
    fun fetchGridAodDetail(aodId: Int, groupId: Int?, cellId: Int?): List<GridAodDetail?> {
        return gridAodDetailMapper.selectByExample(Example(GridAodDetail::class.java).apply {
            createCriteria().andEqualTo("aodId", aodId)
                .andEqualTo("groupId", groupId)
                .andEqualTo("cellId", cellId)
            orderBy("cellId")
        })
    }
 
    fun insertGridAodAndDetail(aod: GridAod, gridAodDetails: List<GridAodDetail>) {
        gridAodMapper.insert(aod)
        gridAodDetails.forEach {
            it.aodId = aod.id
            it.groupId = aod.groupId
        }
        gridAodDetailMapper.insertList(gridAodDetails)
    }
 
    fun updateGridAodBatch(gridDataDetails: List<GridAodDetail>) {
        gridDataDetails.forEach {
            gridAodDetailMapper.updateByExample(it, Example(GridAodDetail::class.java).apply {
                createCriteria().andEqualTo("aodId", it.aodId)
                    .andEqualTo("groupId", it.groupId)
                    .andEqualTo("cellId", it.cellId)
            })
        }
    }
 
    @Transactional
    fun updateGridCellBatch(gridCellList: List<GridCell?>) {
        gridCellList.forEach { gridCellMapper.updateByPrimaryKey(it) }
    }
 
}