package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.driver.domain.DriverQuery;
import com.ruoyi.bst.driver.domain.DriverVO;
import com.ruoyi.bst.driver.domain.dto.DriverVerifyDTO;
import com.ruoyi.bst.driver.service.DriverService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 驾驶证认证Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/bst/driver")
public class DriverController extends BaseController
{
    @Autowired
    private DriverService driverService;

    /**
     * 查询驾驶证认证列表
     */
    @PreAuthorize("@ss.hasPermi('bst:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(DriverQuery query)
    {
        startPage();
        startOrderBy();
        List<DriverVO> list = driverService.selectDriverList(query);
        return getDataTable(list);
    }

    /**
     * 导出驾驶证认证列表
     */
    @PreAuthorize("@ss.hasPermi('bst:driver:export')")
    @Log(title = "驾驶证认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DriverQuery query)
    {
        List<DriverVO> list = driverService.selectDriverList(query);
        ExcelUtil<DriverVO> util = new ExcelUtil<DriverVO>(DriverVO.class);
        util.exportExcel(response, list, "驾驶证认证数据");
    }

    /**
     * 获取驾驶证认证详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:driver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(driverService.selectDriverById(id));
    }

    /**
     * 审核驾驶证认证
     */
    @PreAuthorize("@ss.hasPermi('bst:driver:verify')")
    @Log(title = "驾驶证认证审核", businessType = BusinessType.OTHER)
    @PutMapping("/verify")
    public AjaxResult verify(@RequestBody @Validated DriverVerifyDTO dto) {
        dto.setVerifyId(getUserId());
        return toAjax(driverService.verify(dto));
    }
}
