package com.ruoyi.web.bst;

import com.ruoyi.bst.bindRecord.domain.BindRecord;
import com.ruoyi.bst.bindRecord.domain.BindRecordQuery;
import com.ruoyi.bst.bindRecord.domain.BindRecordVO;
import com.ruoyi.bst.bindRecord.service.BindRecordService;
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 2025-04-24
 */
@RestController
@RequestMapping("/bst/bindRecord")
public class BindRecordController extends BaseController
{
    @Autowired
    private BindRecordService bindRecordService;

    /**
     * 查询设备绑定记录列表
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(BindRecordQuery query)
    {
        startPage();
        startOrderBy();
        List<BindRecordVO> list = bindRecordService.selectBindRecordList(query);
        return getDataTable(list);
    }

    /**
     * 导出设备绑定记录列表
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:export')")
    @Log(title = "设备绑定记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BindRecordQuery query)
    {
        List<BindRecordVO> list = bindRecordService.selectBindRecordList(query);
        ExcelUtil<BindRecordVO> util = new ExcelUtil<BindRecordVO>(BindRecordVO.class);
        util.exportExcel(response, list, "设备绑定记录数据");
    }

    /**
     * 获取设备绑定记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(bindRecordService.selectBindRecordByRecordId(recordId));
    }

    /**
     * 新增设备绑定记录
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:add')")
    @Log(title = "设备绑定记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BindRecord bindRecord)
    {
        return toAjax(bindRecordService.insertBindRecord(bindRecord));
    }

    /**
     * 修改设备绑定记录
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:edit')")
    @Log(title = "设备绑定记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BindRecord bindRecord)
    {
        return toAjax(bindRecordService.updateBindRecord(bindRecord));
    }

    /**
     * 删除设备绑定记录
     */
    @PreAuthorize("@ss.hasPermi('bst:bindRecord:remove')")
    @Log(title = "设备绑定记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(bindRecordService.deleteBindRecordByRecordIds(recordIds));
    }
}
