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.IsHardwareType;
import com.ktg.iscs.domain.dto.hardware.GetListDTO;
import com.ktg.iscs.domain.vo.hardware.IsHardwareTypeVO;
import com.ktg.iscs.service.IIsHardwareTypeService;
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-10-16
 */
@Api(tags = "硬件类型")
@RestController
@RequestMapping("/iscs/type")
public class IsHardwareTypeController extends BaseController
{
    @Autowired
    private IIsHardwareTypeService isHardwareTypeService;

    @ApiOperation("查询硬件类型-列表")
    @Parameters({
            @Parameter(name = "hardwareTypeName", description = "类型名称"),
            @Parameter(name = "hardwareTypeName", description = "类型名称"),
            @Parameter(name = "enableFlag", description = "是否启用(Y-N)")
    })
    @GetMapping("/getIsHardwareTypeList")
    public CommonResult<List<IsHardwareTypeVO>> list(GetListDTO getListDTO)
    {
        List<IsHardwareTypeVO> list = isHardwareTypeService.getIsHardwareTypeList(getListDTO);
        return CommonResult.success(list);
    }

    @ApiOperation("查询硬件类型-分页")
    @Parameters({
            @Parameter(name = "page", description = "page"),
            @Parameter(name = "hardwareTypeName", description = "类型名称"),
            @Parameter(name = "hardwareTypeName", description = "类型名称"),
            @Parameter(name = "enableFlag", description = "是否启用(Y-N)")
    })
    @GetMapping("/getIsHardwareTypePage")
    public CommonResult<Page<IsHardwareType>> getIsHardwareTypePage(Page<IsHardwareType> page, GetListDTO getListDTO)
    {
        Page<IsHardwareType> result = isHardwareTypeService.getIsHardwareTypePage(page, getListDTO);
        return CommonResult.success(result);
    }

    /**
     * 导出硬件类型列表
     */
    @ApiOperation("导出硬件类型列表")
    @Parameter(name = "isHardwareType", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('is:type:export')")
    @Log(title = "硬件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsHardwareType")
    public void exportIsHardwareType(HttpServletResponse response, IsHardwareType isHardwareType)
    {
        List<IsHardwareType> list = isHardwareTypeService.selectIsHardwareTypeList(isHardwareType);
        ExcelUtil<IsHardwareType> util = new ExcelUtil<IsHardwareType>(IsHardwareType.class);
        util.exportExcel(response, list, "硬件类型数据");
    }

    /**
     * 获取硬件类型详细信息
     */
    @ApiOperation("获取硬件类型详细信息")
    @Parameter(name = "id", description = "id")
    // @PreAuthorize("@ss.hasPermi('is:type:query')")
    @GetMapping(value = "/selectIsHardwareTypeById")
    public CommonResult<IsHardwareType> selectIsHardwareTypeById(Long id)
    {
        return CommonResult.success(isHardwareTypeService.selectIsHardwareTypeById(id));
    }

    /**
     * 新增硬件类型
     */
    @ApiOperation("新增硬件类型")
    @PreAuthorize("@ss.hasPermi('mes:hw:type:add')")
    @Log(title = "硬件类型", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsHardwareType")
    public CommonResult<Boolean> insertIsHardwareType(@RequestBody @Parameter(name = "isHardwareType", description = "新增数据类,放到body") IsHardwareType isHardwareType)
    {
        return CommonResult.success(isHardwareTypeService.insertIsHardwareType(isHardwareType) == 1);
    }

    /**
     * 修改硬件类型
     */
    @ApiOperation("修改硬件类型")
    @PreAuthorize("@ss.hasPermi('mes:hw:type:edit')")
    @Log(title = "硬件类型", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsHardwareType")
    public CommonResult<Boolean> updateIsHardwareType(@RequestBody @Parameter(name = "isHardwareType", description = "修改数据类,放到body") IsHardwareType isHardwareType)
    {
        return CommonResult.success(isHardwareTypeService.updateIsHardwareType(isHardwareType) == 1);
    }

    /**
     * 删除硬件类型
     */
    @ApiOperation("删除硬件类型")
    // @PreAuthorize("@ss.hasPermi('mes:hw:type:batchremove')")
    @Log(title = "硬件类型", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsHardwareTypeByIds")
    public CommonResult<Boolean> deleteIsHardwareTypeByIds(String ids)
    {
        return CommonResult.success(isHardwareTypeService.deleteIsHardwareTypeByIds(ids) != 0);
    }
}
