package digital.laboratory.platform.reagent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import digital.laboratory.platform.reagent.entity.ReagentConsumables;
import digital.laboratory.platform.reagent.entity.ReferenceMaterial;
import digital.laboratory.platform.reagent.mapper.ReferenceMaterialMapper;
import digital.laboratory.platform.reagent.service.ReagentConsumablesService;
import digital.laboratory.platform.reagent.service.ReferenceMaterialService;
import digital.laboratory.platform.reagent.vo.ReferenceMaterialVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务实现类
 *
 * @author Zhang Xiaolong created at  2023-03-23
 * @describe  服务实现类
 */
@Service
public class ReferenceMaterialServiceImpl extends ServiceImpl<ReferenceMaterialMapper, ReferenceMaterial> implements ReferenceMaterialService {

    @Autowired
    private ReferenceMaterialService referenceMaterialService;

    @Autowired
    private ReagentConsumablesService reagentConsumablesService;

    @Override
    public List<ReferenceMaterialVO> getReferenceMaterialVOList(String batchDetailsId){

        LambdaQueryWrapper<ReferenceMaterial> referenceMaterialLambdaQueryWrapper = new LambdaQueryWrapper<>();

        referenceMaterialLambdaQueryWrapper.eq(ReferenceMaterial::getBatchDetailsId,batchDetailsId);

        List<ReferenceMaterial> list = referenceMaterialService.list(referenceMaterialLambdaQueryWrapper);

        List<ReferenceMaterialVO> referenceMaterialVOS = new ArrayList<>();

        for (ReferenceMaterial referenceMaterial : list) {

            ReagentConsumables byId = reagentConsumablesService.getById(referenceMaterial.getReagentConsumableId());

            ReferenceMaterialVO referenceMaterialVO = new ReferenceMaterialVO();

            BeanUtils.copyProperties(referenceMaterial,referenceMaterialVO);

            referenceMaterialVO.setReferenceMaterialName(byId.getReagentConsumableName());

            referenceMaterialVOS.add(referenceMaterialVO);
        }

        return referenceMaterialVOS;
    }

}
