package cn.iocoder.yudao.module.system.api.supplier;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.supplier.dto.SupplierRpcDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.supplier.SupplierDO;
import cn.iocoder.yudao.module.system.service.supplier.SupplierService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

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

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class SupplierApiImpl implements SupplierApi {

    @Resource
    private SupplierService supplierService;


    @Override
    public CommonResult saveOrEdit(SupplierRpcDTO supplier) {
        supplierService.saveOrEdit(supplier);
        return success(true);
    }

    @Override
    public CommonResult<String> getNameById(Long id) {
        SupplierDO supplier = supplierService.getSupplier(id);
        return success(supplier == null ? "其他" : supplier.getSupplierName());
    }
}
