package com.stylefeng.guns.modular.crossCity.server.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.stylefeng.guns.modular.crossCity.dao.LocationMapper; import com.stylefeng.guns.modular.crossCity.dao.SiteMapper; import com.stylefeng.guns.modular.crossCity.model.Site; import com.stylefeng.guns.modular.crossCity.server.ISiteService; import com.stylefeng.guns.modular.crossCity.warpper.SiteWarpper; import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; import com.stylefeng.guns.modular.system.util.model.GeoFencingPolygon; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.geo.GeoJsonPoint; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class SiteServiceImpl extends ServiceImpl implements ISiteService { @Resource private SiteMapper siteMapper; @Resource private LocationMapper locationMapper; @Autowired private MongoTemplate mongoTemplate; /** * 获取站点 * @return * @throws Exception */ @Override public List querySite(Integer startSiteId) throws Exception { List> sites = null; if(null == startSiteId){ sites = siteMapper.querySite(null); }else{ sites = siteMapper.querySite(startSiteId); } Set set = new HashSet<>(); for(Map site : sites) { set.add(site.get("cityCode").toString()); } List list = new ArrayList<>(); for(String c : set){ SiteWarpper siteWarpper = new SiteWarpper(); List data = new ArrayList<>(); String name = ""; String code = ""; for(Map s : sites){ if(c.equals(s.get("cityCode").toString())){ Map map = new HashMap<>(); map.put("id", s.get("id")); map.put("name", s.get("name").toString()); name = s.get("cityName").toString(); code = s.get("cityCode").toString(); data.add(map); } } siteWarpper.setName(name); siteWarpper.setCode(code); siteWarpper.setSites(data); list.add(siteWarpper); } return list; } /** * 判断点是都在区域范围内 * @param siteId * @param code * @param lonLat * @return * @throws Exception */ @Override public boolean areaMonitoring(Integer siteId, String code, String lonLat) throws Exception { List> list = this.queryLocation(siteId); for(Map map : list){ if(Integer.valueOf(map.get("type").toString()) == 1){//行政区域 if(null != map.get("districtCode")){ if(code.equals(map.get("districtCode").toString())){ return true; } continue; } if(null != map.get("cityCode")){ if(code.equals(map.get("cityCode").toString())){ return true; } code = code.substring(0, 4) + "00"; if(code.equals(map.get("cityCode").toString())){ return true; } continue; } if(null != map.get("provinceCode")){ code = code.substring(0, 2) + "0000"; if(code.equals(map.get("provinceCode").toString())){ return true; } continue; } } if(Integer.valueOf(map.get("type").toString()) == 2){//电子围栏 String[] split = lonLat.split(","); GeoJsonPoint point = new GeoJsonPoint(Double.valueOf(split[0]), Double.valueOf(split[1])); Query query = Query.query(Criteria.where("geoJsonPolygon").intersects(point)); List geoFencingPolygons = mongoTemplate.find(query, GeoFencingPolygon.class); List s_sites = geoFencingPolygons.stream().map(GeoFencingPolygon::getSiteId).collect(Collectors.toList()); if(s_sites.contains(siteId)){ return true; } } } return false; } /** * 根据站点id获取地点区域 * @param siteId * @return * @throws Exception */ @Override public List> queryLocation(Integer siteId) throws Exception { return locationMapper.queryLocation(siteId); } }