红包模块增加24小时订单消息,自购/分享订单到账消息
| | |
| | | // jiedis原子性做拦截
|
| | | Jedis jedis = jedisPool.getResource();
|
| | | long threadId= Thread.currentThread().getId();
|
| | | LogHelper.test("进入拦截:"+cacheKey+"-"+threadId);
|
| | | try {
|
| | | Constant.waitingThreadSet.add(threadId);
|
| | | String result = null;
|
| | |
| | | while (StringUtil.isNullOrEmpty(result)) {
|
| | |
|
| | | result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30));
|
| | | LogHelper.error("触发并发锁:" + cacheAlias);
|
| | | LogHelper.error("redis键:" + cacheKey);
|
| | | if (StringUtil.isNullOrEmpty(result)) {
|
| | | LogHelper.test("等待:"+threadId);
|
| | | try {
|
| | | Thread.sleep(50);
|
| | | } catch (InterruptedException e) {
|
| | |
| | | return null;
|
| | | }
|
| | | } else {
|
| | | LogHelper.test("获取到锁:"+threadId);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } finally {
|
| | | LogHelper.test("方法执行完毕:"+threadId);
|
| | | jedis.del(cacheKey);
|
| | | Constant.waitingThreadSet.remove(Thread.currentThread().getId());
|
| | | LogHelper.test("释放锁:"+threadId);
|
| | | }
|
| | | }
|
| | | } finally {
|
| | |
| | |
|
| | | public enum OrderTopicTagEnum {
|
| | | orderStatistic(OrderMQMsg.class), // 订单统计
|
| | | orderStatisticDelay(OrderMQMsg.class), // 订单统计延时
|
| | | orderUpdate(OrderMoneyRecievedMQMsg.class), // 订单修改
|
| | | orderFanLiActual(OrderMoneyRecievedMQMsg.class), // 订单实时到账
|
| | | orderFanLiDelay(OrderMoneyRecievedMQMsg.class), // 订单到账延时消息
|
| | | orderFanLiSeparateByOrderNo(OrderMoneyRecievedMQMsg.class),//订单实时到账,按订单号分离
|
| | | banLiShopOrderDelay(BanLiShopOrderMQMsg.class), // 板栗商城下单
|
| | | banLiShopOrderRefund(BanLiShopOrderMQMsg.class), // 板栗商城订单退款
|
| | | banLiShopOrderPaid(BanLiShopOrderMQMsg.class);// 商城订单支付成功
|
| | |
| | | package com.yeshi.fanli.dto.mq.order.body;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
|
| | |
|
| | | /**
|
| | |
| | | private Long uid;
|
| | | private int handleType; // 操作类型
|
| | | private boolean valid;
|
| | | private int delayHour;// 延时的时间(小时记)
|
| | | private Date staticticDate;// 统计到的时间
|
| | |
|
| | | public OrderMQMsg(String orderId, Integer type, Long uid, int handleType, boolean valid) {
|
| | | public OrderMQMsg(String orderId, Integer type, Long uid, int handleType, boolean valid, int delayHour,
|
| | | Date staticticDate) {
|
| | | super();
|
| | | this.orderId = orderId;
|
| | | this.type = type;
|
| | | this.uid = uid;
|
| | | this.handleType = handleType;
|
| | | this.valid = valid;
|
| | | this.delayHour = delayHour;
|
| | | this.staticticDate = staticticDate;
|
| | | }
|
| | |
|
| | | public Date getStaticticDate() {
|
| | | return staticticDate;
|
| | | }
|
| | |
|
| | | public void setStaticticDate(Date staticticDate) {
|
| | | this.staticticDate = staticticDate;
|
| | | }
|
| | |
|
| | | public int getDelayHour() {
|
| | | return delayHour;
|
| | | }
|
| | |
|
| | | public void setDelayHour(int delayHour) {
|
| | | this.delayHour = delayHour;
|
| | | }
|
| | |
|
| | | public OrderMQMsg() {
|
| | |
| | | private BigDecimal money;// 到账金额
|
| | | private Date date;// 到账时间
|
| | | private Boolean orderFirst;// 该订单是否是首次到账
|
| | | private int delayHour;// 延时的时间(以小时计算)
|
| | |
|
| | | public int getDelayHour() {
|
| | | return delayHour;
|
| | | }
|
| | |
|
| | | public void setDelayHour(int delayHour) {
|
| | | this.delayHour = delayHour;
|
| | | }
|
| | |
|
| | | public Boolean getOrderFirst() {
|
| | | return orderFirst;
|
| | |
| | | super();
|
| | | }
|
| | |
|
| | | public OrderMoneyRecievedMQMsg(int type, Long uid, Integer sourceType, String orderId, BigDecimal money,
|
| | | Date date) {
|
| | | public OrderMoneyRecievedMQMsg(int type, Long uid, Integer sourceType, String orderId, BigDecimal money, Date date,
|
| | | int delayHour) {
|
| | | super();
|
| | | this.type = type;
|
| | | this.uid = uid;
|
| | |
| | | this.orderId = orderId;
|
| | | this.money = money;
|
| | | this.date = date;
|
| | | this.delayHour = delayHour;
|
| | | }
|
| | |
|
| | | public int getType() {
|
| | |
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | |
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(), new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(), new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
| | | }
|
| | |
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(),OrderTopicTagEnum.orderFanLiActual.name(), new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
| | | }
|
| | |
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(), new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
| | | }
|
| | |
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid,
|
| | | sourceType, null, null, new Date());
|
| | | sourceType, null, null, new Date(),0);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(), new Gson().toJson(mqMsg).getBytes());
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
| | | // 自购到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_ZIGOU,
|
| | | mainUser.getId(), hongBaoOrder.getCommonOrder().getSourceType(),
|
| | | hongBaoOrder.getCommonOrder().getOrderNo(), null, new Date());
|
| | | hongBaoOrder.getCommonOrder().getOrderNo(), null, new Date(),0);
|
| | | mqMsg.setOrderFirst(first);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderFanLiActual.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | |
| | | }
|
| | | if (resultCode == 1) {// 只发送新增消息
|
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD,
|
| | | isCommonOrderValid(coList));
|
| | | isCommonOrderValid(coList),0,new Date());
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderStatistic.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | | producer.send(msg);
|
| | |
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.MessageListener;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
|
| | | import com.yeshi.fanli.entity.shop.BanLiShopOrder;
|
| | |
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.shop.BanLiShopOrderPayService;
|
| | | import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | |
| | | import com.aliyun.openservices.ons.api.ConsumeContext;
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.MessageListener;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.mq.BaseMQMsgBody;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
|
| | |
| | | import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | |
| | |
|
| | | @Resource
|
| | | private RedPackWinInviteService redPackWinInviteService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private RedPackGiveRecordService redPackGiveRecordService;
|
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | |
| | | OrderMoneyRecievedMQMsg.class);
|
| | | // 分享订单奖励
|
| | | if (orderMoneyRecievedMQMsg.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) {
|
| | | // try {
|
| | | // redPackWinInviteService.orderArriveReward(orderMoneyRecievedMQMsg.getUid(),
|
| | | // orderMoneyRecievedMQMsg.getSourceType(), orderMoneyRecievedMQMsg.getOrderId());
|
| | | // } catch (Exception e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // try {
|
| | | // redPackWinInviteService.orderArriveReward(orderMoneyRecievedMQMsg.getUid(),
|
| | | // orderMoneyRecievedMQMsg.getSourceType(),
|
| | | // orderMoneyRecievedMQMsg.getOrderId());
|
| | | // } catch (Exception e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatistic.name())) {// 订单统计
|
| | | OrderMQMsg orderMQMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | // 发送24小时延时消息
|
| | | // 测试时发送
|
| | | int hour = 24;
|
| | | if (Constant.IS_TEST) {
|
| | | hour = 1;
|
| | | }
|
| | | orderMQMsg.setDelayHour(hour);
|
| | | Message msg = new Message(message.getTopic(), OrderTopicTagEnum.orderStatisticDelay.name(),
|
| | | new Gson().toJson(orderMQMsg).getBytes());
|
| | | if (orderMQMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour > System.currentTimeMillis())// 时间是否已经过了
|
| | | msg.setStartDeliverTime(orderMQMsg.getStaticticDate().getTime() + 1000 * 60 * 60L * hour);
|
| | | else
|
| | | msg.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60);
|
| | | producer.send(msg);
|
| | | return Action.CommitMessage;
|
| | | }
|
| | |
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderStatisticDelay.name())) {// 订单统计
|
| | | OrderMQMsg orderMQMsg = new Gson().fromJson(new String(message.getBody()), OrderMQMsg.class);
|
| | | int hour = 24;
|
| | | if (Constant.IS_TEST) {
|
| | | hour = 1;
|
| | | }
|
| | |
|
| | | if (orderMQMsg.getDelayHour() == hour) {
|
| | | // TODO 处理延时消息
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiSeparateByOrderNo.name())) {// 订单到账(按订单号处理)
|
| | | OrderMoneyRecievedMQMsg orderMoneyRecievedMQMsg = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsg.class);
|
| | | if (orderMoneyRecievedMQMsg.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU
|
| | | || orderMoneyRecievedMQMsg.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) {
|
| | | if (!StringUtil.isNullOrEmpty(orderMoneyRecievedMQMsg.getOrderId())
|
| | | && orderMoneyRecievedMQMsg.getUid() != null) {
|
| | | // TODO 自购与分享订单到账处理
|
| | | }
|
| | | }
|
| | |
|
| | | return Action.CommitMessage;
|
| | | } else if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | boolean inviteSucceedReward = false;
|
| | | Long uid = null;
|
| | |
| | |
|
| | | if (inviteSucceedReward) {
|
| | | try {// 邀请奖励
|
| | | if(uid==6269748)
|
| | | {
|
| | | if (uid == 6269748) {
|
| | | System.out.println(uid);
|
| | | }
|
| | | // redPackWinInviteService.inviteSucceedReward(uid);
|
| | | // redPackWinInviteService.inviteSucceedReward(uid);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | </property>
|
| | | <property name="subscriptionTable">
|
| | | <map>
|
| | | <!-- 产生订单,订单到账 -->
|
| | | <!-- 产生订单/延时,订单到账 -->
|
| | | <entry value-ref="redPackMessageListener">
|
| | | <key>
|
| | | <bean class="com.aliyun.openservices.ons.api.bean.Subscription">
|
| | | <property name="topic" value="TOPIC_ORDER" />
|
| | | <property name="expression" value="orderStatistic||orderFanLiActual" />
|
| | | <property name="expression" value="orderStatistic||orderFanLiActual||orderStatisticDelay||orderFanLiSeparateByOrderNo" />
|
| | | </bean>
|
| | | </key>
|
| | | </entry>
|