离线数据上传

This commit is contained in:
hzj
2024-09-29 16:15:52 +08:00
parent d1574e43be
commit 4745b86085
19 changed files with 1045 additions and 840 deletions

View File

@@ -53,6 +53,7 @@ public interface DataParam {
String EvtParamPhase = "Evt_Param_Phase";
String EvtParamDepth = "Evt_Param_VVaDepth";
String EVTPARAMTM ="Evt_Param_Tm";
String evtData = "evt_data";

View File

@@ -13,6 +13,7 @@ import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.csdevice.service.IPortableOfflLogService;
import com.njcn.csdevice.utils.ExcelStyleUtil;
import com.njcn.csdevice.param.UploadDataParam;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.poi.util.PoiUtil;
import com.njcn.system.api.DicDataFeignClient;
@@ -53,6 +54,8 @@ public class PortableOfflLogController extends BaseController {
private final DicDataFeignClient dicDataFeignClient;
private final FileStorageUtil fileStorageUtil;
@ResponseBody
@ApiOperation("导出设备基础数据模板")
@GetMapping(value = "getExcelTemplate")
@@ -98,5 +101,27 @@ public class PortableOfflLogController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("数据在线补招")
@PostMapping(value = "dataOnlineRecruitment")
public HttpResult<String> dataOnlineRecruitment(@RequestParam("devId") String devId
, @RequestParam("lineId") String lineId, @RequestParam("path") String path,HttpServletRequest request) {
String methodDescribe = getMethodDescribe("dataOnlineRecruitment");
List<MultipartFile> excelreport = null;
try {
excelreport = fileStorageUtil.getAllFile("excelreport", path);
} catch (Exception e) {
throw new RuntimeException(e);
}
UploadDataParam uploadDataParam = new UploadDataParam();
uploadDataParam.setDevId(devId);
uploadDataParam.setLineId(lineId);
uploadDataParam.setFiles(excelreport);
iPortableOfflLogService.importEquipment(uploadDataParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -455,6 +455,14 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
}else {
temp.setFeatureAmplitude(evtParamDepth.get(0).getValue().equals("-")?null:Float.parseFloat(evtParamDepth.get(0).getValue()));
}
List<EventDataSetDTO> evtParmTm = eventDataSetDTOS.stream().
filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), DataParam.EVTPARAMTM)).
collect(Collectors.toList());
if(CollectionUtil.isEmpty(evtParamDepth)){
temp.setPersistTime(null);
}else {
temp.setPersistTime(evtParmTm.get(0).getValue().equals("-")?null:Double.parseDouble(evtParmTm.get(0).getValue()));
}
}
});
return csEventVOPage;

View File

@@ -3,7 +3,6 @@ package com.njcn.csdevice.service.impl;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
@@ -21,10 +20,12 @@ 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.log.vo.TagComtradeCfg;
import com.njcn.csharmonic.offline.mincfg.AnalyseComtradeCfg;
import com.njcn.csharmonic.offline.mincfg.tagComtradeCfg;
import com.njcn.csharmonic.offline.mincfg.vo.CmnModeCfg;
import com.njcn.csharmonic.offline.vo.Response;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.influx.imapper.CommonMapper;
import com.njcn.influx.imapper.EvtDataMapper;
import com.njcn.influx.imapper.PqdDataMapper;
import com.njcn.influx.pojo.po.cs.EntData;
@@ -33,17 +34,17 @@ import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EleEvtFeignClient;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEvtParm;
import com.njcn.web.pojo.param.BaseParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -61,6 +62,9 @@ import java.util.stream.Stream;
@RequiredArgsConstructor
public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMapper, PortableOfflLog> implements IPortableOfflLogService {
private final DecimalFormat df = new DecimalFormat("#0.000");
private final FileStorageUtil fileStorageUtil;
private final DicDataFeignClient dicDataFeignClient;
@@ -82,8 +86,12 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
@Override
public Page<PortableOfflLog> queryPage(BaseParam baseParam) {
Page<PortableOfflLog> returnpage = new Page<> (baseParam.getPageNum(), baseParam.getPageSize ());
if(baseParam.getSearchBeginTime()!=null) baseParam.setSearchBeginTime(baseParam.getSearchBeginTime()+DataParam.startTime);
if(baseParam.getSearchEndTime()!=null) baseParam.setSearchEndTime(baseParam.getSearchEndTime()+DataParam.endTime);
if(baseParam.getSearchBeginTime()!=null) {
baseParam.setSearchBeginTime(baseParam.getSearchBeginTime()+DataParam.startTime);
}
if(baseParam.getSearchEndTime()!=null) {
baseParam.setSearchEndTime(baseParam.getSearchEndTime()+DataParam.endTime);
}
returnpage = this.getBaseMapper().queryPage(returnpage,baseParam);
return returnpage;
}
@@ -112,7 +120,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
Response response = new Response();
response.setFilename(file.getOriginalFilename());
if(OfflineConstant.COMTRADE.equals(type) && file.getOriginalFilename().indexOf(OfflineConstant.CFG) != -1) {
tagComtradeCfg tagComtradeCfg = null;
TagComtradeCfg tagComtradeCfg = null;
try {
tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg(file);
} catch (Exception e) {
@@ -149,6 +157,32 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
@Override
@Transactional(rollbackFor = {Exception.class})
public void importEquipment(UploadDataParam uploadDataParam){
String lineId = uploadDataParam.getLineId();
String cdid = uploadDataParam.getLineId().substring(uploadDataParam.getLineId().length() - 1);
//第一步解析redcord.bin文件获取监测点序号做校验
List<MultipartFile> record = uploadDataParam.getFiles().stream().filter(
temp -> temp.getOriginalFilename().contains("record.bin"))
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(record)){
throw new BusinessException(AlgorithmResponseEnum.RECORD_FILE_LOST);
}else {
InputStream inputStream = null;
try {
inputStream = record.get(0).getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
CmnModeCfg cmnModeCfg = AnalyseComtradeCfg.convertRecord(inputStream);
//监测点序号
int lineIdx = cmnModeCfg.line_idx;
if(lineIdx!=Integer.valueOf(cdid)){
throw new BusinessException(AlgorithmResponseEnum.LINE_NUM_MISMATCH);
}
}
//获取离线上传对应的字典规则(字典用来控制上传的文件夹名称,其中字典的name代表名称,code代表该文件夹下对应的解析规则且code不能更改)
List<DictData> dictDatas = dicDataFeignClient.getDicDataByTypeCode(DataParam.wlRecordUpload).getData();
List<Response> responses = new ArrayList<>();
@@ -159,7 +193,9 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
List<MultipartFile> fileList = new ArrayList<>();
for(MultipartFile file : uploadDataParam.getFiles()){
//获取每个文件夹下对应的文件信息
if(checkPrevsFolder(file.getOriginalFilename(),dictData.getName())!=null) fileList.add(file);
if(checkPrevsFolder(file.getOriginalFilename(),dictData.getName())!=null) {
fileList.add(file);
}
}
if(!fileList.isEmpty()){
//将当前文件夹下的文件统一解析
@@ -197,11 +233,12 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
}
List<CsEquipmentDeliveryDTO> data1 = equipmentFeignClient.queryDeviceById(Stream.of(uploadDataParam.getDevId()).collect(Collectors.toList())).getData();
CsEquipmentDeliveryDTO csEquipmentDeliveryDTO = data1.get(0);
//min文件夹下的文件是否解析过
boolean minFlag = true;
//开始上传文件、记录上传日志、解析的文件结果入库
//最外层便利所有文件确保所有文件都上传及记录上传日志
for(MultipartFile file : uploadDataParam.getFiles()){
//初始上传日志基本信息
PortableOfflLog portableOfflLog = new PortableOfflLog();
@@ -213,11 +250,18 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
//默认总条数及入库数为0(防止解析的数据重复插入及上传的文件目录路径错误)
portableOfflLog.setAllCount(0);
portableOfflLog.setRealCount(0);
//开始匹配解析的文件结果入库
for(Response response : responses){
//min解析结果较为特殊所有的文件解析后只有一条结果
if(OfflineConstant.MIN.equals(response.getFilename()) && checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.MIN)!=null){
List<PqdData> pqdData = (List<PqdData>) response.getObj();
pqdData.forEach(temp->{
temp.setClDid(cdid);
temp.setIsAbnormal(0);
temp.setProcess(data1.get(0).getProcess()+"");
temp.setLineId(uploadDataParam.getLineId());
});
//如果明确返回了state 那么当前文件解析出错
if(response.getState() != null){
portableOfflLog.setState(response.getState());
@@ -241,7 +285,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
if(response.getState() != null){
portableOfflLog.setState(response.getState());
}
tagComtradeCfg tagComtradeCfg = (tagComtradeCfg) response.getObj();
TagComtradeCfg tagComtradeCfg = (TagComtradeCfg) response.getObj();
if(tagComtradeCfg != null){
//否则正常标记为成功解析
portableOfflLog.setState(1);
@@ -268,6 +312,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
NewHeadTaglogbuffer newHeadTaglogbuffer = newTaglogbuffer.getNewHeadTaglogbuffer();
String strId = "";
String strName = newHeadTaglogbuffer.getLogCode()+"";
//todo 其他事件做映射
//中断标志
if(DataParam.intrStr.contains(newHeadTaglogbuffer.getLogCode())){
strId = DataParam.intrStrId;
@@ -283,28 +328,44 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
strId = DataParam.swlStrId;
strName = DataParam.swlStrName;
}
List<EleEvtParm> eleEvtParms = eleEvtFeignClient.queryByPid(strId).getData();
//插入事件表
CsEventPO csEventPO = new CsEventPO();
csEventPO.setId(IdUtil.simpleUUID());
csEventPO.setId(IdUtil.fastSimpleUUID());
csEventPO.setLineId(uploadDataParam.getLineId());
csEventPO.setDeviceId(uploadDataParam.getDevId());
csEventPO.setProcess(csEquipmentDeliveryDTO.getProcess());
//todo 做映射目前置空
csEventPO.setCode(null);
csEventPO.setStartTime(newTaglogbuffer.getStart());
csEventPO.setTag(strName);
//更具唯一索引做校验存在该事件则跳过;
CsEventPO data = eventFeignClient.queryByIndex(csEventPO).getData();
if(Objects.nonNull(data)){
continue;
}
String wavePath = null;
//设置波形文件(去cfg结果集里面去找)
for (Response res : cfgResponse) {
String cfg = res.getFilename();
String dat = cfg.substring(0,cfg.lastIndexOf("."))+OfflineConstant.DAT;
String sharPath = OfflineConstant.COMTRADE+"/"+DataParam.wlRecordPath+uploadDataParam.getDevId()+"/"+uploadDataParam.getLineId()+"/"+getFolderName()+"/";
tagComtradeCfg sing = (tagComtradeCfg) res.getObj();
Date date = Date.from(newTaglogbuffer.getStart().atZone( ZoneId.systemDefault()).toInstant());
String sharPath = OfflineConstant.COMTRADE+"/"+csEquipmentDeliveryDTO.getMac()+"/";
TagComtradeCfg sing = (TagComtradeCfg) res.getObj();
//如果匹配上则需要将当前cfg文件及对应的dat文件上传到comtrade文件夹中
if ((sing!= null && sing.getTimeStart()!= null && sing.getTimeEnd() !=null && sing.getTimeTrigger().compareTo(date) <= 0 && sing.getTimeEnd().compareTo(date) >= 0)) {
if (sing!= null && sing.getTimeStart()!= null && sing.getTimeTrigger().compareTo(csEventPO.getStartTime())<=0
&&sing.getTimeEnd().compareTo(csEventPO.getStartTime())>=0) {
for(MultipartFile f : uploadDataParam.getFiles()){
if(f.getOriginalFilename().equals(cfg) || f.getOriginalFilename().equals(dat)){
fileStorageUtil.uploadMultipart(f, sharPath);
wavePath = sharPath;
int lastIndex = f.getOriginalFilename().lastIndexOf('/');
String fileName = f.getOriginalFilename().substring(lastIndex + 1);
String baseName = FilenameUtils.getBaseName(fileName);
String extension = FilenameUtils.getExtension(fileName);
try {
fileStorageUtil.uploadStreamSpecifyName(f.getInputStream(), sharPath, baseName + "." + extension.toUpperCase());
} catch (IOException e) {
throw new RuntimeException(e);
}
wavePath = sharPath+fileName.substring(0,fileName.lastIndexOf("."));
}
}
}
@@ -314,18 +375,24 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
csEventPO.setType(0);
String clDid = influxDbParamUtil.getClDidByLineId(uploadDataParam.getLineId());
csEventPO.setClDid(clDid == null ? null : Integer.parseInt(clDid));
//默认告警等级2
csEventPO.setLevel(2);
//默认事件发生位置:电网侧
csEventPO.setLocation("grid");
csEventPO.setProcess(data1.get(0).getProcess());
csEventPO.setProcess(csEquipmentDeliveryDTO.getProcess());
csEventPOS.add(csEventPO);
EntData entData = new EntData();
entData.setUuid(csEventPO.getId());
entData.setTime(new Date().toInstant());
//entData.setTime(newTaglogbuffer.getStart().toInstant(ZoneOffset.UTC));
for(NewBodyTaglogbuffer newBodyTaglogbuffer : newTaglogbuffer.getNewBodyTaglogbuffers()){
if(newBodyTaglogbuffer.getParaCode() == 0) entData.setEvtParamVVaDepth(newBodyTaglogbuffer.getParaValue()/65536D);
if(newBodyTaglogbuffer.getParaCode() == 1) entData.setEvtParamTm(newBodyTaglogbuffer.getParaValue()/65536D);
if(newBodyTaglogbuffer.getParaCode() == 0) {
entData.setEvtParamVVaDepth(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
}
if(newBodyTaglogbuffer.getParaCode() == 1) {
entData.setEvtParamTm(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
csEventPO.setPersistTime(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
}
if(newBodyTaglogbuffer.getParaCode() == 5) {
int code = newBodyTaglogbuffer.getParaValue()/65536;
switch (code){

View File

@@ -11,6 +11,9 @@ import com.njcn.csharmonic.pojo.vo.CsEventVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -24,5 +27,8 @@ public interface EventFeignClient {
@PostMapping("/pageQueryByLineId")
HttpResult<Page<DataGroupEventVO>> pageQueryByLineId(@RequestBody CsEventUserQueryPage csEventUserQueryPage);
@PostMapping("/queryByIndex")
HttpResult<CsEventPO> queryByIndex(@RequestBody CsEventPO csEventPO);
}

View File

@@ -12,6 +12,9 @@ import com.njcn.csharmonic.pojo.vo.CsEventVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -40,6 +43,12 @@ public class EventFeignClientFallbackFactory implements FallbackFactory<EventFei
log.error("{}异常,降级处理,异常为:{}","根据监测点分页查询暂降事件",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<CsEventPO> queryByIndex( CsEventPO csEventPO) {
log.error("{}异常,降级处理,异常为:{}","根据根据表唯一索引查询(用于校验是否存在该事件)s",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -14,8 +14,7 @@ import java.util.List;
@Slf4j
public class Log {
private static String logPath = "C:\\Users\\Administrator\\Desktop\\浙江无线\\离线数据上传\\09\\log";//事件文件路径
private static LocalDateTime event_starttime = null;
private static LocalDateTime event_endtime = null;
private static List<TagComtradeCfg> tagComtradeCfgs = new ArrayList();//波形文件cfg信息队列
public static void main(String[] args) throws Exception {
boolean logbin = false;
@@ -55,10 +54,12 @@ public class Log {
e.printStackTrace();
throw new BusinessException("文件" + file.getName() + " 读取时发生错误");
}
LocalDateTime event_starttime = null;
LocalDateTime event_endtime = null;
NewTaglogbuffer newTaglogbuffer = getnewTaglogbuffer(bBuf);
newTaglogbuffers.add(newTaglogbuffer);
TagMsTime devtime = newTaglogbuffer.getNewHeadTaglogbuffer().getDevtime();
LocalDateTime time = LocalDateTime.of(devtime.getYear(), devtime.getMonth(), devtime.getDay(), devtime.getHour(), devtime.getMin(), devtime.getSec(), devtime.getMs());
LocalDateTime time = LocalDateTime.of(devtime.getYear(), devtime.getMonth(), devtime.getDay(), devtime.getHour(), devtime.getMin(), devtime.getSec(), devtime.getMs()*1000*1000);
//存在启动时间
if (event_starttime != LocalDateTime.MIN&& event_starttime!=null) {
if (time.compareTo(event_starttime) <= 0) {
@@ -77,6 +78,7 @@ public class Log {
event_endtime = time;
}
long sec = 0;
for (NewBodyTaglogbuffer sing : newTaglogbuffer.getNewBodyTaglogbuffers()) {
switch (sing.getParaCode()) {
@@ -95,14 +97,19 @@ public class Log {
break;
}
}
//当事件时长超过1分钟直接排除
if(sec>60){
continue;
}
newTaglogbuffer.setStart(time); //事件开始时间
newTaglogbuffer.setEnd(time.plusSeconds(sec)); //事件结束时间
for (TagComtradeCfg sing : tagComtradeCfgs) {
if (sing.getTimeTrigger().compareTo(newTaglogbuffer.getStart()) <= 0 && sing.getTimeEnd().compareTo(newTaglogbuffer.getStart()) >= 0) {
newTaglogbuffer.setPath(sing.getPath());
break;
}
}
//这里tagComtradeCfgs为空无效
// for (TagComtradeCfg sing : tagComtradeCfgs) {
// if (sing.getTimeTrigger().compareTo(newTaglogbuffer.getStart()) <= 0 && sing.getTimeEnd().compareTo(newTaglogbuffer.getStart()) >= 0) {
// newTaglogbuffer.setPath(sing.getPath());
// break;
// }
// }
}
} catch (BusinessException e) {
e.printStackTrace();
@@ -137,9 +144,10 @@ public class Log {
throw new BusinessException("文件" + file.getOriginalFilename() + " 读取时发生错误");
}
NewTaglogbuffer newTaglogbuffer = getnewTaglogbuffer(bBuf);
newTaglogbuffers.add(newTaglogbuffer);
LocalDateTime event_starttime = null;
LocalDateTime event_endtime = null;
TagMsTime devtime = newTaglogbuffer.getNewHeadTaglogbuffer().getDevtime();
LocalDateTime time = LocalDateTime.of(devtime.getYear(), devtime.getMonth(), devtime.getDay(), devtime.getHour(), devtime.getMin(), devtime.getSec(), devtime.getMs());
LocalDateTime time = LocalDateTime.of(devtime.getYear(), devtime.getMonth(), devtime.getDay(), devtime.getHour(), devtime.getMin(), devtime.getSec(), devtime.getMs()*1000*1000);
//存在启动时间
if (event_starttime != LocalDateTime.MIN&& event_starttime!=null) {
if (time.compareTo(event_starttime) <= 0) {
@@ -176,14 +184,21 @@ public class Log {
break;
}
}
//当事件时长超过1分钟直接排除
if(sec>60){
continue;
}
newTaglogbuffer.setStart(time); //事件开始时间
newTaglogbuffer.setEnd(time.plusSeconds(sec)); //事件结束时间
for (TagComtradeCfg sing : tagComtradeCfgs) {
if (sing.getTimeTrigger().compareTo(newTaglogbuffer.getStart()) <= 0 && sing.getTimeEnd().compareTo(newTaglogbuffer.getStart()) >= 0) {
newTaglogbuffer.setPath(sing.getPath());
break;
}
}
//这里tagComtradeCfgs为空无效
// for (TagComtradeCfg sing : tagComtradeCfgs) {
// if (sing.getTimeTrigger().compareTo(newTaglogbuffer.getStart()) <= 0 && sing.getTimeEnd().compareTo(newTaglogbuffer.getStart()) >= 0) {
// newTaglogbuffer.setPath(sing.getPath());
// break;
// }
// }
newTaglogbuffers.add(newTaglogbuffer);
}
} catch (BusinessException e) {
e.printStackTrace();

View File

@@ -5,6 +5,7 @@ import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data

View File

@@ -1,11 +1,13 @@
package com.njcn.csharmonic.offline.log.vo;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
@Data
public class TagComtradeCfg {
public class TagComtradeCfg implements Serializable {
private int nChannelNum; //通道总个数
private int nAnalogNum; //模拟量通道的个数 WW 2013-05-15
private int nDigitalNum; //数字量通道的个数 WW 2013-05-15

View File

@@ -2,8 +2,10 @@ package com.njcn.csharmonic.offline.log.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class TagOneChannleCfg {
public class TagOneChannleCfg implements Serializable {
//通道序号
private int nIndex;
//通道名称

View File

@@ -2,8 +2,10 @@ package com.njcn.csharmonic.offline.log.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class TagOneChannleCfgDigital {
public class TagOneChannleCfgDigital implements Serializable {
//通道序号
private int nIndex;
//通道名称

View File

@@ -2,16 +2,22 @@ package com.njcn.csharmonic.offline.mincfg;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.njcn.influx.pojo.po.cs.PqdData;
import com.njcn.csharmonic.offline.log.vo.TagComtradeCfg;
import com.njcn.csharmonic.offline.log.vo.TagOneChannleCfg;
import com.njcn.csharmonic.offline.mincfg.vo.*;
import com.njcn.csharmonic.offline.mincfg.vo.RTC_Timer_MS;
import com.njcn.csharmonic.offline.mincfg.vo.tagPQDataCmn;
import com.njcn.csharmonic.offline.mincfg.vo.tagPQDataCmnHh;
import com.njcn.influx.pojo.po.cs.PqdData;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
@@ -134,7 +140,7 @@ public class AnalyseComtradeCfg {
//电能质量只有电压偏差,上偏差正下偏差负判断上偏差是否为0如果为0取下偏差负数反正取上偏差
hashMapA.put("pq_UDev",AnalyseComtradeCfg.isZero(uuDeviation[0])?(-ulDeviation[0]):uuDeviation[0]);
hashMapB.put("pq_UDev",AnalyseComtradeCfg.isZero(uuDeviation[1])?(-ulDeviation[1]):uuDeviation[1]);
hashMapC.put("pq_RmsU",AnalyseComtradeCfg.isZero(uuDeviation[2])?(-ulDeviation[2]):uuDeviation[2]);
hashMapC.put("pq_UDev",AnalyseComtradeCfg.isZero(uuDeviation[2])?(-ulDeviation[2]):uuDeviation[2]);
hashMapAB.put("pq_LUDev",AnalyseComtradeCfg.isZero(uuDeviation[3])?(-ulDeviation[3]):uuDeviation[3]);
hashMapBC.put("pq_LUDev",AnalyseComtradeCfg.isZero(uuDeviation[4])?(-ulDeviation[4]):uuDeviation[4]);
hashMapCA.put("pq_LUDev",AnalyseComtradeCfg.isZero(uuDeviation[5])?(-ulDeviation[5]):uuDeviation[5]);
@@ -522,8 +528,8 @@ public class AnalyseComtradeCfg {
}
}
public static List<tagComtradeCfg> convertCfgFile(String strFilePath) { //解析cfg录波文件
List<tagComtradeCfg> tagComtradeCfgList = new ArrayList<>();
public static List<TagComtradeCfg> convertCfgFile(String strFilePath) { //解析cfg录波文件
List<TagComtradeCfg> tagComtradeCfgList = new ArrayList<>();
// File folder = new File(strFilePath);
// File[] files = folder.listFiles((dir, name) -> name.endsWith(".cfg")); //获取文件夹下所有cfg文件
// Arrays.stream(files).forEach(file -> {
@@ -539,8 +545,8 @@ public class AnalyseComtradeCfg {
* @Author: clam
* @Date: 2024/7/15
*/
public static tagComtradeCfg analyseComtradeCfg(MultipartFile file) {
tagComtradeCfg comtradeCfg = new tagComtradeCfg();
public static TagComtradeCfg analyseComtradeCfg(MultipartFile file) {
TagComtradeCfg comtradeCfg = new TagComtradeCfg();
String strFilePath = file.getOriginalFilename();
int i = 0; //用于遍历 字符串转换的字段数组
String strFileLine;//临时存放 cfg每行读取的字符串
@@ -551,7 +557,7 @@ public class AnalyseComtradeCfg {
InputStream readFile = file.getInputStream();
InputStreamReader isr = new InputStreamReader(readFile, StandardCharsets.UTF_8);
BufferedReader sr = new BufferedReader(isr);
comtradeCfg = new tagComtradeCfg();//配置文件总类对象初始化
comtradeCfg = new TagComtradeCfg();//配置文件总类对象初始化
ratesCfg = new tagRates();//多段采样类对象初始化
long nFreq = 0; //临时存放 采样频率 例50Hz
//第一行不关心仅仅是一些描述类的信息
@@ -562,65 +568,65 @@ public class AnalyseComtradeCfg {
for (i = 0; i < strTempArray.length; i++) {
switch (i) {
case 0: //通道总个数
comtradeCfg.nChannelNum = Integer.parseInt(strTempArray[i]);
comtradeCfg.setNChannelNum(Integer.parseInt(strTempArray[i]));
break;
case 1: //模拟量的个数
String str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
comtradeCfg.nAnalogNum = Integer.parseInt(str);
comtradeCfg.setNAnalogNum(Integer.parseInt(str));
break;
case 2://开关量的个数
str = strTempArray[i].substring(0, strTempArray[i].length() - 1);
comtradeCfg.nDigitalNum = Integer.parseInt(str);
comtradeCfg.setNDigitalNum(Integer.parseInt(str));
break;
}
}
//从第三行到第ComtradeCfg.nChannelNum+3行是模拟量通道和数字量通道
List<tagOneChannleCfg> OneChannleCfgList =new ArrayList<>();
for (i = 0; i < comtradeCfg.nChannelNum; i++) {
tagOneChannleCfg oneChannlecfg = new tagOneChannleCfg();
ArrayList<TagOneChannleCfg> OneChannleCfgList =new ArrayList<>();
for (i = 0; i < comtradeCfg.getNChannelNum(); i++) {
TagOneChannleCfg oneChannlecfg = new TagOneChannleCfg();
strFileLine = sr.readLine(); // ③ or ④ or ⑤
strTempArray = strFileLine.split(",");
for (int j = 0; j < strTempArray.length; j++) {
switch (j) {
case 0://通道序号
oneChannlecfg.nIndex = Integer.parseInt(strTempArray[j]);
oneChannlecfg.setNIndex(Integer.parseInt(strTempArray[j]));
break;
case 1://通道名称
oneChannlecfg.szChannleName = strTempArray[j];
oneChannlecfg.setSzChannleName(strTempArray[j]);
break;
case 2://监视的通道名称
oneChannlecfg.szPhasicName = strTempArray[j];
oneChannlecfg.setSzPhasicName(strTempArray[j]);
break;
case 3://监视的通道名称
oneChannlecfg.szMonitoredChannleName = strTempArray[j];
oneChannlecfg.setSzMonitoredChannleName(strTempArray[j]);
break;
case 4://通道的单位
oneChannlecfg.szUnitName = strTempArray[j];
oneChannlecfg.setSzUnitName(strTempArray[j]);
break;
case 5://通道的系数
oneChannlecfg.fCoefficent = Float.parseFloat(strTempArray[j]);
oneChannlecfg.setFCoefficent(Float.parseFloat(strTempArray[j]));
break;
case 6://通道的偏移量
oneChannlecfg.fOffset = Float.parseFloat(strTempArray[j]);
oneChannlecfg.setFOffset(Float.parseFloat(strTempArray[j]));
break;
case 7://起始采样时间的偏移量
oneChannlecfg.fTimeOffset = Float.parseFloat(strTempArray[j]);
oneChannlecfg.setFTimeOffset( Float.parseFloat(strTempArray[j]));
break;
case 8://采样值的最小值
oneChannlecfg.nMin = Integer.parseInt(strTempArray[j]);
oneChannlecfg.setNMin( Integer.parseInt(strTempArray[j]));
break;
case 9://采样值的最大值
oneChannlecfg.nMax = Integer.parseInt(strTempArray[j]);
oneChannlecfg.setNMax(Integer.parseInt(strTempArray[j]));
break;
case 10://一次变比
oneChannlecfg.fPrimary = Float.parseFloat(strTempArray[j]);
oneChannlecfg.setFPrimary( Float.parseFloat(strTempArray[j]));
break;
case 11://二次变比
oneChannlecfg.fSecondary = Float.parseFloat(strTempArray[j]);
oneChannlecfg.setFSecondary(Float.parseFloat(strTempArray[j]));
break;
case 12://一次值还是二次值标志
oneChannlecfg.szValueType = strTempArray[j];
oneChannlecfg.setSzValueType(strTempArray[j]);
break;
}
}
@@ -664,21 +670,21 @@ public class AnalyseComtradeCfg {
sr.close();
readFile.close();
return comtradeCfg;
return new TagComtradeCfg();
}
//波形起始时间
strFileLine = sr.readLine(); // ⑨
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy,HH:mm:ss.SSSSSS");
comtradeCfg.setTimeTrigger(sdf.parse(strFileLine));
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("dd/MM/yyyy,HH:mm:ss.SSSSSS");
comtradeCfg.setTimeTrigger(LocalDateTime.parse(strFileLine, sdf));
strFileLine = sr.readLine(); // ⑩
comtradeCfg.setTimeStart(sdf.parse(strFileLine));
comtradeCfg.setTimeEnd(new Date(comtradeCfg.getTimeStart().getTime() + nMSTotal));;
comtradeCfg.setTimeStart(LocalDateTime.parse(strFileLine, sdf));
comtradeCfg.setTimeEnd(comtradeCfg.getTimeStart().plusSeconds(nMSTotal/1000L));;
comtradeCfg.setPath(file.getOriginalFilename());
sr.close();
readFile.close();
} catch (IOException | ParseException e) {
} catch (IOException e) {
System.out.println("Error opening file: " + strFilePath + " " + e.getMessage());
return comtradeCfg;
}
@@ -686,6 +692,81 @@ public class AnalyseComtradeCfg {
return comtradeCfg;
}
public static CmnModeCfg convertRecord(String strFile) {
File file = new File(strFile);
if (file.length() == 0) {
System.out.println("文件 " + strFile + " 长度为0字节程序将跳过本文件的转换");
}
long nBufSize = file.length();
int n1BufLen = PrjRecordInfo.GetSize();
int n2BufLen = CmnModeCfg.GetSize();
PrjRecordInfo prjRecordInfo = new PrjRecordInfo();
CmnModeCfg cmnModeCfg = new CmnModeCfg();
if (nBufSize == n1BufLen) {
byte[] bBuf = new byte[0];
try {
bBuf = Files.readAllBytes(Paths.get(strFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
prjRecordInfo.SetStructBuf(bBuf, 0);
CmnModeCfg recordInfo = prjRecordInfo.cfg;
} else if (nBufSize == n2BufLen) {
byte[] bBuf = new byte[0];
try {
bBuf = Files.readAllBytes(Paths.get(strFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
cmnModeCfg.SetStructBuf(bBuf, 0);
CmnModeCfg recordInfo = cmnModeCfg;
} else {
System.out.println("解析配置参数文件异常");
}
return cmnModeCfg;
}
public static CmnModeCfg convertRecord(InputStream fileStream) {
PrjRecordInfo prjRecordInfo = new PrjRecordInfo();
CmnModeCfg cmnModeCfg = new CmnModeCfg();
try {
int nBufSize = fileStream.available();//计算需要解析的文件总长
int n1BufLen = PrjRecordInfo.GetSize();
int n2BufLen = CmnModeCfg.GetSize();
if (nBufSize == n1BufLen) {
byte[] bBuf = new byte[nBufSize];
fileStream.read(bBuf, 0, n1BufLen);
prjRecordInfo.SetStructBuf(bBuf, 0);
cmnModeCfg = prjRecordInfo.cfg;
} else if (nBufSize == n2BufLen) {
byte[] bBuf = new byte[nBufSize];
fileStream.read(bBuf, 0, n2BufLen);
cmnModeCfg.SetStructBuf(bBuf, 0);
} else {
System.out.println("解析配置参数文件异常");
}
} catch (IOException e) {
throw new RuntimeException(e);
}finally {
try {
fileStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return cmnModeCfg;
}
public static void main(String[] args) throws IOException {
// tagComtradeCfg tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg("C:\\Users\\Administrator\\Desktop\\浙江无线\\离线数据上传\\09\\comtrade\\line1_20240704_143908_213.cfg");
// System.out.println(tagComtradeCfg);

View File

@@ -1,28 +0,0 @@
package com.njcn.csharmonic.offline.mincfg;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Description:
* Date: 2024/7/15 15:40【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Data
public class tagComtradeCfg implements Serializable {
public int nChannelNum; //通道总个数
public int nAnalogNum; //模拟量通道的个数 WW 2013-05-15
public int nDigitalNum; //数字量通道的个数 WW 2013-05-15
public List<tagOneChannleCfg> OneChannleCfg; //模拟量通道记录类链表
public List<tagOneChannleCfg_digital> OneChannleCfgDig; //数字量通道记录类链表
public Date TimeTrigger; //暂态触发时间
public Date TimeStart; //波形起始时间 注相较于TimeTrigger波形触发时间起始有一段平滑过渡波形时间约100ms
public Date TimeEnd; //波形结束时间
public String path;//对应波形cfg文件全路径名称
}

View File

@@ -5,7 +5,7 @@ package com.njcn.csharmonic.offline.mincfg.vo;
装置普测工程配置信息
*/
public class cmn_mode_cfg
public class CmnModeCfg
{
public byte[] prj_name = new byte[128]; //工程名称
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:

View File

@@ -4,10 +4,10 @@ package com.njcn.csharmonic.offline.mincfg.vo;
工程数据文件信息
*/
public class prj_record_info
public class PrjRecordInfo
{
public pqv_dev_info_int dev_info; //装置信息
public cmn_mode_cfg cfg; //测试记录工程配置
public CmnModeCfg cfg; //测试记录工程配置
public prj_store_info store_mag; //存储管理缓冲
public int tv_sec_s; //开始记录时间
public int tv_sec_e; //结束记录时间
@@ -15,16 +15,16 @@ public class prj_record_info
//ORIGINAL LINE: public uint status;
public int status; //测试工程数据是否有效标志
public prj_record_info()
public PrjRecordInfo()
{
dev_info = new pqv_dev_info_int();
cfg = new cmn_mode_cfg();
cfg = new CmnModeCfg();
store_mag = new prj_store_info();
}
public static int GetSize() //用于定义Byte数组
{
//C# TO JAVA CONVERTER TODO TASK: There is no Java equivalent to 'sizeof':
int nSize = 2 * Integer.SIZE / Byte.SIZE + 1 * Integer.SIZE / Byte.SIZE + pqv_dev_info_int.GetSize() + cmn_mode_cfg.GetSize() + prj_store_info.GetSize(); //CComtradeDataItem数据结构数据长度
int nSize = 2 * Integer.SIZE / Byte.SIZE + 1 * Integer.SIZE / Byte.SIZE + pqv_dev_info_int.GetSize() + CmnModeCfg.GetSize() + prj_store_info.GetSize(); //CComtradeDataItem数据结构数据长度
return nSize;
}
public final boolean SetStructBuf(byte[] bArray, int nHaveRead)
@@ -39,7 +39,7 @@ public class prj_record_info
dev_info.SetStructBuf(bArray, iStep);
iStep = iStep + pqv_dev_info_int.GetSize();
cfg.SetStructBuf(bArray, iStep);
iStep = iStep + cmn_mode_cfg.GetSize();
iStep = iStep + CmnModeCfg.GetSize();
store_mag.SetStructBuf(bArray, iStep);
iStep = iStep + prj_store_info.GetSize();
tv_sec_s = Service.convertInt32_net(bArray, iStep);
@@ -66,7 +66,7 @@ public class prj_record_info
dev_info.SetStructBuf(bArray, iStep);
iStep = iStep + pqv_dev_info_int.GetSize();
cfg.SetStructBuf_net(bArray, iStep);
iStep = iStep + cmn_mode_cfg.GetSize();
iStep = iStep + CmnModeCfg.GetSize();
store_mag.SetStructBuf_net(bArray, iStep);
iStep = iStep + prj_store_info.GetSize();
tv_sec_s = Service.convertInt32(bArray, iStep);

View File

@@ -22,6 +22,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -91,4 +92,13 @@ public class CsEventController extends BaseController {
csEventPOService.saveBatchEventList(csEventPOS);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryByIndex")
@ApiOperation("根据表唯一索引查询(用于校验是否存在该事件)")
public HttpResult<CsEventPO> queryByIndex(@RequestBody CsEventPO csEventPO) {
String methodDescribe = getMethodDescribe("queryByIndex");
CsEventPO po = csEventPOService.lambdaQuery().eq(CsEventPO::getDeviceId,csEventPO.getDeviceId()).eq(CsEventPO::getTag,csEventPO.getTag()).eq(CsEventPO::getStartTime,csEventPO.getStartTime()).one();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
}

View File

@@ -46,11 +46,11 @@
<artifactId>pqs-influx</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>dynamic-datasource-spring-boot-starter</artifactId>-->
<!-- <version>3.5.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
@@ -111,6 +111,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>harmonic-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@@ -67,11 +67,11 @@ public class ReportCovertJob {
/**
* 每小时同步oracle数据库暂态事件
* 每天同步influxdb数据到mysql
*
* @date 2024/3/5
*/
@Scheduled(cron = "0 0/10 * * * ?")
@Scheduled(cron = "0 0 1 * * ? ")
public void executeEvent() throws ClassNotFoundException {
LocalDate today = LocalDate.now().minusDays(3);
// 计算前一天的日期