package cn.iocoder.yudao.module.srm.api.supplier;
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.module.srm.api.supplier.dto.SrmSupplierRespDTO;
|
import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
|
import cn.iocoder.yudao.module.srm.enums.ErrorCodeConstants;
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
import cn.iocoder.yudao.module.srm.service.supplier.SrmSupplierService;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.validation.annotation.Validated;
|
|
import java.util.Collection;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
/**
|
* SRM 供应商 API 实现类
|
*/
|
@Service
|
@Validated
|
public class SrmSupplierApiImpl implements SrmSupplierApi {
|
|
@Resource
|
private SrmSupplierService supplierService;
|
|
@Override
|
public CommonResult<SrmSupplierRespDTO> getSupplier(Long srmId) {
|
SrmSupplierDO supplier = supplierService.getSupplier(srmId);
|
if (supplier == null) {
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.SUPPLIER_NOT_EXISTS);
|
}
|
return success(toRespDTO(supplier));
|
}
|
|
@Override
|
public CommonResult<List<SrmSupplierRespDTO>> getSupplierList(Collection<Long> ids) {
|
List<SrmSupplierDO> list = supplierService.getSupplierList(ids);
|
return success(list.stream().map(this::toRespDTO).collect(Collectors.toList()));
|
}
|
|
@Override
|
public CommonResult<List<SrmSupplierRespDTO>> getSupplierSimpleList() {
|
List<SrmSupplierDO> list = supplierService.getSupplierSimpleList();
|
return success(list.stream().map(this::toRespDTO).collect(Collectors.toList()));
|
}
|
|
private SrmSupplierRespDTO toRespDTO(SrmSupplierDO supplier) {
|
SrmSupplierRespDTO dto = new SrmSupplierRespDTO();
|
dto.setId(supplier.getId());
|
dto.setCode(supplier.getCode());
|
dto.setName(supplier.getName());
|
dto.setStatus(supplier.getStatus());
|
return dto;
|
}
|
|
}
|