‘liusuyi’
2024-03-08 3db0172561e6b784cba42b6fcf7a68d3061995ea
雷达报警增加不存在井写入txt
已修改2个文件
65 ■■■■■ 文件已修改
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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();
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;
@@ -39,6 +40,7 @@
        }
        return map;
    }
    /**
     * 求Map<K,V>中最小 Value 对应的Key值
     *
@@ -53,6 +55,7 @@
//        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)
        {
        } catch (Exception ex) {
            log.error("光电切换获取通道异常:"+ex.getMessage());
            return 1;
        }
    }
    /**
     * 文件大小智能转换
     * 会将文件大小转换为最大满足单位
     *
     * @param size(文件大小,单位为B)
     * @return 文件大小
     */
@@ -105,9 +107,11 @@
        }
        return sizeName;
    }
    /**
     * 文件大小智能转换
     * 会将文件大小转换为最大满足单位
     *
     * @param size(文件大小,单位为B)
     * @return    文件大小
     */
@@ -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();
    }
    /**
     * 将数据写入txt文件
     * 刘苏义
     * 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();
        }
    }
}