package org.dromara.system.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.system.domain.vo.TblDzbcBannerVo;
import org.dromara.system.domain.bo.TblDzbcBannerBo;
import org.dromara.system.service.ITblDzbcBannerService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 定制班车-小程序banner
 *
 * @author Lion Li
 * @date 2025-02-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dzbcBanner")
public class TblDzbcBannerController extends BaseController {

    private final ITblDzbcBannerService tblDzbcBannerService;

    /**
     * 查询定制班车-小程序banner列表
     */
    //@SaCheckPermission("system:dzbcBanner:list")
    @GetMapping("/list")
    public TableDataInfo<TblDzbcBannerVo> list(TblDzbcBannerBo bo, PageQuery pageQuery) {
        return tblDzbcBannerService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出定制班车-小程序banner列表
     */
    //@SaCheckPermission("system:dzbcBanner:export")
    @Log(title = "定制班车-小程序banner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblDzbcBannerBo bo, HttpServletResponse response) {
        List<TblDzbcBannerVo> list = tblDzbcBannerService.queryList(bo);
        ExcelUtil.exportExcel(list, "定制班车-小程序banner", TblDzbcBannerVo.class, response);
    }

    /**
     * 获取定制班车-小程序banner详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("system:dzbcBanner:query")
    @GetMapping("/{id}")
    public R<TblDzbcBannerVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tblDzbcBannerService.queryById(id));
    }

    /**
     * 新增定制班车-小程序banner
     */
    //@SaCheckPermission("system:dzbcBanner:add")
    @Log(title = "定制班车-小程序banner", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TblDzbcBannerBo bo) {
        return toAjax(tblDzbcBannerService.insertByBo(bo));
    }

    /**
     * 修改定制班车-小程序banner
     */
    //@SaCheckPermission("system:dzbcBanner:edit")
    @Log(title = "定制班车-小程序banner", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TblDzbcBannerBo bo) {
        return toAjax(tblDzbcBannerService.updateByBo(bo));
    }

    /**
     * 删除定制班车-小程序banner
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("system:dzbcBanner:remove")
    @Log(title = "定制班车-小程序banner", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tblDzbcBannerService.deleteWithValidByIds(List.of(ids), true));
    }
}
