111 lines
5.1 KiB
Java
111 lines
5.1 KiB
Java
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;
|
|
import com.peanut.config.DelayQueueConfig;
|
|
import com.peanut.modules.common.dao.*;
|
|
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;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
//通用延迟队列
|
|
@Component
|
|
@Slf4j
|
|
public class CommonConsumer {
|
|
|
|
@Autowired
|
|
private ClassEntityDao classEntityDao;
|
|
@Autowired
|
|
private ClassExamUserDao classExamUserDao;
|
|
@Autowired
|
|
private ClassExamService classexamService;
|
|
@Autowired
|
|
private MyUserDao myUserDao;
|
|
@Autowired
|
|
private ClassCourseDao classCourseDao;
|
|
@Autowired
|
|
private UserCourseBuyDao userCourseBuyDao;
|
|
@Autowired
|
|
private ClassEntityService classEntityService;
|
|
@Autowired
|
|
private CouponHistoryService couponHistoryService;
|
|
@Autowired
|
|
private CourseCatalogueDao courseCatalogueDao;
|
|
|
|
@RabbitListener(queues = DelayQueueConfig.COMMON_QUEUE)
|
|
public void commonConsumer(String typeAndParam) {
|
|
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<String,Object> map = new HashMap<>();
|
|
map.put("id",classExamUser.getId());
|
|
classexamService.submitExamPaper(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<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
|
|
.eq(ClassCourse::getModelId,classEntity.getModelId()));
|
|
for (ClassCourse classCourse:courses){
|
|
List<CourseCatalogueEntity> catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>()
|
|
.eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId()));
|
|
for (CourseCatalogueEntity catalog:catalogues){
|
|
int ucbCount = userCourseBuyDao.selectCount(new LambdaQueryWrapper<UserCourseBuyEntity>()
|
|
.eq(UserCourseBuyEntity::getUserId,user.getId())
|
|
.eq(UserCourseBuyEntity::getCatalogueId,catalog.getId()));
|
|
if (ucbCount == 0){
|
|
Map<String,Object> 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);
|
|
}
|
|
}
|
|
}catch (Exception e) {
|
|
log.error("mq通用队列消费异常",e.getMessage()+"-"+typeAndParam);
|
|
}
|
|
}
|
|
|
|
}
|