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.TblDzbcCarVo;
import org.dromara.system.domain.bo.TblDzbcCarBo;
import org.dromara.system.service.ITblDzbcCarService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 定制班车-车辆
 *
 * @author Lion Li
 * @date 2025-02-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dzbcCar")
public class TblDzbcCarController extends BaseController {

    private final ITblDzbcCarService tblDzbcCarService;

    /**
     * 查询定制班车-车辆列表
     */
    //@SaCheckPermission("system:dzbcCar:list")
    @GetMapping("/list")
    public TableDataInfo<TblDzbcCarVo> list(TblDzbcCarBo bo, PageQuery pageQuery) {
        return tblDzbcCarService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出定制班车-车辆列表
     */
    //@SaCheckPermission("system:dzbcCar:export")
    @Log(title = "定制班车-车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblDzbcCarBo bo, HttpServletResponse response) {
        List<TblDzbcCarVo> list = tblDzbcCarService.queryList(bo);
        ExcelUtil.exportExcel(list, "定制班车-车辆", TblDzbcCarVo.class, response);
    }

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

    /**
     * 新增定制班车-车辆
     */
    //@SaCheckPermission("system:dzbcCar:add")
    @Log(title = "定制班车-车辆", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TblDzbcCarBo bo) {
        return toAjax(tblDzbcCarService.insertByBo(bo));
    }

    /**
     * 修改定制班车-车辆
     */
    //@SaCheckPermission("system:dzbcCar:edit")
    @Log(title = "定制班车-车辆", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TblDzbcCarBo bo) {
        return toAjax(tblDzbcCarService.updateByBo(bo));
    }

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