| | |
| | | import com.stylefeng.guns.core.beetl.ShiroExtUtil; |
| | | import com.stylefeng.guns.core.common.constant.factory.PageFactory; |
| | | import com.stylefeng.guns.core.log.LogObjectHolder; |
| | | import com.stylefeng.guns.core.util.IdGenerator; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.modular.system.model.TLocation; |
| | | import com.stylefeng.guns.modular.system.model.TRegion; |
| | |
| | | import com.stylefeng.guns.modular.system.service.ITSiteService; |
| | | import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.model.GeoFencingPolygon; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | |
| | | |
| | | @Autowired |
| | | private GDMapElectricFenceUtil gdMapElectricFenceUtil; |
| | | @Resource |
| | | @Autowired |
| | | private ShiroExtUtil shiroExtUtil; |
| | | |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | |
| | | /** |
| | |
| | | List<TRegion> areaList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", city.getId())); |
| | | model.addAttribute("areaList",areaList); |
| | | }else{ |
| | | model.addAttribute("areaList",null); |
| | | model.addAttribute("areaList",new ArrayList<>()); |
| | | } |
| | | |
| | | //查询所有的站点区域 |
| | |
| | | location.setUpdateTime(new Date()); |
| | | Integer type = jsonObject.getInteger("areaType"); |
| | | location.setType(type); |
| | | if (1 == type){ |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("provinceCode"))){ |
| | | if (1 == type) { |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("provinceCode"))) { |
| | | location.setProvince(jsonObject.getString("province")); |
| | | location.setProvinceCode(jsonObject.getString("provinceCode")); |
| | | } |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("cityCode"))){ |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("cityCode"))) { |
| | | location.setCity(jsonObject.getString("city")); |
| | | location.setCityCode(jsonObject.getString("cityCode")); |
| | | } |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("districtCode"))){ |
| | | if (SinataUtil.isNotEmpty(jsonObject.getString("districtCode"))) { |
| | | location.setDistrict(jsonObject.getString("district")); |
| | | location.setDistrictCode(jsonObject.getString("districtCode")); |
| | | } |
| | | }else if (2 == type){ |
| | | } else if (2 == type) { |
| | | String coordinate = jsonObject.getString("coordinate"); |
| | | coordinate = coordinate.substring(0, coordinate.length() - 1); |
| | | location.setCoordinate(coordinate); |
| | | //将电子围栏坐标信息存储到MongoDB |
| | | String[] s1 = coordinate.split("_"); |
| | | for (String s2 : s1) { |
| | | GeoFencingPolygon gfp = new GeoFencingPolygon(); |
| | | gfp.setId(IdGenerator.getId()); |
| | | gfp.setSiteId(id); |
| | | gfp.setName(jsonObject.getString("name")); |
| | | String[] split = s2.split(";"); |
| | | List<Point> points = new ArrayList<>(); |
| | | for (String s : split) { |
| | | String[] str = s.split(","); |
| | | Point point = new Point(Double.parseDouble(str[0]), Double.parseDouble(str[1])); |
| | | points.add(point); |
| | | } |
| | | //最后一个点要和第一个点相同 |
| | | points.add(new Point(points.get(0).getX(), points.get(0).getY())); |
| | | gfp.setGeoJsonPolygon(new GeoJsonPolygon(points)); |
| | | mongoTemplate.save(gfp); |
| | | } |
| | | } |
| | | itLocationService.insert(location); |
| | | |
| | | if(type == 2){ |
| | | List<String> fence = gdMapElectricFenceUtil.createFence(location.getId().toString(), location.getCoordinate()); |
| | | TLocation location1 = itLocationService.selectById(location.getId()); |
| | | String s = ""; |
| | | for(String gid : fence){ |
| | | s += gid + "_"; |
| | | } |
| | | location1.setGid(s.substring(0, s.length() - 1)); |
| | | location1.setUpdateTime(new Date()); |
| | | itLocationService.updateById(location1); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | TSite tSite = tSiteService.selectById(tSiteId); |
| | | if (1 == optType){ |
| | | tSite.setState(3); |
| | | //删除mongoDB的区域信息 |
| | | Criteria criteria =Criteria.where("siteId").is(tSite.getId()); |
| | | Query query = new Query(criteria); |
| | | mongoTemplate.remove(query,GeoFencingPolygon.class); |
| | | }else if (2 == optType){ |
| | | tSite.setState(2); |
| | | }else if (3 == optType){ |
| | |
| | | } |
| | | } |
| | | for(TLocation location : del){ |
| | | if(location.getType() == 2){ |
| | | String[] s = location.getGid().split("_"); |
| | | for(String gid : s){ |
| | | gdMapElectricFenceUtil.deleteElectricFenc(gid); |
| | | } |
| | | if (location.getType() == 2) { |
| | | //删除mongoDB的区域信息 |
| | | Criteria criteria =Criteria.where("siteId").is(tSite.getId()); |
| | | Query query = new Query(criteria); |
| | | mongoTemplate.remove(query,GeoFencingPolygon.class); |
| | | } |
| | | itLocationService.deleteById(location.getId()); |
| | | } |