https://139.196.190.190:8443/svn/hps_web_mana_iis_copy/ /* * 获取两点路径长度m和时间s coord 传 经度long,纬度lat 起点clientid传0 */ public Map getClinetPath(int customerId, int clientId1, int clientId2, double[] coord1, double[] coord2) { Map map = new HashMap(); Map param = new HashMap(); String clientids = clientId1 + "_" + clientId2; if (clientId1 > clientId2) clientids = clientId2 + "_" + clientId1; param.put("clientids", clientids); String tableName = "client_path" + customerId; String sql = "select `meter`,`time` from " + tableName + " where `clientids`=:clientids"; List retData = nativeSqlService.pageList(sql, param); if (true) { //retData != null && retData.size() > 0 map.put("meter", retData.get(0)[0]); map.put("time", retData.get(0)[1]); } else { double _meter = Coordinate.getDistanceMeter(coord1[0], coord1[1], coord2[0], coord2[1], Ellipsoid.Sphere); double _time = 60 * 10; String url = "https://restapi.amap.com/v5/direction/driving?key=647f841c488bc2dc9352e68d6839ec75&show_fields=cost,duration"; url += "&origin=" + Str.GetRadixSubString(coord1[0], 6) + "," + Str.GetRadixSubString(coord1[1], 6); url += "&destination=" + Str.GetRadixSubString(coord2[0], 6) + "," + Str.GetRadixSubString(coord2[1], 6); log.info(url); String resultData = HttpRequestUtil.get(url); DrivingReturn drivingReturn = JSON.parseObject(resultData, DrivingReturn.class); if (drivingReturn.getStatus().equals("1") && drivingReturn.getInfo().equals("OK")) { _meter = Double.parseDouble(drivingReturn.getRoute().getPaths().get(0).getDistance()); _time = Double.parseDouble(drivingReturn.getRoute().getPaths().get(0).getCost().getDuration()); } map.put("meter", _meter); map.put("time", _time); Map param1 = new HashMap(); int clientid1 = clientId1 > clientId2 ? clientId2 : clientId1; int clientid2 = clientId1 > clientId2 ? clientId1 : clientId2; String sql_3 = "select `meter_line`,`time` from " + tableName + " where `clientids`=:clientids ;"; Map param_3 = new HashMap(); param_3.put("clientids", clientids); List retData_3 = nativeSqlService.pageList(sql_3, param_3); if (retData_3 != null && retData_3.size() > 0) { String sql_u = " update " + tableName + " set `meter_line`= "+_meter+" where `clientids` = '"+clientids+"' ; "; Map param_4 = new HashMap(); nativeSqlService.update(sql_u, param_4); }else { String sql1 = "insert into " + tableName + "(clientid1,clientid2,clientids,`meter`,`time`) values(" + clientid1 + "," + clientid2 + ",'" + clientids + "'," + _meter + "," + _time + ");"; nativeSqlService.update(sql1, param1); } } return map; } ---------------------------------------- /* * 获取两点路径长度m和时间s coord 传 经度long,纬度lat 起点clientid传0 */ public Map getClinetPath(int customerId, int clientId1, int clientId2, double[] coord1, double[] coord2) { Map map = new HashMap(); Map param = new HashMap(); String clientids = clientId1 + "_" + clientId2; if (clientId1 > clientId2) clientids = clientId2 + "_" + clientId1; param.put("clientids", clientids); String tableName = "client_path" + customerId; String sql = "select `meter`,`time` from " + tableName + " where `clientids`=:clientids"; List retData = nativeSqlService.pageList(sql, param); if (false) { //retData != null && retData.size() > 0 map.put("meter", retData.get(0)[0]); map.put("time", retData.get(0)[1]); } else { double _meter = Coordinate.getDistanceMeter(coord1[0], coord1[1], coord2[0], coord2[1], Ellipsoid.Sphere); double _time = 60 * 10; String url = "https://restapi.amap.com/v5/direction/driving?key=647f841c488bc2dc9352e68d6839ec75&show_fields=cost,duration"; url += "&origin=" + Str.GetRadixSubString(coord1[0], 6) + "," + Str.GetRadixSubString(coord1[1], 6); url += "&destination=" + Str.GetRadixSubString(coord2[0], 6) + "," + Str.GetRadixSubString(coord2[1], 6); log.info(url); String resultData = HttpRequestUtil.get(url); DrivingReturn drivingReturn = JSON.parseObject(resultData, DrivingReturn.class); if (drivingReturn.getStatus().equals("1") && drivingReturn.getInfo().equals("OK")) { _meter = Double.parseDouble(drivingReturn.getRoute().getPaths().get(0).getDistance()); _time = Double.parseDouble(drivingReturn.getRoute().getPaths().get(0).getCost().getDuration()); } map.put("meter", _meter); map.put("time", _time); Map param1 = new HashMap(); int clientid1 = clientId1 > clientId2 ? clientId2 : clientId1; int clientid2 = clientId1 > clientId2 ? clientId1 : clientId2; String sql_3 = "select `meter`,`time` from " + tableName + " where `clientids`=:clientids ;"; Map param_3 = new HashMap(); param_3.put("clientids", clientids); List retData_3 = nativeSqlService.pageList(sql_3, param_3); if (retData_3 != null && retData_3.size() > 0) { String sql_u = " update " + tableName + " set `meter`= "+_meter+" where `clientids` = '"+clientids+"' ; "; Map param_4 = new HashMap(); nativeSqlService.update(sql_u, param_4); }else { String sql1 = "insert into " + tableName + "(clientid1,clientid2,clientids,`meter`,`time`) values(" + clientid1 + "," + clientid2 + ",'" + clientids + "'," + _meter + "," + _time + ");"; nativeSqlService.update(sql1, param1); } } return map; } ----------------------------------------------- getClinetPath 16420,16423,16428,16480,16484,16488,16494,16502,16510,16511,16538,16586,16748,16769,16802,16804,16805,16816,16874,16880,16948,16949,16958,16975,16980,17085,17127,17130,17205,17207,17316,17328,17346,17350,17353,17365,17376,17440,17499,17510,17534,17687,17826,17828,17877,17948,17952,17964,18032,18099,18152,18532,18558,18976,19113,19183,19196,19219,19223,19517,19524,19534,19640,19747,20104,20150,20502,20503,20511,20513,20541,20558,20597,20612,20613,20614,20615,20616,20617,---- 19517,20502,16874,16428,16816,17085,16484,20614,19534,17826,17510,17499,17948,17127,16480,18099,20597,17346,18152,19524,20541,16975,18032,17350,17205,17877,20615,17207,20513,16748,19113,19219,19223,20150,19183,16949,16980,19196,17440,18532,16510,16511,17365,17964,20503,20613,16948,16423,17316,17376,16880,20617,20104,16958,20616,19747,16420,16769,20558,16586,16804,19640,16538,16805,16802,17828,17687,20612,18558,17952,16502,17534,16494,16488,17328,17353,18976,20511,17130,---- etNoteOrdered: index:68 clientid:20511 meter:4.0 index:27 clientid:17130 meter:15974.0