package com.zksy.web.controller.base.alarm;

import com.zksy.base.alarm.domain.WarningThreshold;
import com.zksy.base.alarm.service.WarningThresholdService;
import com.zksy.common.annotation.Anonymous;
import com.zksy.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project pipe-ner-server
 * @description 预警阈值
 * @date 2025/9/1 10:29:11
 */
@RestController
@RequestMapping("/warningThreshold")
@Api(tags = "预警阈值信息",description = "预警阈值信息desc")
public class WarningThresholdController {
    @Autowired
    private WarningThresholdService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "预警阈值信息查询分页")
    @Anonymous
    public AjaxResult findByPage(@ApiParam(value = "页码", required = true)long pageNum,
                                 @ApiParam(value = "页数", required = true)long pageSize,
                                 @ApiParam(value = "设备编码", required = false)String deviceCode,
                                 @ApiParam(value = "预警类型", allowableValues = "温度预警,压力预警,湿度预警", required = false) String warningType,
                                 @ApiParam(value = "预警编码", required = false) String warningCode){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, deviceCode,warningType,warningCode));
    }
    @GetMapping("/getWarningThresholdList")
    @ApiOperation(value = "预警阈值信息查询")
    @Anonymous
    public AjaxResult getWarningThresholdList(@ApiParam(value = "设备编码",  required = false)String deviceCode,
                                              @ApiParam(value = "预警类型",  allowableValues = "温度预警,压力预警,湿度预警", required = false) String warningType,
                                              @ApiParam(value = "预警编码",  required = false) String warningCode
    ){
        return AjaxResult.success(service.getWarningThresholdList(deviceCode,warningType,warningCode));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询预警阈值信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "预警阈值信息保存")
    public AjaxResult save(@RequestBody WarningThreshold entity) {
        return service.save(entity) ? AjaxResult.success(entity): AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "预警阈值信息修改")
    public AjaxResult update(@RequestBody WarningThreshold entity) {
        entity.setUpdateTime(LocalDateTime.now());
        return service.updateById(entity) ? AjaxResult.success(entity): AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "预警阈值信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
}
