package com.sooka.sponest.monitor.device.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.sooka.sponest.monitor.device.domain.CentermonitorTMonitoringDevice;
import com.sooka.sponest.monitor.device.domain.CentermonitorTMonitoringThresholdWaterVelocity;
import com.sooka.sponest.monitor.device.service.ICentermonitorTMonitoringDeviceThresholdService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 监测设备阈值Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/threshold")
public class CentermonitorTMonitoringDeviceThresholdController extends BaseController {
    @Resource
    private ICentermonitorTMonitoringDeviceThresholdService centermonitorTMonitoringDeviceThresholdService;

    /**
     * 通过设备编码查询水流速传感器阈值
     * */
    @Log(title = "水流速传感器", businessType = BusinessType.OTHER)
    @RequiresPermissions("camera:device:threshold")
    @GetMapping(value = "/selectWaterVelocityThresholdByCode/{deviceCode}")
    public AjaxResult selectWaterVelocityThresholdByCode(@PathVariable("deviceCode") String deviceCode){
        CentermonitorTMonitoringThresholdWaterVelocity thresholdWaterVelocity = centermonitorTMonitoringDeviceThresholdService.selectWaterVelocityThresholdByCode(deviceCode);
        return AjaxResult.success(thresholdWaterVelocity == null ? new CentermonitorTMonitoringThresholdWaterVelocity() : thresholdWaterVelocity);
    }

    /**
     * 新增水流速监测设备阈值
     */
    @Log(title = "水流速传感器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CentermonitorTMonitoringThresholdWaterVelocity centermonitorTMonitoringThresholdWaterVelocity) {
        return toAjax(centermonitorTMonitoringDeviceThresholdService.insertWaterVelocityThreshold(centermonitorTMonitoringThresholdWaterVelocity));
    }

    /**
     * 修改水流速监测设备阈值
     */
    @Log(title = "水流速传感器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CentermonitorTMonitoringThresholdWaterVelocity centermonitorTMonitoringThresholdWaterVelocity) {
        return toAjax(centermonitorTMonitoringDeviceThresholdService.updateWaterVelocityThreshold(centermonitorTMonitoringThresholdWaterVelocity));
    }
}
