271 lines
10 KiB
Java
271 lines
10 KiB
Java
package com.njcn;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||
import com.njcn.access.enums.AccessEnum;
|
||
import com.njcn.access.enums.TypeEnum;
|
||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||
import com.njcn.csharmonic.api.WavePicFeignClient;
|
||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||
import com.njcn.influx.utils.InfluxDbUtils;
|
||
import com.njcn.oss.utils.FileStorageUtil;
|
||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||
import com.njcn.redis.utils.RedisUtil;
|
||
import com.njcn.user.api.AppUserFeignClient;
|
||
import com.njcn.user.api.UserFeignClient;
|
||
import com.njcn.user.pojo.po.User;
|
||
import com.njcn.zlevent.ZlEventBootApplication;
|
||
import com.njcn.zlevent.pojo.constant.ZlConstant;
|
||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||
import com.njcn.zlevent.service.ICsWaveService;
|
||
import net.sf.json.JSONObject;
|
||
import org.influxdb.InfluxDB;
|
||
import org.influxdb.dto.BatchPoints;
|
||
import org.influxdb.dto.Point;
|
||
import org.junit.Test;
|
||
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 javax.annotation.Resource;
|
||
import java.io.*;
|
||
import java.nio.file.Files;
|
||
import java.nio.file.Path;
|
||
import java.sql.Timestamp;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.*;
|
||
import java.util.concurrent.TimeUnit;
|
||
import java.util.stream.IntStream;
|
||
|
||
import static org.junit.Assert.assertTrue;
|
||
|
||
/**
|
||
* Unit test for simple App.
|
||
*/
|
||
@RunWith(SpringRunner.class)
|
||
@WebAppConfiguration
|
||
@SpringBootTest(classes = ZlEventBootApplication.class)
|
||
public class AppTest {
|
||
|
||
@Resource
|
||
private RedisUtil redisUtil;
|
||
|
||
@Resource
|
||
private FileStorageUtil fileStorageUtil;
|
||
|
||
@Resource
|
||
private WavePicFeignClient wavePicFeignClient;
|
||
|
||
@Resource
|
||
private AppUserFeignClient appUserFeignClient;
|
||
|
||
@Resource
|
||
private InfluxDbUtils influxDbUtils;
|
||
|
||
@Resource
|
||
private MqttPublisher publisher;
|
||
@Resource
|
||
private ICsWaveService csWaveService;
|
||
|
||
/**
|
||
* Rigorous Test :-)
|
||
*/
|
||
@Test
|
||
public void shouldAnswerWithTrue()
|
||
{
|
||
assertTrue( true );
|
||
}
|
||
|
||
@Test
|
||
public void test00() {
|
||
long time = 1726237055L;
|
||
long subtleTime = 889000L;
|
||
Double millisecond = 1430.0;
|
||
|
||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
time = time - 8*3600;
|
||
// 将millisecond转换为长整型,并乘以1000以获取微秒
|
||
long millisecondValue = millisecond.longValue() * 1000;
|
||
long time1 = time * 1000000 + subtleTime;
|
||
long time2 = time * 1000000 + subtleTime + millisecondValue;
|
||
String time1String = String.valueOf(time1);
|
||
String time2String = String.valueOf(time2);
|
||
|
||
String time11 = time1String.substring(time1String.length() - 6);
|
||
String time111 = time1String.substring(0,time1String.length() - 6);
|
||
String formatTime1 = format.format(Long.parseLong(time111) * 1000);
|
||
|
||
String time22 = time2String.substring(time2String.length() - 6);
|
||
String time222 = time2String.substring(0,time2String.length() - 6);
|
||
String formatTime2 = format.format(Long.parseLong(time222) * 1000);
|
||
System.out.println(formatTime1 + "." + time11);
|
||
System.out.println(formatTime2 + "." + time22);
|
||
}
|
||
|
||
@Test
|
||
public void test11() {
|
||
String fileName = "/bd0/comtrade/PQS_PQM1_000063_20241029_101442_886";
|
||
boolean result = csWaveService.findCountByName(fileName);
|
||
System.out.println("result==:" + result);
|
||
}
|
||
|
||
@Test
|
||
public void test3() {
|
||
List<String> records = new ArrayList<String>();
|
||
long timeSec = 1695892557L;
|
||
Map<String, String> tags = new HashMap<>();
|
||
tags.put(InfluxDBTableConstant.UUID,"000002");
|
||
Map<String,Object> fields = new HashMap<>();
|
||
fields.put("location","电网侧");
|
||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||
Point point = influxDbUtils.pointBuilder("zl_test", System.currentTimeMillis(), TimeUnit.MILLISECONDS, tags, fields);
|
||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||
batchPoints.point(point);
|
||
records.add(batchPoints.lineProtocol());
|
||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
|
||
}
|
||
|
||
@Test
|
||
public void test2() throws IOException {
|
||
String localPath = "C:\\Users\\徐扬\\Desktop\\123.dat";
|
||
FileOutputStream fileOut = new FileOutputStream(localPath,true);
|
||
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
|
||
|
||
Map<Integer, String> mapToWrite = new HashMap<>();
|
||
mapToWrite.put(1, "value1");
|
||
mapToWrite.put(2, "value2");
|
||
mapToWrite.put(3, "value3");
|
||
|
||
Map<Integer, String> mapToWrite2 = new HashMap<>();
|
||
mapToWrite2.put(11, "value1");
|
||
mapToWrite2.put(22, "value2");
|
||
mapToWrite2.put(33, "value3");
|
||
|
||
objectOut.writeObject(mapToWrite);
|
||
objectOut.writeObject(mapToWrite2);
|
||
|
||
objectOut.close();
|
||
fileOut.close();
|
||
}
|
||
|
||
@Test
|
||
public void test222() throws IOException {
|
||
List<Map<String, Integer>> mapList = new ArrayList<>();
|
||
String localPath = "C:\\Users\\徐扬\\Desktop\\123.dat";
|
||
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(localPath));
|
||
while (true) {
|
||
try {
|
||
Map<String, Integer> loadedMap = (Map<String, Integer>) inputStream.readObject();
|
||
mapList.add(loadedMap);
|
||
} catch (EOFException | ClassNotFoundException e) {
|
||
// 读取到文件末尾时退出循环
|
||
break;
|
||
}
|
||
}
|
||
System.out.println("list集合为:" + mapList);
|
||
}
|
||
|
||
|
||
@Test
|
||
public void test22() {
|
||
String filePath = "C:\\Users\\徐扬\\Desktop\\PQS_PQM1_000005_20231007_141638_348.dat";
|
||
Map<Integer, String> readMap = new HashMap<>();
|
||
try {
|
||
BufferedReader reader = new BufferedReader(new FileReader(filePath));
|
||
Gson gson = new Gson();
|
||
String line;
|
||
while ((line = reader.readLine()) != null) {
|
||
readMap = gson.fromJson(line, Map.class);
|
||
}
|
||
// 关闭流
|
||
reader.close();
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
System.out.println("从文件读取的Map: " + readMap.size());
|
||
}
|
||
|
||
|
||
@Test
|
||
public void test4() {
|
||
String fileName = "/sd0:1/comtrade/PQS_PQM1_000005_20231007_141638_348.dat";
|
||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(fileName));
|
||
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object1), FileStreamDto.class);
|
||
System.out.println("数据个数:" + dto.getList().size());
|
||
System.out.println("总个数:" + dto.getTotal());
|
||
|
||
IntStream.rangeClosed(1, 476)
|
||
.filter(i -> !dto.getList().contains(i))
|
||
.forEach(missingNumber -> System.out.println("缺失的数字: " + missingNumber));
|
||
}
|
||
|
||
|
||
@Test
|
||
public void test5() {
|
||
String name = "/sd0:1/comtrade/PQS_PQM1_000005_20231007_141638_348.dat";
|
||
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(name), null, 10L);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
@Test
|
||
public void test() {
|
||
long time = 1694598894;
|
||
Double millisecond = 60000.0;
|
||
long subtleTime = 99000L;
|
||
long millisecondValue = millisecond.longValue() * 1000;
|
||
|
||
long time1 = time * 1000000 + subtleTime;
|
||
long time2 = time * 1000000 + subtleTime + millisecondValue;
|
||
String time1String = String.valueOf(time1);
|
||
String time2String = String.valueOf(time2);
|
||
|
||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
|
||
String time11 = time1String.substring(time1String.length() - 6);
|
||
String time111 = time1String.substring(0,time1String.length() - 6);
|
||
String formatTime1 = format.format(Long.parseLong(time111) * 1000);
|
||
|
||
String time22 = time2String.substring(time2String.length() - 6);
|
||
String time222 = time2String.substring(0,time2String.length() - 6);
|
||
String formatTime2 = format.format(Long.parseLong(time222) * 1000);
|
||
|
||
WaveTimeDto waveTimeDto = new WaveTimeDto();
|
||
waveTimeDto.setStartTime(formatTime1 + "." + time11);
|
||
waveTimeDto.setEndTime(formatTime2 + "." + time22);
|
||
System.out.println("waveTimeDto===:" + waveTimeDto);
|
||
|
||
|
||
// long endTime;
|
||
// //开始时间
|
||
// time = (time - 8*3600) * 1000000;
|
||
// //结束时间
|
||
// long millisecondValue = millisecond.longValue() * 1000;
|
||
// endTime = time + subtleTime + millisecondValue;
|
||
// System.out.println("endTime==:" + endTime);
|
||
// String endTimeString = String.valueOf(endTime);
|
||
// String time1 = endTimeString.substring(endTimeString.length() - 6);
|
||
// String time2 = endTimeString.substring(0,endTimeString.length() - 6);
|
||
// System.out.println("time1==:" + time1);
|
||
// System.out.println("time2==:" + time2);
|
||
// long longTime2 = Long.parseLong(time2)/1000;
|
||
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
// System.out.println("time==:" + time);
|
||
// System.out.println("longTime2==:" + longTime2);
|
||
// String formatTime1 = format.format(time/1000000);
|
||
// String formatTime2 = format.format(longTime2);
|
||
// System.out.println("formatTime1==:" + formatTime1);
|
||
// System.out.println("formatTime2==:" + formatTime2);
|
||
// WaveTimeDto waveTimeDto = new WaveTimeDto();
|
||
// waveTimeDto.setStartTime(formatTime1 + "." + subtleTime);
|
||
// waveTimeDto.setEndTime(formatTime2 + "." + time1);
|
||
// System.out.println("waveTimeDto==:" + waveTimeDto);
|
||
}
|
||
|
||
}
|