package com.hotwj.platform.config.vehicleThreeInspect.controller;

import com.hotwj.platform.config.vehicleThreeInspect.domain.bo.HotVehicleThreeInspectBo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.bo.HotVehicleThreeInspectBatchAuditBo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.vo.HotVehicleThreeInspectProcessVo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.bo.HotVehicleThreeInspectVehicleQueryBo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.vo.HotVehicleThreeInspectReceivedVehicleVo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.vo.HotVehicleThreeInspectUnreceivedVehicleVo;
import com.hotwj.platform.config.vehicleThreeInspect.domain.vo.HotVehicleThreeInspectVo;
import com.hotwj.platform.config.vehicleThreeInspect.service.IHotVehicleThreeInspectPrintService;
import com.hotwj.platform.config.vehicleThreeInspect.service.IHotVehicleThreeInspectService;
import com.hotwj.platform.resourceManagement.vehicleManagement.domain.vo.HotVehicleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
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-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/vehicleThreeInspect")
@Tag(name = "车辆三检", description = "车辆三检管理")
public class HotVehicleThreeInspectController extends BaseController {

    private final IHotVehicleThreeInspectService hotVehicleThreeInspectService;
    private final IHotVehicleThreeInspectPrintService printService;

    /**
     * 查询车辆三检列表
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询车辆三检列表")
    public TableDataInfo<HotVehicleThreeInspectVo> list(HotVehicleThreeInspectBo bo, PageQuery pageQuery) {
        return hotVehicleThreeInspectService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询车辆三检流程列表
     */
    @GetMapping("/listProcess")
    @Operation(summary = "分页查询车辆三检流程列表")
    public TableDataInfo<HotVehicleThreeInspectProcessVo> listProcess(HotVehicleThreeInspectBo bo, PageQuery pageQuery) {
        return hotVehicleThreeInspectService.queryProcessPageList(bo, pageQuery);
    }

    /**
     * 查询可进行三检的车辆列表
     */
    @GetMapping("/availableVehicles")
    @Operation(summary = "查询可进行三检的车辆列表")
    public R<List<HotVehicleVo>> queryAvailableVehicles(@RequestParam Long companyId) {
        return R.ok(hotVehicleThreeInspectService.queryAvailableVehicles(companyId));
    }

    /**
     * 查询所有三检未收车的车辆列表
     */
    @GetMapping("/unreceivedVehicles")
    @Operation(summary = "查询所有三检还未收车的车辆列表")
    public R<List<HotVehicleThreeInspectUnreceivedVehicleVo>> queryUnreceivedVehicles(HotVehicleThreeInspectVehicleQueryBo bo) {
        return R.ok(hotVehicleThreeInspectService.queryUnreceivedVehicles(bo));
    }

    /**
     * 查询所有三检已收车的车辆列表
     */
    @GetMapping("/receivedVehicles")
    @Operation(summary = "查询所有三检已收车的车辆列表")
    public R<List<HotVehicleThreeInspectReceivedVehicleVo>> queryReceivedVehicles(HotVehicleThreeInspectVehicleQueryBo bo) {
        return R.ok(hotVehicleThreeInspectService.queryReceivedVehicles(bo));
    }

    /**
     * 校验当前驾驶员是否可选择指定车辆
     */
    @GetMapping("/checkSelectableVehicle")
    @Operation(summary = "校验当前驾驶员是否可选择指定车辆")
    public R<Boolean> checkSelectableVehicle(@RequestParam @NotBlank(message = "驾驶员ID不能为空") String driverId,
                                             @RequestParam @NotBlank(message = "车辆ID不能为空") String vehicleId) {
        return R.ok(hotVehicleThreeInspectService.checkSelectableVehicle(driverId, vehicleId));
    }

    /**
     * 导出车辆三检列表
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:export")
    @Log(title = "车辆三检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出车辆三检列表")
    public void export(HotVehicleThreeInspectBo bo, HttpServletResponse response) {
        List<HotVehicleThreeInspectVo> list = hotVehicleThreeInspectService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆三检", HotVehicleThreeInspectVo.class, response);
    }

    /**
     * 导出车辆三检PDF
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:print")
    @Log(title = "车辆三检打印", businessType = BusinessType.EXPORT)
    @PostMapping("/exportPdf")
    @Operation(summary = "导出车辆三检PDF")
    public void exportPdf(HotVehicleThreeInspectBo bo, HttpServletResponse response) {
        printService.exportPdf(bo, response);
    }

    //@SaCheckPermission("securityManagement:vehicleThreeInspect:print")
    @Log(title = "车辆三检表单打印", businessType = BusinessType.EXPORT)
    @PostMapping("/exportFormPdf")
    @Operation(summary = "导出车辆三检检查表单PDF")
    public void exportFormPdf(@RequestParam Long inspectId, HttpServletResponse response) {
        printService.exportFormPdf(inspectId, response);
    }

    /**
     * 获取车辆三检详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取车辆三检详细信息")
    public R<HotVehicleThreeInspectVo> getInfo(@NotNull(message = "主键不能为空")
                                               @Parameter(name = "id", description = "主键", required = true, example = "1")
                                               @PathVariable Long id) {
        return R.ok(hotVehicleThreeInspectService.queryById(id));
    }

    /**
     * 新增车辆三检
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:add")
    @Log(title = "车辆三检", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增车辆三检")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotVehicleThreeInspectBo bo) {
        return toAjax(hotVehicleThreeInspectService.insertByBo(bo));
    }

    /**
     * 修改车辆三检
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:edit")
    @Log(title = "车辆三检", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改车辆三检")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotVehicleThreeInspectBo bo) {
        return toAjax(hotVehicleThreeInspectService.updateByBo(bo));
    }

    /**
     * 审核车辆三检
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:edit")
    @Log(title = "车辆三检", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/audit")
    @Operation(summary = "审核车辆三检")
    public R<Void> audit(@RequestBody HotVehicleThreeInspectBo bo) {
        hotVehicleThreeInspectService.audit(bo);
        return R.ok();
    }

    /**
     * 批量审核车辆三检
     */
    @Log(title = "车辆三检批量审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/batchAudit")
    @Operation(summary = "批量审核车辆三检")
    public R<Void> batchAudit(@Validated @RequestBody HotVehicleThreeInspectBatchAuditBo bo) {
        hotVehicleThreeInspectService.batchAudit(bo);
        return R.ok();
    }

    /**
     * 删除车辆三检
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:vehicleThreeInspect:remove")
    @Log(title = "车辆三检", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除车辆三检")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotVehicleThreeInspectService.deleteWithValidByIds(List.of(ids), true));
    }
}
