package com.cpxt.web.controller.biz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cpxt.common.annotation.Log;
import com.cpxt.common.core.controller.BaseController;
import com.cpxt.common.core.domain.AjaxResult;
import com.cpxt.common.enums.BusinessType;
import com.cpxt.biz.domain.BizDriver;
import com.cpxt.biz.service.IBizDriverService;
import com.cpxt.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 司机Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/driver")
public class BizDriverController extends BaseController
{
    @Autowired
    private IBizDriverService bizDriverService;

    /**
     * 查询司机列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizDriver bizDriver)
    {
        startPage();
        List<BizDriver> list = bizDriverService.selectBizDriverList(bizDriver);
        return getDataTable(list);
    }

    /**
     * 查询司机列表
     */
    @GetMapping("/list2")
    public AjaxResult list2(BizDriver bizDriver)
    {
        return AjaxResult.success(bizDriverService.selectBizDriverList(bizDriver));
    }

    /**
     * 导出司机列表
     */
    @PreAuthorize("@ss.hasPermi('biz:driver:export')")
    @Log(title = "司机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDriver bizDriver)
    {
        List<BizDriver> list = bizDriverService.selectBizDriverList(bizDriver);
        ExcelUtil<BizDriver> util = new ExcelUtil<BizDriver>(BizDriver.class);
        util.exportExcel(response, list, "司机数据");
    }

    /**
     * 获取司机详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizDriverService.selectBizDriverById(id));
    }

    /**
     * 新增司机
     */
    @PreAuthorize("@ss.hasPermi('biz:driver:add')")
    @Log(title = "司机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDriver bizDriver)
    {
        return toAjax(bizDriverService.insertBizDriver(bizDriver));
    }

    /**
     * 修改司机
     */
    @PreAuthorize("@ss.hasPermi('biz:driver:edit')")
    @Log(title = "司机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDriver bizDriver)
    {
        return toAjax(bizDriverService.updateBizDriver(bizDriver));
    }

    /**
     * 删除司机
     */
    @PreAuthorize("@ss.hasPermi('biz:driver:remove')")
    @Log(title = "司机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizDriverService.deleteBizDriverByIds(ids));
    }
}
