package com.yonge.cooleshow.biz.dal.service.impl;

import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
import com.yonge.cooleshow.biz.dal.dao.VideoLessonAuthRecordDao;
import com.yonge.cooleshow.biz.dal.dao.VideoLessonGroupDao;
import com.yonge.cooleshow.biz.dal.dao.VideoLessonGroupDetailDao;
import com.yonge.cooleshow.biz.dal.dto.search.VideoGroupSearch;
import com.yonge.cooleshow.biz.dal.dto.search.VideoLessonGroupSearch;
import com.yonge.cooleshow.biz.dal.dto.search.VideoLessonSearch;
import com.yonge.cooleshow.biz.dal.entity.Subject;
import com.yonge.cooleshow.biz.dal.entity.Teacher;
import com.yonge.cooleshow.biz.dal.entity.VideoLessonAuthRecord;
import com.yonge.cooleshow.biz.dal.entity.VideoLessonGroup;
import com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupDetail;
import com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupLog;
import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
import com.yonge.cooleshow.biz.dal.enums.TeacherTagEnum;
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
import com.yonge.cooleshow.biz.dal.service.SysMessageService;
import com.yonge.cooleshow.biz.dal.service.TeacherService;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupLogService;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupService;
import com.yonge.cooleshow.biz.dal.vo.CountVideoGroupVo;
import com.yonge.cooleshow.biz.dal.vo.LessonGroupVo;
import com.yonge.cooleshow.biz.dal.vo.ShareProfitVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonAuthGroup;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonExamineVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonGroupUpVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonGroupVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonPurchaseVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonShelvesVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonStudentDetailVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonStudentVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonTeacherVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonVo;
import com.yonge.cooleshow.common.constant.SysConfigConstant;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import com.yonge.toolset.base.exception.BizException;
import com.yonge.toolset.base.string.MessageFormatter;
import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
import com.yonge.toolset.utils.json.JsonUtil;

/**
 * VideoLessonGroupService服务实现类
 *
 * @author yzp
 * @version v1.0
 * @date 2022-03-26 00:01:38
 **/
@Service
public class VideoLessonGroupServiceImpl extends ServiceImpl<VideoLessonGroupDao, VideoLessonGroup> implements VideoLessonGroupService {

    private final static Logger log = LoggerFactory.getLogger(VideoLessonGroupServiceImpl.class);

    @Autowired
    private VideoLessonGroupDao videoLessonGroupDao;
    @Autowired
    private VideoLessonGroupDetailDao videoLessonGroupDetailDao;
    @Autowired
    private VideoLessonAuthRecordDao recordDao;
    @Autowired
    private TeacherDao teacherDao;
    @Autowired
    private SysMessageService sysMessageService;

    @Autowired
    private TeacherService teacherService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private SysConfigService sysConfigService;
    
    @Autowired
    private VideoLessonGroupLogService videoLessonGroupLogService;

    public VideoLessonGroupDao getDao() {
        return videoLessonGroupDao;
    }

    /**
     * @Description: 查询视频课组
     * @Author: cy
     * @Date: 2022/3/31
     */
    @Override
    public IPage<VideoLessonGroupVo> selectPage(IPage<VideoLessonGroupVo> page, VideoLessonGroupSearch query) {
		if (org.apache.commons.lang3.StringUtils.isNotBlank(query.getAuditStatus())) {

			if (query.getAuditStatus().equals(AuthStatusEnum.DOING.getCode())) {
				query.setShelvesFlag(null);
			} else if (query.getAuditStatus().equals(AuthStatusEnum.UNPASS.getCode())) {
				query.setShelvesFlag(null);
			} else {
				if (query.getAuditStatus().equals(AuthStatusEnum.OUT_SALE.getCode())) {
					query.setAuditStatus(AuthStatusEnum.PASS.getCode());
					query.setShelvesFlag(0);
				} else if (query.getAuditStatus().equals(AuthStatusEnum.PASS.getCode())) {
					query.setShelvesFlag(1);
				}
			}
		}
        return page.setRecords(baseMapper.selectPage(page, query));
    }

    public List<VideoLessonGroupVo> selectPage(VideoLessonGroupSearch query) {
        List<VideoLessonGroupVo> list = baseMapper.selectPage(null, query);
        List<VideoLessonGroupVo> collect = list.stream().filter(videoLessonGroupVo -> !videoLessonGroupVo.getId().equals(query.getVideoLessonGroupId()))
                                               .sorted(Comparator.comparing(VideoLessonGroupVo::getCountStudent, Comparator.reverseOrder())).limit(2).collect(Collectors.toList());
        return collect;
    }

    /**
     * @Description: 根据组id查详情
     * @Author: cy
     * @Date: 2022/4/11
     */
    public VideoLessonGroup selectGroup(Long groupId) {
        return videoLessonGroupDao.selectGroupById(groupId);
    }

    /**
     * @Description: 修改视频课组
     * @Author: cy
     * @Date: 2022/3/31
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateGroup(VideoLessonGroupUpVo lessonGroupUpVo) {
        videoLessonGroupDao.updateGroup(lessonGroupUpVo);
    }

    /**
     * @Description: 审核-修改视频课组审核状态
     * @Author: cy
     * @Date: 2022/4/24
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateGroup(VideoLessonExamineVo examineVo) {
    	
    	if (examineVo.getAuditStatus().equals("PASS")) {
    		examineVo.setShelvesFlag(1);
    	}
        //改主表
        videoLessonGroupDao.updateExamine(examineVo);
        
        VideoLessonGroup lessonGroup = baseMapper.selectById(examineVo.getId());
        //插从表
        VideoLessonAuthRecord record = new VideoLessonAuthRecord();
        record.setAuditStatus(examineVo.getAuditStatus());
        record.setVideoGroupId(examineVo.getId());
        record.setAuditId(examineVo.getAuditId());
        record.setAuditName(examineVo.getAuditName());
        record.setRemarks(examineVo.getRemarks());
        record.setVersion(videoLessonGroupLogService.queryMaxVersion(examineVo.getId()));
        recordDao.insert(record);

        //清状态
        recordDao.delete(Wrappers.<VideoLessonAuthRecord>lambdaQuery()
                .eq(VideoLessonAuthRecord::getVideoGroupId, examineVo.getId())
                .eq(VideoLessonAuthRecord::getAuditStatus, AuthStatusEnum.DOING));

        // 设置标签
        if (AuthStatusEnum.PASS.getCode().equals(examineVo.getAuditStatus())) {
            teacherService.setTeacherTag(lessonGroup.getTeacherId(), TeacherTagEnum.VIDEO);
        }

        //推送
        String status = examineVo.getAuditStatus();
        Map<Long, String> receivers = new HashMap<>();
        SysUser teacher = sysUserFeignService.queryUserById(lessonGroup.getTeacherId());
        receivers.put(lessonGroup.getTeacherId(), teacher.getPhone());
        if (status.equals("PASS")) {
            try {
                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.VIDEO_SHEET_AUTH_PASS,
                        receivers, null, 0, null, ClientEnum.TEACHER.getCode(), lessonGroup.getLessonName());
            } catch (Exception e) {
                log.warn("视频课审核失败，{}", e.getMessage());
            }
        } else {
            try {
                String remark = "无";
                if (!StringUtils.isEmpty(examineVo.getRemarks())) {
                    remark = examineVo.getRemarks();
                }
                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.VIDEO_SHEET_AUTH_UNPASS,
                        receivers, null, 0, null, ClientEnum.TEACHER.getCode(), lessonGroup.getLessonName(), remark);
            } catch (Exception e) {
                log.warn("视频课审核失败，{}", e.getMessage());
            }
        }
    }

    @Override
    public void updateShelves(VideoLessonShelvesVo shelvesVo) {
        //改主表
        videoLessonGroupDao.updateShelves(shelvesVo);
        if(shelvesVo.getShelvesFlag() == 0 && ClientEnum.SYSTEM.equals(shelvesVo.getClientType())){
            //发推送
            sendOutSaleMessage(shelvesVo);
        }
    }

    private void sendOutSaleMessage(VideoLessonShelvesVo shelvesVo) {
        VideoLessonGroupVo detail = detail(shelvesVo.getId());
        // 发送课程下架通知
        try {
            SysUser user = sysUserFeignService.queryUserById(detail.getTeacherId());
            Map<Long, String> receivers = new HashMap<>();
            receivers.put(user.getId(), user.getPhone());
            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.VIDEO_COURSE_OUT_SALE_REASON,
                    receivers, null, 0, null, ClientEnum.TEACHER.getCode(),
                    detail.getLessonName(), shelvesVo.getShelvesReason());
        } catch (Exception e) {
            log.warn("视频课下架推送发送失败，{}", e.getMessage());
        }
    }

    /**
     * @Description: 删除视频课
     * @Author: cy
     * @Date: 2022/3/31
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteGroup(Long id) {
        videoLessonGroupDao.deleteById(id);
        videoLessonGroupDetailDao.deleteByGroupId(id);
    }

    /**
     * @Description: 新增视频课组&视频课
     * @Author: cy
     * @Date: 2022/4/1
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(VideoLessonVo lessonVo, SysUser sysUser) {
        VideoLessonGroup lessonGroup = lessonVo.getLessonGroup();
        List<VideoLessonGroupDetail> lessonList = lessonVo.getLessonList();
        lessonGroup.setLessonCount(lessonList.size());

        //校验声部
        Long subjectId = Long.valueOf(lessonGroup.getLessonSubject());
        List<Subject> subjectList = teacherDao.querySubject(sysUser.getId());
        List<Long> longList = subjectList.stream().map(Subject::getId).collect(Collectors.toList());
        if (!longList.contains(subjectId)) {
            throw new BizException("该声部无法选择");
        }
        
        Date date = new Date();

        //添加组
        lessonGroup.setTeacherId(sysUser.getId());
        lessonGroup.setAuditVersion(YesOrNoEnum.NO);
        videoLessonGroupDao.insert(lessonGroup);

        for (VideoLessonGroupDetail detail : lessonList) {
            detail.setVideoLessonGroupId(lessonGroup.getId());
            detail.setTeacherId(sysUser.getId());
        }

        //添加课程
        videoLessonGroupDetailDao.insertVideoLesson(lessonList);

        //刷新统计
        VideoLessonGroupUpVo groupUpVo = new VideoLessonGroupUpVo();
        groupUpVo.setId(lessonGroup.getId());
        videoLessonGroupDao.updateGroup(groupUpVo);

        //记录video_lesson_auth_record
        /*VideoLessonAuthRecord record = new VideoLessonAuthRecord();
        record.setVideoGroupId(lessonGroup.getId());
        record.setGroupId(lessonGroup.getId());
        record.setAuditStatus(AuthStatusEnum.DOING.getCode());
        record.setAuthType(AuthTypeEnum.ADD);
        recordDao.insert(record);*/
        
        VideoLessonGroupLog  videoLessonGroupLog = new VideoLessonGroupLog();
        
        try {
        	org.springframework.beans.BeanUtils.copyProperties(lessonGroup, videoLessonGroupLog);
		} catch (Exception e) {
			throw new BizException("属性复制失败");
		}
        videoLessonGroupLog.setId(null);
        videoLessonGroupLog.setVideoLessonGroupId(lessonGroup.getId());
        videoLessonGroupLog.setCreateTime(date);
        videoLessonGroupLog.setUpdateTime(date);
        videoLessonGroupLog.setModifierId(sysUser.getId());
        videoLessonGroupLog.setVideoDetailJson(JsonUtil.toJSONString(lessonList));
        videoLessonGroupLog.setVersion(videoLessonGroupLogService.queryMaxVersion(lessonGroup.getId()) + 1);
        
        videoLessonGroupLogService.insert(videoLessonGroupLog);
    }

    /**
     * @Description: 学员详情-查询视频课列表
     * @Author: cy
     * @Date: 2022/4/2
     */
    @Override
    public IPage<VideoLessonStudentDetailVo> selectStudentPage(IPage<VideoLessonStudentDetailVo> page, VideoLessonSearch search) {
        return page.setRecords(baseMapper.selectStudentPage(page, search));
    }

    /**
     * @Description: 老师详情-查询视频课列表
     * @Author: cy
     * @Date: 2022/4/6
     */
    @Override
    public IPage<VideoLessonTeacherVo> selectTeacherPage(IPage<VideoLessonTeacherVo> page, VideoLessonSearch search) {
        return page.setRecords(baseMapper.selectTeacherPage(page, search));
    }

    /**
     * @Description: 老师详情-视频课详情-查询购买学员列表
     * @Author: cy
     * @Date: 2022/4/6
     */
    @Override
    public IPage<VideoLessonPurchaseVo> selectPurchaseStudent(IPage<VideoLessonPurchaseVo> page, VideoLessonSearch search) {
        return page.setRecords(baseMapper.selectPurchaseStudent(page, search));
    }

    /**
     * @Description: 根据组id查询视频课&视频课组
     * @Author: cy
     * @Date: 2022/4/7
     */
    @Override
    public VideoLessonStudentVo selectVideoLesson(Long groupId) {
        VideoLessonStudentVo lessonStudentVo = new VideoLessonStudentVo();

        VideoLessonGroupVo videoLessonGroupVo = detail(groupId);
        if (videoLessonGroupVo == null) return lessonStudentVo;

        Teacher teacher = teacherService.getById(videoLessonGroupVo.getTeacherId());
        if (teacher != null) {
            lessonStudentVo.setTeacherFlag(teacher.getTeacherFlag());
            lessonStudentVo.setDegreeFlag(teacher.getDegreeFlag());
        }

        lessonStudentVo.setLessonGroup(videoLessonGroupVo);
        VideoLessonSearch search = new VideoLessonSearch();
        search.setVideoLessonGroupId(groupId);
        lessonStudentVo.setDetailList(videoLessonGroupDetailDao.selectPage(null, search));
        return lessonStudentVo;
    }

    private VideoLessonGroupVo detail(Long groupId) {
        VideoLessonGroupSearch query = new VideoLessonGroupSearch();
        query.setGroupId(groupId);
        List<VideoLessonGroupVo> lessonGroup = videoLessonGroupDao.selectPage(null, query);
        if (CollectionUtils.isEmpty(lessonGroup)) {
            return null;
        }
        return lessonGroup.get(0);
    }

    /**
     * @Description: 修改视频课组&视频课
     * @Author: cy
     * @Date: 2022/4/7
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(VideoLessonVo lessonVo, SysUser sysUser) {
        VideoLessonGroup lessonGroup = lessonVo.getLessonGroup();
        List<VideoLessonGroupDetail> lessonList = lessonVo.getLessonList();
        lessonGroup.setLessonCount(lessonList.size());
        lessonGroup.setTeacherId(sysUser.getId());
        //判断是否有正在审核中
        QueryWrapper<VideoLessonAuthRecord> wrapper = new QueryWrapper<VideoLessonAuthRecord>();
        wrapper.eq("video_group_id_", lessonGroup.getId()).eq("audit_status_", AuthStatusEnum.DOING.getCode());
        
        List<VideoLessonAuthRecord> videoLessonAuthRecords = recordDao.selectList(wrapper);
        if(CollectionUtils.isNotEmpty(videoLessonAuthRecords)){
        	throw new BizException("正在审核中，无法修改");
        }

        //校验声部
        Long subjectId = Long.valueOf(lessonGroup.getLessonSubject());
        List<Subject> subjectList = teacherDao.querySubject(sysUser.getId());
        List<Long> longList = subjectList.stream().map(Subject::getId).collect(Collectors.toList());
        if (!longList.contains(subjectId)) {
            throw new BizException("该声部无法选择");
        }
        
        Date date = new Date();

        /*//创建新的评审记录
        VideoLessonAuthRecord authRecord = new VideoLessonAuthRecord();
        authRecord.setGroupId(lessonGroup.getId());
        authRecord.setAuditStatus(AuthStatusEnum.DOING.getCode());
        authRecord.setAuthType(AuthTypeEnum.MODIFY);
        authRecord.setVideoGroupId(lessonGroup.getId());
        //提交审核
        recordDao.insert(authRecord);*/
        
        videoLessonGroupDetailDao.deleteByGroupId(lessonGroup.getId());
		if (lessonList != null && lessonList.size() > 0) {
			for (VideoLessonGroupDetail detail : lessonList) {
				detail.setVideoLessonGroupId(lessonGroup.getId());
				detail.setTeacherId(sysUser.getId());
				detail.setUpdateBy(sysUser.getId());
			}
			// 添加课程
			videoLessonGroupDetailDao.insertVideoLesson(lessonList);
		}
        
        VideoLessonGroupLog  videoLessonGroupLog = new VideoLessonGroupLog();
        
        try {
        	org.springframework.beans.BeanUtils.copyProperties(lessonGroup, videoLessonGroupLog);
		} catch (Exception e) {
			throw new BizException("属性复制失败");
		}
        videoLessonGroupLog.setId(null);
        videoLessonGroupLog.setVideoLessonGroupId(lessonGroup.getId());
        videoLessonGroupLog.setCreateTime(date);
        videoLessonGroupLog.setUpdateTime(date);
        videoLessonGroupLog.setModifierId(sysUser.getId());
        videoLessonGroupLog.setVideoDetailJson(JsonUtil.toJSONString(lessonList));
        videoLessonGroupLog.setVersion(videoLessonGroupLogService.queryMaxVersion(lessonGroup.getId()) + 1);
        
        videoLessonGroupLogService.insert(videoLessonGroupLog);

        //修改课程组记录
        lessonGroup.setAuditVersion(YesOrNoEnum.NO);
        lessonGroup.setAuditStatus(AuthStatusEnum.DOING);
        lessonGroup.setUpdateTime(date);
        videoLessonGroupDao.updateById(lessonGroup);

        //刷新统计
        VideoLessonGroupUpVo groupUpVo = new VideoLessonGroupUpVo();
        groupUpVo.setId(lessonGroup.getId());
        videoLessonGroupDao.updateGroup(groupUpVo);
    }

    /**
     * @Description: 查询视频课组
     * @Author: cy
     * @Date: 2022/4/11
     */
    @Override
    public IPage<LessonGroupVo> selectLessonGroup(IPage<LessonGroupVo> page, VideoLessonGroupSearch query) {
        query.setAuditStatus(AuthStatusEnum.PASS.getCode());
        query.setShelvesFlag(1);
        return page.setRecords(baseMapper.selectLessonGroup(page, query));
    }

    /**
     * @Description: 查询所有视频课组
     * @Author: cy
     * @Date: 2022/4/20
     */
    @Override
    public IPage<VideoLessonAuthGroup> queryGroupList(IPage<VideoLessonAuthGroup> page, VideoGroupSearch query) {
        if(org.apache.commons.lang3.StringUtils.isNotBlank(query.getAuditStatus())){
        	
        	if(query.getAuditStatus().equals(AuthStatusEnum.DOING.getCode())){
            	query.setShelvesFlag(null);
        	}else if(query.getAuditStatus().equals(AuthStatusEnum.UNPASS.getCode())){
            	query.setShelvesFlag(null);
        	}else{
        		if(query.getAuditStatus().equals(AuthStatusEnum.OUT_SALE.getCode())){
                    query.setAuditStatus(AuthStatusEnum.PASS.getCode());
                    query.setShelvesFlag(0);
                }else if(query.getAuditStatus().equals(AuthStatusEnum.PASS.getCode())){
                    query.setShelvesFlag(1);
                }
        	}
        	
        }
        return page.setRecords(baseMapper.queryGroupList(page, query));
    }

    @Override
    public IPage<VideoLessonAuthGroup> queryGroupHistoryList(IPage<VideoLessonAuthGroup> page, VideoGroupSearch query) {
    	List<VideoLessonAuthGroup> list = baseMapper.queryGroupHistoryList(page, query);
    	for(VideoLessonAuthGroup g : list){
    		g.setVideoList(JsonUtil.parseArray(g.getVideoDetailJson(), VideoLessonGroupDetail.class));
    	}
        return page.setRecords(list);
    }

    @Override
    public VideoLessonAuthGroup authGroupDetil(Long videoGroupId) {
        VideoLessonAuthGroup videoLessonAuthGroup = baseMapper.authGroupDetil(videoGroupId);
        
        List<VideoLessonGroupDetail> details = videoLessonGroupDetailDao.queryByVideoLessonGroupId(videoGroupId);
        videoLessonAuthGroup.setVideoList(details);

        //查询上一次的提交
        VideoLessonGroupLog lastDetil = videoLessonGroupLogService.queryByVideoLessonGroupId(videoGroupId, videoLessonAuthGroup.getVersion());
        videoLessonAuthGroup.setLastVideoLessonGroupLog(lastDetil);
        
        if(lastDetil != null){
        	lastDetil.setVideoList(JsonUtil.parseArray(lastDetil.getVideoDetailJson(), VideoLessonGroupDetail.class));
        }
        
        return videoLessonAuthGroup;
    }

    /**
     * @Description: 学生端-我的-我的课程-购买的视频课组
     * @Author: cy
     * @Date: 2022/4/20
     */
    @Override
    public IPage<LessonGroupVo> selectLessonGroupById(IPage<LessonGroupVo> page, VideoLessonGroupSearch query) {

        return page.setRecords(baseMapper.queryMyLessonGroup(page, query));
    }

    /**
     * @Description: 首页-视频课统计
     * @Author: cy
     * @Date: 2022/5/7
     */
    public CountVideoGroupVo countVideoGroup() {
        CountVideoGroupVo countVideoGroup = baseMapper.countVideoGroup();
        countVideoGroup.setVideoLessonList(baseMapper.selectVideoLesson());
        return countVideoGroup;
    }

    @Override
    public ShareProfitVo shareVideoCourseProfit(SysUser sysUser, Long videoGroupId) {
        VideoLessonStudentVo videoLessonStudentVo = selectVideoLesson(videoGroupId);

        String teacherVideoGroupShareProfitUrl= sysConfigService.findConfigValue(SysConfigConstant.TEACHER_VIDEO_GROUP_SHARE_PROFIT_URL);

        ShareProfitVo result = new ShareProfitVo();
        result.setType("VIDEO");
        result.setTeacherId(sysUser.getId());
        result.setVideoGroup(videoLessonStudentVo);
        result.setUrl(MessageFormatter.arrayFormat(teacherVideoGroupShareProfitUrl, videoGroupId, sysUser.getId()));
        result.setName(sysUser.getUsername());
        result.setAvatar(sysUser.getAvatar());
        return result;

    }


}