From 74756c657109a4e48dd6c0b4d8959cdab89b33a9 Mon Sep 17 00:00:00 2001
From: xiebin <vip_xiaobin810@163.com>
Date: Wed, 28 Jan 2026 20:10:29 +0800
Subject: [PATCH] update-区域划分表结构调整
---
drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseSceneServiceImpl.java | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 162 insertions(+), 6 deletions(-)
diff --git a/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseSceneServiceImpl.java b/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseSceneServiceImpl.java
index 94f5f0d..f953b88 100644
--- a/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseSceneServiceImpl.java
+++ b/drone-service/drone-fw/src/main/java/org/sxkj/fw/area/service/impl/FwDefenseSceneServiceImpl.java
@@ -17,17 +17,33 @@
package org.sxkj.fw.area.service.impl;
import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
import org.sxkj.common.utils.HeaderUtils;
+import org.sxkj.fw.area.entity.FwAreaDivideEntity;
import org.sxkj.fw.area.entity.FwDefenseSceneEntity;
import org.sxkj.fw.area.vo.FwDefenseSceneVO;
import org.sxkj.fw.area.excel.FwDefenseSceneExcel;
import org.sxkj.fw.area.mapper.FwDefenseSceneMapper;
+import org.sxkj.fw.area.service.IFwAreaDivideService;
import org.sxkj.fw.area.service.IFwDefenseSceneService;
+import org.sxkj.fw.device.entity.FwDeviceEntity;
+import org.sxkj.fw.device.service.IFwDeviceService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
+import org.sxkj.system.cache.SysCache;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.Date;
/**
@@ -39,9 +55,131 @@
@Service
public class FwDefenseSceneServiceImpl extends BaseServiceImpl<FwDefenseSceneMapper, FwDefenseSceneEntity> implements IFwDefenseSceneService {
+ private static final BigDecimal AREA_SIZE_FACTOR = new BigDecimal("1000000");
+
+ @Autowired
+ private IFwAreaDivideService fwAreaDivideService;
+
+ @Autowired
+ private IFwDeviceService fwDeviceService;
+
@Override
public IPage<FwDefenseSceneVO> selectFwDefenseScenePage(IPage<FwDefenseSceneVO> page, FwDefenseSceneVO fwDefenseScene) {
- return page.setRecords(baseMapper.selectFwDefenseScenePage(page, fwDefenseScene));
+ List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId()));
+ fwDefenseScene.setDeptList(deptList);
+ IPage<FwDefenseSceneVO> result = page.setRecords(baseMapper.selectFwDefenseScenePage(page, fwDefenseScene));
+ List<FwDefenseSceneVO> records = result.getRecords();
+ if (records == null || records.isEmpty()) {
+ return result;
+ }
+
+ Set<Long> areaIdSet = new HashSet<>();
+ for (FwDefenseSceneVO record : records) {
+ areaIdSet.addAll(parseIdList(record.getAreaDivideIds()));
+ }
+
+ Map<Long, BigDecimal> areaSizeMap = new HashMap<>();
+ Map<Long, List<Long>> areaDeviceMap = new HashMap<>();
+ Set<Long> deviceIdSet = new HashSet<>();
+ if (!areaIdSet.isEmpty()) {
+ List<FwAreaDivideEntity> areaList = fwAreaDivideService.listByIds(areaIdSet);
+ for (FwAreaDivideEntity area : areaList) {
+ if (area == null || area.getId() == null) {
+ continue;
+ }
+// areaSizeMap.put(area.getId(), area.getAreaSize());
+ List<Long> areaDeviceIds = parseIdList(area.getDeviceIds());
+ areaDeviceMap.put(area.getId(), areaDeviceIds);
+ deviceIdSet.addAll(areaDeviceIds);
+ }
+ }
+
+ Map<Long, String> deviceTypeMap = new HashMap<>();
+ if (!deviceIdSet.isEmpty()) {
+ List<FwDeviceEntity> deviceList = fwDeviceService.listByIds(deviceIdSet);
+ for (FwDeviceEntity device : deviceList) {
+ if (device == null || device.getId() == null) {
+ continue;
+ }
+ deviceTypeMap.put(device.getId(), device.getDeviceType());
+ }
+ }
+
+ for (FwDefenseSceneVO record : records) {
+ List<Long> areaIds = parseIdList(record.getAreaDivideIds());
+ record.setAreaCount(areaIds.size());
+ record.setDefenseArea(sumDefenseArea(areaIds, areaSizeMap));
+
+ Set<Long> deviceIds = new HashSet<>();
+ for (Long areaId : areaIds) {
+ List<Long> areaDeviceIds = areaDeviceMap.get(areaId);
+ if (areaDeviceIds != null) {
+ deviceIds.addAll(areaDeviceIds);
+ }
+ }
+ int detectCount = 0;
+ int counterCount = 0;
+ for (Long deviceId : deviceIds) {
+ String deviceType = deviceTypeMap.get(deviceId);
+ if ("1".equals(deviceType)) {
+ detectCount++;
+ counterCount++;
+ } else if ("2".equals(deviceType)) {
+ detectCount++;
+ } else if ("3".equals(deviceType)) {
+ counterCount++;
+ }
+ }
+ record.setDetectDeviceCount(detectCount);
+ record.setCounterDeviceCount(counterCount);
+ }
+
+ return result;
+ }
+
+ @Override
+ public List<FwDefenseSceneVO> selectFwDefenseSceneList(Integer filterSelected, Long zoneId, Long areaId) {
+ return baseMapper.selectFwDefenseSceneList(filterSelected, zoneId, areaId);
+ }
+
+ private List<Long> parseIdList(String ids) {
+ if (StringUtil.isBlank(ids)) {
+ return Collections.emptyList();
+ }
+ String[] idArray = ids.split(",");
+ List<Long> idList = new ArrayList<>(idArray.length);
+ for (String item : idArray) {
+ if (item == null) {
+ continue;
+ }
+ String value = item.trim();
+ if (StringUtil.isBlank(value)) {
+ continue;
+ }
+ try {
+ idList.add(Long.valueOf(value));
+ } catch (NumberFormatException ignored) {
+ }
+ }
+ return idList;
+ }
+
+ private Integer sumDefenseArea(List<Long> areaIds, Map<Long, BigDecimal> areaSizeMap) {
+ if (areaIds == null || areaIds.isEmpty()) {
+ return 0;
+ }
+ BigDecimal total = BigDecimal.ZERO;
+ for (Long areaId : areaIds) {
+ BigDecimal areaSize = areaSizeMap.get(areaId);
+ if (areaSize != null) {
+ total = total.add(areaSize);
+ }
+ }
+ if (BigDecimal.ZERO.compareTo(total) == 0) {
+ return 0;
+ }
+ BigDecimal totalArea = total.multiply(AREA_SIZE_FACTOR);
+ return totalArea.setScale(0, RoundingMode.HALF_UP).intValue();
}
@@ -78,19 +216,37 @@
private void fillCreateFields(FwDefenseSceneEntity fwDefenseScene) {
Long userId = AuthUtil.getUserId();
- Long deptId = Long.valueOf(AuthUtil.getDeptId());
- String areaCode = HeaderUtils.getAreaCode();
+ String deptIdStr = AuthUtil.getDeptId();
+ Long deptId = null;
+ if (StringUtil.isNotBlank(deptIdStr)) {
+ try {
+ deptId = Long.valueOf(deptIdStr);
+ } catch (NumberFormatException ignored) {
+ deptId = null;
+ }
+ }
+// String areaCode = HeaderUtils.getAreaCode();
+// if (StringUtil.isBlank(areaCode)) {
+// areaCode = fwDefenseScene.getAreaCode();
+// }
Date now = new Date();
fwDefenseScene.setCreateUser(userId);
fwDefenseScene.setUpdateUser(userId);
- fwDefenseScene.setCreateDept(deptId);
- fwDefenseScene.setAreaCode(areaCode);
+ if (deptId != null) {
+ fwDefenseScene.setCreateDept(deptId);
+ }
+// if (StringUtil.isNotBlank(areaCode)) {
+// fwDefenseScene.setAreaCode(areaCode);
+// }
fwDefenseScene.setCreateTime(now);
fwDefenseScene.setUpdateTime(now);
}
private void fillUpdateFields(FwDefenseSceneEntity fwDefenseScene) {
- fwDefenseScene.setUpdateUser(AuthUtil.getUserId());
+ Long userId = AuthUtil.getUserId();
+ if (userId != null) {
+ fwDefenseScene.setUpdateUser(userId);
+ }
fwDefenseScene.setUpdateTime(new Date());
}
--
Gitblit v1.9.3