package com.yeejoin.equipmanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.equipmanage.common.dto.AnalysisReportLogDto;
import com.yeejoin.equipmanage.service.IFireAutoSysManageReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
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 org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @author shg
 * @date 2022-04-28
 */
@RestController
@Api(tags = "消防自动化综合管理报表Api")
@RequestMapping(value = "/fire-manage-report")
@Slf4j
public class FireAutoSysManageReportController extends BaseController {

    @Autowired
    IFireAutoSysManageReportService iFireAutoSysManageReportService;

    @ApiOperation(value = "下载报表", notes = "下载报表")
    @GetMapping(value = "/download")
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    public void download(HttpServletRequest request, HttpServletResponse response,
                         @ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
                         @ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                         @ApiParam(value = "结束日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        iFireAutoSysManageReportService.download(request, response, stationCode, startDate, endDate);
    }

    @ApiOperation(value = "预览报表", notes = "预览报表")
    @GetMapping(value = "/preview")
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    public String preview(
            @ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
            @ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @ApiParam(value = "结束日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        return iFireAutoSysManageReportService.preview(stationCode, startDate, endDate);
    }

    @SuppressWarnings("unchecked")
    @ApiOperation(value = "所有站查询列表", notes = "所有站查询列表")
    @GetMapping(value = "/allPage")
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    public IPage<AnalysisReportLogDto> allPage(Page page, @RequestParam Integer reportType,
                                               @ApiParam(value = "开始日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                               @ApiParam(value = "结束日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
                                               @ApiParam(value = "换流站编码") @RequestParam(required = false) String stationCode) {
        return iFireAutoSysManageReportService.allPage(page, reportType, startDate, endDate, stationCode);
    }

}
