Переглянути джерело

逆变器文件解析代码调整

xusl 6 місяців тому
батько
коміт
6cc57faf2f

+ 6 - 5
ipp-idp/src/main/java/com/jiayue/ipp/idp/api/CallForecastPowerUltraShortTermApi.java

@@ -219,7 +219,11 @@ public class CallForecastPowerUltraShortTermApi {
 
                 // 查询该时间段内的短期预测功率
                 List<ForecastPowerShortTerm> forecastPowerShortTermList = this.forecastPowerShortTermService.findByStationCodeAndStartTimeAndEndTimeAndForecastManufactor(stationCode, new Date(startTime), new Date(endTime),"SYJY");
-
+                if (forecastPowerShortTermList.size()>0){
+                    forecastPowerShortTermList.sort(Comparator.comparing(ForecastPowerShortTerm::getForecastTime));
+                    log.info("执行超短期预测生成。。。。。。{}",stationCode);
+                    this.executeForecastForWind(forecastPowerShortTermList, e.getCapacity(), e.getStationCode());
+                }
 //                Map<Date, List<ForecastPowerShortTerm>> forecastPowerShortTermsMap =
 //                        forecastPowerShortTermList.stream().collect(Collectors.groupingBy(ForecastPowerShortTerm::getForecastTime));
 
@@ -243,16 +247,13 @@ public class CallForecastPowerUltraShortTermApi {
 //                // 将补齐的预测功率追加到查询预测功率结果集中
 //                forecastPowerShortTermList.addAll(addForecastPowerShortTermList);
 //            }
-                forecastPowerShortTermList.sort(Comparator.comparing(ForecastPowerShortTerm::getForecastTime));
 
-
-                log.info("执行超短期预测生成。。。。。。{}",stationCode);
 //                if (ElectricFieldTypeEnum.E1.compareTo(electricField.getElectricFieldTypeEnum()) == 0) {
 //                    // 光伏电站
 //                    this.executeForecastForlight(forecastPowerShortTermList, electricField.getCapacity());
 //                } else if (ElectricFieldTypeEnum.E2.compareTo(electricField.getElectricFieldTypeEnum()) == 0) {
                 // 风力电场
-                this.executeForecastForWind(forecastPowerShortTermList, e.getCapacity(), e.getStationCode());
+
 //                }
 //                else {
 //                    log.error("场站类型非法!");

+ 1 - 2
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/an/FTPService.java

@@ -166,7 +166,7 @@ public class FTPService {
                     log.info("{}ftp下载文件并解析执行完成", ftpParsingChannel.getChannelName());
                 } catch (Exception e) {
                     log.error("{}ftp下载文件并解析过程失败", ftpParsingChannel.getChannelName());
-                    e.printStackTrace();
+//                    e.printStackTrace();
                 } finally {
                     try {
                         if (ftp != null) {
@@ -226,7 +226,6 @@ public class FTPService {
             log.info("{} :ftp连接成功", ftpConfig.getHost());
         } catch (Exception e) {
             log.error("{} :获取上送文件ftp连接失败", ftpConfig.getHost());
-            e.printStackTrace();
         } finally {
             return ftp;
         }

+ 54 - 60
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/impl/an/ParsingNbqInfoServiceImpl.java

@@ -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.enums.FileTypeEnum;
 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.service.InverterInfoService;
 import com.jiayue.ipp.idp.service.InverterStatusDataService;
@@ -23,9 +22,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 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.stream.Collectors;
 
@@ -62,73 +59,70 @@ public class ParsingNbqInfoServiceImpl extends ServiceImpl<ParsingNbqInfoMapper,
         fileAnalysisStatusDto.setFileType(FileTypeEnum.NBQ.getCode()+"");
 
         try {
-
             //查询符合该场站的nbq配置信息
             List<ParsingNbqInfo> parsingNbqInfos = baseMapper.selectList(Wrappers.lambdaQuery(ParsingNbqInfo.class).like(ParsingInfo::getStationCode, ftpParsingUrl.getStationCode()));
             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) {
                     //判断文件名是否符合配置
                     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) {
             fileAnalysisStatusDto.setStatus("0");
-            fileAnalysisStatusDto.setMessage("解析逆变器数据失败!");
-            log.error("解析逆变器数据失败! /(ㄒoㄒ)/~~", e);
+            fileAnalysisStatusDto.setMessage("解析逆变器数据错误!");
+            log.error("解析逆变器数据错误!", e);
         } finally {
             return fileAnalysisStatusDto;
         }