package com.ruoyi.ie.service.impl;

import com.ruoyi.ie.domain.Questions;
import com.ruoyi.ie.domain.Subquestions;
import com.ruoyi.ie.mapper.QuestionsMapper;
import com.ruoyi.ie.mapper.SubquestionsMapper;
import com.ruoyi.ie.service.ISubquestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 子试题Service业务层处理
 *
 * @author mingxue
 * @date 2021-06-19
 */
@Service
public class SubquestionsServiceImpl implements ISubquestionsService
{
    @Autowired
    private SubquestionsMapper subquestionsMapper;
    @Autowired
    private QuestionsMapper questionsMapper;
    /**
     * 查询子试题
     *
     * @param id 子试题ID
     * @return 子试题
     */
    @Override
    public Subquestions selectSubquestionsById(Integer id)
    {
        return subquestionsMapper.selectSubquestionsById(id);
    }

    /**
     * 查询子试题列表
     *
     * @param subquestions 子试题
     * @return 子试题
     */
    @Override
    public List<Subquestions> selectSubquestionsList(Subquestions subquestions)
    {
        return subquestionsMapper.selectSubquestionsList(subquestions);
    }

    /**
     * 新增子试题
     *
     * @param subquestions 子试题
     * @return 结果
     */
    @Override
    public int insertSubquestions(Subquestions subquestions)
    {
        Questions questions = questionsMapper.selectQuestionsById(subquestions.getPid());
        questions.setIsSub(1);
        questionsMapper.updateQuestions(questions);
        return subquestionsMapper.insertSubquestions(subquestions);
    }

    /**
     * 修改子试题
     *
     * @param subquestions 子试题
     * @return 结果
     */
    @Override
    public int updateSubquestions(Subquestions subquestions)
    {
        return subquestionsMapper.updateSubquestions(subquestions);
    }

    /**
     * 批量删除子试题
     *
     * @param ids 需要删除的子试题ID
     * @return 结果
     */
    @Override
    public int deleteSubquestionsByIds(Integer[] ids)
    {
        return subquestionsMapper.deleteSubquestionsByIds(ids);
    }

    @Override
    public int deleteSubquestionsByQuestionId(Integer questionId) {
        return subquestionsMapper.deleteSubquestionsByQuestionId(questionId);
    }

    /**
     * 删除子试题信息
     *
     * @param id 子试题ID
     * @return 结果
     */
    @Override
    public int deleteSubquestionsById(Integer id)
    {
        return subquestionsMapper.deleteSubquestionsById(id);
    }

    @Override
    public List<Subquestions> selectSubquestionsByQuestionId(Long questionId) {
        return subquestionsMapper.selectSubquestionsByQuestionId(questionId);
    }

    @Override
    public List<Subquestions> selectSubquestionsByQuestionIds(Long[] ids) {
        return subquestionsMapper.selectSubquestionsByQuestionIds(ids);
    }
}
