package com.ruoyi.web.controller.proprietorCar;

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.system.domain.proprietorCar.ProprietorCar;
import com.ruoyi.system.service.IProprietorCarService;
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 boman
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/wuYe/car")
public class ProprietorCarController extends BaseController {
    @Autowired
    private IProprietorCarService proprietorCarService;

    /**
     * 查询业主车辆管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProprietorCar proprietorCar) {
        startPage();
        List<ProprietorCar> list = proprietorCarService.selectProprietorCarList(proprietorCar);
        return getDataTable(list);
    }

    /**
     * 导出业主车辆管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:export')")
    @Log(title = "业主车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProprietorCar proprietorCar) {
        List<ProprietorCar> list = proprietorCarService.selectProprietorCarList(proprietorCar);
        ExcelUtil<ProprietorCar> util = new ExcelUtil<ProprietorCar>(ProprietorCar.class);
        util.exportExcel(response, list, "业主车辆管理数据");
    }

    /**
     * 获取业主车辆管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId) {
        return success(proprietorCarService.selectProprietorCarByCarId(carId));
    }

    /**
     * 新增业主车辆管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:add')")
    @Log(title = "业主车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProprietorCar proprietorCar) {
        return toAjax(proprietorCarService.insertProprietorCar(proprietorCar));
    }

    /**
     * 修改业主车辆管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:edit')")
    @Log(title = "业主车辆管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ProprietorCar proprietorCar) {
        return toAjax(proprietorCarService.updateProprietorCar(proprietorCar));
    }

    /**
     * 删除业主车辆管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:car:remove')")
    @Log(title = "业主车辆管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds) {
        return toAjax(proprietorCarService.deleteProprietorCarByCarIds(carIds));
    }
}
