package com.jwipc.sys.client.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jwipc.sys.client.PurchaseCategoryClient;
import com.jwipc.sys.client.dto.PurchaseCategoryClientDTO;
import com.jwipc.sys.client.convert.PurchaseCategoryClientConvert;
import com.jwipc.sys.entity.PurchaseCategory;
import com.jwipc.sys.service.IPurchaseCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/4/12 10:42
 * @desc 采购品类
 */
@Service
@RequiredArgsConstructor
public class PurchaseCategoryClientImpl implements PurchaseCategoryClient {
    private final IPurchaseCategoryService purchaseCategoryService;
    private final PurchaseCategoryClientConvert purchaseCategoryClientConvert;
    public List<PurchaseCategoryClientDTO> getAll(){
        final List<PurchaseCategory> purchaseCategories = purchaseCategoryService.list();
        return purchaseCategoryClientConvert.entities2Dtos(purchaseCategories);
    }

    public PurchaseCategoryClientDTO getByCode(String firstLevelPurchaseCode){
        final PurchaseCategory purchaseCategory = purchaseCategoryService.getOne(Wrappers.lambdaQuery(PurchaseCategory.class).eq(PurchaseCategory::getFirstLevelPurchaseCode,firstLevelPurchaseCode).last(" limit 1"));
        return purchaseCategoryClientConvert.entities2Dto(purchaseCategory);
    }
}
