Przeglądaj źródła

Merge branch 'dev-feat' of https://e.coding.net/chuanghaikeji/moxuanyunshangwaimai/backend into dev-wxl

wanxl 1 rok temu
rodzic
commit
ec315633c0

BIN
db.zip


+ 7 - 1
src/main/java/com/sqx/modules/common/service/impl/CommonInfoServiceImpl.java

@@ -32,6 +32,9 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
         Date now = new Date();
         commonInfo.setCreateAt(sdf.format(now));
         commonInfoDao.updateById(commonInfo);
+
+        // 缓存失效
+        redisUtils.delete(String.format(RedisKey.COMMON_INFO_CACHE_KEY, commonInfo.getType()));
         return Result.success();
     }
 
@@ -43,7 +46,7 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
         if (ObjectUtil.isNull(commonInfo)) {
             commonInfo = commonInfoDao.findOne(id);
 
-            redisUtils.set(key, commonInfo);
+            redisUtils.set(key, commonInfo, RedisUtils.HOUR_ONE_EXPIRE);
         }
         return commonInfo;
     }
@@ -58,6 +61,9 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
     @Override
     public Result updateBody(CommonInfo commonInfo) {
         commonInfoDao.updateById(commonInfo);
+
+        // 缓存失效
+        redisUtils.delete(String.format(RedisKey.COMMON_INFO_CACHE_KEY, commonInfo.getType()));
         return Result.success();
     }
 

+ 112 - 19
src/main/java/com/sqx/modules/errand/service/impl/TbIndentServiceImpl.java

@@ -12,6 +12,7 @@ import com.sqx.common.constant.RedisKey;
 import com.sqx.common.exception.SqxException;
 import com.sqx.common.sms.SmsSendResult;
 import com.sqx.common.utils.DateUtils;
+import com.sqx.common.utils.MyGlobalThreadPool;
 import com.sqx.common.utils.PageUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.address.dao.AddressDao;
@@ -690,8 +691,22 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
             msgList.add(userEntity1.getNickName());
             msgList.add(format);
             msgList.add("接单成功,请及时取货!");
-            SenInfoCheckUtil.sendRiderMsg(userEntity1.getRiderOpenId(), five.getValue(), msgList, 4);
-            userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", userEntity1.getRiderClientid());
+
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    SenInfoCheckUtil.sendRiderMsg(userEntity1.getRiderOpenId(), five.getValue(), msgList, 4);
+                } catch (Exception e) {
+                    log.error("订单:{},您已接单成功,请及时派送通知发送失败,失败原因:{}", e);
+                }
+            });
+
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", userEntity1.getRiderClientid());
+                } catch (Exception e) {
+                    log.error("订单:{},您已接单成功,请及时派送通知发送失败,失败原因:{}", e);
+                }
+            });
 
             //用户推送
             CommonInfo msg = commonInfoService.findOne(269);
@@ -723,7 +738,15 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 msgListUser.add(value);
             }
             msgListUser.add(DateUtils.format(new Date()));
-            SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
+
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
+                } catch (Exception e) {
+                    log.error("订单:{},订单接单成功通知发送失败,失败原因:{}", e);
+                }
+            });
+
             if (tbIndent.getOrderId() != null) {
                 TbOrder order = appOrderService.getById(tbIndent.getOrderId());
                 String shopTemplate = commonInfoService.findOne(354).getValue();
@@ -735,7 +758,15 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 log.error("打印:" + msgListShop.toString());
                 GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
                 UserEntity shopUser = userService.selectUserById(goodsShop.getUserId());
-                SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+
+                MyGlobalThreadPool.execute(() -> {
+                    try {
+                        SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+                    } catch (Exception e) {
+                        log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+                    }
+                });
+
             }
         } else {
             return Result.error("你的保证金不足,请缴纳保证金后再接单");
@@ -767,13 +798,20 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 }
                 TbIndent tbIndent = tbIndentDao.findIndentByOrderId(acquireCode);
                 log.error("抢单:" + userId + "     " + tbIndent.getIndentState());
+                RLock lock = redissonClient.getLock(String.format(RedisKey.UPDATE_INDENT_LOCK, tbIndent.getIndentNumber()));
+                lock.lock();
+                try {
 //                if(!"2".equals(tbIndent.getIndentState())){
 //                    return Result.error("订单已被抢走!");
 //                }
-                if ("5".equals(tbIndent.getIndentType())) {
-                    if ("2".equals(tbIndent.getIndentState()) || "3".equals(tbIndent.getIndentState())) {
-                        tbIndentDao.orderIndentReceiv(userId, acquireCode, format, "4");
+                    if ("5".equals(tbIndent.getIndentType())) {
+                        if ("2".equals(tbIndent.getIndentState()) || "3".equals(tbIndent.getIndentState())) {
+                            tbIndentDao.orderIndentReceiv(userId, acquireCode, format, "4");
+                        }
                     }
+
+                } finally {
+                    lock.unlock();
                 }
                 //消息推送(以前写的在下面放着)
                 CommonInfo five = commonInfoService.findOne(310);
@@ -782,9 +820,21 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                 msgList.add(userEntity1.getNickName());
                 msgList.add(format);
                 msgList.add("接单成功,请及时取货!");
-                SenInfoCheckUtil.sendRiderMsg(userEntity1.getRiderOpenId(), five.getValue(), msgList, 4);
-                userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", userEntity1.getRiderClientid());
+                MyGlobalThreadPool.execute(() -> {
+                    try {
+                        SenInfoCheckUtil.sendRiderMsg(userEntity1.getRiderOpenId(), five.getValue(), msgList, 4);
+                    } catch (Exception e) {
+                        log.error("订单:{},接单成功通知发送失败,失败原因:{}", e);
+                    }
+                });
 
+                MyGlobalThreadPool.execute(() -> {
+                    try {
+                        userService.pushToSingleRider("接单成功", "您已接单成功,请及时派送", userEntity1.getRiderClientid());
+                    } catch (Exception e) {
+                        log.error("订单:{},您已接单成功,请及时派送通知发送失败,失败原因:{}", e);
+                    }
+                });
                 //用户推送
                 CommonInfo msg = commonInfoService.findOne(269);
                 UserEntity userEntity = userService.selectUserById(tbIndent.getUserId());
@@ -816,7 +866,15 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                     msgListUser.add(value);
                 }
                 msgListUser.add(DateUtils.format(new Date()));
-                SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
+
+                MyGlobalThreadPool.execute(() -> {
+                    try {
+                        SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), msg.getValue(), msgListUser, 1);
+                    } catch (Exception e) {
+                        log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+                    }
+                });
+
                 if (tbIndent.getOrderId() != null) {
                     TbOrder order = appOrderService.getById(tbIndent.getOrderId());
                     String shopTemplate = commonInfoService.findOne(354).getValue();
@@ -828,7 +886,15 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
                     log.error("打印:" + msgListShop.toString());
                     GoodsShop goodsShop = goodsShopDao.selectById(order.getShopId());
                     UserEntity shopUser = userService.selectUserById(goodsShop.getUserId());
-                    SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+
+                    MyGlobalThreadPool.execute(() -> {
+                        try {
+                            SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+                        } catch (Exception e) {
+                            log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+                        }
+                    });
+
                 }
             } else {
                 return Result.error("你的保证金不足,请缴纳保证金后再接单");
@@ -1034,11 +1100,17 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
 //        TbOrder tbOrder = appOrderService.getById(indentOrder.getOrderId());
 //        tbOrder.setDeliveryImgs(imgs);
 //        appOrderService.updateById(tbOrder);
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                // 发送短信并记录短信发送记录
+                SmsSendResult smsSendResult = smsTemplateService.sendSms(smsTemplateId, riderUser, userPhone);
+                // sourceType 1骑手、2商家
+                smsSendLogService.saveLog(indentOrder.getIndentId(), "1", smsSendResult);
+            } catch (Exception e) {
+                log.error("订单:{},完成跑腿订单成功通知发送失败,失败原因:{}", e);
+            }
+        });
 
-        // 发送短信并记录短信发送记录
-        SmsSendResult smsSendResult = smsTemplateService.sendSms(smsTemplateId, riderUser, userPhone);
-        // sourceType 1骑手、2商家
-        smsSendLogService.saveLog(indentOrder.getIndentId(), "1", smsSendResult);
     }
 
     @Transactional
@@ -1323,7 +1395,14 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         msgList.add("已完成");
         msgList.add(DateUtils.format(new Date()));
         UserEntity riderUser = userService.selectUserById(tbIndent.getRiderUserId());
-        SenInfoCheckUtil.sendRiderMsg(riderUser.getRiderOpenId(), riderTemplate, msgList, 2);
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                SenInfoCheckUtil.sendRiderMsg(riderUser.getRiderOpenId(), riderTemplate, msgList, 2);
+            } catch (Exception e) {
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+            }
+        });
+
     }
 
     @Override
@@ -1631,11 +1710,25 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
         msgList.add(2, "骑手已更换,新骑手将尽快为您送达");
         msgList.add(3, DateUtils.format(new Date()));
         if (org.apache.commons.lang.StringUtils.isNotEmpty(user.getOpenId())) {
-            SenInfoCheckUtil.sendMsg(user.getOpenId(), one.getValue(), msgList, 5);
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    SenInfoCheckUtil.sendMsg(user.getOpenId(), one.getValue(), msgList, 5);
+                } catch (Exception e) {
+                    log.error("订单:{},转单成功通知发送失败,失败原因:{}", e);
+                }
+            });
+
         }
 
         if (org.apache.commons.lang.StringUtils.isNotEmpty(user.getOpenId())) {
-            userService.pushToSingle("更换骑手", "骑手已更换,新骑手将尽快为您送达", user.getClientid());
+            MyGlobalThreadPool.execute(() -> {
+                try {
+                    userService.pushToSingle("更换骑手", "骑手已更换,新骑手将尽快为您送达", user.getClientid());
+                } catch (Exception e) {
+                    log.error("订单:{},骑手已更换通知发送失败,失败原因:{}", e);
+                }
+            });
+
         }
     }
 
@@ -1711,7 +1804,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
     }
 
     @Override
-    public PageUtils selectIndentPage(Integer page, Integer limit, String acquireCode,Long userId) {
+    public PageUtils selectIndentPage(Integer page, Integer limit, String acquireCode, Long userId) {
         List<Integer> states = new ArrayList<>();
         states.add(2);
         states.add(3);

+ 27 - 7
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -275,7 +275,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
      * @return boolean
      */
     private boolean isShopBusinessTime(Long shopId) {
-        GoodsShop goodsShop = goodsShopDao.selectById(shopId);
+        GoodsShop goodsShop = shopMessageService.getShopInfoById(shopId);
         if (goodsShop == null) {
             throw new SqxException("无效的店铺id");
         }
@@ -570,7 +570,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             try {
                 addOrderMessageAndPush(order, goodsShop, mpPushConfig, userEntity);
             } catch (Exception e) {
-                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", order.getOrderId(), e);
             }
         });
 
@@ -614,7 +614,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
                 try {
                     sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
                 } catch (Exception e) {
-                    log.error("订单:{},商家接单通知发送失败,失败原因:{}", e);
+                    log.error("订单:{},商家接单通知发送失败,失败原因:{}", order.getOrderId(), e);
                 }
             });
 
@@ -635,7 +635,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
 
                         FeiYunUtils.print(goodsShop.getSnCode(), null, order);
                     } catch (Exception e) {
-                        log.error("订单:{},小票打印失败,失败原因:{}", e);
+                        log.error("订单:{},小票打印失败,失败原因:{}", order.getOrderId(), e);
                     }
                 });
             }
@@ -2003,15 +2003,35 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         msgList.add(shopName);
         msgList.add(format);
         UserEntity userEntity = userDao.selectById(tbOrder.getUserId());
-        SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 1);
-        userService.pushToSingle("订单完成", "您的订单已完成,欢迎下次光临!", userEntity.getClientid());
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 1);
+            } catch (Exception e) {
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+            }
+        });
+
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                userService.pushToSingle("订单完成", "您的订单已完成,欢迎下次光临!", userEntity.getClientid());
+            } catch (Exception e) {
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+            }
+        });
+
         String shopTemplate = commonInfoService.findOne(354).getValue();
         List<String> msgListShop = new ArrayList<>();
         msgListShop.add(indent.getIndentNumber());
         msgListShop.add("订单完成");
         msgListShop.add(DateUtils.format(new Date()));
         UserEntity shopUser = userService.selectUserById(goodsShop.getUserId());
-        SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+        MyGlobalThreadPool.execute(() -> {
+            try {
+                SenInfoCheckUtil.sendShopMsg(shopUser.getShopOpenId(), shopTemplate, msgListShop, 9);
+            } catch (Exception e) {
+                log.error("订单:{},订单支付成功通知发送失败,失败原因:{}", e);
+            }
+        });
 
         log.info("订单id【{}】,accomplishOrders逻辑执行完成", orderId);
         return Result.success();

+ 3 - 0
src/main/java/com/sqx/modules/shop/service/impl/ShopMessageServiceImpl.java

@@ -315,6 +315,9 @@ public class ShopMessageServiceImpl extends ServiceImpl<ShopMessageDao, GoodsSho
         // }
 
         baseMapper.updateById(goodsShop);
+
+        redisUtils.delete(String.format(RedisKey.SHOP_INFO_CACHE_KEY, goodsShop.getShopId()));
+
         return Result.success();
     }
 

+ 5 - 0
src/main/java/com/sqx/modules/timedtask/service/impl/RiderLocationServiceImpl.java

@@ -1,7 +1,9 @@
 package com.sqx.modules.timedtask.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sqx.common.exception.SqxException;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
@@ -55,6 +57,9 @@ public class RiderLocationServiceImpl extends ServiceImpl<RiderLocationDao, Ride
         HashMap hashMap = new HashMap();
         //查看骑手即时位置
         RiderLocation riderLocation = baseMapper.selectOne(new QueryWrapper<RiderLocation>().eq("user_id", riderUserId));
+        if (ObjectUtil.isNull(riderLocation)) {
+            throw new SqxException("无效的用户id");
+        }
         //计算骑手到用户的距离
         Double aDouble = riderLocationDao.calculateDistance(lng, lat, riderLocation.getLng(), riderLocation.getLat());
         //计算预计送达时间