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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import digital.laboratory.platform.reagent.entity.OutgoingContents;
import digital.laboratory.platform.reagent.entity.ReagentConsumables;
import digital.laboratory.platform.reagent.entity.RequisitionRecord;
import digital.laboratory.platform.reagent.mapper.RequisitionRecordMapper;
import digital.laboratory.platform.reagent.service.ReagentConsumablesService;
import digital.laboratory.platform.reagent.service.RequisitionRecordService;
import digital.laboratory.platform.reagent.vo.RequisitionRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (试剂耗材领用记录表)服务实现类
 *
 * @author Zhang Xiaolong created at  2023-03-10
 * @describe (试剂耗材领用记录表) 服务实现类
 */
@Service
public class RequisitionRecordServiceImpl extends ServiceImpl<RequisitionRecordMapper, RequisitionRecord> implements RequisitionRecordService {

    @Autowired
    private ReagentConsumablesService reagentConsumablesService;

    @Autowired
    private RequisitionRecordService requisitionRecordService;
    @Override
    public RequisitionRecord addRecord(OutgoingContents outgoingContents){

        RequisitionRecord requisitionRecord = new RequisitionRecord();

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

        requisitionRecord.setRequisitionRecordId(IdWorker.get32UUID().toUpperCase());
        requisitionRecord.setRemarks(outgoingContents.getRemarks());
        requisitionRecord.setDrawingAmount(outgoingContents.getQuantity());
        requisitionRecord.setSpecificationAndModel(byId.getSpecificationAndModel());

        if (requisitionRecordService.save(requisitionRecord)){
            return requisitionRecord;
        }else throw new RuntimeException(String.format("试剂耗材领用记录表创建失败"));

    }


    @Override
    public IPage<RequisitionRecordVO> getRequisitionRecordVOPage(IPage<RequisitionRecord> page, QueryWrapper<RequisitionRecord> qw){

        IPage<RequisitionRecordVO> requisitionRecordVOPage = baseMapper.getRequisitionRecordVOPage(page, qw);

        return requisitionRecordVOPage;


    }
}
