From 08f95b2f159b56fa3bd4f4b348855989de8aa456 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 18 十二月 2025 21:48:18 +0800
Subject: [PATCH] feat: vehicle

---
 ruoyi-system/src/main/resources/mapper/system/VehicleGpsMapper.xml                          |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java            |   18 ++
 app/pages/index.vue                                                                         |   22 ++
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java                    |    8 +
 ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml                             |    1 
 ruoyi-common/src/main/java/com/ruoyi/common/utils/DeptUtil.java                             |   12 ++
 app/pages/task/index.vue                                                                    |   16 ++
 ruoyi-common/src/main/java/com/ruoyi/common/utils/UserUtil.java                             |   21 +++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java            |  121 ++++++++++++++++----
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java            |   23 +++
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacyTransferSyncServiceImpl.java |   36 +++--
 sql/add_is_head_push_to_sys_task.sql                                                        |    9 +
 ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml                             |    6 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java     |    4 
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java                    |    6 +
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTaskService.java                    |    8 +
 app/pagesTask/detail.vue                                                                    |   16 ++
 ruoyi-system/src/main/resources/mapper/system/VehicleGpsSegmentMileageMapper.xml            |    1 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTask.java                             |   14 ++
 19 files changed, 291 insertions(+), 54 deletions(-)

diff --git a/app/pages/index.vue b/app/pages/index.vue
index f1e687a..b6dbb88 100644
--- a/app/pages/index.vue
+++ b/app/pages/index.vue
@@ -95,9 +95,10 @@
           <view class="task-main" @click="viewTaskDetail(task)">
             <!-- 浠诲姟澶撮儴锛氭爣棰樺拰鐘舵�佹爣绛� -->
             <view class="task-header">
-              <view class="task-title"
-                >{{ getTaskTypeText(task.type) }} - {{ task.vehicle }}</view
-              >
+              <view class="task-title">
+                {{ getTaskTypeText(task.type) }} - {{ task.vehicle }}
+                <text v-if="task.isHeadPush === '1'" class="head-push-tag">鎬�</text>
+              </view>
               <view
                 class="task-status"
                 :class="
@@ -755,18 +756,29 @@
     height: 0 !important;
     background: transparent;
   }
-
+  
   // Firefox婊氬姩鏉¢殣钘�
   * {
     scrollbar-width: none; /* Firefox */
   }
-
+  
   // IE/Edge婊氬姩鏉¢殣钘�
   * {
     -ms-overflow-style: none; /* IE 10+ */
   }
 }
 
+// 鎬婚儴鎺ㄩ�佹爣璁版牱寮�
+.head-push-tag {
+  color: #ff0000;
+  font-size: 24rpx;
+  font-weight: bold;
+  margin-left: 10rpx;
+  padding: 2rpx 8rpx;
+  border: 1rpx solid #ff0000;
+  border-radius: 4rpx;
+}
+
 // 鐢ㄦ埛淇℃伅鍖哄煙
 .user-info-section {
   background-color: white;
diff --git a/app/pages/task/index.vue b/app/pages/task/index.vue
index c1b7a0d..559b246 100644
--- a/app/pages/task/index.vue
+++ b/app/pages/task/index.vue
@@ -112,7 +112,10 @@
             <view class="task-main" @click="viewTaskDetail(task)">
               <!-- 浠诲姟澶撮儴锛氭爣棰樺拰鐘舵�佹爣绛� -->
               <view class="task-header">
-                <view class="task-title">{{ getTaskTypeText(task.taskType) }} - {{ task.vehicle }}</view>
+                <view class="task-title">
+                  {{ getTaskTypeText(task.taskType) }} - {{ task.vehicle }}
+                  <text v-if="task.isHeadPush === '1'" class="head-push-tag">鎬�</text>
+                </view>
                 <view class="task-status" :class="task.taskStatus === 'PENDING' ? 'status-pending' : task.taskStatus === 'DEPARTING' ? 'status-departing' : task.taskStatus === 'ARRIVED' ? 'status-arrived' : task.taskStatus === 'RETURNING' ? 'status-returning' : task.taskStatus === 'COMPLETED' ? 'status-completed' : task.taskStatus === 'CANCELLED' ? 'status-cancelled' : task.taskStatus === 'IN_PROGRESS' ? 'status-in-progress' : 'status-default'">
                   {{ getStatusText(task.taskStatus) }}
                 </view>
@@ -713,6 +716,17 @@
     }
   }
   
+  // 鎬婚儴鎺ㄩ�佹爣璁版牱寮�
+  .head-push-tag {
+    color: #ff0000;
+    font-size: 24rpx;
+    font-weight: bold;
+    margin-left: 10rpx;
+    padding: 2rpx 8rpx;
+    border: 1rpx solid #ff0000;
+    border-radius: 4rpx;
+  }
+  
   // 浠诲姟鍒楄〃鍖哄煙
   .task-list-section {
     flex: 1;
diff --git a/app/pagesTask/detail.vue b/app/pagesTask/detail.vue
index 17289aa..8cf97d9 100644
--- a/app/pagesTask/detail.vue
+++ b/app/pagesTask/detail.vue
@@ -12,7 +12,10 @@
         <view class="section-title">鍩烘湰淇℃伅</view>
         <view class="info-item">
           <view class="label">浠诲姟缂栧彿</view>
-          <view class="value">{{ taskDetail.showTaskCode }}</view>
+          <view class="value">
+            {{ taskDetail.showTaskCode }}
+            <text v-if="taskDetail.isHeadPush === '1'" class="head-push-tag">鎬�</text>
+          </view>
         </view>
         <view class="info-item">
           <view class="label">浠诲姟绫诲瀷</view>
@@ -1461,6 +1464,17 @@
       }
     }
     
+    // 鎬婚儴鎺ㄩ�佹爣璁版牱寮�
+    .head-push-tag {
+      color: #ff0000;
+      font-size: 24rpx;
+      font-weight: bold;
+      margin-left: 10rpx;
+      padding: 2rpx 8rpx;
+      border: 1rpx solid #ff0000;
+      border-radius: 4rpx;
+    }
+    
     .detail-content {
       padding: 20rpx;
       height: calc(100vh - 220rpx); // 鍑忓幓header(100rpx)鍜屾寜閽尯鍩�(120rpx)鐨勯珮搴�
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DeptUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DeptUtil.java
index f9d2e63..ab5c475 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DeptUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DeptUtil.java
@@ -1,5 +1,7 @@
 package com.ruoyi.common.utils;
 
+import java.util.Map;
+
 public class DeptUtil {
 
     /**
@@ -10,4 +12,14 @@
      * 骞垮窞鎬婚儴閮ㄩ棬ID
      */
     public static Long GUANGZHOU_DEPT_ID=101L;
+
+    private static final Map<Long,Long> deptIdBranchIdMap=new java.util.HashMap<>();
+    public static void setDeptIdBranchId(Long deptId,Long branchId){
+        deptIdBranchIdMap.put(deptId, branchId);
+    }
+
+    public static Long getBranchId(Long deptId) {
+        return deptIdBranchIdMap.get(deptId);
+    }
+
 }
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/UserUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/UserUtil.java
new file mode 100644
index 0000000..afdd39f
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/UserUtil.java
@@ -0,0 +1,21 @@
+package com.ruoyi.common.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class UserUtil {
+    /**
+     * 鐢ㄦ埛ID鍜屽垎鍏徃ID鐨勬槧灏勫叧绯�
+     */
+    private static final Map<Long,Long> userIdBranchMap = new HashMap<>();
+    public static void addUserIdBranch(Long userId,Long branchId){
+        if(userId != null && branchId != null && !userIdBranchMap.containsKey(userId)) {
+            userIdBranchMap.put(userId, branchId);
+        }
+    }
+    public static Long getBranchIdByUserId(Long userId){
+        return userIdBranchMap.get(userId);
+    }
+
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTask.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTask.java
index b950aaa..b6e913e 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTask.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysTask.java
@@ -32,6 +32,18 @@
     @Excel(name = "浠诲姟鐘舵��", readConverterExp = "PENDING=寰呭紑濮�,IN_PROGRESS=浠诲姟涓�,COMPLETED=宸插畬鎴�,CANCELLED=宸插彇娑�")
     private String taskStatus;
 
+    /** 鏄惁鎬婚儴鎺ㄩ�� */
+    @Excel(name = "鏄惁鎬婚儴鎺ㄩ��", readConverterExp = "0=鍚�,1=鏄�")
+    private String isHeadPush;
+
+
+    public void setIsHeadPush(String isHeadPush) {
+        this.isHeadPush = isHeadPush;
+    }
+
+    public String getIsHeadPush() {
+        return isHeadPush;
+    }
     /** 浠诲姟鎻忚堪 */
     @Excel(name = "浠诲姟鎻忚堪")
     private String taskDescription;
@@ -88,6 +100,8 @@
     @Excel(name = "鍒涘缓浜篒D")
     private Long creatorId;
 
+
+
     /** 鎵ц浜篒D */
     @Excel(name = "鎵ц浜篒D")
     private Long assigneeId;
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
index c3d1fcc..957c0d4 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
@@ -134,6 +134,14 @@
      * @return 鍒嗗叕鍙稿垪琛�
      */
     public List<SysDept> computeBranchCompaniesForUser(SysUser user);
+
+    /**
+     * 鏍规嵁鐢ㄦ埛ID鏌ヨ鎵�灞炲垎鍏徃 ID
+     * @param deptId 鐢ㄦ埛ID
+     * @return 鍒嗗叕鍙镐俊鎭�
+     */
+    public Long getBranchCompany(Long deptId);
+
     
     /**
      * 鏍规嵁service_class鏌ヨ閮ㄩ棬淇℃伅
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTaskService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTaskService.java
index a5a2a26..0e06417 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTaskService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTaskService.java
@@ -20,6 +20,14 @@
 public interface ISysTaskService {
 
     public Boolean dispatchSyncEvent(Long taskId);
+
+    /**
+     * 鍒ゆ柇浠诲姟鏄惁鎬婚儴鎺ㄩ��
+     * @param taskCreatorId
+     * @param taskDeptId
+     * @return
+     */
+    public Boolean isTaskHeaderPush(Long taskCreatorId,Long taskDeptId);
     /**
      * 鏌ヨ浠诲姟绠$悊
      * 
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
index 233bf16..4f50a2e 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
@@ -202,6 +202,12 @@
     public int resetPwd(SysUser user);
 
     /**
+     * 閫氳繃鐢ㄦ埛ID鏌ヨ鐢ㄦ埛鎵�灞炲叕鍙窱D
+     * @param userId
+     * @return
+     */
+    public Long getBranchCompanyIdByUserId(Long userId);
+    /**
      * 閲嶇疆鐢ㄦ埛瀵嗙爜
      * 
      * @param userName 鐢ㄦ埛鍚�
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacyTransferSyncServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacyTransferSyncServiceImpl.java
index 7bdf8a6..55d2337 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacyTransferSyncServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LegacyTransferSyncServiceImpl.java
@@ -3,6 +3,7 @@
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.LongUtil;
 import com.ruoyi.common.utils.MapValueUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.SysTaskEmergency;
@@ -257,8 +258,14 @@
             }
             SysDept dept=sysDeptService.selectDeptByServiceClass(serviceOrdClass);
             Long deptId=dept==null?null:dept.getDeptId();
+            if(deptId==null){
+                log.error("鍒涘缓浠诲姟鏃讹紝鑾峰彇閮ㄩ棬淇℃伅澶辫触锛宻erviceOrdID={}, DispatchOrdID={}", serviceOrdID, dispatchOrdID);
+                return false;
+            }
+            createTaskVo.setDeptId(deptId);
             TaskUpdateVO updateTaskVo = new TaskUpdateVO();
             BeanUtils.copyProperties(createTaskVo, updateTaskVo);
+
 //            log.info("寮�濮嬩繚瀛樿浆杩愪换鍔�,serviceOrdID={}, DispatchOrdID={}", serviceOrdID, dispatchOrdID);
 
             int result = sysTaskService.updateTask(updateTaskVo,serviceOrdID,dispatchOrdID, serviceOrdNo, taskCreatorId,createUserName, deptId, ServiceOrd_CC_Time, ServiceOrd_CC_Time);
@@ -334,6 +341,11 @@
             String createUserName= sysUser.getUserName();
             SysDept dept=sysDeptService.selectDeptByServiceClass(serviceOrdClass);
             Long deptId=dept==null?null:dept.getDeptId();
+            if(deptId==null){
+                log.error("鍒涘缓浠诲姟鏃讹紝鑾峰彇閮ㄩ棬淇℃伅澶辫触锛宻erviceOrdID={}, DispatchOrdID={} ServiceOrdClass:{}", serviceOrdID, dispatchOrdID, serviceOrdClass);
+                return false;
+            }
+            createTaskVo.setDeptId(deptId);
 
 
             int result = sysTaskService.insertTask(createTaskVo,serviceOrdID,dispatchOrdID, serviceOrdNo, taskCreatorId,createUserName, deptId, ServiceOrd_CC_Time, ServiceOrd_CC_Time);
@@ -370,7 +382,7 @@
     public boolean isTransferOrderSynced(Long serviceOrdID, Long dispatchOrdID) {
         try {
             // 妫�鏌ュ弬鏁版湁鏁堟��
-            if (serviceOrdID == null || serviceOrdID<=0) {
+            if (LongUtil.isEmpty(serviceOrdID)) {
                 log.warn("鏈嶅姟鍗旾D涓嶈兘涓虹┖");
                 return false;
             }
@@ -387,7 +399,7 @@
                 log.warn("鏈嶅姟鍗旾D涓嶆槸鏈夋晥鏁板瓧: {}", serviceOrdID);
             }
             
-            if (dispatchOrdID>0) {
+            if (LongUtil.isNotEmpty(dispatchOrdID)) {
                 try {
                     SysTaskEmergency emergency = sysTaskEmergencyMapper.selectByLegacyDispatchOrdId(dispatchOrdID);
                     if (emergency != null) {
@@ -435,7 +447,7 @@
                 return null;
             }
             
-            if (serviceOrdID==null || serviceOrdID<=0) {
+            if (LongUtil.isEmpty(serviceOrdID)) {
                 log.error("鏈嶅姟鍗旾D涓嶈兘涓虹┖");
                 return null;
             }
@@ -561,7 +573,7 @@
             createTaskVo.setPrice(MapValueUtils.getBigDecimalValue(order, "ServiceOrdTraTxnPrice"));
             // 璺濈淇℃伅闇�瑕佷粠鍏朵粬瀛楁璁$畻鎴栬幏鍙�
 
-            if(dispatchOrdID!=null) {
+            if(LongUtil.isNotEmpty(dispatchOrdID)) {
                 // 璁剧疆鎵ц浜轰俊鎭�
                 List<TaskCreateVO.AssigneeInfo> assignees = queryAssignees(dispatchOrdID);
                 createTaskVo.setAssignees(assignees);
@@ -718,22 +730,16 @@
         long startTime = System.currentTimeMillis();
         try {
             // 妫�鏌ュ弬鏁版湁鏁堟��
-            if (dispatchOrdID==null || dispatchOrdID <= 0) {
+            if (LongUtil.isEmpty(dispatchOrdID)) {
                 log.warn("璋冨害鍗旾D涓嶈兘涓虹┖");
                 return new ArrayList<>();
             }
             
             // 灏哠tring杞崲涓篖ong锛岄伩鍏嶆暟鎹簱绫诲瀷涓嶅尮閰嶅鑷寸殑鎬ц兘闂
-            Long dispatchOrdIdLong;
-            try {
-                dispatchOrdIdLong = Long.valueOf(dispatchOrdID);
-            } catch (NumberFormatException e) {
-                log.error("璋冨害鍗旾D鏍煎紡涓嶆纭�: {}", dispatchOrdID, e);
-                return new ArrayList<>();
-            }
+
             
             // 浠嶴QL Server鏌ヨ鎵ц浜轰俊鎭紙浣跨敤Long绫诲瀷锛屽尮閰岯IGINT瀛楁锛�
-            List<Map<String, Object>> assigneeList = legacyTransferSyncMapper.selectAssigneesByDispatchOrdID(dispatchOrdIdLong);
+            List<Map<String, Object>> assigneeList = legacyTransferSyncMapper.selectAssigneesByDispatchOrdID(dispatchOrdID);
             long queryTime = System.currentTimeMillis() - startTime;
             
             // 璁板綍鎱㈡煡璇紙瓒呰繃500ms锛�
@@ -782,7 +788,7 @@
                 }
             }
             
-            log.debug("鏌ヨ鍒皗}涓墽琛屼汉锛岃皟搴﹀崟ID: {}, 鑰楁椂: {}ms", assignees.size(), dispatchOrdID, System.currentTimeMillis() - startTime);
+//            log.debug("鏌ヨ鍒皗}涓墽琛屼汉锛岃皟搴﹀崟ID: {}, 鑰楁椂: {}ms", assignees.size(), dispatchOrdID, System.currentTimeMillis() - startTime);
             return assignees;
         } catch (Exception e) {
             long totalTime = System.currentTimeMillis() - startTime;
@@ -800,7 +806,7 @@
     private String queryDiseaseIds(Long serviceOrdID) {
         try {
             // 妫�鏌ュ弬鏁版湁鏁堟��
-            if (serviceOrdID==null || serviceOrdID <= 0) {
+            if (LongUtil.isEmpty(serviceOrdID) ) {
                 log.warn("鏈嶅姟鍗旾D涓嶈兘涓虹┖");
                 return null;
             }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
index 9b11a0f..61e9051 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
@@ -86,8 +86,8 @@
             return 0;
         }
 
-        log.info("寮�濮嬪垎鍙戦�氱煡浠诲姟锛宨d={}, taskId={}, userId={}, notifyType={}", 
-                notifyTask.getId(), notifyTask.getTaskId(), notifyTask.getUserId(), notifyTask.getNotifyType());
+//        log.info("寮�濮嬪垎鍙戦�氱煡浠诲姟锛宨d={}, taskId={}, userId={}, notifyType={}",
+//                notifyTask.getId(), notifyTask.getTaskId(), notifyTask.getUserId(), notifyTask.getNotifyType());
 
         // 鏇存柊鐘舵�佷负澶勭悊涓�
         notifyTaskService.markProcessing(notifyTask.getId());
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index d4aac64..3d393c1 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -6,6 +6,8 @@
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
+
+import com.ruoyi.common.utils.DeptUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.common.annotation.DataScope;
@@ -428,7 +430,21 @@
         
         return result;
     }
-    
+
+    @Override
+    public Long getBranchCompany(Long deptId) {
+       Long branchId = DeptUtil.getBranchId(deptId);
+       if(branchId!=null)return branchId;
+        branchId = deptMapper.selectBranchCompanyIdByDeptId(deptId);
+        if(branchId!=null){
+            DeptUtil.setDeptIdBranchId(deptId,branchId);
+            return branchId;
+        }
+        else {
+            return null;
+        }
+    }
+
     /**
      * 鏍规嵁service_class鏌ヨ閮ㄩ棬淇℃伅
      * 
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
index 3caf8c5..596f1cd 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
@@ -8,6 +8,7 @@
 import java.net.URL;
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.*;
 import com.ruoyi.system.domain.vo.*;
@@ -77,8 +78,13 @@
     @Autowired
     private ISysTaskAttachmentService sysTaskAttachmentService;
 
+
+
     @Autowired
-    private SysUserMapper sysUserMapper;
+    private ISysDeptService deptService;
+
+    @Autowired
+    private ISysUserService userService;
 
     @Autowired(required = false)
     private IMapService mapService;
@@ -98,13 +104,16 @@
     @Override
     public Boolean dispatchSyncEvent(Long taskId) {
         SysTask task= sysTaskMapper.selectSysTaskByTaskId(taskId);
-        SysUser user= sysUserMapper.selectUserById(task.getCreatorId());
+        SysUser user= userService.selectUserById(task.getCreatorId());
         Integer oaUser=user.getOaUserId();
         SysTaskEmergency emergency = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId);
         eventPublisher.publishEvent(new TaskDispatchSyncEvent(this, taskId, task.getTaskCode(),emergency.getLegacyServiceOrdId(), emergency.getLegacyDispatchOrdId(),oaUser));
         return true;
     }
 
+    private Long getBranchCompanyId(Long userId) {
+       return userService.getBranchCompanyIdByUserId(userId);
+    }
     /**
      * 鏌ヨ浠诲姟绠$悊
      * 
@@ -115,6 +124,7 @@
     public SysTask selectSysTaskByTaskId(Long taskId) {
         SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId);
         if (task != null) {
+
             // 鍔犺浇鎬ユ晳杞繍鎵╁睍淇℃伅
             if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) {
                 SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId);
@@ -139,12 +149,32 @@
     public List<SysTask> selectSysTaskList(TaskQueryVO queryVO) {
         List<SysTask> tasks= sysTaskMapper.selectSysTaskList(queryVO);
         tasks.forEach(task -> {
+
             if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) {
                 SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(task.getTaskId());
                 task.setEmergencyInfo(emergencyInfo);
             }
         });
         return tasks;
+    }
+
+    /**
+     * 璁剧疆浠诲姟鏄�婚儴鎺ㄩ�佺殑鏍囪
+     * @param taskCreatorId 浠诲姟鍒涘缓浜虹殑鐢ㄦ埛ID
+     * @param taskDeptId 浠诲姟涓殑褰掑睘鏈烘瀯ID
+     */
+    @Override
+    public Boolean isTaskHeaderPush(Long taskCreatorId,Long taskDeptId){
+        if(LongUtil.isEmpty(taskCreatorId))return false;
+        if(LongUtil.isEmpty(taskDeptId))return false ;
+        Long createrDeptId = getBranchCompanyId(taskCreatorId);
+
+        if(createrDeptId !=null && !taskDeptId.equals(createrDeptId) && createrDeptId.equals(DeptUtil.GUANGZHOU_DEPT_ID)){
+            //骞垮窞鎬婚儴鎺ㄩ�佺殑浠诲姟
+           return true;
+        }else{
+            return false;
+        }
     }
 
     /**
@@ -180,6 +210,7 @@
         // Get all tasks matching the other criteria
         List<SysTask> allTasks = sysTaskMapper.selectSysTaskList(newQuery);
         allTasks.stream().forEach(task -> {
+
             if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) {
                 SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(task.getTaskId());
                 task.setEmergencyInfo(emergencyInfo);
@@ -189,6 +220,7 @@
             if (task.getTaskCode() != null && task.getTaskCode().contains(taskCode)) {
                 return true;
             }
+
             if ("EMERGENCY_TRANSFER".equals(task.getTaskType()) && task.getEmergencyInfo() != null) {
                 String dispatchCode = task.getEmergencyInfo().getDispatchCode();
                 String serviceCode = task.getEmergencyInfo().getServiceCode();
@@ -233,6 +265,8 @@
         task.setUpdateTime(DateUtils.getNowDate());
         task.setRemark(createVO.getRemark());
         task.setDelFlag("0");
+
+        task.setIsHeadPush(isTaskHeaderPush(userId,task.getDeptId())?"1":"0");
         
         // 璁剧疆鍦板潃鍜屽潗鏍囦俊鎭�
         setAddressAndCoordinatesFromVO(task, createVO);
@@ -336,6 +370,13 @@
         task.setUpdateBy(userName);
         task.setRemark(createVO.getRemark());
         task.setDelFlag("0");
+
+        Boolean isHeadPush=this.isTaskHeaderPush(userId, deptId);
+        if(isHeadPush){
+            task.setIsHeadPush("1");
+        }else{
+            task.setIsHeadPush("0");
+        }
 
 
         
@@ -456,6 +497,8 @@
         task.setUpdateBy(userName);
         task.setUpdateTime(updateVO.getUpdateTime() != null ? updateVO.getUpdateTime() : DateUtils.getNowDate());
         task.setRemark(updateVO.getRemark());
+
+
         
         // 璁剧疆閫氱敤鍦板潃鍜屽潗鏍囦俊鎭�
         task.setDepartureAddress(updateVO.getDepartureAddress());
@@ -479,13 +522,16 @@
         // 濡傛灉鏇存柊浜嗛儴闂↖D
         if (updateVO.getDeptId() != null) {
             task.setDeptId(updateVO.getDeptId());
+        }else{
+            task.setDeptId(oldTask.getDeptId());
         }
         
         // 濡傛灉鏇存柊浜嗕换鍔$紪鍙�
         if (updateVO.getTaskCode() != null) {
             task.setTaskCode(updateVO.getTaskCode());
         }
-        
+        //璁剧疆鎬婚儴鎺ㄩ��
+        task.setIsHeadPush(this.isTaskHeaderPush(oldTask.getCreatorId(), task.getDeptId())?"1":"0");
         // 鑷姩鑾峰彇鍑哄彂鍦癎PS鍧愭爣锛堝鏋滄洿鏂颁簡鍦板潃浣嗙己澶卞潗鏍囷級
         if (updateVO.getDepartureAddress() != null && 
             (updateVO.getDepartureLongitude() == null || updateVO.getDepartureLatitude() == null) && 
@@ -533,7 +579,7 @@
             task.setAssigneeName(assigneeInfo.getUserName());
         }
         // 鐢ㄤ簬璺熻釜鏄惁闇�瑕侀噸鏂板悓姝ワ紙杞﹁締銆佷汉鍛樸�佸湴鍧�銆佹垚浜や环鍙樻洿锛�
-        boolean needResync = false;
+        boolean needResync = true;
         int result = sysTaskMapper.updateSysTask(task);
         
 
@@ -585,7 +631,10 @@
                 userId, userName);
         }
 
-        if(result > 0 && oldTask.getTaskStatus().equals(TaskStatus.PENDING.getCode()) && updateVO.getAssignees() != null && !updateVO.getAssignees().isEmpty() && dispatchOrderId>0L){
+        if(result > 0 && oldTask.getTaskStatus().equals(TaskStatus.PENDING.getCode())
+                && updateVO.getAssignees() != null
+                && !updateVO.getAssignees().isEmpty()
+                && LongUtil.isNotEmpty(dispatchOrderId)){
 
             this.sendTaskAssigneeEvent(updateVO,oldTask,userId,userName);
         }
@@ -612,11 +661,13 @@
                          Long userId, String userName, Long deptId, Date createTime, Date updateTime) {
 //        log.info("寮�濮嬫洿鏂颁换鍔� ServiceOrdID: {} , dispatchOrdId:{}", serviceOrderId,dispatchOrderId);
         // 閫氳繃鏃х郴缁熸湇鍔″崟ID鏌ユ壘浠诲姟
+        // 鑾峰彇鏃т换鍔′俊鎭紝鐢ㄤ簬鍒ゆ柇鍦板潃鏄惁鍙樻洿
+
+
         SysTaskEmergency taskEmergency = sysTaskEmergencyMapper.selectByLegacyServiceOrdId(serviceOrderId);
         Long taskId = taskEmergency.getTaskId();
+        SysTask task = sysTaskMapper.selectSysTaskByTaskId(taskId);
         updateVO.setTaskId(taskId);
-        SysTask task = new SysTask();
-        task.setTaskId(taskId);
         if(updateVO.getTaskStatus()!=null){
             task.setTaskStatus(updateVO.getTaskStatus());
         }
@@ -629,6 +680,11 @@
         if(updateVO.getActualEndTime() != null) {
             task.setActualEndTime(updateVO.getActualEndTime());
         }
+        if(deptId!=null){
+            task.setDeptId(deptId);
+        }
+
+
 //        task.setAssigneeId(updateVO.getAssigneeId());
         task.setUpdateBy(userName);
         task.setUpdateTime(DateUtils.getNowDate());
@@ -636,12 +692,7 @@
 
         
         // 璁剧疆鍦板潃鍜屽潗鏍囦俊鎭�
-        task.setDepartureAddress(updateVO.getDepartureAddress());
-        task.setDestinationAddress(updateVO.getDestinationAddress());
-        task.setDepartureLongitude(updateVO.getDepartureLongitude());
-        task.setDepartureLatitude(updateVO.getDepartureLatitude());
-        task.setDestinationLongitude(updateVO.getDestinationLongitude());
-        task.setDestinationLatitude(updateVO.getDestinationLatitude());
+
         if(updateVO.getAssignees()!=null && !updateVO.getAssignees().isEmpty()){
             TaskCreateVO.AssigneeInfo assigneeInfo= updateVO.getAssignees().get(0);
             task.setAssigneeId(assigneeInfo.getUserId());
@@ -656,13 +707,18 @@
         if (updateVO.getTaskCode() != null) {
             task.setTaskCode(updateVO.getTaskCode());
         }
-        
-        // 鑾峰彇鏃т换鍔′俊鎭紝鐢ㄤ簬鍒ゆ柇鍦板潃鏄惁鍙樻洿
-        SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(taskId);
-        
+
+
+
+
+//        task.setDepartureLongitude(updateVO.getDepartureLongitude());
+//        task.setDepartureLatitude(updateVO.getDepartureLatitude());
+//        task.setDestinationLongitude(updateVO.getDestinationLongitude());
+//        task.setDestinationLatitude(updateVO.getDestinationLatitude());
+        Boolean modifyOutLongLat = false;
         // 鑷姩鑾峰彇鍑哄彂鍦癎PS鍧愭爣锛堝鏋滃湴鍧�鍙樻洿涓旂己澶卞潗鏍囷級
-        if (oldTask != null && updateVO.getDepartureAddress() != null
-            && !updateVO.getDepartureAddress().equals(oldTask.getDepartureAddress())
+        if (task != null && updateVO.getDepartureAddress() != null
+            && !updateVO.getDepartureAddress().equals(task.getDepartureAddress())
             && (updateVO.getDepartureLongitude() == null || updateVO.getDepartureLatitude() == null)
             && mapService != null) {
             try {
@@ -673,16 +729,23 @@
                 if (coords != null) {
                     task.setDepartureLongitude(BigDecimal.valueOf(coords.get("lng")));
                     task.setDepartureLatitude(BigDecimal.valueOf(coords.get("lat")));
+                    modifyOutLongLat = true;
 //                    log.info("鍑哄彂鍦癎PS鍧愭爣鑷姩鑾峰彇鎴愬姛: {}, {}", coords.get("lng"), coords.get("lat"));
                 }
             } catch (Exception e) {
                 log.error("鑷姩鑾峰彇鍑哄彂鍦癎PS鍧愭爣澶辫触", e);
             }
         }
-        
+        task.setDepartureAddress(updateVO.getDepartureAddress());
+        if(!modifyOutLongLat){
+            task.setDepartureLongitude(updateVO.getDepartureLongitude());
+            task.setDepartureLatitude(updateVO.getDepartureLatitude());
+        }
+
+        Boolean modifyInLongLat = false;
         // 鑷姩鑾峰彇鐩殑鍦癎PS鍧愭爣锛堝鏋滃湴鍧�鍙樻洿涓旂己澶卞潗鏍囷級
-        if (oldTask != null && updateVO.getDestinationAddress() != null
-            && !updateVO.getDestinationAddress().equals(oldTask.getDestinationAddress())
+        if (task != null && updateVO.getDestinationAddress() != null
+            && !updateVO.getDestinationAddress().equals(task.getDestinationAddress())
             && (updateVO.getDestinationLongitude() == null || updateVO.getDestinationLatitude() == null)
             && mapService != null) {
             try {
@@ -693,11 +756,17 @@
                 if (coords != null) {
                     task.setDestinationLongitude(BigDecimal.valueOf(coords.get("lng")));
                     task.setDestinationLatitude(BigDecimal.valueOf(coords.get("lat")));
+                    modifyInLongLat = true;
 //                    log.info("鐩殑鍦癎PS鍧愭爣鑷姩鑾峰彇鎴愬姛: {}, {}", coords.get("lng"), coords.get("lat"));
                 }
             } catch (Exception e) {
                 log.error("鑷姩鑾峰彇鐩殑鍦癎PS鍧愭爣澶辫触", e);
             }
+        }
+        task.setDestinationAddress(updateVO.getDestinationAddress());
+        if(!modifyInLongLat){
+            task.setDestinationLongitude(updateVO.getDestinationLongitude());
+            task.setDestinationLatitude(updateVO.getDestinationLatitude());
         }
         
         int result = sysTaskMapper.updateSysTask(task);
@@ -745,7 +814,10 @@
             dispatchOrderId = emergency.getLegacyDispatchOrdId();
         }
 
-        if(updateVO.getTaskStatus()!=null && updateVO.getTaskStatus().equals(TaskStatus.PENDING.getCode()) && updateVO.getAssignees()!=null && !updateVO.getAssignees().isEmpty() && dispatchOrderId>0L){
+        if(updateVO.getTaskStatus()!=null
+                && updateVO.getTaskStatus().equals(TaskStatus.PENDING.getCode())
+                && updateVO.getAssignees()!=null && !updateVO.getAssignees().isEmpty()
+                && LongUtil.isNotEmpty(dispatchOrderId)){
             this.sendTaskAssigneeEvent(updateVO,task,userId,userName);
         }
 
@@ -758,7 +830,7 @@
         if(task.getTaskStatus()!=null && task.getTaskStatus().equals(TaskStatus.PENDING.getCode())){
             //濡傛灉娌℃湁鍒嗛厤浜哄憳锛屼笖娌℃湁璋冨害鍗曪紝涓嶆槸骞垮窞鎬诲叕鍙哥殑灏遍渶瑕佸彂閫侀�氱煡璺熻繘
             if(LongUtil.isEmpty(dispatchOrderId)){
-                if(!task.getDeptId().equals(DeptUtil.GUANGZHOU_DEPT_ID) && task.getAssignees().isEmpty()){
+                if(!task.getDeptId().equals(DeptUtil.GUANGZHOU_DEPT_ID) && (task.getAssignees()==null  || task.getAssignees().isEmpty())){
                     //鍙戦�侀�氱煡
                     eventPublisher.publishEvent(new TaskOnlyServerOrderSyncEvent(this, taskId, taskCode));
 
@@ -1112,6 +1184,7 @@
     public List<SysTask> selectMyTasks(Long userId) {
         List<SysTask> list = sysTaskMapper.selectMyTasks(userId);
         list.stream().forEach(task -> {
+
             if(task.getTaskType().equals("EMERGENCY_TRANSFER")){
                 task.setEmergencyInfo(sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(task.getTaskId()));
             }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
index e94af7a..8f10be9 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
@@ -4,6 +4,9 @@
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
+
+import com.ruoyi.common.utils.UserUtil;
+import com.ruoyi.system.service.ISysDeptService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -60,6 +63,8 @@
 
     @Autowired
     protected Validator validator;
+    @Autowired
+    private ISysDeptService sysDeptService;
 
     /**
      * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鐢ㄦ埛鍒楄〃
@@ -410,6 +415,24 @@
         return userMapper.updateUser(user);
     }
 
+
+    @Override
+    public Long getBranchCompanyIdByUserId(Long userId) {
+        Long branchId=UserUtil.getBranchIdByUserId(userId);
+        if(branchId!=null)return branchId;
+
+        SysUser u=userMapper.selectUserById(userId);
+        if(u!=null){
+            Long deptId= u.getDeptId();
+            branchId= sysDeptService.getBranchCompany(deptId);
+            if(branchId!=null){
+                UserUtil.addUserIdBranch(userId,branchId);
+                return branchId;
+            }
+        }
+        return null;
+    }
+
     /**
      * 閲嶇疆鐢ㄦ埛瀵嗙爜
      * 
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
index 18aa0a0..6fb4112 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysTaskMapper.xml
@@ -35,6 +35,7 @@
         <result property="assigneeName"     column="assignee_name"     />
         <result property="deptName"         column="dept_name"         />
         <result property="vehicleNo"        column="vehicle_no"        />
+        <result property="isHeadPush"       column="is_head_push"      />
         <collection property="assignedVehicles" ofType="SysTaskVehicle">
             <result property="id"            column="tv_id"             />
             <result property="taskId"        column="tv_task_id"        />
@@ -57,6 +58,7 @@
                t.planned_start_time, t.planned_end_time,
                t.actual_start_time, t.actual_end_time, t.creator_id, t.assignee_id, t.dept_id,
                t.create_time, t.update_time, t.create_by, t.update_by, t.remark, t.del_flag, t.legacy_synced,
+               t.is_head_push,
                u1.nick_name as creator_name, u2.nick_name as assignee_name, d.dept_name,
                (
                    select v2.vehicle_no 
@@ -234,6 +236,7 @@
             <if test="creatorId != null">creator_id,</if>
             <if test="assigneeId != null">assignee_id,</if>
             <if test="deptId != null">dept_id,</if>
+            <if test="isHeadPush != null">is_head_push,</if>
             <if test="createTime != null">create_time,</if>
             update_time,
             <if test="createBy != null">create_by,</if>
@@ -260,6 +263,7 @@
             <if test="creatorId != null">#{creatorId},</if>
             <if test="assigneeId != null">#{assigneeId},</if>
             <if test="deptId != null">#{deptId},</if>
+            <if test="isHeadPush != null">#{isHeadPush},</if>
             <if test="createTime != null">#{createTime},</if>
             now(),
             <if test="createBy != null">#{createBy},</if>
@@ -289,8 +293,8 @@
             <if test="actualEndTime != null">actual_end_time = #{actualEndTime},</if>
             <if test="creatorId != null">creator_id = #{creatorId},</if>
             <if test="assigneeId != null">assignee_id = #{assigneeId},</if>
-
             <if test="deptId != null">dept_id = #{deptId},</if>
+            <if test="isHeadPush != null">is_head_push = #{isHeadPush},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="remark != null">remark = #{remark},</if>
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
index c0abc50..b62ed45 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -172,6 +172,7 @@
  			<if test="status != null and status != ''">status,</if>
  			<if test="oaUserId != null">oa_user_id,</if>
  			<if test="oaOrderClass != null and oaOrderClass != ''">oa_order_class,</if>
+			<if test="canViewAllConsult != null and canViewAllConsult != ''">can_view_all_consult,</if>
  			<if test="qyWechatUserId != null and qyWechatUserId != ''">qy_wechat_user_id,</if>
  			<if test="qyWechatUpdateTime != null">qy_wechat_update_time,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
diff --git a/ruoyi-system/src/main/resources/mapper/system/VehicleGpsMapper.xml b/ruoyi-system/src/main/resources/mapper/system/VehicleGpsMapper.xml
index 650f10e..0aa55dd 100644
--- a/ruoyi-system/src/main/resources/mapper/system/VehicleGpsMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/VehicleGpsMapper.xml
@@ -127,7 +127,6 @@
         where vehicle_id = #{vehicleId}
           and collect_time &gt;= #{startTime}
           and collect_time &lt;= #{endTime}
-        order by collect_time
     </select>
 
     <!-- 鏌ヨ娲昏穬杞﹁締ID锛堜紭鍖栵細浣跨敤GROUP BY鏇夸唬DISTINCT锛屾彁鍗囨�ц兘锛� -->
@@ -135,8 +134,6 @@
         select vehicle_id
         from tb_vehicle_gps
         where collect_time &gt;= #{startTime}
-        group by vehicle_id
-        order by vehicle_id
     </select>
     
     <!-- 鏌ヨ鏈璁$畻鐨凣PS鍧愭爣锛堜紭鍖栵細浣跨敤NOT EXISTS鏇夸唬LEFT JOIN ... IS NULL锛� -->
diff --git a/ruoyi-system/src/main/resources/mapper/system/VehicleGpsSegmentMileageMapper.xml b/ruoyi-system/src/main/resources/mapper/system/VehicleGpsSegmentMileageMapper.xml
index 1762ebd..674cfdd 100644
--- a/ruoyi-system/src/main/resources/mapper/system/VehicleGpsSegmentMileageMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/VehicleGpsSegmentMileageMapper.xml
@@ -67,7 +67,6 @@
           AND segment_start_time &lt;= #{endDate}
           AND segment_end_time &gt;= #{startDate}
           AND segment_distance &gt;0
-        ORDER BY segment_start_time
     </select>
     
     <!-- 鎸変换鍔D鏌ヨ鍒嗘閲岀▼鍒楄〃 -->
diff --git a/sql/add_is_head_push_to_sys_task.sql b/sql/add_is_head_push_to_sys_task.sql
new file mode 100644
index 0000000..63970e8
--- /dev/null
+++ b/sql/add_is_head_push_to_sys_task.sql
@@ -0,0 +1,9 @@
+-- 涓� sys_task 琛ㄦ坊鍔� is_head_push 瀛楁
+-- 鐢ㄤ簬鏍囪浠诲姟鏄惁鐢辨�婚儴鎺ㄩ��
+
+ALTER TABLE sys_task 
+ADD COLUMN is_head_push CHAR(1) DEFAULT '0' COMMENT '鏄惁鎬婚儴鎺ㄩ�侊紙0鍚� 1鏄級';
+
+-- 娣诲姞绱㈠紩浠ユ彁楂樻煡璇㈡�ц兘
+ALTER TABLE sys_task 
+ADD INDEX idx_is_head_push (is_head_push);
\ No newline at end of file

--
Gitblit v1.9.1