package cn.iocoder.yudao.module.inspection.controller;

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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionPickCar;
import cn.iocoder.yudao.module.inspection.service.IInspectionPickCarService;

/**
 * 上门取车服务Controller
 *
 * @author 朱春云
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/admin-api/inspection/pickCar")
public class InspectionPickCarController extends BaseController
{
    @Autowired
    private IInspectionPickCarService inspectionPickCarService;

    /**
     * 查询上门取车服务列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:list')")
    @GetMapping("/list")
    public CommonResult list(InspectionPickCar inspectionPickCar,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionPickCar> page = new Page<>(pageNum, pageSize);
        IPage<InspectionPickCar> list = inspectionPickCarService.selectInspectionPickCarList(page,inspectionPickCar);
        return success(list);
    }

    /**
     * 导出上门取车服务列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionPickCar inspectionPickCar,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionPickCar> page = new Page<>(pageNum, pageSize);
        IPage<InspectionPickCar> list = inspectionPickCarService.selectInspectionPickCarList(page,inspectionPickCar);
        ExcelUtil<InspectionPickCar> util = new ExcelUtil<InspectionPickCar>(InspectionPickCar.class);
        util.exportExcel(response, list.getRecords(), "上门取车服务数据");
    }

    /**
     * 获取上门取车服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionPickCarService.selectInspectionPickCarById(id));
    }

    /**
     * 新增上门取车服务
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:add')")
    @PostMapping
    public CommonResult add(@RequestBody InspectionPickCar inspectionPickCar)
    {
        return toAjax(inspectionPickCarService.insertInspectionPickCar(inspectionPickCar));
    }

    /**
     * 修改上门取车服务
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:edit')")
    @PutMapping
    public CommonResult edit(@RequestBody InspectionPickCar inspectionPickCar)
    {
        return toAjax(inspectionPickCarService.updateInspectionPickCar(inspectionPickCar));
    }

    /**
     * 删除上门取车服务
     */
    @PreAuthorize("@ss.hasPermi('inspection:pickCar:remove')")
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionPickCarService.deleteInspectionPickCarByIds(ids));
    }
}
