package com.ruoyi.device.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.device.domain.RecordUse;
import com.ruoyi.device.service.IRecordUseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 使用记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-19
 */
@Controller
@RequestMapping("/device/record_use")
public class RecordUseController extends BaseController
{
    private String prefix = "device/record_use";

    @Autowired
    private IRecordUseService recordUseService;

    @RequiresPermissions("device:record_use:view")
    @GetMapping()
    public String record_use()
    {
        return prefix + "/record_use";
    }

    /**
     * 查询使用记录列表
     */
    @RequiresPermissions("device:record_use:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordUse recordUse)
    {
        startPage();
        List<RecordUse> list = recordUseService.selectRecordUseList(recordUse);
        return getDataTable(list);
    }

    /**
     * 导出使用记录列表
     */
    @RequiresPermissions("device:record_use:export")
    @Log(title = "使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordUse recordUse)
    {
        List<RecordUse> list = recordUseService.selectRecordUseList(recordUse);
        ExcelUtil<RecordUse> util = new ExcelUtil<RecordUse>(RecordUse.class);
        return util.exportExcel(list, "使用记录数据");
    }

    /**
     * 新增使用记录
     */
    @RequiresPermissions("device:record_use:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存使用记录
     */
    @RequiresPermissions("device:record_use:add")
    @Log(title = "使用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordUse recordUse)
    {
        return toAjax(recordUseService.insertRecordUse(recordUse));
    }

    /**
     * 修改使用记录
     */
    @RequiresPermissions("device:record_use:edit")
    @GetMapping("/edit/{objId}")
    public String edit(@PathVariable("objId") Long objId, ModelMap mmap)
    {
        RecordUse recordUse = recordUseService.selectRecordUseByObjId(objId);
        mmap.put("recordUse", recordUse);
        return prefix + "/edit";
    }

    /**
     * 修改保存使用记录
     */
    @RequiresPermissions("device:record_use:edit")
    @Log(title = "使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordUse recordUse)
    {
        return toAjax(recordUseService.updateRecordUse(recordUse));
    }

    /**
     * 删除使用记录
     */
    @RequiresPermissions("device:record_use:remove")
    @Log(title = "使用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordUseService.deleteRecordUseByObjIds(ids));
    }
}
