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.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.inspection.entity.InspectionAppointment;
import cn.iocoder.yudao.module.inspection.service.IInspectionAppointmentService;
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;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2023-08-24
 */
@RestController
@RequestMapping("/admin-api/inspection/appointment")
public class InspectionAppointmentController extends BaseController
{
    @Autowired
    private IInspectionAppointmentService inspectionAppointmentService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:list')")
    @GetMapping("/list")
    public CommonResult list(InspectionAppointment inspectionAppointment,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionAppointment> page = new Page<>(pageNum, pageSize);
        IPage<InspectionAppointment> list = inspectionAppointmentService.selectInspectionAppointmentList(page,inspectionAppointment);
        return success(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionAppointment inspectionAppointment,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<InspectionAppointment> page = new Page<>(pageNum, pageSize);
        IPage<InspectionAppointment> list = inspectionAppointmentService.selectInspectionAppointmentList(page,inspectionAppointment);
        ExcelUtil<InspectionAppointment> util = new ExcelUtil<InspectionAppointment>(InspectionAppointment.class);
        util.exportExcel(response, list.getRecords(), "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionAppointmentService.selectInspectionAppointmentById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:add')")
    @PostMapping
    public CommonResult add(@RequestBody InspectionAppointment inspectionAppointment)
    {
        return toAjax(inspectionAppointmentService.insertInspectionAppointment(inspectionAppointment));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:edit')")
    @PutMapping
    public CommonResult edit(@RequestBody InspectionAppointment inspectionAppointment)
    {
        return toAjax(inspectionAppointmentService.updateInspectionAppointment(inspectionAppointment));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:remove')")
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionAppointmentService.deleteInspectionAppointmentByIds(ids));
    }

    @GetMapping("/getAppointmentOwn")
    @TenantIgnore
    public CommonResult getAppointmentOwn()
    {
        return success(inspectionAppointmentService.getAppointmentOwn());
    }

    @GetMapping(value = "/getDetail")
    public CommonResult getDetail(@RequestParam("id") Long id)
    {
        return success(inspectionAppointmentService.getById(id));
    }

}
