From 20f693a9af9e90931ecb004700ec96453d05cecb Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Thu, 27 Jul 2023 10:31:37 +0800
Subject: [PATCH] fix: 远程数据提交修改
---
screen-job/src/main/resources/application-dev.yml | 3 +
screen-job/src/main/resources/application-qa.yml | 3 +
screen-job/src/main/java/com/moral/api/task/HistoryTableInsertTask.java | 11 +++++
screen-job/src/main/resources/application-cjl.yml | 4 +
screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java | 86 ++++++++++++++++--------------------------
screen-common/src/main/java/com/moral/constant/RedisConstants.java | 1
6 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/screen-common/src/main/java/com/moral/constant/RedisConstants.java b/screen-common/src/main/java/com/moral/constant/RedisConstants.java
index ec037ea..c07f1cf 100644
--- a/screen-common/src/main/java/com/moral/constant/RedisConstants.java
+++ b/screen-common/src/main/java/com/moral/constant/RedisConstants.java
@@ -104,4 +104,5 @@
public static final String AQI_ANNOUNCEMENT = "aqi_announcement";
+ public static final String DATE_CHANG_SHU = "date_changshu";
}
diff --git a/screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java b/screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
index 75d11e6..f89f726 100644
--- a/screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
+++ b/screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -23,13 +23,16 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.io.*;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -50,6 +53,8 @@
@Slf4j
public class HistoryHourlyServiceImpl implements HistoryHourlyService {
+ @Value("${result.date.changshu}")
+ private String dateChangShu;
@Autowired
private HistoryHourlyMapper historyHourlyMapper;
@@ -431,34 +436,27 @@
public void dateToChangShu(String time) {
//������������������������������
Date end = new Date();
+ List<String> stringList = Arrays.asList(dateChangShu.split(","));
String startTime = DateUtils.dateToDateString(DateUtils.addHours(end,-1),DateUtils.yyyy_MM_dd_HH_EN)+":00:00";
Map<String, Object> prop = new HashMap<>();
String timeUnits = DateUtils.dateToDateString(end, DateUtils.yyyyMM_EN);
prop.put("timeUnits", timeUnits);
prop.put("start", startTime);
prop.put("end", DateUtils.dateToDateString(end,DateUtils.yyyy_MM_dd_HH_EN)+":00:00");
- prop.put("list", Arrays.asList("p5dnd7a0245358"));
+ prop.put("list", stringList);
List<Map<String, Object>> dailyData = this.selectDailyData(prop);
String startTimeStr = DateUtils.dateToDateString(DateUtils.addHours(end,-1),"yyyyMMddHH")+"0000";
List<String> list = new ArrayList<>();
for(Map<String, Object> m : dailyData){
- list.add(strList(startTimeStr,m.get("mac").toString(),m.get("value").toString()));
+ String result = strList(startTimeStr,m.get("mac").toString(),m.get("value").toString());
+ list.add(result);
+ redisTemplate.opsForHash().put(RedisConstants.DATE_CHANG_SHU,m.get("mac").toString(),result);
}
// httpResult(list.get(0));
- sendSocket("222.92.166.238",15031,list.get(0));
- int i = 0;
- }
-
- public static void main(String[] args) {
- Date end = new Date();
- String startTime = DateUtils.dateToDateString(DateUtils.addHours(end,-1),DateUtils.yyyyMMddHHmmss_EN);
- String value = "{\"mac\": \"p5dnd7a0391978\", \"time\": 1690354822594, \"a00e03\": 1280.64, \"a00e04\": 4.49, \"a00e12\": 7473.89, \"a00e13\": 60.04, \"a01001\": 35.74, \"a01002\": 62.91, \"a01006\": 803.2987, \"a01007\": 0.93, \"a01008\": 141.69, \"a05024\": 140.89, \"a21001\": 0.13132, \"a21004\": 31.67, \"a21005\": 0.03161, \"a21026\": 118.09, \"a21028\": 0.00832, \"a31001\": 0, \"a34002\": 7.91, \"a34004\": 6.92, \"a99054\": 0.02583, \"a00e03-Flag\": \"N\", \"a00e04-Flag\": \"N\", \"a00e12-Flag\": \"N\", \"a00e13-Flag\": \"N\", \"a01001-Flag\": \"N\", \"a01002-Flag\": \"N\", \"a01006-Flag\": \"N\", \"a01007-Flag\": \"N\", \"a01008-Flag\": \"N\", \"a05024-Flag\": \"N\", \"a21001-Flag\": \"N\", \"a21004-Flag\": \"N\", \"a21005-Flag\": \"N\", \"a21026-Flag\": \"N\", \"a21028-Flag\": \"N\", \"a31001-Flag\": \"N\", \"a34002-Flag\": \"N\", \"a34004-Flag\": \"N\", \"a99054-Flag\": \"N\"}";
- String time = "2023-07-26 14:00:00.0";
- String mac = "p5dnd7a0391978";
- HistoryHourlyServiceImpl historyHourlyService = new HistoryHourlyServiceImpl();
- String s = historyHourlyService.strList(startTime,mac,value);
- historyHourlyService.httpResult(s);
- int i = 0;
+ for(String s : list){
+ sendSocket("222.92.166.238",15031,s);
+ }
+ log.info("������������");
}
private String strList(String startTime,String mn,String msg){
@@ -472,55 +470,37 @@
String mapKey = entry.getKey();
Object mapValue = entry.getValue();
if(mapKey.contains("e")){
- continue;
+ if(mapKey.contains("a00e12")||mapKey.contains("a00e13")){
+
+ }else {
+ continue;
+ }
+
}
if(!mapKey.contains("-Flag")){
+ if(mapKey.contains("a34002")||mapKey.contains("a34004")||mapKey.contains("a21026")||mapKey.contains("a21004")||mapKey.contains("a05024")){
+ Double d = Objects.nonNull(mapValue)?Double.valueOf(mapValue.toString())/1000:0d;
+ mapValue = d;
+ }
+ if(mapKey.contains("a00e13")){
+ mapKey = "a90085";
+ }
stringBuffer.append(mapKey+"-Avg=").append(mapValue+",").append(mapKey+"-Flag=N;");
}
+
}
}
stringBuffer.deleteCharAt(stringBuffer.length()-1);
stringBuffer.append("&&");
- String result = "QN=20230726160000001;ST=22;CN=2061;PW=123456;MN=P5DND7A0391978;CP=&&DataTime=20230726160000;a21005-Avg=0.03072,a21005-Flag=N;a21004-Avg=20.6,a21004-Flag=N;a21026-Avg=140.43,a21026-Flag=N;a21028-Avg=0.00778,a21028-Flag=N;a21001-Avg=0.13132,a21001-Flag=N;a01001-Avg=38.68,a01001-Flag=N;a05024-Avg=116.27,a05024-Flag=N;a01002-Avg=57.47,a01002-Flag=N;a01007-Avg=0.864,a01007-Flag=N;a01006-Avg=811.918,a01006-Flag=N;a01008-Avg=156.66,a01008-Flag=N;a34002-Avg=9.18,a34002-Flag=N;a34004-Avg=8.1,a34004-Flag=N;a99054-Avg=0.02283,a99054-Flag=N;a31001-Avg=0,a31001-Flag=N&&";
+ //String result = "QN=20230726160000001;ST=22;CN=2061;PW=123456;MN=P5DND7A0391978;CP=&&DataTime=20230726160000;a21005-Avg=0.03072,a21005-Flag=N;a21004-Avg=20.6,a21004-Flag=N;a21026-Avg=140.43,a21026-Flag=N;a21028-Avg=0.00778,a21028-Flag=N;a21001-Avg=0.13132,a21001-Flag=N;a01001-Avg=38.68,a01001-Flag=N;a05024-Avg=116.27,a05024-Flag=N;a01002-Avg=57.47,a01002-Flag=N;a01007-Avg=0.864,a01007-Flag=N;a01006-Avg=811.918,a01006-Flag=N;a01008-Avg=156.66,a01008-Flag=N;a34002-Avg=9.18,a34002-Flag=N;a34004-Avg=8.1,a34004-Flag=N;a99054-Avg=0.02283,a99054-Flag=N;a31001-Avg=0,a31001-Flag=N&&";
- //String result = qn+stringBuffer.toString();
+ String result = qn+stringBuffer.toString();
String s = Crc16Utils.padLeftTest(String.valueOf(result.length()),4,null);
String s1 = Crc16Utils.crc16_2017(result, result.length());
- return "##"+s+result+s1;
+ return "##"+s+result+s1+"\r\n";
}
- private void httpResult(String date){
- try {
- System.out.println(date);
- Socket socket = new Socket(InetAddress.getByName("127.0.0.1"),5656);
- OutputStream os = socket.getOutputStream();
- //������������
- os.write(date.getBytes());
-
-
- // ��������������������������������������� Socket ���������
- InputStream in = socket.getInputStream();
- byte[] buf = new byte[1024];
-
- int len = in.read(buf);
-
- String text = new String(buf, 0, len);
-
- System.out.println(text);
-
- socket.close();
-
-
-
-
-
- }catch (Exception e){
- System.out.println("������"+e.getMessage());
- }finally {
- System.out.println("������������");
- }
- }
private static String sendSocket(String host, Integer port, String message) {
log.debug("���������������{}������������{}������������{}", host, port, message);
Socket socket = null;
@@ -529,12 +509,12 @@
BufferedReader bufferedReader = null;
try {
socket = new Socket(host, port);
- socket.setSoTimeout(20000);
+ socket.setSoTimeout(3000);
// ������������������������������
outputStream = socket.getOutputStream();
outputStream.write(message.getBytes());
outputStream.flush();
-
+ socket.shutdownOutput();
inputStream = socket.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String readLen=bufferedReader.readLine();
diff --git a/screen-job/src/main/java/com/moral/api/task/HistoryTableInsertTask.java b/screen-job/src/main/java/com/moral/api/task/HistoryTableInsertTask.java
index 9f33024..635efde 100644
--- a/screen-job/src/main/java/com/moral/api/task/HistoryTableInsertTask.java
+++ b/screen-job/src/main/java/com/moral/api/task/HistoryTableInsertTask.java
@@ -105,4 +105,15 @@
}
return ReturnT.SUCCESS;
}
+
+ @XxlJob("dateToChangShu")
+ public ReturnT dateToChangShu(){
+ try {
+ historyHourlyService.dateToChangShu(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
+ }
+ return ReturnT.SUCCESS;
+ }
}
diff --git a/screen-job/src/main/resources/application-cjl.yml b/screen-job/src/main/resources/application-cjl.yml
index 60f3371..15dbe6d 100644
--- a/screen-job/src/main/resources/application-cjl.yml
+++ b/screen-job/src/main/resources/application-cjl.yml
@@ -106,4 +106,6 @@
logretentiondays: -1
-
+result:
+ date:
+ changshu: P5DND7A0245358,P5DND7A0245364,P5DND7A0245413,P5DND7A0245355,P5DND7A0245416,P5DND7A0245426,P5DND7A0245398,P5DND7A0245441,P5DND7A0245429,P5DND7A0245435,P5DND7A0245372,P5DND7A0245397,P5DND7A0245415,P5DND7A0245411,P5DND7A0245407,P5DND7A0245418,P5DND7A0245430,P5DND7A0245493,P5DND7A0245414,P5DND7A0245366,P5DND7A0245442,P5DND7A0245386,P5DND7A0245431,P5DND7A0245394,P5DND7A0245380,P5DND7A0245420,P5DND7A0245440,P5DND7A0245432,P5DND7A0391974,P5DND7A0391989,P5DND7A0245481,P5DND7A0392001,P5DND7A0391991,P5DND7A0391978
diff --git a/screen-job/src/main/resources/application-dev.yml b/screen-job/src/main/resources/application-dev.yml
index 9bb131f..78d25c5 100644
--- a/screen-job/src/main/resources/application-dev.yml
+++ b/screen-job/src/main/resources/application-dev.yml
@@ -106,4 +106,7 @@
logretentiondays: -1
+result:
+ date:
+ changshu: P5DND7A0245358,P5DND7A0245364,P5DND7A0245413,P5DND7A0245355,P5DND7A0245416,P5DND7A0245426,P5DND7A0245398,P5DND7A0245441,P5DND7A0245429,P5DND7A0245435,P5DND7A0245372,P5DND7A0245397,P5DND7A0245415,P5DND7A0245411,P5DND7A0245407,P5DND7A0245418,P5DND7A0245430,P5DND7A0245493,P5DND7A0245414,P5DND7A0245366,P5DND7A0245442,P5DND7A0245386,P5DND7A0245431,P5DND7A0245394,P5DND7A0245380,P5DND7A0245420,P5DND7A0245440,P5DND7A0245432,P5DND7A0391974,P5DND7A0391989,P5DND7A0245481,P5DND7A0392001,P5DND7A0391991,P5DND7A0391978
diff --git a/screen-job/src/main/resources/application-qa.yml b/screen-job/src/main/resources/application-qa.yml
index d52585e..fc456f6 100644
--- a/screen-job/src/main/resources/application-qa.yml
+++ b/screen-job/src/main/resources/application-qa.yml
@@ -106,5 +106,8 @@
#������������������������������������������������������������������������������������������������������3���������������������-1���������������
logretentiondays: -1
+result:
+ date:
+ changshu: P5DND7A0245358,P5DND7A0245364,P5DND7A0245413,P5DND7A0245355,P5DND7A0245416,P5DND7A0245426,P5DND7A0245398,P5DND7A0245441,P5DND7A0245429,P5DND7A0245435,P5DND7A0245372,P5DND7A0245397,P5DND7A0245415,P5DND7A0245411,P5DND7A0245407,P5DND7A0245418,P5DND7A0245430,P5DND7A0245493,P5DND7A0245414,P5DND7A0245366,P5DND7A0245442,P5DND7A0245386,P5DND7A0245431,P5DND7A0245394,P5DND7A0245380,P5DND7A0245420,P5DND7A0245440,P5DND7A0245432,P5DND7A0391974,P5DND7A0391989,P5DND7A0245481,P5DND7A0392001,P5DND7A0391991,P5DND7A0391978
--
Gitblit v1.8.0