package com.sundot.airport.exam.common.manager.impl;

import com.sundot.airport.exam.common.manager.QuesManager;
import com.sundot.airport.exam.common.model.result.QuesOptResult;
import com.sundot.airport.exam.common.service.QuesOptService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <b>功能名：QuesMangerImpl</b><br>
 * <b>说明：</b> 试题通用业务处理层 <br>
 * <b>著作权：</b> Copyright (C) 2021 HUIFANEDU  CORPORATION<br>
 * <b>修改履历：</b><br>
 *
 * @author 2021-06-30 liangxiao
 */
@Service
public class QuesMangerImpl implements QuesManager {

    @Resource
    private QuesOptService quesOptService;

    @Override
    public Map<String, List<QuesOptResult>> byTpIdsFindAndBuildQoResult(List<String> quIds) {
        // 转换结果。根据试卷业务id进行分组
        return quesOptService.byQuIdFindList(quIds)
                .stream()
                .map(i -> new QuesOptResult() {
                    {
                        BeanUtils.copyProperties(i, this);
                    }
                })
                .collect(Collectors.groupingBy(QuesOptResult::getQuId));
    }
}
