From 8cb5d3440208a3be3e772e65f1bd0ec63031ba62 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期三, 17 十二月 2025 08:37:14 +0800
Subject: [PATCH] feat: 增加服务单派发通知

---
 ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 3 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java b/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
index e847ee4..8cc98ed 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/listener/TaskMessageListener.java
@@ -1,7 +1,10 @@
 package com.ruoyi.system.listener;
 
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.utils.DeptUtil;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.event.TaskDispatchSyncEvent;
+import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysTaskAssigneeService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -78,7 +81,8 @@
                List<SysTaskAssignee> assignees=taskAssigneeService.getAssigneesByTaskId(emergency.getTaskId());
                if(assignees!=null && !assignees.isEmpty()){
                    List<Long> assigneeIds=assignees.stream().map(SysTaskAssignee::getUserId).collect(Collectors.toList());
-                   sendDispatchNotify(assigneeIds, task.getCreatorId(), event.getTaskId(), task.getTaskCode(), buildNotifyContent(task, emergency));
+                   task.setEmergencyInfo( emergency);
+                   sendDispatchNotify(assigneeIds, task.getCreatorId(), event.getTaskId(),task.getShowTaskCode(), buildNotifyContent(task, emergency));
                }
             }
 
@@ -129,6 +133,93 @@
     }
 
 
+    @Autowired
+    private ISysDeptService sysDeptService;
+    /**
+     * 鍙湁鏈嶅姟鍗曪紝涓斿彧鍦ㄥ箍宸炲鐨勬湇鍔″崟锛屾病鏈夎皟搴﹀崟
+     * @param event
+     */
+    @Async
+    @EventListener
+    public void handleTaskOnlyServiceSync(TaskDispatchSyncEvent event){
+        //缁欒礋璐d汉鍙戦�佹秷鎭�
+       Long taskId= event.getTaskId();
+       SysTask task=sysTaskMapper.selectSysTaskByTaskId(taskId);
+       SysTaskEmergency emergency = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId);
+       if(emergency != null){
+           task.setEmergencyInfo( emergency);
+           Long deptId=task.getDeptId();
+           if(!deptId.equals(DeptUtil.GUANGZHOU_DEPT_ID)){
+               //鎵惧埌璇ラ儴闂ㄧ殑璐熻矗浜�
+               SysDept dept= sysDeptService.selectDeptById(deptId);
+               if(dept!=null){
+                  String serviceOrdClass= dept.getServiceOrderClass();
+                  String dispatchOrdClass= dept.getDispatchOrderClass();
+                  List<SysUser> user=sysUserMapper.selectUsersByOrderClassAndCanViewAllConsult(serviceOrdClass);
+                  if(user!=null && !user.isEmpty()){
+                      List<NotifyTask> tasks=new ArrayList<>();
+                      String buildNotifyContent = buildUnAssignNotifyContent(task, emergency);
+                      for(SysUser u:user){
+                       NotifyTask notifyTask= this.sendTaskUnAssignNotify(u.getUserId(),u.getNickName(),u.getPhonenumber(),taskId,task.getShowTaskCode(),"鏈嶅姟鍗曟淳鍙�",buildNotifyContent);
+                       tasks.add(notifyTask);
+                      }
+                      if(!tasks.isEmpty()){
+                          int successCount = notifyDispatchService.dispatchNotifies(tasks);
+                          log.info("浠诲姟鏈垎閰嶆秷鎭凡鍙戦�侊紝鍙戦�佹垚鍔熸暟閲忥細{}", successCount);
+                      }
+                  }
+               }
+           }
+
+
+
+       }
+    }
+
+    private  String buildUnAssignNotifyContent(SysTask task, SysTaskEmergency emergency){
+        //娲惧彂鍗曞彿
+        String dispatchCode=emergency.getDispatchCode();
+        String taskCode=task.getTaskCode();
+        String orderCode=dispatchCode;
+        if(dispatchCode==null){
+            orderCode=taskCode;
+        }
+        Date dispatchTime=task.getPlanedStartTime();
+
+        StringBuilder content = new StringBuilder();
+        content.append("鎮ㄦ湁鏂扮殑鏈嶅姟鍗曪紝浠诲姟鍗曞彿:"+orderCode);
+        // 娣诲姞鍑哄彂鍦颁俊鎭�
+        String departure = null;
+        if (emergency != null && StringUtils.isNotEmpty(emergency.getHospitalOutName())) {
+            departure = emergency.getHospitalOutName();
+        } else if (StringUtils.isNotEmpty(task.getDepartureAddress())) {
+            departure = task.getDepartureAddress();
+        }
+        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        content.append("锛屽嚭鍙戞椂闂�:").append(df.format(dispatchTime));
+
+        // 娣诲姞鐩殑鍦颁俊鎭�
+        String destination = null;
+        if (emergency != null && StringUtils.isNotEmpty(emergency.getHospitalInName())) {
+            destination = emergency.getHospitalInName();
+        } else if (StringUtils.isNotEmpty(task.getDestinationAddress())) {
+            destination = task.getDestinationAddress();
+        }
+
+        if (departure != null || destination != null) {
+            if (departure != null) {
+                content.append("鍑哄彂鍦帮細").append(departure);
+            }
+            if (destination != null) {
+                if (content.length() > 0) content.append("锛�");
+                content.append("鐩殑鍦帮細").append(destination);
+            }
+            content.append("锛岃鍙婃椂澶勭悊銆�");
+        }
+
+        return content.toString();
+    }
+
 
     /**
      * 鐩戝惉浠诲姟鍒嗛厤浜嬩欢
@@ -161,7 +252,7 @@
 
             Long creatorId = task.getCreatorId();
             String taskStatus = task.getTaskStatus();
-            
+            task.setEmergencyInfo(emergency);
             // 浠呭湪寰呭噯澶囩姸鎬佷笅鍙戦�侀�氱煡
             if (!TASK_STATUS_PENDING.equals(taskStatus) && !TASK_STATUS_PREPARING.equals(taskStatus)) {
                 log.info("浠诲姟鐘舵��({})闈炲緟鍑嗗鐘舵�侊紝璺宠繃閫氱煡锛宼askId={}", taskStatus, event.getTaskId());
@@ -170,7 +261,7 @@
 
             // 鏋勫缓閫氱煡鍐呭
             String notifyContent = buildNotifyContent(task, emergency);
-            this.sendDispatchNotify(event.getAssigneeIds(), creatorId, event.getTaskId(), event.getTaskCode(), notifyContent);
+            this.sendDispatchNotify(event.getAssigneeIds(), creatorId, event.getTaskId(),task.getShowTaskCode(), notifyContent);
 
             
         } catch (Exception e) {
@@ -237,6 +328,23 @@
                     taskId, createdTasks.size(), successCount);
         }
     }
+
+    private NotifyTask  sendTaskUnAssignNotify(Long userId,String nickName,String phone,
+                            Long taskId,String taskCode,String title,String notifyContent) {
+        NotifyTask notifyTask = new NotifyTask();
+        notifyTask.setTaskId(taskId);
+        notifyTask.setTaskCode(taskCode);
+        notifyTask.setNotifyType(NotifyTask.NOTIFY_TASK_UNASSIGN);
+        notifyTask.setUserId(userId);
+        notifyTask.setUserName(nickName);
+        notifyTask.setUserPhone(phone);
+        notifyTask.setTitle(title);
+        notifyTask.setContent(notifyContent);
+        notifyTask.setCreateBy( "绯荤粺");
+
+        NotifyTask created = notifyTaskService.createNotifyTask(notifyTask);
+        return created;
+    }
     /**
      * 鏋勫缓閫氱煡鍐呭
      */

--
Gitblit v1.9.1