package com.xtd.project.system.controller;

import java.util.List;

import com.xtd.project.system.domain.vo.SelectVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xtd.framework.aspectj.lang.annotation.Log;
import com.xtd.framework.aspectj.lang.enums.BusinessType;
import com.xtd.project.system.domain.DbSupplier;
import com.xtd.project.system.service.IDbSupplierService;
import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.common.utils.poi.ExcelUtil;
import com.xtd.framework.web.page.TableDataInfo;

/**
 * 供应商Controller
 *
 * @author xtd
 * @date 2020-04-07
 */
@RestController
@RequestMapping("/system/supplier")
public class DbSupplierController extends BaseController
{
    @Autowired
    private IDbSupplierService dbSupplierService;

    /**
     * 查询供应商列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbSupplier dbSupplier)
    {
        startPage();
        List<DbSupplier> list = dbSupplierService.selectDbSupplierList(dbSupplier);
        return getDataTable(list);
    }
    /**
     * 查询供应商下路列表
     */
    @GetMapping("/select/list")
    public AjaxResult selectList()
    {
        List<SelectVo> list = dbSupplierService.selectList();
        return AjaxResult.success(list);
    }


    /**
     * 导出供应商列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:export')")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbSupplier dbSupplier)
    {
        List<DbSupplier> list = dbSupplierService.selectDbSupplierList(dbSupplier);
        ExcelUtil<DbSupplier> util = new ExcelUtil<DbSupplier>(DbSupplier.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取供应商详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:query')")
    @GetMapping(value = "/{sId}")
    public AjaxResult getInfo(@PathVariable("sId") Long sId)
    {
        return AjaxResult.success(dbSupplierService.selectDbSupplierById(sId));
    }

    /**
     * 新增供应商
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:add')")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbSupplier dbSupplier)
    {
        return toAjax(dbSupplierService.insertDbSupplier(dbSupplier));
    }

    /**
     * 修改供应商
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:edit')")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbSupplier dbSupplier)
    {
        return toAjax(dbSupplierService.updateDbSupplier(dbSupplier));
    }

    /**
     * 删除供应商
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:remove')")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sIds}")
    public AjaxResult remove(@PathVariable Long[] sIds)
    {
        return toAjax(dbSupplierService.deleteDbSupplierByIds(sIds));
    }
}
