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.DetailsOfCentralized;
import digital.laboratory.platform.reagent.entity.ReagentConsumables;
import digital.laboratory.platform.reagent.mapper.DetailsOfCentralizedMapper;
import digital.laboratory.platform.reagent.service.DetailsOfCentralizedService;
import digital.laboratory.platform.reagent.service.ReagentConsumablesService;
import digital.laboratory.platform.reagent.vo.DetailsOfCentralizedVO;
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 (集中采购申请明细) 服务实现类
 */
@Service
public class DetailsOfCentralizedServiceImpl extends ServiceImpl<DetailsOfCentralizedMapper, DetailsOfCentralized> implements DetailsOfCentralizedService {

    @Autowired
    private DetailsOfCentralizedService detailsOfCentralizedService;

    @Autowired
    private ReagentConsumablesService reagentConsumablesService;

    @Override
    public List<DetailsOfCentralizedVO> getDetailsOfCentralizedVOList(String centralizedRequestId) {

        List<DetailsOfCentralizedVO> list = baseMapper.getDetailsOfCentralizedVOList(centralizedRequestId);

        return list;
    }

    @Override
    public List<DetailsOfCentralizedVO> getDetailsOfCentralizedList(String purchasingPlanId) {

        LambdaQueryWrapper<DetailsOfCentralized> detailsOfCentralizedLambdaQueryWrapper = new LambdaQueryWrapper<>();

        detailsOfCentralizedLambdaQueryWrapper.eq(DetailsOfCentralized::getProcurementContentId, purchasingPlanId);

        List<DetailsOfCentralized> list = detailsOfCentralizedService.list(detailsOfCentralizedLambdaQueryWrapper);

        List<DetailsOfCentralizedVO> detailsOfCentralizedVOS = new ArrayList<>();

        for (DetailsOfCentralized detailsOfCentralized : list) {

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

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

            ReagentConsumables one = reagentConsumablesService.getOne(reagentConsumablesLambdaQueryWrapper);

            DetailsOfCentralizedVO detailsOfCentralizedVO = new DetailsOfCentralizedVO();

            BeanUtils.copyProperties(detailsOfCentralized, detailsOfCentralizedVO);

            detailsOfCentralizedVO.setReplacementReagentConsumableName(one.getReagentConsumableName());

            detailsOfCentralizedVOS.add(detailsOfCentralizedVO);
        }

        return detailsOfCentralizedVOS;
    }
}
