package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsRfidToken;
import com.ktg.iscs.service.IIsRfidTokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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;

/**
 * rfid标识Controller
 *
 * @author cgj
 * @date 2025-05-14
 */
@Api(tags = "rfid标识")
@RestController
@RequestMapping("/iscs/token")
public class IsRfidTokenController extends BaseController
{
    @Autowired
    private IIsRfidTokenService isRfidTokenService;

    @ApiOperation("查询rfid标识-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isRfidToken", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:token:list')")
    @GetMapping("/getIsRfidTokenPage")
    public CommonResult<Page<IsRfidToken>> getIsRfidTokenPage(Page<IsRfidToken> page, IsRfidToken isRfidToken)
    {
        Page<IsRfidToken> result = isRfidTokenService.getIsRfidTokenPage(page, isRfidToken);
        return CommonResult.success(result);
    }

    @ApiOperation("导出rfid标识列表")
    @Parameter(name = "isRfidToken", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:token:export')")
    @Log(title = "rfid标识", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsRfidToken")
    public void exportIsRfidToken(HttpServletResponse response, IsRfidToken isRfidToken)
    {
        Page<IsRfidToken> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsRfidToken> list = isRfidTokenService.page(page, Wrappers.<IsRfidToken>lambdaQuery()
                .orderByDesc(IsRfidToken::getRfidId)).getRecords();
        ExcelUtil<IsRfidToken> util = new ExcelUtil<IsRfidToken>(IsRfidToken.class);
        util.exportExcel(response, list, "rfid标识数据");
    }

    @ApiOperation("获取rfid标识详细信息")
    @Parameter(name = "rfidId", description = "rfidId")
    @PreAuthorize("@ss.hasPermi('iscs:token:query')")
    @GetMapping(value = "/selectIsRfidTokenById")
    public CommonResult<IsRfidToken> selectIsRfidTokenById(Long rfidId)
    {
        return CommonResult.success(isRfidTokenService.getById(rfidId));
    }

    @ApiOperation("新增rfid标识")
    @PreAuthorize("@ss.hasPermi('iscs:token:add')")
    @Log(title = "rfid标识", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsRfidToken")
    public CommonResult<Boolean> insertIsRfidToken(@RequestBody @Parameter(name = "isRfidToken", description = "新增数据类,放到body") IsRfidToken isRfidToken)
    {
        return CommonResult.success(isRfidTokenService.insertIsRfidToken(isRfidToken));
    }

    @ApiOperation("修改rfid标识")
    @PreAuthorize("@ss.hasPermi('iscs:token:edit')")
    @Log(title = "rfid标识", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsRfidToken")
    public CommonResult<Boolean> updateIsRfidToken(@RequestBody @Parameter(name = "isRfidToken", description = "修改数据类,放到body") IsRfidToken isRfidToken)
    {
        return CommonResult.success(isRfidTokenService.updateIsRfidToken(isRfidToken));
    }

    @ApiOperation("删除rfid标识")
    @PreAuthorize("@ss.hasPermi('iscs:token:remove')")
    @Log(title = "rfid标识", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsRfidTokenByRfidIds")
    public CommonResult<Boolean> deleteIsRfidTokenByRfidIds(String rfidIds)
    {
        return CommonResult.success(isRfidTokenService.deleteIsRfidTokenByRfidIds(rfidIds));
    }

    @ApiOperation("机柜录入rfid标识")
    @PreAuthorize("@ss.hasPermi('iscs:token:add')")
    @Log(title = "rfid标识", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsRfidTokenByCabinet")
    public CommonResult<Boolean> insertIsRfidTokenByCabinet(@RequestBody @Parameter(name = "isRfidToken", description = "新增数据类,放到body") IsRfidToken isRfidToken)
    {
        return CommonResult.success(isRfidTokenService.insertIsRfidTokenByCabinet(isRfidToken));
    }
}
