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.RfidDeviceVo;
import org.dromara.rfid.domain.bo.RfidDeviceBo;
import org.dromara.rfid.service.IRfidDeviceService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 设备信息
 *
 * @author zch
 * @date 2025-11-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rfid/rfidDevice")
public class RfidDeviceController extends BaseController {

    private final IRfidDeviceService rfidDeviceService;

    /**
     * 查询设备信息列表
     */
    @SaCheckPermission("rfid:rfidDevice:list")
    @GetMapping("/list")
    public TableDataInfo<RfidDeviceVo> list(RfidDeviceBo bo, PageQuery pageQuery) {
        return rfidDeviceService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出设备信息列表
     */
    @SaCheckPermission("rfid:rfidDevice:export")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RfidDeviceBo bo, HttpServletResponse response) {
        List<RfidDeviceVo> list = rfidDeviceService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备信息", RfidDeviceVo.class, response);
    }

    /**
     * 获取设备信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("rfid:rfidDevice:query")
    @GetMapping("/{id}")
    public R<RfidDeviceVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(rfidDeviceService.queryById(id));
    }

    /**
     * 新增设备信息
     */
    @SaCheckPermission("rfid:rfidDevice:add")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RfidDeviceBo bo) {
        return toAjax(rfidDeviceService.insertByBo(bo));
    }

    /**
     * 修改设备信息
     */
    @SaCheckPermission("rfid:rfidDevice:edit")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RfidDeviceBo bo) {
        return toAjax(rfidDeviceService.updateByBo(bo));
    }

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

        /**
     * 下拉框查询设备信息列表
     */
    @SaCheckPermission("rfid:rfidDevice:list")
    @GetMapping("/getRfidDeviceList")
    public R<List<RfidDeviceVo>> getRfidDeviceList(RfidDeviceBo bo) {
       List<RfidDeviceVo> list = rfidDeviceService.queryList(bo);
        return R.ok(list);
    }
    
}
