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.IsLocksetType;
import com.ktg.iscs.domain.vo.locksetType.IsLocksetTypeVO;
import com.ktg.iscs.service.IIsLocksetTypeService;
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;

/**
 * 锁具类型Controller
 *
 * @author cgj
 * @date 2024-11-19
 */
@Api(tags = "锁具类型")
@RestController
@RequestMapping("/iscs/type")
public class IsLocksetTypeController extends BaseController
{
    @Autowired
    private IIsLocksetTypeService isLocksetTypeService;

    /**
     * 查询锁具类型分页
     */
    @ApiOperation("查询锁具类型-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isLocksetType", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:type:list')")
    @GetMapping("/getIsLocksetTypePage")
    public CommonResult<Page<IsLocksetTypeVO>> getIsLocksetTypePage(Page<IsLocksetType> page, IsLocksetType isLocksetType)
    {
        Page<IsLocksetTypeVO> result = isLocksetTypeService.getIsLocksetTypePage(page, isLocksetType);
        return CommonResult.success(result);
    }

    /**
     * 导出锁具类型列表
     */
    @ApiOperation("导出锁具类型列表")
    @Parameter(name = "isLocksetType", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:type:export')")
    @Log(title = "锁具类型", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsLocksetType")
    public void exportIsLocksetType(HttpServletResponse response, IsLocksetType isLocksetType)
    {
        List<IsLocksetType> list = isLocksetTypeService.selectIsLocksetTypeList(isLocksetType);
        ExcelUtil<IsLocksetType> util = new ExcelUtil<IsLocksetType>(IsLocksetType.class);
        util.exportExcel(response, list, "锁具类型数据");
    }

    /**
     * 获取锁具类型详细信息
     */
    @ApiOperation("获取锁具类型详细信息")
    @Parameter(name = "locksetTypeId", description = "locksetTypeId")
    // @PreAuthorize("@ss.hasPermi('iscs:type:query')")
    @GetMapping(value = "/selectIsLocksetTypeById")
    public CommonResult<IsLocksetType> selectIsLocksetTypeById(Long locksetTypeId)
    {
        return CommonResult.success(isLocksetTypeService.selectIsLocksetTypeByLocksetTypeId(locksetTypeId));
    }

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

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

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