package com.ktg.iscs.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
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.IsLockCabinetSlots;
import com.ktg.iscs.service.IIsLockCabinetSlotsService;
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.Arrays;
import java.util.List;

/**
 * 锁控机柜-仓位Controller
 *
 * @author cgj
 * @date 2025-05-14
 */
@Api(tags = "锁控机柜-仓位")
@RestController
@RequestMapping("/iscs/slots")
public class IsLockCabinetSlotsController extends BaseController
{
    @Autowired
    private IIsLockCabinetSlotsService isLockCabinetSlotsService;

    @ApiOperation("查询锁控机柜-仓位-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isLockCabinetSlots", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:slots:list')")
    @GetMapping("/getIsLockCabinetSlotsPage")
    public CommonResult<Page<IsLockCabinetSlots>> getIsLockCabinetSlotsPage(Page<IsLockCabinetSlots> page, IsLockCabinetSlots isLockCabinetSlots)
    {
        Page<IsLockCabinetSlots> result = isLockCabinetSlotsService.getIsLockCabinetSlotsPage(page, isLockCabinetSlots);
        return CommonResult.success(result);
    }

    @ApiOperation("导出锁控机柜-仓位列表")
    @Parameter(name = "isLockCabinetSlots", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:slots:export')")
    @Log(title = "锁控机柜-仓位", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsLockCabinetSlots")
    public void exportIsLockCabinetSlots(HttpServletResponse response, IsLockCabinetSlots isLockCabinetSlots)
    {
        Page<IsLockCabinetSlots> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsLockCabinetSlots> list = isLockCabinetSlotsService.page(page, Wrappers.<IsLockCabinetSlots>lambdaQuery()
                .orderByDesc(IsLockCabinetSlots::getSlotId)).getRecords();
        ExcelUtil<IsLockCabinetSlots> util = new ExcelUtil<IsLockCabinetSlots>(IsLockCabinetSlots.class);
        util.exportExcel(response, list, "锁控机柜-仓位数据");
    }

    @ApiOperation("获取锁控机柜-仓位详细信息")
    @Parameter(name = "slotId", description = "slotId")
    @PreAuthorize("@ss.hasPermi('iscs:slots:query')")
    @GetMapping(value = "/selectIsLockCabinetSlotsById")
    public CommonResult<IsLockCabinetSlots> selectIsLockCabinetSlotsById(Long slotId)
    {
        return CommonResult.success(isLockCabinetSlotsService.getById(slotId));
    }

    @ApiOperation("新增锁控机柜-仓位")
    @PreAuthorize("@ss.hasPermi('iscs:slots:add')")
    @Log(title = "锁控机柜-仓位", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsLockCabinetSlots")
    public CommonResult<Boolean> insertIsLockCabinetSlots(@RequestBody @Parameter(name = "isLockCabinetSlots", description = "新增数据类,放到body") IsLockCabinetSlots isLockCabinetSlots)
    {
        return CommonResult.success(isLockCabinetSlotsService.insertIsLockCabinetSlots(isLockCabinetSlots));
    }

    @ApiOperation("修改锁控机柜-仓位")
    @PreAuthorize("@ss.hasPermi('iscs:slots:edit')")
    @Log(title = "锁控机柜-仓位", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsLockCabinetSlots")
    public CommonResult<Boolean> updateIsLockCabinetSlots(@RequestBody @Parameter(name = "isLockCabinetSlots", description = "修改数据类,放到body") IsLockCabinetSlots isLockCabinetSlots)
    {
        return CommonResult.success(isLockCabinetSlotsService.updateIsLockCabinetSlots(isLockCabinetSlots));
    }

    @ApiOperation("删除锁控机柜-仓位")
    @PreAuthorize("@ss.hasPermi('iscs:slots:remove')")
    @Log(title = "锁控机柜-仓位", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsLockCabinetSlotsBySlotIds")
    public CommonResult<Boolean> deleteIsLockCabinetSlotsBySlotIds(String slotIds)
    {
        Assert.notBlank(slotIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(slotIds);
        return CommonResult.success(isLockCabinetSlotsService.removeBatchByIds(Arrays.asList(longIds)));
    }
}
