package com.sckw.slope.detection.controller;

import com.alibaba.fastjson2.JSONObject;
import com.sckw.core.annotation.Log;
import com.sckw.core.web.response.HttpResult;
import com.sckw.slope.detection.model.param.StatementQuery;
import com.sckw.slope.detection.service.ReportService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lfdc
 * @description 报表Controller
 * @date 2023-10-30 17:10:27
 */
@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    ReportService reportService;

    @Log(description = "报表查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "报表查询", value = "/select", method = RequestMethod.POST)
    public HttpResult select(@RequestBody @Valid StatementQuery query, HttpServletRequest request) {
        log.info("报表查询 select param:{}", JSONObject.toJSONString(query));
        return HttpResult.ok(reportService.select(query, request));
    }

    @Log(description = "模版详情")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "模版详情", value = "/detail", method = RequestMethod.GET)
    public HttpResult detail(@RequestParam("id") @NotBlank(message = "id不能为空") String id, HttpServletRequest request) {
        log.info("模版详情 detail param:{}", id);
        return reportService.detail(id, request);
    }

    @Log(description = "报表删除")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "报表删除", value = "/dels", method = RequestMethod.GET)
    public HttpResult dels(@RequestParam("ids") @NotBlank(message = "id不能为空") String ids, HttpServletRequest request) {
        log.info("报表删除 dels param:{}", ids);
        return reportService.dels(ids, request);
    }

    @Log(description = "报表导出")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "报表导出", value = "/export", method = RequestMethod.GET)
    public HttpResult export(@RequestParam("ids") @NotBlank(message = "id不能为空") String ids, HttpServletRequest request) {
        log.info("报表导出 export param:{}", ids);
        return reportService.export(ids, request);
    }
}
