| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Menu; |
| | | import com.moral.api.entity.MonitorPoint; |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.mapper.MonitorPointMapper; |
| | | import com.moral.api.mapper.SysAreaMapper; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysArea> implements SysAreaService { |
| | | |
| | | @Autowired |
| | | private SysAreaMapper sysAreaMapper; |
| | | |
| | | @Autowired |
| | | private MonitorPointMapper monitorPointMapper; |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getMapPath(Integer orgId) { |
| | | QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("province_code", "city_code", "area_code") |
| | | .eq("organization_id", orgId) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | //根据组织id查询所有站点 |
| | | List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(queryWrapper); |
| | | Set<Integer> cityCodes = new HashSet<>(); |
| | | for (MonitorPoint monitorPoint : monitorPoints) { |
| | | Integer provinceCode = monitorPoint.getProvinceCode(); |
| | | Integer cityCode = monitorPoint.getCityCode(); |
| | | Integer areaCode = monitorPoint.getAreaCode(); |
| | | if (provinceCode != null) { |
| | | cityCodes.add(provinceCode); |
| | | } |
| | | if (cityCode != null) { |
| | | cityCodes.add(cityCode); |
| | | } |
| | | if (areaCode != null) { |
| | | cityCodes.add(areaCode); |
| | | } |
| | | } |
| | | |
| | | QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>(); |
| | | sysAreaQueryWrapper.select("area_code", "area_name", "parent_code").in("area_code", cityCodes); |
| | | //获取当前用户拥有权限的地图列表 |
| | | List<SysArea> allAreas = sysAreaMapper.selectList(sysAreaQueryWrapper); |
| | | |
| | | //第一级城市 |
| | | List<SysArea> oneSysArea = allAreas.stream() |
| | | .filter(o -> o.getParentCode().equals(0)) |
| | | .sorted(Comparator.comparing(SysArea::getAreaCode)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Map<String, Object>> newList = new ArrayList<>(); |
| | | //遍历一级菜单 |
| | | oneSysArea.forEach(o -> { |
| | | Map<String, Object> sysAreaMap = new LinkedHashMap<>(); |
| | | sysAreaMap.put("provinceCode", o.getAreaCode()); |
| | | sysAreaMap.put("provinceName", o.getAreaName()); |
| | | sysAreaMap.put("cities", getAreasByRecursion(o, allAreas)); |
| | | newList.add(sysAreaMap); |
| | | }); |
| | | return newList; |
| | | } |
| | | |
| | | //获取层级城市列表 |
| | | private List<Map<String, Object>> getAreasByRecursion(SysArea sysArea, List<SysArea> sysAreas) { |
| | | SysArea newSysArea = new SysArea(); |
| | | newSysArea.setParentCode(sysArea.getAreaCode()); |
| | | //筛选出下一级城市信息 |
| | | List<SysArea> nextLevel = sysAreas.stream() |
| | | .filter(o -> o.getParentCode().equals(sysArea.getAreaCode())) |
| | | .collect(Collectors.toList()); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | |
| | | if (nextLevel.size() > 0) { |
| | | nextLevel.forEach(o -> { |
| | | Map<String, Object> sysMap = new LinkedHashMap<>(); |
| | | if (o.getAreaCode().toString().endsWith("00")) { |
| | | sysMap.put("cityCode", o.getAreaCode()); |
| | | sysMap.put("cityName", o.getAreaName()); |
| | | sysMap.put("provinceCode", o.getParentCode()); |
| | | sysMap.put("areas", getAreasByRecursion(o, sysAreas)); |
| | | } else { |
| | | sysMap.put("areaCode", o.getAreaCode()); |
| | | sysMap.put("areaName", o.getAreaName()); |
| | | sysMap.put("cityCode", o.getParentCode()); |
| | | } |
| | | list.add(sysMap); |
| | | }); |
| | | } |
| | | return list; |
| | | } |
| | | } |