package beilv.web.controller.carinformation;

import beilv.carinformation.domain.CarInformation;
import beilv.carinformation.service.ICarInformationService;
import beilv.common.annotation.Log;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.core.page.TableDataInfo;
import beilv.common.enums.BusinessType;
import beilv.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 卡种信息Controller
 *
 * @author ruoyi
 * @date 2025-01-02
 */
@Controller
@RequestMapping("/information")
public class CarInformationController extends BaseController {
    private String prefix = "information";

    @Autowired
    private ICarInformationService carInformationService;

    @RequiresPermissions("system:information:view")
    @GetMapping()
    public String information() {
        return prefix + "/information";
    }

    /**
     * 查询卡种信息列表
     */
    @RequiresPermissions("system:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarInformation carInformation) {
        startPage();
        List<CarInformation> list = carInformationService.selectCarInformationList(carInformation);
        return getDataTable(list);
    }

    /**
     * 导出卡种信息列表
     */
    @RequiresPermissions("system:information:export")
    @Log(title = "卡种信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarInformation carInformation) {
        List<CarInformation> list = carInformationService.selectCarInformationList(carInformation);
        ExcelUtil<CarInformation> util = new ExcelUtil<CarInformation>(CarInformation.class);
        return util.exportExcel(list, "卡种信息数据");
    }

    /**
     * 新增卡种信息
     */
    @RequiresPermissions("system:information:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存卡种信息
     */
    @RequiresPermissions("system:information:add")
    @Log(title = "卡种信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarInformation carInformation) {
        return toAjax(carInformationService.insertCarInformation(carInformation));
    }

    /**
     * 修改卡种信息
     */
    @RequiresPermissions("system:information:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CarInformation carInformation = carInformationService.selectCarInformationById(id);
        mmap.put("carInformation", carInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡种信息
     */
    @RequiresPermissions("system:information:edit")
    @Log(title = "卡种信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarInformation carInformation) {
        return toAjax(carInformationService.updateCarInformation(carInformation));
    }

    /**
     * 删除卡种信息
     */
    @RequiresPermissions("system:information:remove")
    @Log(title = "卡种信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(carInformationService.deleteCarInformationByIds(ids));
    }
}
