From 5f2ee03958a1a16dc27195c76ea7cffb422c95d1 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期五, 19 十二月 2025 22:40:34 +0800
Subject: [PATCH] feat: 任务修改接口,删除一些不要的字段同步

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java |   91 ++++++++++++++++++++++++++-------------------
 1 files changed, 53 insertions(+), 38 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 596f1cd..0159840 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
@@ -386,8 +386,8 @@
         if (createVO.getTransferTime() != null) {
             task.setPlannedStartTime(createVO.getTransferTime());
         }
-        if (createVO.getTransferDistance() != null) {
-            task.setEstimatedDistance(createVO.getTransferDistance());
+        if (createVO.getDistance() != null) {
+            task.setEstimatedDistance(createVO.getDistance());
         }
         if (createVO.getPlannedStartTime() != null) {
             task.setPlannedStartTime(createVO.getPlannedStartTime());
@@ -481,14 +481,13 @@
     @Override
     @Transactional
     public int updateSysTask(TaskUpdateVO updateVO, Boolean updateFromLegacy) {
-        SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(updateVO.getTaskId());
-        if (oldTask == null) {
+        SysTask task = sysTaskMapper.selectSysTaskByTaskId(updateVO.getTaskId());
+        if (task == null) {
             throw new RuntimeException("浠诲姟涓嶅瓨鍦�");
         }
         Long userId = SecurityUtils.getUserId();
         String userName = SecurityUtils.getUsername();
-        
-        SysTask task = new SysTask();
+
         task.setTaskId(updateVO.getTaskId());
         task.setTaskDescription(updateVO.getTaskDescription());
         task.setPlannedStartTime(updateVO.getPlannedStartTime());
@@ -500,43 +499,32 @@
 
 
         
-        // 璁剧疆閫氱敤鍦板潃鍜屽潗鏍囦俊鎭�
-        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.getEstimatedDistance() != null) {
             task.setEstimatedDistance(updateVO.getEstimatedDistance());
-        } else if (updateVO.getTransferDistance() != null) {
-            // 鍏煎鎬ユ晳杞繍瀛楁
-            task.setEstimatedDistance(updateVO.getTransferDistance());
         } else if (updateVO.getDistance() != null) {
-            // 鍏煎绂忕杞﹀瓧娈�
+            // 鍏煎鎬ユ晳杞繍瀛楁
             task.setEstimatedDistance(updateVO.getDistance());
         }
         
         // 濡傛灉鏇存柊浜嗛儴闂↖D
         if (updateVO.getDeptId() != null) {
             task.setDeptId(updateVO.getDeptId());
-        }else{
-            task.setDeptId(oldTask.getDeptId());
         }
-        
         // 濡傛灉鏇存柊浜嗕换鍔$紪鍙�
         if (updateVO.getTaskCode() != null) {
             task.setTaskCode(updateVO.getTaskCode());
         }
+        Boolean hasSetDepartureFlag=false;
         //璁剧疆鎬婚儴鎺ㄩ��
-        task.setIsHeadPush(this.isTaskHeaderPush(oldTask.getCreatorId(), task.getDeptId())?"1":"0");
+        task.setIsHeadPush(this.isTaskHeaderPush(task.getCreatorId(), task.getDeptId())?"1":"0");
         // 鑷姩鑾峰彇鍑哄彂鍦癎PS鍧愭爣锛堝鏋滄洿鏂颁簡鍦板潃浣嗙己澶卞潗鏍囷級
         if (updateVO.getDepartureAddress() != null && 
             (updateVO.getDepartureLongitude() == null || updateVO.getDepartureLatitude() == null) && 
             mapService != null) {
-            if (!updateVO.getDepartureAddress().equals(oldTask.getDepartureAddress())) {
+            if (!updateVO.getDepartureAddress().equals(task.getDepartureAddress())) {
                 try {
                     Map<String, Double> coords = mapService.geocoding(
                         updateVO.getDepartureAddress(),
@@ -545,6 +533,7 @@
                     if (coords != null) {
                         task.setDepartureLongitude(BigDecimal.valueOf(coords.get("lng")));
                         task.setDepartureLatitude(BigDecimal.valueOf(coords.get("lat")));
+                        hasSetDepartureFlag = true;
 //                        log.info("鍑哄彂鍦癎PS鍧愭爣鑷姩鑾峰彇鎴愬姛: {}, {}", coords.get("lng"), coords.get("lat"));
                     }
                 } catch (Exception e) {
@@ -552,12 +541,20 @@
                 }
             }
         }
-        
+        // 璁剧疆閫氱敤鍦板潃鍜屽潗鏍囦俊鎭�
+        task.setDepartureAddress(updateVO.getDepartureAddress());
+        if(!hasSetDepartureFlag) {
+
+            task.setDepartureLongitude(updateVO.getDepartureLongitude());
+            task.setDepartureLatitude(updateVO.getDepartureLatitude());
+        }
+
+        Boolean hasSetDestinationFlag=false;
         // 鑷姩鑾峰彇鐩殑鍦癎PS鍧愭爣锛堝鏋滄洿鏂颁簡鍦板潃浣嗙己澶卞潗鏍囷級
         if (updateVO.getDestinationAddress() != null && 
             (updateVO.getDestinationLongitude() == null || updateVO.getDestinationLatitude() == null) && 
             mapService != null) {
-            if (!updateVO.getDestinationAddress().equals(oldTask.getDestinationAddress())) {
+            if (!updateVO.getDestinationAddress().equals(task.getDestinationAddress())) {
                 try {
                     Map<String, Double> coords = mapService.geocoding(
                         updateVO.getDestinationAddress(),
@@ -566,6 +563,7 @@
                     if (coords != null) {
                         task.setDestinationLongitude(BigDecimal.valueOf(coords.get("lng")));
                         task.setDestinationLatitude(BigDecimal.valueOf(coords.get("lat")));
+                        hasSetDestinationFlag = true;
 //                        log.info("鐩殑鍦癎PS鍧愭爣鑷姩鑾峰彇鎴愬姛: {}, {}", coords.get("lng"), coords.get("lat"));
                     }
                 } catch (Exception e) {
@@ -573,6 +571,12 @@
                 }
             }
         }
+        task.setDestinationAddress(updateVO.getDestinationAddress());
+        if(!hasSetDestinationFlag) {
+            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());
@@ -593,7 +597,8 @@
                 needResync = true;
             }
         }
-        
+
+
         // 鏇存柊鎵ц浜哄憳锛堟娴嬩汉鍛樺彉鏇达級
         if (result > 0 && updateVO.getAssignees() != null) {
             boolean assigneesChanged = sysTaskAssigneeService.updateTaskAssignees(
@@ -605,43 +610,52 @@
         }
         Long dispatchOrderId=0L;
         // 鏇存柊鎬ユ晳杞繍鎵╁睍淇℃伅锛堟娴嬪湴鍧�鍜屾垚浜や环鍙樻洿锛�
-        if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType())) {
+        if (result > 0 && "EMERGENCY_TRANSFER".equals(task.getTaskType())) {
             SysTaskEmergency oldEmergency = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(updateVO.getTaskId());
             sysEmergencyTaskService.updateEmergencyInfoFromUpdateVO(oldEmergency, updateVO, userName);
           dispatchOrderId=  oldEmergency.getLegacyDispatchOrdId();
-            sysEmergencyTaskService.markNeedResyncIfNecessary(updateVO.getTaskId(), oldTask, updateVO, updateFromLegacy);
+
+            markNeedSync(task,updateVO);
         }
         
         // 鏇存柊绂忕杞︽墿灞曚俊鎭�
-        if (result > 0 && "WELFARE".equals(oldTask.getTaskType())) {
+        if (result > 0 && "WELFARE".equals(task.getTaskType())) {
             if (updateVO.getPassenger() != null || updateVO.getStartAddress() != null || updateVO.getEndAddress() != null) {
                 sysWelfareTaskService.updateWelfareInfo(updateVO.getTaskId(), updateVO, userName);
             }
         }
         
-        // 濡傛灉鏄�ユ晳杞繍浠诲姟涓旀湁鍙樻洿锛屾爣璁伴渶瑕侀噸鏂板悓姝�
-        if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && needResync && !updateFromLegacy) {
-            sysEmergencyTaskService.markNeedResyncIfNecessary(updateVO.getTaskId(), oldTask, updateVO, updateFromLegacy);
-        }
+
         
         // 璁板綍鎿嶄綔鏃ュ織
         if (result > 0) {
             recordTaskLog(updateVO.getTaskId(), "UPDATE", "鏇存柊浠诲姟",
-                buildTaskDescription(oldTask), buildTaskDescription(task),
+                buildTaskDescription(task), buildTaskDescription(task),
                 userId, userName);
         }
 
-        if(result > 0 && oldTask.getTaskStatus().equals(TaskStatus.PENDING.getCode())
+        if(result > 0 && task.getTaskStatus().equals(TaskStatus.PENDING.getCode())
                 && updateVO.getAssignees() != null
                 && !updateVO.getAssignees().isEmpty()
                 && LongUtil.isNotEmpty(dispatchOrderId)){
 
-            this.sendTaskAssigneeEvent(updateVO,oldTask,userId,userName);
+            this.sendTaskAssigneeEvent(updateVO,task,userId,userName);
         }
 
         return result;
     }
 
+
+    private void markNeedSync(SysTask sysTask,TaskUpdateVO updateVO){
+        // 濡傛灉鏄�ユ晳杞繍浠诲姟涓旀湁鍙樻洿锛屾爣璁伴渶瑕侀噸鏂板悓姝�
+        if ( "EMERGENCY_TRANSFER".equals(sysTask.getTaskType()) ) {
+
+            sysEmergencyTaskService.markNeedResyncIfNecessary(updateVO.getTaskId(), sysTask, updateVO, true);
+
+            eventPublisher.publishEvent(new TaskUpdateEvent(this,sysTask.getTaskId(),
+                    sysTask.getTaskCode(),sysTask.getTaskType()));
+        }
+    }
     /**
      * 鏇存柊浠诲姟锛堢敤浜庢棫绯荤粺鍚屾锛�
      * 
@@ -803,7 +817,8 @@
             }
             taskEmergency.setUpdateTime(DateUtils.getNowDate());
 
-            Boolean hasEmergencyInfo = updateVO.getHospitalOut() != null || updateVO.getHospitalIn() != null || updateVO.getPatient() != null;
+            Boolean hasEmergencyInfo = updateVO.getHospitalOut() != null || updateVO.getHospitalIn() != null || updateVO.getPatient() != null
+                    || updateVO.getPrice() != null || updateVO.getDistance() != null;
 
 
             // 浣跨敤TaskCreateVO鐨勫瓧娈垫潵鏇存柊鎬ユ晳杞繍淇℃伅
@@ -1426,8 +1441,8 @@
         if (createVO.getTransferTime() != null) {
             task.setPlannedStartTime(createVO.getTransferTime());
         }
-        if (createVO.getTransferDistance() != null) {
-            task.setEstimatedDistance(createVO.getTransferDistance());
+        if (createVO.getDistance() != null) {
+            task.setEstimatedDistance(createVO.getDistance());
         }
         
         // 璁剧疆绂忕杞︾壒瀹氫俊鎭�

--
Gitblit v1.9.1