commit
1d98d347d7
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mall.common.domain.OrderItemEntity;
|
||||
import com.mall.server.config.DelayConfig;
|
||||
import com.mall.server.config.MqConfig;
|
||||
import com.mall.server.constant.SpikesConstant;
|
||||
import com.mall.server.service.OrderItemService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
|
@ -48,7 +49,39 @@ public class SpikesMonitor {
|
|||
try {
|
||||
channel.basicAck(deliveryTag,false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
try {
|
||||
if(deliveryTag<3){
|
||||
Thread.sleep(3000);
|
||||
channel.basicNack(deliveryTag,false,true);
|
||||
}else {
|
||||
channel.basicNack(deliveryTag,false,false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = MqConfig.DXQUEUE)
|
||||
public void orderConsumer(String meg, Message message, Channel channel){
|
||||
log.info("下订单"+meg);
|
||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
|
||||
orderItemService.save(JSON.parseObject(meg,OrderItemEntity.class));
|
||||
|
||||
try {
|
||||
channel.basicAck(deliveryTag,false);
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
if(deliveryTag<3){
|
||||
Thread.sleep(3000);
|
||||
channel.basicNack(deliveryTag,false,true);
|
||||
}else {
|
||||
channel.basicNack(deliveryTag,false,false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.mall.server.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mall.common.constant.TokenConstants;
|
||||
|
@ -14,6 +13,7 @@ import com.mall.common.result.Result;
|
|||
import com.mall.common.utils.IdUtils;
|
||||
import com.mall.common.utils.StringUtils;
|
||||
import com.mall.server.config.DelayConfig;
|
||||
import com.mall.server.config.MqConfig;
|
||||
import com.mall.server.constant.SpikesConstant;
|
||||
import com.mall.server.domain.SkuEntity;
|
||||
import com.mall.server.domain.SpikesEntity;
|
||||
|
@ -21,12 +21,10 @@ import com.mall.server.mapper.SpikesMapper;
|
|||
import com.mall.server.service.OrderItemService;
|
||||
import com.mall.server.service.SkuService;
|
||||
import com.mall.server.service.SpikesService;
|
||||
import com.mall.server.service.SpuService;
|
||||
import org.redisson.api.RSemaphore;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -69,6 +67,7 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
|
|||
|
||||
/**
|
||||
* 添加秒杀信息
|
||||
*
|
||||
* @param spikesRequest
|
||||
* @return
|
||||
*/
|
||||
|
@ -147,6 +146,7 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
|
|||
|
||||
/**
|
||||
* 秒杀
|
||||
*
|
||||
* @param skuId
|
||||
* @return
|
||||
*/
|
||||
|
@ -173,8 +173,7 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
|
|||
throw new BizException(500, "系统繁忙,商品已抢购完");
|
||||
}
|
||||
String orderSn = IdUtils.genId();
|
||||
orderItemService.save(
|
||||
OrderItemEntity.builder()
|
||||
OrderItemEntity orderItem = OrderItemEntity.builder()
|
||||
.userId(login.getId())
|
||||
.orderSn(orderSn)
|
||||
.skuId(skuId)
|
||||
|
@ -185,8 +184,14 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
|
|||
// .couponAmount()
|
||||
// .integrationAmount()
|
||||
.realAmount(skuEntity.getActivityPrice())
|
||||
.status(0).build()
|
||||
);
|
||||
.status(0).build();
|
||||
//异步下订单
|
||||
rabbitTemplate.convertAndSend(MqConfig.DXEXCHANGE, MqConfig.ROUTINGKEY, orderItem.toString(),
|
||||
message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.genId());
|
||||
return message;
|
||||
});
|
||||
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayConfig.EXCHANGE, DelayConfig.ROUKEYCZK, skuId + "," + orderSn,
|
||||
message -> {
|
||||
|
|
Loading…
Reference in New Issue