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.IsMaterialsProperty;
import com.ktg.iscs.service.IIsMaterialsPropertyService;
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-02-05
 */
@Api(tags = "物资属性项")
@RestController
@RequestMapping("/iscs/property")
public class IsMaterialsPropertyController extends BaseController
{
    @Autowired
    private IIsMaterialsPropertyService isMaterialsPropertyService;

    @ApiOperation("查询物资属性项-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "isMaterialsProperty", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:property:list')")
    @GetMapping("/getIsMaterialsPropertyPage")
    public CommonResult<Page<IsMaterialsProperty>> getIsMaterialsPropertyPage(Page<IsMaterialsProperty> page, IsMaterialsProperty isMaterialsProperty)
    {
        Page<IsMaterialsProperty> result = isMaterialsPropertyService.getIsMaterialsPropertyPage(page, isMaterialsProperty);
        return CommonResult.success(result);
    }

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

    @ApiOperation("获取物资属性项详细信息")
    @Parameter(name = "propertyId", description = "propertyId")
    @PreAuthorize("@ss.hasPermi('iscs:property:query')")
    @GetMapping(value = "/selectIsMaterialsPropertyById")
    public CommonResult<IsMaterialsProperty> selectIsMaterialsPropertyById(Long propertyId)
    {
        return CommonResult.success(isMaterialsPropertyService.getById(propertyId));
    }

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

    @ApiOperation("修改物资属性项")
    @PreAuthorize("@ss.hasPermi('iscs:property:edit')")
    @Log(title = "物资属性项", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsProperty")
    public CommonResult<Boolean> updateIsMaterialsProperty(@RequestBody @Parameter(name = "isMaterialsProperty", description = "修改数据类,放到body") IsMaterialsProperty isMaterialsProperty)
    {
        return CommonResult.success(isMaterialsPropertyService.updateIsMaterialsProperty(isMaterialsProperty));
    }

    @ApiOperation("删除物资属性项")
    @PreAuthorize("@ss.hasPermi('iscs:property:remove')")
    @Log(title = "物资属性项", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsPropertyByPropertyIds")
    public CommonResult<Boolean> deleteIsMaterialsPropertyByPropertyIds(String propertyIds)
    {
        return CommonResult.success(isMaterialsPropertyService.deleteIsMaterialsPropertyByPropertyIds(propertyIds));
    }
}
