package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.warning.drowningWarning.DrowningWarningAddRequest;
import com.ruoyi.web.domain.dto.warning.drowningWarning.DrowningWarningEditRequest;
import com.ruoyi.web.domain.dto.warning.drowningWarning.DrowningWarningQueryRequest;
import com.ruoyi.web.domain.vo.DrowningWarningVO;
import com.ruoyi.web.service.DrowningWarningService;
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.Map;

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

@Api(tags = "防溺水预警")
@RestController
@RequestMapping("/system/drowning/warning")
public class DrowningWarningController {

    @Autowired
    private DrowningWarningService drowningWarningService;

    /**
     * 添加防溺水预警
     *
     * @param drowningWarningAddRequest
     * @return
     */
    @ApiOperation("添加防溺水预警")
    @PostMapping("/add")
    public AjaxResult addDrowningWarning(@RequestBody DrowningWarningAddRequest drowningWarningAddRequest) {
        if (drowningWarningAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = drowningWarningService.addDrowningWarning(drowningWarningAddRequest);
        return success(id);
    }

    /**
     * 删除防溺水预警
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除防溺水预警")
    @PostMapping("/delete")
    public AjaxResult deleteDrowningWarning(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = drowningWarningService.deleteDrowningWarning(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑防溺水预警
     *
     * @param drowningWarningEditRequest
     * @return
     */
    @ApiOperation("编辑防溺水预警")
    @PostMapping("/edit")
    public AjaxResult editFacility(@RequestBody DrowningWarningEditRequest drowningWarningEditRequest) {
        if (drowningWarningEditRequest == null) {
            return error("请求参数为空");
        }
        drowningWarningService.editDrowningWarning(drowningWarningEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取防溺水预警
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取防溺水预警")
    @GetMapping("/get")
    public AjaxResult getDrowningWarningById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        DrowningWarningVO drowningWarningVO = drowningWarningService.getDrowningWarningById(id);
        return success(drowningWarningVO);
    }

    /**
     * 分页获取防溺水预警列表
     *
     * @param drowningWarningQueryRequest
     * @return
     */
    @ApiOperation("分页获取防溺水预警列表")
    @PostMapping("/list/page")
    public AjaxResult listDrowningWarningByPage(@RequestBody DrowningWarningQueryRequest drowningWarningQueryRequest) {
        if (drowningWarningQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<DrowningWarningVO> listDrowningWarningVOByPage = drowningWarningService.getListDrowningWarningByPage(drowningWarningQueryRequest);
        return success(listDrowningWarningVOByPage);
    }
}
