package com.jwipc.sys.client.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jwipc.sys.client.ProductGroupClient;
import com.jwipc.sys.client.dto.ProductGroupDTO;
import com.jwipc.sys.client.convert.ProductGroupClientConvert;
import com.jwipc.sys.entity.ProductGroup;
import com.jwipc.sys.service.IProductGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/3/27 14:20
 * @desc
 */
@Service
@RequiredArgsConstructor
public class ProductGroupClientImpl implements ProductGroupClient {
    private final IProductGroupService productGroupService;
    private final ProductGroupClientConvert productGroupClientConvert;
    public List<ProductGroupDTO> getAll(){
        final List<ProductGroup> purchaseGroup = productGroupService.list();
        return productGroupClientConvert.entities2Dtos(purchaseGroup);
    }

    public ProductGroupDTO getByCodeAndCategory(String code,String categoryCode){
        final ProductGroup purchaseGroup = productGroupService.getOne(Wrappers.lambdaQuery(ProductGroup.class).eq(ProductGroup::getMaterialGroup,code).eq(ProductGroup::getCategoryCode,categoryCode).last(" limit 1"));
        return productGroupClientConvert.entities2Dto(purchaseGroup);
    }

    @Override
    public ProductGroupDTO getByCode(String code) {
        final ProductGroup purchaseGroup = productGroupService.getOne(Wrappers.lambdaQuery(ProductGroup.class).eq(ProductGroup::getMaterialGroup,code).last(" limit 1"));
        return productGroupClientConvert.entities2Dto(purchaseGroup);
    }
}
