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.log.TraceLog.TraceLog;
import com.sckw.slope.detection.model.dto.DeleteThresholdDTO;
import com.sckw.slope.detection.model.dto.ThresholdConfigurationDTO;
import com.sckw.slope.detection.model.param.ProjectAndDeviceParam;
import com.sckw.slope.detection.model.param.ProjectThresholdSettingParam;
import com.sckw.slope.detection.model.param.ThresholdDetailQuery;
import com.sckw.slope.detection.model.param.ThresholdQuery;
import com.sckw.slope.detection.service.ThresholdService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfdc
 * @description 阈值controller
 * @date 2023-10-30 17:10:25
 */
@Slf4j
@RestController
@RequestMapping("/threshold")
public class ThresholdController {

    @Autowired
    ThresholdService thresholdService;

    @Log(description = "阈值查询-分页")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "阈值查询-分页", value = "/select", method = RequestMethod.POST)
    public HttpResult select(@Valid @RequestBody ThresholdQuery thresholdQuery, HttpServletRequest request) {
        log.info("阈值查询-分页 select param:{}", JSONObject.toJSONString(thresholdQuery));
        return HttpResult.ok(thresholdService.select(thresholdQuery, request));
    }



    @Log(description = "项目和设备查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目和设备查询", value = "/getDevice", method = RequestMethod.POST)
    public HttpResult getDevice(@RequestBody @Valid ProjectAndDeviceParam param , HttpServletRequest request) {
        log.info("数据总览 getDevice param:{}", JSONObject.toJSONString(param));
        return thresholdService.getDevice(param);
    }

    @Log(description = "阈值详情")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "阈值详情", value = "/detail", method = RequestMethod.POST)
    public HttpResult detail(@Valid @RequestBody ThresholdDetailQuery thresholdQuery, HttpServletRequest request) {
        log.info("阈值详情 detail param:{}", JSONObject.toJSONString(thresholdQuery));
        return thresholdService.detail(thresholdQuery, request);
    }

    @TraceLog(description = "阈值配置")
    @Log(description = "阈值配置")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "阈值配置", value = "/configuration", method = RequestMethod.POST)
    public HttpResult configuration(@Valid @RequestBody ThresholdConfigurationDTO configurationDTO, HttpServletRequest request) {
        log.info("阈值配置 configuration param:{}", JSONObject.toJSONString(configurationDTO));
        return thresholdService.configuration(configurationDTO, request);
    }

    @Log(description = "阈值删除")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "阈值删除", value = "/dels", method = RequestMethod.POST)
    public HttpResult dels(@Valid @RequestBody DeleteThresholdDTO deleteThreshold, HttpServletRequest request) {
        log.info("阈值删除 dels param:{}", JSONObject.toJSONString(deleteThreshold));
        return thresholdService.dels(deleteThreshold, request);
    }


    @Log(description = "阈值设置查询-app")
    @TraceLog(description = "阈值设置查询-app")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "阈值设置查询-app", value = "/selectSetting", method = RequestMethod.POST)
    public HttpResult selectSetting(@Valid @RequestBody ProjectThresholdSettingParam param, HttpServletRequest request) {
        log.info("阈值设置查询-app selectSetting param:{}", JSONObject.toJSONString(param));
        return thresholdService.selectSetting(param, request);
    }

}
