package com.cpxt.web.controller.biz;

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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpxt.common.constant.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.BizCarModel;
import com.cpxt.biz.service.IBizCarModelService;
import com.cpxt.common.utils.poi.ExcelUtil;
import com.cpxt.common.core.page.TableDataInfo;

/**
 * 车型Controller
 * 
 * @author YIN
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/biz/model")
public class BizCarModelController extends BaseController
{
    @Autowired
    private IBizCarModelService bizCarModelService;

    /**
     * 查询车型列表（分页）
     */
    @PreAuthorize("@ss.hasPermi('biz:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCarModel bizCarModel,
                              @RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize)
    {
        Page<BizCarModel> recordPage = bizCarModelService.selectBizCarModelPage(bizCarModel,pageNum,pageSize);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(recordPage.getRecords());
        rspData.setTotal(recordPage.getTotal());
        return rspData;
    }

    /**
     * 查询车型列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('biz:model:list')")
    @GetMapping("/list2")
    public AjaxResult list2(BizCarModel bizCarModel)
    {
        return AjaxResult.success(bizCarModelService.selectBizCarModelList(bizCarModel));
    }

    /**
     * 导出车型列表
     */
    @PreAuthorize("@ss.hasPermi('biz:model:export')")
    @Log(title = "车型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCarModel bizCarModel)
    {
        List<BizCarModel> list = bizCarModelService.selectBizCarModelList(bizCarModel);
        ExcelUtil<BizCarModel> util = new ExcelUtil<BizCarModel>(BizCarModel.class);
        util.exportExcel(response, list, "车型数据");
    }

    /**
     * 获取车型详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:model:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCarModelService.selectBizCarModelById(id));
    }

    /**
     * 新增车型
     */
    @PreAuthorize("@ss.hasPermi('biz:model:add')")
    @Log(title = "车型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCarModel bizCarModel)
    {
        return toAjax(bizCarModelService.insertBizCarModel(bizCarModel));
    }

    /**
     * 修改车型
     */
    @PreAuthorize("@ss.hasPermi('biz:model:edit')")
    @Log(title = "车型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCarModel bizCarModel)
    {
        return toAjax(bizCarModelService.updateBizCarModel(bizCarModel));
    }

    /**
     * 删除车型
     */
    @PreAuthorize("@ss.hasPermi('biz:model:remove')")
    @Log(title = "车型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCarModelService.deleteBizCarModelByIds(ids));
    }
}
