package com.ktg.iscs.controller;

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.IsLock;
import com.ktg.iscs.domain.vo.lock.IsLockVO;
import com.ktg.iscs.service.IIsLockService;
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.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 挂锁Controller
 *
 * @author cgj
 * @date 2024-11-19
 */
@Api(tags = "挂锁")
@RestController
@RequestMapping("/iscs/lock")
public class IsLockController extends BaseController
{
    @Autowired
    private IIsLockService isLockService;

    /**
     * 查询挂锁分页
     */
    @ApiOperation("查询挂锁-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isLock", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:lock:list')")
    @GetMapping("/getIsLockPage")
    public CommonResult<Page<IsLockVO>> getIsLockPage(Page<IsLock> page, IsLock isLock)
    {
        Page<IsLockVO> result = isLockService.getIsLockPage(page, isLock);
        return CommonResult.success(result);
    }

    /**
     * 导出挂锁列表
     */
    @ApiOperation("导出挂锁列表")
    @Parameter(name = "isLock", description = "实体参数")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:export')")
    @Log(title = "挂锁", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsLock")
    public void exportIsLock(HttpServletResponse response, IsLock isLock)
    {
        List<IsLock> list = isLockService.selectIsLockList(isLock);
        ExcelUtil<IsLock> util = new ExcelUtil<IsLock>(IsLock.class);
        util.exportExcel(response, list, "挂锁数据");
    }

    /**
     * 获取挂锁详细信息
     */
    @ApiOperation("获取挂锁详细信息")
    @Parameter(name = "lockId", description = "lockId")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:query')")
    @GetMapping(value = "/selectIsLockById")
    public CommonResult<IsLock> selectIsLockById(Long lockId)
    {
        return CommonResult.success(isLockService.selectIsLockByLockId(lockId));
    }

    @ApiOperation("通过NFC获取挂锁详细信息")
    @Parameter(name = "nfc", description = "nfc")
    @GetMapping("/selectIsLockByNfc")
    public CommonResult<IsLock> selectIsLockByNfc(String nfc) {
        return CommonResult.success(isLockService.selectIsLockByNfc(nfc));
    }

    /**
     * 新增挂锁
     */
    @ApiOperation("新增挂锁")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:add')")
    @Log(title = "挂锁", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsLock")
    public CommonResult<Boolean> insertIsLock(@RequestBody @Parameter(name = "isLock", description = "新增数据类,放到body") IsLock isLock)
    {
        return CommonResult.success(isLockService.insertIsLock(isLock) == 1);
    }

    /**
     * 修改挂锁
     */
    @ApiOperation("修改挂锁")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:edit')")
    @Log(title = "挂锁", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsLock")
    public CommonResult<Boolean> updateIsLock(@RequestBody @Parameter(name = "isLock", description = "修改数据类,放到body") IsLock isLock)
    {
        return CommonResult.success(isLockService.updateIsLock(isLock) == 1);
    }

    /**
     * 删除挂锁
     */
    @ApiOperation("删除挂锁")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:remove')")
    @Log(title = "挂锁", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsLockByLockIds")
    public CommonResult<Boolean> deleteIsLockByLockIds(String lockIds)
    {
        return CommonResult.success(isLockService.deleteIsLockByLockIds(lockIds) != 0);
    }

    @ApiOperation("机柜录入挂锁")
    // @PreAuthorize("@ss.hasPermi('iscs:lock:add')")
    @Log(title = "机柜录入挂锁", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsLockByCabinet")
    public CommonResult<Boolean> insertIsLockByCabinet(@RequestBody @Parameter(name = "isLock", description = "新增数据类,放到body") IsLock isLock)
    {
        return CommonResult.success(isLockService.insertIsLockByCabinet(isLock));
    }
}
