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.ethnicActivities.EthnicActivitiesAddRequest;
import com.ruoyi.web.domain.dto.ethnicActivities.EthnicActivitiesEditRequest;
import com.ruoyi.web.domain.dto.ethnicActivities.EthnicActivitiesQueryRequest;
import com.ruoyi.web.domain.vo.EthnicActivitiesVO;
import com.ruoyi.web.service.EthnicActivitiesService;
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("民族团结活动管理")
@RestController
@RequestMapping("/system/ethnic/activities")
public class EthnicActivitiesController {

    @Autowired
    private EthnicActivitiesService ethnicActivitiesService;

    /**
     * 添加民族团结活动数据
     *
     * @param ethnicActivitiesAddRequest
     * @return
     */
    @ApiOperation("添加民族团结活动数据")
    @PostMapping("/add")
    public AjaxResult addEthnicActivities(@RequestBody EthnicActivitiesAddRequest ethnicActivitiesAddRequest) {
        if (ethnicActivitiesAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = ethnicActivitiesService.addEthnicActivities(ethnicActivitiesAddRequest);
        return success(id);
    }

    /**
     * 删除民族团结活动数据
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除民族团结活动数据")
    @PostMapping("/delete")
    public AjaxResult deleteEthnicActivities(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = ethnicActivitiesService.deleteEthnicActivities(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑民族团结活动数据
     *
     * @param ethnicActivitiesEditRequest
     * @return
     */
    @ApiOperation("编辑民族团结活动数据")
    @PostMapping("/edit")
    public AjaxResult editFacility(@RequestBody EthnicActivitiesEditRequest ethnicActivitiesEditRequest) {
        if (ethnicActivitiesEditRequest == null) {
            return error("请求参数为空");
        }
        ethnicActivitiesService.editEthnicActivities(ethnicActivitiesEditRequest);
        return AjaxResult.success();
    }

    /**
     * 根据id获取民族团结活动数据
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取民族团结活动数据")
    @GetMapping("/get")
    public AjaxResult getEthnicActivitiesById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        EthnicActivitiesVO ethnicActivitiesVO = ethnicActivitiesService.getEthnicActivitiesById(id);
        return success(ethnicActivitiesVO);
    }

    /**
     * 分页获取民族团结活动数据列表
     *
     * @param ethnicActivitiesQueryRequest
     * @return
     */
    @ApiOperation("分页获取民族团结活动数据列表")
    @PostMapping("/list/page")
    public AjaxResult listEthnicActivitiesByPage(@RequestBody EthnicActivitiesQueryRequest ethnicActivitiesQueryRequest) {
        if (ethnicActivitiesQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<EthnicActivitiesVO> listEthnicActivitiesByPageVO = ethnicActivitiesService.getListEthnicActivitiesByPage(ethnicActivitiesQueryRequest);
        return success(listEthnicActivitiesByPageVO);
    }
}
