package com.ruoyi.web.controller.appointment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AccessRecord;
import com.ruoyi.system.service.IAccessRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访问记录Controller
 *
 * @author ruoyi
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/system/record")
public class AccessRecordController extends BaseController
{
    @Autowired
    private IAccessRecordService accessRecordService;

/**
 * 查询访问记录列表
 */
@PreAuthorize("@ss.hasPermi('system:record:list')")
@GetMapping("/list")
    public TableDataInfo list(AccessRecord accessRecord)
    {
        startPage();
        List<AccessRecord> list = accessRecordService.selectAccessRecordList(accessRecord);
        return getDataTable(list);
    }

    /**
     * 导出访问记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "访问记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccessRecord accessRecord)
    {
        List<AccessRecord> list = accessRecordService.selectAccessRecordList(accessRecord);
        ExcelUtil<AccessRecord> util = new ExcelUtil<AccessRecord>(AccessRecord.class);
        util.exportExcel(response, list, "访问记录数据");
    }

    /**
     * 获取访问记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(accessRecordService.selectAccessRecordByRecordId(recordId));
    }

    /**
     * 新增访问记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "访问记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccessRecord accessRecord)
    {
        return toAjax(accessRecordService.insertAccessRecord(accessRecord));
    }

    /**
     * 修改访问记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "访问记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody AccessRecord accessRecord)
    {
        return toAjax(accessRecordService.updateAccessRecord(accessRecord));
    }

    /**
     * 删除访问记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "访问记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(accessRecordService.deleteAccessRecordByRecordIds(recordIds));
    }
}
