package com.gyee.frame.common.spring;

import com.gyee.frame.model.auto.*;
import com.gyee.frame.service.*;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务启动执行
 */
@Component
public class InitialRunner implements CommandLineRunner {


    @Resource
    private RMConfigService rMConfigService;
    @Resource
    private WindpowerstationService windpowerstationService;
    @Resource
    private ProjectService projectService;
    @Resource
    private LineService lineService;
    @Resource
    private WindturbineService windturbineService;
    @Resource
    private WindPowerstationTestingPointService windPowerstationTestingPointService;
    @Resource
    private WindTurbineTestingPointAiService windTurbineTestingPointAiService;
    @Resource
    private WindTurbineTestingPointDiService windTurbineTestingPointDiService;
    //RMConfig

    public static int status = 0;
    public static Map<String, RMConfig> rmcmap = new HashMap<String, RMConfig>();
    public static List<Windpowerstation> wpls = new ArrayList<Windpowerstation>(); // 风电场LIST集合
    public static List<Project> pjls = new ArrayList<Project>(); // 项目LIST集合
    public static List<Windturbine> wtls = new ArrayList<Windturbine>(); // 风电机LIST集合
    public static List<Line> lnls = new ArrayList<Line>(); // 线路LIST集合

    public static Map<String, Map<String, WindTurbineTestingPointAi>> wtpAimap = new HashMap<String, Map<String, WindTurbineTestingPointAi>>();// 风电机测点AI表
    public static Map<String, Map<String, WindPowerstationTestingPoint>> stationPointmap = new HashMap<String, Map<String, WindPowerstationTestingPoint>>();//场站测点
    @Override
    public void run(String... args) throws Exception {
        System.out.println(">>>>>>>>>>>>>>>服务启动执行，换成测点关联数据 <<<<<<<<<<<<<");

//        RMConfigExample example=new RMConfigExample();
//        example.createCriteria().getAllCriteria();
//        List<RMConfig> list= rMConfigService.selectByExample(example);
//        if(!list.isEmpty())
//        {
//            for(RMConfig rm:list)
//            {
//                rmcmap.put(rm.getId(),rm);
//            }
//        }
//
//        WindpowerstationExample windpowerstationExample=new WindpowerstationExample();
//        windpowerstationExample.setOrderByClause("ordernum ASC");
//        windpowerstationExample.createCriteria().getAllCriteria();
//        wpls= windpowerstationService.selectByExample(windpowerstationExample);
//
//        ProjectExample projectExample=new ProjectExample();
//        projectExample.setOrderByClause("ordernum ASC");
//        projectExample.createCriteria().getAllCriteria();
//        //pjls= projectService.selectByExample(projectExample);
//
//        LineExample lineExample=new LineExample();
//        lineExample.setOrderByClause("ordernum ASC");
//        lineExample.createCriteria().getAllCriteria();
//        lnls= lineService.selectByExample(lineExample);
//
//        WindturbineExample windturbineExample=new WindturbineExample();
//        windturbineExample.setOrderByClause("id ASC");
//        windturbineExample.createCriteria().getAllCriteria();
//        wtls= windturbineService.selectByExample(windturbineExample);
//

//        WindPowerstationTestingPointExample windPowerstationTestingPointExample=new WindPowerstationTestingPointExample();
//        windPowerstationTestingPointExample.createCriteria().getAllCriteria();
//        List<WindPowerstationTestingPoint> wpPointlist= windPowerstationTestingPointService.selectByExample(windPowerstationTestingPointExample);
//
//        Map<String,WindPowerstationTestingPoint> items=null;
//        if(wpPointlist!=null && !wpPointlist.isEmpty()){
//            for(int i=0;i<wpPointlist.size();i++){
//                WindPowerstationTestingPoint point=wpPointlist.get(i);
//                if(stationPointmap.containsKey(point.getWindpowerstationid())){
//                    items=stationPointmap.get(point.getWindpowerstationid());
//                    items.put(point.getUniformcode(), point);
//                }
//                else{
//                    items=new HashMap<String,WindPowerstationTestingPoint>();
//                    stationPointmap.put(point.getWindpowerstationid(), items);
//                    items.put(point.getUniformcode(), point);
//                }
//
//            }
//        }
//
//        WindTurbineTestingPointAiExample windTurbineTestingPointAiExample=new WindTurbineTestingPointAiExample();
//        windTurbineTestingPointAiExample.createCriteria().getAllCriteria();
//        List<WindTurbineTestingPointAi> wtAilist= windTurbineTestingPointAiService.selectByExample(windTurbineTestingPointAiExample);
//
//        Map<String, WindTurbineTestingPointAi> map = null;
//
//        if(wtAilist != null && !wtAilist.isEmpty()){
//            for(WindTurbineTestingPointAi mp : wtAilist){
//                if(wtpAimap.containsKey(mp.getWindturbineid())){
//                    map = wtpAimap.get(mp.getWindturbineid());
//                    map.put(mp.getUniformcode(), mp);
//                }else{
//                    map = new HashMap<String, WindTurbineTestingPointAi>();
//                    map.put(mp.getUniformcode(), mp);
//                    wtpAimap.put(mp.getWindturbineid(), map);
//                }
//            }
//        }

    }

}
