package org.dromara.ygpassport.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ygpassport.domain.vo.ExtracActivitiesVo;
import org.dromara.ygpassport.domain.bo.ExtracActivitiesBo;
import org.dromara.ygpassport.service.IExtracActivitiesService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 第二课堂活动记录
 *
 * @author Lion Li
 * @date 2024-03-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ygpassport/extracActivities")
public class ExtracActivitiesController extends BaseController {

    private final IExtracActivitiesService extracActivitiesService;

    /**
     * 查询第二课堂活动记录列表
     */
    @SaCheckPermission("ygpassport:extracActivities:list")
    @GetMapping("/list")
    public TableDataInfo<ExtracActivitiesVo> list(ExtracActivitiesBo bo, PageQuery pageQuery) {
        return extracActivitiesService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出第二课堂活动记录列表
     */
    @SaCheckPermission("ygpassport:extracActivities:export")
    @Log(title = "第二课堂活动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExtracActivitiesBo bo, HttpServletResponse response) {
        List<ExtracActivitiesVo> list = extracActivitiesService.queryList(bo);
        ExcelUtil.exportExcel(list, "第二课堂活动记录", ExtracActivitiesVo.class, response);
    }

    /**
     * 获取第二课堂活动记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("ygpassport:extracActivities:query")
    @GetMapping("/{id}")
    public R<ExtracActivitiesVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(extracActivitiesService.queryById(id));
    }

    /**
     * 新增第二课堂活动记录
     */
    @SaCheckPermission("ygpassport:extracActivities:add")
    @Log(title = "第二课堂活动记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExtracActivitiesBo bo) {
        return toAjax(extracActivitiesService.insertByBo(bo));
    }

    /**
     * 修改第二课堂活动记录
     */
    @SaCheckPermission("ygpassport:extracActivities:edit")
    @Log(title = "第二课堂活动记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExtracActivitiesBo bo) {
        return toAjax(extracActivitiesService.updateByBo(bo));
    }

    /**
     * 删除第二课堂活动记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("ygpassport:extracActivities:remove")
    @Log(title = "第二课堂活动记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(extracActivitiesService.deleteWithValidByIds(List.of(ids), true));
    }
}
