From 0ce061d9ed37a6c25fff70e4734fa8cc8747237c Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Wed, 26 Jul 2023 19:45:09 +0800
Subject: [PATCH] fix: 部分提交
---
screen-job/pom.xml | 5 +
screen-job/src/main/java/com/moral/api/service/HistoryHourlyService.java | 4 +
screen-job/src/main/java/com/moral/api/controller/PubController.java | 10 +++
screen-job/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java | 129 ++++++++++++++++++++++++++++++++++++++++--
screen-job/src/main/resources/mapper/HistoryHourlyMapper.xml | 6 ++
5 files changed, 147 insertions(+), 7 deletions(-)
diff --git a/screen-job/pom.xml b/screen-job/pom.xml
index a22891e..e7d9d3b 100644
--- a/screen-job/pom.xml
+++ b/screen-job/pom.xml
@@ -19,6 +19,11 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
<groupId>org.moral</groupId>
<artifactId>screen-common</artifactId>
<version>1.0-SNAPSHOT</version>
diff --git a/screen-job/src/main/java/com/moral/api/controller/PubController.java b/screen-job/src/main/java/com/moral/api/controller/PubController.java
index 48e41a2..16805cd 100644
--- a/screen-job/src/main/java/com/moral/api/controller/PubController.java
+++ b/screen-job/src/main/java/com/moral/api/controller/PubController.java
@@ -3,6 +3,7 @@
import com.moral.api.service.HistoryAqiService;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryFiveMinutelyService;
+import com.moral.api.service.HistoryHourlyService;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
import io.swagger.annotations.Api;
@@ -36,6 +37,8 @@
@Autowired
private HistoryAqiService historyAqiService;
+ @Autowired
+ private HistoryHourlyService historyHourlyService;
@GetMapping("insertHistoryDaily")
@ApiOperation(value = "���������������", notes = "���������������")
@@ -67,6 +70,13 @@
return new ResultMessage();
}
+ @GetMapping("dateToChangShu")
+ @ApiOperation(value = "������������������", notes = "������������������")
+ public ResultMessage dateToChangShu() {
+ historyHourlyService.dateToChangShu(null);
+ return new ResultMessage();
+ }
+
public static void main(String[] args) {
String s = "2023-9-01";
diff --git a/screen-job/src/main/java/com/moral/api/service/HistoryHourlyService.java b/screen-job/src/main/java/com/moral/api/service/HistoryHourlyService.java
index 93dc956..4c248b4 100644
--- a/screen-job/src/main/java/com/moral/api/service/HistoryHourlyService.java
+++ b/screen-job/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -40,4 +40,8 @@
//���������������������������������������������������������������
void insertHistoryHourlyComplete();
+
+ void dateToChangShu(String time);
+
+
}
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 b6f156f..4f95534 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
@@ -1,5 +1,6 @@
package com.moral.api.service.impl;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.config.mybatis.MybatisPlusConfig;
@@ -17,18 +18,19 @@
import com.moral.util.MybatisPLUSUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.OptionalDouble;
-import java.util.Set;
+import java.io.*;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -44,6 +46,7 @@
* @since 2021-06-28
*/
@Service
+@Slf4j
public class HistoryHourlyServiceImpl implements HistoryHourlyService {
@Autowired
@@ -422,4 +425,116 @@
}
return null;
}
+
+ @Override
+ public void dateToChangShu(String time) {
+ //������������������������������
+ Date end = new Date();
+ 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"));
+ 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()));
+ }
+ // 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();
+ historyHourlyService.strList(startTime,mac,value);
+ }
+
+ private String strList(String startTime,String mn,String msg){
+ String qn = "QN="+ startTime + "001;ST=22;CN=2061;PW=123456;MN="+mn.toUpperCase()+";CP=&&DataTime="+startTime+";";
+ Map<String, Object> data = JSON.parseObject(msg, Map.class);
+ StringBuffer stringBuffer = new StringBuffer();
+ if(data.size()>0){
+ data.remove("mac");
+ data.remove("time");
+ for(Map.Entry<String, Object> entry : data.entrySet()){
+ String mapKey = entry.getKey();
+ Object mapValue = entry.getValue();
+ if(mapKey.contains("e")){
+ continue;
+ }
+ if(!mapKey.contains("-Flag")){
+ stringBuffer.append(mapKey+"-Avg=").append(mapValue+",").append(mapKey+"-Flag=N;");
+ }
+ }
+ }
+ stringBuffer.deleteCharAt(stringBuffer.length()-1);
+ stringBuffer.append("&&");
+ return qn+stringBuffer.toString();
+ }
+
+ private void httpResult(String date){
+ try {
+ System.out.println(date);
+ Socket socket = new Socket(InetAddress.getByName("222.92.166.238"),15031);
+ OutputStream os = socket.getOutputStream();
+ //������������
+ os.write(date.getBytes());
+ os.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;
+ OutputStream outputStream = null;
+ InputStream inputStream = null;
+ BufferedReader bufferedReader = null;
+ try {
+ socket = new Socket(host, port);
+ socket.setSoTimeout(20000);
+ // ������������������������������
+ outputStream = socket.getOutputStream();
+ outputStream.write(message.getBytes(StandardCharsets.UTF_8));
+ outputStream.flush();
+
+ inputStream = socket.getInputStream();
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
+ String readLen=bufferedReader.readLine();
+ log.debug("���������������{}", readLen);
+ return readLen;
+ } catch (IOException e) {
+ log.error("socket���������������{}", e.toString());
+ } finally {
+ try {
+ if(bufferedReader != null){
+ bufferedReader.close();
+ }
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ if (socket != null) {
+ socket.close();
+ }
+ } catch (IOException e) {
+ log.error("socket���������������{}", e.toString());
+ }
+ }
+ return null;
+ }
+
}
diff --git a/screen-job/src/main/resources/mapper/HistoryHourlyMapper.xml b/screen-job/src/main/resources/mapper/HistoryHourlyMapper.xml
index 40ac177..56024a1 100644
--- a/screen-job/src/main/resources/mapper/HistoryHourlyMapper.xml
+++ b/screen-job/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -40,6 +40,12 @@
FROM history_hourly_${timeUnits}
WHERE `time` <![CDATA[>=]]> #{start}
AND `time` <![CDATA[<]]> #{end}
+ <if test="list != null and list.size()!=0">
+ and mac in
+ <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
+ #{item}
+ </foreach>
+ </if>
</select>
<insert id="insertHistoryHourlyComplete">
--
Gitblit v1.8.0