| | |
| | | |
| | | /** |
| | | * 创建电子围栏 |
| | | * |
| | | * @param id |
| | | * @param points |
| | | * @return |
| | | */ |
| | | public List<String> createFence(String id, String points){ |
| | | public List<String> createFence(String id, String points) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 35); |
| | |
| | | //开始调用高德接口创建围栏 |
| | | String[] s = points.split("_"); |
| | | List<String> resoult = new ArrayList<>(); |
| | | for(int i = 0; i < s.length; i++){ |
| | | for (int i = 0; i < s.length; i++) { |
| | | String[] split = s[i].split(";"); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("name", "location_" + id); |
| | | if(split.length == 2){ |
| | | if (split.length == 2) { |
| | | json.put("center", split[0]); |
| | | json.put("radius", split[1]); |
| | | }else{ |
| | | } else { |
| | | json.put("points", s[i]); |
| | | } |
| | | json.put("enable", "true"); |
| | |
| | | |
| | | gdInterfaceService.saveData("https://restapi.amap.com/v4/geofence/meta", "创建电子围栏"); |
| | | |
| | | if(status.equals("0")){//创建成功 |
| | | if (status.equals("0")) {//创建成功 |
| | | resoult.add(data.getString("gid")); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 创建电子围栏 |
| | | * @param id 围栏名称----绘制的数据id值 |
| | | * @param points 多边形围栏坐标 |
| | | * |
| | | * @param id 围栏名称----绘制的数据id值 |
| | | * @param points 多边形围栏坐标 |
| | | */ |
| | | public List<String> createElectricFenc(String id, String points){ |
| | | public List<String> createElectricFenc(String id, String points) { |
| | | List<String> fence = this.createFence(id, points); |
| | | List<String> gids = new ArrayList<>(); |
| | | for(String f : fence){ |
| | | for (String f : fence) { |
| | | JSONObject jsonObject = JSON.parseObject(f); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | String status = data.getString("status"); |
| | | if(status.equals("0")){ |
| | | if (status.equals("0")) { |
| | | gids.add(data.getString("gid")); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 查询 |
| | | * |
| | | * @param gid |
| | | * @return |
| | | */ |
| | | public String findElectricFenc(String gid){ |
| | | public String findElectricFenc(String gid) { |
| | | String url = "https://restapi.amap.com/v4/geofence/meta?key=" + key + "&gid=" + gid; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | JSONArray rs_list = data.getJSONArray("rs_list"); |
| | | if(rs_list.size() > 0){ |
| | | if (rs_list.size() > 0) { |
| | | return rs_list.getJSONObject(0).getString("gid"); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询以创建的所有电子围栏 |
| | | */ |
| | | public String findElectricFenc(String center, String radius, String points){ |
| | | public String findElectricFenc(String center, String radius, String points) { |
| | | String url = "https://restapi.amap.com/v4/geofence/meta?key=" + key; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | |
| | | |
| | | gdInterfaceService.saveData("https://restapi.amap.com/v4/geofence/meta", "查询电子围栏"); |
| | | |
| | | if(ToolUtil.isNotEmpty(center)){//圆形电子围栏 |
| | | if (ToolUtil.isNotEmpty(center)) {//圆形电子围栏 |
| | | JSONArray rs_list = data.getJSONArray("rs_list"); |
| | | for(int i = 0; i < rs_list.size(); i++){ |
| | | for (int i = 0; i < rs_list.size(); i++) { |
| | | String c = rs_list.getJSONObject(i).getString("center"); |
| | | Double r = rs_list.getJSONObject(i).getDouble("radius"); |
| | | if(c.equals(center) && radius.equals(String.valueOf(r))){ |
| | | if (c.equals(center) && radius.equals(String.valueOf(r))) { |
| | | return rs_list.getJSONObject(i).getString("gid"); |
| | | } |
| | | } |
| | | }else{ |
| | | } else { |
| | | JSONArray rs_list = data.getJSONArray("rs_list"); |
| | | for(int i = 0; i < rs_list.size(); i++){ |
| | | for (int i = 0; i < rs_list.size(); i++) { |
| | | String p = rs_list.getJSONObject(i).getString("points"); |
| | | if(points.equals(p)){ |
| | | if (points.equals(p)) { |
| | | return rs_list.getJSONObject(i).getString("gid"); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 查询所有绘制好的电子围栏 |
| | | * |
| | | * @return |
| | | */ |
| | | public JSONArray findAllElectricFenc(int page){ |
| | | if(page == 1){ |
| | | public JSONArray findAllElectricFenc(int page) { |
| | | if (page == 1) { |
| | | jsonArray = new JSONArray(); |
| | | } |
| | | String url = "https://restapi.amap.com/v4/geofence/meta?key=" + key + "&page_no=" + page + "&page_size=" + 30; |
| | |
| | | |
| | | //判断是否有分页 |
| | | int total_record = data.getIntValue("total_record"); |
| | | if(total_record > jsonArray.size()){ |
| | | if (total_record > jsonArray.size()) { |
| | | //有分页,递归调用自己 |
| | | page++; |
| | | this.findAllElectricFenc(page); |
| | |
| | | |
| | | /** |
| | | * 批量更新电子围栏(失效的数据) |
| | | * |
| | | * @param jsonArray |
| | | * @throws ParseException |
| | | */ |
| | | public void updateElectricFenc(JSONArray jsonArray) throws ParseException{ |
| | | public void updateElectricFenc(JSONArray jsonArray) throws ParseException { |
| | | //批量更新查询出的失效的电子围栏,围栏失效日期在当前日期之后的数据 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | for(int i = 0; i < jsonArray.size(); i++){ |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | |
| | | cale.set(Calendar.SECOND, 0); |
| | | cale.set(Calendar.MILLISECOND, 0); |
| | | long timeInMillis = cale.getTimeInMillis(); |
| | | if(timeInMillis1 >= timeInMillis){ |
| | | if (timeInMillis1 >= timeInMillis) { |
| | | String gid = jsonObject.getString("gid"); |
| | | String id = jsonObject.getString("name"); |
| | | String center = jsonObject.getString("center"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 更新电子围栏 |
| | | * |
| | | * @param gid |
| | | * @param id |
| | | * @param center |
| | |
| | | //开始调用高德接口创建围栏 |
| | | JSONObject json = new JSONObject(); |
| | | json.put("name", id); |
| | | if(ToolUtil.isNotEmpty(center)){ |
| | | if (ToolUtil.isNotEmpty(center)) { |
| | | json.put("center", center); |
| | | json.put("radius", radius); |
| | | }else{ |
| | | } else { |
| | | json.put("points", points); |
| | | } |
| | | json.put("valid_time", valid_time); |
| | |
| | | |
| | | /** |
| | | * 电子围栏监控 |
| | | * |
| | | * @param diu 设备唯一标识符,作为记录依据,不影响判断结果。Android设备一般使用imei号码,iOS一般使用idfv号,其余设备可根据业务自定义。 |
| | | * @param locations 数据为坐标数据和坐标产生的时间戳数据,至少包含一个坐标对和时间戳。 |
| | | * 1、传入1个点时,直接判断交互关系。 |
| | |
| | | * 动态交互判断方法:第一个点作为当前时间的点,然后从其余点中选出在当前点之前10s~1小时范围内的最早点,用这两个时间点的位置判断设备与围栏的动态交互关系。若数据无效交互关系默认返回leave。 |
| | | * @return |
| | | */ |
| | | public List<String> monitorElectricFenc(String diu, String locations){ |
| | | if(ToolUtil.isEmpty(diu)){ |
| | | public List<String> monitorElectricFenc(String diu, String locations) { |
| | | if (ToolUtil.isEmpty(diu)) { |
| | | diu = "B78F99DD-2496-4A43-843B-172CDA2D9798"; |
| | | } |
| | | locations = locations + "," + (new Date().getTime() / 1000); |
| | |
| | | List<String> ids = new ArrayList<>(); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | int status = data.getIntValue("status"); |
| | | if(0 == status){ |
| | | if (0 == status) { |
| | | JSONArray fencingEventList = data.getJSONArray("fencing_event_list"); |
| | | for(int i = 0; i < fencingEventList.size(); i++){ |
| | | for (int i = 0; i < fencingEventList.size(); i++) { |
| | | String clientStatus = fencingEventList.getJSONObject(i).getString("client_status"); |
| | | if(clientStatus.equals("in")){//包含给定坐标的电子围栏 |
| | | if (clientStatus.equals("in")) {//包含给定坐标的电子围栏 |
| | | JSONObject fence_info = fencingEventList.getJSONObject(i).getJSONObject("fence_info");//获取电子围栏信息 |
| | | String gid = fence_info.getString("fence_gid"); |
| | | ids.add(gid); |
| | |
| | | |
| | | /** |
| | | * 删除电子围栏 |
| | | * |
| | | * @param gid |
| | | * @return |
| | | */ |
| | | public boolean deleteElectricFenc(String gid){ |
| | | public boolean deleteElectricFenc(String gid) { |
| | | restTemplate.delete("https://restapi.amap.com/v4/geofence/meta?key={1}&gid={2}", key, gid); |
| | | System.out.println("删除:" ); |
| | | System.out.println("删除:"); |
| | | |
| | | gdInterfaceService.saveData("https://restapi.amap.com/v4/geofence/meta", "删除电子围栏"); |
| | | |
| | |
| | | |
| | | /** |
| | | * 获取两点的距离 |
| | | * @param origins 起点坐标 |
| | | * @param destination 终点坐标 |
| | | * @param type 计算类型:0:直线距离 1:驾车导航距离(仅支持国内坐标)。 |
| | | * |
| | | * @param origins 起点坐标 |
| | | * @param destination 终点坐标 |
| | | * @param type 计算类型:0:直线距离 1:驾车导航距离(仅支持国内坐标)。 |
| | | * @return |
| | | */ |
| | | public Map<String, String> getDistance(String origins, String destination, Integer type){ |
| | | public Map<String, String> getDistance(String origins, String destination, Integer type) { |
| | | String url = "https://restapi.amap.com/v3/distance?key=" + key + "&origins=" + origins + "&destination=" + destination + |
| | | "&type=" + type; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | |
| | | |
| | | gdInterfaceService.saveData("https://restapi.amap.com/v3/distance", "查询两点间的距离"); |
| | | |
| | | if(status.equals("1")){ |
| | | if (status.equals("1")) { |
| | | JSONArray results = jsonObject.getJSONArray("results"); |
| | | JSONObject jsonObject1 = results.getJSONObject(0); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("distance", jsonObject1.getString("distance"));//距离(米) |
| | | map.put("duration", jsonObject1.getString("duration"));//预计时间(秒) |
| | | return map; |
| | | }else{ |
| | | } else { |
| | | System.err.println(forObject); |
| | | } |
| | | return null; |
| | |
| | | |
| | | /** |
| | | * 获取路径规划 |
| | | * @param origins 起点坐标 |
| | | * @param destination 终点坐标 |
| | | * @param waypoints 途经点 |
| | | * |
| | | * @param origins 起点坐标 |
| | | * @param destination 终点坐标 |
| | | * @param waypoints 途经点 |
| | | * @return |
| | | */ |
| | | public Map<String, String> getDriving(String origins, String destination, String waypoints){ |
| | | public Map<String, String> getDriving(String origins, String destination, String waypoints) { |
| | | String url = "https://restapi.amap.com/v3/direction/driving?key=" + key + "&origin=" + origins + "&destination=" + destination + |
| | | "&waypoints=" + waypoints + "&extensions=base&strategy=0"; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | |
| | | |
| | | gdInterfaceService.saveData("https://restapi.amap.com/v3/direction/driving", "获取路径规划"); |
| | | |
| | | if(status.equals("1")){ |
| | | if (status.equals("1")) { |
| | | JSONObject route = jsonObject.getJSONObject("route"); |
| | | JSONArray results = route.getJSONArray("paths"); |
| | | JSONObject jsonObject1 = results.getJSONObject(0); |