| | |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.sxkj.common.utils.HeaderUtils; |
| | | 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.vo.FwDefenseSceneVO; |
| | | import org.sxkj.fw.area.excel.FwAreaDivideExcel; |
| | | import org.sxkj.fw.area.mapper.FwAreaDivideMapper; |
| | | import org.sxkj.fw.area.service.IFwAreaDivideService; |
| | |
| | | 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.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | * @since 2026-01-07 |
| | | */ |
| | | @Service |
| | | public class FwAreaDivideServiceImpl extends BaseServiceImpl<FwAreaDivideMapper, FwAreaDivideEntity> implements IFwAreaDivideService { |
| | | public class FwAreaDivideServiceImpl extends BaseServiceImpl<FwAreaDivideMapper, FwAreaDivideEntity> |
| | | implements IFwAreaDivideService { |
| | | |
| | | @Override |
| | | public IPage<FwAreaDivideVO> selectFwAreaDividePage(IPage<FwAreaDivideVO> page, FwAreaDivideDTO fwAreaDivide) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | fwAreaDivide.setDeptList(deptList); |
| | | return page.setRecords(baseMapper.selectFwAreaDividePage(page, fwAreaDivide)); |
| | | } |
| | | |
| | | @Override |
| | | public List<FwAreaDivideVO> selectFwAreaDivideList(Integer filterSelected, Long sceneId) { |
| | | return baseMapper.selectFwAreaDivideList(filterSelected, sceneId); |
| | | } |
| | | |
| | | @Override |
| | | 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) { |
| | | List<Long> deptList = SysCache.getDeptChildIds(Long.valueOf(AuthUtil.getDeptId())); |
| | | fwAreaDivideStatistics.setDeptList(deptList); |
| | | return page.setRecords(baseMapper.selectFwAreaDivideStatisticsPage(page, fwAreaDivideStatistics)); |
| | | } |
| | | |
| | | @Override |
| | | public FwAreaDivideStatisticsVO selectFwAreaDivideStatisticsDetail( |
| | | FwAreaDivideStatisticsDTO fwAreaDivideStatistics) { |
| | | return baseMapper.selectFwAreaDivideStatisticsDetail(fwAreaDivideStatistics); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @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; |
| | | } |
| | | |
| | |
| | | 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()); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |