package com.ktg.iscs.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
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.IsMaterialsPropertyValue;
import com.ktg.iscs.service.IIsMaterialsPropertyValueService;
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.Arrays;
import java.util.List;

/**
 * 物资属性值Controller
 *
 * @author cgj
 * @date 2025-02-05
 */
@Api(tags = "物资属性值")
@RestController
@RequestMapping("/iscs/propvalue")
public class IsMaterialsPropertyValueController extends BaseController
{
    @Autowired
    private IIsMaterialsPropertyValueService isMaterialsPropertyValueService;

    @ApiOperation("查询物资属性值-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsPropertyValue", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:list')")
    @GetMapping("/getIsMaterialsPropertyValuePage")
    public CommonResult<Page<IsMaterialsPropertyValue>> getIsMaterialsPropertyValuePage(Page<IsMaterialsPropertyValue> page, IsMaterialsPropertyValue isMaterialsPropertyValue)
    {
        Page<IsMaterialsPropertyValue> result = isMaterialsPropertyValueService.getIsMaterialsPropertyValuePage(page, isMaterialsPropertyValue);
        return CommonResult.success(result);
    }

    @ApiOperation("导出物资属性值列表")
    @Parameter(name = "isMaterialsPropertyValue", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:export')")
    @Log(title = "物资属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsPropertyValue")
    public void exportIsMaterialsPropertyValue(HttpServletResponse response, IsMaterialsPropertyValue isMaterialsPropertyValue)
    {
        Page<IsMaterialsPropertyValue> page = new Page<>();
        page.setSize(-1);
        page.setCurrent(1);
        List<IsMaterialsPropertyValue> list = isMaterialsPropertyValueService.page(page, Wrappers.<IsMaterialsPropertyValue>lambdaQuery()
                .orderByDesc(IsMaterialsPropertyValue::getRecordId)).getRecords();
        ExcelUtil<IsMaterialsPropertyValue> util = new ExcelUtil<IsMaterialsPropertyValue>(IsMaterialsPropertyValue.class);
        util.exportExcel(response, list, "物资属性值数据");
    }

    @ApiOperation("获取物资属性值详细信息")
    @Parameter(name = "recordId", description = "recordId")
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:query')")
    @GetMapping(value = "/selectIsMaterialsPropertyValueById")
    public CommonResult<IsMaterialsPropertyValue> selectIsMaterialsPropertyValueById(Long recordId)
    {
        return CommonResult.success(isMaterialsPropertyValueService.getById(recordId));
    }

    @ApiOperation("新增物资属性值")
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:add')")
    @Log(title = "物资属性值", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMaterialsPropertyValue")
    public CommonResult<Boolean> insertIsMaterialsPropertyValue(@RequestBody @Parameter(name = "isMaterialsPropertyValue", description = "新增数据类,放到body") IsMaterialsPropertyValue isMaterialsPropertyValue)
    {
        return CommonResult.success(isMaterialsPropertyValueService.insertIsMaterialsPropertyValue(isMaterialsPropertyValue));
    }

    @ApiOperation("修改物资属性值")
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:edit')")
    @Log(title = "物资属性值", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsPropertyValue")
    public CommonResult<Boolean> updateIsMaterialsPropertyValue(@RequestBody @Parameter(name = "isMaterialsPropertyValue", description = "修改数据类,放到body") IsMaterialsPropertyValue isMaterialsPropertyValue)
    {
        return CommonResult.success(isMaterialsPropertyValueService.updateById(isMaterialsPropertyValue));
    }

    @ApiOperation("删除物资属性值")
    @PreAuthorize("@ss.hasPermi('iscs:propvalue:remove')")
    @Log(title = "物资属性值", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsPropertyValueByRecordIds")
    public CommonResult<Boolean> deleteIsMaterialsPropertyValueByRecordIds(String recordIds)
    {
        Assert.notBlank(recordIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(recordIds);
        return CommonResult.success(isMaterialsPropertyValueService.removeBatchByIds(Arrays.asList(longIds)));
    }
}
