package com.ruoyi.predict.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.predict.domain.*;
import com.ruoyi.predict.service.*;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;

import java.sql.*;
import java.util.List;

/**
 * @author hlf
 * @date 2022/9/21 10:52
 * 文件说明：定时任务工具类
 */
@Configuration
@EnableScheduling
@EnableAsync
public class ScheduledTaskTools {

    private static DefaultWebSecurityManager manager = new DefaultWebSecurityManager();

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private IWeatherForecastService weatherForecastService;

    @Autowired
    private IWindplantService windplantService;

    @Autowired
    private IPvPowerStationService pvPowerStationService;

    @Autowired
    private IWfFileConfigService wfFileConfigService;

    @Autowired
    private IWindplantprojectService windplantprojectService;

    @Autowired
    private IWfUspTsPeriodDataService wfUspTsPeriodDataService;

    @Autowired
    private IProjectUspTsPeriodDataService projectUspTsPeriodDataService;

    @Autowired
    private INoscaleWfDaPfPeriodDataService noscaleWfDaPfPeriodDataService;

    @Autowired
    private INoscalePrDaPfPeriodDataService noscalePrDaPfPeriodDataService;

    @Autowired
    private IWfStatPeriodDataService wfStatPeriodDataService;

    @Autowired
    private IWfYcHistoryData1Service wfYcHistoryData1Service;

    @Autowired
    private IWfTheorypowerDataService wfTheorypowerDataService;

    @Autowired
    private IPrTheorypowerDataService prTheorypowerDataService;

    @Autowired
    private IWfNwpDataService wfNwpDataService;

    @Autowired
    private IWfPrPfutilizationhoursService wfPrPfutilizationhoursService;

    @Autowired
    private ILpProjectMonthDataService lpProjectMonthDataService;

    @Autowired
    private ILpProjectYearDataService lpProjectYearDataService;

    @Autowired
    private IWfPrUtilizationhoursService wfPrUtilizationhoursService;

    @Autowired
    private IWfUspTsEfPeriodDataService wfUspTsEfPeriodDataService;

    @Autowired
    private IProjectEuspTsPeriodDataService projectEuspTsPeriodDataService;

    @Autowired
    private INoscaleWfDaEfPeriodDataService noscaleWfDaEfPeriodDataService;

    @Autowired
    private INoscalePrDaEfPeriodDataService noscalePrDaEfPeriodDataService;

    @Autowired
    private ILpWfMonthDataService lpWfMonthDataService;

    @Autowired
    private ILpWfYearDataService lpWfYearDataService;

    @Autowired
    private IWfTheoryenergyDataService wfTheoryenergyDataService;

    @Autowired
    private IPrTheoryenergyDataService prTheoryenergyDataService;

    /**
     * 天气预报
     */
    @Async
    @Scheduled(cron = "0 0 */1 * * ?")
    public void weatherForecastScheduledTask() {
        ThreadContext.bind(manager);
        ThreadUtil.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    //风场
                    List<Windplant> windplantList = windplantService.selectWindplantList(new Windplant());
                    if (windplantList.size() > 0) {
                        for (Windplant windplant : windplantList) {
                            String url = "http://weathernew.pae.baidu.com/weathernew/pc?query=" + windplant.getSite() + "天气&srcid=4982";
                            ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class);
                            if (entity.getBody() != null) {
                                String bodyStr = entity.getBody();
                                int index = bodyStr.indexOf("<!DOC");
                                String a = bodyStr.substring(0, index);
                                String b = a.replaceAll("<script>", "");
                                int index1 = b.lastIndexOf(";<");
                                String c = b.substring(0, index1);
                                int index2 = c.indexOf(" {");
                                String d = c.substring(index2, c.length());
                                String e = d.substring(1, d.length());
                                String f = e.substring(0, e.indexOf(";</"));
                                JSONObject base = (JSONObject) JSONUtil.parseObj(f).get("base");
                                String date = (String) base.get("date");
                                WeatherForecast flag = weatherForecastService.selectWeatherForecastById(windplant.getWindplantNo(), DateUtil.parse(date));
                                WeatherForecast weatherForecast = new WeatherForecast();
                                if (ObjectUtil.isNotNull(flag)) {//非空 执行修改操作
                                    weatherForecast.setTerminalNumber(windplant.getWindplantNo());
                                    weatherForecast.setDataTime(DateUtil.parse(date));
                                    weatherForecast.setContent(f);
                                    weatherForecastService.updateWeatherForecast(weatherForecast);
                                } else {//为空 执行添加操作
                                    weatherForecast.setTerminalNumber(windplant.getWindplantNo());
                                    weatherForecast.setDataTime(DateUtil.parse(date));
                                    weatherForecast.setContent(f);
                                    weatherForecastService.insertWeatherForecast(weatherForecast);
                                }
                            }
                        }
                    }
                    //光伏场站
                    List<PvPowerStation> pvPowerStationList = pvPowerStationService.selectPvPowerStationList(new PvPowerStation());
                    if (pvPowerStationList.size() > 0) {
                        for (PvPowerStation pvPowerStation : pvPowerStationList) {
                            String url = "http://weathernew.pae.baidu.com/weathernew/pc?query=" + pvPowerStation.getSite() + "天气&srcid=4982";
                            ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class);
                            if (entity.getBody() != null) {
                                String bodyStr = entity.getBody();
                                int index = bodyStr.indexOf("<!DOC");
                                String a = bodyStr.substring(0, index);
                                String b = a.replaceAll("<script>", "");
                                int index1 = b.lastIndexOf(";<");
                                String c = b.substring(0, index1);
                                int index2 = c.indexOf(" {");
                                String d = c.substring(index2, c.length());
                                String e = d.substring(1, d.length());
                                String f = e.substring(0, e.indexOf(";</"));
                                JSONObject base = (JSONObject) JSONUtil.parseObj(f).get("base");
                                String date = (String) base.get("date");
                                WeatherForecast flag = weatherForecastService.selectWeatherForecastById(pvPowerStation.getPvStationNo(), DateUtil.parse(date));
                                WeatherForecast weatherForecast = new WeatherForecast();
                                if (ObjectUtil.isNotNull(flag)) {//非空 执行修改操作
                                    weatherForecast.setTerminalNumber(pvPowerStation.getPvStationNo());
                                    weatherForecast.setDataTime(DateUtil.parse(date));
                                    weatherForecast.setContent(f);
                                    weatherForecastService.updateWeatherForecast(weatherForecast);
                                } else {//为空 执行添加操作
                                    weatherForecast.setTerminalNumber(pvPowerStation.getPvStationNo());
                                    weatherForecast.setDataTime(DateUtil.parse(date));
                                    weatherForecast.setContent(f);
                                    weatherForecastService.insertWeatherForecast(weatherForecast);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 数据同步
     */
    //@Async
    //@Scheduled(cron = "0 0/5 * * * ?")
    public void dataSynchronizationScheduledTaskTerminal() {
        ThreadContext.bind(manager);
        ThreadUtil.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    Connection con = null;
                    PreparedStatement pst = null;
                    ResultSet rs = null;
                    try {
                        //实例化oracle数据库驱动程序(建立中间件)
                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        String url = "jdbc:oracle:thin:@120.46.129.85:1521/ORCL";
                        con = DriverManager.getConnection(url, "gyee", "FRWIND");
                        List<Windplant> windplantList = windplantService.selectWindplantList(new Windplant());
                        for (Windplant windplant : windplantList) {
                            System.out.println(windplant.getWindplantNo() + ":" + windplant.getName());
                            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(windplant.getWindplantNo());
                            if (ObjectUtil.isNotNull(wfFileConfig)) {
                                //可用电量-场站
                                pst = con.prepareStatement("select * from ( select * from wf_theoryenergy_data where windplant_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_theoryenergy_data(windplant_no, data_time, theoryenergy, availableenergy, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfTheoryenergyData> wfTheoryenergyDataList = wfTheoryenergyDataService.selectWfTheoryenergyData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfTheoryenergyData wfTheoryenergyData : wfTheoryenergyDataList) {
                                        pst.setLong(1, wfTheoryenergyData.getWindplantNo());
                                        pst.setDate(2, new java.sql.Date(wfTheoryenergyData.getDataTime().getTime()));
                                        pst.setDouble(3, wfTheoryenergyData.getTheoryenergy());
                                        pst.setDouble(4, wfTheoryenergyData.getAvailableenergy());
                                        pst.setLong(5, wfTheoryenergyData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期电量预测-场站-长期
                                pst = con.prepareStatement("select * from ( select * from lp_wf_year_data where wf_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_wf_year_data(wf_no, model_no, data_time, generating_capacity, pf_generating_capacity, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpWfYearData> lpWfYearDataList = lpWfYearDataService.selectLpWfYearData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpWfYearData lpWfYearData : lpWfYearDataList) {
                                        pst.setLong(1, lpWfYearData.getWfNo());
                                        pst.setLong(2, lpWfYearData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpWfYearData.getDataTime().getTime()));
                                        pst.setDouble(4, lpWfYearData.getGeneratingCapacity());
                                        pst.setDouble(5, lpWfYearData.getPfGeneratingCapacity());
                                        pst.setLong(6, lpWfYearData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期电量预测-场站-中期
                                pst = con.prepareStatement("select * from ( select * from lp_wf_month_data where wf_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_wf_month_data(wf_no, model_no, data_time, generating_capacity, pf_generating_capacity, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpWfMonthData> lpWfMonthDataList = lpWfMonthDataService.selectLpWfMonthData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpWfMonthData lpWfMonthData : lpWfMonthDataList) {
                                        pst.setLong(1, lpWfMonthData.getWfNo());
                                        pst.setLong(2, lpWfMonthData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpWfMonthData.getDataTime().getTime()));
                                        pst.setDouble(4, lpWfMonthData.getGeneratingCapacity());
                                        pst.setDouble(5, lpWfMonthData.getPfGeneratingCapacity());
                                        pst.setLong(6, lpWfMonthData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期电量预测-场站
                                pst = con.prepareStatement("select * from ( select * from noscale_wf_da_ef_period_data where windplant_no = ? and model_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, wfFileConfig.getWpfemodelNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into noscale_wf_da_ef_period_data(windplant_no, model_no, data_time, value, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<NoscaleWfDaEfPeriodData> noscaleWfDaEfPeriodDataList = noscaleWfDaEfPeriodDataService.selectNoscaleWfDaEfPeriodData(windplant.getWindplantNo(), wfFileConfig.getWpfemodelNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (NoscaleWfDaEfPeriodData noscaleWfDaEfPeriodData : noscaleWfDaEfPeriodDataList) {
                                        pst.setLong(1, noscaleWfDaEfPeriodData.getWindplantNo());
                                        pst.setLong(2, noscaleWfDaEfPeriodData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(noscaleWfDaEfPeriodData.getDataTime().getTime()));
                                        pst.setDouble(4, noscaleWfDaEfPeriodData.getValue());
                                        pst.setLong(5, noscaleWfDaEfPeriodData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //实际利用时长-场站
                                pst = con.prepareStatement("select * from ( select * from wf_pr_utilizationhours where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, (long) 0);
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_pr_utilizationhours(windplant_no, project_no, data_time, hour_count, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfPrUtilizationhours> wfPrUtilizationhoursList = wfPrUtilizationhoursService.selectWfPrUtilizationhours(windplant.getWindplantNo(), (long) 0, DateUtil.parse(rs.getString("data_time")));
                                    for (WfPrUtilizationhours wfPrUtilizationhours : wfPrUtilizationhoursList) {
                                        pst.setLong(1, wfPrUtilizationhours.getWindplantNo());
                                        pst.setLong(2, wfPrUtilizationhours.getProjectNo());
                                        pst.setDate(3, new java.sql.Date(wfPrUtilizationhours.getDataTime().getTime()));
                                        pst.setDouble(4, wfPrUtilizationhours.getHourCount());
                                        pst.setLong(5, wfPrUtilizationhours.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期预测发电时长-场站-长期
                                pst = con.prepareStatement("select * from ( select * from lp_project_year_data where wf_pr_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_project_year_data(wf_pr_no, model_no, data_time, k, c, pf_k, k_relativeerror, pf_c, c_relativeerror, speed, hour_count, factors, wind_energy, generating_capacity, pf_generating_capacity, pf_hour_count, max_probability_density, energy_relativeerror, data_flag) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpProjectYearData> lpProjectYearDataList = lpProjectYearDataService.selectLpProjectYearData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpProjectYearData lpProjectYearData : lpProjectYearDataList) {
                                        pst.setLong(1, lpProjectYearData.getWfPrNo());
                                        pst.setLong(2, lpProjectYearData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpProjectYearData.getDataTime().getTime()));
                                        pst.setDouble(4, lpProjectYearData.getK());
                                        pst.setDouble(5, lpProjectYearData.getC());
                                        pst.setDouble(6, lpProjectYearData.getPfK());
                                        pst.setDouble(7, lpProjectYearData.getkRelativeerror());
                                        pst.setDouble(8, lpProjectYearData.getPfC());
                                        pst.setDouble(9, lpProjectYearData.getcRelativeerror());
                                        pst.setDouble(10, lpProjectYearData.getSpeed());
                                        pst.setDouble(11, lpProjectYearData.getHourCount());
                                        pst.setDouble(12, lpProjectYearData.getFactors());
                                        pst.setDouble(13, lpProjectYearData.getWindEnergy());
                                        pst.setDouble(14, lpProjectYearData.getGeneratingCapacity());
                                        pst.setDouble(15, lpProjectYearData.getPfGeneratingCapacity());
                                        pst.setDouble(16, lpProjectYearData.getPfHourCount());
                                        pst.setDouble(17, lpProjectYearData.getMaxProbabilityDensity());
                                        pst.setDouble(18, lpProjectYearData.getEnergyRelativeerror());
                                        pst.setLong(19, lpProjectYearData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期预测发电时长-场站-中期
                                pst = con.prepareStatement("select * from ( select * from lp_project_month_data where wf_pr_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_project_month_data(wf_pr_no, model_no, data_time, k, c, pf_k, k_relativeerror, pf_c, c_relativeerror, speed, hour_count, factors, wind_energy, generating_capacity, pf_generating_capacity, pf_hour_count, max_probability_density, energy_relativeerror, data_flag) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpProjectMonthData> lpProjectMonthDataList = lpProjectMonthDataService.selectLpProjectMonthData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpProjectMonthData lpProjectMonthData : lpProjectMonthDataList) {
                                        pst.setLong(1, lpProjectMonthData.getWfPrNo());
                                        pst.setLong(2, lpProjectMonthData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpProjectMonthData.getDataTime().getTime()));
                                        pst.setDouble(4, lpProjectMonthData.getK());
                                        pst.setDouble(5, lpProjectMonthData.getC());
                                        pst.setDouble(6, lpProjectMonthData.getPfK());
                                        pst.setDouble(7, lpProjectMonthData.getkRelativeerror());
                                        pst.setDouble(8, lpProjectMonthData.getPfC());
                                        pst.setDouble(9, lpProjectMonthData.getcRelativeerror());
                                        pst.setDouble(10, lpProjectMonthData.getSpeed());
                                        pst.setDouble(11, lpProjectMonthData.getHourCount());
                                        pst.setDouble(12, lpProjectMonthData.getFactors());
                                        pst.setDouble(13, lpProjectMonthData.getWindEnergy());
                                        pst.setDouble(14, lpProjectMonthData.getGeneratingCapacity());
                                        pst.setDouble(15, lpProjectMonthData.getPfGeneratingCapacity());
                                        pst.setDouble(16, lpProjectMonthData.getPfHourCount());
                                        pst.setDouble(17, lpProjectMonthData.getMaxProbabilityDensity());
                                        pst.setDouble(18, lpProjectMonthData.getEnergyRelativeerror());
                                        pst.setLong(19, lpProjectMonthData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期预测发电时长-场站
                                pst = con.prepareStatement("select * from ( select * from wf_pr_pfutilizationhours where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, (long) 0);
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_pr_pfutilizationhours(windplant_no, project_no, model_no, data_time, pf_hour_count, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfPrPfutilizationhours> wfPrPfutilizationhoursList = wfPrPfutilizationhoursService.selectWfPrPfutilizationhours(windplant.getWindplantNo(), (long) 0, wfFileConfig.getWpfmodelNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfPrPfutilizationhours wfPrPfutilizationhours : wfPrPfutilizationhoursList) {
                                        pst.setLong(1, wfPrPfutilizationhours.getWindplantNo());
                                        pst.setLong(2, wfPrPfutilizationhours.getProjectNo());
                                        pst.setLong(3, wfPrPfutilizationhours.getModelNo());
                                        pst.setDate(4, new java.sql.Date(wfPrPfutilizationhours.getDataTime().getTime()));
                                        pst.setDouble(5, wfPrPfutilizationhours.getPfHourCount());
                                        pst.setLong(6, wfPrPfutilizationhours.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //数值天气预报
                                pst = con.prepareStatement("select * from ( select * from wf_nwp_data where windplant_no = ? and nwp_type = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, wfFileConfig.getUspNwpNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_nwp_data(windplant_no, nwp_type, file_time, data_time, wind_speed, temperature, wind_dir, humidity, air_pressure) values(?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfNwpData> wfNwpDataList = wfNwpDataService.selectWfNwpData(windplant.getWindplantNo(), wfFileConfig.getUspNwpNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfNwpData wfNwpData : wfNwpDataList) {
                                        pst.setLong(1, wfNwpData.getWindplantNo());
                                        pst.setLong(2, wfNwpData.getNwpType());
                                        pst.setLong(3, wfNwpData.getFileTime());
                                        pst.setDate(4, new java.sql.Date(wfNwpData.getDataTime().getTime()));
                                        pst.setDouble(5, wfNwpData.getWindSpeed());
                                        pst.setDouble(6, wfNwpData.getTemperature());
                                        pst.setDouble(7, wfNwpData.getWindDir());
                                        pst.setDouble(8, wfNwpData.getHumidity());
                                        pst.setDouble(9, wfNwpData.getAirPressure());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //可用功率-场站、理论功率-场站
                                pst = con.prepareStatement("select * from ( select * from wf_theorypower_data where windplant_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_theorypower_data(windplant_no, data_time, theorypower, availablepower, is_limit, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerData(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfTheorypowerData wfTheorypowerData : wfTheorypowerDataList) {
                                        pst.setLong(1, wfTheorypowerData.getWindplantNo());
                                        pst.setDate(2, new java.sql.Date(wfTheorypowerData.getDataTime().getTime()));
                                        pst.setDouble(3, wfTheorypowerData.getTheorypower());
                                        pst.setDouble(4, wfTheorypowerData.getAvailablepower());
                                        pst.setDouble(5, wfTheorypowerData.getIsLimit());
                                        pst.setLong(6, wfTheorypowerData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //实时功率-场站
                                pst = con.prepareStatement("select * from ( select * from wf_stat_period_data where windplant_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_stat_period_data(windplant_no, data_time, p1, p2, p0, avg_wind_speed, avg_temp, energy, data_flag) values(?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfStatPeriodData> wfStatPeriodDataList = wfStatPeriodDataService.selectWfStatPeriodData1(windplant.getWindplantNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfStatPeriodData wfStatPeriodData : wfStatPeriodDataList) {
                                        pst.setLong(1, wfStatPeriodData.getWindplantNo());
                                        pst.setDate(2, new java.sql.Date(wfStatPeriodData.getDataTime().getTime()));
                                        pst.setDouble(3, wfStatPeriodData.getP1());
                                        pst.setDouble(4, wfStatPeriodData.getP2());
                                        pst.setDouble(5, wfStatPeriodData.getP0());
                                        pst.setDouble(6, wfStatPeriodData.getAvgWindSpeed());
                                        pst.setDouble(7, wfStatPeriodData.getAvgTemp());
                                        pst.setDouble(8, wfStatPeriodData.getEnergy());
                                        pst.setLong(9, wfStatPeriodData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期功率预测-场站
                                pst = con.prepareStatement("select * from ( select * from noscale_wf_da_pf_period_data where windplant_no = ? and model_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, wfFileConfig.getWpfmodelNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into noscale_wf_da_pf_period_data(windplant_no, model_no, data_time, value, data_flag, modspeed) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<NoscaleWfDaPfPeriodData> noscaleWfDaPfPeriodDataList = noscaleWfDaPfPeriodDataService.selectNoscaleWfDaPfPeriodData(windplant.getWindplantNo(), wfFileConfig.getWpfmodelNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (NoscaleWfDaPfPeriodData noscaleWfDaPfPeriodData : noscaleWfDaPfPeriodDataList) {
                                        pst.setLong(1, noscaleWfDaPfPeriodData.getWindplantNo());
                                        pst.setLong(2, noscaleWfDaPfPeriodData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(noscaleWfDaPfPeriodData.getDataTime().getTime()));
                                        pst.setDouble(4, noscaleWfDaPfPeriodData.getValue());
                                        pst.setLong(5, noscaleWfDaPfPeriodData.getDataFlag());
                                        pst.setDouble(6, noscaleWfDaPfPeriodData.getModspeed());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                for (int i = 0; i < 12; i++) {
                                    //超短期电量预测-场站
                                    pst = con.prepareStatement("select * from ( select * from wf_usp_ts_ef_period_data where windplant_no = ? and model_no = ? and time_scale = ? order by data_time DESC ) c where rownum = 1");
                                    pst.setLong(1, windplant.getWindplantNo());
                                    pst.setLong(2, wfFileConfig.getUwpfemodelNo());
                                    pst.setLong(3, (long) i);
                                    rs = pst.executeQuery();
                                    while (rs.next()) {
                                        String sql = "insert into wf_usp_ts_ef_period_data(windplant_no, model_no, time_scale, data_time, wind_speed, mod_coeff, energy, mod_energy, data_flag) values(?,?,?,?,?,?,?,?,?)";
                                        pst = con.prepareStatement(sql);
                                        List<WfUspTsEfPeriodData> wfUspTsEfPeriodDataList = wfUspTsEfPeriodDataService.selectWfUspTsEfPeriodData(windplant.getWindplantNo(), wfFileConfig.getUwpfemodelNo(), (long) i, DateUtil.parse(rs.getString("data_time")));
                                        for (WfUspTsEfPeriodData wfUspTsEfPeriodData : wfUspTsEfPeriodDataList) {
                                            pst.setLong(1, wfUspTsEfPeriodData.getWindplantNo());
                                            pst.setLong(2, wfUspTsEfPeriodData.getModelNo());
                                            pst.setLong(3, wfUspTsEfPeriodData.getTimeScale());
                                            pst.setDate(4, new java.sql.Date(wfUspTsEfPeriodData.getDataTime().getTime()));
                                            pst.setDouble(5, wfUspTsEfPeriodData.getWindSpeed());
                                            pst.setDouble(6, wfUspTsEfPeriodData.getModCoeff());
                                            pst.setDouble(7, wfUspTsEfPeriodData.getEnergy());
                                            pst.setDouble(8, wfUspTsEfPeriodData.getModEnergy());
                                            pst.setLong(9, wfUspTsEfPeriodData.getDataFlag());
                                            pst.addBatch();
                                        }
                                        pst.executeBatch();
                                        pst.clearBatch();
                                        pst.close();
                                    }
                                    //超短期功率预测-场站
                                    pst = con.prepareStatement("select * from ( select * from wf_usp_ts_period_data where windplant_no = ? and model_no = ? and time_scale = ? order by data_time DESC ) c where rownum = 1");
                                    pst.setLong(1, windplant.getWindplantNo());
                                    pst.setLong(2, wfFileConfig.getUwpfemodelNo());
                                    pst.setLong(3, (long) i);
                                    rs = pst.executeQuery();
                                    while (rs.next()) {
                                        String sql = "insert into wf_usp_ts_period_data(windplant_no, model_no, time_scale, data_time, wind_speed, mod_coeff, power, mod_power, data_flag) values(?,?,?,?,?,?,?,?,?)";
                                        pst = con.prepareStatement(sql);
                                        List<WfUspTsPeriodData> wfUspTsPeriodDataList = wfUspTsPeriodDataService.selectWfUspTsPeriodData1(windplant.getWindplantNo(), wfFileConfig.getUwpfmodelNo(), (long) i, DateUtil.parse(rs.getString("data_time")));
                                        for (WfUspTsPeriodData wfUspTsPeriodData : wfUspTsPeriodDataList) {
                                            pst.setLong(1, wfUspTsPeriodData.getWindplantNo());
                                            pst.setLong(2, wfUspTsPeriodData.getModelNo());
                                            pst.setLong(3, wfUspTsPeriodData.getTimeScale());
                                            pst.setDate(4, new java.sql.Date(wfUspTsPeriodData.getDataTime().getTime()));
                                            pst.setDouble(5, wfUspTsPeriodData.getWindSpeed());
                                            pst.setDouble(6, wfUspTsPeriodData.getModCoeff());
                                            pst.setDouble(7, wfUspTsPeriodData.getPower());
                                            pst.setDouble(8, wfUspTsPeriodData.getModPower());
                                            pst.setLong(9, wfUspTsPeriodData.getDataFlag());
                                            pst.addBatch();
                                        }
                                        pst.executeBatch();
                                        pst.clearBatch();
                                        pst.close();
                                    }
                                }
                            }
                            List<Windplantproject> windplantprojectList = windplantprojectService.selectWindplantprojectByWindplantNo(windplant.getWindplantNo());
                            for (Windplantproject windplantproject : windplantprojectList) {
                                System.out.println(windplant.getWindplantNo() + ":" + windplant.getName() + "," + windplantproject.getProjectNo() + ":" + windplantproject.getProjectName());
                                //可用电量-期次
                                pst = con.prepareStatement("select * from ( select * from pr_theoryenergy_data where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into pr_theoryenergy_data(windplant_no, project_no, data_time, theoryenergy, availableenergy, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<PrTheoryenergyData> prTheoryenergyDataList = prTheoryenergyDataService.selectPrTheoryenergyData(windplant.getWindplantNo(), windplantproject.getProjectNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (PrTheoryenergyData prTheoryenergyData : prTheoryenergyDataList) {
                                        pst.setLong(1, prTheoryenergyData.getWindplantNo());
                                        pst.setLong(2, prTheoryenergyData.getProjectNo());
                                        pst.setDate(3, new java.sql.Date(prTheoryenergyData.getDataTime().getTime()));
                                        pst.setDouble(4, prTheoryenergyData.getTheoryenergy());
                                        pst.setDouble(5, prTheoryenergyData.getAvailableenergy());
                                        pst.setLong(6, prTheoryenergyData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期电量预测-期次
                                pst = con.prepareStatement("select * from ( select * from noscale_pr_da_ef_period_data where wf_pr_no = ? and model_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplantproject.getProjectNo());
                                pst.setLong(2, (long) 7045);
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into noscale_pr_da_ef_period_data(wf_pr_no, model_no, data_time, value, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<NoscalePrDaEfPeriodData> noscalePrDaEfPeriodDataList = noscalePrDaEfPeriodDataService.selectNoscalePrDaEfPeriodData(windplantproject.getProjectNo(), (long) 7045, DateUtil.parse(rs.getString("data_time")));
                                    for (NoscalePrDaEfPeriodData noscalePrDaEfPeriodData : noscalePrDaEfPeriodDataList) {
                                        pst.setLong(1, noscalePrDaEfPeriodData.getWfPrNo());
                                        pst.setLong(2, noscalePrDaEfPeriodData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(noscalePrDaEfPeriodData.getDataTime().getTime()));
                                        pst.setDouble(4, noscalePrDaEfPeriodData.getValue());
                                        pst.setLong(5, noscalePrDaEfPeriodData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //实际利用时长-期次
                                pst = con.prepareStatement("select * from ( select * from wf_pr_utilizationhours where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_pr_utilizationhours(windplant_no, project_no, data_time, hour_count, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfPrUtilizationhours> wfPrUtilizationhoursList = wfPrUtilizationhoursService.selectWfPrUtilizationhours(windplant.getWindplantNo(), windplantproject.getProjectNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfPrUtilizationhours wfPrUtilizationhours : wfPrUtilizationhoursList) {
                                        pst.setLong(1, wfPrUtilizationhours.getWindplantNo());
                                        pst.setLong(2, wfPrUtilizationhours.getProjectNo());
                                        pst.setDate(3, new java.sql.Date(wfPrUtilizationhours.getDataTime().getTime()));
                                        pst.setDouble(4, wfPrUtilizationhours.getHourCount());
                                        pst.setLong(5, wfPrUtilizationhours.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期预测发电时长-期次-长期、中长期电量预测-期次-长期
                                pst = con.prepareStatement("select * from ( select * from lp_project_year_data where wf_pr_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_project_year_data(wf_pr_no, model_no, data_time, k, c, pf_k, k_relativeerror, pf_c, c_relativeerror, speed, hour_count, factors, wind_energy, generating_capacity, pf_generating_capacity, pf_hour_count, max_probability_density, energy_relativeerror, data_flag) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpProjectYearData> lpProjectYearDataList = lpProjectYearDataService.selectLpProjectYearData(windplantproject.getProjectNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpProjectYearData lpProjectYearData : lpProjectYearDataList) {
                                        pst.setLong(1, lpProjectYearData.getWfPrNo());
                                        pst.setLong(2, lpProjectYearData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpProjectYearData.getDataTime().getTime()));
                                        pst.setDouble(4, lpProjectYearData.getK());
                                        pst.setDouble(5, lpProjectYearData.getC());
                                        pst.setDouble(6, lpProjectYearData.getPfK());
                                        pst.setDouble(7, lpProjectYearData.getkRelativeerror());
                                        pst.setDouble(8, lpProjectYearData.getPfC());
                                        pst.setDouble(9, lpProjectYearData.getcRelativeerror());
                                        pst.setDouble(10, lpProjectYearData.getSpeed());
                                        pst.setDouble(11, lpProjectYearData.getHourCount());
                                        pst.setDouble(12, lpProjectYearData.getFactors());
                                        pst.setDouble(13, lpProjectYearData.getWindEnergy());
                                        pst.setDouble(14, lpProjectYearData.getGeneratingCapacity());
                                        pst.setDouble(15, lpProjectYearData.getPfGeneratingCapacity());
                                        pst.setDouble(16, lpProjectYearData.getPfHourCount());
                                        pst.setDouble(17, lpProjectYearData.getMaxProbabilityDensity());
                                        pst.setDouble(18, lpProjectYearData.getEnergyRelativeerror());
                                        pst.setLong(19, lpProjectYearData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //中长期预测发电时长-期次-中期、中长期电量预测-期次-中期
                                pst = con.prepareStatement("select * from ( select * from lp_project_month_data where wf_pr_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into lp_project_month_data(wf_pr_no, model_no, data_time, k, c, pf_k, k_relativeerror, pf_c, c_relativeerror, speed, hour_count, factors, wind_energy, generating_capacity, pf_generating_capacity, pf_hour_count, max_probability_density, energy_relativeerror, data_flag) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<LpProjectMonthData> lpProjectMonthDataList = lpProjectMonthDataService.selectLpProjectMonthData(windplantproject.getProjectNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (LpProjectMonthData lpProjectMonthData : lpProjectMonthDataList) {
                                        pst.setLong(1, lpProjectMonthData.getWfPrNo());
                                        pst.setLong(2, lpProjectMonthData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(lpProjectMonthData.getDataTime().getTime()));
                                        pst.setDouble(4, lpProjectMonthData.getK());
                                        pst.setDouble(5, lpProjectMonthData.getC());
                                        pst.setDouble(6, lpProjectMonthData.getPfK());
                                        pst.setDouble(7, lpProjectMonthData.getkRelativeerror());
                                        pst.setDouble(8, lpProjectMonthData.getPfC());
                                        pst.setDouble(9, lpProjectMonthData.getcRelativeerror());
                                        pst.setDouble(10, lpProjectMonthData.getSpeed());
                                        pst.setDouble(11, lpProjectMonthData.getHourCount());
                                        pst.setDouble(12, lpProjectMonthData.getFactors());
                                        pst.setDouble(13, lpProjectMonthData.getWindEnergy());
                                        pst.setDouble(14, lpProjectMonthData.getGeneratingCapacity());
                                        pst.setDouble(15, lpProjectMonthData.getPfGeneratingCapacity());
                                        pst.setDouble(16, lpProjectMonthData.getPfHourCount());
                                        pst.setDouble(17, lpProjectMonthData.getMaxProbabilityDensity());
                                        pst.setDouble(18, lpProjectMonthData.getEnergyRelativeerror());
                                        pst.setLong(19, lpProjectMonthData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期预测发电时长-期次
                                pst = con.prepareStatement("select * from ( select * from wf_pr_pfutilizationhours where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_pr_pfutilizationhours(windplant_no, project_no, model_no, data_time, pf_hour_count, data_flag) values(?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfPrPfutilizationhours> wfPrPfutilizationhoursList = wfPrPfutilizationhoursService.selectWfPrPfutilizationhours(windplant.getWindplantNo(), windplantproject.getProjectNo(), null, DateUtil.parse(rs.getString("data_time")));
                                    for (WfPrPfutilizationhours wfPrPfutilizationhours : wfPrPfutilizationhoursList) {
                                        pst.setLong(1, wfPrPfutilizationhours.getWindplantNo());
                                        pst.setLong(2, wfPrPfutilizationhours.getProjectNo());
                                        pst.setLong(3, wfPrPfutilizationhours.getModelNo());
                                        pst.setDate(4, new java.sql.Date(wfPrPfutilizationhours.getDataTime().getTime()));
                                        pst.setDouble(5, wfPrPfutilizationhours.getPfHourCount());
                                        pst.setLong(6, wfPrPfutilizationhours.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //可用功率-期次、理论功率-期次
                                pst = con.prepareStatement("select * from ( select * from pr_theorypower_data where windplant_no = ? and project_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplant.getWindplantNo());
                                pst.setLong(2, windplantproject.getProjectNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into pr_theorypower_data(windplant_no, project_no, data_time, theorypower, availablepower, is_limit, data_flag) values(?,?,?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<PrTheorypowerData> prTheorypowerDataList = prTheorypowerDataService.selectPrTheorypowerData(windplant.getWindplantNo(), windplantproject.getProjectNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (PrTheorypowerData prTheorypowerData : prTheorypowerDataList) {
                                        pst.setLong(1, prTheorypowerData.getWindplantNo());
                                        pst.setLong(2, prTheorypowerData.getProjectNo());
                                        pst.setDate(3, new java.sql.Date(prTheorypowerData.getDataTime().getTime()));
                                        pst.setDouble(4, prTheorypowerData.getTheorypower());
                                        pst.setDouble(5, prTheorypowerData.getAvailablepower());
                                        pst.setLong(6, prTheorypowerData.getIsLimit());
                                        pst.setLong(7, prTheorypowerData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //实时功率-期次
                                pst = con.prepareStatement("select * from ( select * from wf_yc_history_data1 where analog_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplantproject.getAnalogNo());
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into wf_yc_history_data1(analog_no, data_time, yc_raw_val, yc_val, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<WfYcHistoryData1> wfYcHistoryData1List = wfYcHistoryData1Service.selectWfYcHistoryData11(windplantproject.getAnalogNo(), DateUtil.parse(rs.getString("data_time")));
                                    for (WfYcHistoryData1 wfYcHistoryData1 : wfYcHistoryData1List) {
                                        pst.setLong(1, wfYcHistoryData1.getAnalogNo());
                                        pst.setDate(2, new java.sql.Date(wfYcHistoryData1.getDataTime().getTime()));
                                        pst.setDouble(3, wfYcHistoryData1.getYcRawVal());
                                        pst.setDouble(4, wfYcHistoryData1.getYcVal());
                                        pst.setLong(5, wfYcHistoryData1.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                //短期功率预测-期次
                                pst = con.prepareStatement("select * from ( select * from noscale_pr_da_pf_period_data where wf_pr_no = ? and model_no = ? order by data_time DESC ) c where rownum = 1");
                                pst.setLong(1, windplantproject.getProjectNo());
                                pst.setLong(2, (long) 7042);
                                rs = pst.executeQuery();
                                while (rs.next()) {
                                    String sql = "insert into noscale_pr_da_pf_period_data(wf_pr_no, model_no, data_time, value, data_flag) values(?,?,?,?,?)";
                                    pst = con.prepareStatement(sql);
                                    List<NoscalePrDaPfPeriodData> noscalePrDaPfPeriodDataList = noscalePrDaPfPeriodDataService.selectNoscalePrDaPfPeriodData(windplantproject.getProjectNo(), (long) 7042, DateUtil.parse(rs.getString("data_time")));
                                    for (NoscalePrDaPfPeriodData noscalePrDaPfPeriodData : noscalePrDaPfPeriodDataList) {
                                        pst.setLong(1, noscalePrDaPfPeriodData.getWfPrNo());
                                        pst.setLong(2, noscalePrDaPfPeriodData.getModelNo());
                                        pst.setDate(3, new java.sql.Date(noscalePrDaPfPeriodData.getDataTime().getTime()));
                                        pst.setDouble(4, noscalePrDaPfPeriodData.getValue());
                                        pst.setLong(5, noscalePrDaPfPeriodData.getDataFlag());
                                        pst.addBatch();
                                    }
                                    pst.executeBatch();
                                    pst.clearBatch();
                                    pst.close();
                                }
                                for (int i = 0; i < 12; i++) {
                                    //超短期电量预测-期次
                                    pst = con.prepareStatement("select * from ( select * from project_eusp_ts_period_data where project_no = ? and model_no = ? and time_scale = ? order by data_time DESC ) c where rownum = 1");
                                    pst.setLong(1, windplantproject.getProjectNo());
                                    pst.setLong(2, (long) 7041);
                                    pst.setLong(3, (long) i);
                                    rs = pst.executeQuery();
                                    while (rs.next()) {
                                        String sql = "insert into project_eusp_ts_period_data(project_no, model_no, time_scale, data_time, wind_speed, mod_coeff, energy, mod_energy, data_flag) values(?,?,?,?,?,?,?,?,?)";
                                        pst = con.prepareStatement(sql);
                                        List<ProjectEuspTsPeriodData> projectEuspTsPeriodDataList = projectEuspTsPeriodDataService.selectProjectEuspTsPeriodData(windplantproject.getProjectNo(), (long) 7041, (long) i, DateUtil.parse(rs.getString("data_time")));
                                        for (ProjectEuspTsPeriodData projectEuspTsPeriodData : projectEuspTsPeriodDataList) {
                                            pst.setLong(1, projectEuspTsPeriodData.getProjectNo());
                                            pst.setLong(2, projectEuspTsPeriodData.getModelNo());
                                            pst.setLong(3, projectEuspTsPeriodData.getTimeScale());
                                            pst.setDate(4, new java.sql.Date(projectEuspTsPeriodData.getDataTime().getTime()));
                                            pst.setDouble(5, projectEuspTsPeriodData.getWindSpeed());
                                            pst.setDouble(6, projectEuspTsPeriodData.getModCoeff());
                                            pst.setDouble(7, projectEuspTsPeriodData.getEnergy());
                                            pst.setDouble(8, projectEuspTsPeriodData.getModEnergy());
                                            pst.setLong(9, projectEuspTsPeriodData.getDataFlag());
                                            pst.addBatch();
                                        }
                                        pst.executeBatch();
                                        pst.clearBatch();
                                        pst.close();
                                    }
                                    //超短期功率预测-期次
                                    pst = con.prepareStatement("select * from ( select * from project_usp_ts_period_data where project_no = ? and model_no = ? and time_scale = ? order by data_time DESC ) c where rownum = 1");
                                    pst.setLong(1, windplantproject.getProjectNo());
                                    pst.setLong(2, (long) 7041);
                                    pst.setLong(3, (long) i);
                                    rs = pst.executeQuery();
                                    while (rs.next()) {
                                        String sql = "insert into project_usp_ts_period_data(project_no, model_no, time_scale, data_time, wind_speed, mod_coeff, power, mod_power, data_flag) values(?,?,?,?,?,?,?,?,?)";
                                        pst = con.prepareStatement(sql);
                                        List<ProjectUspTsPeriodData> projectUspTsPeriodDataList = projectUspTsPeriodDataService.selectProjectUspTsPeriodData(windplantproject.getProjectNo(), (long) 7041, (long) i, DateUtil.parse(rs.getString("data_time")));
                                        for (ProjectUspTsPeriodData projectUspTsPeriodData : projectUspTsPeriodDataList) {
                                            pst.setLong(1, projectUspTsPeriodData.getProjectNo());
                                            pst.setLong(2, projectUspTsPeriodData.getModelNo());
                                            pst.setLong(3, projectUspTsPeriodData.getTimeScale());
                                            pst.setDate(4, new java.sql.Date(projectUspTsPeriodData.getDataTime().getTime()));
                                            pst.setDouble(5, projectUspTsPeriodData.getWindSpeed());
                                            pst.setDouble(6, projectUspTsPeriodData.getModCoeff());
                                            pst.setDouble(7, projectUspTsPeriodData.getPower());
                                            pst.setDouble(8, projectUspTsPeriodData.getModPower());
                                            pst.setLong(9, projectUspTsPeriodData.getDataFlag());
                                            pst.addBatch();
                                        }
                                        pst.executeBatch();
                                        pst.clearBatch();
                                        pst.close();
                                    }
                                }
                            }
                        }
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (rs != null) {
                            try {
                                rs.close();
                            } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        if (pst != null) {
                            try {
                                pst.close();
                            } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        if (con != null) {
                            try {
                                con.close();
                            } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
