package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.environmentWarningThreshold.EnvironmentWarningThresholdAddRequest;
import com.ruoyi.web.domain.dto.environmentWarningThreshold.EnvironmentWarningThresholdEditRequest;
import com.ruoyi.web.domain.dto.environmentWarningThreshold.EnvironmentWarningThresholdQueryRequest;
import com.ruoyi.web.domain.vo.EnvironmentWarningThresholdVO;
import com.ruoyi.web.service.EnvironmentWarningThresholdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags = "人居环境预警阈值设置")
@RestController
@RequestMapping("/system/environment/warning/threshold")
public class EnvironmentWarningThresholdController {

    @Autowired
    private EnvironmentWarningThresholdService environmentWarningThresholdService;

    /**
     * 添加人居环境预警阈值
     *
     * @param environmentWarningThresholdAddRequest
     * @return
     */
    @ApiOperation("添加人居环境预警阈值")
    @PostMapping("/add")
    public AjaxResult addEnvironmentWarningThreshold(@RequestBody EnvironmentWarningThresholdAddRequest environmentWarningThresholdAddRequest) {
        if (environmentWarningThresholdAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = environmentWarningThresholdService.addEnvironmentWarningThreshold(environmentWarningThresholdAddRequest);
        return success(id);
    }

    /**
     * 删除人居环境预警阈值
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除人居环境预警阈值")
    @PostMapping("/delete")
    public AjaxResult deleteEnvironmentWarningThreshold(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = environmentWarningThresholdService.deleteEnvironmentWarningThreshold(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑人居环境预警阈值
     *
     * @param environmentWarningThresholdEditRequest
     * @return
     */
    @ApiOperation("编辑人居环境预警阈值")
    @PostMapping("/edit")
    public AjaxResult editEnvironmentWarningThreshold(@RequestBody EnvironmentWarningThresholdEditRequest environmentWarningThresholdEditRequest) {
        if (environmentWarningThresholdEditRequest == null) {
            return error("请求参数为空");
        }
        environmentWarningThresholdService.editEnvironmentWarningThreshold(environmentWarningThresholdEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取人居环境预警阈值
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取人居环境预警阈值")
    @GetMapping("/get")
    public AjaxResult getEnvironmentWarningThresholdById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        EnvironmentWarningThresholdVO environmentWarningThresholdVO = environmentWarningThresholdService.getEnvironmentWarningThresholdById(id);
        return success(environmentWarningThresholdVO);
    }

    /**
     * 获取人居环境预警阈值列表
     *
     * @param environmentWarningThresholdQueryRequest
     * @return
     */
    @ApiOperation("获取人居环境预警阈值列表")
    @PostMapping("/list")
    public AjaxResult listEnvironmentWarningThresholdByPage(@RequestBody EnvironmentWarningThresholdQueryRequest environmentWarningThresholdQueryRequest) {
        if (environmentWarningThresholdQueryRequest == null) {
            return error("请求参数为空");
        }
        List<EnvironmentWarningThresholdVO> listEnvironmentWarningThreshold = environmentWarningThresholdService.getListEnvironmentWarningThreshold(environmentWarningThresholdQueryRequest);
        return success(listEnvironmentWarningThreshold);
    }

}
