package com.xhkjedu.slive.service.gradeclass;

import com.xhkjedu.slive.mapper.gradeclass.GroupMapper;
import com.xhkjedu.slive.model.gradeclass.TGroup;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ywx
 * @classname GroupService
 * @description 
 * @date 2020/6/2 17:26
 **/
@Service
public class GroupService {
    @Resource
    private GroupMapper groupMapper;
    @Resource
    private GroupStudentService groupStudentService;

    //添加
    public Integer save(TGroup model) {
        model.setGroupnum(0);
        model.setCreatetime(N_Utils.getSecondTimestamp());
        groupMapper.insertUseGeneratedKeys(model);
        if (N_Utils.isListNotEmpty(model.getStudents())){
            model.setGroupid(model.getId());
            groupStudentService.batchSave(model);//批量添加分组学生
        }
        return model.getId();
    }

    //删除
    public Integer deleteById(Integer groupid) {
        return groupMapper.deleteByPrimaryKey(groupid);
    }
}
