package com.bonus.material.ma.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.ma.domain.SupplierInfo;
import com.bonus.material.ma.service.ISupplierInfoService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 物资厂家管理Controller
 * @author bonus
 */
@Api(tags = "物资厂家管理接口")
@RestController
@RequestMapping("/ma_supplier_info")
public class SupplierInfoController extends BaseController {

    @Resource
    private ISupplierInfoService supplierInfoService;

    /**
     * 查询物资厂家管理列表
     */
    @ApiOperation(value = "查询物资厂家管理列表")
    //@RequiresPermissions("ma:info:list")
    @GetMapping("/list")
    public TableDataInfo list(SupplierInfo supplierInfo) {
        startPage();
        List<SupplierInfo> list = supplierInfoService.selectSupplierInfoList(supplierInfo);
        return getDataTable(list);
    }

    /**
     * 查询物资厂家--下拉框--不分页
     */
    @ApiOperation(value = "查询物资厂家下拉框--不分页")
    //@RequiresPermissions("ma:info:list")
    @GetMapping("/select")
    public TableDataInfo select(SupplierInfo supplierInfo) {
        List<SupplierInfo> list = supplierInfoService.selectSupplierInfoList(supplierInfo);
        return getDataTable(list);
    }

    /**
     * 导出物资厂家管理列表
     */
    @ApiOperation(value = "导出物资厂家管理列表")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:info:export")
    @SysLog(title = "物资厂家管理", businessType = OperaType.EXPORT, logType = 1,module = "物资管理->导出物资厂家管理")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierInfo supplierInfo) {
        List<SupplierInfo> list = supplierInfoService.selectSupplierInfoList(supplierInfo);
        ExcelUtil<SupplierInfo> util = new ExcelUtil<>(SupplierInfo.class);
        util.exportExcel(response, list, "物资厂家管理数据");
    }

    /**
     * 获取物资厂家管理详细信息
     */
    @ApiOperation(value = "获取物资厂家管理详细信息")
    @RequiresPermissions("ma:info:query")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId) {
        return success(supplierInfoService.selectSupplierInfoBySupplierId(supplierId));
    }

    /**
     * 新增物资厂家管理
     */
    @ApiOperation(value = "新增物资厂家管理")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:info:add")
    @SysLog(title = "物资厂家管理", businessType = OperaType.INSERT, module = "物资管理->新增物资厂家管理")
    @PostMapping
    public AjaxResult add(@RequestBody SupplierInfo supplierInfo) {
        try {
            return supplierInfoService.insertSupplierInfo(supplierInfo);
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 修改物资厂家管理
     */
    @ApiOperation(value = "修改物资厂家管理")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:info:edit")
    @SysLog(title = "物资厂家管理", businessType = OperaType.UPDATE, module = "物资管理->修改物资厂家管理")
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierInfo supplierInfo) {
        try {
            return supplierInfoService.updateSupplierInfo(supplierInfo);
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 删除物资厂家管理
     */
    @ApiOperation(value = "删除物资厂家管理")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:info:remove")
    @SysLog(title = "物资厂家管理", businessType = OperaType.DELETE, module = "物资管理->删除物资厂家管理")
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds) {
        return toAjax(supplierInfoService.deleteSupplierInfoBySupplierIds(supplierIds));
    }
}
