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.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.disaster.DisasterReliefAddRequest;
import com.ruoyi.web.domain.dto.disaster.DisasterReliefEditRequest;
import com.ruoyi.web.domain.dto.disaster.DisasterReliefQueryRequest;
import com.ruoyi.web.domain.vo.DisasterReliefVO;
import com.ruoyi.web.service.DisasterReliefService;
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;

/**
 * 灾情共度管理控制器
 */
@Api(tags ="灾情共度管理")
@RestController
@RequestMapping("/system/disaster/relief")
public class DisasterReliefController extends BaseController {

    @Autowired
    private DisasterReliefService disasterReliefService;

    /**
     * 添加灾情共度记录
     *
     * @param disasterReliefAddRequest 添加请求
     * @return 结果
     */
    @ApiOperation("添加灾情共度记录")
    @PostMapping("/add")
    public AjaxResult addDisasterRelief(@RequestBody DisasterReliefAddRequest disasterReliefAddRequest) {
        if (disasterReliefAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = disasterReliefService.addDisasterRelief(disasterReliefAddRequest);
        return success(id);
    }

    /**
     * 删除灾情共度记录
     *
     * @param paramsMap 参数，包含ids
     * @return 结果
     */
    @ApiOperation("删除灾情共度记录")
    @PostMapping("/delete")
    public AjaxResult deleteDisasterRelief(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean result = disasterReliefService.deleteDisasterRelief(ids);
        if (result) {
            return success("删除成功");
        }
        return error("删除失败");
    }

    /**
     * 编辑灾情共度记录
     *
     * @param disasterReliefEditRequest 编辑请求
     * @return 结果
     */
    @ApiOperation("编辑灾情共度记录")
    @PostMapping("/edit")
    public AjaxResult editDisasterRelief(@RequestBody DisasterReliefEditRequest disasterReliefEditRequest) {
        if (disasterReliefEditRequest == null) {
            return error("请求参数为空");
        }
        disasterReliefService.editDisasterRelief(disasterReliefEditRequest);
        return success();
    }

    /**
     * 根据ID获取灾情共度记录详情
     *
     * @param id 记录ID
     * @return 灾情共度记录详情
     */
    @ApiOperation("根据ID获取灾情共度记录详情")
    @GetMapping("/get")
    public AjaxResult getDisasterReliefById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        DisasterReliefVO disasterReliefVO = disasterReliefService.getDisasterReliefById(id);
        return success(disasterReliefVO);
    }

    /**
     * 分页获取灾情共度记录列表
     *
     * @param disasterReliefQueryRequest 查询请求
     * @return 分页结果
     */
    @ApiOperation("分页获取灾情共度记录列表")
    @PostMapping("/list/page")
    public AjaxResult listDisasterReliefByPage(@RequestBody DisasterReliefQueryRequest disasterReliefQueryRequest) {
        if (disasterReliefQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<DisasterReliefVO> pageResult = disasterReliefService.getListDisasterReliefByPage(disasterReliefQueryRequest);
        return success(pageResult);
    }
} 