package com.gyee.frame.controller.goodness;

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.Windturbineanalysisday;
import com.gyee.frame.model.auto.Windturbinegoodness;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.WindturbineanalysisdayService;
import com.gyee.frame.service.goodness.WindturbinegoodnessService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * 单机性能分析列表
 */
@Controller
@RequestMapping("/goodness")
public class WindturbinegoodnessController {
    @Resource
    private WindturbinegoodnessService windturbinegoodnessService;
    @Resource
    private WindturbineanalysisdayService windturbineanalysisdayService;


    /**
     * 获得单机性能总览列表信息
     *
     * @param tablepar
     * @param wpId
     * @param recorddate
     * @return
     */
    @PostMapping("/windturbinegoodness")
    @ResponseBody
    public AjaxResult windturbinegoodness(Tablepar tablepar, String wpId, String recorddate) {

        PageInfo<Windturbinegoodness> resultList = windturbinegoodnessService.windturbinegoodnessList(tablepar, wpId, recorddate);
        if (resultList != null) {
            return AjaxResult.successData(AjaxStatus.success.code, resultList);
        } else {
            return AjaxResult.successData(AjaxStatus.emptyresultset.code, resultList);
        }
    }


    /**
     * 获得单机性能总览历史列表信息
     *
     * @param tablepar
     * @param wtId
     * @param beginDate
     * @param endDate
     * @return
     */
    @PostMapping("/goodhistorylist")
    @ResponseBody
    public AjaxResult goodhistorylist(Tablepar tablepar, String wtId, String beginDate, String endDate) {
        List<Windturbineanalysisday> resultList =new ArrayList<>();
        if(StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate) )
        {
            resultList = windturbineanalysisdayService.goodhistorylist(tablepar,wtId, DateUtils.parseDate(beginDate),  DateUtils.parseDate(endDate));
        }
        if (resultList != null) {
            return AjaxResult.successData(AjaxStatus.success.code, resultList);
        } else {
            return AjaxResult.successData(AjaxStatus.emptyresultset.code, resultList);
        }
    }

}
