package com.jiayue.ipfcst.console.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.HolidayCalendar;
import com.jiayue.ipfcst.common.data.entity.OverhaulPlan;
import com.jiayue.ipfcst.console.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 控制管理首页控制层
 *
 * @author tl
 * @version 3.0
 */
@RestController
@RequestMapping("consoleDsb")
public class ConsoleDsbController {

  private final WindTowerInfoService windTowerInfoService;

  private final WindTurbineInfoService windTurbineInfoService;

  private final WeatherStationInfoService weatherStationInfoService;

  private final PvModuleModelService pvModuleModelService;

  private final HolidayCalendarService holidayCalendarService;

  private final OverHaulPlanService overHaulPlanService;

  private final InverterInfoService inverterInfoService;

  @Autowired
  public ConsoleDsbController(WindTowerInfoService windTowerInfoService, WindTurbineInfoService windTurbineInfoService, WeatherStationInfoService weatherStationInfoService, PvModuleModelService pvModuleModelService,HolidayCalendarService holidayCalendarService,OverHaulPlanService overHaulPlanService,InverterInfoService inverterInfoService){
    this.windTowerInfoService = windTowerInfoService;
    this.windTurbineInfoService = windTurbineInfoService;
    this.weatherStationInfoService = weatherStationInfoService;
    this.pvModuleModelService = pvModuleModelService;
    this.holidayCalendarService = holidayCalendarService;
    this.overHaulPlanService = overHaulPlanService;
    this.inverterInfoService = inverterInfoService;
  }

  //查询设备数量
  @GetMapping("/getCount")
  public ResponseVO getCount(){

    Map<String,Object> map = new HashMap();

    map.put("wetherNumber",weatherStationInfoService.getAll().size());
    map.put("windTowerNumber",windTowerInfoService.getAll().size());
    map.put("windTurbineNumber",windTurbineInfoService.getAll().size());
    map.put("pvModuleModelNumber", pvModuleModelService.getAll().size());
    map.put("inverterInfoNumber", inverterInfoService.getAll().size());

    return ResponseVO.success(map);
  }


  //查询最近的假期日历时间和最近的检修计划
  @GetMapping("/getTime")
  public ResponseVO getTime(){
    Map<String,Object> map = new HashMap<>();
    HolidayCalendar holidayCalendar = holidayCalendarService.findByNextTime();
    if(holidayCalendar.getId()==null){
      map.put("holidayCalendar",null);
    }else {
      map.put("holidayCalendar",holidayCalendar);
    }
    OverhaulPlan overhaulPlan = overHaulPlanService.findByNextTime();
    if(overhaulPlan.getId()==null){
      map.put("overhaulPlan",null);
    }else {
      map.put("overhaulPlan",overhaulPlan);
    }
    return ResponseVO.success(map);
  }


}
