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

import javax.annotation.Resource;

/**
 * 监测设备阈值Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/atmosphereThreshold")
public class CentermonitorTMonitoringDeviceAtmosphereThresholdController extends BaseController {
    @Resource
    private ICentermonitorTMonitoringDeviceAtmosphereThresholdService centermonitorTMonitoringDeviceAtmosphereThresholdService;
    /**
     * 通过设备编码查询大气传感器阈值
     * */
    @Log(title = "大气传感器", businessType = BusinessType.OTHER)
    @RequiresPermissions("camera:device:threshold")
    @GetMapping(value = "/selectAtmosphereThresholdByCode/{deviceCode}")
    public AjaxResult selectAtmosphereThresholdByCode(@PathVariable("deviceCode") String deviceCode){
        CentermonitorTMonitoringThresholdAtmosphere thresholdAtmosphere = centermonitorTMonitoringDeviceAtmosphereThresholdService.selectAtmosphereThresholdByCode(deviceCode);
        return AjaxResult.success(thresholdAtmosphere == null ? new CentermonitorTMonitoringThresholdAtmosphere() : thresholdAtmosphere);
    }

    /**
     * 新增大气监测设备阈值
     */
    @Log(title = "大气传感器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CentermonitorTMonitoringThresholdAtmosphere centermonitorTMonitoringThresholdAtmosphere) {
        return toAjax(centermonitorTMonitoringDeviceAtmosphereThresholdService.insertAtmosphereThreshold(centermonitorTMonitoringThresholdAtmosphere));
    }

    /**
     * 修改大气监测设备阈值
     */
    @Log(title = "大气传感器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CentermonitorTMonitoringThresholdAtmosphere centermonitorTMonitoringThresholdAtmosphere) {
        return toAjax(centermonitorTMonitoringDeviceAtmosphereThresholdService.updateAtmosphereThreshold(centermonitorTMonitoringThresholdAtmosphere));
    }
}
