package com.xhkjedu.slive.service.liveplay;

import com.xhkjedu.slive.mapper.liveplay.CourseSectionChatroomMapper;
import com.xhkjedu.slive.model.liveplay.LCourseSectionChatroom;
import org.springframework.stereotype.Service;

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

/**
 * @ClassName CourseSectionChatroomService
 * Description TODO 课程课节聊天室
 * Author WN
 * Date 2021/3/6 10:37
 **/
@Service
public class CourseSectionChatroomService {
    @Resource
    private CourseSectionChatroomMapper courseSectionChatroomMapper;

    public void save(LCourseSectionChatroom chatroom) {
        courseSectionChatroomMapper.insertSelective(chatroom);
    }

    public List<LCourseSectionChatroom> listChatrooms(Integer sectionid) {
        return courseSectionChatroomMapper.listChatrooms(sectionid);
    }

    public Map listChatrooms2(Integer sectionid, Integer userid) {
        Map map = courseSectionChatroomMapper.getSectionStu(sectionid, userid);
        List<Map> students = (List<Map>) map.get("students");
        Integer onstunum = students.stream().filter(m->(Long) m.get("onlined")==1).collect(Collectors.toList()).size();
        map.put("onstunum",onstunum);
        List<LCourseSectionChatroom> msg = courseSectionChatroomMapper.listChatrooms(sectionid);
        map.put("msg",msg);
        return map;
    }
}
