package com.gyee.frame.controller.powercompare;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Windturbineinfoday3;
import com.gyee.frame.model.benchmarking.PowerCompareDetail;
import com.gyee.frame.service.Windpowerinfoday3Service;
import com.gyee.frame.service.Windturbineinfoday3Service;
import com.gyee.frame.service.benchmarking.PowerCompareDetailService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @ClassName : PowerCompareDetailController
 * @Author : xieshengjie
 * @Date: 2021/1/30 19:15
 * @Description : 风机绩效榜明细Controller
 */
@Controller
@RequestMapping("/powercomparedetail")
public class PowerCompareDetailController {

    @Resource
    private PowerCompareDetailService powerCompareDetailService;




    /**查询风机列表数据结果**/
    @GetMapping("/powerAjaxDetail")
    @ResponseBody
    public AjaxResult powerAjaxDetail(@RequestParam(value = "beginDate",required = true) String beginDate,
                                      @RequestParam(value = "endDate",required = true) String endDate,
                                      @RequestParam(value = "wpId",required = false) String  wpId,
                                      @RequestParam(value = "pjId",required = false) String  pjId,
                                      @RequestParam(value = "xlId",required = false) String  xlId )  {
        Date begin = DateUtils.parseDate(beginDate);
        Date end = DateUtils.parseDate(endDate);
        List<PowerCompareDetail>  vos = powerCompareDetailService.getDetailWtInfo(begin,end,wpId,pjId,xlId);
        if(vos !=null && !vos.isEmpty())
        {
            vos.stream().forEach(i -> i.setFnlyl(i.getScadafdl()/i.getLlfdl()*100));
            return	AjaxResult.successData(AjaxStatus.success.code,vos);
        }else
        {
            return	AjaxResult.successData(AjaxStatus.emptyresultset.code,vos);
        }
    }

    /**查询风场、项目、线路列表数据结果**/
    @GetMapping("/powerAjaxDetailAll")
    @ResponseBody
    public AjaxResult powerAjaxDetailAll(@RequestParam(value = "beginDate",required = true) String beginDate,
                                         @RequestParam(value = "endDate",required = true) String endDate,
                                         @RequestParam(value = "queryType",required = true) String  queryType)  {

        List<PowerCompareDetail>  vos=null;
        Date begin = DateUtils.parseDate(beginDate);
        Date end = DateUtils.parseDate(endDate);
        if (queryType.equals("fc")) {
            vos = powerCompareDetailService.getDetailInfo(begin,end,0);
        } else if (queryType.equals("pj")) {
            vos = powerCompareDetailService.getDetailInfo(begin,end,1);
        } else if (queryType.equals("xl")) {
            vos = powerCompareDetailService.getDetailInfo(begin,end,2);
        }
        if(vos !=null && !vos.isEmpty())
        {
            vos.stream().forEach(i -> i.setFnlyl(i.getScadafdl()/i.getLlfdl()*100));
            return	AjaxResult.successData(AjaxStatus.success.code,vos);
        }else
        {
            return	AjaxResult.successData(AjaxStatus.emptyresultset.code,vos);
        }
    }
}
