wlzboy
2025-11-29 364adbc9a93a396b74e154f910c2a0a72bfb1a0f
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTaskServiceImpl.java
@@ -2,10 +2,7 @@
import java.io.*;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.util.stream.Collectors;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -39,7 +36,9 @@
import com.ruoyi.system.domain.VehicleInfo;
import com.ruoyi.system.service.ISysTaskService;
import com.ruoyi.system.service.ILegacySystemSyncService;
import com.ruoyi.system.service.ISysTaskEmergencyService;
import com.ruoyi.system.service.ITaskAttachmentSyncService;
import com.ruoyi.system.service.IMapService;
import com.ruoyi.system.event.TaskCreatedEvent;
import com.ruoyi.system.event.TaskAssignedEvent;
import com.ruoyi.system.event.TaskStatusChangedEvent;
@@ -87,6 +86,9 @@
    private ILegacySystemSyncService legacySystemSyncService;
    
    @Autowired
    private ISysTaskEmergencyService sysTaskEmergencyService;
    @Autowired
    private ApplicationEventPublisher eventPublisher;
    
    @Autowired
@@ -97,6 +99,9 @@
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired(required = false)
    private IMapService mapService;
    /**
     * 查询任务管理
@@ -205,6 +210,44 @@
        // 设置福祉车公里数
        if (createVO.getDistance() != null) {
            task.setEstimatedDistance(createVO.getDistance());
        }
        // 自动获取出发地GPS坐标(如果缺失)
        if (task.getDepartureAddress() != null &&
            (task.getDepartureLongitude() == null || task.getDepartureLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    task.getDepartureAddress(),
                    extractCityFromAddress(task.getDepartureAddress())
                );
                if (coords != null) {
                    task.setDepartureLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDepartureLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("出发地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取出发地GPS坐标失败", e);
            }
        }
        // 自动获取目的地GPS坐标(如果缺失)
        if (task.getDestinationAddress() != null &&
            (task.getDestinationLongitude() == null || task.getDestinationLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    task.getDestinationAddress(),
                    extractCityFromAddress(task.getDestinationAddress())
                );
                if (coords != null) {
                    task.setDestinationLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDestinationLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("目的地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取目的地GPS坐标失败", e);
            }
        }
        
        int result = sysTaskMapper.insertSysTask(task);
@@ -382,6 +425,44 @@
            task.setEstimatedDistance(createVO.getDistance());
        }
        
        // 自动获取出发地GPS坐标(如果缺失)
        if (task.getDepartureAddress() != null &&
            (task.getDepartureLongitude() == null || task.getDepartureLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    task.getDepartureAddress(),
                    extractCityFromAddress(task.getDepartureAddress())
                );
                if (coords != null) {
                    task.setDepartureLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDepartureLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("出发地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取出发地GPS坐标失败", e);
            }
        }
        // 自动获取目的地GPS坐标(如果缺失)
        if (task.getDestinationAddress() != null &&
            (task.getDestinationLongitude() == null || task.getDestinationLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    task.getDestinationAddress(),
                    extractCityFromAddress(task.getDestinationAddress())
                );
                if (coords != null) {
                    task.setDestinationLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDestinationLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("目的地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取目的地GPS坐标失败", e);
            }
        }
        int result = sysTaskMapper.insertSysTask(task);
        
        // 保存车辆关联信息
@@ -397,7 +478,7 @@
                taskVehicle.setCreateTime(createTime);
                taskVehicle.setUpdateBy(userName);
                taskVehicle.setUpdateTime(updateTime);
                sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle);
            }
        }
@@ -490,10 +571,178 @@
        task.setUpdateTime(DateUtils.getNowDate());
        task.setRemark(updateVO.getRemark());
        
        // 如果更新了部门ID
        if (updateVO.getDeptId() != null) {
            task.setDeptId(updateVO.getDeptId());
        }
        // 自动获取出发地GPS坐标(如果更新了地址但缺失坐标)
        if (updateVO.getDepartureAddress() != null &&
            (updateVO.getDepartureLongitude() == null || updateVO.getDepartureLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    updateVO.getDepartureAddress(),
                    extractCityFromAddress(updateVO.getDepartureAddress())
                );
                if (coords != null) {
                    task.setDepartureLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDepartureLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("出发地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取出发地GPS坐标失败", e);
            }
        }
        // 自动获取目的地GPS坐标(如果更新了地址但缺失坐标)
        if (updateVO.getDestinationAddress() != null &&
            (updateVO.getDestinationLongitude() == null || updateVO.getDestinationLatitude() == null) &&
            mapService != null) {
            try {
                Map<String, Double> coords = mapService.geocoding(
                    updateVO.getDestinationAddress(),
                    extractCityFromAddress(updateVO.getDestinationAddress())
                );
                if (coords != null) {
                    task.setDestinationLongitude(BigDecimal.valueOf(coords.get("lng")));
                    task.setDestinationLatitude(BigDecimal.valueOf(coords.get("lat")));
                    log.info("目的地GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                }
            } catch (Exception e) {
                log.error("自动获取目的地GPS坐标失败", e);
            }
        }
        // 重新计算预计公里数
        calculateEstimatedDistance(task);
        
        int result = sysTaskMapper.updateSysTask(task);
        // 用于跟踪是否需要重新同步(车辆、人员、地址、成交价变更)
        boolean needResync = false;
        // 更新车辆关联
        if (result > 0 && updateVO.getVehicleIds() != null && !updateVO.getVehicleIds().isEmpty()) {
            // 查询现有的车辆关联
            List<SysTaskVehicle> existingVehicles = sysTaskVehicleMapper.selectSysTaskVehicleByTaskId(updateVO.getTaskId());
            List<Long> existingVehicleIds = existingVehicles.stream()
                .map(SysTaskVehicle::getVehicleId)
                .collect(Collectors.toList());
            // 比较新旧车辆ID列表,判断是否有变化
            boolean vehiclesChanged = !new HashSet<>(existingVehicleIds).equals(new HashSet<>(updateVO.getVehicleIds()));
            // 只有车辆发生变化时才更新
            if (vehiclesChanged) {
                // 删除旧的车辆关联
                sysTaskVehicleMapper.deleteSysTaskVehicleByTaskId(updateVO.getTaskId());
                // 添加新的车辆关联
                Date now = DateUtils.getNowDate();
                String currentUser = SecurityUtils.getUsername();
                for (Long vehicleId : updateVO.getVehicleIds()) {
                    SysTaskVehicle taskVehicle = new SysTaskVehicle();
                    taskVehicle.setTaskId(updateVO.getTaskId());
                    taskVehicle.setVehicleId(vehicleId);
                    taskVehicle.setAssignTime(now);
                    taskVehicle.setAssignBy(currentUser);
                    taskVehicle.setCreateTime(now);
                    sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle);
                }
                // 标记需要重新同步(车辆变更)
                needResync = true;
            }
        }
        // 更新执行人员(检测人员变更)
        if (result > 0 && updateVO.getAssignees() != null) {
            // 查询现有的执行人员
            List<SysTaskAssignee> existingAssignees = sysTaskAssigneeMapper.selectSysTaskAssigneeByTaskId(updateVO.getTaskId());
            List<Long> existingAssigneeIds = existingAssignees.stream()
                .map(SysTaskAssignee::getUserId)
                .collect(Collectors.toList());
            List<Long> newAssigneeIds = updateVO.getAssignees().stream()
                .map(TaskUpdateVO.AssigneeInfo::getUserId)
                .collect(Collectors.toList());
            // 比较新旧执行人员ID列表,判断是否有变化
            boolean assigneesChanged = !new HashSet<>(existingAssigneeIds).equals(new HashSet<>(newAssigneeIds));
            // 只有执行人员发生变化时才更新
            if (assigneesChanged) {
                // 删除旧的执行人员关联
                sysTaskAssigneeMapper.deleteSysTaskAssigneeByTaskId(updateVO.getTaskId());
                // 添加新的执行人员关联
                if (!updateVO.getAssignees().isEmpty()) {
                    // 将 TaskUpdateVO.AssigneeInfo 转换为 TaskCreateVO.AssigneeInfo
                    List<TaskCreateVO.AssigneeInfo> createAssignees = updateVO.getAssignees().stream()
                        .map(assignee -> {
                            TaskCreateVO.AssigneeInfo createAssignee = new TaskCreateVO.AssigneeInfo();
                            createAssignee.setUserId(assignee.getUserId());
                            createAssignee.setUserName(assignee.getUserName());
                            createAssignee.setUserType(assignee.getUserType());
                            return createAssignee;
                        })
                        .collect(Collectors.toList());
                    saveTaskAssignees(updateVO.getTaskId(), createAssignees, SecurityUtils.getUsername());
                }
                // 标记需要重新同步(人员变更)
                needResync = true;
            }
        }
        // 更新急救转运扩展信息(检测地址和成交价变更)
        if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && updateVO.getEmergencyInfo() != null) {
            // 获取旧的急救转运信息
            SysTaskEmergency oldEmergency = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(updateVO.getTaskId());
            // 检测转出医院地址变更
            boolean hospitalOutAddressChanged = false;
            if (updateVO.getEmergencyInfo().getHospitalOutAddress() != null
                && oldEmergency != null
                && !updateVO.getEmergencyInfo().getHospitalOutAddress().equals(oldEmergency.getHospitalOutAddress())) {
                hospitalOutAddressChanged = true;
            }
            // 检测转入医院地址变更
            boolean hospitalInAddressChanged = false;
            if (updateVO.getEmergencyInfo().getHospitalInAddress() != null
                && oldEmergency != null
                && !updateVO.getEmergencyInfo().getHospitalInAddress().equals(oldEmergency.getHospitalInAddress())) {
                hospitalInAddressChanged = true;
            }
            // 检测成交价变更
            boolean transferPriceChanged = false;
            if (updateVO.getEmergencyInfo().getTransferPrice() != null
                && oldEmergency != null
                && oldEmergency.getTransferPrice() != null
                && updateVO.getEmergencyInfo().getTransferPrice().compareTo(oldEmergency.getTransferPrice()) != 0) {
                transferPriceChanged = true;
            }
            // 更新急救转运信息
            updateEmergencyInfo(updateVO.getTaskId(), updateVO);
            // 如果地址或成交价发生变更,标记需要重新同步
            if (hospitalOutAddressChanged || hospitalInAddressChanged || transferPriceChanged) {
                needResync = true;
            }
        }
        // 如果是急救转运任务且有变更,标记需要重新同步
        if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && needResync) {
            try {
                sysTaskEmergencyService.markNeedResync(updateVO.getTaskId());
            } catch (Exception e) {
                // 标记失败不影响主流程
            }
        }
        
        // 记录操作日志
        if (result > 0) {
@@ -703,7 +952,7 @@
                recordTaskLog(taskId, "UPDATE", "上传附件", null, 
                             "上传文件:" + file.getOriginalFilename() + "(分类:" + categoryDesc + ")", 
                             SecurityUtils.getUserId(), SecurityUtils.getUsername());
            }
            
@@ -763,7 +1012,7 @@
                recordTaskLog(taskId, "UPDATE", "上传附件", null, 
                             "通过微信上传文件:" + fileName + "(分类:" + categoryDesc + ")", 
                             SecurityUtils.getUserId(), SecurityUtils.getUsername());
            }
            
@@ -1112,6 +1361,8 @@
            task.setAttachments(attachments);
            // 查询操作日志
            task.setOperationLogs(sysTaskLogMapper.selectSysTaskLogByTaskId(taskId));
            // 查询执行人员列表
            task.setAssignees(sysTaskAssigneeMapper.selectSysTaskAssigneeByTaskId(taskId));
            // 加载急救转运扩展信息
            if ("EMERGENCY_TRANSFER".equals(task.getTaskType())) {
                SysTaskEmergency emergencyInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId);
@@ -1212,6 +1463,30 @@
     */
    private String generateTaskCode() {
        return taskCodeGenerator.generateTaskCode();
    }
    /**
     * 从地址中提取城市名称(用于地图地理编码)
     *
     * @param address 地址
     * @return 城市名称
     */
    private String extractCityFromAddress(String address) {
        if (address == null || address.trim().isEmpty()) {
            return null;
        }
        // 常见城市名列表
        String[] cities = {"广州", "深圳", "东莞", "佛山", "珠海", "惠州", "中山", "江门", "湛江", "肇庆", "清远", "韶关", "梅州", "河源", "潮州", "揭阳", "汕头", "汕尾", "云浮", "阳江","北京","上海","天津"};
        for (String city : cities) {
            if (address.contains(city)) {
                return city;
            }
        }
        return null;
    }
    /**
@@ -1396,8 +1671,27 @@
            emergencyInfo.setHospitalOutDepartmentId(createVO.getHospitalOut().getDepartmentId());
            emergencyInfo.setHospitalOutBedNumber(createVO.getHospitalOut().getBedNumber());
            emergencyInfo.setHospitalOutAddress(createVO.getHospitalOut().getAddress());
            emergencyInfo.setHospitalOutLongitude(createVO.getHospitalOut().getLongitude());
            emergencyInfo.setHospitalOutLatitude(createVO.getHospitalOut().getLatitude());
            // GPS坐标:优先使用前端传入的,否则后端自动获取
            if (createVO.getHospitalOut().getLongitude() != null && createVO.getHospitalOut().getLatitude() != null) {
                emergencyInfo.setHospitalOutLongitude(createVO.getHospitalOut().getLongitude());
                emergencyInfo.setHospitalOutLatitude(createVO.getHospitalOut().getLatitude());
            } else if (mapService != null && createVO.getHospitalOut().getAddress() != null) {
                // 后端自动获取GPS坐标
                try {
                    Map<String, Double> coords = mapService.geocoding(
                        createVO.getHospitalOut().getAddress(),
                        extractCityFromAddress(createVO.getHospitalOut().getAddress())
                    );
                    if (coords != null) {
                        emergencyInfo.setHospitalOutLongitude(BigDecimal.valueOf(coords.get("lng")));
                        emergencyInfo.setHospitalOutLatitude(BigDecimal.valueOf(coords.get("lat")));
                        log.info("转出医院GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                    }
                } catch (Exception e) {
                    log.error("自动获取转出医院GPS坐标失败", e);
                }
            }
        }
        
        // 设置转入医院信息
@@ -1408,8 +1702,27 @@
            emergencyInfo.setHospitalInDepartmentId(createVO.getHospitalIn().getDepartmentId());
            emergencyInfo.setHospitalInBedNumber(createVO.getHospitalIn().getBedNumber());
            emergencyInfo.setHospitalInAddress(createVO.getHospitalIn().getAddress());
            emergencyInfo.setHospitalInLongitude(createVO.getHospitalIn().getLongitude());
            emergencyInfo.setHospitalInLatitude(createVO.getHospitalIn().getLatitude());
            // GPS坐标:优先使用前端传入的,否则后端自动获取
            if (createVO.getHospitalIn().getLongitude() != null && createVO.getHospitalIn().getLatitude() != null) {
                emergencyInfo.setHospitalInLongitude(createVO.getHospitalIn().getLongitude());
                emergencyInfo.setHospitalInLatitude(createVO.getHospitalIn().getLatitude());
            } else if (mapService != null && createVO.getHospitalIn().getAddress() != null) {
                // 后端自动获取GPS坐标
                try {
                    Map<String, Double> coords = mapService.geocoding(
                        createVO.getHospitalIn().getAddress(),
                        extractCityFromAddress(createVO.getHospitalIn().getAddress())
                    );
                    if (coords != null) {
                        emergencyInfo.setHospitalInLongitude(BigDecimal.valueOf(coords.get("lng")));
                        emergencyInfo.setHospitalInLatitude(BigDecimal.valueOf(coords.get("lat")));
                        log.info("转入医院GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                    }
                } catch (Exception e) {
                    log.error("自动获取转入医院GPS坐标失败", e);
                    }
                }
        }
        
        // 设置费用信息
@@ -1441,8 +1754,6 @@
            emergencyInfo.setDispatchSyncStatus(2);
            emergencyInfo.setDispatchSyncTime(new Date());
            emergencyInfo.setDispatchSyncErrorMsg("旧系统同步过来");
        // 系统字段
        }
        // 系统字段
        emergencyInfo.setCreateTime(DateUtils.getNowDate());
@@ -1454,6 +1765,158 @@
    }
    /**
     * 更新急救转运任务扩展信息
     *
     * @param taskId 任务ID
     * @param updateVO 任务更新对象
     */
    private void updateEmergencyInfo(Long taskId, TaskUpdateVO updateVO) {
        // 查询现有的扩展信息
        SysTaskEmergency existingInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId);
        if (existingInfo == null) {
            // 如果不存在,则创建新的
            existingInfo = new SysTaskEmergency();
            existingInfo.setTaskId(taskId);
            existingInfo.setCreateTime(DateUtils.getNowDate());
            existingInfo.setCreateBy(SecurityUtils.getUsername());
        }
        TaskUpdateVO.EmergencyInfoVO emergencyInfo = updateVO.getEmergencyInfo();
        // 更新患者信息
        if (emergencyInfo.getPatientContact() != null) {
            existingInfo.setPatientContact(emergencyInfo.getPatientContact());
        }
        if (emergencyInfo.getPatientPhone() != null) {
            existingInfo.setPatientPhone(emergencyInfo.getPatientPhone());
        }
        if (emergencyInfo.getPatientName() != null) {
            existingInfo.setPatientName(emergencyInfo.getPatientName());
        }
        if (emergencyInfo.getPatientGender() != null) {
            existingInfo.setPatientGender(emergencyInfo.getPatientGender());
        }
        if (emergencyInfo.getPatientIdCard() != null) {
            existingInfo.setPatientIdCard(emergencyInfo.getPatientIdCard());
        }
        if (emergencyInfo.getPatientCondition() != null) {
            existingInfo.setPatientCondition(emergencyInfo.getPatientCondition());
        }
        // 更新转出医院信息
        if (emergencyInfo.getHospitalOutId() != null) {
            existingInfo.setHospitalOutId(emergencyInfo.getHospitalOutId());
        }
        if (emergencyInfo.getHospitalOutName() != null) {
            existingInfo.setHospitalOutName(emergencyInfo.getHospitalOutName());
        }
        if (emergencyInfo.getHospitalOutDepartment() != null) {
            existingInfo.setHospitalOutDepartment(emergencyInfo.getHospitalOutDepartment());
        }
        if (emergencyInfo.getHospitalOutDepartmentId() != null) {
            existingInfo.setHospitalOutDepartmentId(emergencyInfo.getHospitalOutDepartmentId());
        }
        if (emergencyInfo.getHospitalOutBedNumber() != null) {
            existingInfo.setHospitalOutBedNumber(emergencyInfo.getHospitalOutBedNumber());
        }
        if (emergencyInfo.getHospitalOutAddress() != null) {
            existingInfo.setHospitalOutAddress(emergencyInfo.getHospitalOutAddress());
            // 如果更新了地址但没有GPS坐标,后端自动获取
            if (emergencyInfo.getHospitalOutLongitude() == null && emergencyInfo.getHospitalOutLatitude() == null && mapService != null) {
                try {
                    Map<String, Double> coords = mapService.geocoding(
                        emergencyInfo.getHospitalOutAddress(),
                        extractCityFromAddress(emergencyInfo.getHospitalOutAddress())
                    );
                    if (coords != null) {
                        existingInfo.setHospitalOutLongitude(BigDecimal.valueOf(coords.get("lng")));
                        existingInfo.setHospitalOutLatitude(BigDecimal.valueOf(coords.get("lat")));
                        log.info("转出医院GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                    }
                } catch (Exception e) {
                    log.error("自动获取转出医院GPS坐标失败", e);
                }
            }
        }
        if (emergencyInfo.getHospitalOutLongitude() != null) {
            existingInfo.setHospitalOutLongitude(emergencyInfo.getHospitalOutLongitude());
        }
        if (emergencyInfo.getHospitalOutLatitude() != null) {
            existingInfo.setHospitalOutLatitude(emergencyInfo.getHospitalOutLatitude());
        }
        // 更新转入医院信息
        if (emergencyInfo.getHospitalInId() != null) {
            existingInfo.setHospitalInId(emergencyInfo.getHospitalInId());
        }
        if (emergencyInfo.getHospitalInName() != null) {
            existingInfo.setHospitalInName(emergencyInfo.getHospitalInName());
        }
        if (emergencyInfo.getHospitalInDepartment() != null) {
            existingInfo.setHospitalInDepartment(emergencyInfo.getHospitalInDepartment());
        }
        if (emergencyInfo.getHospitalInDepartmentId() != null) {
            existingInfo.setHospitalInDepartmentId(emergencyInfo.getHospitalInDepartmentId());
        }
        if (emergencyInfo.getHospitalInBedNumber() != null) {
            existingInfo.setHospitalInBedNumber(emergencyInfo.getHospitalInBedNumber());
        }
        if (emergencyInfo.getHospitalInAddress() != null) {
            existingInfo.setHospitalInAddress(emergencyInfo.getHospitalInAddress());
            // 如果更新了地址但没有GPS坐标,后端自动获取
            if (emergencyInfo.getHospitalInLongitude() == null && emergencyInfo.getHospitalInLatitude() == null && mapService != null) {
                try {
                    Map<String, Double> coords = mapService.geocoding(
                        emergencyInfo.getHospitalInAddress(),
                        extractCityFromAddress(emergencyInfo.getHospitalInAddress())
                    );
                    if (coords != null) {
                        existingInfo.setHospitalInLongitude(BigDecimal.valueOf(coords.get("lng")));
                        existingInfo.setHospitalInLatitude(BigDecimal.valueOf(coords.get("lat")));
                        log.info("转入医院GPS坐标自动获取成功: {}, {}", coords.get("lng"), coords.get("lat"));
                    }
                } catch (Exception e) {
                    log.error("自动获取转入医院GPS坐标失败", e);
                }
            }
        }
        if (emergencyInfo.getHospitalInLongitude() != null) {
            existingInfo.setHospitalInLongitude(emergencyInfo.getHospitalInLongitude());
        }
        if (emergencyInfo.getHospitalInLatitude() != null) {
            existingInfo.setHospitalInLatitude(emergencyInfo.getHospitalInLatitude());
        }
        // 更新费用信息
        if (emergencyInfo.getTransferDistance() != null) {
            existingInfo.setTransferDistance(emergencyInfo.getTransferDistance());
        }
        if (emergencyInfo.getTransferPrice() != null) {
            existingInfo.setTransferPrice(emergencyInfo.getTransferPrice());
        }
        // 更新病情ID列表
        if (updateVO.getDiseaseIds() != null && !updateVO.getDiseaseIds().isEmpty()) {
            String diseaseIdsStr = updateVO.getDiseaseIds().stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
            existingInfo.setDiseaseIds(diseaseIdsStr);
        } else {
            // 如果病情ID列表为空,清空该字段
            existingInfo.setDiseaseIds(null);
        }
        // 系统字段
        existingInfo.setUpdateTime(DateUtils.getNowDate());
        existingInfo.setUpdateBy(SecurityUtils.getUsername());
        // 执行更新
        sysTaskEmergencyMapper.updateSysTaskEmergency(existingInfo);
    }
    /**
     * 保存福祉车任务扩展信息
     * 
     * @param taskId 任务ID