package com.zcloud.service.onlinexxks.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.dsno3.onlinexxks.StageexammiddleMapper;
import com.zcloud.service.onlinexxks.StageexammiddleService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.UuidUtil;

/**
 * 说明：阶段考试试题中间表【！！！作废！！！】
 * 作者：luoxiaobao
 * 时间：2021-07-04
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class StageexammiddleServiceImpl implements StageexammiddleService{

	@Autowired
	private StageexammiddleMapper stageexammiddleMapper;

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

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

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

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

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

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

	/**批量删除
	 * @param pd
	 * @throws Exception
	 */
	public void deleteAll(PageData pd)throws Exception{
		stageexammiddleMapper.deleteAll(pd);
	}

	/**列表(根据所选ID获取数据)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> findByIds(PageData pd) throws Exception {
		return stageexammiddleMapper.findByIds(pd);
	}

	/**新增(保存抽取后的试题数据)
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public void saveAll(PageData pd, List<PageData> questions) throws Exception {
		for (PageData q : questions) {
			PageData question = new PageData();
			question.put("STAGEEXAMMIDDLE_ID", UuidUtil.get32UUID());    //主键
			question.put("STAGEEXAMPAPERID", pd.getString("STAGEEXAMPAPER_ID"));    // 试卷
			question.put("CURRICULUMID", pd.getString("CURRICULUMID"));    // 课程
			question.put("COURSEWAREID", q.getString("COURSEWAREID"));    // 课件
			question.put("COURSEWARETYPE", q.getString("COURSEWARETYPE"));    // 课件类型
			question.put("QUESTIONID", q.getString("QUESTION_ID"));
			question.put("QUESTIONSCORE", Integer.parseInt(pd.get("QUESTIONSCORE").toString()));
			question.put("CREATOR", Jurisdiction.getUsername());    //添加人
			question.put("CREATTIME", DateUtil.date2Str(new Date()));    //添加时间
			question.put("OPERATOR", Jurisdiction.getUsername());    //修改人
			question.put("OPERATTIME", DateUtil.date2Str(new Date()));    //修改时间
			question.put("ISDELETE", "0");    //是否删除(0:有效 1：删除)
			question.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());    //企业ID
			this.save(question);
		}
	}

	/**列表(根据试卷ID获取试题数据)
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> findByExamPaper(PageData pd) {
		return stageexammiddleMapper.findByExamPaper(pd);
	}

	/**删除(根据试卷ID删除试题数据)
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public void deleteByExamPaper(PageData pd) {
		stageexammiddleMapper.deleteByExamPaper(pd);
	}

	/**删除(根据课程ID删除试题数据)
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public void deleteByCurriculumIds(PageData pd) throws Exception {
		stageexammiddleMapper.deleteByCurriculumIds(pd);

	}
}

