Explorar o código

用户下单给商家推送

qmj hai 1 semana
pai
achega
345f450c37

+ 91 - 15
ruoyi-admin/src/main/java/com/ruoyi/app/order/PosOrderController.java

@@ -35,6 +35,7 @@ import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DictUtils;
 import com.ruoyi.common.utils.MessageUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.manager.AsyncManager;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.domain.vo.OrderDTO;
@@ -293,22 +294,43 @@ public class PosOrderController extends BaseController {
                                 if (lock.isHeldByCurrentThread()) {
                                     lock.unlock();
                                 }
-                                try {
-                                    if (!"".equals(user.getCid())) {
-                                        logger.info("用户cid:" + user.getCid() + "推送");
-                                        push.apppush(user.getCid(), MessageUtils.message("no.message.push.message"), finalUserMessage, OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState())));
-                                        pushEventService.PublisherEvent(user.getUserId(), MessageUtils.message("no.message.push.message"), finalUserMessage, OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState())));
+                                // 给用户推送(骑手已接单/配送中/已送达)
+                                if (!StringUtils.isEmpty(user.getCid())) {
+                                    String userTitle = "no.message.push.message";
+                                    String userContent = "no.message.push.delivery.personnel.receiving.order";
+                                    if (posOrder.getState() == 4) {
+                                        userContent = "no.message.push.delivery.personnel.qspsz.order";
+                                    } else if (posOrder.getState() == 12) {
+                                        userContent = "no.message.push.delivery.personnel.qsysd.order";
                                     }
-                                    if (!"".equals(shu.getCid()) && posOrder.getState() == 3) {
-                                        logger.info("商家cid:" + user.getCid() + "推送");
-                                        push.shpush(shu.getCid(), MessageUtils.message("no.message.push.message"), MessageUtils.message("no.message.push.new.order"), OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState())));
-                                        pushEventService.PublisherEvent(shu.getUserId(), MessageUtils.message("no.message.push.message"), MessageUtils.message("no.message.push.new.order"), OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState())));
-                                    }
-                                } catch (Exception ex) {
-                                    // 注意:此时事务已提交,失败不会回滚主事务
-                                    logger.error("setOrderQsState, orderId={}", orst.getDdId(), ex);
-                                    // 可在此触发重试/告警/记录Outbox补偿等
-                                    throw new ServiceException("no.action.fail");
+                                    final String finalUserContent = userContent;
+                                    String userBody = OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState()));
+                                    Long userUserId = user.getUserId();
+                                    String userCid = user.getCid();
+                                    String userCidType = "";
+                                    String userDdId = String.valueOf(orst.getDdId());
+                                    AsyncManager.me().execute(new TimerTask() {
+                                        @Override
+                                        public void run() {
+                                            PayPush.userPushHandleLocal(push, pushEventService, userUserId, userCid, userTitle, finalUserContent, userBody, userCidType, userDdId);
+                                        }
+                                    });
+                                }
+                                // 给商家推送(骑手已接单时)
+                                if (!StringUtils.isEmpty(shu.getCid()) && posOrder.getState() == 3) {
+                                    String shTitle = "no.message.push.message";
+                                    String shContent = "no.message.push.delivery.personnel.receiving.order";
+                                    String shBody = OrderPushBodyDto.getJson(String.valueOf(orst.getDdId()), String.valueOf(posOrder.getState()));
+                                    Long shUserId = shu.getUserId();
+                                    String shCid = shu.getCid();
+                                    String shCidType = "";
+                                    String shDdId = String.valueOf(orst.getDdId());
+                                    AsyncManager.me().execute(new TimerTask() {
+                                        @Override
+                                        public void run() {
+                                            PayPush.shPushHandleLocal(push, pushEventService, shUserId, shCid, shTitle, shContent, shBody, shCidType, shDdId);
+                                        }
+                                    });
                                 }
                             }
                         });
@@ -448,6 +470,7 @@ public class PosOrderController extends BaseController {
         }
         boolean org = posOrderService.saveOrUpdate(posOrder);
         if (org) {
+            chuCan(ordera, posOrder);
             PosOrder order = posOrderService.getById(posOrder.getId());
 
             return success(MessageUtils.message("no.modify.success"), posOrder.getId());
@@ -456,6 +479,59 @@ public class PosOrderController extends BaseController {
         }
     }
 
+    /**
+     * 商家出餐推送:给用户和骑手推送通知
+     */
+    private void chuCan(PosOrder oldOrder, PosOrder posOrder) {
+        if (oldOrder.getDiningStatus() != null && oldOrder.getDiningStatus() == 0
+                && posOrder.getDiningStatus() != null && posOrder.getDiningStatus().equals(1L)) {
+            List<Long> ids = new ArrayList<>();
+            ids.add(oldOrder.getUserId());
+            if (oldOrder.getQsId() != null) {
+                ids.add(oldOrder.getQsId());
+            }
+            List<InfoUser> users = infoUserService.list(new LambdaQueryWrapper<InfoUser>().in(InfoUser::getUserId, ids));
+            Optional<InfoUser> user = users.stream().filter(x -> "0".equals(x.getUserType())).findFirst();
+            Optional<InfoUser> qsUser = users.stream().filter(x -> "2".equals(x.getUserType())).findFirst();
+
+            String title = "no.message.push.merchant.ready.title";
+            String content = "no.message.push.merchant.ready.content";
+            Long stateVal = posOrder.getState() != null ? posOrder.getState() : oldOrder.getState();
+            String stateStr = stateVal != null ? String.valueOf(stateVal) : "2";
+            String body = OrderPushBodyDto.getJson(String.valueOf(oldOrder.getDdId()), stateStr);
+            String ddId = String.valueOf(oldOrder.getDdId());
+
+            // 给用户推送
+            if (user.isPresent()) {
+                InfoUser u = user.get();
+                PayPush push = new PayPush();
+                Long uUserId = u.getUserId();
+                String uCid = u.getCid();
+                AsyncManager.me().execute(new TimerTask() {
+                    @Override
+                    public void run() {
+                        PayPush.userPushHandleLocal(push, pushEventService, uUserId, uCid, title, content, body, "", ddId);
+                    }
+                });
+            }
+            // 给骑手推送
+            if (qsUser.isPresent()) {
+                InfoUser qs = qsUser.get();
+                if (!StringUtils.isEmpty(qs.getCid())) {
+                    PayPush push = new PayPush();
+                    Long qsUserId = qs.getUserId();
+                    String qsCid = qs.getCid();
+                    AsyncManager.me().execute(new TimerTask() {
+                        @Override
+                        public void run() {
+                            PayPush.qsPushHandleLocal(push, pushEventService, qsUserId, qsCid, title, content, body, "", ddId);
+                        }
+                    });
+                }
+            }
+        }
+    }
+
     /**
      * 获取预计送达时间
      *

+ 2 - 0
ruoyi-admin/src/main/resources/i18n/messages.properties

@@ -159,4 +159,6 @@ no.points.use.enable=Việc sử dụng điểm đã bị tắt
 no.points.update.fail=Cập nhật ví điểm thất bại, vui lòng thử lại
 no.points.use.fail=Khấu trừ điểm chưa được bật
 no.points.not.exist=Ví điểm của bạn không tồn tại
+no.message.push.merchant.ready.title=Thương gia đã chuẩn bị xong
+no.message.push.merchant.ready.content=Thương gia đã chuẩn bị xong, mã đơn hàng:
 

+ 2 - 0
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties

@@ -165,3 +165,5 @@ no.wallet.noexist.userinfo=User information does not exist
 no.user.state.no.audit=Account status is not audited
 no.system.busy.try.again=System is busy, please try again later
 no.operation.interrupted.try.again=Operation was interrupted, please try again
+no.message.push.merchant.ready.title=Merchant has prepared the order
+no.message.push.merchant.ready.content=Merchant has prepared the order, Order ID:

+ 2 - 0
ruoyi-admin/src/main/resources/i18n/messages_vi.properties

@@ -165,3 +165,5 @@ no.wallet.noexist.userinfo=Thông tin người dùng không tồn tại
 no.user.state.no.audit=Trạng thái tài khoản chưa được xét duyệt
 no.system.busy.try.again=Hệ thống đang bận, vui lòng thử lại sau
 no.operation.interrupted.try.again=Thao tác đã bị gián đoạn, vui lòng thử lại
+no.message.push.merchant.ready.title=Thương gia đã chuẩn bị xong
+no.message.push.merchant.ready.content=Thương gia đã chuẩn bị xong, mã đơn hàng:

+ 2 - 0
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties

@@ -165,3 +165,5 @@ no.wallet.noexist.userinfo=用户信息不存在
 no.user.state.no.audit=账号状态未审核
 no.system.busy.try.again=系统繁忙,请稍后重试
 no.operation.interrupted.try.again=操作被中断,请重试
+no.message.push.merchant.ready.title=商家已经出餐
+no.message.push.merchant.ready.content=商家已经出餐,订单号:

+ 2 - 0
ruoyi-admin/src/main/resources/i18n/messages_zh_TW.properties

@@ -165,3 +165,5 @@ no.wallet.noexist.userinfo=用戶資訊不存在
 no.user.state.no.audit=帳號狀態未審核
 no.system.busy.try.again=系統繁忙,請稍後重試
 no.operation.interrupted.try.again=操作被中斷,請重試
+no.message.push.merchant.ready.title=商家已經出餐
+no.message.push.merchant.ready.content=商家已經出餐,訂單號: