package com.xhkjedu.suser.service.gradeclass;

import com.xhkjedu.suser.mapper.gradeclass.ClassMapper;
import com.xhkjedu.suser.mapper.gradeclass.SchoolMapper;
import com.xhkjedu.suser.model.gradeclass.TClass;
import com.xhkjedu.suser.model.gradeclass.TGroup;
import com.xhkjedu.suser.vo.gradeclass.ClassTeacherSubjectVo;
import com.xhkjedu.suser.vo.gradeclass.ClassVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.stereotype.Service;

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

/**
 * @author ywx
 * @classname TClassService
 * @description 
 * @date 2020/6/2 14:57
 **/
@Service
public class ClassService {
    @Resource
    private ClassMapper classMapper;
    @Resource
    private GroupService groupService;
    @Resource
    private SchoolMapper schoolMapper;

    //添加
    public Integer save(TClass model) {
        model.setCreatetime(N_Utils.getSecondTimestamp());
        model.setClassnum(0);
        model.setClassstate(1);
        Integer year = schoolMapper.getYearById(model.getSchoolid());
        model.setYear(year);//当前年份必须和学校年份一致
        classMapper.insertUseGeneratedKeys(model);
        //创建全体分组
        TGroup group = new TGroup();
        group.setGroupname("全班学生");
        group.setClassid(model.getId());
        group.setGrouptype(1);
        group.setCreateid(model.getCreateid());
        group.setSchoolid(model.getSchoolid());
        groupService.save(group);
        return model.getId();
    }

    //删除
    public ResultVo deleteById(Integer classid) {
        classMapper.updateClassstateByClassid(classid,10);//删除班级逻辑删除
        return new ResultVo(0,"删除成功");
    }

    //修改
    public Integer update(TClass model) {
        model.setYear(null);//当前年份不能修改
        return classMapper.updateByPrimaryKeySelective(model);
    }

    //获取列表
    public List <ClassVo> findAll(TClass tClass) {
        return classMapper.findAll(tClass);
    }

    //根据班级名称获取班级信息
    public TClass getByName(TClass tClass) {
        return classMapper.getByName(tClass);
    }

    //获取任教老师列表
    public List<ClassTeacherSubjectVo> listTeacher(Integer classid, Integer schoolid) {
        return classMapper.listTeacher(classid, schoolid);
    }

    //班级下教师，以及教师科目
    public List<Map> listTeacherSubject(Integer classid){
        return classMapper.listTeacherSubject(classid);
    }

    /*
     * @Description 获取伙伴学校及伙伴学校班级
     * @Date 2023/8/29 10:49:57
     * @Author WN
     * @Param [schoolid]
     * @Return java.util.List<java.util.Map>
     **/
    public List<Map> listSchoolAndClass(Integer schoolid) {
        return classMapper.listSchoolAndClass(schoolid);
    }
}
