离线数据上传第一版代码提交
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 类的介绍:离线数据上传解析服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gfh
|
||||
* @since 2024/7/22 13:56
|
||||
*/
|
||||
public interface OfflineDataUploadService {
|
||||
|
||||
byte[] uploadAnalysis(List<MultipartFile> files,String type) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csharmonic.offline.log.Log;
|
||||
import com.njcn.csharmonic.offline.log.vo.NewTaglogbuffer;
|
||||
import com.njcn.csharmonic.offline.mincfg.AnalyseComtradeCfg;
|
||||
import com.njcn.csharmonic.offline.mincfg.tagComtradeCfg;
|
||||
import com.njcn.csharmonic.offline.vo.Response;
|
||||
import com.njcn.csharmonic.service.OfflineDataUploadService;
|
||||
import com.njcn.influx.pojo.po.cs.PqdData;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:离线数据上传解析服务实现类
|
||||
*
|
||||
* @author gfh
|
||||
* @version 1.0.0
|
||||
* @createTime 2024/7/22 13:56
|
||||
*/
|
||||
@Service
|
||||
public class OfflineDataUploadServiceImpl implements OfflineDataUploadService {
|
||||
|
||||
@Override
|
||||
public byte[] uploadAnalysis(List<MultipartFile> files,String type) throws Exception{
|
||||
byte[] bytes = null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
|
||||
List<Response> responses = new ArrayList<>();
|
||||
//min解析较为特殊需要同时解析所有文件
|
||||
if(!files.isEmpty() && "min".equals(type)){
|
||||
Response response = new Response();
|
||||
response.setFilename("min");
|
||||
List<PqdData> pqdData = AnalyseComtradeCfg.processDirectory(files);
|
||||
response.setObj(pqdData);
|
||||
responses.add(response);
|
||||
}else{
|
||||
for(MultipartFile file : files){
|
||||
Response response = new Response();
|
||||
response.setFilename(file.getOriginalFilename());
|
||||
if("comtrade".equals(type) && file.getOriginalFilename().indexOf(".cfg") != -1) {
|
||||
tagComtradeCfg tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg(file);
|
||||
response.setObj(tagComtradeCfg);
|
||||
}else if("log".equals(type) && file.getOriginalFilename().indexOf(".bin") != -1){
|
||||
List<NewTaglogbuffer> newTaglogbuffers = Log.convertLog(file);
|
||||
response.setObj(newTaglogbuffers);
|
||||
}
|
||||
responses.add(response);
|
||||
}
|
||||
}
|
||||
try {
|
||||
oos.writeObject(responses);
|
||||
bytes = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new BusinessException("数据集对象转字节数组失败");
|
||||
} finally {
|
||||
oos.close();
|
||||
baos.close();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user