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.IsMaterialsRestitutionRules;
import com.ktg.iscs.service.IIsMaterialsRestitutionRulesService;
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/rules")
public class IsMaterialsRestitutionRulesController extends BaseController
{
    @Autowired
    private IIsMaterialsRestitutionRulesService isMaterialsRestitutionRulesService;

    /**
     * 查询物资借出规则分页
     */
    @ApiOperation("查询物资借出规则-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsRestitutionRules", description = "实体参数")
    })
    // @PreAuthorize("@ss.hasPermi('iscs:rules:list')")
    @GetMapping("/getIsMaterialsRestitutionRulesPage")
    public CommonResult<Page<IsMaterialsRestitutionRules>> getIsMaterialsRestitutionRulesPage(Page<IsMaterialsRestitutionRules> page, IsMaterialsRestitutionRules isMaterialsRestitutionRules)
    {
        Page<IsMaterialsRestitutionRules> result = isMaterialsRestitutionRulesService.page(page, Wrappers.<IsMaterialsRestitutionRules>lambdaQuery()
                .orderByDesc(IsMaterialsRestitutionRules::getRuleId));
        return CommonResult.success(result);
    }

    /**
     * 导出物资借出规则列表
     */
    @ApiOperation("导出物资借出规则列表")
    @Parameter(name = "isMaterialsRestitutionRules", description = "实体参数")
    // @PreAuthorize("@ss.hasPermi('iscs:rules:export')")
    @Log(title = "物资借出规则", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsRestitutionRules")
    public void exportIsMaterialsRestitutionRules(HttpServletResponse response, IsMaterialsRestitutionRules isMaterialsRestitutionRules)
    {
        List<IsMaterialsRestitutionRules> list = isMaterialsRestitutionRulesService.selectIsMaterialsRestitutionRulesList(isMaterialsRestitutionRules);
        ExcelUtil<IsMaterialsRestitutionRules> util = new ExcelUtil<IsMaterialsRestitutionRules>(IsMaterialsRestitutionRules.class);
        util.exportExcel(response, list, "物资借出规则数据");
    }

    /**
     * 获取物资借出规则详细信息
     */
    @ApiOperation("获取物资借出规则详细信息")
    @Parameter(name = "ruleId", description = "ruleId")
    //  @PreAuthorize("@ss.hasPermi('iscs:rules:query')")
    @GetMapping(value = "/selectIsMaterialsRestitutionRulesById")
    public CommonResult<IsMaterialsRestitutionRules> selectIsMaterialsRestitutionRulesById(Long ruleId)
    {
        return CommonResult.success(isMaterialsRestitutionRulesService.selectIsMaterialsRestitutionRulesByRuleId(ruleId));
    }

    /**
     * 新增物资借出规则
     */
    @ApiOperation("新增物资借出规则")
    // @PreAuthorize("@ss.hasPermi('iscs:rules:add')")
    @Log(title = "物资借出规则", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMaterialsRestitutionRules")
    public CommonResult<Boolean> insertIsMaterialsRestitutionRules(@RequestBody @Parameter(name = "isMaterialsRestitutionRules", description = "新增数据类,放到body") IsMaterialsRestitutionRules isMaterialsRestitutionRules)
    {
        return CommonResult.success(isMaterialsRestitutionRulesService.insertIsMaterialsRestitutionRules(isMaterialsRestitutionRules) == 1);
    }

    /**
     * 修改物资借出规则
     */
    @ApiOperation("修改物资借出规则")
    // @PreAuthorize("@ss.hasPermi('iscs:rules:edit')")
    @Log(title = "物资借出规则", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsRestitutionRules")
    public CommonResult<Boolean> updateIsMaterialsRestitutionRules(@RequestBody @Parameter(name = "isMaterialsRestitutionRules", description = "修改数据类,放到body") IsMaterialsRestitutionRules isMaterialsRestitutionRules)
    {
        return CommonResult.success(isMaterialsRestitutionRulesService.updateIsMaterialsRestitutionRules(isMaterialsRestitutionRules) == 1);
    }

    /**
     * 删除物资借出规则
     */
    @ApiOperation("删除物资借出规则")
    // @PreAuthorize("@ss.hasPermi('iscs:rules:remove')")
    @Log(title = "物资借出规则", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsRestitutionRulesByRuleIds")
    public CommonResult<Boolean> deleteIsMaterialsRestitutionRulesByRuleIds(String ruleIds)
    {
        return CommonResult.success(isMaterialsRestitutionRulesService.deleteIsMaterialsRestitutionRulesByRuleIds(ruleIds) != 0);
    }
}
