From 8546b3d285af4235a0ef615a0c6e89486ae2c806 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期四, 17 十月 2024 21:01:37 +0800 Subject: [PATCH] 达梦不支持value改为values --- src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java | 124 +++++++++++++++++++++++++++++++++++------ 1 files changed, 106 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java index 1dcefdb..548338d 100644 --- a/src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java +++ b/src/main/java/com/ycl/jxkg/service/impl/MeetServiceImpl.java @@ -1,29 +1,37 @@ package com.ycl.jxkg.service.impl; -import com.alibaba.fastjson2.JSONArray; +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; +import com.ycl.jxkg.base.Result; +import com.ycl.jxkg.base.SystemCode; import com.ycl.jxkg.context.WebContext; import com.ycl.jxkg.domain.entity.Meet; +import com.ycl.jxkg.domain.entity.MeetStudent; +import com.ycl.jxkg.domain.entity.StudyRecord; +import com.ycl.jxkg.domain.form.MeetForm; +import com.ycl.jxkg.domain.query.MeetQuery; +import com.ycl.jxkg.domain.vo.MeetVO; +import com.ycl.jxkg.domain.vo.StudentSimpleVO; import com.ycl.jxkg.enums.MeetStatusEnum; import com.ycl.jxkg.mapper.ClassesUserMapper; import com.ycl.jxkg.mapper.MeetMapper; +import com.ycl.jxkg.mapper.MeetStudentMapper; +import com.ycl.jxkg.mapper.StudyRecordMapper; +import com.ycl.jxkg.rabbitmq.msg.MeetStatusMsg; +import com.ycl.jxkg.rabbitmq.product.Producer; import com.ycl.jxkg.service.MeetService; -import com.ycl.jxkg.base.Result; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ycl.jxkg.domain.form.MeetForm; -import com.ycl.jxkg.domain.vo.MeetVO; -import com.ycl.jxkg.domain.query.MeetQuery; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.User; -import org.springframework.stereotype.Service; -import lombok.RequiredArgsConstructor; +import com.ycl.jxkg.utils.DateTimeUtil; import com.ycl.jxkg.utils.PageUtil; +import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; - -import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -43,6 +51,9 @@ private WebContext webContext; @Autowired private ClassesUserMapper classesUserMapper; + private final Producer producer; + private final MeetStudentMapper meetStudentMapper; + private final StudyRecordMapper studyRecordMapper; /** * 娣诲姞 * @param form @@ -53,7 +64,11 @@ Meet entity = MeetForm.getEntityByForm(form, null); entity.setStatus(MeetStatusEnum.Wait.getCode()); entity.setCreateUser(webContext.getCurrentUser().getId()); - baseMapper.insert(entity); + // 璁剧疆涔愯閿佺増鏈� + entity.setUpdateVersion(0); + if (baseMapper.insert(entity) > 0) { + this.sendMQ(entity, 0); + } return Result.ok("娣诲姞鎴愬姛"); } @@ -65,11 +80,13 @@ @Override public Result update(MeetForm form) { Meet entity = baseMapper.selectById(form.getId()); - // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); BeanUtils.copyProperties(form, entity); - baseMapper.updateById(entity); + // 濡傛灉淇敼鎴愬姛鍙戦�乵q娑堟伅 + if (baseMapper.updateById(entity) > 0) { + this.sendMQ(entity, entity.getUpdateVersion()); + } return Result.ok("淇敼鎴愬姛"); } @@ -131,6 +148,19 @@ return Result.ok().data(page.getRecords()).total(page.getTotal()); } + @Override + public Result start(MeetForm form) { + Meet entity = baseMapper.selectById(form.getId()); + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + // 涓嶄娇鐢╱pdateById杩欑鏂瑰紡锛岄伩鍏嶄箰瑙傞攣鍔犱竴銆� + new LambdaUpdateChainWrapper<>(meetMapper) + .eq(Meet::getId, entity.getId()) + .set(Meet::getStatus,form.getStatus()) + .update(); + return Result.ok(); + } + /** * 鏍规嵁id鏌ユ壘 * @param id @@ -138,9 +168,46 @@ */ @Override public Result detail(Integer id) { - MeetVO vo = baseMapper.getById(id); + Meet vo = baseMapper.getById(id); Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); - return Result.ok().data(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(0L); + meetStudentMapper.insert(meetStudent); + //瀛︾敓瀛︿範妗f鏇存柊 + StudyRecord studyRecord = studyRecordMapper.getByStudentId(userId); + if(studyRecord ==null){ + StudyRecord record = new StudyRecord(); + record.setMeetCount(0); + record.setStudyTime(0L); + record.setStudentId(userId); + studyRecordMapper.insert(record); + }else { + studyRecord.setMeetCount(studyRecord.getMeetCount()+1); + studyRecordMapper.updateById(studyRecord); + } + return Result.ok(); + }else { + return Result.fail(SystemCode.InnerError.getCode(),"鎴块棿灏氭湭寮�濮嬫垨宸茬粨鏉�"); + } } /** @@ -155,4 +222,25 @@ .collect(Collectors.toList()); return Result.ok().data(vos); } + + @Override + public Result getStudentList(Integer meetId, String keyword) { + List<StudentSimpleVO> studentList = baseMapper.getStudentList(meetId, keyword); + return Result.ok().data(studentList); + } + + /** + * 鍙戦�乵q娑堟伅 + * + * @param entity 鑰冭瘯瀹炰綋绫� + * @param version 涔愯閿佺増鏈� + */ + public void sendMQ(Meet entity, Integer version) { + MeetStatusMsg finishedMsg = new MeetStatusMsg(); + finishedMsg.setVersion(version); + finishedMsg.setMeetId(entity.getId()); + finishedMsg.setMeetStatus(MeetStatusEnum.End.getCode()); + producer.meetMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date())); + } + } -- Gitblit v1.8.0