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.param.DeviceModelAdd;
import com.sckw.slope.detection.model.param.DeviceModelQuery;
import com.sckw.slope.detection.service.DeviceModelService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author sky
 * @description 设备Model controller
 * @date 2023-10-30 17:10:24
 */
@Slf4j
@RestController
@RequestMapping("/deviceModel")
public class DeviceModelController {


    @Autowired
    DeviceModelService deviceModelService;

    @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 response) {
        log.info("设备型号删除 delete param:{}", ids);
        return deviceModelService.dels(ids,response);
    }


    @Log(description = "设备型号查询-分页")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "设备型号查询-分页", value = "/select", method = RequestMethod.POST)
    public HttpResult select(@Valid @RequestBody DeviceModelQuery deviceModelQuery, HttpServletRequest response) {
        log.info("设备型号查询 select param:{}", JSONObject.toJSONString(deviceModelQuery));
        return HttpResult.ok(deviceModelService.select(deviceModelQuery, response));
    }

    @Log(description = "设备型号新增")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "设备型号新增", value = "/add", method = RequestMethod.POST)
    public HttpResult add(@Valid @RequestBody DeviceModelAdd deviceModelAdd, HttpServletRequest response) {
        log.info("设备型号新增 add param:{}", JSONObject.toJSONString(deviceModelAdd));
        return deviceModelService.add(deviceModelAdd, response);
    }

    @Log(description = "设备型号详情")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "设备型号详情", value = "/detail", method = RequestMethod.GET)
    public HttpResult detail(@RequestParam("id") @NotNull(message = "数据id不能为空") long id, HttpServletRequest response) {
        log.info("设备型号详情 detail param:{}", id);
        return deviceModelService.detail(id, response);
    }


    @Log(description = "设备型号编辑")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "设备型号编辑", value = "/update", method = RequestMethod.POST)
    public HttpResult update(@Valid @RequestBody DeviceModelAdd deviceModelAdd, HttpServletRequest response) {
        log.info("设备型号编辑 update param:{}", JSONObject.toJSONString(deviceModelAdd));
        return deviceModelService.update(deviceModelAdd, response);
    }

    @Log(description = "查询设备型号")
    @TraceLog(description = "查询设备型号")
    @RequestMapping(name = "查询设备型号", value = "/findModelList", method = RequestMethod.GET)
    public HttpResult findModelList(HttpServletRequest request) {
        log.info("查询设备型号 findModelList");
        return deviceModelService.findModelList(request);
    }
}
