package com.xhkjedu.slive.controller.liveplay;

import com.xhkjedu.slive.model.liveplay.LCourseSectionChatroom;
import com.xhkjedu.slive.service.liveplay.CourseSectionChatroomService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @ClassName CourseSectionChatroomController
 * Description TODO 课程课节聊天室
 * Author WN
 * Date 2021/3/6 10:07
 **/
@RestController
@RequestMapping("/chatr")
public class CourseSectionChatroomController {
    @Resource
    private CourseSectionChatroomService courseSectionChatroomService;

    //保存聊天室消息
    @PostMapping("/add")
    public ResultVo save(@RequestBody LCourseSectionChatroom chatroom) {
        N_Utils.validation(new Object[]{chatroom.getSectionid(),"课节id",1
        ,chatroom.getUserid(),"用户id",1});
        courseSectionChatroomService.save(chatroom);
        return new ResultVo(0,"保存成功");
    }

    //聊天室消息记录集合
    @PostMapping("/list")
    public ResultVo list(@RequestBody LCourseSectionChatroom chatroom) {
        N_Utils.validation(new Object[]{chatroom.getSectionid(),"课节id",1});
        List<LCourseSectionChatroom> list = courseSectionChatroomService.listChatrooms(chatroom.getSectionid());
        return new ResultVo(0,"聊天室消息记录集合",list);
    }

    @PostMapping("/list2")
    public ResultVo list2(@RequestBody LCourseSectionChatroom chatroom) {
        N_Utils.validation(new Object[]{chatroom.getSectionid(),"课节id",1});
        Map map =  courseSectionChatroomService.listChatrooms2(chatroom.getSectionid(),chatroom.getUserid());
        return new ResultVo(0,"聊天室消息记录集合",map);
    }

}
