吉安感知网项目-后端
linwei
2026-02-11 dbc7e62be76ff48b26461ffaef9c3fc87be018cb
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package org.sxkj.fw.cockpit.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.sxkj.common.utils.HeaderUtils;
import org.sxkj.fw.area.entity.FwDefenseSceneEntity;
import org.sxkj.fw.area.param.FwAreaDivideListParam;
import org.sxkj.fw.area.service.IFwAreaDivideService;
import org.sxkj.fw.area.service.IFwDefenseSceneService;
import org.sxkj.fw.area.service.IFwDefenseSceneManageService;
import org.sxkj.fw.area.vo.FwAreaDivideVO;
import org.sxkj.fw.area.vo.FwDefenseSceneManageVO;
import org.sxkj.fw.cockpit.service.ICockpitService;
import org.sxkj.fw.cockpit.vo.AlarmStatisticsVO;
import org.sxkj.fw.cockpit.vo.DeviceStatisticsVO;
import org.sxkj.fw.cockpit.vo.SceneManageStatisticsVO;
import org.sxkj.fw.common.FwBaseInfo;
import org.sxkj.fw.detection.entity.FwEffectEvalEntity;
import org.sxkj.fw.detection.param.FwEffectEvalParam;
import org.sxkj.fw.detection.service.IFwEffectEvalService;
import org.sxkj.fw.device.dto.FwDeviceDTO;
import org.sxkj.fw.device.entity.FwDeviceEntity;
import org.sxkj.fw.device.service.IFwDeviceService;
import org.sxkj.fw.device.vo.CockpitFwDeviceVO;
import org.sxkj.fw.record.dto.FwDroneAlarmRecordDTO;
import org.sxkj.fw.record.entity.FwDroneAlarmRecordEntity;
import org.sxkj.fw.record.service.IFwDroneAlarmRecordService;
import org.sxkj.fw.record.vo.FwDroneAlarmRecordVO;
import org.sxkj.system.cache.RegionCache;
import org.sxkj.system.cache.SysCache;
import org.sxkj.system.entity.Dept;
import org.sxkj.system.entity.Region;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
 
@Service
public class CockpitServiceImpl implements ICockpitService {
 
    @Resource
    private IFwDroneAlarmRecordService fwDroneAlarmRecordService;
 
    @Resource
    private IFwDeviceService fwDeviceService;
 
    @Resource
    private IFwEffectEvalService fwEffectEvalService;
 
    @Resource
    private IFwAreaDivideService iFwAreaDivideService;
 
    @Resource
    private IFwDefenseSceneManageService iFwDefenseSceneManageService;
 
    @Resource
    private IFwDefenseSceneService iFwDefenseSceneService;
 
    @Override
    public IPage<FwDroneAlarmRecordVO> selectFwDroneAlarmRecordPage(IPage<FwDroneAlarmRecordVO> page, FwDroneAlarmRecordDTO fwDroneAlarmRecord) {
        return fwDroneAlarmRecordService.selectFwDroneAlarmRecordPage(page, fwDroneAlarmRecord);
    }
 
    @Override
    public IPage<CockpitFwDeviceVO> selectCockpitDevicePage(IPage<CockpitFwDeviceVO> page, FwDeviceDTO fwDevice) {
            Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
            Region byCode = RegionCache.getByCode(dept.getAreaCode());
            fwDevice.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
            fwDevice.setCurrentDeptId(AuthUtil.getDeptId());
        IPage<CockpitFwDeviceVO> cockpitFwDeviceVOIPage = fwDeviceService.selectCockpitDevicePage(page, fwDevice);
        return cockpitFwDeviceVOIPage;
    }
 
    @Override
    public List<DeviceStatisticsVO> statisticalDeviceType() {
        Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
        Region byCode = RegionCache.getByCode(dept.getAreaCode());
        return fwDeviceService.statisticalDeviceType(HeaderUtils.formatAreaCode(byCode.getCode()), AuthUtil.getDeptId());
    }
 
    @Override
    public boolean interferenceAndExpulsion(FwEffectEvalParam fwEffectEvalParam) {
        // 告警记录
        FwDroneAlarmRecordEntity alarmRecordEntity = fwDroneAlarmRecordService.getById(fwEffectEvalParam.getAlarmRecordId());
        // 设备信息
        FwDeviceEntity device = fwDeviceService.getById(alarmRecordEntity.getDeviceId());
        // 反制效果
        FwEffectEvalEntity one = fwEffectEvalService.getOne(Wrappers.<FwEffectEvalEntity>lambdaQuery().eq(FwEffectEvalEntity::getAlarmRecordId, fwEffectEvalParam.getAlarmRecordId()));
        FwEffectEvalEntity fwEffectEvalEntity = Optional.ofNullable(one)
            .orElse(new FwEffectEvalEntity());
 
        // 告警记录相关字段
        fwEffectEvalEntity.setAlarmRecordId(fwEffectEvalParam.getAlarmRecordId());
        fwEffectEvalEntity.setDroneName(alarmRecordEntity.getDroneName());
        fwEffectEvalEntity.setDroneType(alarmRecordEntity.getDroneType());
        fwEffectEvalEntity.setDroneDeviceCode(alarmRecordEntity.getDroneSerialNo());
        fwEffectEvalEntity.setFindTime(alarmRecordEntity.getAlarmTime());
 
        // 从参数获取反制方式,否则使用告警记录中的值
        fwEffectEvalEntity.setCounterWay(fwEffectEvalParam.getCounterWay());
        alarmRecordEntity.setCounterWay(fwEffectEvalParam.getCounterWay());
        // 设备相关字段
        fwEffectEvalEntity.setDeviceId(alarmRecordEntity.getDeviceId());
        fwEffectEvalEntity.setDeviceSn(device.getDeviceSn());
        fwEffectEvalEntity.setDeviceName(device.getDeviceName());
        fwEffectEvalEntity.setDeviceModel(device.getDeviceModel());
        fwEffectEvalEntity.setDeviceType(device.getDeviceType());
        fwEffectEvalEntity.setDeployLongitude(device.getLongitude() != null ? Double.parseDouble(device.getLongitude()) : null);
        fwEffectEvalEntity.setDeployLatitude(device.getLatitude() != null ? Double.parseDouble(device.getLatitude()) : null);
        fwEffectEvalEntity.setAreaCode(device.getAreaCode());
 
        // 反制效果及工作模式(从参数获取,否则使用默认值)
        fwEffectEvalEntity.setCounterEffect("1"); // 1.success/2.fail
        fwEffectEvalEntity.setCoverRadiusM(2500); // 覆盖范围(米)
        fwEffectEvalEntity.setWorkMode("1"); // 1.机动/2.固定
        fwDroneAlarmRecordService.updateById(alarmRecordEntity);
        return fwEffectEvalService.saveOrUpdate(fwEffectEvalEntity);
    }
 
    @Override
    public AlarmStatisticsVO statisticsAlarmsAndDeviceRecords() {
        Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
        Region byCode = RegionCache.getByCode(dept.getAreaCode());
        String regionCode = HeaderUtils.formatAreaCode(byCode.getCode());
        // 设备统计
        AlarmStatisticsVO alarmStatisticsVO = fwDeviceService.statisticalDeviceAtt(regionCode, AuthUtil.getDeptId());
        // 告警统计
        AlarmStatisticsVO alarmStatistics = fwDroneAlarmRecordService.alarmTypeStatistics(regionCode, AuthUtil.getDeptId());
        alarmStatisticsVO.setHistoryAlarmCount(alarmStatistics.getHistoryAlarmCount());
        alarmStatisticsVO.setRealTimeAlarmCount(alarmStatistics.getRealTimeAlarmCount());
        return alarmStatisticsVO;
    }
 
    /**
     * @param effectiveRangeKmIsNotNull
     * @return
     */
    @Override
    public List<DeviceStatisticsVO> getDeviceOutStatistics(String effectiveRangeKmIsNotNull) {
        FwDeviceDTO fwDeviceDTO = new FwDeviceDTO();
        Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
        Region byCode = RegionCache.getByCode(dept.getAreaCode());
        fwDeviceDTO.setCurrentDeptId(AuthUtil.getDeptId());
        fwDeviceDTO.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
        return fwDeviceService.getDeviceStatistics(fwDeviceDTO);
    }
 
    /**
     *
     * @param filterTime
     * @return
     */
    @Override
    public List<FwDefenseSceneManageVO> selectFwDefenseSceneManageList(Date filterTime) {
        return iFwDefenseSceneManageService.selectFwDefenseSceneManageList(filterTime);
    }
 
    @Override
    public SceneManageStatisticsVO statisticsSceneManageAndArea(Date filterTime) {
        List<FwDefenseSceneManageVO> sceneManageList = iFwDefenseSceneManageService.selectFwDefenseSceneManageCockpitList(buildFwBaseInfo(), filterTime);
        SceneManageStatisticsVO statisticsVO = new SceneManageStatisticsVO();
        if (sceneManageList == null || sceneManageList.isEmpty()) {
            statisticsVO.setSceneManageCount(0);
            statisticsVO.setAreaCount(0);
            return statisticsVO;
        }
 
        Map<Long, Long> sceneManageSceneMap = new HashMap<>();
        for (FwDefenseSceneManageVO sceneManage : sceneManageList) {
            if (sceneManage == null || sceneManage.getId() == null) {
                continue;
            }
            sceneManageSceneMap.putIfAbsent(sceneManage.getId(), sceneManage.getDefenseSceneId());
        }
        statisticsVO.setSceneManageCount(sceneManageSceneMap.size());
 
        Set<Long> defenseSceneIds = new HashSet<>();
        for (Long defenseSceneId : sceneManageSceneMap.values()) {
            if (defenseSceneId != null) {
                defenseSceneIds.add(defenseSceneId);
            }
        }
        if (defenseSceneIds.isEmpty()) {
            statisticsVO.setAreaCount(0);
            return statisticsVO;
        }
 
        List<FwDefenseSceneEntity> defenseScenes = iFwDefenseSceneService.listByIds(defenseSceneIds);
        Map<Long, Integer> sceneAreaCountMap = new HashMap<>();
        if (defenseScenes != null && !defenseScenes.isEmpty()) {
            for (FwDefenseSceneEntity scene : defenseScenes) {
                if (scene == null || scene.getId() == null) {
                    continue;
                }
                sceneAreaCountMap.put(scene.getId(), countAreaDivide(scene.getAreaDivideIds()));
            }
        }
 
        int totalAreaCount = 0;
        for (Long defenseSceneId : sceneManageSceneMap.values()) {
            if (defenseSceneId == null) {
                continue;
            }
            Integer areaCount = sceneAreaCountMap.get(defenseSceneId);
            if (areaCount != null) {
                totalAreaCount += areaCount;
            }
        }
        statisticsVO.setAreaCount(totalAreaCount);
        return statisticsVO;
    }
 
    /**
     *
     * @param filterSelected
     * @param sceneId
     * @param areaTypeKeys
     * @param isSetSceneManage
     * @param flyTime
     * @return
     */
    @Override
    public List<FwAreaDivideVO> selectFwAreaDivideList(Integer filterSelected, Long sceneId, String areaTypeKeys, Integer isSetSceneManage, LocalDateTime flyTime) {
        FwAreaDivideListParam fwAreaDivideListParam = new FwAreaDivideListParam();
        fwAreaDivideListParam.setFilterSelected(filterSelected);
        fwAreaDivideListParam.setSceneId(sceneId);
        fwAreaDivideListParam.setAreaTypeKeys(areaTypeKeys);
        fwAreaDivideListParam.setIsSetSceneManage(isSetSceneManage);
        fwAreaDivideListParam.setFlyTime(flyTime);
        // 解析区域类型键值列表
        fwAreaDivideListParam.setAreaTypeKeyList(Func.toStrList(areaTypeKeys));
        Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
        Region byCode = RegionCache.getByCode(dept.getAreaCode());
        fwAreaDivideListParam.setCurrentDeptId(AuthUtil.getDeptId());
        fwAreaDivideListParam.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
        return iFwAreaDivideService.selectFwAreaDivideList(fwAreaDivideListParam);
    }
 
    /**
     * 构建当前部门与区域信息
     *
     * @return 基础信息
     */
    private FwBaseInfo buildFwBaseInfo() {
        FwBaseInfo fwBaseInfo = new FwBaseInfo();
        Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
        Region byCode = RegionCache.getByCode(dept.getAreaCode());
        fwBaseInfo.setCurrentDeptId(AuthUtil.getDeptId());
        fwBaseInfo.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
        return fwBaseInfo;
    }
 
    /**
     * 统计逗号分隔区域ID的数量
     *
     * @param areaDivideIds 区域ID字符串
     * @return 区域数量
     */
    private int countAreaDivide(String areaDivideIds) {
        if (StringUtil.isBlank(areaDivideIds)) {
            return 0;
        }
        return Func.toLongList(areaDivideIds).size();
    }
}