package com.ruoyi.szxc.controller;

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;
import com.ruoyi.szxc.domain.SzxcCarInfo;
import com.ruoyi.szxc.service.ISzxcCarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆信息Controller
 * 
 * @author hs
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/szxc/carinfo")
public class SzxcCarInfoController extends BaseController
{
    @Autowired
    private ISzxcCarInfoService szxcCarInfoService;

    /**
     * 查询车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcCarInfo szxcCarInfo)
    {
        startPage();
        List<SzxcCarInfo> list = szxcCarInfoService.selectSzxcCarInfoList(szxcCarInfo);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:export')")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcCarInfo szxcCarInfo)
    {
        List<SzxcCarInfo> list = szxcCarInfoService.selectSzxcCarInfoList(szxcCarInfo);
        ExcelUtil<SzxcCarInfo> util = new ExcelUtil<SzxcCarInfo>(SzxcCarInfo.class);
        util.exportExcel(response, list, "车辆信息数据");
    }

    /**
     * 获取车辆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcCarInfoService.selectSzxcCarInfoById(id));
    }

    /**
     * 新增车辆信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:add')")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcCarInfo szxcCarInfo)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcCarInfo.getDeptId()==null){
            szxcCarInfo.setDeptId(getDeptId());
        }
        szxcCarInfo.setUserId(getUserId());
        return toAjax(szxcCarInfoService.insertSzxcCarInfo(szxcCarInfo));
    }

    /**
     * 修改车辆信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:edit')")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcCarInfo szxcCarInfo)
    {
        return toAjax(szxcCarInfoService.updateSzxcCarInfo(szxcCarInfo));
    }

    /**
     * 删除车辆信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:carinfo:remove')")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcCarInfoService.deleteSzxcCarInfoByIds(ids));
    }
}
