xiangpei
2024-07-11 5073a245f53fd5ca936e779be8c6b9b19d42f67d
src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java
@@ -1,6 +1,7 @@
package com.ycl.jxkg.service.impl;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -78,13 +79,12 @@
    @Override
    public Result update(MeetForm form) {
        Meet entity = baseMapper.selectById(form.getId());
        // 为空抛IllegalArgumentException,做全局异常处理
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        // 如果修改成功发送mq消息
        if (baseMapper.updateById(entity) > 0) {
            this.sendMQ(entity, entity.getUpdateVersion() + 1);
            this.sendMQ(entity, entity.getUpdateVersion());
        }
        return Result.ok("修改成功");
    }
@@ -152,10 +152,10 @@
        Meet entity = baseMapper.selectById(form.getId());
        // 为空抛IllegalArgumentException,做全局异常处理
        Assert.notNull(entity, "记录不存在");
        BeanUtils.copyProperties(form, entity);
        // 不使用updateById这种方式,避免乐观锁加一。
        new LambdaUpdateChainWrapper<>(meetMapper)
                .eq(Meet::getId, entity.getId())
                .set(Meet::getStatus,form.getStatus())
                .update();
        return Result.ok();
    }
@@ -170,15 +170,26 @@
        Meet vo = baseMapper.getById(id);
        Assert.notNull(vo, "记录不存在");
        if(vo.getStatus().equals(MeetStatusEnum.Starting.getCode())){
            //增加学生上课记录
            Integer userId = webContext.getCurrentUser().getId();
            //验证有没有重复进入(重复进入会导致上课次数增多)
            QueryWrapper<MeetStudent> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("meet_id",id);
            queryWrapper.eq("student_id",userId);
            queryWrapper.eq("version",vo.getUpdateVersion());
            MeetStudent one = meetStudentMapper.selectOne(queryWrapper);
            if(one != null){
                return Result.ok();
            }
            //增加学生上课记录
            MeetStudent meetStudent = new MeetStudent();
            meetStudent.setMeetId(id);
            meetStudent.setStudentId(userId);
            meetStudent.setCreateTime(new Date());
            meetStudent.setStartTime(vo.getStartTime());
            meetStudent.setVersion(vo.getUpdateVersion());
            meetStudent.setMeetName(vo.getMeetName());
            //TODO:暂时处理,后期考虑jitsiApi
            meetStudent.setDuringTime((vo.getEndTime().getTime()-new Date().getTime())/1000);
            meetStudent.setDuringTime(0L);
            meetStudentMapper.insert(meetStudent);
            //学生学习档案更新
            StudyRecord studyRecord = studyRecordMapper.getByStudentId(userId);