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.CompanyAdd;
import com.sckw.slope.detection.model.param.CompanyQuery;
import com.sckw.slope.detection.model.param.DeviceAdd;
import com.sckw.slope.detection.service.CompanyService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
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 矿山Controller
 * @date 2023-10-30 17:10:28
 */
@Slf4j
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    CompanyService companyService;

    @Log(description = "矿山查询-分页")
    @RequestMapping(name = "矿山查询-分页", value = "/select", method = RequestMethod.POST)
    public HttpResult select(@Valid @RequestBody CompanyQuery query, HttpServletRequest request) {
        log.info("矿山查询-分页 select param:{}", JSONObject.toJSONString(query));
        return HttpResult.ok(companyService.select(query, request));
    }

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

    @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 request) {
        log.info("矿山详情 detail param:{}", id);
        return companyService.detail(id, request);
    }

    @Log(description = "矿山编辑")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "矿山编辑", value = "/update", method = RequestMethod.POST)
    public HttpResult update(@Valid @RequestBody CompanyAdd query, HttpServletRequest request) {
        log.info("矿山编辑 update param:{}", JSONObject.toJSONString(query));
        return companyService.update(query, request);
    }


}
