|
@@ -9,7 +9,6 @@ import com.jiayue.ipp.common.data.entity.an.ParsingNbqInfo;
|
|
import com.jiayue.ipp.common.data.entity.an.ParsingUrl;
|
|
import com.jiayue.ipp.common.data.entity.an.ParsingUrl;
|
|
import com.jiayue.ipp.common.data.enums.FileTypeEnum;
|
|
import com.jiayue.ipp.common.data.enums.FileTypeEnum;
|
|
import com.jiayue.ipp.idp.dto.FileAnalysisStatusDto;
|
|
import com.jiayue.ipp.idp.dto.FileAnalysisStatusDto;
|
|
-import com.jiayue.ipp.idp.dto.ParsingConstant;
|
|
|
|
import com.jiayue.ipp.idp.mapper.an.ParsingNbqInfoMapper;
|
|
import com.jiayue.ipp.idp.mapper.an.ParsingNbqInfoMapper;
|
|
import com.jiayue.ipp.idp.service.InverterInfoService;
|
|
import com.jiayue.ipp.idp.service.InverterInfoService;
|
|
import com.jiayue.ipp.idp.service.InverterStatusDataService;
|
|
import com.jiayue.ipp.idp.service.InverterStatusDataService;
|
|
@@ -23,9 +22,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.time.Instant;
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.ZoneId;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -62,73 +59,70 @@ public class ParsingNbqInfoServiceImpl extends ServiceImpl<ParsingNbqInfoMapper,
|
|
fileAnalysisStatusDto.setFileType(FileTypeEnum.NBQ.getCode()+"");
|
|
fileAnalysisStatusDto.setFileType(FileTypeEnum.NBQ.getCode()+"");
|
|
|
|
|
|
try {
|
|
try {
|
|
-
|
|
|
|
//查询符合该场站的nbq配置信息
|
|
//查询符合该场站的nbq配置信息
|
|
List<ParsingNbqInfo> parsingNbqInfos = baseMapper.selectList(Wrappers.lambdaQuery(ParsingNbqInfo.class).like(ParsingInfo::getStationCode, ftpParsingUrl.getStationCode()));
|
|
List<ParsingNbqInfo> parsingNbqInfos = baseMapper.selectList(Wrappers.lambdaQuery(ParsingNbqInfo.class).like(ParsingInfo::getStationCode, ftpParsingUrl.getStationCode()));
|
|
if (parsingNbqInfos.size() > 0) {
|
|
if (parsingNbqInfos.size() > 0) {
|
|
-
|
|
|
|
- //解析文件内容以行为单位的 List<String>
|
|
|
|
- List<String> fileContent = FileUtil.getFileContent(file);
|
|
|
|
-
|
|
|
|
- //查询对应该场站路径下的逆变器信息
|
|
|
|
- List<InverterInfo> inverterInfoList = inverterInfoService.list(Wrappers.lambdaQuery(InverterInfo.class).eq(InverterInfo::getStationCode, ftpParsingUrl.getStationCode()));
|
|
|
|
-
|
|
|
|
- //因为有可能该场站有多种解析配置,例如多个逆变器数据情况,需要循环解析信息
|
|
|
|
for (ParsingNbqInfo parsingNbqInfo : parsingNbqInfos) {
|
|
for (ParsingNbqInfo parsingNbqInfo : parsingNbqInfos) {
|
|
//判断文件名是否符合配置
|
|
//判断文件名是否符合配置
|
|
if (file.getName().indexOf(parsingNbqInfo.getFileName()) >= 0) {
|
|
if (file.getName().indexOf(parsingNbqInfo.getFileName()) >= 0) {
|
|
-
|
|
|
|
- //判断数据类型是单行还是多行
|
|
|
|
-// if (parsingNbqInfo.getDataType().equals(FieldUtil.SINGLE)) {
|
|
|
|
-// /**
|
|
|
|
-// * 逆变器和风机id 需要解析名称找出对应设备存入id
|
|
|
|
-// *
|
|
|
|
-// */
|
|
|
|
-// String nbqName = parsingName(parsingNbqInfo.getEquipmentName(), fileContent);
|
|
|
|
-// List<InverterInfo> filterInverterInfos = inverterInfoList.stream().filter(i -> i.getName().equals(nbqName)).collect(Collectors.toList());
|
|
|
|
-// if (filterInverterInfos.size() > 0) {
|
|
|
|
-// Long time = parsingTime(parsingNbqInfo.getTime(), fileContent);
|
|
|
|
-// if (time != 0l) {
|
|
|
|
-// InverterStatusData inverterStatusData = new InverterStatusData();
|
|
|
|
-// LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
|
|
|
|
-// inverterStatusData.setTime(localDateTime);
|
|
|
|
-//
|
|
|
|
-// inverterStatusData.setActivePower(parsingValue(parsingNbqInfo.getActivePower(), fileContent));
|
|
|
|
-// inverterStatusData.setCumulativeGeneratedEnergy(parsingValue(parsingNbqInfo.getCumulativeGeneratedEnergy(), fileContent));
|
|
|
|
-// inverterStatusData.setDayGridConnectedHours(parsingValue(parsingNbqInfo.getDayGridConnectedHours(), fileContent));
|
|
|
|
-// inverterStatusData.setDayElectricQuantity(parsingValue(parsingNbqInfo.getDayElectricQuantity(), fileContent));
|
|
|
|
-// inverterStatusData.setElectricalCurrent(parsingValue(parsingNbqInfo.getElectricalCurrent(), fileContent));
|
|
|
|
-// inverterStatusData.setReactivePower(parsingValue(parsingNbqInfo.getReactivePower(), fileContent));
|
|
|
|
-// inverterStatusData.setPowerFactor(parsingValue(parsingNbqInfo.getPowerFactor(), fileContent));
|
|
|
|
-// inverterStatusData.setVoltage(parsingValue(parsingNbqInfo.getVoltage(), fileContent));
|
|
|
|
-// inverterStatusData.setStatus(parsingStatus(parsingNbqInfo.getStatus(), fileContent));
|
|
|
|
-// inverterStatusData.setEquipmentId(filterInverterInfos.get(0).getEquipmentNo());
|
|
|
|
-// inverterStatusData.setStationCode(ftpParsingUrl.getStationCode());
|
|
|
|
-// inverterStatusDataService.save(inverterStatusData);
|
|
|
|
-// log.info("解析NBQ文件:{} 成功! O(∩_∩)O", file.getName());
|
|
|
|
-// fileAnalysisStatusDto.setStatus("1");
|
|
|
|
-// } else {
|
|
|
|
-// fileAnalysisStatusDto.setStatus("0");
|
|
|
|
-// fileAnalysisStatusDto.setMessage("逆变器在本地无配置无法解析");
|
|
|
|
-// log.info("nbq {} 在本地无配置无法解析", nbqName);
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// fileAnalysisStatusDto.setStatus("0");
|
|
|
|
-// fileAnalysisStatusDto.setMessage("解析逆变器文件时间错误");
|
|
|
|
-// log.error("解析NBQ文件时间错误");
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// fileAnalysisStatusDto.setStatus("0");
|
|
|
|
-// fileAnalysisStatusDto.setMessage("逆变器暂无多行解析方式");
|
|
|
|
-// log.info("nbq暂无多行解析方式");
|
|
|
|
-// }
|
|
|
|
|
|
+ List<InverterStatusData> inverterStatusDataList = new ArrayList<>();
|
|
|
|
+ if (parsingNbqInfo.getDataType().equals(FieldUtil.SINGLE)) {
|
|
|
|
+ //查询对应该场站路径下的逆变器信息
|
|
|
|
+ List<InverterInfo> inverterInfoList = inverterInfoService.list(Wrappers.lambdaQuery(InverterInfo.class).eq(InverterInfo::getStationCode, ftpParsingUrl.getStationCode()));
|
|
|
|
+ //解析文件内容以行为单位的 List<String>
|
|
|
|
+ List<String> fileContent = FileUtil.getFileContent(file);
|
|
|
|
+ // 对#号开头的数据行获取
|
|
|
|
+ for (String str: fileContent){
|
|
|
|
+ if (str.startsWith("#")){
|
|
|
|
+ String nbqName = parsingName(parsingNbqInfo.getEquipmentName(), str);
|
|
|
|
+ List<InverterInfo> filterInverterInfos = inverterInfoList.stream().filter(i -> i.getName().equals(nbqName)).collect(Collectors.toList());
|
|
|
|
+ if (filterInverterInfos.size() > 0) {
|
|
|
|
+ InverterStatusData inverterStatusData = new InverterStatusData();
|
|
|
|
+ inverterStatusData.setEquipmentId(filterInverterInfos.get(0).getEquipmentNo());
|
|
|
|
+ Long time = parsingTime(parsingNbqInfo.getTime(), fileContent);
|
|
|
|
+ if (time != 0l) {
|
|
|
|
+ inverterStatusData.setActivePower(parsingRowValue(parsingNbqInfo.getActivePower(), str));
|
|
|
|
+ inverterStatusData.setCumulativeGeneratedEnergy(parsingRowValue(parsingNbqInfo.getCumulativeGeneratedEnergy(), str));
|
|
|
|
+ inverterStatusData.setDayGridConnectedHours(parsingRowValue(parsingNbqInfo.getDayGridConnectedHours(), str));
|
|
|
|
+ inverterStatusData.setDayElectricQuantity(parsingRowValue(parsingNbqInfo.getDayElectricQuantity(), str));
|
|
|
|
+ inverterStatusData.setElectricalCurrent(parsingRowValue(parsingNbqInfo.getElectricalCurrent(), str));
|
|
|
|
+ inverterStatusData.setReactivePower(parsingRowValue(parsingNbqInfo.getReactivePower(), str));
|
|
|
|
+ inverterStatusData.setPowerFactor(parsingRowValue(parsingNbqInfo.getPowerFactor(), str));
|
|
|
|
+ inverterStatusData.setVoltage(parsingRowValue(parsingNbqInfo.getVoltage(), str));
|
|
|
|
+ inverterStatusData.setStatus(parsingRowStatus(parsingNbqInfo.getStatus(), str));
|
|
|
|
+ inverterStatusData.setStationCode(ftpParsingUrl.getStationCode());
|
|
|
|
+ } else {
|
|
|
|
+ fileAnalysisStatusDto.setStatus("0");
|
|
|
|
+ fileAnalysisStatusDto.setMessage("解析逆变器文件时间错误");
|
|
|
|
+ log.error("解析NBQ文件时间错误");
|
|
|
|
+ }
|
|
|
|
+ inverterStatusDataList.add(inverterStatusData);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ fileAnalysisStatusDto.setStatus("0");
|
|
|
|
+ fileAnalysisStatusDto.setMessage("逆变器缺少配置无法解析");
|
|
|
|
+ log.info("逆变器 {} 缺少配置无法解析", nbqName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ fileAnalysisStatusDto.setStatus("0");
|
|
|
|
+ fileAnalysisStatusDto.setMessage("逆变器暂无多行解析方式");
|
|
|
|
+ log.info("nbq暂无多行解析方式");
|
|
|
|
+ }
|
|
|
|
+ if (!"0".equals(fileAnalysisStatusDto.getStatus()) && inverterStatusDataList.size() > 0){
|
|
|
|
+ inverterStatusDataService.saveBatch(inverterStatusDataList);
|
|
|
|
+ log.info("解析NBQ文件:" + file.getName() + " 成功! O(∩_∩)O");
|
|
|
|
+ fileAnalysisStatusDto.setStatus("1");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
fileAnalysisStatusDto.setStatus("0");
|
|
fileAnalysisStatusDto.setStatus("0");
|
|
- fileAnalysisStatusDto.setMessage("解析逆变器数据失败!");
|
|
|
|
- log.error("解析逆变器数据失败! /(ㄒoㄒ)/~~", e);
|
|
|
|
|
|
+ fileAnalysisStatusDto.setMessage("解析逆变器数据错误!");
|
|
|
|
+ log.error("解析逆变器数据错误!", e);
|
|
} finally {
|
|
} finally {
|
|
return fileAnalysisStatusDto;
|
|
return fileAnalysisStatusDto;
|
|
}
|
|
}
|