package com.zcloud.service.questionnaire.impl;

import com.zcloud.entity.PageData;
import com.zcloud.mapper.dsno2.questionnaire.SurveyMapper;
import com.zcloud.service.questionnaire.QuestionitemService;
import com.zcloud.service.questionnaire.SurveyService;
import com.zcloud.service.questionnaire.SurveyquestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 说明：习题管理
 * 作者：luoxiaobao
 * 时间：2021-07-03
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class SurveyServiceImpl implements SurveyService {

	@Autowired
	private SurveyMapper surveyMapper;

	@Autowired
	private SurveyquestionService surveyquestionService;

	@Autowired
	private QuestionitemService questionitemService;
	/**
	 * 通过试卷ID获取数据
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> getQuestions(PageData pd) throws Exception {
		List<PageData> questionList = surveyquestionService.findBySurveyId(pd);
		List<PageData> returnList = new ArrayList<PageData>();
		for (int i = 0; i < questionList.size(); i++) {
			PageData question = questionList.get(i);
			question.put("selection",questionitemService.findByQuestionId(question));
			returnList.add(question);
		}
		return returnList;
	}

	public void getstate(PageData pd)throws Exception{
		surveyMapper.getstate(pd);
	}

	public PageData findBycorpinfoId(PageData pd)throws Exception{
		return surveyMapper.findBycorpinfoId(pd);
	}

	public PageData findBysurveyId(PageData pd)throws Exception{
		return surveyMapper.findBysurveyId(pd);
	}

	public PageData findById(PageData pd)throws Exception{
		return surveyMapper.findById(pd);
	}
}

