From 3db0172561e6b784cba42b6fcf7a68d3061995ea Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 08 三月 2024 13:55:02 +0800
Subject: [PATCH] 雷达报警增加不存在井写入txt
---
ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java | 66 ++++++++++++++++++++++++++++----
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java | 7 +++
2 files changed, 63 insertions(+), 10 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
index 2762f49..73831f6 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
@@ -53,9 +53,12 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
+import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
+
+import static com.ruoyi.utils.tools.ArdTool.writeStringToFile;
/**
@@ -1067,7 +1070,9 @@
String alarmpointName = ardAlarmRadar.getName();//鍏磋叮鐐瑰悕绉�
ArdAlarmpointsWell well = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
if (well == null) {
- return;
+ String path=System.getProperty("user.dir") + File.separator +"noExistWell.txt";
+ writeStringToFile(alarmpointName,path);
+ continue;
}
Double longitude = well.getLongitude();
diff --git a/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java b/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
index 674b0de..f2185bb 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
@@ -2,6 +2,7 @@
import lombok.extern.slf4j.Slf4j;
+import java.io.*;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.time.LocalTime;
@@ -20,7 +21,7 @@
/**
* @鎻忚堪 瀹炰綋瀵硅薄杞琈ap
* @鍙傛暟 [entity]
- * @杩斿洖鍊� java.util.Map<java.lang.String,java.lang.Object>
+ * @杩斿洖鍊� java.util.Map<java.lang.String, java.lang.Object>
* @鍒涘缓浜� 鍒樿嫃涔�
* @鍒涘缓鏃堕棿 2023/6/2 14:35
* @淇敼浜哄拰鍏跺畠淇℃伅
@@ -39,6 +40,7 @@
}
return map;
}
+
/**
* 姹侻ap<K,V>涓渶灏� Value 瀵瑰簲鐨凨ey鍊�
*
@@ -46,13 +48,14 @@
* @return
*/
public static String getKeyByMinValue(Map<String, Double> map) {
- if (map == null||map.size()==0) return null;
+ if (map == null || map.size() == 0) return null;
List<Map.Entry<String, Double>> list = new ArrayList(map.entrySet());
Collections.sort(list, (o1, o2) -> (o1.getValue().intValue() - o2.getValue().intValue()));
String min = list.get(0).getKey();
// String max = list.get(list.size() - 1).getKey();
return min;
}
+
/**
* @鎻忚堪 閫氳繃鏃ュ鍒囨崲鏃堕棿鍒ゆ柇褰撳墠浣跨敤閫氶亾鍙�
* @鍙傛暟 []
@@ -61,8 +64,7 @@
* @鍒涘缓鏃堕棿 2023/6/17 13:50
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
- public static Integer getChannelBydayNightTime(String dayNightTime)
- {
+ public static Integer getChannelBydayNightTime(String dayNightTime) {
try {
// 鑾峰彇褰撳墠鏃堕棿
LocalTime currentTime = LocalTime.now();
@@ -79,16 +81,16 @@
} else {
return 2;
}
- }
- catch (Exception ex)
- {
- log.error("鍏夌數鍒囨崲鑾峰彇閫氶亾寮傚父锛�"+ex.getMessage());
+ } catch (Exception ex) {
+ log.error("鍏夌數鍒囨崲鑾峰彇閫氶亾寮傚父锛�" + ex.getMessage());
return 1;
}
}
+
/**
* 鏂囦欢澶у皬鏅鸿兘杞崲
* 浼氬皢鏂囦欢澶у皬杞崲涓烘渶澶ф弧瓒冲崟浣�
+ *
* @param size锛堟枃浠跺ぇ灏忥紝鍗曚綅涓築锛�
* @return 鏂囦欢澶у皬
*/
@@ -105,11 +107,13 @@
}
return sizeName;
}
+
/**
* 鏂囦欢澶у皬鏅鸿兘杞崲
* 浼氬皢鏂囦欢澶у皬杞崲涓烘渶澶ф弧瓒冲崟浣�
+ *
* @param size锛堟枃浠跺ぇ灏忥紝鍗曚綅涓築锛�
- * @return 鏂囦欢澶у皬
+ * @return 鏂囦欢澶у皬
*/
public static String readableFileSize(long size) {
if (size <= 0) {
@@ -124,6 +128,7 @@
* byte鏁扮粍杞瓧绗︿覆
* 鍒樿嫃涔�
* 2023/10/18 8:42:59
+ *
* @param byteArray
*/
public static String byteArrayToString(byte[] byteArray) {
@@ -133,4 +138,47 @@
}
return stringBuilder.toString();
}
+
+ /**
+ * 灏嗘暟鎹啓鍏xt鏂囦欢
+ * 鍒樿嫃涔�
+ * 2024/3/8 12:58:39
+ */
+ public static void writeStringToFile(String data, String fileName) {
+
+ try {
+ File file = new File(fileName);
+ boolean fileExists = file.exists();
+ boolean dataExists = false;
+ if(fileExists) {
+ // 璇诲彇鏂囦欢鍐呭
+ BufferedReader reader = new BufferedReader(new FileReader(fileName));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if (line.equals(data)) {
+ dataExists = true;
+ break;
+ }
+ }
+ reader.close();
+ }
+
+ // 濡傛灉鏂囦欢涓嶅瓨鍦ㄦ垨鏁版嵁涓嶅瓨鍦紝鍒欒拷鍔犲埌鏂囦欢
+ if (!fileExists || !dataExists) {
+ FileWriter writer = new FileWriter(fileName, true);
+ writer.write(data + System.lineSeparator());
+ writer.close();
+ if (!fileExists) {
+ log.debug("File created and data has been appended.");
+ } else {
+ log.debug("Data has been appended to the file.");
+ }
+ } else {
+ log.debug("Data already exists in the file. Not appending.");
+ }
+ } catch (IOException e) {
+ log.error("An error occurred.");
+ e.printStackTrace();
+ }
+ }
}
--
Gitblit v1.9.3