package com.gyee.frame.controller.warn;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.custom.ShutdowneventVo;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.ShutdowneventService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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;

@Controller
@RequestMapping("/event")
@Api(value = "停机事件", tags = "停机事件")
public class ShutdowneventController {

    @Resource
    private ShutdowneventService shutdowneventService;


    /**
     *
     * @param tablepar
     * @param wpId
     * @param wtId
     * @param beginDate
     * @param endDate
     * @param type
     * @return
     * @throws Exception
     */
    @PostMapping("/getShutdownevent")
    @ResponseBody
    @ApiOperation(value = "停机事件查询", notes = "停机事件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页控件", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型", required = false, dataType = "string", paramType = "query")})

    public AjaxResult getShutdownevent(Tablepar tablepar, String wpId, String wtId, String beginDate, String endDate, String type) throws Exception {

        PageInfo<ShutdowneventVo> result=new PageInfo<>() ;
        if (StringUtils.notEmp(tablepar) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            result=shutdowneventService.getShutdownevent(tablepar, wpId, wtId, DateUtils.parseDate(beginDate), DateUtils.parseDate(endDate), type);

        }
        if (null != result) {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, result);
        }

    }


}
