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

import com.hotwj.platform.driverManagement.driverHealthReport.domain.bo.HotDriverHealthReportBo;
import com.hotwj.platform.driverManagement.driverHealthReport.domain.vo.HotDriverHealthReportVo;
import com.hotwj.platform.driverManagement.driverHealthReport.service.IHotDriverHealthReportService;
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/driverHealthReport")
@Tag(name = "驾驶员体检报告", description = "体检报告管理")
public class HotDriverHealthReportController extends BaseController {

    private final IHotDriverHealthReportService hotDriverHealthReportService;

    /**
     * 查询驾驶员体检报告列表
     */
    //@SaCheckPermission("driverManagement:driver:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询驾驶员体检报告列表")
    public TableDataInfo<HotDriverHealthReportVo> list(HotDriverHealthReportBo bo, PageQuery pageQuery) {
        return hotDriverHealthReportService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出驾驶员体检报告列表
     */
    //@SaCheckPermission("driverManagement:driver:export")
    @Log(title = "驾驶员体检报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出驾驶员体检报告列表")
    public void export(HotDriverHealthReportBo bo, HttpServletResponse response) {
        List<HotDriverHealthReportVo> list = hotDriverHealthReportService.queryList(bo);
        ExcelUtil.exportExcel(list, "驾驶员体检报告", HotDriverHealthReportVo.class, response);
    }

    /**
     * 获取驾驶员体检报告详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("driverManagement:driver:query")
    @GetMapping("/{id}")
    @Operation(summary = "查询驾驶员体检报告详情")
    public R<HotDriverHealthReportVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return R.ok(hotDriverHealthReportService.queryById(id));
    }

    /**
     * 归档驾驶员体检报告
     *
     * @param id 主键
     */
    //@SaCheckPermission("driverManagement:driverHealthReport:edit")
    @Log(title = "驾驶员体检报告", businessType = BusinessType.UPDATE)
    @PutMapping("/archive/{id}")
    @Operation(summary = "归档驾驶员体检报告")
    public R<Void> archive(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return toAjax(hotDriverHealthReportService.archive(id));
    }

    /**
     * 新增驾驶员体检报告
     */
    //@SaCheckPermission("driverManagement:driver:add")
    @Log(title = "驾驶员体检报告", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增驾驶员体检报告")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotDriverHealthReportBo bo) {
        return toAjax(hotDriverHealthReportService.insertByBo(bo));
    }

    /**
     * 修改驾驶员体检报告
     */
    //@SaCheckPermission("driverManagement:driverHealthReport:edit")
    @Log(title = "驾驶员体检报告", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改驾驶员体检报告")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotDriverHealthReportBo bo) {
        return toAjax(hotDriverHealthReportService.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(hotDriverHealthReportService.deleteWithValidByIds(List.of(ids), true));
    }
}
