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.dto.IsEnableDTO;
import com.sckw.slope.detection.model.dto.ReportTemplateAddDTO;
import com.sckw.slope.detection.model.dto.ReportTemplateUpdateDTO;
import com.sckw.slope.detection.model.param.StatementQuery;
import com.sckw.slope.detection.service.ReportTemplateService;
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("/reportTemplate")
public class ReportTemplateController {

    @Autowired
    ReportTemplateService reportTemplateService;

    @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(reportTemplateService.select(query, request));
    }

    @Log(description = "模版新增")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "模版新增", value = "/add", method = RequestMethod.POST)
    public HttpResult add(@RequestBody @Valid ReportTemplateAddDTO reportTemplateDTO, HttpServletRequest request) {
        log.info("模版新增 add param:{}", JSONObject.toJSONString(reportTemplateDTO));
        return reportTemplateService.add(reportTemplateDTO, request);
    }

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

    @Log(description = "修改模版")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "修改模版", value = "/update", method = RequestMethod.POST)
    public HttpResult update(@RequestBody @Valid ReportTemplateUpdateDTO reportTemplateUpdateDTO, HttpServletRequest request) {
        log.info("修改模版 update param:{}", JSONObject.toJSONString(reportTemplateUpdateDTO));
        return reportTemplateService.update(reportTemplateUpdateDTO, request);
    }

    @Log(description = "模版启用/模版禁用")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "模版启用/模版禁用", value = "/enable", method = RequestMethod.POST)
    public HttpResult enable(@RequestBody @Valid IsEnableDTO isEnable, HttpServletRequest request) {
        log.info("模版启用/模版禁用 enable param:{}", JSONObject.toJSONString(isEnable));
        return reportTemplateService.enable(isEnable, 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 reportTemplateService.dels(ids, request);
    }

}
