package com.bonus.sgzb.base.controller;

import com.bonus.sgzb.base.domain.MaSupplierInfo;
import com.bonus.sgzb.base.service.IMaSupplierInfoService;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 供应商管理
 * 
 * @author bonus
 * @date 2023-12-10
 */
@RestController
@Api(tags = "供应商管理")
@RequestMapping("/base/supplierInfo")
public class MaSupplierInfoController extends BaseController
{
    @Autowired
    private IMaSupplierInfoService maSupplierInfoService;

    /**
     * 查询供应商管理列表
     */
    @ApiOperation(value = "查询供应商管理列表")
    @GetMapping("/list")
    public TableDataInfo list(MaSupplierInfo maSupplierInfo)
    {
        startPage();
        List<MaSupplierInfo> list = maSupplierInfoService.selectMaSupplierInfoList(maSupplierInfo);
        return getDataTable(list);
    }

    /**
     * 查询供应商管理列表
     */
    @ApiOperation(value = "查询供应商管理列表")
    @GetMapping("/supplierInfoList")
    public TableDataInfo supplierInfoList(MaSupplierInfo maSupplierInfo)
    {
        List<MaSupplierInfo> list = maSupplierInfoService.selectMaSupplierInfoList(maSupplierInfo);
        return getDataTable(list);
    }

    /**
     * 查询供应商管理下拉选
     */
    @ApiOperation(value = "查询供应商管理下拉选")
    @GetMapping("/getSupplierSelect")
    public AjaxResult getSupplierSelect(MaSupplierInfo maSupplierInfo)
    {
        List<MaSupplierInfo> list = maSupplierInfoService.selectMaSupplierInfoList(maSupplierInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出供应商管理列表
     */
    @ApiOperation(value = "导出查询供应商管理列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaSupplierInfo maSupplierInfo)
    {
        List<MaSupplierInfo> list = maSupplierInfoService.selectMaSupplierInfoList(maSupplierInfo);
        ExcelUtil<MaSupplierInfo> util = new ExcelUtil<MaSupplierInfo>(MaSupplierInfo.class);
        util.exportExcel(response, list, "供应商管理数据");
    }

    /**
     * 获取供应商管理详细信息
     */
    @ApiOperation(value = "获取供应商管理详细信息")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return success(maSupplierInfoService.selectMaSupplierInfoBySupplierId(supplierId));
    }

    /**
     * 新增供应商管理
     */
    @ApiOperation(value = "新增供应商管理")
    @PostMapping
    public AjaxResult add(@RequestBody MaSupplierInfo maSupplierInfo)
    {
        return toAjax(maSupplierInfoService.insertMaSupplierInfo(maSupplierInfo));
    }

    /**
     * 修改供应商管理
     */
    @ApiOperation(value = "修改供应商管理")
    @PutMapping
    public AjaxResult edit(@RequestBody MaSupplierInfo maSupplierInfo)
    {
        return toAjax(maSupplierInfoService.updateMaSupplierInfo(maSupplierInfo));
    }

    /**
     * 删除供应商管理
     */
    @ApiOperation(value = "删除供应商管理")
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(maSupplierInfoService.deleteMaSupplierInfoBySupplierIds(supplierIds));
    }
}
