package org.dromara.rfid.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.rfid.domain.vo.RfidReadRecordVo;
import org.dromara.rfid.domain.bo.RfidReadRecordBo;
import org.dromara.rfid.service.IRfidReadRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 读取记录
 *
 * @author zch
 * @date 2025-11-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rfid/rfidReadRecord")
public class RfidReadRecordController extends BaseController {

    private final IRfidReadRecordService rfidReadRecordService;

    /**
     * 查询读取记录列表
     */
    @SaCheckPermission("rfid:rfidReadRecord:list")
    @GetMapping("/list")
    public TableDataInfo<RfidReadRecordVo> list(RfidReadRecordBo bo, PageQuery pageQuery) {
        return rfidReadRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出读取记录列表
     */
    @SaCheckPermission("rfid:rfidReadRecord:export")
    @Log(title = "读取记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RfidReadRecordBo bo, HttpServletResponse response) {
        List<RfidReadRecordVo> list = rfidReadRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "读取记录", RfidReadRecordVo.class, response);
    }

    /**
     * 获取读取记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("rfid:rfidReadRecord:query")
    @GetMapping("/{id}")
    public R<RfidReadRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(rfidReadRecordService.queryById(id));
    }

    /**
     * 新增读取记录
     */
    @SaCheckPermission("rfid:rfidReadRecord:add")
    @Log(title = "读取记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RfidReadRecordBo bo) {
        return toAjax(rfidReadRecordService.insertByBo(bo));
    }

    /**
     * 修改读取记录
     */
    @SaCheckPermission("rfid:rfidReadRecord:edit")
    @Log(title = "读取记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RfidReadRecordBo bo) {
        return toAjax(rfidReadRecordService.updateByBo(bo));
    }

    /**
     * 删除读取记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("rfid:rfidReadRecord:remove")
    @Log(title = "读取记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(rfidReadRecordService.deleteWithValidByIds(List.of(ids), true));
    }

        /**
     * 下拉框查询读取记录列表
     */
    @SaCheckPermission("rfid:rfidReadRecord:list")
    @GetMapping("/getRfidReadRecordList")
    public R<List<RfidReadRecordVo>> getRfidReadRecordList(RfidReadRecordBo bo) {
       List<RfidReadRecordVo> list = rfidReadRecordService.queryList(bo);
        return R.ok(list);
    }
    
}
