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.environmentWarningThresholdRole.EnvironmentWarningThresholdUserAddRequest;
import com.ruoyi.web.domain.dto.environmentWarningThresholdRole.EnvironmentWarningThresholdUserEditRequest;
import com.ruoyi.web.domain.dto.environmentWarningThresholdRole.EnvironmentWarningThresholdUserQueryRequest;
import com.ruoyi.web.domain.vo.EnvironmentWarningThresholdUserVO;
import com.ruoyi.web.service.EnvironmentWarningThresholdUserService;
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/environmentWarning/warning/threshold/user")
public class EnvironmentWarningThresholdUserController {

    @Autowired
    private EnvironmentWarningThresholdUserService environmentWarningThresholdUserService;

    /**
     * 添加人居环境负责人
     *
     * @param environmentWarningThresholdUserAddRequest
     * @return
     */
    @ApiOperation("添加人居环境负责人")
    @PostMapping("/add")
    public AjaxResult addEnvironmentWarningThresholdUser(@RequestBody EnvironmentWarningThresholdUserAddRequest environmentWarningThresholdUserAddRequest) {
        if (environmentWarningThresholdUserAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = environmentWarningThresholdUserService.addEnvironmentWarningThresholdUser(environmentWarningThresholdUserAddRequest);
        return success(id);
    }

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


    /**
     * 编辑人居环境负责人
     *
     * @param environmentWarningThresholdUserEditRequest
     * @return
     */
    @ApiOperation("编辑人居环境负责人")
    @PostMapping("/edit")
    public AjaxResult editEnvironmentWarningThresholdUser(@RequestBody EnvironmentWarningThresholdUserEditRequest environmentWarningThresholdUserEditRequest) {
        if (environmentWarningThresholdUserEditRequest == null) {
            return error("请求参数为空");
        }
        environmentWarningThresholdUserService.editEnvironmentWarningThresholdUser(environmentWarningThresholdUserEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取人居环境负责人
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取人居环境负责人")
    @GetMapping("/get")
    public AjaxResult getEnvironmentWarningThresholdUserById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        EnvironmentWarningThresholdUserVO environmentWarningThresholdUserVO = environmentWarningThresholdUserService.getEnvironmentWarningThresholdUserVOById(id);
        return success(environmentWarningThresholdUserVO);
    }

    /**
     * 获取人居环境负责人列表
     *
     * @param environmentWarningThresholdUserQueryRequest
     * @return
     */
    @ApiOperation("获取人居环境负责人列表")
    @PostMapping("/list")
    public AjaxResult getListEnvironmentWarningThresholdUser(@RequestBody EnvironmentWarningThresholdUserQueryRequest environmentWarningThresholdUserQueryRequest) {
        if (environmentWarningThresholdUserQueryRequest == null) {
            return error("请求参数为空");
        }
        List<EnvironmentWarningThresholdUserVO> listEnvironmentWarningThresholdUserVO = environmentWarningThresholdUserService.getListEnvironmentWarningThresholdUserVO(environmentWarningThresholdUserQueryRequest);
        return success(listEnvironmentWarningThresholdUserVO);
    }

}
