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.CentermonitorTMonitoringThresholdWaterQuality;
import com.sooka.sponest.monitor.device.service.ICentermonitorTMonitoringDeviceWaterQualityThresholdService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 监测设备阈值Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/waterQualityThreshold")
public class CentermonitorTMonitoringDeviceWaterQualityThresholdController extends BaseController {
    @Resource
    private ICentermonitorTMonitoringDeviceWaterQualityThresholdService centermonitorTMonitoringDeviceWaterQualityThresholdService;

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

    /**
     * 新增水质监测设备阈值
     */
    @PostMapping
    @Log(title = "水质传感器", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody CentermonitorTMonitoringThresholdWaterQuality centermonitorTMonitoringThresholdWaterQuality) {
        return toAjax(centermonitorTMonitoringDeviceWaterQualityThresholdService.insertWaterQualityThreshold(centermonitorTMonitoringThresholdWaterQuality));
    }

    /**
     * 修改水质监测设备阈值
     */
    @PutMapping
    @Log(title = "水质传感器", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody CentermonitorTMonitoringThresholdWaterQuality centermonitorTMonitoringThresholdWaterQuality) {
        return toAjax(centermonitorTMonitoringDeviceWaterQualityThresholdService.updateWaterQualityThreshold(centermonitorTMonitoringThresholdWaterQuality));
    }
}
