package com.ruoyi.web.controller.chenyanlogin.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.controller.chenyanlogin.entity.NationUnity;
import com.ruoyi.web.controller.chenyanlogin.service.INationUnityService;
import com.ruoyi.web.domain.dto.mediaPropaganda.MediaPropagandaEditRequest;
import com.ruoyi.web.domain.dto.mediaPropaganda.MediaPropagandaQueryRequest;
import com.ruoyi.web.domain.vo.MediaPropagandaVO;
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;

/**
 * <p>
 * 民族团结内容收集表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-23
 */
@RestController
@RequestMapping("/nation-unity")
@Api(tags ="民族团结")
public class NationUnityController {
    @Autowired
    private INationUnityService nationUnityService;

    /**
     * 添加民族团结内容
     *
     * @param mediaPropagandaAddRequest 添加请求
     * @return 结果
     */
    @ApiOperation("添加民族团结内容")
    @PostMapping("/add")
    public AjaxResult addMediaPropaganda(@RequestBody NationUnity mediaPropagandaAddRequest) {
        if (mediaPropagandaAddRequest == null) {
            return error("请求参数为空");
        }
        nationUnityService.save(mediaPropagandaAddRequest);
//        Integer id = nationUnityService.addMediaPropaganda(mediaPropagandaAddRequest);
        return success();
    }



    /**
     * 删除民族团结内容
     *
     * @param paramsMap 参数，包含ids
     * @return 结果
     */
    @ApiOperation("删除民族团结内容")
    @PostMapping("/delete")
    public AjaxResult deleteMediaPropaganda(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean result = nationUnityService.deleteMediaPropaganda(ids);
        if (result) {
            return success("删除成功");
        }
        return error("删除失败");
    }

    /**
     * 编辑民族团结内容
     *
     * @param mediaPropagandaEditRequest 编辑请求
     * @return 结果
     */
    @ApiOperation("编辑民族团结内容")
    @PostMapping("/edit")
    public AjaxResult editMediaPropaganda(@RequestBody NationUnity mediaPropagandaEditRequest) {
        if (mediaPropagandaEditRequest == null) {
            return error("请求参数为空");
        }
        nationUnityService.updateById(mediaPropagandaEditRequest);
        return success();
    }

    /**
     * 根据ID获取民族团结内容详情
     *
     * @param id 记录ID
     * @return 民族团结内容详情
     */
    @ApiOperation("根据ID获取民族团结内容详情")
    @GetMapping("/get")
    public AjaxResult getMediaPropagandaById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }

        return success( nationUnityService.getById(id));
    }

    /**
     * 分页获取民族团结内容列表
     *
     * @param mediaPropagandaQueryRequest 查询请求
     * @return 分页结果
     */
    @ApiOperation("分页获取民族团结内容列表")
    @PostMapping("/list/page")
    public AjaxResult listMediaPropagandaByPage(@RequestBody MediaPropagandaQueryRequest mediaPropagandaQueryRequest) {
        if (mediaPropagandaQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<MediaPropagandaVO> pageResult = nationUnityService.getListMediaPropagandaByPage(mediaPropagandaQueryRequest);
        return success(pageResult);
    }
    @ApiOperation("获取民族团结内容列表")
    @PostMapping("/list/list")
    public AjaxResult listMediaPropagandaByPage() {

        return success(nationUnityService.list(new QueryWrapper<NationUnity>().orderByDesc("id")));
    }

}
