package com.zcloud.service.paper.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.paper.StageExamPaperInputQuestionMapper;
import com.zcloud.service.paper.StageExamPaperInputQuestionService;
import com.zcloud.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 说明：阶段试卷和习题关系表
 * 作者：luoxiaobao
 * 时间：2021-12-17
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class StageExamPaperInputQuestionServiceImpl implements StageExamPaperInputQuestionService {

	@Autowired
	private StageExamPaperInputQuestionMapper stageexampaperinputquestionMapper;

	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		stageexampaperinputquestionMapper.save(pd);
	}

	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		stageexampaperinputquestionMapper.delete(pd);
	}

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		stageexampaperinputquestionMapper.edit(pd);
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> list(Page page)throws Exception{
		return stageexampaperinputquestionMapper.datalistPage(page);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAll(PageData pd)throws Exception{
		return stageexampaperinputquestionMapper.listAll(pd);
	}

	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findById(PageData pd)throws Exception{
		return stageexampaperinputquestionMapper.findById(pd);
	}

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		stageexampaperinputquestionMapper.deleteAll(ArrayDATA_IDS);
	}

	/**新增(保存抽取后的试题数据)
	 * @param pd
	 * @throws Exception
	 */
	public void saveAll(PageData pd, List<PageData> questions) throws Exception {
		for (PageData q : questions) {
			PageData question = new PageData();
			question.put("STAGEEXAMPAPER_INPUTQUESTION_ID", UuidUtil.get32UUID());    //主键
			question.put("STAGEEXAMPAPERINPUT_ID", pd.getString("STAGEEXAMPAPERINPUT_ID"));    // 试卷
//			question.put("CURRICULUM_ID", pd.getString("CURRICULUMID"));    // 课程
			question.put("COURSEWARE_ID", q.getString("COURSEWAREID"));    // 课件
			question.put("COURSEWARETYPE", q.getString("COURSEWARETYPE"));    // 课件类型
			question.put("QUESTION_ID", q.getString("QUESTION_ID"));
			question.put("QUESTIONSCORE", Integer.parseInt(q.get("QUESTIONSCORE").toString()));
			question.put("CREATOR", pd.getString("CREATOR"));    //添加人
			question.put("CREATTIME", pd.getString("CREATTIME"));    //添加时间
			question.put("OPERATOR", pd.getString("OPERATOR"));    //修改人
			question.put("OPERATTIME", pd.getString("OPERATTIME"));    //修改时间
			question.put("ISDELETE", "0");    //是否删除(0:有效 1：删除)
			question.put("CORPINFO_ID", pd.getString("CORPINFO_ID"));    //企业ID
			this.save(question);
		}
	}
	/**列表(全部) 关联习题信息 QUESTION
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAllAndQuestion(PageData pd)throws Exception{
		return stageexampaperinputquestionMapper.listAllAndQuestion(pd);
	}
}

