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.common.exception.ServiceException;
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;

@Api(tags ="民族团结活动管理")
@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) {
            throw new ServiceException("参数为空");
        }
        Integer id = ethnicActivitiesService.addEthnicActivities(ethnicActivitiesAddRequest);
        return AjaxResult.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)) {
            throw new ServiceException("参数为空");
        }
        boolean b = ethnicActivitiesService.deleteEthnicActivities(ids);
        if (b) {
            return AjaxResult.success("删除成功");
        }
        return AjaxResult.error("删除失败");
    }


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

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

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

    /**
     * 完成
     *
     * @param id
     * @return
     */
    @ApiOperation("完成民族团结活动")
    @GetMapping("/complete")
    public AjaxResult completeEthnicActivities(@RequestParam int id) {
        if (id <= 0) {
            throw new ServiceException("参数为空");
        }
        boolean b = ethnicActivitiesService.completeEthnicActivities(id);
        if (b) {
            return AjaxResult.success("完成成功");
        }else{
            return AjaxResult.error("完成失败");
        }
    }

}
