Browse Source

修复微信消息发送异常问题

fuyuchuan 5 days ago
parent
commit
2ef405d085

+ 19 - 7
flow-im/flow-im-entity/src/main/java/com/flow/job/SendUskyJob.java

@@ -2,6 +2,7 @@ package com.flow.job;
 
 import com.flow.entity.Notify;
 import com.flow.entity.User;
+import com.flow.enums.NotifyEnum;
 import com.flow.mapstruct.NotifyRowMapper;
 import dm.jdbc.filter.stat.json.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -59,9 +60,8 @@ public class SendUskyJob {
         int notifySize = notifies.size();
         log.info("需要同步的消息数量为:" + notifySize);
 
-        if (!notifies.isEmpty()) {
+        if (notifySize > 0) {
             sendUsky(notifies);
-            updateNotify(notifies);
         }
 
         // 记录任务结束时间
@@ -82,6 +82,7 @@ public class SendUskyJob {
             String subject = send.getSubject().split("-")[0];
             String processName = send.getSubject().split("-")[1];
             String approvalResult = "";
+            NotifyEnum sendType = send.getType();
 
             log.info("审批单:{}", processName);
             log.info("审批节点:{}", send.getContent());
@@ -103,21 +104,24 @@ public class SendUskyJob {
             }
 
             List<String> userNames = unSend.stream().map(Notify::getSender).collect(Collectors.toList());
-            // Map<String, String> userNamesMap = unSendUser(userNames).stream()
-            //         .collect(Collectors.toMap(User::getUsername, User::getName));
             log.info("查询到的未发送用户: {}", userNames);
-
             List<User> unSendUsers = unSendUser(userNames);
             log.info("查询到未发送的用户信息: {}", unSendUsers);
+
             Map<String, String> userNamesMap = unSendUsers.stream()
-                    .collect(Collectors.toMap(User::getUsername, User::getName));
+                    .filter(user -> user.getUsername() != null && user.getName() != null)
+                    .collect(Collectors.toMap(
+                            User::getUsername, User::getName,
+                            (existingValue, newValue) -> existingValue
+                    ));
+
             log.info("查询到的用户映射: {}", userNamesMap);
 
             if (userNamesMap.containsKey(send.getSender())) {
                 sendJson.put("infoTypeName", "OA审批");
                 sendJson.put("infoType", 3);
                 sendJson.put("infoTitle", "OA审批");
-                sendJson.put("infoContent", userNamesMap.get(send.getSender()) + send.getSubject());
+                sendJson.put("infoContent", send.getSubject());
                 sendJson.put("userName", send.getSender());
                 sendJson.put("userNames", Collections.singletonList(send.getReceiver()));
                 sendJson.put("id", send.getId());
@@ -126,6 +130,12 @@ public class SendUskyJob {
                 sendJson.put("approvalNode", send.getContent());
                 sendJson.put("realName", userNamesMap.get(send.getSender()));
 
+                if ("system".equals(sendType.getType())) {
+                    sendJson.put("oaType", "me");
+                } else {
+                    sendJson.put("oaType", "todo");
+                }
+
                 String sendJsonString = sendJson.toString();
                 log.info("准备发送 {} 的消息:{} ", send.getSender(), sendJsonString);
 
@@ -143,6 +153,8 @@ public class SendUskyJob {
             }
         }
         log.info("消息发送完成,成功数量:" + successCount + ",失败数量:" + failCount);
+        // 更新消息发送状态
+        updateNotify(unSend);
     }
 
     // 查询未发送的消息

+ 2 - 1
flow-workflow/flow-workflow-biz/src/main/java/com/flow/listener/GlobalActivityEventListener.java

@@ -143,6 +143,7 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
                 notify.setContent(entity.getName());
                 notify.setSender(SecurityContextUtil.getUserId());
                 notify.setType(NotifyEnum.TODO);
+                // 接收者 entity.getAssignee() 下一节点的审批人
                 notify.setReceiver(entity.getAssignee());
                 notify.setReceivingTime(LocalDateTime.now());
                 notify.setUrl("/flow/todo");
@@ -212,7 +213,7 @@ public class GlobalActivityEventListener extends AbstractFlowableEngineEventList
                 notify.setUrl("/flow/instance");
                 notifyService.notify(notify);
 
-                log.info("通过{}", (entity.getStartUserId()));
+                log.info("实体开始userId{}", (entity.getStartUserId()));
             }
         });
     }

+ 1 - 1
flow-workflow/flow-workflow-biz/src/main/java/com/flow/service/impl/FlowInstanceServiceImpl.java

@@ -214,7 +214,7 @@ public class FlowInstanceServiceImpl extends BaseServiceImpl<FlowInstanceDao, Fl
         String fromName = form.getFlowDefine().getName();
         notify.setSubject("申请拒绝" + "-" + fromName);
 
-        notify.setSender(SecurityContextUtil.getNickName());
+        notify.setSender(SecurityContextUtil.getUserId());
         notify.setType(NotifyEnum.SYSTEM);
         notify.setReceiver(processInstance.getStartUserId());
         notify.setReceivingTime(LocalDateTime.now());