package com.xhkjedu.suser.service.gradeclass;

import com.xhkjedu.suser.mapper.gradeclass.GradeMapper;
import com.xhkjedu.suser.mapper.gradeclass.SchoolMapper;
import com.xhkjedu.suser.model.gradeclass.TGrade;
import com.xhkjedu.suser.vo.gradeclass.GradeVo;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ywx
 * @classname TGradeService
 * @description
 * @date 2020/6/2 14:53
 **/
@Service
public class GradeService {
    @Resource
    private GradeMapper gradeMapper;
    @Resource
    private SchoolMapper schoolMapper;

    //添加
    public Integer save(TGrade model) {
        model.setCreatetime(N_Utils.getSecondTimestamp());
        gradeMapper.insertUseGeneratedKeys(model);
        return model.getId();
    }

    //删除
    public Integer deleteById(Integer gradeid) {
        return gradeMapper.deleteByPrimaryKey(gradeid);
    }

    //修改
    public Integer update(TGrade model) {
        return gradeMapper.updateByPrimaryKeySelective(model);
    }

    //获取详情
    public TGrade findById(Integer gradeid) {
        return gradeMapper.findById(gradeid);
    }

    //获取列表
    public List<TGrade> findAll(Integer schoolid) {
        Integer year = schoolMapper.getYearById(schoolid);
        return gradeMapper.findAll(schoolid, year);
    }

    /**
     * 获取通知班级列表
     *
     * @return java.util.List<com.xhkjedu.suser.vo.gradeclass.GradeVo>
     * @Param [schoolid, year]
     * @Author ywx
     * @Date 2020/6/13 15:41
     **/
    public List<GradeVo> listClass(Integer schoolid, Integer classtype) {
        Integer year = schoolMapper.getYearById(schoolid);
        return gradeMapper.listClass(schoolid, year, classtype);
    }

    /**
     * 获取通知教师列表
     *
     * @return java.util.List<com.xhkjedu.suser.vo.gradeclass.GradeVo>
     * @Param [schoolid, year]
     * @Author ywx
     * @Date 2020/6/13 15:42
     **/
    public List<GradeVo> listTeacher(Integer schoolid) {
        Integer year = schoolMapper.getYearById(schoolid);
        return gradeMapper.listTeacher(schoolid, year);
    }

    //获取行政班和提高班
    public List<GradeVo> listClassForTeacher(Integer schoolid) {
        Integer year = schoolMapper.getYearById(schoolid);
        return gradeMapper.listClassForTeacher(schoolid, year);
    }
}
