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.IsMaterialsType;
import com.ktg.iscs.domain.dto.materialsType.MaterialsTypePageDTO;
import com.ktg.iscs.domain.vo.materialsType.MaterialsTypePageVO;
import com.ktg.iscs.service.IIsMaterialsTypeService;
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-08
 */
@Api(tags = "物资类型")
@RestController
@RequestMapping("/iscs/type")
public class IsMaterialsTypeController extends BaseController
{
    @Autowired
    private IIsMaterialsTypeService isMaterialsTypeService;

    /**
     * 查询物资类型分页
     */
    @ApiOperation("查询物资类型-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsType", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:type:list')")
    @GetMapping("/getIsMaterialsTypePage")
    public CommonResult<Page<MaterialsTypePageVO>> getIsMaterialsTypePage(Page<IsMaterialsType> page, IsMaterialsType isMaterialsType)
    {
        Page<MaterialsTypePageVO> result = isMaterialsTypeService.getIsMaterialsTypePage(page, isMaterialsType);
        return CommonResult.success(result);
    }

    /**
     * 导出物资类型列表
     */
    @ApiOperation("导出物资类型列表")
    @Parameter(name = "isMaterialsType", description = "实体参数")
    //  @PreAuthorize("@ss.hasPermi('iscs:type:export')")
    @Log(title = "物资类型", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsType")
    public void exportIsMaterialsType(HttpServletResponse response, IsMaterialsType isMaterialsType)
    {
        List<IsMaterialsType> list = isMaterialsTypeService.selectIsMaterialsTypeList(isMaterialsType);
        ExcelUtil<IsMaterialsType> util = new ExcelUtil<IsMaterialsType>(IsMaterialsType.class);
        util.exportExcel(response, list, "物资类型数据");
    }

    /**
     * 获取物资类型详细信息
     */
    @ApiOperation("获取物资类型详细信息")
    @Parameter(name = "materialsTypeId", description = "materialsTypeId")
    //  @PreAuthorize("@ss.hasPermi('iscs:type:query')")
    @GetMapping(value = "/selectIsMaterialsTypeById")
    public CommonResult<MaterialsTypePageVO> selectIsMaterialsTypeById(Long materialsTypeId)
    {
        return CommonResult.success(isMaterialsTypeService.selectIsMaterialsTypeByMaterialsTypeId(materialsTypeId));
    }

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

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

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