src/main/java/com/moral/controller/WebController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/entity/WebCity.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/entity/WebProvince.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/mapper/MonitorPointMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/MapPathService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/MonitorPointService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/AccountServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/MapPathServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/controller/WebController.java
@@ -44,6 +44,7 @@ AccountService accountService; @Resource DictionaryDataService dictionaryDataService; @Resource OrganizationService organizationService; @Resource WebTokenService webTokenService; @@ -67,17 +68,35 @@ @GetMapping("test") public ResultBean<List<WebProvince>> add(HttpServletRequest request) { String token = request.getHeader("token"); String token = request.getHeader("token"); List<WebProvince> mapPath = mapPathService.getMapPath(token); if(ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败",ResultBean.FAIL); if (ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败", ResultBean.FAIL); return new ResultBean<>(mapPath); } @GetMapping("redisTest") public ResultBean<List<WebProvince>> redisTest(HttpServletRequest request) { String token = request.getHeader("token"); List<WebProvince> mapPath = mapPathService.getMapPath(token); if (ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败", ResultBean.FAIL); return new ResultBean<>(mapPath); } @GetMapping("sqlTest") public ResultBean<List<WebProvince>> sqlTest(HttpServletRequest request) { String token = request.getHeader("token"); List<WebProvince> mapPath = mapPathService.getMapPathTest(token); if (ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败", ResultBean.FAIL); return new ResultBean<>(mapPath); } /** * @Description: 登陆接口 * @Param: [parameters] * @return: java.util.Map<java.lang.String , java.lang.Object> * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 下雨听风 * @Date: 2020/10/19 */ @@ -101,7 +120,7 @@ /** * @Description: 退出接口 * @Param: [request] * @return: java.util.Map<java.lang.String , java.lang.Object> * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 下雨听风 * @Date: 2020/10/19 */ @@ -116,13 +135,7 @@ return resultMap; } /** * @Description: * @Param: [request] * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 下雨听风 * @Date: 2020/10/19 */ @UserLoginToken @GetMapping("getAccountInfo") public Map<String, Object> getAccountInfo(HttpServletRequest request) { @@ -134,48 +147,9 @@ throw new WebAuthException("401,token无效"); } Map<String, Object> resultMap = accountService.getAccountInfoById(id); Object orgId = resultMap.get("orgId"); if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) { StringBuilder areaNamesBuilder = new StringBuilder("中国"); //判断是否为本公司开发者 if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) { //不是本公司开发者则获取用户所属地区 Organization organization = organizationService.getOrganizationById((Integer) orgId); if (organization.getAreaNames() != null) { Map<String, String> areaNameMap = BeanUtils.beanToMap(organization.getAreaNames()); List<String> names = areaNameMap.entrySet().stream().filter(item -> { return item.getValue() != null; }).map(item -> { return item.getValue(); }).collect(Collectors.toList()); AreaNames areaNames = organization.getAreaNames(); areaNamesBuilder.append("/"); areaNamesBuilder.append(String.join("/", names)); } // 企业用户 if (organization.getRank() != null && organization.getRank() == 0) { resultMap.put("type", "enterprise"); } else { resultMap.put("type", "government"); } Number mapAreaCode = null; if (organization.getVillageCode() != null) { mapAreaCode = organization.getVillageCode(); } else if (organization.getTownCode() != null) { mapAreaCode = organization.getTownCode(); } else if (organization.getAreaCode() != null) { mapAreaCode = organization.getAreaCode(); } else if (organization.getCityCode() != null) { mapAreaCode = organization.getCityCode(); } else if (organization.getProvinceCode() != null) { mapAreaCode = organization.getProvinceCode(); } resultMap.put("mapAreaCode", mapAreaCode.toString()); } resultMap.put("mapPath", areaNamesBuilder.toString()); String accountId = String.valueOf(resultMap.get("accountId")); resultMap.put("token", webTokenService.getToken(accountId)); } String accountId = String.valueOf(resultMap.get("accountId")); resultMap.put("token", webTokenService.getToken(accountId)); return resultMap; } @@ -183,7 +157,7 @@ /** * @Description: 获取传感器平均值 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.List < java.util.Map < java.lang.String , java.lang.Object>>> * @return: com.moral.common.bean.ResultBean<java.util.List < java.util.Map < java.lang.String , java.lang.Object>>> * @Author: 下雨听风 * @Date: 2020/10/19 */ @@ -212,7 +186,7 @@ /** * @Description: 获取某个站点设备信息 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.MonitorPoint>> * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.MonitorPoint>> * @Author: 下雨听风 * @Date: 2020/10/19 */ @@ -228,7 +202,7 @@ /** * @Description: 获取坐标接口,前端用于建点 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.Device>> * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.Device>> * @Author: 下雨听风 * @Date: 2020/10/19 */ @@ -243,13 +217,13 @@ /** * @Description: 根据monitorId获取该站点下每一台设备具体传感器的五分钟平均值 * @Param: [] * @return: com.moral.common.bean.ResultBean<java.util.Map < java.lang.String , java.lang.Object>> * @return: com.moral.common.bean.ResultBean<java.util.Map < java.lang.String , java.lang.Object>> * @Author: 下雨听风 * @Date: 2020/10/19 */ @GetMapping("fiveMinuteAvgData") public ResultBean<Map<String,Object>> getSensorFiveMinuteAvgData(HttpServletRequest request) { public ResultBean<Map<String, Object>> getSensorFiveMinuteAvgData(HttpServletRequest request) { //获取参数,传感器和monitorpointId Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId"))) @@ -284,30 +258,30 @@ datas = insertDeviceInfo(datas, devices); //根据monitorPointId获取国控站坐标 List<Map<String,Object>> coordinate = new ArrayList<>(); List<Map<String, Object>> coordinate = new ArrayList<>(); MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId); Integer orgId = monitorPoint.getOrganizationId(); List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId); monitorPoints.forEach(value->{ if("国控站".equals(value.getDescription())) { monitorPoints.forEach(value -> { if ("国控站".equals(value.getDescription())) { List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); Map<String,Object> controlStation = new HashMap<>(); controlStation.put("name",value.getName()); Map<String, Object> controlStation = new HashMap<>(); controlStation.put("name", value.getName()); controlStation.put("longitude", list.get(0)); controlStation.put("latitude", list.get(1)); coordinate.add(controlStation); } }); Map<String,Object> datasMap = new HashMap<>(); datasMap.put("coordinate",coordinate); datasMap.put("device",datas); Map<String, Object> datasMap = new HashMap<>(); datasMap.put("coordinate", coordinate); datasMap.put("device", datas); return new ResultBean<Map<String,Object>>(datasMap); return new ResultBean<Map<String, Object>>(datasMap); } @GetMapping("cangzhouMIdGetAllDevice") public ResultBean<Map<String,Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) { public ResultBean<Map<String, Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) { //获取参数,传感器和monitorpointId Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId"))) @@ -317,10 +291,10 @@ MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId); Integer code = mPoint.getCityCode(); List<Device> devices = null; if (code == 130900){ devices = deviceService.getDeviceByCode(); }else { devices = deviceService.getDevicesByMonitorPointId(monitorPointId); if (code == 130900) { devices = deviceService.getDeviceByCode(); } else { devices = deviceService.getDevicesByMonitorPointId(monitorPointId); } //根据monitorpointId获取该站点下所有设备mac集合 if (ObjectUtils.isEmpty(devices)) @@ -348,35 +322,35 @@ datas = insertDeviceInfo(datas, devices); //根据monitorPointId获取国控站坐标 List<Map<String,Object>> coordinate = new ArrayList<>(); List<Map<String, Object>> coordinate = new ArrayList<>(); MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId); Integer orgId = monitorPoint.getOrganizationId(); List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId); monitorPoints.forEach(value->{ if("国控站".equals(value.getDescription())) { monitorPoints.forEach(value -> { if ("国控站".equals(value.getDescription())) { List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); Map<String,Object> controlStation = new HashMap<>(); controlStation.put("name",value.getName()); Map<String, Object> controlStation = new HashMap<>(); controlStation.put("name", value.getName()); controlStation.put("longitude", list.get(0)); controlStation.put("latitude", list.get(1)); coordinate.add(controlStation); } }); Map<String,Object> datasMap = new HashMap<>(); datasMap.put("coordinate",coordinate); datasMap.put("device",datas); Map<String, Object> datasMap = new HashMap<>(); datasMap.put("coordinate", coordinate); datasMap.put("device", datas); return new ResultBean<Map<String,Object>>(datasMap); return new ResultBean<Map<String, Object>>(datasMap); } /** * @Description: 根据mac号获取单台设备信息,特殊客户只显示客户需要的传感器信息 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.Map<java.lang.String,java.lang.Object>> * @Author: 下雨听风 * @Date: 2020/10/22 */ /** * @Description: 根据mac号获取单台设备信息,特殊客户只显示客户需要的传感器信息 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.Map < java.lang.String , java.lang.Object>> * @Author: 下雨听风 * @Date: 2020/10/22 */ @GetMapping("fiveMinuteAvgDataByMac") public ResultBean<Map<String, Object>> fiveMinuteAvgDataByMac(HttpServletRequest request) { //获取参数,mac号 @@ -446,22 +420,29 @@ return new ResultBean<Map<String, Object>>(sortDatas); } /** * @Description: 根据token获取用户地图 * @Param: [request] * @return: com.moral.common.bean.ResultBean<java.util.List < com.moral.entity.WebProvince>> * @Author: 下雨听风 * @Date: 2020/11/27 */ @UserLoginToken @GetMapping("mapPath") public ResultBean<List<WebProvince>> mapPath(HttpServletRequest request) { String token = request.getHeader("token"); String token = request.getHeader("token"); List<WebProvince> mapPath = mapPathService.getMapPath(token); if(ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败",ResultBean.FAIL); if (ObjectUtils.isEmpty(mapPath)) return new ResultBean<>("获取地图信息失败", ResultBean.FAIL); return new ResultBean<>(mapPath); } /** * @Description: 返回结果添加设备经纬度以及state * @Param: [datas, devices] * @return: java.util.List<java.util.Map < java.lang.String , java.lang.Object>> * @return: java.util.List<java.util.Map < java.lang.String , java.lang.Object>> * @Author: 下雨听风 * @Date: 2020/10/19 */ src/main/java/com/moral/entity/WebCity.java
@@ -15,4 +15,11 @@ private Integer provinceCode; private List<Area> areas; public WebCity(Integer cityCode, String cityName, Integer provinceCode, List<Area> areas) { this.cityCode = cityCode; this.cityName = cityName; this.provinceCode = provinceCode; this.areas = areas; } } src/main/java/com/moral/entity/WebProvince.java
@@ -13,4 +13,10 @@ private String provinceName; private List<WebCity> cities; public WebProvince(Integer provinceCode, String provinceName, List<WebCity> cities) { this.provinceCode = provinceCode; this.provinceName = provinceName; this.cities = cities; } } src/main/java/com/moral/mapper/MonitorPointMapper.java
@@ -2,6 +2,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import com.moral.entity.Device; @@ -50,4 +51,6 @@ String getOrgIdByMac(String mac); String getMonitorName(int mpId); List<MonitorPoint> getMonitorPointsByOrganizationIds(@Param("orgIds") Set<Integer> orgIds); } src/main/java/com/moral/service/MapPathService.java
@@ -6,4 +6,5 @@ public interface MapPathService { List<WebProvince> getMapPath(String token); List<WebProvince> getMapPathTest(String token); } src/main/java/com/moral/service/MonitorPointService.java
@@ -3,6 +3,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import com.alibaba.fastjson.JSONObject; import com.moral.common.bean.PageBean; @@ -31,6 +32,8 @@ List<MonitorPoint> getMonitorPointsByOrganizationId(Integer orgId); List<MonitorPoint> getMonitorPointsByOrganizationIds(Set<Integer> orgIds); List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters); List<Integer> queryVersionsById(Integer id); src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -14,6 +14,7 @@ import com.moral.entity.*; import com.moral.mapper.DictionaryDataMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -73,6 +74,9 @@ result.put("accountId", account.getId()); result.put("orgId", account.getOrganizationId()); result.put("data", menuList); String regionCode = getRegionCodeByAccount(account); if (!ObjectUtils.isEmpty(regionCode)) result.put("regionCode", regionCode); setOrgIdsByAccount(result); } } @@ -396,11 +400,6 @@ result.put("accountId", -1); } else { result = judgeAccountInfo(account); if (!result.get("accountId").equals(-1)){ String regionCode = getRegionCodeByAccount(account); if(!ObjectUtils.isEmpty(regionCode)) result.put("regionCode",regionCode); } } return result; @@ -409,7 +408,7 @@ /** * @Description: 根据id获取默认显示的地区码 * @Param: [params] * @return: java.util.Map<java.lang.String , java.lang.Object> * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 下雨听风 * @Date: 2020/11/25 */ @@ -418,13 +417,13 @@ organization.setId(account.getOrganizationId()); organization = organizationMapper.selectOne(organization); Map<String, Object> regionCodeAndType = getRegionCodeAndTypeByOrg(organization); if(ObjectUtils.isEmpty(regionCodeAndType)) if (ObjectUtils.isEmpty(regionCodeAndType)) return null; return (String) regionCodeAndType.get("regionCode"); } public static Map<String,Object> getRegionCodeAndTypeByOrg(Organization organization){ Map<String,Object> result = new HashMap<>(); public Map<String, Object> getRegionCodeAndTypeByOrg(Organization organization) { Map<String, Object> result = new HashMap<>(); String regionCode = ""; String regionType = ""; Long villageCode = organization.getVillageCode(); @@ -433,26 +432,26 @@ Integer cityCode = organization.getCityCode(); Integer provinceCode = organization.getProvinceCode(); if(!ObjectUtils.isEmpty(villageCode)){ if (!ObjectUtils.isEmpty(villageCode)) { regionCode = String.valueOf(villageCode); regionType = "village"; }else if(!ObjectUtils.isEmpty(townCode)){ } else if (!ObjectUtils.isEmpty(townCode)) { regionCode = String.valueOf(townCode); regionType = "town"; }else if(!ObjectUtils.isEmpty(areaCode)){ } else if (!ObjectUtils.isEmpty(areaCode)) { regionCode = String.valueOf(areaCode); regionType = "area"; }else if(!ObjectUtils.isEmpty(cityCode)){ } else if (!ObjectUtils.isEmpty(cityCode)) { regionCode = String.valueOf(cityCode); regionType = "city"; }else if(!ObjectUtils.isEmpty(provinceCode)){ } else if (!ObjectUtils.isEmpty(provinceCode)) { regionCode = String.valueOf(provinceCode); regionType = "province"; }else{ } else { return null; } result.put("regionCode",regionCode); result.put("regionType",regionType); result.put("regionCode", regionCode); result.put("regionType", regionType); return result; } } src/main/java/com/moral/service/impl/MapPathServiceImpl.java
@@ -1,20 +1,21 @@ package com.moral.service.impl; import com.alibaba.fastjson.JSON; import com.moral.common.util.WebTokenUtils; import com.moral.controller.ScreenController; import com.moral.entity.Organization; import com.moral.entity.WebProvince; import com.moral.mapper.MapPathMapper; import com.moral.entity.*; import com.moral.mapper.*; import com.moral.service.DictionaryDataService; import com.moral.service.MapPathService; import com.moral.service.MonitorPointService; import com.moral.service.OrganizationService; import org.apache.log4j.Logger; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.*; @Service public class MapPathServiceImpl implements MapPathService { @@ -23,6 +24,42 @@ MapPathMapper mapPathMapper; @Resource OrganizationService organizationService; @Resource DictionaryDataService dictionaryDataService; @Resource MonitorPointService monitorPointService; @Resource ProvinceMapper provinceMapper; @Resource CityMapper cityMapper; @Resource AreaMapper areaMapper; @Resource MonitorPointMapper monitorPointMapper; @Resource RedisTemplate redisTemplate; /*@Override public List<WebProvince> getMapPath(String token) { List<WebProvince> results; try { Map<String, Object> params = new HashMap<>(); Integer id = Integer.parseInt(WebTokenUtils.getIdBytoken(token)); Organization organization = organizationService.getOrganizationByAccountId(id); Map<String, Object> regionCodeAndType = getRegionCodeAndTypeByOrg(organization); String regionType = (String) regionCodeAndType.get("regionType"); String regionCode = (String) regionCodeAndType.get("regionCode"); params.put(regionType, regionCode); results = mapPathMapper.getMapPathByRegionCode(params); filterMapPath(organization, results); return results; } catch (Exception e) { log.error(e.getMessage()); } return null; }*/ /** * @Description: 根据用户token获取用户地图权限 @@ -33,25 +70,152 @@ */ @Override public List<WebProvince> getMapPath(String token) { List<WebProvince> results; try { Map<String, Object> params = new HashMap<>(); Integer id = Integer.parseInt(WebTokenUtils.getIdBytoken(token)); Organization organization = organizationService.getOrganizationByAccountId(id); Map<String, Object> regionCodeAndType = getRegionCodeAndTypeByOrg(organization); String regionType = (String) regionCodeAndType.get("regionType"); String regionCode = (String) regionCodeAndType.get("regionCode"); params.put(regionType, regionCode); results = mapPathMapper.getMapPathByRegionCode(params); return results; } catch (Exception e) { log.error(e.getMessage()); Integer id = Integer.parseInt(WebTokenUtils.getIdBytoken(token)); Organization organization = organizationService.getOrganizationByAccountId(id); List<MonitorPoint> monitorPoints; //判断是否属于超级组织,如果属于超级组织则返回所有存在设备的省市区,否则根据org下的站点进行查询。 if (dictionaryDataService.querySupperOrgId().equals(organization.getId())) { monitorPoints = monitorPointMapper.selectAll(); } else { Integer parentOrgId = organization.getId(); Set<Integer> childOrgIds = organizationService.getChildOrganizationIds(parentOrgId); childOrgIds.add(parentOrgId); monitorPoints = monitorPointService.getMonitorPointsByOrganizationIds(childOrgIds); } return null; Set<Integer> provinceCodesSet = new HashSet<>(); Set<Integer> cityCodesSet = new HashSet<>(); Set<Integer> areaCodesSet = new HashSet<>(); for (MonitorPoint monitorPoint : monitorPoints) { provinceCodesSet.add(monitorPoint.getProvinceCode()); cityCodesSet.add(monitorPoint.getCityCode()); areaCodesSet.add(monitorPoint.getAreaCode()); } //Set转为List用于排序 List<Integer> provinceCodes = new ArrayList<>(provinceCodesSet); List<Integer> cityCodes = new ArrayList<>(cityCodesSet); List<Integer> areaCodes = new ArrayList<>(areaCodesSet); provinceCodes.removeAll(Collections.singleton(null)); cityCodes.removeAll(Collections.singleton(null)); areaCodes.removeAll(Collections.singleton(null)); Comparator<Integer> comparator = new ComparatorUtil(); Collections.sort(provinceCodes, comparator); Collections.sort(cityCodes, comparator); Collections.sort(areaCodes, comparator); List<WebProvince> mapPath = new ArrayList<>(); for (Integer provinceCode : provinceCodes) { String provinceCodeStr = String.valueOf(provinceCode); String provinceJSON = (String) redisTemplate.opsForHash().get("province_Map", String.valueOf(provinceCode)); Province province = JSON.parseObject(provinceJSON).toJavaObject(Province.class); WebProvince webProvince = new WebProvince(province.getProvinceCode(), province.getProvinceName(), new ArrayList<>()); for (Integer cityCode : cityCodes) { String cityCodeStr = String.valueOf(cityCode); //判断该市是否属于该省 if (cityCodeStr.substring(0, 2).equals(provinceCodeStr.substring(0, 2))) { String cityJSON = (String) redisTemplate.opsForHash().get("city_Map", String.valueOf(cityCode)); City city = JSON.parseObject(cityJSON).toJavaObject(City.class); WebCity WebCity = new WebCity(city.getCityCode(), city.getCityName(), provinceCode, new ArrayList<>()); for (Integer areaCode : areaCodes) { String areaCodeStr = String.valueOf(areaCode); if (cityCodeStr.substring(0, 4).equals(areaCodeStr.substring(0, 4))) { String areaJSON = (String) redisTemplate.opsForHash().get("area_Map", String.valueOf(areaCode)); Area area = JSON.parseObject(areaJSON).toJavaObject(Area.class); WebCity.getAreas().add(area); } } webProvince.getCities().add(WebCity); } } mapPath.add(webProvince); } return mapPath; } public static Map<String, Object> getRegionCodeAndTypeByOrg(Organization organization) { @Override public List<WebProvince> getMapPathTest(String token) { long monitorStartTime = System.currentTimeMillis(); Integer id = Integer.parseInt(WebTokenUtils.getIdBytoken(token)); Organization organization = organizationService.getOrganizationByAccountId(id); List<MonitorPoint> monitorPoints; //判断是否属于超级组织,如果属于超级组织则返回所有存在设备的省市区,否则根据org下的站点进行查询。 if (dictionaryDataService.querySupperOrgId().equals(organization.getId())) { monitorPoints = monitorPointMapper.selectAll(); } else { Integer parentOrgId = organization.getId(); Set<Integer> childOrgIds = organizationService.getChildOrganizationIds(parentOrgId); childOrgIds.add(parentOrgId); monitorPoints = monitorPointService.getMonitorPointsByOrganizationIds(childOrgIds); } System.out.println("查询站点消耗时间:" + String.valueOf(System.currentTimeMillis() - monitorStartTime)); long listStartTime = System.currentTimeMillis(); Set<Integer> provinceCodesSet = new HashSet<>(); Set<Integer> cityCodesSet = new HashSet<>(); Set<Integer> areaCodesSet = new HashSet<>(); for (MonitorPoint monitorPoint : monitorPoints) { provinceCodesSet.add(monitorPoint.getProvinceCode()); cityCodesSet.add(monitorPoint.getCityCode()); areaCodesSet.add(monitorPoint.getAreaCode()); } //Set转为List用于排序 List<Integer> provinceCodes = new ArrayList<>(provinceCodesSet); List<Integer> cityCodes = new ArrayList<>(cityCodesSet); List<Integer> areaCodes = new ArrayList<>(areaCodesSet); provinceCodes.removeAll(Collections.singleton(null)); cityCodes.removeAll(Collections.singleton(null)); areaCodes.removeAll(Collections.singleton(null)); Comparator<Integer> comparator = new ComparatorUtil(); Collections.sort(provinceCodes, comparator); Collections.sort(cityCodes, comparator); Collections.sort(areaCodes, comparator); System.out.println("遍历站点集合转换消耗时间" + String.valueOf(System.currentTimeMillis() - listStartTime)); List<WebProvince> mapPath = new ArrayList<>(); long redisStartTime = System.currentTimeMillis(); for (Integer provinceCode : provinceCodes) { String provinceCodeStr = String.valueOf(provinceCode); Province province = new Province(); province.setProvinceCode(provinceCode); province = provinceMapper.selectOne(province); WebProvince webProvince = new WebProvince(province.getProvinceCode(), province.getProvinceName(), new ArrayList<>()); for (Integer cityCode : cityCodes) { String cityCodeStr = String.valueOf(cityCode); //判断该市是否属于该省 if (cityCodeStr.substring(0, 2).equals(provinceCodeStr.substring(0, 2))) { City city = new City(); city.setCityCode(cityCode); city = cityMapper.selectOne(city); WebCity WebCity = new WebCity(city.getCityCode(), city.getCityName(), provinceCode, new ArrayList<>()); for (Integer areaCode : areaCodes) { String areaCodeStr = String.valueOf(areaCode); if (cityCodeStr.substring(0, 4).equals(areaCodeStr.substring(0, 4))) { Area area = new Area(); area.setAreaCode(areaCode); area = areaMapper.selectOne(area); WebCity.getAreas().add(area); } } webProvince.getCities().add(WebCity); } } mapPath.add(webProvince); } System.out.println("redis转换时间:" + String.valueOf(System.currentTimeMillis() - redisStartTime)); return mapPath; } /** * @Description: 根据组织id,获取该组织地区的定位和类型。 * @Param: [organization] * @return: java.util.Map<java.lang.String , java.lang.Object> * @Author: 下雨听风 * @Date: 2020/11/30 */ private Map<String, Object> getRegionCodeAndTypeByOrg(Organization organization) { Map<String, Object> result = new HashMap<>(); String regionCode = ""; String regionType = ""; @@ -77,4 +241,11 @@ result.put("regionType", regionType); return result; } class ComparatorUtil implements Comparator<Integer> { @Override public int compare(Integer o1, Integer o2) { return o1 - o2; } } } src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -275,6 +275,11 @@ } @Override public List<MonitorPoint> getMonitorPointsByOrganizationIds(Set<Integer> orgIds) { return monitorPointMapper.getMonitorPointsByOrganizationIds(orgIds); } @Override public List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters) { Example example = new Example(MonitorPoint.class); Criteria criteria = example.createCriteria();