package com.hotwj.platform.driverManagement.driverProfCert.controller;

import com.hotwj.platform.driverManagement.driverProfCert.domain.bo.HotDriverProfCertBo;
import com.hotwj.platform.driverManagement.driverProfCert.domain.vo.HotDriverProfCertVo;
import com.hotwj.platform.driverManagement.driverProfCert.service.IHotDriverProfCertService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 从业资格证
 *
 * @author shihongwei
 * @date 2025-12-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/driverManagement/driverProfCert")
@Tag(name = "从业资格证", description = "从业资格证管理")
public class HotDriverProfCertController extends BaseController {

    private final IHotDriverProfCertService hotDriverProfCertService;

    /**
     * 查询从业资格证列表
     */
    //@SaCheckPermission("driverManagement:driver:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询从业资格证列表")
    public TableDataInfo<HotDriverProfCertVo> list(HotDriverProfCertBo bo, PageQuery pageQuery) {
        return hotDriverProfCertService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出从业资格证列表
     */
    //@SaCheckPermission("driverManagement:driver:export")
    @Log(title = "从业资格证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出从业资格证列表")
    public void export(HotDriverProfCertBo bo, HttpServletResponse response) {
        List<HotDriverProfCertVo> list = hotDriverProfCertService.queryList(bo);
        ExcelUtil.exportExcel(list, "从业资格证", HotDriverProfCertVo.class, response);
    }

    /**
     * 获取从业资格证详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("driverManagement:driver:query")
    @GetMapping("/{id}")
    @Operation(summary = "查询从业资格证详情")
    public R<HotDriverProfCertVo> getInfo(@NotNull(message = "主键不能为空")
                                          @PathVariable Long id) {
        return R.ok(hotDriverProfCertService.queryById(id));
    }

    /**
     * 新增从业资格证
     */
    //@SaCheckPermission("driverManagement:driver:add")
    @Log(title = "从业资格证", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增从业资格证")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotDriverProfCertBo bo) {
        return toAjax(hotDriverProfCertService.insertByBo(bo));
    }

    /**
     * 修改从业资格证
     */
    //@SaCheckPermission("driverManagement:driver:edit")
    @Log(title = "从业资格证", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改从业资格证")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotDriverProfCertBo bo) {
        return toAjax(hotDriverProfCertService.updateByBo(bo));
    }

    /**
     * 删除从业资格证
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("driverManagement:driver:remove")
    @Log(title = "从业资格证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除从业资格证")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotDriverProfCertService.deleteWithValidByIds(List.of(ids), true));
    }
}
