From 8853292babb2ad94de4a3207966f1e83b767cd2d Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Sun, 17 Sep 2023 16:38:34 +0800
Subject: [PATCH] 新增流程节点进程查询接口

---
 src/main/java/org/springblade/modules/equipage/controller/fixed.java |  336 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 177 insertions(+), 159 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 74f46ea..f71eceb 100644
--- a/src/main/java/org/springblade/modules/equipage/controller/fixed.java
+++ b/src/main/java/org/springblade/modules/equipage/controller/fixed.java
@@ -1,21 +1,19 @@
 package org.springblade.modules.equipage.controller;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.alibaba.fastjson.JSON;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONException;
 import net.sf.json.JSONObject;
 import org.springblade.common.utils.HttpReqUtil;
 import org.springblade.common.utils.Md5SignUtil;
-import org.springblade.core.mp.support.Condition;
-import org.springblade.core.tool.api.R;
 import org.springblade.modules.FTP.FtpUtil;
 import org.springblade.modules.equipage.service.CarService;
 import org.springblade.modules.location.entity.LiveLocation;
 import org.springblade.modules.location.entity.Locus;
 import org.springblade.modules.location.service.LiveLocationService;
 import org.springblade.modules.location.service.LocusService;
-import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IUserService;
+import org.springblade.modules.system.service.MyAsyncService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -26,7 +24,7 @@
 import java.text.SimpleDateFormat;
 import java.util.*;
 
-@Component
+@Component("fixed")
 public class fixed {
 	private static final DateFormat JSON = null;
 	@Autowired
@@ -37,6 +35,8 @@
 	private LocusService locusService;
 	@Autowired
 	private CarService carService;
+	@Autowired
+	private MyAsyncService myAsyncService;
 
 	/**
 	 * 押运人员
@@ -44,88 +44,92 @@
 	 * @return
 	 * @throws Exception
 	 */
-	@Scheduled(cron = "0 */5 * * * ?")
+//	@Scheduled(cron = "0 */5 * * * ?")
 	public void Peo() throws Exception {
 		String url = "http://47.104.104.46/api/client/getgis.php";
 		//查询有押运人员的数据
 		List<Map<String, Object>> list = userService.selectEquipent();
-		for (int i = 0; i < list.size(); i++) {
-			//实时位置实体类
-			LiveLocation liveLocation = new LiveLocation();
-			liveLocation.setType(1);
-			String id = list.get(i).get("id").toString();
-			liveLocation.setWorkerId(id);
-			Map<String, Object> params = new HashMap<>();
-			String equipmentCode = list.get(i).get("code").toString();
-			//设备imei号
-			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);
+		if (list.size() > 0) {
+			for (int i = 0; i < list.size(); i++) {
+				//实时位置实体类
+				LiveLocation liveLocation = new LiveLocation();
+				liveLocation.setType(1);
+				String id = list.get(i).get("id").toString();
+				liveLocation.setWorkerId(id);
+				Map<String, Object> params = new HashMap<>();
+				String equipmentCode = list.get(i).get("code").toString();
+				//设备imei号
+				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));
 				}
-			});
-			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,location) " +
-						"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);
+					myAsyncService.dataSync(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);
+					myAsyncService.dataSync(s1);
+				}
 			}
 		}
 	}
@@ -136,8 +140,9 @@
 	 * @return
 	 * @throws Exception
 	 */
-	@Scheduled(cron = "0 0 * * * ?")
+//	@Scheduled(cron = "0 0 * * * ?")
 	public void Peog() throws Exception {
+		System.out.println("押运人员");
 		String url = "http://47.104.104.46/api/client/getgistrack.php";
 		Calendar calendar = Calendar.getInstance();
 		calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
@@ -163,36 +168,41 @@
 			JSONArray jsonArray = JSONArray.fromObject(a);
 			String s1 = "";
 			String track = jsonArray.getJSONObject(0).get("track").toString();
-			JSONArray jsonArray1 = JSONArray.fromObject(track);
-			for (int j = 0; j < jsonArray1.size(); j++) {
-				String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
-				String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
-				String date = jsonArray1.getJSONObject(j).get("date").toString();
-				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-				try {
-					//使用SimpleDateFormat的parse()方法生成Date
-					Date dates = sf.parse(date);
-					locus.setRecordTime(dates);
-					//打印Date
-				} catch (ParseException e) {
-					e.printStackTrace();
+			if (track.equals("[]")) {
+				System.out.println("数据为空");
+			} else {
+				JSONArray jsonArray1 = JSONArray.fromObject(track);
+				for (int j = 0; j < jsonArray1.size(); j++) {
+					String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
+					String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
+					String date = jsonArray1.getJSONObject(j).get("date").toString();
+					SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+					try {
+						//使用SimpleDateFormat的parse()方法生成Date
+						Date dates = sf.parse(date);
+						locus.setRecordTime(dates);
+						//打印Date
+					} catch (ParseException e) {
+						e.printStackTrace();
+					}
+					locus.setLongitude(gis_jd);
+					locus.setLatitude(gis_wd);
+					locusService.save(locus);
+					//数据推送
+					s1 += "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values" +
+						" (" + "'" + locus.getId() + "'" + "," +
+						"'" + locus.getType() + "'" + "," +
+						"'" + locus.getWorkerId() + "'" + "," +
+						"'" + locus.getLongitude() + "'" + "," +
+						"'" + locus.getLatitude() + "'" + "," +
+						"'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
+					if (j != jsonArray1.size() - 1) {
+						s1 += ";";
+					}
 				}
-				locus.setLongitude(gis_jd);
-				locus.setLatitude(gis_wd);
-				locusService.save(locus);
-				//数据推送
-				s1 += "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values" +
-					" (" + "'" + locus.getId() + "'" + "," +
-					"'" + locus.getType() + "'" + "," +
-					"'" + locus.getWorkerId() + "'" + "," +
-					"'" + locus.getLongitude() + "'" + "," +
-					"'" + locus.getLatitude() + "'" + "," +
-					"'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
-				if (j != jsonArray1.size() - 1) {
-					s1 += ";";
-				}
+				//FtpUtil.sqlFileUpload(s1);
+				myAsyncService.dataSync(s1);
 			}
-			FtpUtil.sqlFileUpload(s1);
 		}
 	}
 
@@ -200,7 +210,7 @@
 	/**
 	 * 车辆实时位置
 	 */
-	@Scheduled(cron = "0 */5 * * * ?")
+//	@Scheduled(cron = "0 */5 * * * ?")
 	public void locationcar() {
 		String url = "http://dvopenapi.aimap.net.cn/openapi/device/location";
 		String res = null;
@@ -222,50 +232,59 @@
 				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,location) " +
-							"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);
+						if (status) {
+							//数据推送
+							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);
+							myAsyncService.dataSync(s1);
+						}
+					} else {
+						status = liveLocationService.updateById(liveLocationInfo);
+						//内网同步
+						if (status) {
+							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);
+							myAsyncService.dataSync(s1);
+						}
+					}
 				}
 			} catch (Exception e) {
 				e.printStackTrace();
@@ -290,9 +309,8 @@
 	/**
 	 * 查询车辆轨迹
 	 */
-	@Scheduled(cron = "0 0 * * * ?")
+//	@Scheduled(cron = "0 0 * * * ?")
 	public void locationhistoryTrack() {
-		System.out.println("车辆轨迹");
 		Calendar calendar = Calendar.getInstance();
 		/* HOUR_OF_DAY 指示一天中的小时 */
 		calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
@@ -306,7 +324,7 @@
 			params.put("beginTime", df.format(calendar.getTime()));
 			params.put("endTime", df.format(new Date()));
 			params.put("rectify", 0);
-			params.put("callbackUrl", "http://223.82.109.183:2080/api/locus/SaveUrl");
+			params.put("callbackUrl", "http://61.131.136.25:2080/api/locus/SaveUrl");
 			params.put("callbackId", maps.get(i).get("carnumber").toString());
 			params.put("appId", "PO00000761");
 			params.put("timestamp", System.currentTimeMillis());

--
Gitblit v1.9.3