package com.gyee.alarm.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.model.auto.ProEconEarlyReport;
import com.gyee.alarm.model.vo.AjaxResult;
import com.gyee.alarm.model.vo.AjaxStatus;
import com.gyee.alarm.service.EarlyReportService;
import com.gyee.alarm.util.StringUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 预警报告 前端控制器
 * </p>
 *
 * @author shilin
 * @since 2023-09-05
 */
@RestController
@RequestMapping("//earlyreport")
public class ProEconEarlyReportController {


    @Resource
    private EarlyReportService earlyReportService;

    @ApiOperation(value = "分页查询风机诊断报告")
    @GetMapping("/list")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pagesize", value = "分页大小", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "stationId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键字", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "starttime", value = "起始时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endtime", value = "结束时间", required = true, dataType = "string", paramType = "query")

    })
    public AjaxResult getReportList(Integer pageNum,Integer pageSize,String stationid,String keyWord,String startTime,String endTime  ) {

        Page<ProEconEarlyReport> page = new Page<>(pageNum,pageSize);

        IPage reportByPage = earlyReportService.getReportByPage(page,stationid);
        if (StringUtils.notEmp(reportByPage)) {

            return AjaxResult.successData(AjaxStatus.success.code, reportByPage);
        } else {
            return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
        }
    }

    @ApiOperation(value = "根据id获取报告详细内容")
    @GetMapping("/info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "报告编号", required = true, dataType = "String", paramType = "query")
    })
    public AjaxResult getReportInfo(String reportId) {

        ProEconEarlyReport report = earlyReportService.getEarlyReportById(reportId);

        if (StringUtils.notEmp(report)) {

            return AjaxResult.successData(AjaxStatus.success.code, report);
        } else {
            return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
        }
    }


}
