From 015e0d1feda843d198e736c000b1d27167aef625 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Fri, 14 Jan 2022 18:22:43 +0800
Subject: [PATCH] token 设置修改
---
src/main/java/org/springblade/modules/equipage/controller/fixed.java | 226 +++++++++++++++++++++++++++++---------------------------
1 files changed, 118 insertions(+), 108 deletions(-)
diff --git a/src/main/java/org/springblade/modules/equipage/controller/fixed.java b/src/main/java/org/springblade/modules/equipage/controller/fixed.java
index 4208321..f0b1f31 100644
--- a/src/main/java/org/springblade/modules/equipage/controller/fixed.java
+++ b/src/main/java/org/springblade/modules/equipage/controller/fixed.java
@@ -1,5 +1,6 @@
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;
@@ -19,6 +20,7 @@
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;
@@ -61,71 +63,76 @@
params.put("acc", equipmentCode);
String res = null;
res = HttpReqUtil.getInstance().doPost(url, params, null);
- 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);
+ System.out.println("res = " + res);
+ 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);
+ }
}
}
}
@@ -228,50 +235,53 @@
res = HttpReqUtil.getInstance().doPost(url, params, null);
String a = "[" + res + "]";
JSONArray jsonArray = JSONArray.fromObject(a);
- String data = jsonArray.getJSONObject(0).get("data").toString();
- String b = "[" + data + "]";
- JSONArray jsonArrayb = JSONArray.fromObject(b);
- String x = jsonArrayb.getJSONObject(0).get("x").toString();
- String y = jsonArrayb.getJSONObject(0).get("y").toString();
- String timestamp = jsonArrayb.getJSONObject(0).get("timestamp").toString();
- //实时位置实体类
- LiveLocation liveLocation = new LiveLocation();
- liveLocation.setType(2);
- String carnumber = maps.get(i).get("carnumber").toString();
- liveLocation.setWorkerId(carnumber);
- //经度
- liveLocation.setLongitude(x);
- //纬度
- liveLocation.setLatitude(y);
- Date date = timeStamp2Date(timestamp);
- liveLocation.setRecordTime(date);
- //先查询是否已有实时位置信息,如果有,则更新,没有则插入
- 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);
+ String code = jsonArray.getJSONObject(0).get("code").toString();
+ if (Integer.parseInt(code)==200) {
+ String data = jsonArray.getJSONObject(0).get("data").toString();
+ String b = "[" + data + "]";
+ JSONArray jsonArrayb = JSONArray.fromObject(b);
+ String x = jsonArrayb.getJSONObject(0).get("x").toString();
+ String y = jsonArrayb.getJSONObject(0).get("y").toString();
+ String timestamp = jsonArrayb.getJSONObject(0).get("timestamp").toString();
+ //实时位置实体类
+ LiveLocation liveLocation = new LiveLocation();
+ liveLocation.setType(2);
+ String carnumber = maps.get(i).get("carnumber").toString();
+ liveLocation.setWorkerId(carnumber);
+ //经度
+ liveLocation.setLongitude(x);
+ //纬度
+ liveLocation.setLatitude(y);
+ Date date = timeStamp2Date(timestamp);
+ liveLocation.setRecordTime(date);
+ //先查询是否已有实时位置信息,如果有,则更新,没有则插入
+ 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);
+ }
}
} catch (Exception e) {
e.printStackTrace();
--
Gitblit v1.9.3