|
@@ -4,12 +4,18 @@ import com.platform.common.exception.BusinessException;
|
|
import com.platform.common.exception.DeniedException;
|
|
import com.platform.common.exception.DeniedException;
|
|
import com.platform.common.util.DateUtils;
|
|
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.StringUtils;
|
|
import com.platform.common.util.StringUtils;
|
|
|
|
+import com.ydl.iec.iec104.message.MessageDetail;
|
|
|
|
+import com.ydl.iec.iec104.message.MessageInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
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.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -56,23 +62,57 @@ public class MySqlUtil {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 更新遥测数据
|
|
|
|
- * @param positionNum
|
|
|
|
- * @param result
|
|
|
|
|
|
+ * 处理数据
|
|
|
|
+ *
|
|
|
|
+ * @param ruleDetail104
|
|
*/
|
|
*/
|
|
- public static void updateRemoteMeasureByPositionNum(Integer positionNum, String result) {
|
|
|
|
|
|
+ public static void dealMessage(MessageDetail ruleDetail104) {
|
|
|
|
+ LocalDateTime time = LocalDateTime.now();
|
|
|
|
+ int year = time.getYear();
|
|
|
|
+ int month = time.getMonthValue();
|
|
|
|
+ int day = time.getDayOfMonth();
|
|
|
|
+ int hour = time.getHour();
|
|
|
|
+ List<MessageInfo> addMessage = new ArrayList<>();
|
|
|
|
+ List<MessageInfo> updateMessage = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < ruleDetail104.getMeasgLength(); i++) {
|
|
|
|
+ MessageInfo messageInfo = ruleDetail104.getMessages().get(i);
|
|
|
|
+ if (messageInfo.getMessageAddress() >= remote_config_degree_min && messageInfo.getMessageAddress() <= remote_config_degree_max) {
|
|
|
|
+ addMessage.add(messageInfo);
|
|
|
|
+ } else if (messageInfo.getMessageAddress() >= remote_config_measure_min && messageInfo.getMessageAddress() <= remote_config_measure_max) {
|
|
|
|
+ updateMessage.add(messageInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 新增电度数据
|
|
|
|
+ if (!CollectionUtils.isEmpty(addMessage)) {
|
|
|
|
+ addBatch(addMessage, time, year, month, day, hour);
|
|
|
|
+ }
|
|
|
|
+ // 更新遥测数据
|
|
|
|
+ if (!CollectionUtils.isEmpty(addMessage)) {
|
|
|
|
+ updateBatch(updateMessage);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新遥测数据,批量更新
|
|
|
|
+ *
|
|
|
|
+ * @param list
|
|
|
|
+ */
|
|
|
|
+ public static void updateBatch(List<MessageInfo> list) {
|
|
Statement stmt = null;
|
|
Statement stmt = null;
|
|
- StringBuffer updateSql = new StringBuffer("update " + "t_remote_measure" + " set " +
|
|
|
|
- "result='" + result +
|
|
|
|
- "' where position_num=" + positionNum);
|
|
|
|
- log.info("更新数据:" + updateSql);
|
|
|
|
try {
|
|
try {
|
|
conn = getConnection();
|
|
conn = getConnection();
|
|
stmt = conn.createStatement();
|
|
stmt = conn.createStatement();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ MessageInfo messageInfo = list.get(i);
|
|
|
|
+ String updateSql = "update t_remote_measure set result='" + ByteUtil.byteArrayToHexString(messageInfo.getMessageInfos()) +
|
|
|
|
+ "' where position_num = " + messageInfo.getMessageAddress();
|
|
|
|
+ stmt.addBatch(updateSql);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 获取总条数
|
|
// 获取总条数
|
|
- int num = stmt.executeUpdate(updateSql.toString());
|
|
|
|
- if (num != 1) {
|
|
|
|
- throw new BusinessException("更新t_remote_measure失败,定位信息:" +positionNum );
|
|
|
|
|
|
+ int[] num = stmt.executeBatch();
|
|
|
|
+ if (num.length == 0) {
|
|
|
|
+ throw new BusinessException("批量更新t_remote_measure失败");
|
|
// 找不到定位数据,属于新增,则对应新增进入库,但是没有系数也不好处理
|
|
// 找不到定位数据,属于新增,则对应新增进入库,但是没有系数也不好处理
|
|
}
|
|
}
|
|
stmt.close();
|
|
stmt.close();
|
|
@@ -94,31 +134,43 @@ public class MySqlUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 记录电度数据-每一条新增保存
|
|
* 记录电度数据-每一条新增保存
|
|
- * @param positionNum
|
|
|
|
- * @param result
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param list
|
|
* @param time
|
|
* @param time
|
|
|
|
+ * @param year
|
|
|
|
+ * @param month
|
|
|
|
+ * @param day
|
|
|
|
+ * @param hour
|
|
*/
|
|
*/
|
|
- public static void addRemoteDegreeByPositionNum(Integer positionNum, String result, String time) {
|
|
|
|
|
|
+ public static void addBatch(List<MessageInfo> list, LocalDateTime time, Integer year, Integer month, Integer day, Integer hour) {
|
|
Statement stmt = null;
|
|
Statement stmt = null;
|
|
try {
|
|
try {
|
|
- if (StringUtils.isBlank(time)) {
|
|
|
|
- time = DateUtils.dateToString(LocalDateTime.now(), DateUtils.PATTERN_YMD_HMS);
|
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ MessageInfo messageInfo = list.get(i);
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append("insert into " + " t_remote_degree_log " +
|
|
|
|
+ " (id,position_num,year,month,day,hour,result,remark,created_time,created_user_id) values ");
|
|
|
|
+ sql.append("(");
|
|
|
|
+ sql.append("'" + IdGeneratorUtils.getObjectId() + "',");
|
|
|
|
+ sql.append("" + messageInfo.getMessageAddress() + ",");
|
|
|
|
+ sql.append("" + year + ",");
|
|
|
|
+ sql.append("" + month + ",");
|
|
|
|
+ sql.append("" + day + ",");
|
|
|
|
+ sql.append("" + hour + ",");
|
|
|
|
+ sql.append("'" + messageInfo + "',");
|
|
|
|
+ sql.append("'" + ByteUtil.byteArrayToHexString(messageInfo.getMessageInfos()) + "',");
|
|
|
|
+ sql.append("'" + DateUtils.dateToString(time, DateUtils.PATTERN_YMD_HMS) + "'");
|
|
|
|
+ sql.append("'" + 1 + "',");// 创建人
|
|
|
|
+ sql.append(")");
|
|
|
|
+ stmt.addBatch(sql.toString());
|
|
}
|
|
}
|
|
- StringBuffer sql = new StringBuffer();
|
|
|
|
- sql.append("insert into " + " t_remote_degree_log " +
|
|
|
|
- " (id,position_num,result,created_time) values ");
|
|
|
|
- sql.append("(");
|
|
|
|
- sql.append("'" + IdGeneratorUtils.getObjectId() + "',");
|
|
|
|
- sql.append("" + positionNum + ",");
|
|
|
|
- sql.append("'" + result + "',");
|
|
|
|
- sql.append("'" + time + "'");
|
|
|
|
- sql.append(")");
|
|
|
|
- log.info("----------" + sql.toString());
|
|
|
|
|
|
+
|
|
conn = getConnection();
|
|
conn = getConnection();
|
|
stmt = conn.createStatement();
|
|
stmt = conn.createStatement();
|
|
- stmt.executeUpdate(sql.toString());
|
|
|
|
|
|
+ stmt.executeBatch();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
@@ -134,17 +186,18 @@ public class MySqlUtil {
|
|
/**
|
|
/**
|
|
* 查询遥测最高最低点位
|
|
* 查询遥测最高最低点位
|
|
* 查询电度最高最低点位
|
|
* 查询电度最高最低点位
|
|
|
|
+ *
|
|
* @param type 1 遥测
|
|
* @param type 1 遥测
|
|
* 2 电度
|
|
* 2 电度
|
|
*/
|
|
*/
|
|
public static Map<String, Integer> selectRemotePositionMap(int type) {
|
|
public static Map<String, Integer> selectRemotePositionMap(int type) {
|
|
Statement stmt = null;
|
|
Statement stmt = null;
|
|
ResultSet rs = null;
|
|
ResultSet rs = null;
|
|
- Map<String, Integer> map= new HashMap<>();
|
|
|
|
- if(type==1){
|
|
|
|
|
|
+ Map<String, Integer> map = new HashMap<>();
|
|
|
|
+ if (type == 1) {
|
|
map.put("low", remote_config_measure_min);
|
|
map.put("low", remote_config_measure_min);
|
|
map.put("max", remote_config_measure_max);
|
|
map.put("max", remote_config_measure_max);
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
map.put("low", remote_config_degree_min);
|
|
map.put("low", remote_config_degree_min);
|
|
map.put("max", remote_config_degree_max);
|
|
map.put("max", remote_config_degree_max);
|
|
}
|
|
}
|
|
@@ -158,15 +211,15 @@ public class MySqlUtil {
|
|
rs = stmt.executeQuery(sql.toString());
|
|
rs = stmt.executeQuery(sql.toString());
|
|
rs.next();
|
|
rs.next();
|
|
String content = rs.getString(1);
|
|
String content = rs.getString(1);
|
|
- if(StringUtils.isBlank(content)){
|
|
|
|
|
|
+ if (StringUtils.isBlank(content)) {
|
|
log.error("点位最低最高未配置,将使用默认配置,请联系管理员配置,结构:遥测最低,遥测最高;电度最低,电度最高");
|
|
log.error("点位最低最高未配置,将使用默认配置,请联系管理员配置,结构:遥测最低,遥测最高;电度最低,电度最高");
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
String[] arr = content.split(";");
|
|
String[] arr = content.split(";");
|
|
- if(type==1){
|
|
|
|
|
|
+ if (type == 1) {
|
|
map.put("min", Integer.valueOf(arr[0].split(",")[0]));
|
|
map.put("min", Integer.valueOf(arr[0].split(",")[0]));
|
|
map.put("max", Integer.valueOf(arr[0].split(",")[1]));
|
|
map.put("max", Integer.valueOf(arr[0].split(",")[1]));
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
map.put("min", Integer.valueOf(arr[1].split(",")[0]));
|
|
map.put("min", Integer.valueOf(arr[1].split(",")[0]));
|
|
map.put("max", Integer.valueOf(arr[1].split(",")[1]));
|
|
map.put("max", Integer.valueOf(arr[1].split(",")[1]));
|
|
}
|
|
}
|
|
@@ -184,7 +237,7 @@ public class MySqlUtil {
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void handler(){
|
|
|
|
|
|
+ public static void handler() {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|