package com.gyee.frame.controller.benchmarking;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Windturbineinfodaytop3;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.model.custom.ValueVo;
import com.gyee.frame.service.Windturbineinfodaytop3Service;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/benchmarking")
public class BenchmarkingController {
    @Autowired
    private Windturbineinfodaytop3Service windturbineinfodaytop3Service;

    /**查询等级评估日所有信息**/
    @GetMapping("/gadaylist")
    @ResponseBody
    public AjaxResult gadaylist(String wpId, String recorddate) {

        Date tempDate=null;
        if (StringUtils.isNotEmpty(recorddate))
        {
            tempDate=DateUtils.parseDate(recorddate);
        }
        List<Windturbineinfodaytop3> ls=windturbineinfodaytop3Service.gadaylist(wpId,tempDate);

        if(ls !=null && !ls.isEmpty())
        {
            return	AjaxResult.successData(AjaxStatus.success.code,ls);
        }else
        {
            return	AjaxResult.successData(AjaxStatus.emptyresultset.code,ls);
        }

    }
    /**按页查询等级评估日所有信息**/
    @PostMapping("/gadaylistByPage")
    @ResponseBody
    public AjaxResult gadaylistByPage(Tablepar tablepar,String wpId, String recorddate) {

        Date tempDate=null;
        if (StringUtils.isNotEmpty(recorddate))
        {
            tempDate=DateUtils.parseDate(recorddate);
        }
        PageInfo<Windturbineinfodaytop3> ls=windturbineinfodaytop3Service.gadaylistByPage(tablepar,wpId,tempDate);


        return	AjaxResult.successData(AjaxStatus.success.code,ls);

    }
    /**按页查询等级评估月所有信息**/
    @PostMapping("/gamonthlistByPage")
    @ResponseBody
    public AjaxResult gamonthlistByPage(Tablepar tablepar,String wpId, String year,String month) {


        PageInfo<Windturbineinfodaytop3> ls=windturbineinfodaytop3Service.gamonthlistByPage(tablepar,wpId,year,month);

        return	AjaxResult.successData(AjaxStatus.success.code,ls);

    }
    /**按页查询等级评估年所有信息**/
    @PostMapping("/gayearlistByPage")
    @ResponseBody
    public AjaxResult gayearlistByPage(Tablepar tablepar,String wpId, String year) {


        PageInfo<Windturbineinfodaytop3> ls=windturbineinfodaytop3Service.gayearlistByPage(tablepar,wpId,year);

        return	AjaxResult.successData(AjaxStatus.success.code,ls);

    }
    /**按等级评估ID查询相应信息返回玫瑰图**/
    @GetMapping("/wtchart")
    @ResponseBody
    public AjaxResult wtchart(String gaid1,String gaid2) {


        if (StringUtils.isNotEmpty(gaid1) && StringUtils.isNotEmpty(gaid2))
        {
            List<ValueVo> ls1=windturbineinfodaytop3Service.wtchart(gaid1);
            List<ValueVo> ls2=windturbineinfodaytop3Service.wtchart(gaid2);

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

            map.put("gaid1",ls1);
            map.put("gaid2",ls2);

            return	AjaxResult.successData(AjaxStatus.success.code,map);
        }

         return	AjaxResult.error(AjaxStatus.error.code,null);
    }

    /**按等级评估ID查询相应详细信息**/
    @GetMapping("/wtinfo")
    @ResponseBody
    public AjaxResult wtinfo(String gaid1,String gaid2) {


        if (StringUtils.isNotEmpty(gaid1) && StringUtils.isNotEmpty(gaid2))
        {
            Map<String,Windturbineinfodaytop3> map=new HashMap();

            Windturbineinfodaytop3 wtd1=windturbineinfodaytop3Service.selectByPrimaryKey(gaid1);
            Windturbineinfodaytop3 wtd2=windturbineinfodaytop3Service.selectByPrimaryKey(gaid2);

            map.put("gaid1",wtd1);
            map.put("gaid2",wtd2);

            return	AjaxResult.successData(AjaxStatus.success.code,map);
        }

        return	AjaxResult.error(AjaxStatus.error.code,null);
    }
}
