package com.xhkjedu.sstudy.service.subjectbook;

import com.xhkjedu.sstudy.mapper.subjectbook.SubjectMapper;
import com.xhkjedu.sstudy.model.subjectbook.TSubject;
import com.xhkjedu.sstudy.utils.StudyUtil;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sstudy.vo.subjectbook.SubjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @ClassName SubjectService
 * Description
 * Author WN
 * Date 2020/6/1 11:44
 **/
@Service
public class SubjectService {
    @Autowired
    private SubjectMapper subjectMapper;


    /**
     *功能描述  获取阶段下科目
     * @author WN
     * @date 2020/6/1
     * @param  * @param subject
     * @return java.util.List<com.xhkjedu.model.subjectbook.TSubject>
     */
    public List<TSubject> listSubjects(TSubject subject){
        return subjectMapper.listSubjects(subject);
    }

    /**
     *功能描述 获取阶段下科目--选择框
     * @author WN
     * @date 2020/6/1
     * @param  * @param subject
     * @return java.util.List<com.xhkjedu.vo.subjectbook.SubjectVo>
     */
    public List<SubjectVo> listSubjectsForSel(TSubject subject){
        return subjectMapper.listSubjectsForSel(subject);
    }

    /**
     *功能描述  保存科目
     * @author WN
     * @date 2020/6/1
     * @param  * @param subject
     * @return java.lang.Integer
     */
    public Integer addSubject(TSubject subject){
        String id = StudyUtil.getId();
        subject.setSubjectid(id);
        subject.setCreatetime(N_Utils.getSecondTimestamp());
        return subjectMapper.insertSelective(subject);
    }

    /**
     *功能描述 修改科目
     * @author WN
     * @date 2020/6/1
     * @param  * @param subject
     * @return java.lang.Integer
     */
    public Integer updateSubject(TSubject subject){
        subject.setCreatetime(N_Utils.getSecondTimestamp());
        return subjectMapper.updateByPrimaryKeySelective(subject);
    }

    /**
     *功能描述 删除科目
     * @author WN
     * @date 2020/6/1
     * @param  * @param subject
     * @return java.lang.Integer
     */
    public Integer delSubject(TSubject subject){
        int result = subjectMapper.deleteByPrimaryKey(subject.getSubjectid());
        return result;
    }

    /**
     * 根据学段id获取科目id集合
     * @Param [level]
     * @Author ywx
     * @Date 2020/6/8 9:59
     * @return java.lang.String
     **/
    public String getSubjectIds(Integer level) {
        return subjectMapper.getSubjectIds(level);
    }

    /**
     * 教师科目集合
     * @Param [teacherid]
     * @Author ywx
     * @Date 2020/6/28 9:33
     * @return java.util.List<com.xhkjedu.model.subjectbook.TSubject>
     **/
    public List<TSubject> listTeacherSubjects(Integer teacherid) {
        return subjectMapper.listTeacherSubjects(teacherid);
    }

    //查找使用科目的模块
    public String findUseModule(String subjectid) {
        String useModule = subjectMapper.findUseModule(subjectid);
        if (useModule.startsWith(",")) {
            useModule = useModule.substring(1);
        }
        return useModule;
    }
}
