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.ReagentConsumablesSet;
import digital.laboratory.platform.reagent.mapper.ReagentConsumablesSetMapper;
import digital.laboratory.platform.reagent.service.ReagentConsumablesService;
import digital.laboratory.platform.reagent.service.ReagentConsumablesSetService;
import digital.laboratory.platform.reagent.vo.ReagentConsumablesSetVO;
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-10
 * @describe (试剂耗材集合) 服务实现类
 */
@SuppressWarnings("all")
@Service
public class ReagentConsumablesSetServiceImpl extends ServiceImpl<ReagentConsumablesSetMapper, ReagentConsumablesSet> implements ReagentConsumablesSetService {

    @Autowired
    private ReagentConsumablesSetService reagentConsumablesSetService;

    @Autowired
    private ReagentConsumablesService reagentConsumablesService;

    @Override
    public List<ReagentConsumablesSetVO> getList(String applicationForUseId){

        LambdaQueryWrapper<ReagentConsumablesSet> reagentConsumablesSetLambdaQueryWrapper = new LambdaQueryWrapper<>();

        reagentConsumablesSetLambdaQueryWrapper.eq(ReagentConsumablesSet::getApplicationForUseId,applicationForUseId);

        List<ReagentConsumablesSet> list = reagentConsumablesSetService.list(reagentConsumablesSetLambdaQueryWrapper);

        List<ReagentConsumablesSetVO> reagentConsumablesSetVOS = new ArrayList<>();
        //查找出试剂耗材名称
        for (ReagentConsumablesSet reagentConsumablesSet : list) {

            ReagentConsumablesSetVO reagentConsumablesSetVO = new ReagentConsumablesSetVO();

            BeanUtils.copyProperties(reagentConsumablesSet,reagentConsumablesSetVO);

            LambdaQueryWrapper<ReagentConsumables> reagentConsumablesLambdaQueryWrapper = new LambdaQueryWrapper<>();

            reagentConsumablesLambdaQueryWrapper.eq(ReagentConsumables::getReagentConsumableId,reagentConsumablesSet.getReagentConsumableId());

            ReagentConsumables one = reagentConsumablesService.getOne(reagentConsumablesLambdaQueryWrapper);

            reagentConsumablesSetVO.setReagentConsumableName(one.getReagentConsumableName());

            reagentConsumablesSetVOS.add(reagentConsumablesSetVO);
        }
        return reagentConsumablesSetVOS;
    }
}
