离线文件上传工具类不走fegin
This commit is contained in:
@@ -17,9 +17,11 @@ import com.njcn.csdevice.util.InfluxDbParamUtil;
|
||||
import com.njcn.csharmonic.api.EventFeignClient;
|
||||
import com.njcn.csharmonic.api.OfflineDataUploadFeignClient;
|
||||
import com.njcn.csharmonic.offline.constant.OfflineConstant;
|
||||
import com.njcn.csharmonic.offline.log.Log;
|
||||
import com.njcn.csharmonic.offline.log.vo.NewBodyTaglogbuffer;
|
||||
import com.njcn.csharmonic.offline.log.vo.NewHeadTaglogbuffer;
|
||||
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.pojo.po.CsEventPO;
|
||||
@@ -30,7 +32,6 @@ import com.njcn.influx.pojo.po.cs.PqdData;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EleEvtFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.EleEvtParm;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
@@ -39,9 +40,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -74,8 +73,6 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final InfluxDbParamUtil influxDbParamUtil;
|
||||
|
||||
private final PqdDataMapper pqdDataMapper;
|
||||
@@ -91,6 +88,64 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
||||
return returnpage;
|
||||
}
|
||||
|
||||
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() && OfflineConstant.MIN.equals(type)){
|
||||
Response response = new Response();
|
||||
response.setFilename(OfflineConstant.MIN);
|
||||
List<PqdData> pqdData = null;
|
||||
try {
|
||||
pqdData = AnalyseComtradeCfg.processDirectory(files);
|
||||
} catch (Exception e) {
|
||||
log.error("min文件夹下的数据文件解析失败");
|
||||
response.setState(2);
|
||||
}
|
||||
response.setObj(pqdData);
|
||||
responses.add(response);
|
||||
}else{
|
||||
for(MultipartFile file : files){
|
||||
Response response = new Response();
|
||||
response.setFilename(file.getOriginalFilename());
|
||||
if(OfflineConstant.COMTRADE.equals(type) && file.getOriginalFilename().indexOf(OfflineConstant.CFG) != -1) {
|
||||
tagComtradeCfg tagComtradeCfg = null;
|
||||
try {
|
||||
tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg(file);
|
||||
} catch (Exception e) {
|
||||
log.error("当前文件:{},解析失败",file.getOriginalFilename());
|
||||
response.setState(2);
|
||||
}
|
||||
response.setObj(tagComtradeCfg);
|
||||
}else if(OfflineConstant.LOG.equals(type) && file.getOriginalFilename().indexOf(OfflineConstant.BIN) != -1){
|
||||
List<NewTaglogbuffer> newTaglogbuffers = null;
|
||||
try {
|
||||
newTaglogbuffers = Log.convertLog(file);
|
||||
} catch (Exception e) {
|
||||
log.error("当前文件:{},解析失败",file.getOriginalFilename());
|
||||
response.setState(2);
|
||||
}
|
||||
response.setObj(newTaglogbuffers);
|
||||
}
|
||||
responses.add(response);
|
||||
}
|
||||
}
|
||||
try {
|
||||
oos.writeObject(responses);
|
||||
bytes = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new BusinessException(OfflineConstant.DATATOBYTE_FAIL);
|
||||
} finally {
|
||||
oos.close();
|
||||
baos.close();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void importEquipment(UploadDataParam uploadDataParam) {
|
||||
@@ -108,7 +163,12 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
||||
}
|
||||
if(!fileList.isEmpty()){
|
||||
//将当前文件夹下的文件统一解析
|
||||
byte[] resp = offlineDataUploadFeignClient.uploadAnalysis(fileList,dictData.getCode()).getData();
|
||||
byte[] resp = new byte[0];
|
||||
try {
|
||||
resp = uploadAnalysis(fileList,dictData.getCode());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//解析的返回的是复杂对象所以直接转成byte数组
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(resp);
|
||||
ObjectInputStream ois = null;
|
||||
@@ -293,7 +353,11 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
||||
}
|
||||
}
|
||||
log.info("类型log,插入infulxDb的evtData");
|
||||
evtDataMapper.insertOne(entData);
|
||||
try {
|
||||
evtDataMapper.insertOne(entData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
log.info("类型log,插入mysql事件表cs_event");
|
||||
eventFeignClient.saveBatchEventList(csEventPOS);
|
||||
|
||||
Reference in New Issue
Block a user