package org.dromara.rfid.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.rfid.domain.bo.RfidLocationBo;
import org.dromara.rfid.domain.vo.RfidLocationVo;
import org.dromara.rfid.service.IRfidLocationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 位置信息
 *
 * @author zch
 * @date 2025-11-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rfid/rfidLocation")
public class RfidLocationController extends BaseController {

    private final IRfidLocationService rfidLocationService;

    /**
     * 查询位置信息列表
     */
    @SaCheckPermission("rfid:rfidLocation:list")
    @GetMapping("/list")
    public R<List<RfidLocationVo>> list(RfidLocationBo bo) {
        List<RfidLocationVo> list = rfidLocationService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出位置信息列表
     */
    @SaCheckPermission("rfid:rfidLocation:export")
    @Log(title = "位置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RfidLocationBo bo, HttpServletResponse response) {
        List<RfidLocationVo> list = rfidLocationService.queryList(bo);
        ExcelUtil.exportExcel(list, "位置信息", RfidLocationVo.class, response);
    }

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

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

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

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

        /**
     * 下拉框查询位置信息列表
     */
    @SaCheckPermission("rfid:rfidLocation:list")
    @GetMapping("/getRfidLocationList")
    public R<List<RfidLocationVo>> getRfidLocationList(RfidLocationBo bo) {
       List<RfidLocationVo> list = rfidLocationService.queryList(bo);
        return R.ok(list);
    }

}
