| | |
| | | import java.net.URL; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.system.domain.vo.*; |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.utils.TaskCodeGenerator; |
| | | import com.ruoyi.common.config.ImageUrlConfig; |
| | |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.domain.SysTaskWelfare; |
| | | import com.ruoyi.system.domain.SysTaskAssignee; |
| | | import com.ruoyi.system.domain.vo.TaskQueryVO; |
| | | import com.ruoyi.system.domain.vo.TaskCreateVO; |
| | | import com.ruoyi.system.domain.vo.TaskUpdateVO; |
| | | import com.ruoyi.system.domain.vo.TaskStatisticsVO; |
| | | import com.ruoyi.system.domain.enums.TaskStatus; |
| | | import com.ruoyi.system.domain.VehicleInfo; |
| | | import com.ruoyi.system.service.ISysTaskService; |
| | |
| | | taskVehicle.setTaskId(task.getTaskId()); |
| | | taskVehicle.setVehicleId(vehicleId); |
| | | taskVehicle.setAssignTime(DateUtils.getNowDate()); |
| | | taskVehicle.setAssignBy(SecurityUtils.getUsername()); |
| | | taskVehicle.setAssignBy(username); |
| | | taskVehicle.setStatus("ASSIGNED"); |
| | | taskVehicle.setCreateBy(SecurityUtils.getUsername()); |
| | | taskVehicle.setCreateBy(username); |
| | | taskVehicle.setCreateTime(DateUtils.getNowDate()); |
| | | taskVehicle.setUpdateBy(SecurityUtils.getUsername()); |
| | | taskVehicle.setUpdateBy(username); |
| | | taskVehicle.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle); |
| | |
| | | |
| | | // 保存急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType())) { |
| | | saveEmergencyInfo(task.getTaskId(),username, createVO,null,null); |
| | | saveEmergencyInfo(task.getTaskId(),username, createVO,null,null,null); |
| | | } |
| | | |
| | | // 保存福祉车扩展信息 |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int insertTask(TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId, Long userId,String userName, Long deptId, Date createTime, Date updateTime) { |
| | | public int insertTask(TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId, String serviceOrdNo, Long userId,String userName, Long deptId, Date createTime, Date updateTime) { |
| | | SysTask task = new SysTask(); |
| | | if(createVO.getTaskCode()!=null){ |
| | | task.setTaskCode(createVO.getTaskCode()); |
| | |
| | | |
| | | // 保存急救转运扩展信息 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(createVO.getTaskType())) { |
| | | saveEmergencyInfo(task.getTaskId(),userName, createVO, serviceOrderId, dispatchOrderId); |
| | | saveEmergencyInfo(task.getTaskId(),userName, createVO, serviceOrderId, dispatchOrderId, serviceOrdNo); |
| | | } |
| | | |
| | | // 保存福祉车扩展信息 |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int updateSysTask(TaskUpdateVO updateVO) { |
| | | public int updateSysTask(TaskUpdateVO updateVO, Boolean updateFromLegacy) { |
| | | SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(updateVO.getTaskId()); |
| | | if (oldTask == null) { |
| | | throw new RuntimeException("任务不存在"); |
| | | } |
| | | String userName = SecurityUtils.getUsername(); |
| | | |
| | | SysTask task = new SysTask(); |
| | | task.setTaskId(updateVO.getTaskId()); |
| | | task.setTaskDescription(updateVO.getTaskDescription()); |
| | | task.setPlannedStartTime(updateVO.getPlannedStartTime()); |
| | | task.setPlannedEndTime(updateVO.getPlannedEndTime()); |
| | | task.setAssigneeId(updateVO.getAssigneeId()); |
| | | task.setUpdateBy(userName); |
| | | task.setUpdateTime(updateVO.getUpdateTime() != null ? updateVO.getUpdateTime() : DateUtils.getNowDate()); |
| | | task.setRemark(updateVO.getRemark()); |
| | | |
| | | // 设置通用地址和坐标信息 |
| | | task.setDepartureAddress(updateVO.getDepartureAddress()); |
| | | task.setDestinationAddress(updateVO.getDestinationAddress()); |
| | | task.setDepartureLongitude(updateVO.getDepartureLongitude()); |
| | | task.setDepartureLatitude(updateVO.getDepartureLatitude()); |
| | | task.setDestinationLongitude(updateVO.getDestinationLongitude()); |
| | | task.setDestinationLatitude(updateVO.getDestinationLatitude()); |
| | | task.setPlannedStartTime(updateVO.getPlannedStartTime()); |
| | | task.setPlannedEndTime(updateVO.getPlannedEndTime()); |
| | | task.setAssigneeId(updateVO.getAssigneeId()); |
| | | task.setUpdateBy(SecurityUtils.getUsername()); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | task.setRemark(updateVO.getRemark()); |
| | | |
| | | // 设置预计距离 |
| | | 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()); |
| | | } |
| | | |
| | | // 如果更新了部门ID |
| | | if (updateVO.getDeptId() != null) { |
| | | task.setDeptId(updateVO.getDeptId()); |
| | | } |
| | | |
| | | // 如果更新了任务编号 |
| | | if (updateVO.getTaskCode() != null) { |
| | | task.setTaskCode(updateVO.getTaskCode()); |
| | | } |
| | | |
| | | // 自动获取出发地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")); |
| | | if (!updateVO.getDepartureAddress().equals(oldTask.getDepartureAddress())) { |
| | | 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); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("自动获取出发地GPS坐标失败", e); |
| | | } |
| | | } |
| | | |
| | |
| | | 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")); |
| | | if (!updateVO.getDestinationAddress().equals(oldTask.getDestinationAddress())) { |
| | | 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); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("自动获取目的地GPS坐标失败", e); |
| | | } |
| | | } |
| | | |
| | | // 重新计算预计公里数 |
| | | calculateEstimatedDistance(task); |
| | | |
| | | // 用于跟踪是否需要重新同步(车辆、人员、地址、成交价变更) |
| | | boolean needResync = true; |
| | | int result = sysTaskMapper.updateSysTask(task); |
| | | |
| | | // 用于跟踪是否需要重新同步(车辆、人员、地址、成交价变更) |
| | | boolean needResync = false; |
| | | |
| | | |
| | | // 更新车辆关联 |
| | | if (result > 0 && updateVO.getVehicleIds() != null && !updateVO.getVehicleIds().isEmpty()) { |
| | |
| | | |
| | | // 添加新的车辆关联 |
| | | Date now = DateUtils.getNowDate(); |
| | | String currentUser = SecurityUtils.getUsername(); |
| | | String currentUser = userName; |
| | | for (Long vehicleId : updateVO.getVehicleIds()) { |
| | | SysTaskVehicle taskVehicle = new SysTaskVehicle(); |
| | | taskVehicle.setTaskId(updateVO.getTaskId()); |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Long> newAssigneeIds = updateVO.getAssignees().stream() |
| | | .map(TaskUpdateVO.AssigneeInfo::getUserId) |
| | | .map(TaskCreateVO.AssigneeInfo::getUserId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 比较新旧执行人员ID列表,判断是否有变化 |
| | |
| | | |
| | | // 添加新的执行人员关联 |
| | | 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()); |
| | | saveTaskAssignees(updateVO.getTaskId(), updateVO.getAssignees(), userName); |
| | | } |
| | | |
| | | // 标记需要重新同步(人员变更) |
| | |
| | | } |
| | | |
| | | // 更新急救转运扩展信息(检测地址和成交价变更) |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && updateVO.getEmergencyInfo() != null) { |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType())) { |
| | | // 获取旧的急救转运信息 |
| | | SysTaskEmergency oldEmergency = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(updateVO.getTaskId()); |
| | | |
| | | // 检测转出医院地址变更 |
| | | boolean hospitalOutAddressChanged = false; |
| | | if (updateVO.getEmergencyInfo().getHospitalOutAddress() != null |
| | | && oldEmergency != null |
| | | && !updateVO.getEmergencyInfo().getHospitalOutAddress().equals(oldEmergency.getHospitalOutAddress())) { |
| | | if (updateVO.getHospitalOut() != null && updateVO.getHospitalOut().getAddress() != null |
| | | && oldEmergency != null |
| | | && !updateVO.getHospitalOut().getAddress().equals(oldEmergency.getHospitalOutAddress())) { |
| | | hospitalOutAddressChanged = true; |
| | | } |
| | | |
| | | // 检测转入医院地址变更 |
| | | boolean hospitalInAddressChanged = false; |
| | | if (updateVO.getEmergencyInfo().getHospitalInAddress() != null |
| | | && oldEmergency != null |
| | | && !updateVO.getEmergencyInfo().getHospitalInAddress().equals(oldEmergency.getHospitalInAddress())) { |
| | | if (updateVO.getHospitalIn() != null && updateVO.getHospitalIn().getAddress() != null |
| | | && oldEmergency != null |
| | | && !updateVO.getHospitalIn().getAddress().equals(oldEmergency.getHospitalInAddress())) { |
| | | hospitalInAddressChanged = true; |
| | | } |
| | | |
| | | // 检测成交价变更 |
| | | boolean transferPriceChanged = false; |
| | | if (updateVO.getEmergencyInfo().getTransferPrice() != null |
| | | && oldEmergency != null |
| | | if (updateVO.getPrice() != null |
| | | && oldEmergency != null |
| | | && oldEmergency.getTransferPrice() != null |
| | | && updateVO.getEmergencyInfo().getTransferPrice().compareTo(oldEmergency.getTransferPrice()) != 0) { |
| | | && updateVO.getPrice().compareTo(oldEmergency.getTransferPrice()) != 0) { |
| | | transferPriceChanged = true; |
| | | } |
| | | |
| | | ; |
| | | |
| | | // 更新急救转运信息 |
| | | updateEmergencyInfo(updateVO.getTaskId(), updateVO); |
| | | if (updateVO.getHospitalOut() != null || updateVO.getHospitalIn() != null || updateVO.getPatient() != null) { |
| | | updateEmergencyInfoFromCreateVO(updateVO.getTaskId(), updateVO, userName); |
| | | } |
| | | |
| | | // 如果地址或成交价发生变更,标记需要重新同步 |
| | | if (hospitalOutAddressChanged || hospitalInAddressChanged || transferPriceChanged) { |
| | |
| | | } |
| | | } |
| | | |
| | | // 更新福祉车扩展信息 |
| | | if (result > 0 && "WELFARE".equals(oldTask.getTaskType())) { |
| | | if (updateVO.getPassenger() != null || updateVO.getStartAddress() != null || updateVO.getEndAddress() != null) { |
| | | updateWelfareInfoFromCreateVO(updateVO.getTaskId(), updateVO, userName); |
| | | } |
| | | } |
| | | |
| | | // 如果是急救转运任务且有变更,标记需要重新同步 |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && needResync) { |
| | | if (result > 0 && "EMERGENCY_TRANSFER".equals(oldTask.getTaskType()) && needResync && !updateFromLegacy) { |
| | | try { |
| | | sysTaskEmergencyService.markNeedResync(updateVO.getTaskId()); |
| | | } catch (Exception e) { |
| | |
| | | |
| | | // 记录操作日志 |
| | | if (result > 0) { |
| | | recordTaskLog(updateVO.getTaskId(), "UPDATE", "更新任务", |
| | | buildTaskDescription(oldTask), buildTaskDescription(task), |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | recordTaskLog(updateVO.getTaskId(), "UPDATE", "更新任务", |
| | | buildTaskDescription(oldTask), buildTaskDescription(task), |
| | | SecurityUtils.getUserId(), userName); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 更新任务(用于旧系统同步) |
| | | * |
| | | * @param updateVO 任务更新对象 |
| | | * @param serviceOrderId 旧系统服务单ID |
| | | * @param dispatchOrderId 旧系统调度单ID |
| | | * @param serviceOrdNo 旧系统服务单编号 |
| | | * @param userId 用户ID |
| | | * @param userName 用户名 |
| | | * @param deptId 部门ID |
| | | * @param createTime 创建时间 |
| | | * @param updateTime 更新时间 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateTask(TaskUpdateVO updateVO, String serviceOrderId, String dispatchOrderId, String serviceOrdNo, |
| | | Long userId, String userName, Long deptId, Date createTime, Date updateTime) { |
| | | // 通过旧系统服务单ID查找任务 |
| | | SysTaskEmergency taskEmergency = sysTaskEmergencyMapper.selectByLegacyServiceOrdId(Long.parseLong(serviceOrderId)); |
| | | Long taskId = taskEmergency.getTaskId(); |
| | | updateVO.setTaskId(taskId); |
| | | SysTask task = new SysTask(); |
| | | task.setTaskId(taskId); |
| | | task.setTaskDescription(updateVO.getTaskDescription()); |
| | | task.setPlannedStartTime(updateVO.getPlannedStartTime()); |
| | | task.setPlannedEndTime(updateVO.getPlannedEndTime()); |
| | | task.setAssigneeId(updateVO.getAssigneeId()); |
| | | task.setUpdateBy(userName); |
| | | task.setUpdateTime(DateUtils.getNowDate()); |
| | | task.setRemark(updateVO.getRemark()); |
| | | |
| | | |
| | | // 设置地址和坐标信息 |
| | | task.setDepartureAddress(updateVO.getDepartureAddress()); |
| | | task.setDestinationAddress(updateVO.getDestinationAddress()); |
| | | task.setDepartureLongitude(updateVO.getDepartureLongitude()); |
| | | task.setDepartureLatitude(updateVO.getDepartureLatitude()); |
| | | task.setDestinationLongitude(updateVO.getDestinationLongitude()); |
| | | task.setDestinationLatitude(updateVO.getDestinationLatitude()); |
| | | |
| | | // 如果更新了部门ID |
| | | if (updateVO.getDeptId() != null) { |
| | | task.setDeptId(updateVO.getDeptId()); |
| | | } |
| | | |
| | | // 如果更新了任务编号 |
| | | if (updateVO.getTaskCode() != null) { |
| | | task.setTaskCode(updateVO.getTaskCode()); |
| | | } |
| | | |
| | | // 获取旧任务信息,用于判断地址是否变更 |
| | | SysTask oldTask = sysTaskMapper.selectSysTaskByTaskId(taskId); |
| | | |
| | | // 自动获取出发地GPS坐标(如果地址变更且缺失坐标) |
| | | if (oldTask != null && updateVO.getDepartureAddress() != null |
| | | && !updateVO.getDepartureAddress().equals(oldTask.getDepartureAddress()) |
| | | && (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 (oldTask != null && updateVO.getDestinationAddress() != null |
| | | && !updateVO.getDestinationAddress().equals(oldTask.getDestinationAddress()) |
| | | && (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); |
| | | } |
| | | } |
| | | |
| | | int result = sysTaskMapper.updateSysTask(task); |
| | | |
| | | // 更新车辆关联 |
| | | if (result > 0 && updateVO.getVehicleIds() != null && !updateVO.getVehicleIds().isEmpty()) { |
| | | // 查询现有的车辆关联 |
| | | List<SysTaskVehicle> existingVehicles = sysTaskVehicleMapper.selectSysTaskVehicleByTaskId(taskId); |
| | | 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(taskId); |
| | | |
| | | // 添加新的车辆关联 |
| | | Date now = DateUtils.getNowDate(); |
| | | for (Long vehicleId : updateVO.getVehicleIds()) { |
| | | SysTaskVehicle taskVehicle = new SysTaskVehicle(); |
| | | taskVehicle.setTaskId(taskId); |
| | | taskVehicle.setVehicleId(vehicleId); |
| | | taskVehicle.setAssignTime(now); |
| | | taskVehicle.setAssignBy(userName); |
| | | taskVehicle.setCreateTime(now); |
| | | sysTaskVehicleMapper.insertSysTaskVehicle(taskVehicle); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 更新执行人员(检测人员变更) |
| | | if (result > 0 && updateVO.getAssignees() != null) { |
| | | // 查询现有的执行人员 |
| | | List<SysTaskAssignee> existingAssignees = sysTaskAssigneeMapper.selectSysTaskAssigneeByTaskId(taskId); |
| | | List<Long> existingAssigneeIds = existingAssignees.stream() |
| | | .map(SysTaskAssignee::getUserId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Long> newAssigneeIds = updateVO.getAssignees().stream() |
| | | .map(TaskCreateVO.AssigneeInfo::getUserId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 比较新旧执行人员ID列表,判断是否有变化 |
| | | boolean assigneesChanged = !new HashSet<>(existingAssigneeIds).equals(new HashSet<>(newAssigneeIds)); |
| | | |
| | | // 只有执行人员发生变化时才更新 |
| | | if (assigneesChanged) { |
| | | // 删除旧的执行人员关联 |
| | | sysTaskAssigneeMapper.deleteSysTaskAssigneeByTaskId(taskId); |
| | | |
| | | // 添加新的执行人员关联 |
| | | if (!updateVO.getAssignees().isEmpty()) { |
| | | saveTaskAssignees(taskId, updateVO.getAssignees(), userName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 更新急救转运扩展信息 |
| | | if (result > 0) { |
| | | // 更新旧系统ID |
| | | if (serviceOrderId != null) { |
| | | taskEmergency.setLegacyServiceOrdId(Long.parseLong(serviceOrderId)); |
| | | } |
| | | if (dispatchOrderId != null) { |
| | | taskEmergency.setLegacyDispatchOrdId(Long.parseLong(dispatchOrderId)); |
| | | } |
| | | if (serviceOrdNo != null) { |
| | | taskEmergency.setLegacyServiceOrdNo(serviceOrdNo); |
| | | } |
| | | |
| | | // 使用TaskCreateVO的字段来更新急救转运信息 |
| | | if (updateVO.getHospitalOut() != null || updateVO.getHospitalIn() != null || updateVO.getPatient() != null) { |
| | | updateEmergencyInfoFromCreateVO(taskId, updateVO, userName); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int assignVehicleToTask(Long taskId, Long vehicleId, String remark) { |
| | | public int assignVehicleToTask(Long taskId, Long vehicleId, String remark,Long userId,String userName) { |
| | | // 检查是否已经分配 |
| | | int exists = sysTaskVehicleMapper.checkTaskVehicleExists(taskId, vehicleId); |
| | | if (exists > 0) { |
| | |
| | | taskVehicle.setTaskId(taskId); |
| | | taskVehicle.setVehicleId(vehicleId); |
| | | taskVehicle.setAssignTime(DateUtils.getNowDate()); |
| | | taskVehicle.setAssignBy(SecurityUtils.getUsername()); |
| | | taskVehicle.setAssignBy(userName); |
| | | taskVehicle.setStatus("ASSIGNED"); |
| | | taskVehicle.setRemark(remark); |
| | | |
| | |
| | | if (result > 0) { |
| | | recordTaskLog(taskId, "ASSIGN", "分配车辆", null, |
| | | "分配车辆ID:" + vehicleId + ",备注:" + remark, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | userId, userName); |
| | | } |
| | | |
| | | return result; |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int assignMultipleVehiclesToTask(Long taskId, List<Long> vehicleIds, String remark) { |
| | | public int assignMultipleVehiclesToTask(Long taskId, List<Long> vehicleIds, String remark,Long userId,String userName) { |
| | | List<SysTaskVehicle> taskVehicles = new ArrayList<>(); |
| | | Date now = DateUtils.getNowDate(); |
| | | String assignBy = SecurityUtils.getUsername(); |
| | | String assignBy = userName; |
| | | |
| | | for (Long vehicleId : vehicleIds) { |
| | | // 检查是否已经分配 |
| | |
| | | if (result > 0) { |
| | | recordTaskLog(taskId, "ASSIGN", "批量分配车辆", null, |
| | | "分配车辆数量:" + result + ",备注:" + remark, |
| | | SecurityUtils.getUserId(), SecurityUtils.getUsername()); |
| | | userId,userName); |
| | | } |
| | | |
| | | return result; |
| | |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建对象 |
| | | */ |
| | | private void saveEmergencyInfo(Long taskId,String createUserName, TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId) { |
| | | private void saveEmergencyInfo(Long taskId,String createUserName, TaskCreateVO createVO,String serviceOrderId,String dispatchOrderId, String serviceOrdNo) { |
| | | SysTaskEmergency emergencyInfo = new SysTaskEmergency(); |
| | | emergencyInfo.setTaskId(taskId); |
| | | |
| | |
| | | emergencyInfo.setDispatchSyncTime(new Date()); |
| | | emergencyInfo.setDispatchSyncErrorMsg("旧系统同步过来"); |
| | | } |
| | | if(serviceOrdNo!=null){ |
| | | emergencyInfo.setLegacyServiceOrdNo(serviceOrdNo); |
| | | } |
| | | // 系统字段 |
| | | emergencyInfo.setCreateTime(DateUtils.getNowDate()); |
| | | emergencyInfo.setUpdateTime(DateUtils.getNowDate()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 更新急救转运任务扩展信息 |
| | | * 从 TaskCreateVO 更新急救转运任务扩展信息 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param updateVO 任务更新对象 |
| | | * @param createVO 任务创建/更新对象 |
| | | * @param userName 操作人名 |
| | | */ |
| | | private void updateEmergencyInfo(Long taskId, TaskUpdateVO updateVO) { |
| | | private void updateEmergencyInfoFromCreateVO(Long taskId, TaskCreateVO createVO, String userName) { |
| | | // 查询现有的扩展信息 |
| | | SysTaskEmergency existingInfo = sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | if (existingInfo == null) { |
| | |
| | | existingInfo = new SysTaskEmergency(); |
| | | existingInfo.setTaskId(taskId); |
| | | existingInfo.setCreateTime(DateUtils.getNowDate()); |
| | | existingInfo.setCreateBy(SecurityUtils.getUsername()); |
| | | existingInfo.setCreateBy(userName); |
| | | } |
| | | |
| | | 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 (createVO.getPatient() != null) { |
| | | if (createVO.getPatient().getContact() != null) { |
| | | existingInfo.setPatientContact(createVO.getPatient().getContact()); |
| | | } |
| | | if (createVO.getPatient().getPhone() != null) { |
| | | existingInfo.setPatientPhone(createVO.getPatient().getPhone()); |
| | | } |
| | | if (createVO.getPatient().getName() != null) { |
| | | existingInfo.setPatientName(createVO.getPatient().getName()); |
| | | } |
| | | if (createVO.getPatient().getGender() != null) { |
| | | existingInfo.setPatientGender(createVO.getPatient().getGender()); |
| | | } |
| | | if (createVO.getPatient().getIdCard() != null) { |
| | | existingInfo.setPatientIdCard(createVO.getPatient().getIdCard()); |
| | | } |
| | | if (createVO.getPatient().getCondition() != null) { |
| | | existingInfo.setPatientCondition(createVO.getPatient().getCondition()); |
| | | } |
| | | } |
| | | |
| | | // 更新转出医院信息 |
| | | 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")); |
| | | if (createVO.getHospitalOut() != null) { |
| | | if (createVO.getHospitalOut().getId() != null) { |
| | | existingInfo.setHospitalOutId(createVO.getHospitalOut().getId()); |
| | | } |
| | | if (createVO.getHospitalOut().getName() != null) { |
| | | existingInfo.setHospitalOutName(createVO.getHospitalOut().getName()); |
| | | } |
| | | if (createVO.getHospitalOut().getDepartment() != null) { |
| | | existingInfo.setHospitalOutDepartment(createVO.getHospitalOut().getDepartment()); |
| | | } |
| | | if (createVO.getHospitalOut().getDepartmentId() != null) { |
| | | existingInfo.setHospitalOutDepartmentId(createVO.getHospitalOut().getDepartmentId()); |
| | | } |
| | | if (createVO.getHospitalOut().getBedNumber() != null) { |
| | | existingInfo.setHospitalOutBedNumber(createVO.getHospitalOut().getBedNumber()); |
| | | } |
| | | if (createVO.getHospitalOut().getAddress() != null && !createVO.getHospitalOut().getAddress().equals(existingInfo.getHospitalOutAddress())) { |
| | | existingInfo.setHospitalOutAddress(createVO.getHospitalOut().getAddress()); |
| | | |
| | | // 如枟更新了地址但没有GPS坐标,后端自动获取 |
| | | if (createVO.getHospitalOut().getLongitude() == null && createVO.getHospitalOut().getLatitude() == null && mapService != null) { |
| | | try { |
| | | |
| | | Map<String, Double> coords = mapService.geocoding( |
| | | createVO.getHospitalOut().getAddress(), |
| | | extractCityFromAddress(createVO.getHospitalOut().getAddress()) |
| | | ); |
| | | 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); |
| | | } |
| | | } 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")); |
| | | if (createVO.getHospitalIn() != null) { |
| | | if (createVO.getHospitalIn().getId() != null) { |
| | | existingInfo.setHospitalInId(createVO.getHospitalIn().getId()); |
| | | } |
| | | if (createVO.getHospitalIn().getName() != null) { |
| | | existingInfo.setHospitalInName(createVO.getHospitalIn().getName()); |
| | | } |
| | | if (createVO.getHospitalIn().getDepartment() != null) { |
| | | existingInfo.setHospitalInDepartment(createVO.getHospitalIn().getDepartment()); |
| | | } |
| | | if (createVO.getHospitalIn().getDepartmentId() != null) { |
| | | existingInfo.setHospitalInDepartmentId(createVO.getHospitalIn().getDepartmentId()); |
| | | } |
| | | if (createVO.getHospitalIn().getBedNumber() != null) { |
| | | existingInfo.setHospitalInBedNumber(createVO.getHospitalIn().getBedNumber()); |
| | | } |
| | | if (createVO.getHospitalIn().getAddress() != null && !createVO.getHospitalIn().getAddress().equals(existingInfo.getHospitalInAddress())) { |
| | | existingInfo.setHospitalInAddress(createVO.getHospitalIn().getAddress()); |
| | | |
| | | // 如果更新了地址但没有GPS坐标,后端自动获取 |
| | | if (createVO.getHospitalIn().getLongitude() == null && createVO.getHospitalIn().getLatitude() == null && mapService != null) { |
| | | try { |
| | | Map<String, Double> coords = mapService.geocoding( |
| | | createVO.getHospitalIn().getAddress(), |
| | | extractCityFromAddress(createVO.getHospitalIn().getAddress()) |
| | | ); |
| | | 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); |
| | | } |
| | | } 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 (createVO.getTransferDistance() != null) { |
| | | existingInfo.setTransferDistance(createVO.getTransferDistance()); |
| | | } |
| | | if (emergencyInfo.getTransferPrice() != null) { |
| | | existingInfo.setTransferPrice(emergencyInfo.getTransferPrice()); |
| | | if (createVO.getPrice() != null) { |
| | | existingInfo.setTransferPrice(createVO.getPrice()); |
| | | } |
| | | |
| | | // 更新单据类型ID |
| | | if (createVO.getDocumentTypeId() != null) { |
| | | existingInfo.setDocumentTypeId(createVO.getDocumentTypeId()); |
| | | } |
| | | |
| | | // 更新任务类型ID |
| | | if (createVO.getTaskTypeId() != null) { |
| | | existingInfo.setTaskTypeId(createVO.getTaskTypeId()); |
| | | } |
| | | |
| | | // 更新病情ID列表 |
| | | if (updateVO.getDiseaseIds() != null && !updateVO.getDiseaseIds().isEmpty()) { |
| | | String diseaseIdsStr = updateVO.getDiseaseIds().stream() |
| | | if (createVO.getDiseaseIds() != null && !createVO.getDiseaseIds().isEmpty()) { |
| | | String diseaseIdsStr = createVO.getDiseaseIds().stream() |
| | | .map(String::valueOf) |
| | | .collect(Collectors.joining(",")); |
| | | existingInfo.setDiseaseIds(diseaseIdsStr); |
| | | } else { |
| | | // 如果病情ID列表为空,清空该字段 |
| | | existingInfo.setDiseaseIds(null); |
| | | } |
| | | |
| | | // 系统字段 |
| | | existingInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | existingInfo.setUpdateBy(SecurityUtils.getUsername()); |
| | | existingInfo.setUpdateBy(userName); |
| | | |
| | | // 执行更新 |
| | | sysTaskEmergencyMapper.updateSysTaskEmergency(existingInfo); |
| | | } |
| | | |
| | | /** |
| | | * 从 TaskCreateVO 更新福祉车任务扩展信息 |
| | | * |
| | | * @param taskId 任务ID |
| | | * @param createVO 任务创建/更新对象 |
| | | * @param userName 操作人名 |
| | | */ |
| | | private void updateWelfareInfoFromCreateVO(Long taskId, TaskCreateVO createVO, String userName) { |
| | | // 查询现有的扩展信息 |
| | | SysTaskWelfare existingInfo = sysTaskWelfareMapper.selectSysTaskWelfareByTaskId(taskId); |
| | | if (existingInfo == null) { |
| | | // 如果不存在,则创建新的 |
| | | existingInfo = new SysTaskWelfare(); |
| | | existingInfo.setTaskId(taskId); |
| | | existingInfo.setCreateTime(DateUtils.getNowDate()); |
| | | existingInfo.setCreateBy(userName); |
| | | } |
| | | |
| | | // 更新乘客信息 |
| | | if (createVO.getPassenger() != null) { |
| | | if (createVO.getPassenger().getContact() != null) { |
| | | existingInfo.setPassengerContact(createVO.getPassenger().getContact()); |
| | | } |
| | | if (createVO.getPassenger().getPhone() != null) { |
| | | existingInfo.setPassengerPhone(createVO.getPassenger().getPhone()); |
| | | } |
| | | } |
| | | |
| | | // 更新地址信息 |
| | | if (createVO.getStartAddress() != null) { |
| | | existingInfo.setPickupAddress(createVO.getStartAddress()); |
| | | } |
| | | if (createVO.getEndAddress() != null) { |
| | | existingInfo.setDestinationAddress(createVO.getEndAddress()); |
| | | } |
| | | |
| | | // 更新GPS坐标 |
| | | if (createVO.getDepartureLongitude() != null) { |
| | | existingInfo.setPickupLongitude(createVO.getDepartureLongitude()); |
| | | } |
| | | if (createVO.getDepartureLatitude() != null) { |
| | | existingInfo.setPickupLatitude(createVO.getDepartureLatitude()); |
| | | } |
| | | if (createVO.getDestinationLongitude() != null) { |
| | | existingInfo.setDestinationLongitude(createVO.getDestinationLongitude()); |
| | | } |
| | | if (createVO.getDestinationLatitude() != null) { |
| | | existingInfo.setDestinationLatitude(createVO.getDestinationLatitude()); |
| | | } |
| | | |
| | | // 更新距离和费用 |
| | | if (createVO.getDistance() != null) { |
| | | existingInfo.setServiceDistance(createVO.getDistance()); |
| | | } else if (createVO.getEstimatedDistance() != null) { |
| | | existingInfo.setServiceDistance(createVO.getEstimatedDistance()); |
| | | } |
| | | if (createVO.getPrice() != null) { |
| | | existingInfo.setServicePrice(createVO.getPrice()); |
| | | } |
| | | |
| | | // 系统字段 |
| | | existingInfo.setUpdateTime(DateUtils.getNowDate()); |
| | | existingInfo.setUpdateBy(userName); |
| | | |
| | | // 执行更新 |
| | | sysTaskWelfareMapper.updateSysTaskWelfare(existingInfo); |
| | | } |
| | | |
| | | /** |
| | | * 保存福祉车任务扩展信息 |