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.*;
import com.sckw.slope.detection.model.param.DeviceQuery;
import com.sckw.slope.detection.model.param.ProjectChartLogParam;
import com.sckw.slope.detection.model.param.ProjectQuery;
import com.sckw.slope.detection.service.CommonService;
import com.sckw.slope.detection.service.ProjectService;
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 13:10:42
 */
@Slf4j
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    ProjectService projectService;

    @Autowired
    CommonService commonService;

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

    @Log(description = "项目新增")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目新增", value = "/add", method = RequestMethod.POST)
    public HttpResult projectAdd(@Valid @RequestBody ProjectAddDTO projectAddDto, HttpServletRequest response) {
        log.info("项目新增 add param:{}", JSONObject.toJSONString(projectAddDto));
        return projectService.add(projectAddDto, response);
    }

    @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 response) {
        log.info("项目详情 detail param:{}", id);
        return projectService.detail(id, response);
    }

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

    @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("项目删除 delete param:{}", ids);
        return projectService.dels(ids, request);
    }

    @Log(description = "项目监测要素项")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目监测要素项", value = "/monitorItem", method = RequestMethod.GET)
    public HttpResult monitorItem(@RequestParam("id") @NotBlank(message = "数据id不能为空") String id, HttpServletRequest request) {
        log.info("项目监测要素项 select param:{}", id);
        return projectService.monitorItem(id, request);
    }

    @Log(description = "设备组网查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "设备组网查询", value = "/selectDevice", method = RequestMethod.POST)
    public HttpResult selectDevice(@RequestBody @Valid DeviceQuery deviceQuery, HttpServletRequest request) {
        log.info("设备组网查询 select param:{}", JSONObject.toJSONString(deviceQuery));
        return HttpResult.ok(projectService.selectDevice(deviceQuery, request));
    }

    @Log(description = "新增组网设备-关联设备-查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "新增组网设备-关联设备-查询", value = "/deviceBindSelect", method = RequestMethod.POST)
    public HttpResult deviceBindSelect(@RequestBody @Valid DeviceQuery bindDevice, HttpServletRequest request) {
        log.info("新增组网设备-关联设备-查询 deviceBindSelect param:{}", JSONObject.toJSONString(bindDevice));
        return HttpResult.ok(projectService.deviceBindSelect(bindDevice, request));
    }

    @Log(description = "新增组网设备-关联设备")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "新增组网设备-关联设备", value = "/deviceBind", method = RequestMethod.POST)
    public HttpResult deviceBind(@RequestBody @Valid BindDevice bindDevice, HttpServletRequest request) {
        log.info("新增组网设备-关联设备 deviceBind param:{}", JSONObject.toJSONString(bindDevice));
        return projectService.deviceBind(bindDevice, request);
    }

    @TraceLog(description = "修改组网设备-关联设备-查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "修改组网设备-关联设备-查询", value = "/updateDeviceBindSelect", method = RequestMethod.GET)
    public HttpResult updateDeviceBindSelect(@RequestParam("id") @NotBlank(message = "关联id不能为空") String id, HttpServletRequest request) {
        log.info("修改组网设备-关联设备-查询 updateDeviceBindSelect param:{}", id);
        return projectService.updateDeviceBindSelect(id, request);
    }

    @TraceLog(description = "修改组网设备-关联设备")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "修改组网设备-关联设备", value = "/updateDeviceBind", method = RequestMethod.POST)
    public HttpResult updateDeviceBind(@RequestBody @Valid BindDevice bindDevice, HttpServletRequest request) {
        log.info("新增组网设备-关联设备 updateDeviceBind param:{}", JSONObject.toJSONString(bindDevice));
        return projectService.updateDeviceBind(bindDevice, request);
    }

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

    @Log(description = "项目设备删除")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目设备删除", value = "/deviceDelete", method = RequestMethod.POST)
    public HttpResult deviceDelete(@RequestBody @Valid DeviceDeleteDTO deviceDelete, HttpServletRequest request) {
        log.info("项目设备删除 deviceDelete delete:{}", JSONObject.toJSONString(deviceDelete));
        return projectService.deviceDelete(deviceDelete, request);
    }

    @Log(description = "项目详情-图表查询")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目详情-图表查询", value = "/chartLog", method = RequestMethod.POST)
    public HttpResult chartLog(@Valid @RequestBody ProjectChartLogParam param, HttpServletRequest request) {
        log.info("项目详情-图表查询 chartLog param:{}", JSONObject.toJSONString(param));
        return projectService.chartLog(param, request);
    }

    @Log(description = "查询所有项目")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "查询所有项目", value = "/selectAll", method = RequestMethod.GET)
    public HttpResult selectAll(HttpServletRequest request) {
        return projectService.selectAll(request);
    }

    @Log(description = "数据总览")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "数据总览", value = "/dataScreening", method = RequestMethod.GET)
    public HttpResult dataScreening(/*@RequestParam("projectId") */String companyId,/*@RequestParam("projectId") */String projectId ,HttpServletRequest request) {
        log.info("数据总览 dataScreening param:{}", projectId,companyId);
        HeaderData headerData = commonService.getHeaderData(request);
        return projectService.dataScreening(projectId,headerData.getCompanyId());
    }

    @Log(description = "项目查询(项目+设备)")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目查询(项目+设备)", value = "/projectList", method = RequestMethod.GET)
    public HttpResult projectList(/*@RequestParam("projectId")*/ String projectId ,HttpServletRequest request) {
        log.info("项目查询(项目+设备) projectList param:{}", projectId);
        HeaderData headerData = commonService.getHeaderData(request);
        return projectService.projectList(projectId,headerData);
    }
}
