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.IsLockset;
import com.ktg.iscs.domain.vo.lockset.IsLocksetVO;
import com.ktg.iscs.service.IIsLocksetService;
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/lockset")
public class IsLocksetController extends BaseController
{
    @Autowired
    private IIsLocksetService isLocksetService;

    /**
     * 查询锁具分页
     */
    @ApiOperation("查询锁具-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isLockset", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:list')")
    @GetMapping("/getIsLocksetPage")
    public CommonResult<Page<IsLocksetVO>> getIsLocksetPage(Page<IsLockset> page, IsLockset isLockset)
    {
        Page<IsLocksetVO> result = isLocksetService.getIsLocksetPage(page, isLockset);


        return CommonResult.success(result);
    }

    /**
     * 导出锁具列表
     */
    @ApiOperation("导出锁具列表")
    @Parameter(name = "isLockset", description = "实体参数")
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:export')")
    @Log(title = "锁具", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsLockset")
    public void exportIsLockset(HttpServletResponse response, IsLockset isLockset)
    {
        List<IsLockset> list = isLocksetService.selectIsLocksetList(isLockset);
        ExcelUtil<IsLockset> util = new ExcelUtil<IsLockset>(IsLockset.class);
        util.exportExcel(response, list, "锁具数据");
    }

    /**
     * 获取锁具详细信息
     */
    @ApiOperation("获取锁具详细信息")
    @Parameter(name = "locksetId", description = "locksetId")
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:query')")
    @GetMapping(value = "/selectIsLocksetById")
    public CommonResult<IsLockset> selectIsLocksetById(Long locksetId)
    {
        return CommonResult.success(isLocksetService.selectIsLocksetByLocksetId(locksetId));
    }

    /**
     * 新增锁具
     */
    @ApiOperation("新增锁具")
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:add')")
    @Log(title = "锁具", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsLockset")
    public CommonResult<Boolean> insertIsLockset(@RequestBody @Parameter(name = "isLockset", description = "新增数据类,放到body") IsLockset isLockset)
    {
        return CommonResult.success(isLocksetService.insertIsLockset(isLockset) == 1);
    }

    /**
     * 修改锁具
     */
    @ApiOperation("修改锁具")
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:edit')")
    @Log(title = "锁具", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsLockset")
    public CommonResult<Boolean> updateIsLockset(@RequestBody @Parameter(name = "isLockset", description = "修改数据类,放到body") IsLockset isLockset)
    {
        return CommonResult.success(isLocksetService.updateIsLockset(isLockset) == 1);
    }

    /**
     * 删除锁具
     */
    @ApiOperation("删除锁具")
    // @PreAuthorize("@ss.hasPermi('iscs:lockset:remove')")
    @Log(title = "锁具", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsLocksetByLocksetIds")
    public CommonResult<Boolean> deleteIsLocksetByLocksetIds(String locksetIds)
    {
        return CommonResult.success(isLocksetService.deleteIsLocksetByLocksetIds(locksetIds) != 0);
    }
}
