5 小时以前 4d15fa8051884869c5b612d0641508874cc71811
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
    }
 
}