定时任务超v过期
课程过期
This commit is contained in:
@@ -3,6 +3,7 @@ package com.peanut.config;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.*;
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -43,19 +44,24 @@ public class DelayQueueConfig {
|
|||||||
public static final String DEAD_LETTER_QUEUE = "delay.queue.deadLetter.queue";
|
public static final String DEAD_LETTER_QUEUE = "delay.queue.deadLetter.queue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单待支付交换机
|
* 订单待支付+订单取消
|
||||||
*/
|
*/
|
||||||
public static final String ORDER_TO_BE_PAY_EXCHANGE = "order_to_be_pay_exchange";
|
public static final String ORDER_TO_BE_PAY_EXCHANGE = "order_to_be_pay_exchange";
|
||||||
public static final String ORDER_TO_BE_PAY_ROUTING_KEY = "order_to_be_pay_routingKey";
|
public static final String ORDER_TO_BE_PAY_ROUTING_KEY = "order_to_be_pay_routingKey";
|
||||||
public static final String ORDER_TO_BE_PAY_QUEUE = "order_to_be_pay_queue";
|
public static final String ORDER_TO_BE_PAY_QUEUE = "order_to_be_pay_queue";
|
||||||
/**
|
|
||||||
* 订单取消队列
|
|
||||||
*/
|
|
||||||
public static final String ORDER_CANCEL_DEAD_LETTER_EXCHANGE = "order_cancel_dead_letter_exchange";
|
public static final String ORDER_CANCEL_DEAD_LETTER_EXCHANGE = "order_cancel_dead_letter_exchange";
|
||||||
public static final String ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY = "order_cancel_dead_letter_routingKey";
|
public static final String ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY = "order_cancel_dead_letter_routingKey";
|
||||||
public static final String ORDER_CANCEL_DEAD_LETTER_QUEUE = "order_cancel_dead_letter_queue";
|
public static final String ORDER_CANCEL_DEAD_LETTER_QUEUE = "order_cancel_dead_letter_queue";
|
||||||
|
|
||||||
|
|
||||||
|
//超V过期队列+死信
|
||||||
|
public static final String USERVIP_QUEUE = "uservip_queue";
|
||||||
|
public static final String USERVIP_EXCHANGE = "uservip_exchange";
|
||||||
|
public static final String USERVIP_ROUTING_KEY = "uservip_routingKey";
|
||||||
|
public static final String USERVIP_DEAD_LETTER_QUEUE = "uservip_dead_letter_queue";
|
||||||
|
public static final String USERVIP_DEAD_LETTER_EXCHANGE = "uservip_dead_letter_exchange";
|
||||||
|
public static final String USERVIP_DEAD_LETTER_ROUTING_KEY = "uservip_dead_letter_routingKey";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 快递队列
|
* 快递队列
|
||||||
*/
|
*/
|
||||||
@@ -64,55 +70,6 @@ public class DelayQueueConfig {
|
|||||||
public static final String FMS_ROUTING_KEY = "fms.routing.key";
|
public static final String FMS_ROUTING_KEY = "fms.routing.key";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明 死信交换机
|
|
||||||
*
|
|
||||||
* @return deadLetterExchange
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DirectExchange deadLetterExchange() {
|
|
||||||
return new DirectExchange(DEAD_LETTER_EXCHANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明 订单交换机
|
|
||||||
*
|
|
||||||
* @return deadLetterExchange
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Exchange orderEventExchange() {
|
|
||||||
return new TopicExchange(ORDER_EVENT_EXCHANGE, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Queue orderDelayQueue() {
|
|
||||||
|
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
|
||||||
|
|
||||||
// 队列绑定DLX参数(关键一步)
|
|
||||||
map.put("x-dead-letter-exchange", ORDER_EVENT_EXCHANGE);
|
|
||||||
// 队列绑定 死信RoutingKey参数
|
|
||||||
map.put("x-dead-letter-routing-key", ORDER_QUEUE_ROUTING_KEY);
|
|
||||||
|
|
||||||
map.put("x-message-ttl", 60000);
|
|
||||||
|
|
||||||
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false, map);
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Queue orderReleaseOrderQueue() {
|
|
||||||
|
|
||||||
Queue queue = new Queue(ORDER_RELEASE_QUEUE, true, false, false);
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 声明 死信队列 用于接收死信消息
|
* 声明 死信队列 用于接收死信消息
|
||||||
*
|
*
|
||||||
@@ -123,6 +80,16 @@ public class DelayQueueConfig {
|
|||||||
return new Queue(DEAD_LETTER_QUEUE);
|
return new Queue(DEAD_LETTER_QUEUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明 死信交换机
|
||||||
|
*
|
||||||
|
* @return deadLetterExchange
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public DirectExchange deadLetterExchange() {
|
||||||
|
return new DirectExchange(DEAD_LETTER_EXCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 死信队列 绑定到死信交换机上
|
* 将 死信队列 绑定到死信交换机上
|
||||||
*
|
*
|
||||||
@@ -136,16 +103,6 @@ public class DelayQueueConfig {
|
|||||||
.with(DEAD_LETTER_QUEUE_ROUTING_KEY);
|
.with(DEAD_LETTER_QUEUE_ROUTING_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明 延时交换机
|
|
||||||
*
|
|
||||||
* @return delayExchange
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DirectExchange directExchange() {
|
|
||||||
return new DirectExchange(DELAY_EXCHANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 延时队列 绑定参数
|
* 将 延时队列 绑定参数
|
||||||
*
|
*
|
||||||
@@ -163,6 +120,16 @@ public class DelayQueueConfig {
|
|||||||
return QueueBuilder.durable(DELAY_QUEUE).withArguments(maps).build();
|
return QueueBuilder.durable(DELAY_QUEUE).withArguments(maps).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明 延时交换机
|
||||||
|
*
|
||||||
|
* @return delayExchange
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public DirectExchange directExchange() {
|
||||||
|
return new DirectExchange(DELAY_EXCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 延时队列 绑定到延时交换机上面
|
* 将 延时队列 绑定到延时交换机上面
|
||||||
*
|
*
|
||||||
@@ -176,6 +143,40 @@ public class DelayQueueConfig {
|
|||||||
.with(DELAY_QUEUE_ROUTING_KEY);
|
.with(DELAY_QUEUE_ROUTING_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue orderDelayQueue() {
|
||||||
|
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
// 队列绑定DLX参数(关键一步)
|
||||||
|
map.put("x-dead-letter-exchange", ORDER_EVENT_EXCHANGE);
|
||||||
|
// 队列绑定 死信RoutingKey参数
|
||||||
|
map.put("x-dead-letter-routing-key", ORDER_QUEUE_ROUTING_KEY);
|
||||||
|
|
||||||
|
map.put("x-message-ttl", 60000);
|
||||||
|
|
||||||
|
Queue queue = new Queue(ORDER_DELAY_QUEUE, true, false, false, map);
|
||||||
|
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue orderReleaseOrderQueue() {
|
||||||
|
|
||||||
|
Queue queue = new Queue(ORDER_RELEASE_QUEUE, true, false, false);
|
||||||
|
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明 订单交换机
|
||||||
|
*
|
||||||
|
* @return deadLetterExchange
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Exchange orderEventExchange() {
|
||||||
|
return new TopicExchange(ORDER_EVENT_EXCHANGE, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Binding orderCreateOrderBingding() {
|
public Binding orderCreateOrderBingding() {
|
||||||
@@ -187,6 +188,80 @@ public class DelayQueueConfig {
|
|||||||
return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE, ORDER_EVENT_EXCHANGE, ORDER_QUEUE_ROUTING_KEY, null);
|
return new Binding(ORDER_RELEASE_QUEUE, Binding.DestinationType.QUEUE, ORDER_EVENT_EXCHANGE, ORDER_QUEUE_ROUTING_KEY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//订单队列+过期死信
|
||||||
|
@Bean
|
||||||
|
public Queue orderQueue() {
|
||||||
|
Map<String, Object> arguments = new HashMap<>(2);
|
||||||
|
// 绑定死信交换机
|
||||||
|
arguments.put("x-dead-letter-exchange", ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
|
||||||
|
// 绑定我们的路由key
|
||||||
|
arguments.put("x-dead-letter-routing-key", ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
|
||||||
|
return new Queue(ORDER_TO_BE_PAY_QUEUE, true, false, false, arguments);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public DirectExchange orderExchange() {
|
||||||
|
return new DirectExchange(ORDER_TO_BE_PAY_EXCHANGE);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Binding orderBinding() {
|
||||||
|
return BindingBuilder
|
||||||
|
.bind(orderQueue())
|
||||||
|
.to(orderExchange())
|
||||||
|
.with(ORDER_TO_BE_PAY_ROUTING_KEY);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Queue orderCancelDeadLetterQueue() {
|
||||||
|
return new Queue(ORDER_CANCEL_DEAD_LETTER_QUEUE);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public DirectExchange orderCancelDeadLetterExchange() {
|
||||||
|
return new DirectExchange(ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Binding binding() {
|
||||||
|
return BindingBuilder
|
||||||
|
.bind(orderCancelDeadLetterQueue())
|
||||||
|
.to(orderCancelDeadLetterExchange())
|
||||||
|
.with(ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
//超V过期队列+死信
|
||||||
|
@Bean
|
||||||
|
public Queue uservipQueue() {
|
||||||
|
Map<String, Object> arguments = new HashMap<>(2);
|
||||||
|
// 绑定死信交换机
|
||||||
|
arguments.put("x-dead-letter-exchange", USERVIP_DEAD_LETTER_EXCHANGE);
|
||||||
|
// 绑定我们的路由key
|
||||||
|
arguments.put("x-dead-letter-routing-key", USERVIP_DEAD_LETTER_ROUTING_KEY);
|
||||||
|
return new Queue(USERVIP_QUEUE, true, false, false, arguments);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public CustomExchange uservipExchange() {
|
||||||
|
Map<String, Object> args = new HashMap<>();
|
||||||
|
args.put("x-delayed-type", "direct");
|
||||||
|
return new CustomExchange(USERVIP_EXCHANGE, "x-delayed-message", true, false, args);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Binding uservipBinding(@Qualifier("uservipQueue") Queue delayedQueue,
|
||||||
|
@Qualifier("uservipExchange") Exchange delayedExchange) {
|
||||||
|
return BindingBuilder.bind(delayedQueue).to(delayedExchange).with(USERVIP_ROUTING_KEY).noargs();
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Queue uservipDeadLetterQueue() {
|
||||||
|
return new Queue(USERVIP_DEAD_LETTER_QUEUE);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public DirectExchange uservipDeadLetterExchange() {
|
||||||
|
return new DirectExchange(USERVIP_DEAD_LETTER_EXCHANGE);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Binding uservipDeadBinding() {
|
||||||
|
return BindingBuilder
|
||||||
|
.bind(uservipDeadLetterQueue())
|
||||||
|
.to(uservipDeadLetterExchange())
|
||||||
|
.with(USERVIP_DEAD_LETTER_ROUTING_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Queue FMSQueue() {
|
public Queue FMSQueue() {
|
||||||
@@ -199,41 +274,9 @@ public class DelayQueueConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Binding bindingExchangeMessage() {
|
Binding bindingExchangeMessage() {
|
||||||
return BindingBuilder.bind(FMSQueue()).to(FMSExchange()).with(FMS_ROUTING_KEY);
|
return BindingBuilder
|
||||||
}
|
.bind(FMSQueue())
|
||||||
|
.to(FMSExchange())
|
||||||
@Bean
|
.with(FMS_ROUTING_KEY);
|
||||||
public DirectExchange orderCancelDeadLetterExchange() {
|
|
||||||
return new DirectExchange(ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Queue orderCancelDeadLetterQueue() {
|
|
||||||
return new Queue(ORDER_CANCEL_DEAD_LETTER_QUEUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DirectExchange orderExchange() {
|
|
||||||
return new DirectExchange(ORDER_TO_BE_PAY_EXCHANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Queue orderQueue() {
|
|
||||||
Map<String, Object> arguments = new HashMap<>(2);
|
|
||||||
// 绑定死信交换机
|
|
||||||
arguments.put("x-dead-letter-exchange", ORDER_CANCEL_DEAD_LETTER_EXCHANGE);
|
|
||||||
// 绑定我们的路由key
|
|
||||||
arguments.put("x-dead-letter-routing-key", ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
|
|
||||||
return new Queue(ORDER_TO_BE_PAY_QUEUE, true, false, false, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Binding orderBinding() {
|
|
||||||
return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(ORDER_TO_BE_PAY_ROUTING_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Binding binding() {
|
|
||||||
return BindingBuilder.bind(orderCancelDeadLetterQueue()).to(orderCancelDeadLetterExchange()).with(ORDER_CANCEL_DEAD_LETTER_ROUTING_KEY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,4 +39,6 @@ public class CourseMedicine {
|
|||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<CourseMedicine> children;
|
private List<CourseMedicine> children;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<CourseEntity> courseList;
|
||||||
}
|
}
|
||||||
48
src/main/java/com/peanut/modules/job/task/CourseTask.java
Normal file
48
src/main/java/com/peanut/modules/job/task/CourseTask.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package com.peanut.modules.job.task;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||||
|
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
||||||
|
import org.apache.commons.lang.time.DateUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component("courseTask")
|
||||||
|
public class CourseTask implements ITask{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCourseBuyDao userCourseBuyDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String params) {
|
||||||
|
LambdaQueryWrapper<UserCourseBuyEntity> wrapper = new LambdaQueryWrapper();
|
||||||
|
wrapper.eq(UserCourseBuyEntity::getUserId,params);
|
||||||
|
List<UserCourseBuyEntity> list = userCourseBuyDao.selectList(wrapper);
|
||||||
|
if (list.size() > 0) {
|
||||||
|
for (UserCourseBuyEntity userCourseBuyEntity : list) {
|
||||||
|
if (userCourseBuyEntity.getStartTime()==null) {
|
||||||
|
//未开始学习,超过一年自动开始
|
||||||
|
if (DateUtils.addYears(userCourseBuyEntity.getCreateTime(),1).getTime()<=new Date().getTime()){
|
||||||
|
userCourseBuyEntity.setStartTime(DateUtils.addYears(userCourseBuyEntity.getCreateTime(),1));
|
||||||
|
userCourseBuyEntity.setEndTime(DateUtils.addDays(userCourseBuyEntity.getStartTime(),userCourseBuyEntity.getDays()));
|
||||||
|
userCourseBuyDao.updateById(userCourseBuyEntity);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//开始时间+有效天数,过期删除
|
||||||
|
if (DateUtils.addDays(userCourseBuyEntity.getStartTime(),userCourseBuyEntity.getDays()).getTime() >= new Date().getTime()) {
|
||||||
|
userCourseBuyDao.deleteById(userCourseBuyEntity.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("课程过期更新完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,19 @@
|
|||||||
package com.peanut.modules.job.task;
|
package com.peanut.modules.job.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.peanut.common.utils.MailUtil;
|
||||||
|
import com.peanut.config.DelayQueueConfig;
|
||||||
import com.peanut.modules.common.entity.MyUserEntity;
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
import com.peanut.modules.common.entity.UserVip;
|
import com.peanut.modules.common.entity.UserVip;
|
||||||
import com.peanut.modules.common.service.MyUserService;
|
import com.peanut.modules.common.service.MyUserService;
|
||||||
import com.peanut.modules.master.service.UserVipService;
|
import com.peanut.modules.master.service.UserVipService;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.lang.time.DateUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.amqp.core.MessagePostProcessor;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -13,28 +22,68 @@ import java.util.List;
|
|||||||
|
|
||||||
@Component("userVipTask")
|
@Component("userVipTask")
|
||||||
public class UserVipTask implements ITask{
|
public class UserVipTask implements ITask{
|
||||||
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserVipService vipService;
|
private UserVipService vipService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private MyUserService userService;
|
private MyUserService userService;
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String params) {
|
public void run(String params) {
|
||||||
LambdaQueryWrapper<UserVip> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<UserVip> wrapper = new LambdaQueryWrapper();
|
||||||
wrapper.eq(UserVip::getState,0);
|
wrapper.eq(UserVip::getState,0);
|
||||||
|
wrapper.eq(UserVip::getUserId,params);
|
||||||
List<UserVip> list = vipService.list(wrapper);
|
List<UserVip> list = vipService.list(wrapper);
|
||||||
if (list.size() > 0) {
|
if (list.size() > 0) {
|
||||||
for (UserVip userVip : list) {
|
for (UserVip userVip : list) {
|
||||||
|
MyUserEntity user = userService.getById(userVip.getUserId());
|
||||||
if (userVip.getEndTime().getTime()<new Date().getTime()){
|
if (userVip.getEndTime().getTime()<new Date().getTime()){
|
||||||
userVip.setState(1);
|
userVip.setState(1);
|
||||||
vipService.saveOrUpdate(userVip);
|
vipService.saveOrUpdate(userVip);
|
||||||
MyUserEntity user = userService.getById(userVip.getUserId());
|
|
||||||
user.setVip("0");
|
user.setVip("0");
|
||||||
userService.saveOrUpdate(user);
|
userService.saveOrUpdate(user);
|
||||||
|
}else if (DateUtils.isSameDay(DateUtils.addDays(new Date(),60),userVip.getEndTime())) {
|
||||||
|
try {
|
||||||
|
if (StringUtils.isNotEmpty(user.getTel())){
|
||||||
|
userService.sendCodeForRegister(user.getTel(),"VIPWillExpire",86);
|
||||||
|
}else if (StringUtils.isNotEmpty(user.getEmail())) {
|
||||||
|
MailUtil.sendMail("太湖超V提醒","超V还有2月到期",user.getEmail());
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("userVipTask定时任务超V提醒出错,错误为:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}else if (DateUtils.isSameDay(DateUtils.addDays(new Date(),30),userVip.getEndTime())) {
|
||||||
|
try {
|
||||||
|
if (StringUtils.isNotEmpty(user.getTel())){
|
||||||
|
userService.sendCodeForRegister(user.getTel(),"VIPWillExpire",86);
|
||||||
|
}else if (StringUtils.isNotEmpty(user.getEmail())) {
|
||||||
|
MailUtil.sendMail("太湖超V提醒","超V还有一月到期",user.getEmail());
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.error("userVipTask定时任务超V提醒出错,错误为:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}else if (DateUtils.isSameDay(DateUtils.addMinutes(new Date(),3),userVip.getEndTime())) {
|
||||||
|
rabbitTemplate.convertAndSend(
|
||||||
|
DelayQueueConfig.USERVIP_EXCHANGE,
|
||||||
|
DelayQueueConfig.USERVIP_ROUTING_KEY,
|
||||||
|
userVip.getId(),
|
||||||
|
messagePostProcessor(userVip.getEndTime().getTime()-new Date().getTime())
|
||||||
|
);
|
||||||
|
System.out.println("----------------------------------------");
|
||||||
|
System.out.println("会员还剩7天,加入队列");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessagePostProcessor messagePostProcessor(long date) {
|
||||||
|
return message -> {
|
||||||
|
//设置有效期7天
|
||||||
|
message.getMessageProperties().setExpiration(String.valueOf(date));
|
||||||
|
return message;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,26 +81,36 @@ public class CourseMedicalServiceImpl extends ServiceImpl<CourseMedicineDao, Cou
|
|||||||
@Override
|
@Override
|
||||||
public List getMedicalCoursePrice() {
|
public List getMedicalCoursePrice() {
|
||||||
//获取所有医学标签
|
//获取所有医学标签
|
||||||
List<CourseMedicine> courseMedicines = this.list(null);
|
List<CourseMedicine> courseMedicines = getCourseMedicalTree();
|
||||||
ArrayList<Map> flag = new ArrayList<>();
|
|
||||||
for (CourseMedicine c : courseMedicines){
|
for (CourseMedicine c : courseMedicines){
|
||||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
getLastLevelCourseList(c);
|
||||||
MPJLambdaWrapper<CourseToMedicine> wrapper = new MPJLambdaWrapper<>();
|
}
|
||||||
wrapper.selectAll(CourseEntity.class);
|
return courseMedicines;
|
||||||
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId);
|
}
|
||||||
wrapper.eq(CourseToMedicine::getMedicalId,c.getId());
|
|
||||||
List<CourseEntity> courseEntities = toMedicineDao.selectJoinList(CourseEntity.class, wrapper);
|
private void getLastLevelCourseList(CourseMedicine c){
|
||||||
if(courseEntities.size()==0){
|
if (c.getChildren()!=null&&c.getChildren().size() > 0){
|
||||||
continue;
|
for (CourseMedicine child : c.getChildren()){
|
||||||
|
getLastLevelCourseList(child);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
MPJLambdaWrapper<CourseToMedicine> wrapper = new MPJLambdaWrapper<>();
|
||||||
|
wrapper.selectAll(CourseEntity.class);
|
||||||
|
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId);
|
||||||
|
wrapper.eq(CourseToMedicine::getMedicalId,c.getId());
|
||||||
|
wrapper.orderByAsc(CourseToMedicine::getSort);
|
||||||
|
List<CourseEntity> courseEntities = toMedicineDao.selectJoinList(CourseEntity.class, wrapper);
|
||||||
|
if(courseEntities.size()!=0){
|
||||||
for (CourseEntity co:courseEntities){
|
for (CourseEntity co:courseEntities){
|
||||||
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, co.getId()).orderByAsc(CourseCatalogueEntity::getSort));
|
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, co.getId()).orderByAsc(CourseCatalogueEntity::getSort));
|
||||||
co.setCourseCatalogueEntityList(courseCatalogueEntities);
|
co.setCourseCatalogueEntityList(courseCatalogueEntities);
|
||||||
}
|
}
|
||||||
stringObjectHashMap.put("medical",c);
|
c.setCourseList(courseEntities);
|
||||||
stringObjectHashMap.put("courseList",courseEntities);
|
|
||||||
flag.add(stringObjectHashMap);
|
|
||||||
}
|
}
|
||||||
return flag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,16 @@ public class OrderCancelConsumer {
|
|||||||
if(Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus())){
|
if(Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus())){
|
||||||
buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME);
|
buyOrder.setOrderStatus(Constants.ORDER_STATUS_OUT_OF_TIME);
|
||||||
//回滚库存
|
//回滚库存
|
||||||
// LambdaQueryWrapper<BuyOrderProduct> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BuyOrderProduct> wrapper = new LambdaQueryWrapper<>();
|
||||||
// wrapper.eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId());
|
wrapper.eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId());
|
||||||
// List<BuyOrderProduct> buyOrderProducts = buyOrderProductDao.selectList(wrapper);
|
List<BuyOrderProduct> buyOrderProducts = buyOrderProductDao.selectList(wrapper);
|
||||||
// for (BuyOrderProduct b : buyOrderProducts){
|
for (BuyOrderProduct b : buyOrderProducts){
|
||||||
// ShopProduct shopProduct = shopProductDao.selectById(b.getProductId());
|
ShopProduct shopProduct = shopProductDao.selectById(b.getProductId());
|
||||||
// shopProduct.setProductStock(shopProduct.getProductStock()+b.getQuantity());
|
shopProduct.setProductStock(shopProduct.getProductStock()+b.getQuantity());
|
||||||
// shopProductDao.updateById(shopProduct);
|
shopProductDao.updateById(shopProduct);
|
||||||
// }
|
}
|
||||||
|
buyOrderService.updateById(buyOrder);
|
||||||
}
|
}
|
||||||
buyOrderService.updateById(buyOrder);
|
|
||||||
if(Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())){
|
if(Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())){
|
||||||
buyOrderService.removeById(buyOrder);
|
buyOrderService.removeById(buyOrder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.peanut.modules.mq.Consumer;
|
||||||
|
|
||||||
|
import com.peanut.config.DelayQueueConfig;
|
||||||
|
import com.peanut.modules.common.dao.MyUserDao;
|
||||||
|
import com.peanut.modules.common.dao.UserVipDao;
|
||||||
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
|
import com.peanut.modules.common.entity.UserVip;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
//超v过期死信操作
|
||||||
|
@Component
|
||||||
|
public class UserVipConsumer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserVipDao userVipDao;
|
||||||
|
@Autowired
|
||||||
|
private MyUserDao userDao;
|
||||||
|
|
||||||
|
@RabbitListener(queues = DelayQueueConfig.USERVIP_DEAD_LETTER_QUEUE)
|
||||||
|
public void userVipConsumer(String userVipId) {
|
||||||
|
UserVip userVip = userVipDao.selectById(userVipId);
|
||||||
|
if(userVip == null){
|
||||||
|
return;
|
||||||
|
}else {
|
||||||
|
userVip.setState(1);
|
||||||
|
userVipDao.updateById(userVip);
|
||||||
|
MyUserEntity user = userDao.selectById(userVip.getUserId());
|
||||||
|
user.setVip("0");
|
||||||
|
userDao.updateById(user);
|
||||||
|
System.out.println("vip更新完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user