From 04f727bd9e91d80de93efeeaf1addcb62abbea10 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 16 Jul 2026 17:00:05 +0800
Subject: [PATCH] feat(cockpit): 添加设备启用状态过滤功能

---
 drone-service/drone-fw/src/main/java/org/sxkj/fw/cockpit/service/impl/CockpitServiceImpl.java |  129 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 124 insertions(+), 5 deletions(-)

diff --git a/drone-service/drone-fw/src/main/java/org/sxkj/fw/cockpit/service/impl/CockpitServiceImpl.java b/drone-service/drone-fw/src/main/java/org/sxkj/fw/cockpit/service/impl/CockpitServiceImpl.java
index 3811d56..36c3846 100644
--- a/drone-service/drone-fw/src/main/java/org/sxkj/fw/cockpit/service/impl/CockpitServiceImpl.java
+++ b/drone-service/drone-fw/src/main/java/org/sxkj/fw/cockpit/service/impl/CockpitServiceImpl.java
@@ -2,16 +2,24 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import lombok.extern.slf4j.Slf4j;
 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;
@@ -31,10 +39,15 @@
 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
+@Slf4j
 public class CockpitServiceImpl implements ICockpitService {
 
 	@Resource
@@ -52,6 +65,8 @@
 	@Resource
 	private IFwDefenseSceneManageService iFwDefenseSceneManageService;
 
+	@Resource
+	private IFwDefenseSceneService iFwDefenseSceneService;
 
 	@Override
 	public IPage<FwDroneAlarmRecordVO> selectFwDroneAlarmRecordPage(IPage<FwDroneAlarmRecordVO> page, FwDroneAlarmRecordDTO fwDroneAlarmRecord) {
@@ -64,13 +79,13 @@
 			Region byCode = RegionCache.getByCode(dept.getAreaCode());
 			fwDevice.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
 			fwDevice.setCurrentDeptId(AuthUtil.getDeptId());
+			fwDevice.setFlyTime(new Date());
 		IPage<CockpitFwDeviceVO> cockpitFwDeviceVOIPage = fwDeviceService.selectCockpitDevicePage(page, fwDevice);
 		return cockpitFwDeviceVOIPage;
 	}
 
 	@Override
 	public List<DeviceStatisticsVO> statisticalDeviceType() {
-		// List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId()));
 		Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
 		Region byCode = RegionCache.getByCode(dept.getAreaCode());
 		return fwDeviceService.statisticalDeviceType(HeaderUtils.formatAreaCode(byCode.getCode()), AuthUtil.getDeptId());
@@ -103,8 +118,8 @@
 		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.setDeployLongitude(StringUtil.isNotBlank(device.getLongitude()) ? Double.parseDouble(device.getLongitude()) : null);
+		fwEffectEvalEntity.setDeployLatitude(StringUtil.isNotBlank(device.getLatitude()) ? Double.parseDouble(device.getLatitude()) : null);
 		fwEffectEvalEntity.setAreaCode(device.getAreaCode());
 
 		// 反制效果及工作模式(从参数获取,否则使用默认值)
@@ -117,7 +132,6 @@
 
 	@Override
 	public AlarmStatisticsVO statisticsAlarmsAndDeviceRecords() {
-		// List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId()));
 		Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
 		Region byCode = RegionCache.getByCode(dept.getAreaCode());
 		String regionCode = HeaderUtils.formatAreaCode(byCode.getCode());
@@ -137,10 +151,17 @@
 	@Override
 	public List<DeviceStatisticsVO> getDeviceOutStatistics(String effectiveRangeKmIsNotNull) {
 		FwDeviceDTO fwDeviceDTO = new FwDeviceDTO();
+		// 打印用户信息
+		log.info("用户信息:{}", AuthUtil.getUser());
+		// 获取部门信息
 		Dept dept = SysCache.getDept(Long.valueOf(AuthUtil.getDeptId()));
+		log.info("部门信息:{}", dept);
 		Region byCode = RegionCache.getByCode(dept.getAreaCode());
+		log.info("区域信息:{}", byCode);
 		fwDeviceDTO.setCurrentDeptId(AuthUtil.getDeptId());
 		fwDeviceDTO.setRegionCode(HeaderUtils.formatAreaCode(byCode.getCode()));
+		fwDeviceDTO.setFlyTime(new Date());
+		fwDeviceDTO.setIsEnabled(1);
 		return fwDeviceService.getDeviceStatistics(fwDeviceDTO);
 	}
 
@@ -155,6 +176,77 @@
 	}
 
 	/**
+	 * 统计场景管理与区域数量
+	 * <p>
+	 * 该方法统计指定时间下的场景管理数量和关联的区域总数。
+	 * 统计逻辑:
+	 * 1. 查询符合条件的场景管理列表
+	 * 2. 去重统计场景管理数量
+	 * 3. 获取场景管理关联的防控场景ID集合
+	 * 4. 查询防控场景并统计每个场景关联的区域划分数量
+	 * 5. 累加所有场景的区域数量得到总数
+	 * </p>
+	 *
+	 * @param filterTime 过滤时间,用于筛选有效的场景管理数据
+	 * @return 场景管理统计结果,包含场景管理数量和区域总数
+	 */
+	@Override
+	public SceneManageStatisticsVO statisticsSceneManageAndArea(Date filterTime) {
+		List<FwDefenseSceneManageVO> sceneManageList = iFwDefenseSceneManageService.selectFwDefenseSceneManageCockpitList(buildFwBaseInfo(), filterTime);
+		log.info("场景管理列表数据:{}", sceneManageList);
+		SceneManageStatisticsVO statisticsVO = new SceneManageStatisticsVO();
+
+		if (sceneManageList == null || sceneManageList.isEmpty()) {
+			statisticsVO.setSceneManageCount(0);
+			statisticsVO.setAreaCount(0);
+			return statisticsVO;
+		}
+
+		// 场景管理数量:按 id 去重(JOIN 可能产生重复行)
+		long sceneManageCount = sceneManageList.stream()
+			.filter(vo -> vo != null && vo.getId() != null)
+			.map(FwDefenseSceneManageVO::getId)
+			.distinct()
+			.count();
+		statisticsVO.setSceneManageCount((int) sceneManageCount);
+
+		// 区域数量:按防控场景ID去重后,统计每个防控场景关联的区域数量
+		// 同一个防控场景可能被多个场景管理引用,只计一次
+		Map<Long, String> defenseSceneAreaMap = new HashMap<>();
+		for (FwDefenseSceneManageVO vo : sceneManageList) {
+			if (vo != null && vo.getDefenseSceneId() != null) {
+				defenseSceneAreaMap.putIfAbsent(vo.getDefenseSceneId(), vo.getDefenseSceneName());
+			}
+		}
+
+		if (defenseSceneAreaMap.isEmpty()) {
+			statisticsVO.setAreaCount(0);
+			return statisticsVO;
+		}
+
+		// 批量查询防控场景,统计区域数量(同一防控场景只计一次)
+		List<FwDefenseSceneEntity> defenseScenes = iFwDefenseSceneService.listByIds(defenseSceneAreaMap.keySet());
+		Set<Long> countedAreaIds = new HashSet<>();
+		int totalAreaCount = 0;
+		if (defenseScenes != null) {
+			for (FwDefenseSceneEntity scene : defenseScenes) {
+				if (scene == null || scene.getId() == null) {
+					continue;
+				}
+				List<Long> areaIds = Func.toLongList(scene.getAreaDivideIds());
+				for (Long areaId : areaIds) {
+					// 全局去重:同一区域ID被多个防控场景引用只计一次
+					if (countedAreaIds.add(areaId)) {
+						totalAreaCount++;
+					}
+				}
+			}
+		}
+		statisticsVO.setAreaCount(totalAreaCount);
+		return statisticsVO;
+	}
+
+	/**
 	 *
 	 * @param filterSelected
 	 * @param sceneId
@@ -165,6 +257,33 @@
 	 */
 	@Override
 	public List<FwAreaDivideVO> selectFwAreaDivideList(Integer filterSelected, Long sceneId, String areaTypeKeys, Integer isSetSceneManage, LocalDateTime flyTime) {
-		return iFwAreaDivideService.selectFwAreaDivideList(filterSelected, sceneId, areaTypeKeys, isSetSceneManage, 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;
+	}
+
 }

--
Gitblit v1.9.3