治理设备新增模块状态查询功能
This commit is contained in:
@@ -1,14 +1,39 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.csdevice.CsDeviceBootApplication;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest(classes = CsDeviceBootApplication.class)
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class AppTest{
|
||||
|
||||
@Autowired
|
||||
private DeviceFtpService deviceFtpService;
|
||||
|
||||
@Autowired
|
||||
private ICsCommunicateService csCommunicateService;
|
||||
|
||||
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@@ -17,4 +42,35 @@ public class AppTest
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void downloadFileTest() {
|
||||
String nDid = "00B78D016AB5";
|
||||
String name = "/etc/pqs_arm.bin";
|
||||
Integer size = 5123552;
|
||||
String fileCheck = "859E36E8";
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log.info("开始第{}次", i);
|
||||
deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||
Thread.sleep(1000 * 60 * 4);
|
||||
log.info("这是第{}次询问装置,结果为:{}", i, null);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void writeData() {
|
||||
PqsCommunicateDto pqsCommunicateDto = new PqsCommunicateDto();
|
||||
pqsCommunicateDto.setTime("2024-01-01 00:00:00");
|
||||
pqsCommunicateDto.setDevId("da7aa071bf89864bedea8833133676b7");
|
||||
pqsCommunicateDto.setType(1);
|
||||
pqsCommunicateDto.setDescription("通讯连接");
|
||||
csCommunicateService.insertion(pqsCommunicateDto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.csdevice.CsDeviceBootApplication;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest(classes = CsDeviceBootApplication.class)
|
||||
public class BaseJunitTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
double num1 = 123.456;
|
||||
double num2 = 123.4;
|
||||
double num3 = 123.0;
|
||||
|
||||
System.out.println(roundToTwoDecimalPlaces(num1)); // 输出: 123.46
|
||||
System.out.println(roundToTwoDecimalPlaces(num2)); // 输出: 123.40
|
||||
System.out.println(roundToTwoDecimalPlaces(num3)); // 输出: 123.00
|
||||
}
|
||||
|
||||
public static double roundToTwoDecimalPlaces(double num) {
|
||||
// 乘以100,然后四舍五入,再除以100
|
||||
return Math.round(num * 100.0) / 100.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.njcn;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.influx.imapper.EvtDataMapper;
|
||||
import com.njcn.influx.imapper.PqsCommunicateMapper;
|
||||
import com.njcn.influx.pojo.po.PqsCommunicate;
|
||||
import com.njcn.influx.pojo.po.cs.EntData;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
public class DownloadFileTest extends BaseJunitTest{
|
||||
|
||||
@Autowired
|
||||
private DeviceFtpService deviceFtpService;
|
||||
|
||||
@Autowired
|
||||
private FileStorageUtil fileStorageUtil;
|
||||
@Autowired
|
||||
private EvtDataMapper evtDataMapper;
|
||||
@Autowired
|
||||
private PqsCommunicateMapper pqsCommunicateMapper;
|
||||
private final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
||||
|
||||
/**
|
||||
* inflxudb写入
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void addInfluxdb() {
|
||||
PqsCommunicateDto pqsCommunicate = new PqsCommunicateDto();
|
||||
pqsCommunicate.setTime("2025-06-23 ");
|
||||
pqsCommunicate.setDevId("da7aa071bf89864bedea8833133676b7");
|
||||
pqsCommunicate.setType(1);
|
||||
pqsCommunicate.setDescription("设备上线");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void downloadFileTest() {
|
||||
String nDid = "00B78D016AB3";
|
||||
String name = "/etc/pqs_arm.bin";
|
||||
Integer size = 5127376;
|
||||
String fileCheck = "E883C579";
|
||||
String filePath = "C:\\Users\\徐扬\\Desktop\\download.txt";
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println("开始第"+i+"次");
|
||||
deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||
String dataToAppend = LocalDateTime.now() + "开始下载,这是第"+i+"次,结果为:" + null + "\r\n";
|
||||
// 第二个参数为 true 表示追加模式
|
||||
try (FileWriter fileWriter = new FileWriter(filePath, true)) {
|
||||
fileWriter.write(dataToAppend); // 写入数据
|
||||
System.out.println("数据已成功追加到文件中。");
|
||||
} catch (IOException e) {
|
||||
System.err.println("写入文件时发生错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void moveFile() {
|
||||
String oldPath = "/db0/cmn/07/min/20240925/line2_avg.bin";
|
||||
StringBuilder result = null;
|
||||
String[] arr = oldPath.split("/");
|
||||
for (String s : arr) {
|
||||
s = s + File.separator;
|
||||
}
|
||||
System.out.println("result==:" + result);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String nDid = "00B78D016AB3";
|
||||
String oldPath = "/db0/cmn/07/min/20240925/line2_avg.bin";
|
||||
String path = getFilePath(oldPath,nDid);
|
||||
System.out.println("path==:" + path);
|
||||
}
|
||||
|
||||
private static String getFilePath(String path, String nDid) {
|
||||
String[] parts = path.split("/");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int i = 3; i < parts.length; i++) {
|
||||
if (!first) {
|
||||
sb.append(File.separator);
|
||||
}
|
||||
sb.append(parts[i]);
|
||||
first = false;
|
||||
}
|
||||
|
||||
return nDid + File.separator + sb.toString();
|
||||
}
|
||||
|
||||
// private static String getFilePath(String path, String nDid) {
|
||||
// path = nDid + "/" + path;
|
||||
// String[] parts = path.split("/");
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// boolean first = true;
|
||||
// for (int i = 4; i < parts.length; i++) {
|
||||
// if (!first) {
|
||||
// sb.append("/");
|
||||
// }
|
||||
// sb.append(parts[i]);
|
||||
// first = false;
|
||||
// }
|
||||
// return sb.toString();
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user