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/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java |  121 ++++++++++++++++++++++++++++++++--------
 1 files changed, 97 insertions(+), 24 deletions(-)

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()));
             }

--
Gitblit v1.9.1