فهرست منبع

调整人工干预下发与定时自动下发的整和,并将下发天数参数配置

xusl 9 ماه پیش
والد
کامیت
29900ed5cc

+ 2 - 2
ipp-ap/src/views/idp/control/dqIntervene/index.vue

@@ -188,7 +188,7 @@ export default {
         return
       }
 
-      if (this.bathForm.dqValue=='' ||this.bathForm.dqValue==null ){
+      if (this.bathForm.dqValue==null){
         this.$message.warning('请录入干预值!')
         return
       }
@@ -209,7 +209,7 @@ export default {
     closeDialog() {
       this.bathForm.startTime=''
       this.bathForm.endTime=''
-      this.bathForm.dqValue=''
+      this.bathForm.dqValue=0
       this.bathInterveneVisible = false
     },
     getStationCode() {

+ 7 - 52
ipp-idp/src/main/java/com/jiayue/ipp/idp/controller/DqInterveneController.java

@@ -13,6 +13,7 @@ import com.jiayue.ipp.idp.dto.ForecastData;
 import com.jiayue.ipp.idp.service.DqInterveneService;
 import com.jiayue.ipp.idp.service.an.ParsingChannelService;
 import com.jiayue.ipp.idp.service.an.ParsingUrlService;
+import com.jiayue.ipp.idp.service.impl.SendJyDqDataServiceImpl;
 import com.jiayue.ipp.idp.util.FileUtil;
 import com.jiayue.ipp.idp.util.R;
 import lombok.extern.slf4j.Slf4j;
@@ -47,6 +48,9 @@ public class DqInterveneController {
     @Autowired
     ParsingUrlService parsingUrlService;
 
+    @Autowired
+    SendJyDqDataServiceImpl sendDqDownloadFileImpl;
+
     /**
      * 获取短期干预
      */
@@ -84,7 +88,7 @@ public class DqInterveneController {
         }
         dqInterveneService.saveBatch(presetsShortList);
         // 下发短期干预
-        log.info(stationCode+"下发嘉越DQ数据开始:"+gyrq);
+        log.info(stationCode+"下发人工干预短期数据开始");
 
         LambdaQueryWrapper<ParsingUrl> urlWrapper = new LambdaQueryWrapper<>();
         urlWrapper.eq(ParsingUrl::getUrlStatus, "1");
@@ -99,61 +103,12 @@ public class DqInterveneController {
                 lambdaQueryWrapper.eq(ParsingChannel::getId, parsingUrl.getCId());
                 ParsingChannel parsingChannel = parsingChannelService.getOne(lambdaQueryWrapper);
                 if (parsingChannel!=null){
-                    String distPath = "/home"+ File.separator+parsingChannel.getUsername()+File.separator+"download";
-                    File dirFile = new File(distPath);
-                    if (!dirFile.exists()) {
-                        dirFile.mkdirs();
-                    }
-                    VelocityContext velocityContext = new VelocityContext();
-                    List<ForecastData> vList = new ArrayList<>();
-
-                    for (DqIntervene d1:presetsShortList) {
-                        ForecastData forecastData = new ForecastData();
-                        forecastData.setTime(DateFormatUtils.format(d1.getForecastTime(), "yyyy-MM-dd HH:mm:ss"));
-                        forecastData.setPower(d1.getActivePower().toString());
-                        vList.add(forecastData);
-                    }
-
-                    velocityContext.put("vList", vList);
-                    // 系统当前日期
-                    velocityContext.put("currentTime", DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
-                    StringWriter writer = new StringWriter();
-                    org.apache.velocity.Template template = this.velocityEngine.getTemplate(FileUtil.getResourceBasePath() + "/templates/send_dq.vm");
-                    template.merge(velocityContext, writer);
-
-                    String vmFileName = "send_"+stationCode+"_dq_"+gyrq+".WPD";
-                    createSendDqFile(writer,new File(distPath + File.separator+vmFileName));
-                    log.info(stationCode+"下发嘉越DQ数据成功:"+gyrq);
+                    sendDqDownloadFileImpl.sendDqDownloadFile(stationCode,parsingChannel.getUsername());
                 }
             }
         }
+        log.info(stationCode+"下发人工干预短期数据结束");
         return R.ok();
 
     }
-    /**
-     * 生成上报文件
-     *
-     * @param writer
-     * @param file
-     */
-    protected void createSendDqFile(StringWriter writer, File file) {
-        FileOutputStream os = null;
-        try {
-            os = new FileOutputStream(file);
-            // 采用UTF-8字符集
-            os.write(writer.toString().getBytes("UTF-8"));
-            os.flush();
-
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        } finally {
-            if (os != null) {
-                try {
-                    os.close();
-                } catch (IOException e) {
-                    log.error("文件生成关闭流失败", e);
-                }
-            }
-        }
-    }
 }

+ 63 - 190
ipp-idp/src/main/java/com/jiayue/ipp/idp/job/SendJyDqData.java

@@ -1,190 +1,63 @@
-//package com.jiayue.ipp.idp.job;
-//
-//import cn.hutool.core.io.IoUtil;
-//import cn.hutool.core.io.resource.ResourceUtil;
-//import cn.hutool.core.util.CharsetUtil;
-//import cn.hutool.extra.template.Template;
-//import cn.hutool.extra.template.TemplateConfig;
-//import cn.hutool.extra.template.TemplateEngine;
-//import cn.hutool.extra.template.TemplateUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
-//import com.jiayue.ipp.common.data.entity.DqIntervene;
-//import com.jiayue.ipp.common.data.entity.ForecastPowerShortTerm;
-//import com.jiayue.ipp.common.data.entity.an.ParsingChannel;
-//import com.jiayue.ipp.idp.dto.ForecastData;
-//import com.jiayue.ipp.idp.service.DqInterveneService;
-//import com.jiayue.ipp.idp.service.ForecastPowerShortTermService;
-//import com.jiayue.ipp.idp.service.an.ParsingChannelService;
-//import com.jiayue.ipp.idp.util.FileUtil;
-//import lombok.AllArgsConstructor;
-//import lombok.extern.slf4j.Slf4j;
-//import org.apache.commons.io.FileUtils;
-//import org.apache.commons.lang.time.DateFormatUtils;
-//import org.apache.commons.lang.time.DateUtils;
-//import org.apache.velocity.VelocityContext;
-//import org.apache.velocity.app.VelocityEngine;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.stereotype.Service;
-//
-//import java.io.File;
-//import java.io.FileOutputStream;
-//import java.io.IOException;
-//import java.io.StringWriter;
-//import java.util.*;
-//import java.util.stream.Collectors;
-//
-///**
-// * 下发嘉越短期数据
-// *
-// * @author jy
-// * @since 2024/07/01
-// */
-//@Service
-//@Slf4j
-//public class SendJyDqData {
-//
-//    @Value("${dqForecastDays}")
-//    private Integer dqForecastDays;
-//
-//    @Autowired
-//    ParsingChannelService parsingChannelService;
-//    @Autowired
-//    ForecastPowerShortTermService forecastPowerShortTermService;
-//    @Autowired
-//    VelocityEngine velocityEngine;
-//    @Autowired
-//    DqInterveneService dqInterveneService;
-//
-//    @Scheduled(cron = "0 0/1 * * * *")
-//    public void sendJyDqData() {
-//        log.info("下发嘉越DQ数据开始");
-//        // 获取ftp通道
-//        LambdaQueryWrapper<ParsingChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-//        lambdaQueryWrapper.eq(ParsingChannel::getAnChannelType, "E1");
-//        lambdaQueryWrapper.eq(ParsingChannel::getUseStatus, "E1");
-//        List<ParsingChannel> parsingChannels = parsingChannelService.list(lambdaQueryWrapper);
-//        String dateDir = DateFormatUtils.format(new Date(), "yyyyMMdd");
-//        //遍历解析路径,对文件进行解析
-//        for (ParsingChannel parsingChannel : parsingChannels) {
-//            try{
-//                String distPath = FileUtil.getSendJyDataPath()+File.separator+parsingChannel.getUsername()+File.separator+"download"+File.separator+dateDir;
-//                File dirFile = new File(distPath);
-//                if (!dirFile.exists()) {
-//                    dirFile.mkdirs();
-//                }
-//                // 生成短期文件
-//                String stationCode = parsingChannel.getUsername().split("-")[0];
-//                // 获取短期实时数据,开始时间
-//                Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(new Date(), 1).getTime());
-//                // 结束时间(开始加24小时再减去1秒)
-//                Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(new Date(), dqForecastDays).getTime());
-//
-//                // 查询短期预测功率
-//                LambdaQueryWrapper<ForecastPowerShortTerm> queryWrapper = new LambdaQueryWrapper<>();
-//                queryWrapper.eq(ForecastPowerShortTerm::getForecastManufactor, "SYJY");
-//                queryWrapper.eq(ForecastPowerShortTerm::getStationCode, stationCode);
-//                queryWrapper.between(ForecastPowerShortTerm::getForecastTime, new Date(startTime), new Date(endTime));
-//
-//                List<ForecastPowerShortTerm> forecastPowerShortTermList = this.forecastPowerShortTermService.list(queryWrapper);
-//                Map<Long, ForecastPowerShortTerm> forecastPowerShortMap = forecastPowerShortTermList.stream()
-//                        .collect(Collectors.toMap(
-//                                myObject -> myObject.getForecastTime().getTime(), // keyMapper,将Date转换为long
-//                                myObject -> myObject, // valueMapper,保持原对象
-//                                (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
-//                        ));
-//
-//                // 人工干预
-//                QueryWrapper<DqIntervene> dqInterveneQueryWrapper = new QueryWrapper<>();
-//                dqInterveneQueryWrapper.between("forecast_time", new Date(startTime), new Date(endTime));
-//                dqInterveneQueryWrapper.eq("station_code",stationCode);
-//                List<DqIntervene> dqInterveneList = dqInterveneService.list(dqInterveneQueryWrapper);
-//                Map<Long, DqIntervene> dqInterveneMap = dqInterveneList.stream()
-//                        .collect(Collectors.toMap(
-//                                myObject -> myObject.getForecastTime().getTime(), // keyMapper,将Date转换为long
-//                                myObject -> myObject, // valueMapper,保持原对象
-//                                (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
-//                        ));
-//
-//                List<ForecastData> vList = new ArrayList<>();
-//
-//                for (Long tempTime = startTime.longValue(); tempTime <= endTime.longValue(); tempTime = tempTime + 15 * 60 * 1000L) {
-//                    ForecastData forecastData = new ForecastData();
-//                    forecastData.setTime(DateFormatUtils.format(tempTime, "yyyy-MM-dd HH:mm:ss"));
-//                    if (dqInterveneMap.get(tempTime)!=null){
-//                        forecastData.setPower(dqInterveneMap.get(tempTime).getActivePower().toString());
-//                    }
-//                    else if (forecastPowerShortMap.get(tempTime)!=null){
-//                        forecastData.setPower(forecastPowerShortMap.get(tempTime).getFpValue().toString());
-//                    }
-//                    else{
-//                        forecastData.setPower("");
-//                    }
-//                    vList.add(forecastData);
-//                }
-//
-//                VelocityContext velocityContext = new VelocityContext();
-//                velocityContext.put("vList", vList);
-//                // 系统当前日期
-//                velocityContext.put("currentTime", DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
-//                StringWriter writer = new StringWriter();
-//                org.apache.velocity.Template template = this.velocityEngine.getTemplate(FileUtil.getResourceBasePath() + "/templates/send_dq.vm");
-//                template.merge(velocityContext, writer);
-//                String vmFileName = "send_"+stationCode+"_dq_"+dateDir+".WPD";
-//                createSendDqFile(writer,new File(distPath + File.separator+vmFileName));
-//
-//
-////                Map bindingMap = new HashMap();
-////                bindingMap.put("vList", forecastPowerShortTermHisList);
-////                String content = IoUtil.readUtf8(ResourceUtil.getStream("templates"+File.separator +"send_dq.vm"));
-////                Template templateDq = getTemplate(content);
-////                //渲染模型数据
-////                String vmStr = templateDq.render(bindingMap);
-////
-////                cn.hutool.core.io.FileUtil.writeString(vmStr, distPath + File.separator+vmFileName, CharsetUtil.UTF_8);
-//                log.info(stationCode+"下发嘉越DQ数据成功!");
-//            }
-//            catch (Exception e){
-//                e.printStackTrace();
-//            }
-//        }
-//        log.info("下发嘉越DQ数据结束");
-//
-//    }
-//    public static Template getTemplate(String templateStr) {
-//        //构造模板引擎
-//        TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
-//        Template template = engine.getTemplate(templateStr);
-//        return template;
-//    }
-//
-//    /**
-//     * 生成上报文件
-//     *
-//     * @param writer
-//     * @param file
-//     */
-//    protected void createSendDqFile(StringWriter writer, File file) {
-//        FileOutputStream os = null;
-//        try {
-//            os = new FileOutputStream(file);
-//            // 采用UTF-8字符集
-//            os.write(writer.toString().getBytes("UTF-8"));
-//            os.flush();
-//
-//        } catch (IOException e) {
-//            throw new RuntimeException(e);
-//        } finally {
-//            if (os != null) {
-//                try {
-//                    os.close();
-//                } catch (IOException e) {
-//                    log.error("文件生成关闭流失败", e);
-//                }
-//            }
-//        }
-//    }
-//}
+package com.jiayue.ipp.idp.job;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.jiayue.ipp.common.data.entity.an.ParsingChannel;
+import com.jiayue.ipp.common.data.entity.an.ParsingUrl;
+import com.jiayue.ipp.idp.service.DqInterveneService;
+import com.jiayue.ipp.idp.service.ForecastPowerShortTermService;
+import com.jiayue.ipp.idp.service.an.ParsingChannelService;
+import com.jiayue.ipp.idp.service.an.ParsingUrlService;
+import com.jiayue.ipp.idp.service.impl.SendJyDqDataServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.velocity.app.VelocityEngine;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+
+/**
+ * 下发嘉越短期数据
+ *
+ * @author jy
+ * @since 2024/07/01
+ */
+@Service
+@Slf4j
+public class SendJyDqData {
+    @Autowired
+    ParsingChannelService parsingChannelService;
+    @Autowired
+    ForecastPowerShortTermService forecastPowerShortTermService;
+    @Autowired
+    VelocityEngine velocityEngine;
+    @Autowired
+    DqInterveneService dqInterveneService;
+    @Autowired
+    SendJyDqDataServiceImpl sendDqDownloadFileImpl;
+    @Autowired
+    ParsingUrlService parsingUrlService;
+
+    @Scheduled(cron = "0 0 6 * * ?")
+    public void sendJyDqData() {
+        log.info("中心侧下发DQ数据定时开始");
+        // 获取ftp通道
+        LambdaQueryWrapper<ParsingChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(ParsingChannel::getAnChannelType, "E1");
+        lambdaQueryWrapper.eq(ParsingChannel::getUseStatus, "E1");
+        List<ParsingChannel> parsingChannels = parsingChannelService.list(lambdaQueryWrapper);
+        //遍历解析路径,对文件进行解析
+        for (ParsingChannel parsingChannel : parsingChannels) {
+            LambdaQueryWrapper<ParsingUrl> urlWrapper = new LambdaQueryWrapper<>();
+            urlWrapper.eq(ParsingUrl::getUrlStatus, "1");
+            urlWrapper.eq(ParsingUrl::getCId, parsingChannel.getId());
+            List<ParsingUrl> parsingUrlList = parsingUrlService.list(urlWrapper);
+            if (parsingUrlList.size()>0){
+                sendDqDownloadFileImpl.sendDqDownloadFile(parsingUrlList.get(0).getStationCode(),parsingChannel.getUsername());
+            }
+        }
+        log.info("中心侧下发DQ数据定时结束");
+
+    }
+}

+ 148 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/impl/SendJyDqDataServiceImpl.java

@@ -0,0 +1,148 @@
+package com.jiayue.ipp.idp.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
+import com.jiayue.ipp.common.data.entity.DqIntervene;
+import com.jiayue.ipp.common.data.entity.ForecastPowerShortTerm;
+import com.jiayue.ipp.idp.dto.ForecastData;
+import com.jiayue.ipp.idp.service.DqInterveneService;
+import com.jiayue.ipp.idp.service.ForecastPowerShortTermService;
+import com.jiayue.ipp.idp.service.SysParameterService;
+import com.jiayue.ipp.idp.util.FileUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * idp_inverter_info
+ *
+ * @author whc
+ * @date 2022-03-18 15:49:11
+ */
+@Service
+@Slf4j
+public class SendJyDqDataServiceImpl{
+    @Autowired
+    SysParameterService sysParameterService;
+    @Autowired
+    ForecastPowerShortTermService forecastPowerShortTermService;
+    @Autowired
+    DqInterveneService dqInterveneService;
+    @Autowired
+    VelocityEngine velocityEngine;
+
+    public void sendDqDownloadFile(String stationCode,String ftpAccount){
+        try{
+            // 获取人工干预下发未来短期数据天数
+            int dqForecastDays = Integer.parseInt(sysParameterService.getSysParameterAndStationCode("SEND_DQ_DAYS", "10", stationCode));
+
+            String distPath = "/home"+ File.separator+ftpAccount+File.separator+"download";
+            File dirFile = new File(distPath);
+            if (!dirFile.exists()) {
+                dirFile.mkdirs();
+            }
+            // 获取短期实时数据,开始时间
+            Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(new Date(), 1).getTime());
+            // 结束时间(开始加24小时再减去1秒)
+            Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(new Date(), dqForecastDays).getTime());
+            // 查询短期预测功率
+            LambdaQueryWrapper<ForecastPowerShortTerm> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(ForecastPowerShortTerm::getForecastManufactor, "SYJY");
+            queryWrapper.eq(ForecastPowerShortTerm::getStationCode, stationCode);
+            queryWrapper.between(ForecastPowerShortTerm::getForecastTime, new Date(startTime), new Date(endTime));
+
+            List<ForecastPowerShortTerm> forecastPowerShortTermList = this.forecastPowerShortTermService.list(queryWrapper);
+            Map<Long, ForecastPowerShortTerm> forecastPowerShortMap = forecastPowerShortTermList.stream()
+                    .collect(Collectors.toMap(
+                            myObject -> myObject.getForecastTime().getTime(), // keyMapper,将Date转换为long
+                            myObject -> myObject, // valueMapper,保持原对象
+                            (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
+                    ));
+
+            // 人工干预
+            QueryWrapper<DqIntervene> dqInterveneQueryWrapper = new QueryWrapper<>();
+            dqInterveneQueryWrapper.between("forecast_time", new Date(startTime), new Date(endTime));
+            dqInterveneQueryWrapper.eq("station_code",stationCode);
+            List<DqIntervene> dqInterveneList = dqInterveneService.list(dqInterveneQueryWrapper);
+            Map<Long, DqIntervene> dqInterveneMap = dqInterveneList.stream()
+                    .collect(Collectors.toMap(
+                            myObject -> myObject.getForecastTime().getTime(), // keyMapper,将Date转换为long
+                            myObject -> myObject, // valueMapper,保持原对象
+                            (existing, replacement) -> existing // mergeFunction,处理重复key的情况,这里简单地保留现有的value
+                    ));
+
+            List<ForecastData> vList = new ArrayList<>();
+
+            for (Long tempTime = startTime.longValue(); tempTime <= endTime.longValue(); tempTime = tempTime + 15 * 60 * 1000L) {
+                ForecastData forecastData = new ForecastData();
+                forecastData.setTime(DateFormatUtils.format(tempTime, "yyyy-MM-dd HH:mm:ss"));
+                if (dqInterveneMap.get(tempTime)!=null){
+                    forecastData.setPower(dqInterveneMap.get(tempTime).getActivePower().toString());
+                }
+                else if (forecastPowerShortMap.get(tempTime)!=null){
+                    forecastData.setPower(forecastPowerShortMap.get(tempTime).getFpValue().toString());
+                }
+                else{
+                    forecastData.setPower("");
+                }
+                vList.add(forecastData);
+            }
+
+            VelocityContext velocityContext = new VelocityContext();
+            velocityContext.put("vList", vList);
+            // 系统当前日期
+            velocityContext.put("currentTime", DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+            StringWriter writer = new StringWriter();
+            org.apache.velocity.Template template = this.velocityEngine.getTemplate(FileUtil.getResourceBasePath() + "/templates/send_dq.vm");
+            template.merge(velocityContext, writer);
+            String dateDir = DateFormatUtils.format(new Date(startTime), "yyyyMMdd");
+            String vmFileName = "download_"+ftpAccount+"_dq_"+dateDir+".WPD";
+            createSendDqFile(writer,new File(distPath + File.separator+vmFileName));
+        }
+        catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 生成上报文件
+     *
+     * @param writer
+     * @param file
+     */
+    protected void createSendDqFile(StringWriter writer, File file) {
+        FileOutputStream os = null;
+        try {
+            os = new FileOutputStream(file);
+            // 采用UTF-8字符集
+            os.write(writer.toString().getBytes("UTF-8"));
+            os.flush();
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    log.error("文件生成关闭流失败", e);
+                }
+            }
+        }
+    }
+}