package com.ruoyi.web.controller.record;

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.OperationRecord;
import com.ruoyi.system.service.IOperationRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作记录Controller
 * 
 * @author boman
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/operation/record")
public class OperationRecordController extends BaseController
{
    @Autowired
    private IOperationRecordService operationRecordService;

    /**
     * 查询操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('operation:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperationRecord operationRecord)
    {
        startPage();
        List<OperationRecord> list = operationRecordService.selectOperationRecordList(operationRecord);
        return getDataTable(list);
    }

    /**
     * 导出操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('operation:record:export')")
    @Log(title = "操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationRecord operationRecord)
    {
        List<OperationRecord> list = operationRecordService.selectOperationRecordList(operationRecord);
        ExcelUtil<OperationRecord> util = new ExcelUtil<OperationRecord>(OperationRecord.class);
        util.exportExcel(response, list, "操作记录数据");
    }

    /**
     * 获取操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('operation:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(operationRecordService.selectOperationRecordById(id));
    }

    /**
     * 新增操作记录
     */
    @PreAuthorize("@ss.hasPermi('operation:record:add')")
    @Log(title = "操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationRecord operationRecord)
    {
        return toAjax(operationRecordService.insertOperationRecord(operationRecord));
    }

    /**
     * 修改操作记录
     */
    @PreAuthorize("@ss.hasPermi('operation:record:edit')")
    @Log(title = "操作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody OperationRecord operationRecord)
    {
        return toAjax(operationRecordService.updateOperationRecord(operationRecord));
    }

    /**
     * 删除操作记录
     */
    @PreAuthorize("@ss.hasPermi('operation:record:remove')")
    @Log(title = "操作记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operationRecordService.deleteOperationRecordByIds(ids));
    }
}
