package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.IsMaterialsInstructions;
import com.ktg.iscs.service.IIsMaterialsInstructionsService;
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 2025-01-23
 */
@Api(tags = "物资使用说明")
@RestController
@RequestMapping("/iscs/instructions")
public class IsMaterialsInstructionsController extends BaseController
{
    @Autowired
    private IIsMaterialsInstructionsService isMaterialsInstructionsService;

    @ApiOperation("查询物资使用说明-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsInstructions", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:instructions:list')")
    @GetMapping("/getIsMaterialsInstructionsPage")
    public CommonResult<Page<IsMaterialsInstructions>> getIsMaterialsInstructionsPage(Page<IsMaterialsInstructions> page, IsMaterialsInstructions isMaterialsInstructions)
    {
        Page<IsMaterialsInstructions> result = isMaterialsInstructionsService.getIsMaterialsInstructionsPage(page, isMaterialsInstructions);
        return CommonResult.success(result);
    }

    @ApiOperation("导出物资使用说明列表")
    @Parameter(name = "isMaterialsInstructions", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:instructions:export')")
    @Log(title = "物资使用说明", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsInstructions")
    public void exportIsMaterialsInstructions(HttpServletResponse response, IsMaterialsInstructions isMaterialsInstructions)
    {
        Page<IsMaterialsInstructions> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsMaterialsInstructions> list = isMaterialsInstructionsService.page(page, Wrappers.<IsMaterialsInstructions>lambdaQuery()
                .orderByDesc(IsMaterialsInstructions::getInstructionsId)).getRecords();
        ExcelUtil<IsMaterialsInstructions> util = new ExcelUtil<IsMaterialsInstructions>(IsMaterialsInstructions.class);
        util.exportExcel(response, list, "物资使用说明数据");
    }

    @ApiOperation("获取物资使用说明详细信息")
    @Parameter(name = "instructionsId", description = "instructionsId")
    @PreAuthorize("@ss.hasPermi('iscs:instructions:query')")
    @GetMapping(value = "/selectIsMaterialsInstructionsById")
    public CommonResult<IsMaterialsInstructions> selectIsMaterialsInstructionsById(Long instructionsId)
    {
        return CommonResult.success(isMaterialsInstructionsService.getById(instructionsId));
    }

    @ApiOperation("新增物资使用说明")
    @PreAuthorize("@ss.hasPermi('iscs:instructions:add')")
    @Log(title = "物资使用说明", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMaterialsInstructions")
    public CommonResult<Boolean> insertIsMaterialsInstructions(@RequestBody @Parameter(name = "isMaterialsInstructions", description = "新增数据类,放到body") IsMaterialsInstructions isMaterialsInstructions)
    {
        return CommonResult.success(isMaterialsInstructionsService.insertIsMaterialsInstructions(isMaterialsInstructions));
    }

    @ApiOperation("修改物资使用说明")
    @PreAuthorize("@ss.hasPermi('iscs:instructions:edit')")
    @Log(title = "物资使用说明", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsInstructions")
    public CommonResult<Boolean> updateIsMaterialsInstructions(@RequestBody @Parameter(name = "isMaterialsInstructions", description = "修改数据类,放到body") IsMaterialsInstructions isMaterialsInstructions)
    {
        return CommonResult.success(isMaterialsInstructionsService.updateIsMaterialsInstructions(isMaterialsInstructions));
    }

    @ApiOperation("删除物资使用说明")
    @PreAuthorize("@ss.hasPermi('iscs:instructions:remove')")
    @Log(title = "物资使用说明", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsInstructionsByInstructionsIds")
    public CommonResult<Boolean> deleteIsMaterialsInstructionsByInstructionsIds(String instructionsIds)
    {
        return CommonResult.success(isMaterialsInstructionsService.deleteIsMaterialsInstructionsByInstructionsIds(instructionsIds));
    }
}
