Ver código fonte

增加调控后短期解析时间校验(在指定时间之前不可上传解析)

tl 6 meses atrás
pai
commit
647695f7b1

+ 83 - 72
cpp-admin/src/main/java/com/cpp/web/service/datafactory/impl/ParsingRdqServiceImpl.java

@@ -9,6 +9,8 @@ import com.cpp.web.domain.datafactory.ParsingDq;
 import com.cpp.web.domain.datafactory.dto.ParsingConfParam;
 import com.cpp.web.domain.datafactory.dto.ParsingResultDto;
 import com.cpp.web.domain.datafactory.enums.FileTypeEnum;
+import com.cpp.web.domain.enums.AlarmEnum;
+import com.cpp.web.domain.enums.DataSourcesEnum;
 import com.cpp.web.domain.enums.UploadStatusEnum;
 import com.cpp.web.domain.regulation.TempShortRegulation;
 import com.cpp.web.domain.station.ForecastPowerShortTermRegulation;
@@ -21,10 +23,7 @@ import com.cpp.web.service.datafactory.ScheduledHelper;
 import com.cpp.web.service.regulation.TempShortRegulationService;
 import com.cpp.web.service.station.ForecastPowerShortTermRegulationService;
 import com.cpp.web.service.station.ForecastPowerShortTermSendService;
-import com.cpp.web.utils.DateTimeUtil;
-import com.cpp.web.utils.ParsingFieldUtil;
-import com.cpp.web.utils.ParsingFileUtil;
-import com.cpp.web.utils.ParsingUtil;
+import com.cpp.web.utils.*;
 import lombok.AllArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -89,81 +88,96 @@ public class ParsingRdqServiceImpl implements ParsingInterface {
         parsingResultDto.setFileType(FileTypeEnum.dq.name());
         parsingResultDto.setFileName(file.getName());
         try {
-            List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList = new ArrayList();
-            if (!this.parsingDqs.isEmpty()) {
-                ParsingDq parsingDqInfo = this.parsingDqs.get(0);
-                List<String> fileContent = ParsingFileUtil.getFileContent(file);
-                if (parsingDqInfo.getDataType().equals(ParsingFieldUtil.MULTI)) {//多行操作
-                    Date forecastTime = parsingForecastTime(parsingDqInfo.getForecastTime(), fileContent);
-                    Date genDate = DateTimeUtil.getDayStartTime(forecastTime.getTime() - 86400000L);
-                    String status = parsingUploadStatus("2<=>5<=>status=", fileContent);
-                    Date time = forecastTime;
-                    if (forecastTime != null) {//解析时间成功才可以进行以下操作
-                        if (parsingDqInfo.getFpValue() != null) {
-                            List<BigDecimal> fpValues = parsingFpValue(parsingDqInfo.getFpValue(), fileContent);
-                            if (fpValues.size() > 0) {
-                                BigDecimal capacity = parsingValue(parsingDqInfo.getCapacity(), fileContent);
-                                for (BigDecimal fpValue : fpValues) {
-                                    ForecastPowerShortTermRegulation forecastPowerShortTermRegulation = new ForecastPowerShortTermRegulation();
-                                    forecastPowerShortTermRegulation.setStationCode(stationCode);
-                                    forecastPowerShortTermRegulation.setFpValue(fpValue);
-                                    forecastPowerShortTermRegulation.setGenDate(genDate);
-                                    forecastPowerShortTermRegulation.setTime(time);
-                                    forecastPowerShortTermRegulation.setForecastHowLongAgo(calcHowLongAgo(forecastTime, time));
-                                    forecastPowerShortTermRegulation.setCapacity(capacity);
-                                    forecastPowerShortTermRegulationList.add(forecastPowerShortTermRegulation);
-                                    time = new Date(time.getTime() + 900000L);//递增15分钟
-                                }
-                                int dqDay = 10;
-                                try {
-                                    dqDay = Integer.parseInt(configService.selectConfigByKey("require_dq_day"));
-                                } catch (Exception e) {
-                                }
-                                if (forecastPowerShortTermRegulationList.size() == dqDay * 96) {
-                                    List<BigDecimal> openCapacityList = parsingOpenCapacityValue(parsingDqInfo.getOpenCapacity(), fileContent);
-                                    if (openCapacityList != null && openCapacityList.size() == fpValues.size()) {
-                                        for (int i = 0; i < forecastPowerShortTermRegulationList.size(); i++) {
-                                            forecastPowerShortTermRegulationList.get(i).setOpenCapacity(openCapacityList.get(i));
-                                        }
+
+            String dqEndTime = configService.selectConfigByKey("dqEndTime");
+            if (dqEndTime.equals(StringUtils.EMPTY)) {
+                dqEndTime = "08:00";
+            }
+
+            if (dqEndTime.compareTo(DateFormatUtils.format(new Date(), "HH:mm")) < 0) {
+
+                List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList = new ArrayList();
+                if (!this.parsingDqs.isEmpty()) {
+                    ParsingDq parsingDqInfo = this.parsingDqs.get(0);
+                    List<String> fileContent = ParsingFileUtil.getFileContent(file);
+                    if (parsingDqInfo.getDataType().equals(ParsingFieldUtil.MULTI)) {//多行操作
+                        Date forecastTime = parsingForecastTime(parsingDqInfo.getForecastTime(), fileContent);
+                        Date genDate = DateTimeUtil.getDayStartTime(forecastTime.getTime() - 86400000L);
+                        String status = parsingUploadStatus("2<=>5<=>status=", fileContent);
+                        Date time = forecastTime;
+                        if (forecastTime != null) {//解析时间成功才可以进行以下操作
+                            if (parsingDqInfo.getFpValue() != null) {
+                                List<BigDecimal> fpValues = parsingFpValue(parsingDqInfo.getFpValue(), fileContent);
+                                if (fpValues.size() > 0) {
+                                    BigDecimal capacity = parsingValue(parsingDqInfo.getCapacity(), fileContent);
+                                    for (BigDecimal fpValue : fpValues) {
+                                        ForecastPowerShortTermRegulation forecastPowerShortTermRegulation = new ForecastPowerShortTermRegulation();
+                                        forecastPowerShortTermRegulation.setStationCode(stationCode);
+                                        forecastPowerShortTermRegulation.setFpValue(fpValue);
+                                        forecastPowerShortTermRegulation.setGenDate(genDate);
+                                        forecastPowerShortTermRegulation.setTime(time);
+                                        forecastPowerShortTermRegulation.setForecastHowLongAgo(calcHowLongAgo(forecastTime, time));
+                                        forecastPowerShortTermRegulation.setCapacity(capacity);
+                                        forecastPowerShortTermRegulationList.add(forecastPowerShortTermRegulation);
+                                        time = new Date(time.getTime() + 900000L);//递增15分钟
+                                    }
+                                    int dqDay = 10;
+                                    try {
+                                        dqDay = Integer.parseInt(configService.selectConfigByKey("require_dq_day"));
+                                    } catch (Exception e) {
                                     }
-                                    scheduleAddCache(forecastPowerShortTermRegulationList, stationCode);
-                                    forecastPowerShortTermRegulationService.remove(
-                                            new QueryWrapper<ForecastPowerShortTermRegulation>()
-                                                    .eq("gen_date", genDate)
-                                                    .eq("station_code", stationCode)
-                                                    .between("time", forecastPowerShortTermRegulationList.get(0).getTime(), forecastPowerShortTermRegulationList.get(forecastPowerShortTermRegulationList.size() - 1).getTime()));
-
-                                    forecastPowerShortTermRegulationService.saveBatch(forecastPowerShortTermRegulationList);
-                                    log.info("[" + stationCode + "]解析调控后短期文件:{} 成功! O(∩_∩)O", file.getName());
-                                    parsingResultDto.setStatus("success");
-                                    //使用新线程写入状态,不会影响解析速度
-                                    SpringUtils.getBean(ThreadPoolTaskExecutor.class).execute(new Runnable() {
-                                        @Override
-                                        public void run() {
-                                            verifyRegulation(stationCode, forecastPowerShortTermRegulationList, forecastTime, status);
+                                    if (forecastPowerShortTermRegulationList.size() == dqDay * 96) {
+                                        List<BigDecimal> openCapacityList = parsingOpenCapacityValue(parsingDqInfo.getOpenCapacity(), fileContent);
+                                        if (openCapacityList != null && openCapacityList.size() == fpValues.size()) {
+                                            for (int i = 0; i < forecastPowerShortTermRegulationList.size(); i++) {
+                                                forecastPowerShortTermRegulationList.get(i).setOpenCapacity(openCapacityList.get(i));
+                                            }
                                         }
-                                    });
+                                        scheduleAddCache(forecastPowerShortTermRegulationList, stationCode);
+                                        forecastPowerShortTermRegulationService.remove(
+                                                new QueryWrapper<ForecastPowerShortTermRegulation>()
+                                                        .eq("gen_date", genDate)
+                                                        .eq("station_code", stationCode)
+                                                        .between("time", forecastPowerShortTermRegulationList.get(0).getTime(), forecastPowerShortTermRegulationList.get(forecastPowerShortTermRegulationList.size() - 1).getTime()));
+
+                                        forecastPowerShortTermRegulationService.saveBatch(forecastPowerShortTermRegulationList);
+                                        log.info("[" + stationCode + "]解析调控后短期文件:{} 成功! O(∩_∩)O", file.getName());
+                                        parsingResultDto.setStatus("success");
+                                        //使用新线程写入状态,不会影响解析速度
+                                        String finalDqEndTime = dqEndTime;
+                                        SpringUtils.getBean(ThreadPoolTaskExecutor.class).execute(new Runnable() {
+                                            @Override
+                                            public void run() {
+                                                verifyRegulation(finalDqEndTime, stationCode, forecastPowerShortTermRegulationList, forecastTime, status);
+                                            }
+                                        });
+                                    } else {
+                                        parsingResultDto.setMessage("解析调控后短期文件数据量与要求不一致");
+                                        log.error("[" + stationCode + "]解析调控后短期文件数据量与要求不一致,fileName:{}", file.getName());
+                                    }
                                 } else {
-                                    parsingResultDto.setMessage("解析调控后短期文件数据量与要求不一致");
-                                    log.error("[" + stationCode + "]解析调控后短期文件数据量与要求不一致,fileName:{}", file.getName());
+                                    parsingResultDto.setMessage("解析调控后短期文件时间错误");
+                                    log.error("[" + stationCode + "]解析调控后短期文件时间错误,fileName:{}", file.getName());
                                 }
                             } else {
-                                parsingResultDto.setMessage("解析调控后短期文件时间错误");
-                                log.error("[" + stationCode + "]解析调控后短期文件时间错误,fileName:{}", file.getName());
+                                parsingResultDto.setMessage("调控后短期文件里日期不对");
+                                log.error("[" + stationCode + "]调控后短期文件里日期不对,fileName:{}", file.getName());
                             }
                         } else {
-                            parsingResultDto.setMessage("调控后短期文件里日期不对");
-                            log.error("[" + stationCode + "]调控后短期文件里日期不对,fileName:{}", file.getName());
+                            parsingResultDto.setMessage("解析 调控后短期文件无数据");
+                            log.error("[" + stationCode + "]解析调控后短期文件无数据,fileName:{}", file.getName());
                         }
                     } else {
-                        parsingResultDto.setMessage("解析 调控后短期文件无数据");
-                        log.error("[" + stationCode + "]解析调控后短期文件无数据,fileName:{}", file.getName());
+                        parsingResultDto.setMessage("调控后短期暂无单行解析方式");
+                        log.info("[" + stationCode + "]调控后短期暂无单行解析方式,fileName:{}", file.getName());
                     }
-                } else {
-                    parsingResultDto.setMessage("调控后短期暂无单行解析方式");
-                    log.info("[" + stationCode + "]调控后短期暂无单行解析方式,fileName:{}", file.getName());
                 }
+            } else {
+                parsingResultDto.setMessage("调控后短期不允许提前上报!");
+                log.info("[" + stationCode + "]调控后短期提前上报!,fileName:{}", file.getName());
+                LogUtil.info(DataSourcesEnum.E1, AlarmEnum.E4, "调控后短期提前上报!", stationCode);
             }
+
         } catch (Exception e) {
             parsingResultDto.setMessage("解析调控后短期数据失败!");
             log.error("[" + stationCode + "]解析调控后短期数据失败! /(ㄒoㄒ)/~~,fileName:{}", file.getName(), e);
@@ -180,15 +194,12 @@ public class ParsingRdqServiceImpl implements ParsingInterface {
      * @param forecastTime
      * @param status
      */
-    private void verifyRegulation(String stationCode, List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList, Date forecastTime, String status) {
-        String dqEndTime = configService.selectConfigByKey("dqEndTime");
-        if (dqEndTime.equals(StringUtils.EMPTY)) {
-            dqEndTime = "08:00";
-        }
+    private void verifyRegulation(String dqEndTime, String stationCode, List<ForecastPowerShortTermRegulation> forecastPowerShortTermRegulationList, Date forecastTime, String status) {
         try {
             Long longTime = forecastTime.getTime() - 86400000L;
             Date startTime = DateTimeUtil.getDayStartTime(longTime);
             Date endTime = DateUtils.parseDate(DateFormatUtils.format(startTime, "yyyy-MM-dd " + dqEndTime), "yyyy-MM-dd HH:mm");
+
             QueryWrapper<TempShortRegulation> tk_date = new QueryWrapper<TempShortRegulation>().between("tk_date", startTime, endTime).eq("station_code", stationCode);
             List<TempShortRegulation> tempShortRegulations = tempShortRegulationService.list(tk_date);
             if (tempShortRegulations.size() > 0) {