From 36f828ee9f83c283dc1b22f37592409480100ae2 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Tue, 8 Oct 2024 10:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A9=BA=E5=80=BC=E8=BF=87?= =?UTF-8?q?=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/mq/Consumer/CommonConsumer.java | 101 ++++++++++-------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/peanut/modules/mq/Consumer/CommonConsumer.java b/src/main/java/com/peanut/modules/mq/Consumer/CommonConsumer.java index 3751d430..7d235a4d 100644 --- a/src/main/java/com/peanut/modules/mq/Consumer/CommonConsumer.java +++ b/src/main/java/com/peanut/modules/mq/Consumer/CommonConsumer.java @@ -1,5 +1,6 @@ package com.peanut.modules.mq.Consumer; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.peanut.common.utils.DateUtils; import com.peanut.common.utils.R; @@ -9,6 +10,7 @@ import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.ClassEntityService; import com.peanut.modules.common.service.ClassExamService; import com.peanut.modules.common.service.CouponHistoryService; +import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,6 +21,7 @@ import java.util.Map; //通用延迟队列 @Component +@Slf4j public class CommonConsumer { @Autowired @@ -42,60 +45,66 @@ public class CommonConsumer { @RabbitListener(queues = DelayQueueConfig.COMMON_QUEUE) public void commonConsumer(String typeAndParam) { - //参数为 业务模块 + , + 参数 - String[] typeAndParams = typeAndParam.split(","); - //考试周天数,根据设置的天数将班级状态从进行中设置成考试中 - if ("examDays".equals(typeAndParams[0])){ - ClassEntity classEntity = classEntityDao.selectById(typeAndParams[1]); - if (classEntity!=null&&!"3".equals(classEntity.getState())){ - classEntity.setState("3"); - classEntityDao.updateById(classEntity); + try { + //参数为 业务模块 + , + 参数 + String[] typeAndParams = typeAndParam.split(","); + //考试周天数,根据设置的天数将班级状态从进行中设置成考试中 + if ("examDays".equals(typeAndParams[0])){ + ClassEntity classEntity = classEntityDao.selectById(typeAndParams[1]); + if (classEntity!=null&&!"3".equals(classEntity.getState())){ + classEntity.setState("3"); + classEntityDao.updateById(classEntity); + } } - } - //在考试结束时检查是否提交,未完成者自动提交 - if ("examSubmit".equals(typeAndParams[0])){ - ClassExamUser classExamUser = classExamUserDao.selectById(typeAndParams[1]); - if (classExamUser!=null&&classExamUser.getScoreSuccess()==0){ - Map map = new HashMap<>(); - map.put("id",classExamUser.getId()); - classexamService.submitExamPaper(map); + //在考试结束时检查是否提交,未完成者自动提交 + if ("examSubmit".equals(typeAndParams[0])){ + ClassExamUser classExamUser = classExamUserDao.selectById(typeAndParams[1]); + if (classExamUser!=null&&classExamUser.getScoreSuccess()==0){ + Map map = new HashMap<>(); + map.put("id",classExamUser.getId()); + classexamService.submitExamPaper(map); + } } - } - //加班后24小时未买课踢出去 - if ("joinClass".equals(typeAndParams[0])){ - ClassEntity classEntity = classEntityDao.selectById(typeAndParams[1]); - MyUserEntity user = myUserDao.selectById(typeAndParams[2]); - if ("0".equals(user.getVip())||"3".equals(user.getVip())){ - //不是vip查询每门课是否购买 - List courses = classCourseDao.selectList(new LambdaQueryWrapper() - .eq(ClassCourse::getModelId,classEntity.getModelId())); - for (ClassCourse classCourse:courses){ - List catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper() - .eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId())); - for (CourseCatalogueEntity catalog:catalogues){ - int ucbCount = userCourseBuyDao.selectCount(new LambdaQueryWrapper() - .eq(UserCourseBuyEntity::getUserId,user.getId()) - .eq(UserCourseBuyEntity::getCatalogueId,catalog.getId())); - if (ucbCount == 0){ - Map map = new HashMap<>(); - map.put("classId",classEntity.getId()); - map.put("userId",user.getId()); - classEntityService.quitClass(map); + //加班后24小时未买课踢出去 + if ("joinClass".equals(typeAndParams[0])){ + ClassEntity classEntity = classEntityDao.selectById(typeAndParams[1]); + if (classEntity!=null&&"0".equals(classEntity.getState())){ + MyUserEntity user = myUserDao.selectById(typeAndParams[2]); + if (user!=null){ + if ("0".equals(user.getVip())||"3".equals(user.getVip())){ + //不是vip查询每门课是否购买 + List courses = classCourseDao.selectList(new LambdaQueryWrapper() + .eq(ClassCourse::getModelId,classEntity.getModelId())); + for (ClassCourse classCourse:courses){ + List catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper() + .eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId())); + for (CourseCatalogueEntity catalog:catalogues){ + int ucbCount = userCourseBuyDao.selectCount(new LambdaQueryWrapper() + .eq(UserCourseBuyEntity::getUserId,user.getId()) + .eq(UserCourseBuyEntity::getCatalogueId,catalog.getId())); + if (ucbCount == 0){ + Map map = new HashMap<>(); + map.put("classId",classEntity.getId()); + map.put("userId",user.getId()); + classEntityService.quitClass(map); + } + } + } } } } } - } - //优惠卷过期 - if ("couponExpire".equals(typeAndParams[0])){ - CouponHistory couponHistory = couponHistoryService.getById(typeAndParams[1]); - if (couponHistory != null&&couponHistory.getStatus()==0) { - couponHistory.setStatus(2); - couponHistoryService.updateById(couponHistory); + //优惠卷过期 + if ("couponExpire".equals(typeAndParams[0])){ + CouponHistory couponHistory = couponHistoryService.getById(typeAndParams[1]); + if (couponHistory != null&&couponHistory.getStatus()==0) { + couponHistory.setStatus(2); + couponHistoryService.updateById(couponHistory); + } } + }catch (Exception e) { + log.error("mq通用队列消费异常",e.getMessage()+"-"+typeAndParam); } - - } }