package org.dromara.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.domain.vo.SenEventsMediaVo;
import org.dromara.domain.bo.SenEventsMediaBo;
import org.dromara.service.ISenEventsMediaService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 事件媒介

 *
 * @author luogang
 * @date 2024-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/eventsMedia")
public class SenEventsMediaController extends BaseController {

    private final ISenEventsMediaService senEventsMediaService;

    /**
     * 查询事件媒介
列表
     */
    @GetMapping("/list")
    public TableDataInfo<SenEventsMediaVo> list(SenEventsMediaBo bo, PageQuery pageQuery) {
        return senEventsMediaService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出事件媒介列表
     */
    @Log(title = "事件媒介 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SenEventsMediaBo bo, HttpServletResponse response) {
        List<SenEventsMediaVo> list = senEventsMediaService.queryList(bo);
        ExcelUtil.exportExcel(list, "事件媒介 ", SenEventsMediaVo.class, response);
    }

    /**
     * 获取事件媒介
详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<SenEventsMediaVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(senEventsMediaService.queryById(id));
    }

    /**
     * 新增事件媒介

     */
    @Log(title = "事件媒介 ", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SenEventsMediaBo bo) {
        return toAjax(senEventsMediaService.insertByBo(bo));
    }

    /**
     * 修改事件媒介

     */
    @Log(title = "事件媒介 ", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SenEventsMediaBo bo) {
        return toAjax(senEventsMediaService.updateByBo(bo));
    }

    /**
     * 删除事件媒介

     *
     * @param ids 主键串
     */
    @Log(title = "事件媒介 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(senEventsMediaService.deleteWithValidByIds(List.of(ids), true));
    }
    /**
     * 获取事件媒介详细信息
     *
     * @param bo
     */
    @GetMapping("/getMediaByEventId")
    public R<SenEventsMediaVo> getInfo(SenEventsMediaBo bo) {
        return R.ok(senEventsMediaService.getMediaByEventId(bo));
    }
}
