| | |
| | | */ |
| | | package org.sxkj.fw.area.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.common.utils.HeaderUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideDTO; |
| | | import org.sxkj.fw.area.dto.FwAreaDivideStatisticsDTO; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideEntity; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideVO; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO; |
| | | import org.sxkj.fw.area.entity.FwAreaDivideExtEntity; |
| | | import org.sxkj.fw.area.excel.FwAreaDivideExcel; |
| | | import org.sxkj.fw.area.mapper.FwAreaDivideMapper; |
| | | import org.sxkj.fw.area.param.FwAreaDivideListParam; |
| | | import org.sxkj.fw.area.service.IFwAreaDivideExtService; |
| | | import org.sxkj.fw.area.service.IFwAreaDivideService; |
| | | 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 java.util.List; |
| | | import java.util.Date; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideExtVO; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO; |
| | | import org.sxkj.fw.area.vo.FwAreaDivideVO; |
| | | import org.sxkj.fw.area.vo.FwDefenseSceneVO; |
| | | import org.sxkj.fw.device.entity.FwDeviceEntity; |
| | | import org.sxkj.fw.device.service.IFwDeviceService; |
| | | import org.sxkj.system.cache.SysCache; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 区域划分表 服务实现类 |
| | |
| | | * @since 2026-01-07 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class FwAreaDivideServiceImpl extends BaseServiceImpl<FwAreaDivideMapper, FwAreaDivideEntity> implements IFwAreaDivideService { |
| | | |
| | | private final IFwAreaDivideExtService fwAreaDivideExtService; |
| | | |
| | | @Override |
| | | public IPage<FwAreaDivideVO> selectFwAreaDividePage(IPage<FwAreaDivideVO> page, FwAreaDivideDTO fwAreaDivide) { |
| | | return page.setRecords(baseMapper.selectFwAreaDividePage(page, fwAreaDivide)); |
| | | if (!AuthUtil.isAdministrator()) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | fwAreaDivide.setDeptList(deptList); |
| | | } |
| | | fwAreaDivide.setAreaTypeKeyList(parseAreaTypeKeyList(fwAreaDivide.getAreaTypeKeys())); |
| | | |
| | | List<FwAreaDivideVO> areaDivideList = baseMapper.selectFwAreaDividePage(page, fwAreaDivide); |
| | | |
| | | // 获取面数据 |
| | | if (areaDivideList != null && !areaDivideList.isEmpty()) { |
| | | enrichWithExtensionData(areaDivideList); |
| | | } |
| | | |
| | | return page.setRecords(areaDivideList); |
| | | } |
| | | |
| | | @Override |
| | | public List<FwAreaDivideVO> selectFwAreaDivideList(Integer filterSelected, Long sceneId) { |
| | | return baseMapper.selectFwAreaDivideList(filterSelected, sceneId); |
| | | public List<FwAreaDivideVO> selectFwAreaDivideList(Integer filterSelected, Long sceneId, String areaTypeKeys, Integer isSetSceneManage, java.time.LocalDateTime flyTime) { |
| | | // 创建参数对象 |
| | | FwAreaDivideListParam param = new FwAreaDivideListParam(); |
| | | param.setFilterSelected(filterSelected); |
| | | param.setSceneId(sceneId); |
| | | param.setAreaTypeKeys(areaTypeKeys); |
| | | param.setIsSetSceneManage(isSetSceneManage); |
| | | param.setFlyTime(flyTime); |
| | | // 解析区域类型键值列表 |
| | | param.setAreaTypeKeyList(parseAreaTypeKeyList(areaTypeKeys)); |
| | | if (!AuthUtil.isAdministrator()) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | param.setDeptList(deptList); |
| | | } |
| | | // 调用Mapper方法,传入参数对象 |
| | | List<FwAreaDivideVO> areaDivideList = baseMapper.selectFwAreaDivideList(param); |
| | | // 获取面数据 |
| | | if (areaDivideList != null && !areaDivideList.isEmpty()) { |
| | | enrichWithExtensionData(areaDivideList); |
| | | } |
| | | return areaDivideList; |
| | | } |
| | | |
| | | /** |
| | | * 区域划分列表查询(对象参数版本) |
| | | * |
| | | * @param param 区域划分列表查询参数 |
| | | * @return 区域划分列表 |
| | | */ |
| | | @Override |
| | | public List<FwAreaDivideVO> selectFwAreaDivideList(FwAreaDivideListParam param) { |
| | | // 调用Mapper方法,传入参数对象 |
| | | List<FwAreaDivideVO> areaDivideList = baseMapper.selectFwAreaDivideListCockpit(param); |
| | | // 获取面数据 |
| | | if (areaDivideList != null && !areaDivideList.isEmpty()) { |
| | | enrichWithExtensionData(areaDivideList); |
| | | } |
| | | return areaDivideList; |
| | | } |
| | | |
| | | /** |
| | | * 为区域划分列表填充扩展表数据 |
| | | * |
| | | * @param areaDivideList 区域划分列表 |
| | | */ |
| | | private void enrichWithExtensionData(List<FwAreaDivideVO> areaDivideList) { |
| | | if (areaDivideList == null || areaDivideList.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | areaDivideList.stream() |
| | | .filter(area -> area.getId() != null) // 过滤掉id为空的对象 |
| | | .forEach(area -> { |
| | | List<FwAreaDivideExtVO> extList = fwAreaDivideExtService.getByAreaDivideId(area.getId()); |
| | | area.setFwAreaDivideExtList(extList); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<FwAreaDivideStatisticsVO> selectFwAreaDivideStatisticsPage(IPage<FwAreaDivideStatisticsVO> page, FwAreaDivideStatisticsDTO fwAreaDivideStatistics) { |
| | | public Map<Long, String> selectSceneNameByDeviceIds(List<Long> deviceIds) { |
| | | Map<Long, String> result = new HashMap<>(); |
| | | if (deviceIds == null || deviceIds.isEmpty()) { |
| | | return result; |
| | | } |
| | | Set<Long> deviceIdSet = new HashSet<>(); |
| | | for (Long deviceId : deviceIds) { |
| | | if (deviceId != null) { |
| | | deviceIdSet.add(deviceId); |
| | | } |
| | | } |
| | | if (deviceIdSet.isEmpty()) { |
| | | return result; |
| | | } |
| | | List<FwAreaDivideVO> areaList = baseMapper.selectFwAreaDivideListByDeviceIds(new ArrayList<>(deviceIdSet)); |
| | | if (areaList == null || areaList.isEmpty()) { |
| | | for (Long deviceId : deviceIdSet) { |
| | | result.put(deviceId, "/"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | Map<Long, Set<Long>> deviceAreaMap = new HashMap<>(); |
| | | Set<Long> areaIdSet = new HashSet<>(); |
| | | for (FwAreaDivideVO area : areaList) { |
| | | if (area == null || area.getId() == null) { |
| | | continue; |
| | | } |
| | | List<Long> areaDeviceIds = parseIdList(area.getDeviceIds()); |
| | | if (areaDeviceIds.isEmpty()) { |
| | | continue; |
| | | } |
| | | for (Long deviceId : areaDeviceIds) { |
| | | if (!deviceIdSet.contains(deviceId)) { |
| | | continue; |
| | | } |
| | | deviceAreaMap.computeIfAbsent(deviceId, key -> new HashSet<>()).add(area.getId()); |
| | | } |
| | | areaIdSet.add(area.getId()); |
| | | } |
| | | if (areaIdSet.isEmpty()) { |
| | | for (Long deviceId : deviceIdSet) { |
| | | result.put(deviceId, "/"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | List<FwDefenseSceneVO> sceneList = baseMapper.selectFwDefenseSceneListByAreaIds(new ArrayList<>(areaIdSet)); |
| | | Map<Long, Set<String>> areaSceneNameMap = new HashMap<>(); |
| | | if (sceneList != null && !sceneList.isEmpty()) { |
| | | for (FwDefenseSceneVO scene : sceneList) { |
| | | if (scene == null) { |
| | | continue; |
| | | } |
| | | String sceneName = scene.getSceneName(); |
| | | if (StringUtil.isBlank(sceneName)) { |
| | | continue; |
| | | } |
| | | List<Long> areaIds = parseIdList(scene.getAreaDivideIds()); |
| | | for (Long areaId : areaIds) { |
| | | if (!areaIdSet.contains(areaId)) { |
| | | continue; |
| | | } |
| | | areaSceneNameMap.computeIfAbsent(areaId, key -> new HashSet<>()).add(sceneName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (Long deviceId : deviceIdSet) { |
| | | Set<Long> areaIds = deviceAreaMap.get(deviceId); |
| | | if (areaIds == null || areaIds.isEmpty()) { |
| | | result.put(deviceId, "/"); |
| | | continue; |
| | | } |
| | | Set<String> sceneNames = new HashSet<>(); |
| | | for (Long areaId : areaIds) { |
| | | Set<String> names = areaSceneNameMap.get(areaId); |
| | | if (names != null) { |
| | | sceneNames.addAll(names); |
| | | } |
| | | } |
| | | if (sceneNames.isEmpty()) { |
| | | result.put(deviceId, "/"); |
| | | } else { |
| | | result.put(deviceId, String.join(",", sceneNames)); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean existsAreaByDeviceId(Long deviceId) { |
| | | if (deviceId == null) { |
| | | return false; |
| | | } |
| | | Integer count = baseMapper.selectAreaCountByDeviceId(deviceId); |
| | | return count != null && count > 0; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<FwAreaDivideStatisticsVO> selectFwAreaDivideStatisticsPage(IPage<FwAreaDivideStatisticsVO> page, |
| | | FwAreaDivideStatisticsDTO fwAreaDivideStatistics) { |
| | | if (!AuthUtil.isAdministrator()) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | fwAreaDivideStatistics.setDeptList(deptList); |
| | | } |
| | | fwAreaDivideStatistics.setAreaTypeKeyList(parseAreaTypeKeyList(fwAreaDivideStatistics.getAreaTypeKeys())); |
| | | return page.setRecords(baseMapper.selectFwAreaDivideStatisticsPage(page, fwAreaDivideStatistics)); |
| | | } |
| | | |
| | | @Override |
| | | public FwAreaDivideStatisticsVO selectFwAreaDivideStatisticsDetail(FwAreaDivideStatisticsDTO fwAreaDivideStatistics) { |
| | | public FwAreaDivideStatisticsVO selectFwAreaDivideStatisticsDetail( |
| | | FwAreaDivideStatisticsDTO fwAreaDivideStatistics) { |
| | | return baseMapper.selectFwAreaDivideStatisticsDetail(fwAreaDivideStatistics); |
| | | } |
| | | |
| | | @Override |
| | | public FwAreaDivideVO selectFwAreaDivideDetail(Long id) { |
| | | return baseMapper.selectFwAreaDivideDetail(id); |
| | | FwAreaDivideVO detail = baseMapper.selectFwAreaDivideDetail(id); |
| | | if (detail == null || detail.getId() == null) { |
| | | return detail; |
| | | } |
| | | List<FwAreaDivideExtVO> extList = fwAreaDivideExtService.getByAreaDivideId(detail.getId()); |
| | | detail.setFwAreaDivideExtList(extList); |
| | | return detail; |
| | | } |
| | | |
| | | @Override |
| | | public List<FwAreaDivideExcel> exportFwAreaDivide(Wrapper<FwAreaDivideEntity> queryWrapper) { |
| | | List<FwAreaDivideExcel> fwAreaDivideList = baseMapper.exportFwAreaDivide(queryWrapper); |
| | | //fwAreaDivideList.forEach(fwAreaDivide -> { |
| | | // fwAreaDivide.setTypeName(DictCache.getValue(DictEnum.YES_NO, FwAreaDivide.getType())); |
| | | //}); |
| | | // fwAreaDivideList.forEach(fwAreaDivide -> { |
| | | // fwAreaDivide.setTypeName(DictCache.getValue(DictEnum.YES_NO, |
| | | // FwAreaDivide.getType())); |
| | | // }); |
| | | return fwAreaDivideList; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateWithExt(FwAreaDivideEntity fwAreaDivide, List<FwAreaDivideExtEntity> fwAreaDivideExtList) { |
| | | // 主表与扩展面数据保持同一事务,扩展面列表为空时仅保存主表 |
| | | if (fwAreaDivide == null) { |
| | | return false; |
| | | } |
| | | if (fwAreaDivideExtList != null && !fwAreaDivideExtList.isEmpty()) { |
| | | // 由扩展面类型key去重生成主表areaTypeKeys |
| | | String areaTypeKeys = buildAreaTypeKeys(fwAreaDivideExtList); |
| | | if (StringUtil.isNotBlank(areaTypeKeys)) { |
| | | fwAreaDivide.setAreaTypeKeys(areaTypeKeys); |
| | | } |
| | | } |
| | | String deviceIds = fwAreaDivide.getDeviceIds(); |
| | | // 判断deviceIds是否和数据库里面一致,不一致需要处理 |
| | | boolean isCreate = fwAreaDivide.getId() == null; |
| | | // 处理设备启用禁用 |
| | | handleDeviceEnablementAndDisabling(fwAreaDivide, isCreate, deviceIds); |
| | | |
| | | boolean mainResult = saveOrUpdate(fwAreaDivide); |
| | | if (!mainResult) { |
| | | return false; |
| | | } |
| | | if (fwAreaDivideExtList == null || fwAreaDivideExtList.isEmpty()) { |
| | | return true; |
| | | } |
| | | List<FwAreaDivideExtEntity> extList = new ArrayList<>(); |
| | | for (FwAreaDivideExtEntity ext : fwAreaDivideExtList) { |
| | | if (ext == null) { |
| | | continue; |
| | | } |
| | | ext.setAreaDivideId(fwAreaDivide.getId()); |
| | | if (StringUtil.isBlank(ext.getAreaCode()) && StringUtil.isNotBlank(fwAreaDivide.getAreaCode())) { |
| | | ext.setAreaCode(fwAreaDivide.getAreaCode()); |
| | | } |
| | | fillCreateFieldsExt(ext); |
| | | extList.add(ext); |
| | | } |
| | | if (extList.isEmpty()) { |
| | | return true; |
| | | } |
| | | if (!isCreate) { |
| | | // 更新时先清理该主表下历史扩展面数据,再整体写入 |
| | | QueryWrapper<FwAreaDivideExtEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(FwAreaDivideExtEntity::getAreaDivideId, fwAreaDivide.getId()); |
| | | fwAreaDivideExtService.remove(wrapper); |
| | | } |
| | | if (!fwAreaDivideExtService.saveBatchWithGeom(extList)) { |
| | | throw new RuntimeException("保存区域扩展面数据失败"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param fwAreaDivide |
| | | * @param isCreate |
| | | * @param deviceIds |
| | | */ |
| | | private void handleDeviceEnablementAndDisabling(FwAreaDivideEntity fwAreaDivide, boolean isCreate, String deviceIds) { |
| | | // 查找新增和删除的设备ID |
| | | Set<String> addedDeviceIds = new HashSet<>(); |
| | | Set<String> removedDeviceIds = new HashSet<>(); |
| | | |
| | | if (!isCreate) { |
| | | // 更新操作,需要比较数据库中的deviceIds |
| | | FwAreaDivideEntity existingEntity = baseMapper.selectById(fwAreaDivide.getId()); |
| | | if (existingEntity != null) { |
| | | String oldDeviceIds = existingEntity.getDeviceIds(); |
| | | // 解析新旧deviceIds为集合 |
| | | Set<String> oldDeviceIdSet = parseDeviceIds(oldDeviceIds); |
| | | Set<String> newDeviceIdSet = parseDeviceIds(deviceIds); |
| | | |
| | | // 找出新增的设备ID |
| | | for (String id : newDeviceIdSet) { |
| | | if (!oldDeviceIdSet.contains(id)) { |
| | | addedDeviceIds.add(id); |
| | | } |
| | | } |
| | | |
| | | // 找出删除的设备ID |
| | | for (String id : oldDeviceIdSet) { |
| | | if (!newDeviceIdSet.contains(id)) { |
| | | removedDeviceIds.add(id); |
| | | } |
| | | } |
| | | } |
| | | // 判断区域是否绑定到场景中 |
| | | boolean isBindScene = baseMapper.checkAreaBindScene(fwAreaDivide.getId()); |
| | | if (isBindScene) { |
| | | IFwDeviceService fwDeviceService = SpringUtil.getBean(IFwDeviceService.class); |
| | | if (!addedDeviceIds.isEmpty()) { |
| | | fwDeviceService.update(Wrappers.<FwDeviceEntity>lambdaUpdate() |
| | | .set(FwDeviceEntity::getIsEnabled, 1) |
| | | .in(FwDeviceEntity::getId, addedDeviceIds)); |
| | | } |
| | | if (!removedDeviceIds.isEmpty()) { |
| | | fwDeviceService.update(Wrappers.<FwDeviceEntity>lambdaUpdate() |
| | | .set(FwDeviceEntity::getIsEnabled, 0) |
| | | .in(FwDeviceEntity::getId, removedDeviceIds)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void fillCreateFields(FwAreaDivideEntity fwAreaDivide) { |
| | | Long userId = AuthUtil.getUserId(); |
| | | String deptIdStr = AuthUtil.getDeptId(); |
| | |
| | | deptId = null; |
| | | } |
| | | } |
| | | // String areaCode = fwAreaDivide.getAreaCode(); |
| | | // if (StringUtil.isBlank(areaCode)) { |
| | | // areaCode = HeaderUtils.getAreaCode(); |
| | | // } |
| | | // String areaCode = fwAreaDivide.getAreaCode(); |
| | | // if (StringUtil.isBlank(areaCode)) { |
| | | // areaCode = HeaderUtils.getAreaCode(); |
| | | // } |
| | | Date now = new Date(); |
| | | fwAreaDivide.setCreateUser(userId); |
| | | fwAreaDivide.setUpdateUser(userId); |
| | | if (deptId != null) { |
| | | fwAreaDivide.setCreateDept(deptId); |
| | | } |
| | | // if (StringUtil.isNotBlank(areaCode)) { |
| | | // fwAreaDivide.setAreaCode(areaCode); |
| | | // } |
| | | // if (StringUtil.isNotBlank(areaCode)) { |
| | | // fwAreaDivide.setAreaCode(areaCode); |
| | | // } |
| | | fwAreaDivide.setCreateTime(now); |
| | | fwAreaDivide.setUpdateTime(now); |
| | | } |
| | |
| | | fwAreaDivide.setUpdateTime(new Date()); |
| | | } |
| | | |
| | | /** |
| | | * 解析设备ID字符串为集合 |
| | | * |
| | | * @param deviceIds 设备ID字符串,逗号分隔 |
| | | * @return 设备ID集合 |
| | | */ |
| | | private Set<String> parseDeviceIds(String deviceIds) { |
| | | Set<String> deviceIdSet = new HashSet<>(); |
| | | if (StringUtil.isNotBlank(deviceIds)) { |
| | | String[] ids = deviceIds.split(","); |
| | | for (String id : ids) { |
| | | if (StringUtil.isNotBlank(id)) { |
| | | deviceIdSet.add(id.trim()); |
| | | } |
| | | } |
| | | } |
| | | return deviceIdSet; |
| | | } |
| | | |
| | | private void fillCreateFieldsExt(FwAreaDivideExtEntity fwAreaDivideExt) { |
| | | Long userId = AuthUtil.getUserId(); |
| | | String deptIdStr = AuthUtil.getDeptId(); |
| | | Long deptId = null; |
| | | if (StringUtil.isNotBlank(deptIdStr)) { |
| | | try { |
| | | deptId = Long.valueOf(deptIdStr); |
| | | } catch (NumberFormatException ignored) { |
| | | deptId = null; |
| | | } |
| | | } |
| | | Date now = new Date(); |
| | | if (fwAreaDivideExt.getCreateUser() == null) { |
| | | fwAreaDivideExt.setCreateUser(userId); |
| | | } |
| | | if (fwAreaDivideExt.getUpdateUser() == null) { |
| | | fwAreaDivideExt.setUpdateUser(userId); |
| | | } |
| | | if (fwAreaDivideExt.getCreateDept() == null && deptId != null) { |
| | | fwAreaDivideExt.setCreateDept(deptId); |
| | | } |
| | | if (fwAreaDivideExt.getCreateTime() == null) { |
| | | fwAreaDivideExt.setCreateTime(now); |
| | | } |
| | | if (fwAreaDivideExt.getUpdateTime() == null) { |
| | | fwAreaDivideExt.setUpdateTime(now); |
| | | } |
| | | } |
| | | |
| | | private String buildAreaTypeKeys(List<FwAreaDivideExtEntity> fwAreaDivideExtList) { |
| | | if (fwAreaDivideExtList == null || fwAreaDivideExtList.isEmpty()) { |
| | | return null; |
| | | } |
| | | // 保持输入顺序,去重后拼接 |
| | | Set<String> keySet = new LinkedHashSet<>(); |
| | | for (FwAreaDivideExtEntity ext : fwAreaDivideExtList) { |
| | | if (ext == null) { |
| | | continue; |
| | | } |
| | | String key = ext.getAreaTypeKey(); |
| | | if (StringUtil.isBlank(key)) { |
| | | continue; |
| | | } |
| | | // 兼容前端传入逗号分隔的类型key |
| | | String[] keyArray = key.split(","); |
| | | for (String item : keyArray) { |
| | | if (item == null) { |
| | | continue; |
| | | } |
| | | String value = item.trim(); |
| | | if (StringUtil.isNotBlank(value)) { |
| | | keySet.add(value); |
| | | } |
| | | } |
| | | } |
| | | if (keySet.isEmpty()) { |
| | | return null; |
| | | } |
| | | return String.join(",", keySet); |
| | | } |
| | | |
| | | private List<String> parseAreaTypeKeyList(String areaTypeKeys) { |
| | | if (StringUtil.isBlank(areaTypeKeys)) { |
| | | return null; |
| | | } |
| | | String[] keyArray = areaTypeKeys.split(","); |
| | | Set<String> keySet = new LinkedHashSet<>(); |
| | | for (String item : keyArray) { |
| | | if (item == null) { |
| | | continue; |
| | | } |
| | | String value = item.trim(); |
| | | if (StringUtil.isNotBlank(value)) { |
| | | keySet.add(value); |
| | | } |
| | | } |
| | | if (keySet.isEmpty()) { |
| | | return null; |
| | | } |
| | | return new ArrayList<>(keySet); |
| | | } |
| | | |
| | | private List<Long> parseIdList(String ids) { |
| | | if (StringUtil.isBlank(ids)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 禁用设备 |
| | | * @param deviceIds 设备ID列表 |
| | | */ |
| | | private void disableDevices(List<Long> deviceIds) { |
| | | IFwDeviceService fwDeviceService = SpringUtil.getBean(IFwDeviceService.class); |
| | | if (deviceIds != null && !deviceIds.isEmpty()) { |
| | | // 实现设备禁用逻辑 |
| | | // 这里假设FwDeviceEntity有enabled字段,1表示启用,0表示禁用 |
| | | for (Long deviceId : deviceIds) { |
| | | FwDeviceEntity device = new FwDeviceEntity(); |
| | | device.setId(deviceId); |
| | | device.setIsEnabled(false); |
| | | fwDeviceService.updateById(device); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 逻辑删除区域划分,并处理关联设备的禁用 |
| | | * @param ids 区域划分ID列表 |
| | | * @return 是否删除成功 |
| | | */ |
| | | @Override |
| | | public boolean deleteLogic(List<Long> ids) { |
| | | if (ids == null || ids.isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | // 先获取要删除的区域划分 |
| | | List<FwAreaDivideEntity> areas = listByIds(ids); |
| | | if (areas == null || areas.isEmpty()) { |
| | | return false; |
| | | } |
| | | // 过滤出配置了场景的区域数据 |
| | | List<FwAreaDivideEntity> sceneBoundAreas = areas.stream() |
| | | .filter(area -> area != null && baseMapper.checkAreaBindScene(area.getId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 收集所有相关的设备ID |
| | | List<Long> deviceIds = new ArrayList<>(); |
| | | for (FwAreaDivideEntity area : sceneBoundAreas) { |
| | | if (area != null && StringUtil.isNotBlank(area.getDeviceIds())) { |
| | | deviceIds.addAll(parseIdList(area.getDeviceIds())); |
| | | } |
| | | } |
| | | |
| | | // 禁用相关设备 |
| | | if (!deviceIds.isEmpty()) { |
| | | disableDevices(deviceIds); |
| | | } |
| | | |
| | | // 执行逻辑删除 |
| | | return super.deleteLogic(ids); |
| | | } |
| | | |
| | | } |