package com.zbf.web.controller.system;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.SafetyStockVO;
import com.zbf.system.service.ITSafetyStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 安全库存Controller
 *
 * @author sunits
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/system/safetyStock")
@Api(value = "安全库存控制器", tags = {"安全库存管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TSafetyStockController extends BaseController {


    private final ITSafetyStockService safetyStockService;

    /**
     * 查询库存列表
     */
    @ApiOperation("查询库存列表")
    @PreAuthorize("@ss.hasPermi('system:safetyStock:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyStockVO safetyStockVO) {
        startPage();
        List<SafetyStockVO> list = safetyStockService.selectList(safetyStockVO);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @ApiOperation("导出库存列表")
    @PreAuthorize("@ss.hasPermi('system:safetyStock:export')")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyStockVO safetyStockVO) {
        List<SafetyStockVO> list = safetyStockService.selectList(safetyStockVO);
        ExcelUtil<SafetyStockVO> util = new ExcelUtil<SafetyStockVO>(SafetyStockVO.class);
        util.exportExcel(response, list, "库存数据");
    }
}
