package com.xhkjedu.sstudy.service.subjectbook;

import com.xhkjedu.sstudy.mapper.subjectbook.SubjectQuestiontypeMapper;
import com.xhkjedu.sstudy.model.subjectbook.TSubjectQuestiontype;
import com.xhkjedu.sstudy.utils.StudyUtil;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sstudy.vo.subjectbook.SubjectQuestiontypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName SubjectQuestiontypeService
 * Description TODO
 * Author WN
 * Date 2020/6/2 11:57
 **/
@Service
public class SubjectQuestiontypeService {
    @Autowired
    private SubjectQuestiontypeMapper subjectQuestiontypeMapper;

    /**
     *功能描述 获取科目下所有题型
     * @author WN
     * @date 2020/6/2
     * @param  * @param sqtype
     * @return java.util.List<com.xhkjedu.model.subjectbook.TSubjectQuestiontype>
     */
    public List<TSubjectQuestiontype> listQuestiontypes(TSubjectQuestiontype sqtype){
        return subjectQuestiontypeMapper.listQuestiontypes(sqtype);
    }

    /**
     *功能描述 获取科目下所有题型用于选择数据
     * @author WN
     * @date 2020/6/2
     * @param  * @param sqtype
     * @return java.util.List<com.xhkjedu.vo.subjectbook.SubjectQuestiontypeVo>
     */
    public List<SubjectQuestiontypeVo> listQuestiontypesForSel(TSubjectQuestiontype sqtype){
        return subjectQuestiontypeMapper.listQuestiontypesForSel(sqtype);
    }

    /**
     *功能描述 添加题型
     * @author WN
     * @date 2020/6/2
     * @param  * @param sqtype
     * @return java.lang.Integer
     */
    public Integer addQuestiontype(TSubjectQuestiontype sqtype){
        String id = StudyUtil.getId();
        sqtype.setQtypeid(id);
        sqtype.setCreatetime(N_Utils.getSecondTimestamp());
        return subjectQuestiontypeMapper.insertSelective(sqtype);
    }

   /**
    *功能描述 修改题型
    * @author WN
    * @date 2020/6/2
    * @param  * @param sqtype
    * @return java.lang.Integer
    */
    public Integer updateQuestiontype(TSubjectQuestiontype sqtype){
        sqtype.setCreatetime(N_Utils.getSecondTimestamp());
        return subjectQuestiontypeMapper.updateByPrimaryKeySelective(sqtype);
    }

    /**
     *功能描述 修改题型
     * @author WN
     * @date 2020/6/2
     * @param  * @param sqtype
     * @return java.lang.Integer
     */
    public Integer delQuestiontype(TSubjectQuestiontype sqtype){
        int result = subjectQuestiontypeMapper.deleteByPrimaryKey(sqtype.getQtypeid());
        return result;
    }

    //查找使用题型的模块
    public String findUseModule(String qtypeid) {
        String useModule = subjectQuestiontypeMapper.findUseModule(qtypeid);
        if (useModule.startsWith(",")) {
            useModule = useModule.substring(1);
        }
        return useModule;
    }
}
