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

import javax.annotation.Resource;

/**
 * 监测设备阈值Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/soilMoistureThreshold")
public class CentermonitorTMonitoringDeviceSoilMoistureThresholdController extends BaseController {
    @Resource
    private ICentermonitorTMonitoringDeviceSoilMoistureThresholdService centermonitorTMonitoringDeviceSoilMoistureThresholdService;

    /**
     * 通过设备编码查询土壤传感器阈值
     * */
    @Log(title = "土壤传感器", businessType = BusinessType.OTHER)
    @RequiresPermissions("camera:device:threshold")
    @GetMapping(value = "/selectSoilMoistureThresholdByCode/{deviceCode}")
    public AjaxResult selectSoilMoistureThresholdByCode(@PathVariable("deviceCode") String deviceCode){
        CentermonitorTMonitoringThresholdSoilMoisture thresholdSoilMoisture = centermonitorTMonitoringDeviceSoilMoistureThresholdService.selectSoilMoistureThresholdByCode(deviceCode);
        return AjaxResult.success(thresholdSoilMoisture == null ? new CentermonitorTMonitoringThresholdSoilMoisture() : thresholdSoilMoisture);
    }

    /**
     * 新增土壤监测设备阈值
     */
    @Log(title = "土壤传感器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CentermonitorTMonitoringThresholdSoilMoisture centermonitorTMonitoringThresholdSoilMoisture) {
        return toAjax(centermonitorTMonitoringDeviceSoilMoistureThresholdService.insertSoilMoistureThreshold(centermonitorTMonitoringThresholdSoilMoisture));
    }

    /**
     * 修改土壤监测设备阈值
     */
    @Log(title = "土壤传感器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CentermonitorTMonitoringThresholdSoilMoisture centermonitorTMonitoringThresholdSoilMoisture) {
        return toAjax(centermonitorTMonitoringDeviceSoilMoistureThresholdService.updateSoilMoistureThreshold(centermonitorTMonitoringThresholdSoilMoisture));
    }
}
