package com.jwipc.sys.client.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwipc.sys.client.PurchaseOrgClient;
import com.jwipc.sys.client.dto.PurchaseOrgDTO;
import com.jwipc.sys.client.convert.PurchaseOrgClientConvert;
import com.jwipc.sys.entity.PurchaseOrg;
import com.jwipc.sys.service.IPurchaseOrgService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@RequiredArgsConstructor
public class PurchaseOrgClientImpl implements PurchaseOrgClient {
    private final IPurchaseOrgService purchaseOrgService;
    private final PurchaseOrgClientConvert purchaseOrgClientConvert;

    public PurchaseOrgDTO getByCode(String code) {
        final PurchaseOrg purchaseOrg = purchaseOrgService.getOne(
                new LambdaQueryWrapper<PurchaseOrg>().eq(PurchaseOrg::getPurchaseOrgCode, code));
        return purchaseOrgClientConvert.entity2Dto(purchaseOrg);
    }

    public List<PurchaseOrgDTO> getAll(){
        final List<PurchaseOrg> purchaseOrg = purchaseOrgService.list();
        return purchaseOrgClientConvert.entities2Dtos(purchaseOrg);
    }
}
