From 9821b30d9432630d839089e5fb0278b76d98275e Mon Sep 17 00:00:00 2001 From: guofeihu <3347277866@qq.com> Date: Sat, 14 Sep 2024 16:30:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=B7=A5=E5=85=B7=E7=B1=BB=E4=B8=8D=E8=B5=B0fegin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PortableOfflLogServiceImpl.java | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java index 877cc9f..ae593f9 100644 --- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java +++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/PortableOfflLogServiceImpl.java @@ -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 files,String type) throws Exception{ + byte[] bytes = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + + List responses = new ArrayList<>(); + //min解析较为特殊需要同时解析所有文件 + if(!files.isEmpty() && OfflineConstant.MIN.equals(type)){ + Response response = new Response(); + response.setFilename(OfflineConstant.MIN); + List 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 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