审计日志入库完成
This commit is contained in:
@@ -68,9 +68,9 @@ public class TransientServiceImpl implements TransientService {
|
||||
if (!CollectionUtils.isEmpty(deviceList)) {
|
||||
List<List<String>> lists = deviceList.stream().map(GeneralDeviceDTO::getLineIndexes).collect(Collectors.toList());
|
||||
List<String> lineList = new ArrayList<>();
|
||||
for (int i = 0; i<lists.size(); i++) {
|
||||
for (int i = 0; i < lists.size(); i++) {
|
||||
List<String> strings1 = lists.get(i);
|
||||
for (int a = 0; a<strings1.size(); a++) {
|
||||
for (int a = 0; a < strings1.size(); a++) {
|
||||
lineList.add(strings1.get(a));
|
||||
}
|
||||
}
|
||||
@@ -79,10 +79,10 @@ public class TransientServiceImpl implements TransientService {
|
||||
List<EventDetail> data = eventDetailService.getEventDetail(lineList, transientParam.getSearchBeginTime(), transientParam.getSearchEndTime());
|
||||
page.setTotal(data.size());
|
||||
//分页总页数
|
||||
int pages = (int)Math.ceil(data.size()*1.0/transientParam.getPageSize());
|
||||
int pages = (int) Math.ceil(data.size() * 1.0 / transientParam.getPageSize());
|
||||
page.setPages(pages);
|
||||
//influxDB分页查询
|
||||
List<EventDetail> eventDetailData = eventDetailService.getEventDetailLimit(lineList, transientParam.getSearchBeginTime(), transientParam.getSearchEndTime(), transientParam.getPageSize(), transientParam.getPageNum());
|
||||
List<EventDetail> eventDetailData = eventDetailService.getEventDetailLimit(lineList, transientParam.getSearchBeginTime(), transientParam.getSearchEndTime(), transientParam.getPageSize(), transientParam.getPageNum());
|
||||
// List<List<EventDetail>> partition = Lists.partition(eventDetailData, transientParam.getPageSize());
|
||||
// List<EventDetail> detailList = partition.get(transientParam.getPageNum() - 1);
|
||||
if (!CollectionUtils.isEmpty(eventDetailData)) {
|
||||
@@ -90,7 +90,7 @@ public class TransientServiceImpl implements TransientService {
|
||||
collect = collect.stream().distinct().collect(Collectors.toList());
|
||||
List<TransientVO> transientData = transientMapper.getTransientData(collect);
|
||||
int i = 1;
|
||||
for (EventDetail eventDetail: eventDetailData) {
|
||||
for (EventDetail eventDetail : eventDetailData) {
|
||||
if (!Objects.isNull(eventDetail)) {
|
||||
TransientVO transientVO = new TransientVO();
|
||||
transientVO.setId(eventDetail.getLineId());
|
||||
@@ -127,9 +127,9 @@ public class TransientServiceImpl implements TransientService {
|
||||
break;
|
||||
}
|
||||
Double value = new BigDecimal(eventDetail.getEventValue()).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
transientVO.setEventValue(new BigDecimal(value*100).setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
transientVO.setEventValues(100-transientVO.getEventValue());
|
||||
transientVO.setPersistTime((Float.parseFloat(eventDetail.getPersistTime().toString()))/1000);
|
||||
transientVO.setEventValue(new BigDecimal(value * 100).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue());
|
||||
transientVO.setEventValues(100 - transientVO.getEventValue());
|
||||
transientVO.setPersistTime((Float.parseFloat(eventDetail.getPersistTime().toString())) / 1000);
|
||||
|
||||
Float eventValue = Float.parseFloat(eventDetail.getEventValue().toString());
|
||||
Float persistTime = Float.parseFloat(eventDetail.getPersistTime().toString());
|
||||
@@ -174,7 +174,7 @@ public class TransientServiceImpl implements TransientService {
|
||||
// waveDataVO.setName("变电站名称: "+ substation +" 监测点名称: "+ name +" 发生时刻: "+ timeId +" 暂降幅值: "+ v +"% 持续时间: "+ persistTime +"s");
|
||||
// waveDataVO.setTargetName("相电压有效值");
|
||||
AnalyWave analyWave = new AnalyWave();
|
||||
WaveDataDTO comtrade = analyWave.getComtrade(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".CFG", 1);
|
||||
WaveDataDTO comtrade = analyWave.getComtrade(eventBaseConfig.getWavePath() + File.separator + ip + File.separator + waveName + ".CFG", 1);
|
||||
if (Objects.isNull(comtrade.getComtradeCfgDTO())) {
|
||||
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
|
||||
}
|
||||
@@ -185,8 +185,8 @@ public class TransientServiceImpl implements TransientService {
|
||||
double pt2 = Double.parseDouble(lineDetailData.getPt().split("/")[1]);
|
||||
double ct1 = Double.parseDouble(lineDetailData.getCt().split("/")[0]);
|
||||
double ct2 = Double.parseDouble(lineDetailData.getCt().split("/")[1]);
|
||||
waveDataDTO.setPt(pt1/pt2);
|
||||
waveDataDTO.setCt(ct1/ct2);
|
||||
waveDataDTO.setPt(pt1 / pt2);
|
||||
waveDataDTO.setCt(ct1 / ct2);
|
||||
return waveDataDTO;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class TransientServiceImpl implements TransientService {
|
||||
public HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception {
|
||||
List<String> lineId = waveFileParam.getLineId();
|
||||
List<String> timeId = waveFileParam.getTimeId();
|
||||
copyTempData(timeId,lineId);
|
||||
copyTempData(timeId, lineId);
|
||||
zipCompress(new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade"));
|
||||
|
||||
String zipPath = "C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade.zip";
|
||||
@@ -229,9 +229,11 @@ public class TransientServiceImpl implements TransientService {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**复制保存文件 */
|
||||
/**
|
||||
* 复制保存文件
|
||||
*/
|
||||
public void copyTempData(List<String> timeId, List<String> lineId) throws IOException {
|
||||
for (int i=0; i<timeId.size(); i++) {
|
||||
for (int i = 0; i < timeId.size(); i++) {
|
||||
//根据监测点id获取监测点详情
|
||||
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(lineId.get(i)).getData();
|
||||
EventDetail eventDetailByTime = eventDetailService.getEventDetailByTime(lineId.get(i), timeId.get(i));
|
||||
@@ -240,29 +242,30 @@ public class TransientServiceImpl implements TransientService {
|
||||
}
|
||||
String ip = lineDetailData.getIp();
|
||||
String waveName = eventDetailByTime.getWaveName();
|
||||
File srcCFGFile = new File(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".CFG");
|
||||
File srcDATFile = new File(eventBaseConfig.getWavePath()+"\\"+ip+"\\"+waveName+".DAT");
|
||||
File srcCFGFile = new File(eventBaseConfig.getWavePath() + "\\" + ip + "\\" + waveName + ".CFG");
|
||||
File srcDATFile = new File(eventBaseConfig.getWavePath() + "\\" + ip + "\\" + waveName + ".DAT");
|
||||
if (!srcCFGFile.exists() && !srcDATFile.exists()) {
|
||||
throw new BusinessException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND);
|
||||
}
|
||||
File temp = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip);
|
||||
File temp = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\" + ip);
|
||||
temp.mkdirs();
|
||||
// File cfg = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\a1234567890\\"+srcCFGFile.getName());
|
||||
// File dat = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\a1234567890\\"+srcDATFile.getName());
|
||||
File cfg = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip+"\\"+srcCFGFile.getName());
|
||||
File dat = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\"+ip+"\\"+srcDATFile.getName());
|
||||
File cfg = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\" + ip + "\\" + srcCFGFile.getName());
|
||||
File dat = new File("C:\\Users\\陈超\\Desktop\\YSWJ\\comtrade\\" + ip + "\\" + srcDATFile.getName());
|
||||
|
||||
writeFile(srcCFGFile,cfg);
|
||||
writeFile(srcDATFile,dat);
|
||||
writeFile(srcCFGFile, cfg);
|
||||
writeFile(srcDATFile, dat);
|
||||
}
|
||||
}
|
||||
|
||||
//读写文件
|
||||
public static void writeFile(File wave, File temp) throws IOException {
|
||||
FileInputStream fis=new FileInputStream(wave);
|
||||
FileOutputStream fos=new FileOutputStream(temp);
|
||||
FileInputStream fis = new FileInputStream(wave);
|
||||
FileOutputStream fos = new FileOutputStream(temp);
|
||||
int len;
|
||||
byte[] bys=new byte[1024];
|
||||
while((len=fis.read(bys))!=-1){
|
||||
byte[] bys = new byte[1024];
|
||||
while ((len = fis.read(bys)) != -1) {
|
||||
fos.write(bys, 0, len);
|
||||
fos.flush();
|
||||
}
|
||||
@@ -276,72 +279,75 @@ public class TransientServiceImpl implements TransientService {
|
||||
/**
|
||||
* 将文件夹及文件夹包含的内容压缩成zip文件
|
||||
* (为了解决中文乱码的问题,ZipOutputStream用org.apache.tools.zip.*)
|
||||
*
|
||||
* @param inputFile 源文件(夹)
|
||||
* @return File 压缩后的文件(路径在源文件的文件夹路径下)
|
||||
*/
|
||||
public static File zipCompress(File inputFile) throws Exception {
|
||||
File zipFile = null;
|
||||
ZipOutputStream zos = null;
|
||||
if(inputFile != null && inputFile.exists()) {
|
||||
if (inputFile != null && inputFile.exists()) {
|
||||
try {
|
||||
String path = inputFile.getCanonicalPath();
|
||||
String zipFileName = path + ".zip";
|
||||
zipFile = new File(zipFileName);
|
||||
if(zipFile.exists()) {
|
||||
if (zipFile.exists()) {
|
||||
zipFile.delete();
|
||||
}
|
||||
zipFile.createNewFile();//创建文件
|
||||
zos = new ZipOutputStream(new FileOutputStream(zipFile));
|
||||
//压缩文件或文件夹
|
||||
compressFile(zos, inputFile, inputFile.getName());
|
||||
}catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("文件压缩异常:" + e);
|
||||
throw e;
|
||||
}finally {
|
||||
} finally {
|
||||
try {
|
||||
if(zos != null) {
|
||||
if (zos != null) {
|
||||
//先调用outputStream的flush()再关闭流;
|
||||
//流如果未正常关闭,则会在解压的时候出现压缩文件损坏的现象
|
||||
zos.flush();
|
||||
zos.close();
|
||||
}
|
||||
}catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
System.out.println("输出流关闭异常:" + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return zipFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩文件或文件夹 (ZipEntry 使用org.apache.tools.zip.*,不要用 java.util.zip.*)
|
||||
* @param zos zip输出流
|
||||
*
|
||||
* @param zos zip输出流
|
||||
* @param sourceFile 源文件
|
||||
* @param baseName 父路径
|
||||
* @param baseName 父路径
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public static void compressFile(ZipOutputStream zos, File sourceFile, String baseName) throws Exception{
|
||||
if(!sourceFile.exists()) {
|
||||
public static void compressFile(ZipOutputStream zos, File sourceFile, String baseName) throws Exception {
|
||||
if (!sourceFile.exists()) {
|
||||
return;
|
||||
}
|
||||
//若路径为目录(文件夹)
|
||||
if(sourceFile.isDirectory()) {
|
||||
if (sourceFile.isDirectory()) {
|
||||
//取出文件夹中的文件(或子文件夹)
|
||||
File[] fileList = sourceFile.listFiles();
|
||||
//若文件夹为空,则创建一个目录进入点
|
||||
if(fileList.length == 0) {
|
||||
if (fileList.length == 0) {
|
||||
//文件名称后跟File.separator表示这是一个文件夹
|
||||
zos.putNextEntry(new ZipEntry(baseName + File.separator));
|
||||
|
||||
//若文件夹非空,则递归调用compressFile,对文件夹中的每个文件或每个文件夹进行压缩
|
||||
}else {
|
||||
for(int i = 0; i < fileList.length; i++) {
|
||||
} else {
|
||||
for (int i = 0; i < fileList.length; i++) {
|
||||
compressFile(zos, fileList[i],
|
||||
baseName + File.separator + fileList[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
//若为文件,则先创建目录进入点,再将文件写入zip文件中
|
||||
}else {
|
||||
} else {
|
||||
ZipEntry ze = new ZipEntry(baseName);
|
||||
//设置ZipEntry的最后修改时间为源文件的最后修改时间
|
||||
ze.setTime(sourceFile.lastModified());
|
||||
@@ -350,27 +356,29 @@ public class TransientServiceImpl implements TransientService {
|
||||
FileInputStream fis = new FileInputStream(sourceFile);
|
||||
copyStream(fis, zos);
|
||||
try {
|
||||
if(fis != null) {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
}catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("输入流关闭异常:" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流拷贝
|
||||
* @param in 输入流
|
||||
*
|
||||
* @param in 输入流
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copyStream(InputStream in, OutputStream out) throws IOException{
|
||||
public static void copyStream(InputStream in, OutputStream out) throws IOException {
|
||||
int bufferLength = 1024 * 100;
|
||||
synchronized(in) {
|
||||
synchronized(out) {
|
||||
synchronized (in) {
|
||||
synchronized (out) {
|
||||
int count = 0;
|
||||
byte[] buffer = new byte[bufferLength];
|
||||
while((count = in.read(buffer, 0, bufferLength)) != -1) {
|
||||
while ((count = in.read(buffer, 0, bufferLength)) != -1) {
|
||||
out.write(buffer, 0, count);
|
||||
}
|
||||
out.flush();
|
||||
@@ -380,14 +388,17 @@ public class TransientServiceImpl implements TransientService {
|
||||
|
||||
|
||||
//=================================================================================================================
|
||||
/**处理文件路径和指定压缩包位置 */
|
||||
|
||||
/**
|
||||
* 处理文件路径和指定压缩包位置
|
||||
*/
|
||||
public static String downloadWaveMoreFile(List<String> pathList) {
|
||||
List<File> list = new ArrayList<>();
|
||||
for (String string: pathList) {
|
||||
for (String string : pathList) {
|
||||
String path = string;
|
||||
//待压缩的多个源文件
|
||||
File f1 = new File(path+".CFG");
|
||||
File f2 = new File(path+".DAT");
|
||||
File f1 = new File(path + ".CFG");
|
||||
File f2 = new File(path + ".DAT");
|
||||
list.add(f1);
|
||||
list.add(f2);
|
||||
}
|
||||
@@ -401,6 +412,7 @@ public class TransientServiceImpl implements TransientService {
|
||||
|
||||
/**
|
||||
* 压缩多个文件成一个zip文件
|
||||
*
|
||||
* @param srcfile:源文件列表
|
||||
* @param zipfile:压缩后的文件
|
||||
*/
|
||||
@@ -426,7 +438,9 @@ public class TransientServiceImpl implements TransientService {
|
||||
}
|
||||
}
|
||||
|
||||
/**删除文件(夹)和空文件夹 */
|
||||
/**
|
||||
* 删除文件(夹)和空文件夹
|
||||
*/
|
||||
private void deleteDirectoryLegacyIO(File file) {
|
||||
File[] list = file.listFiles(); //无法做到list多层文件夹数据
|
||||
if (list != null) {
|
||||
@@ -443,6 +457,7 @@ public class TransientServiceImpl implements TransientService {
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param filePathAndName 指定得路径
|
||||
*/
|
||||
public static void delFile(String filePathAndName) {
|
||||
|
||||
Reference in New Issue
Block a user