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.SzxcJmCar;
import com.ruoyi.szxc.service.ISzxcJmCarService;
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-30
 */
@RestController
@RequestMapping("/szxc/jmcar")
public class SzxcJmCarController extends BaseController
{
    @Autowired
    private ISzxcJmCarService szxcJmCarService;

    /**
     * 查询居民车辆关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcJmCar szxcJmCar)
    {
        startPage();
        List<SzxcJmCar> list = szxcJmCarService.selectSzxcJmCarList(szxcJmCar);
        return getDataTable(list);
    }

    /**
     * 导出居民车辆关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:export')")
    @Log(title = "居民车辆关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcJmCar szxcJmCar)
    {
        List<SzxcJmCar> list = szxcJmCarService.selectSzxcJmCarList(szxcJmCar);
        ExcelUtil<SzxcJmCar> util = new ExcelUtil<SzxcJmCar>(SzxcJmCar.class);
        util.exportExcel(response, list, "居民车辆关联数据");
    }

    /**
     * 获取居民车辆关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcJmCarService.selectSzxcJmCarById(id));
    }

    /**
     * 新增居民车辆关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:add')")
    @Log(title = "居民车辆关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcJmCar szxcJmCar)
    {
        return toAjax(szxcJmCarService.insertSzxcJmCar(szxcJmCar));
    }

    /**
     * 修改居民车辆关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:edit')")
    @Log(title = "居民车辆关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcJmCar szxcJmCar)
    {
        return toAjax(szxcJmCarService.updateSzxcJmCar(szxcJmCar));
    }

    /**
     * 删除居民车辆关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmcar:remove')")
    @Log(title = "居民车辆关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcJmCarService.deleteSzxcJmCarByIds(ids));
    }
}
