| | |
| | | package org.springblade.modules.equipage.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONException; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import springfox.documentation.spring.web.json.Json; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.DateFormat; |
| | |
| | | String res = null; |
| | | res = HttpReqUtil.getInstance().doPost(url, params, null); |
| | | System.out.println("res = " + res); |
| | | JSONArray jsonArray = JSONArray.fromObject(res); |
| | | JSONArray sortedJsonArray = new JSONArray(); |
| | | List<JSONObject> jsonValues = new ArrayList<JSONObject>(); |
| | | for (int j = 0; j < jsonArray.size(); j++) { |
| | | jsonValues.add(jsonArray.getJSONObject(j)); |
| | | } |
| | | Collections.sort(jsonValues, new Comparator<JSONObject>() { |
| | | private static final String KEY_NAME = "date"; |
| | | String string1; |
| | | String string2; |
| | | |
| | | @Override |
| | | public int compare(JSONObject a, JSONObject b) { |
| | | try { |
| | | string1 = a.getString(KEY_NAME).replaceAll("-", ""); |
| | | string2 = b.getString(KEY_NAME).replaceAll("-", ""); |
| | | } catch (JSONException e) { |
| | | // 处理异常 |
| | | } |
| | | //这里是按照时间逆序排列,不加负号为正序排列 |
| | | return -string1.compareTo(string2); |
| | | Map<String,Object> map =(Map<String,Object>) com.alibaba.fastjson.JSON.parse("header"); |
| | | System.out.println("map = " + map.get("code")); |
| | | if (!map.get("code").equals("3")) { |
| | | JSONArray jsonArray = JSONArray.fromObject(res); |
| | | JSONArray sortedJsonArray = new JSONArray(); |
| | | List<JSONObject> jsonValues = new ArrayList<JSONObject>(); |
| | | for (int j = 0; j < jsonArray.size(); j++) { |
| | | jsonValues.add(jsonArray.getJSONObject(j)); |
| | | } |
| | | }); |
| | | for (int c = 0; c < jsonArray.size(); c++) { |
| | | sortedJsonArray.add(jsonValues.get(c)); |
| | | } |
| | | //经度 |
| | | String gis_jd = sortedJsonArray.getJSONObject(0).getString("gis_jd"); |
| | | //纬度 |
| | | String gis_wd = sortedJsonArray.getJSONObject(0).getString("gis_wd"); |
| | | String date = sortedJsonArray.getJSONObject(0).getString("date"); |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date dates = formatter.parse(date); |
| | | //经度 |
| | | liveLocation.setLongitude(gis_jd); |
| | | liveLocation.setLatitude(gis_wd); |
| | | //纬度 |
| | | liveLocation.setRecordTime(dates); |
| | | //先查询是否已有实时位置信息,如果有,则更新,没有则插入 |
| | | LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation); |
| | | boolean status = false; |
| | | if (null == liveLocationInfo) { |
| | | //新增 |
| | | status = liveLocationService.save(liveLocation); |
| | | //数据推送 |
| | | String s1 = |
| | | "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time) " + |
| | | "values(" + "'" + liveLocation.getId() + "'" + "," + |
| | | "'" + liveLocation.getType() + "'" + "," + |
| | | "'" + liveLocation.getWorkerId() + "'" + "," + |
| | | "'" + liveLocation.getLongitude() + "'" + "," + |
| | | "'" + liveLocation.getLatitude() + "'" + "," + |
| | | "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" + ")"; |
| | | FtpUtil.sqlFileUpload(s1); |
| | | } else { |
| | | status = liveLocationService.updateById(liveLocationInfo); |
| | | //内网同步 |
| | | String s1 = |
| | | "update sys_live_location set type = " + "'" + liveLocationInfo.getType() + "'" + |
| | | ",worker_id = " + "'" + liveLocationInfo.getWorkerId() + "'" + |
| | | ",longitude = " + "'" + liveLocationInfo.getLongitude() + "'" + |
| | | ",latitude = " + "'" + liveLocationInfo.getLatitude() + "'" + |
| | | ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocationInfo.getRecordTime()) + "'" + |
| | | " " + "where id = " + "'" + liveLocationInfo.getId() + "'"; |
| | | FtpUtil.sqlFileUpload(s1); |
| | | Collections.sort(jsonValues, new Comparator<JSONObject>() { |
| | | private static final String KEY_NAME = "date"; |
| | | String string1; |
| | | String string2; |
| | | |
| | | @Override |
| | | public int compare(JSONObject a, JSONObject b) { |
| | | try { |
| | | string1 = a.getString(KEY_NAME).replaceAll("-", ""); |
| | | string2 = b.getString(KEY_NAME).replaceAll("-", ""); |
| | | } catch (JSONException e) { |
| | | // 处理异常 |
| | | } |
| | | //这里是按照时间逆序排列,不加负号为正序排列 |
| | | return -string1.compareTo(string2); |
| | | } |
| | | }); |
| | | for (int c = 0; c < jsonArray.size(); c++) { |
| | | sortedJsonArray.add(jsonValues.get(c)); |
| | | } |
| | | //经度 |
| | | String gis_jd = sortedJsonArray.getJSONObject(0).getString("gis_jd"); |
| | | //纬度 |
| | | String gis_wd = sortedJsonArray.getJSONObject(0).getString("gis_wd"); |
| | | String date = sortedJsonArray.getJSONObject(0).getString("date"); |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Date dates = formatter.parse(date); |
| | | //经度 |
| | | liveLocation.setLongitude(gis_jd); |
| | | liveLocation.setLatitude(gis_wd); |
| | | //纬度 |
| | | liveLocation.setRecordTime(dates); |
| | | //先查询是否已有实时位置信息,如果有,则更新,没有则插入 |
| | | LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation); |
| | | boolean status = false; |
| | | if (null == liveLocationInfo) { |
| | | //新增 |
| | | status = liveLocationService.save(liveLocation); |
| | | //数据推送 |
| | | String s1 = |
| | | "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time) " + |
| | | "values(" + "'" + liveLocation.getId() + "'" + "," + |
| | | "'" + liveLocation.getType() + "'" + "," + |
| | | "'" + liveLocation.getWorkerId() + "'" + "," + |
| | | "'" + liveLocation.getLongitude() + "'" + "," + |
| | | "'" + liveLocation.getLatitude() + "'" + "," + |
| | | "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" + ")"; |
| | | FtpUtil.sqlFileUpload(s1); |
| | | } else { |
| | | status = liveLocationService.updateById(liveLocationInfo); |
| | | //内网同步 |
| | | String s1 = |
| | | "update sys_live_location set type = " + "'" + liveLocationInfo.getType() + "'" + |
| | | ",worker_id = " + "'" + liveLocationInfo.getWorkerId() + "'" + |
| | | ",longitude = " + "'" + liveLocationInfo.getLongitude() + "'" + |
| | | ",latitude = " + "'" + liveLocationInfo.getLatitude() + "'" + |
| | | ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocationInfo.getRecordTime()) + "'" + |
| | | " " + "where id = " + "'" + liveLocationInfo.getId() + "'"; |
| | | FtpUtil.sqlFileUpload(s1); |
| | | } |
| | | } |
| | | } |
| | | } |