package cn.iocoder.yudao.module.basic.controller.admin.vendorinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.basic.controller.admin.vendorinfo.vo.*;
import cn.iocoder.yudao.module.basic.dal.dataobject.vendorinfo.VendorInfoDO;
import cn.iocoder.yudao.module.basic.convert.vendorinfo.VendorInfoConvert;
import cn.iocoder.yudao.module.basic.service.vendorinfo.VendorInfoService;

@Api(tags = "管理后台 - 供应商")
@RestController
@RequestMapping("/basic/vendor-info")
@Validated
public class VendorInfoController {

    @Resource
    private VendorInfoService vendorInfoService;

    @PostMapping("/create")
    @ApiOperation("创建供应商")
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:create')")
    public CommonResult<Long> createVendorInfo(@Valid @RequestBody VendorInfoCreateReqVO createReqVO) {
        return success(vendorInfoService.createVendorInfo(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新供应商")
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:update')")
    public CommonResult<Boolean> updateVendorInfo(@Valid @RequestBody VendorInfoUpdateReqVO updateReqVO) {
        vendorInfoService.updateVendorInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除供应商")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:delete')")
    public CommonResult<Boolean> deleteVendorInfo(@RequestParam("id") Long id) {
        vendorInfoService.deleteVendorInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得供应商")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:query')")
    public CommonResult<VendorInfoRespVO> getVendorInfo(@RequestParam("id") Long id) {
        VendorInfoDO vendorInfo = vendorInfoService.getVendorInfo(id);
        return success(VendorInfoConvert.INSTANCE.convert(vendorInfo));
    }

    @GetMapping("/page")
    @ApiOperation("获得供应商分页")
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:query')")
    public CommonResult<PageResult<VendorInfoRespVO>> getVendorInfoPage(@Valid VendorInfoPageReqVO pageVO) {
        PageResult<VendorInfoDO> pageResult = vendorInfoService.getVendorInfoPage(pageVO);
        return success(VendorInfoConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/getVendorInfoOptionsList")
    @ApiOperation("获得供应商下拉列表")
    @PreAuthorize("@ss.hasPermission('basic:vendor-info:query')")
    public CommonResult<List<VendorInfoOfOptionsRespVO>> getVendorInfoOptionsList() {
        List<VendorInfoDO> list = vendorInfoService.getVendorInfoList();
        return success(VendorInfoConvert.INSTANCE.convertToOptionsList(list));
    }

}
