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.mediaPropaganda.MediaPropagandaAddRequest;
import com.ruoyi.web.domain.dto.mediaPropaganda.MediaPropagandaEditRequest;
import com.ruoyi.web.domain.dto.mediaPropaganda.MediaPropagandaQueryRequest;
import com.ruoyi.web.domain.vo.MediaPropagandaVO;
import com.ruoyi.web.service.MediaPropagandaService;
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/media/propaganda")
public class MediaPropagandaController extends BaseController {

    @Autowired
    private MediaPropagandaService mediaPropagandaService;

    /**
     * 添加媒体宣传内容
     *
     * @param mediaPropagandaAddRequest 添加请求
     * @return 结果
     */
    @ApiOperation("添加媒体宣传内容")
    @PostMapping("/add")
    public AjaxResult addMediaPropaganda(@RequestBody MediaPropagandaAddRequest mediaPropagandaAddRequest) {
        if (mediaPropagandaAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = mediaPropagandaService.addMediaPropaganda(mediaPropagandaAddRequest);
        return success(id);
    }

    /**
     * 删除媒体宣传内容
     *
     * @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 = mediaPropagandaService.deleteMediaPropaganda(ids);
        if (result) {
            return success("删除成功");
        }
        return error("删除失败");
    }

    /**
     * 编辑媒体宣传内容
     *
     * @param mediaPropagandaEditRequest 编辑请求
     * @return 结果
     */
    @ApiOperation("编辑媒体宣传内容")
    @PostMapping("/edit")
    public AjaxResult editMediaPropaganda(@RequestBody MediaPropagandaEditRequest mediaPropagandaEditRequest) {
        if (mediaPropagandaEditRequest == null) {
            return error("请求参数为空");
        }
        mediaPropagandaService.editMediaPropaganda(mediaPropagandaEditRequest);
        return success();
    }

    /**
     * 根据ID获取媒体宣传内容详情
     *
     * @param id 记录ID
     * @return 媒体宣传内容详情
     */
    @ApiOperation("根据ID获取媒体宣传内容详情")
    @GetMapping("/get")
    public AjaxResult getMediaPropagandaById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        MediaPropagandaVO mediaPropagandaVO = mediaPropagandaService.getMediaPropagandaById(id);
        return success(mediaPropagandaVO);
    }

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