package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.RobotOpsAppointmentRecord;
import com.ruoyi.base.service.IRobotOpsAppointmentRecordService;
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 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 ruoyi
 * @date 2026-04-28
 */
@RestController
@RequestMapping("/base/appointmentRecord")
public class RobotOpsAppointmentRecordController extends BaseController
{
    @Autowired
    private IRobotOpsAppointmentRecordService robotOpsAppointmentRecordService;

    /**
     * 查询访客预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(RobotOpsAppointmentRecord robotOpsAppointmentRecord,
                              @RequestParam(required = false) String appointmentTimeStart,
                              @RequestParam(required = false) String appointmentTimeEnd)
    {
        startPage();
        if (appointmentTimeStart != null && !appointmentTimeStart.isEmpty()) {
            robotOpsAppointmentRecord.getParams().put("beginTime", appointmentTimeStart);
        }
        if (appointmentTimeEnd != null && !appointmentTimeEnd.isEmpty()) {
            robotOpsAppointmentRecord.getParams().put("endTime", appointmentTimeEnd);
        }
        List<RobotOpsAppointmentRecord> list = robotOpsAppointmentRecordService.selectRobotOpsAppointmentRecordList(robotOpsAppointmentRecord);
        return getDataTable(list);
    }

    /**
     * 导出访客预约记录列表
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:export')")
    @Log(title = "访客预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RobotOpsAppointmentRecord robotOpsAppointmentRecord)
    {
        List<RobotOpsAppointmentRecord> list = robotOpsAppointmentRecordService.selectRobotOpsAppointmentRecordList(robotOpsAppointmentRecord);
        ExcelUtil<RobotOpsAppointmentRecord> util = new ExcelUtil<RobotOpsAppointmentRecord>(RobotOpsAppointmentRecord.class);
        util.exportExcel(response, list, "访客预约记录数据");
    }

    /**
     * 获取访客预约记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(robotOpsAppointmentRecordService.selectRobotOpsAppointmentRecordById(id));
    }

    /**
     * 新增访客预约记录
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:add')")
    @Log(title = "访客预约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RobotOpsAppointmentRecord robotOpsAppointmentRecord)
    {
        return toAjax(robotOpsAppointmentRecordService.insertRobotOpsAppointmentRecord(robotOpsAppointmentRecord));
    }

    /**
     * 修改访客预约记录
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:edit')")
    @Log(title = "访客预约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RobotOpsAppointmentRecord robotOpsAppointmentRecord)
    {
        return toAjax(robotOpsAppointmentRecordService.updateRobotOpsAppointmentRecord(robotOpsAppointmentRecord));
    }

    /**
     * 删除访客预约记录
     */
    @PreAuthorize("@ss.hasPermi('base:appointmentRecord:remove')")
    @Log(title = "访客预约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(robotOpsAppointmentRecordService.deleteRobotOpsAppointmentRecordByIds(ids));
    }
}
