|
@@ -7,6 +7,9 @@ import com.platform.common.util.DateUtils;
|
|
import com.platform.common.util.IdGeneratorUtils;
|
|
import com.platform.common.util.IdGeneratorUtils;
|
|
import com.platform.common.util.SecurityUtils;
|
|
import com.platform.common.util.SecurityUtils;
|
|
import com.platform.common.util.StringUtils;
|
|
import com.platform.common.util.StringUtils;
|
|
|
|
+import com.platform.dao.vo.query.qykh.HotspotHelpVO;
|
|
|
|
+import com.platform.dao.vo.sb.SbInfoScreenDetailVO;
|
|
|
|
+import com.ydl.iec.iec104.core.Iec104ThreadLocal;
|
|
import com.ydl.iec.iec104.message.MessageDetail;
|
|
import com.ydl.iec.iec104.message.MessageDetail;
|
|
import com.ydl.iec.iec104.message.MessageInfo;
|
|
import com.ydl.iec.iec104.message.MessageInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -16,27 +19,25 @@ import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.sql.*;
|
|
import java.sql.*;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
public class MySqlUtil {
|
|
public class MySqlUtil {
|
|
//是否连接数据库
|
|
//是否连接数据库
|
|
public static String mysql_open = "false";
|
|
public static String mysql_open = "false";
|
|
//数据库连接地址
|
|
//数据库连接地址
|
|
- //public static String mysql_url = "jdbc:mysql://123.60.19.203:5006/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
|
|
|
|
|
|
+ public static String mysql_url = "jdbc:mysql://123.60.19.203:5006/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
|
|
//用户名
|
|
//用户名
|
|
- //public static String mysql_username = "root";
|
|
|
|
|
|
+ public static String mysql_username = "root";
|
|
//密码
|
|
//密码
|
|
- //public static String mysql_password = "mysql?MYSQLmoniu123";
|
|
|
|
|
|
+ public static String mysql_password = "mysql?MYSQLmoniu123";
|
|
//数据库连接地址
|
|
//数据库连接地址
|
|
- public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
|
|
|
|
|
|
+ //public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
|
|
//用户名
|
|
//用户名
|
|
- public static String mysql_username = "root";
|
|
|
|
|
|
+ //public static String mysql_username = "root";
|
|
//密码
|
|
//密码
|
|
- public static String mysql_password = "mydm888";
|
|
|
|
|
|
+ //public static String mysql_password = "mydm888";
|
|
//驱动名称
|
|
//驱动名称
|
|
public static String mysql_driver = "com.mysql.cj.jdbc.Driver";
|
|
public static String mysql_driver = "com.mysql.cj.jdbc.Driver";
|
|
// 采集数据,结构:遥测最低,遥测最高;电度最低,电度最高
|
|
// 采集数据,结构:遥测最低,遥测最高;电度最低,电度最高
|
|
@@ -76,7 +77,7 @@ public class MySqlUtil {
|
|
* @param ruleDetail104
|
|
* @param ruleDetail104
|
|
*/
|
|
*/
|
|
public static void dealMessage(MessageDetail ruleDetail104) {
|
|
public static void dealMessage(MessageDetail ruleDetail104) {
|
|
- log.info("处理数据中……………………");
|
|
|
|
|
|
+ // log.info("处理数据中……………………");
|
|
LocalDateTime time = LocalDateTime.now();
|
|
LocalDateTime time = LocalDateTime.now();
|
|
int year = time.getYear();
|
|
int year = time.getYear();
|
|
int month = time.getMonthValue();
|
|
int month = time.getMonthValue();
|
|
@@ -159,6 +160,90 @@ public class MySqlUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询电度数量
|
|
|
|
+ */
|
|
|
|
+ public static int selectCountDegree() {
|
|
|
|
+ PreparedStatement ps = null;
|
|
|
|
+ int count = 0;
|
|
|
|
+ try {
|
|
|
|
+ conn = getConnection();
|
|
|
|
+ String selectSql = "select count(*) from t_remote_degree";
|
|
|
|
+ ps = conn.prepareStatement(selectSql);
|
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
|
+ if (rs.next()) {
|
|
|
|
+ count = rs.getInt(1);
|
|
|
|
+ }
|
|
|
|
+ ps.close();
|
|
|
|
+ closeConn();
|
|
|
|
+ return count;
|
|
|
|
+ } catch (SQLException e1) {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ throw new DeniedException("获取乾元数据库连接失败" + e1.getCause().getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (ps != null) {
|
|
|
|
+ ps.close();
|
|
|
|
+ }
|
|
|
|
+ if (conn != null) {
|
|
|
|
+ closeConn();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询电度在当前小时内是否存在
|
|
|
|
+ */
|
|
|
|
+ public static List<Integer> selectExistDegree(int year, int month, int day, int hour, List<Integer> positionNumList) {
|
|
|
|
+ PreparedStatement ps = null;
|
|
|
|
+ try {
|
|
|
|
+ conn = getConnection();
|
|
|
|
+ StringBuffer selectSql = new StringBuffer("select position_num from t_remote_degree_log where ");
|
|
|
|
+ if(CollectionUtils.isEmpty(positionNumList)){
|
|
|
|
+ selectSql.append(" year = " + year);
|
|
|
|
+ }else{
|
|
|
|
+ selectSql.append(" position_num in ( ");
|
|
|
|
+ for (int i = 0; i < positionNumList.size(); i++) {
|
|
|
|
+ if (i == positionNumList.size() - 1) {
|
|
|
|
+ selectSql.append(positionNumList.get(i) + ") ");
|
|
|
|
+ } else {
|
|
|
|
+ selectSql.append(positionNumList.get(i) + ", ");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ selectSql.append(" and year = " + year);
|
|
|
|
+ }
|
|
|
|
+ selectSql.append(" and month = " + month);
|
|
|
|
+ selectSql.append(" and day = " + day);
|
|
|
|
+ selectSql.append(" and hour = " + hour);
|
|
|
|
+ System.out.println(selectSql.toString());
|
|
|
|
+ ps = conn.prepareStatement(selectSql.toString());
|
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
|
+ while (rs.next()) {
|
|
|
|
+ list.add(rs.getInt(1));
|
|
|
|
+ }
|
|
|
|
+ ps.close();
|
|
|
|
+ closeConn();
|
|
|
|
+ return list;
|
|
|
|
+ } catch (SQLException e1) {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ throw new DeniedException("获取乾元数据库连接失败" + e1.getCause().getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (ps != null) {
|
|
|
|
+ ps.close();
|
|
|
|
+ }
|
|
|
|
+ if (conn != null) {
|
|
|
|
+ closeConn();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 记录电度数据-每一条新增保存
|
|
* 记录电度数据-每一条新增保存
|
|
@@ -171,6 +256,7 @@ public class MySqlUtil {
|
|
* @param hour
|
|
* @param hour
|
|
*/
|
|
*/
|
|
public static void addBatch(List<MessageInfo> list, LocalDateTime time, Integer year, Integer month, Integer day, Integer hour, Integer minute) {
|
|
public static void addBatch(List<MessageInfo> list, LocalDateTime time, Integer year, Integer month, Integer day, Integer hour, Integer minute) {
|
|
|
|
+ List<Integer> checkList = selectExistDegree(year, month, day, hour, list.stream().map(MessageInfo::getMessageAddress).collect(Collectors.toList()));
|
|
PreparedStatement ps = null;
|
|
PreparedStatement ps = null;
|
|
try {
|
|
try {
|
|
String sql = "insert into t_remote_degree_log (id,position_num,year,month,day,hour,minute,result,info,created_time,created_user_id) values (?,?,?,?,?,?,?,?,?,?,?)";
|
|
String sql = "insert into t_remote_degree_log (id,position_num,year,month,day,hour,minute,result,info,created_time,created_user_id) values (?,?,?,?,?,?,?,?,?,?,?)";
|
|
@@ -178,6 +264,10 @@ public class MySqlUtil {
|
|
ps = conn.prepareStatement(sql);
|
|
ps = conn.prepareStatement(sql);
|
|
for (int i = 0; i < list.size(); i++) {
|
|
for (int i = 0; i < list.size(); i++) {
|
|
MessageInfo messageInfo = list.get(i);
|
|
MessageInfo messageInfo = list.get(i);
|
|
|
|
+ if (checkList.contains(messageInfo.getMessageAddress())) {
|
|
|
|
+ log.info("点位已存在,不处理。" + year + ", " + month + ", " + day + ", " + hour + ", " + messageInfo.getMessageAddress());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
ps.setObject(1, IdGeneratorUtils.getObjectId());
|
|
ps.setObject(1, IdGeneratorUtils.getObjectId());
|
|
ps.setObject(2, messageInfo.getMessageAddress());
|
|
ps.setObject(2, messageInfo.getMessageAddress());
|
|
ps.setObject(3, year);
|
|
ps.setObject(3, year);
|
|
@@ -300,8 +390,16 @@ public class MySqlUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
- String str = "68FA020002000D1E140001000140000000000000024000000000000003400000000000000440000000000000054000000000000006400000000000000740000000000000084000000000000009400000000000000A400000000000000B400000000000000C400000000000000D400000000000000E400000000000000F4000000000000010400000000000001140000000000000124000000000000013400000000000001440000000000000154000000000000016400000000000001740000000000000184000000000000019400000000000001A400000000000001B400000000000001C400000000000001D400000000000001E40000000000000";
|
|
|
|
- System.out.println(ByteUtil.testStr(str));
|
|
|
|
|
|
+ List<Integer> result = selectExistDegree(2022, 11, 25, 22, Arrays.asList(25601, 25602, 25603));
|
|
|
|
+ for (Integer ss : result) {
|
|
|
|
+ System.out.println("ss: " + ss);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("result: " + result.contains(25601));
|
|
|
|
+ List<Integer> result1 = selectExistDegree(2022, 11, 25, 22, null);
|
|
|
|
+ for (Integer ss : result1) {
|
|
|
|
+ System.out.println("ss: " + ss);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("result: " + result1.contains(25601));
|
|
}
|
|
}
|
|
|
|
|
|
private static float changeMeassInfosToFloat(byte[] bytes) {
|
|
private static float changeMeassInfosToFloat(byte[] bytes) {
|