liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpTaskServiceImpl.java
@@ -261,20 +261,20 @@
            throw new ServiceException("上报失败,未获取到车辆信息", I18nKeyConstant.TASK_VEHICLE_NOT_EXIST);
        }
        String vin = SensitiveDataCryptoUtil.decryptIfPossible(vehicle.getVehicleVin());
         VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class);
         if (Objects.isNull(vehiclePosition)) {
             log.error("事故上报未获取到车辆当前定位");
             throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR);
         }
         xpTask.setVehicleLon(new BigDecimal(vehiclePosition.getPoint().getX()));
         xpTask.setVehicleLat(new BigDecimal(vehiclePosition.getPoint().getY()));
         Map<String, String> geocode = gdMapGeocodingUtil.geocode(xpTask.getVehicleLon().toString(), xpTask.getVehicleLat().toString());
         String address = geocode == null ? null : geocode.get("address");
         if (StringUtils.isBlank(address)) {
             log.error("事故上报通过车辆定位从高德获取地址信息失败");
             throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR);
         }
         xpTask.setVehicleLocation(address);
        VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class);
        if (Objects.isNull(vehiclePosition)) {
            log.error("事故上报未获取到车辆当前定位");
            throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR);
        }
        xpTask.setVehicleLon(new BigDecimal(vehiclePosition.getPoint().getX()));
        xpTask.setVehicleLat(new BigDecimal(vehiclePosition.getPoint().getY()));
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(xpTask.getVehicleLon().toString(), xpTask.getVehicleLat().toString());
        String address = geocode == null ? null : geocode.get("address");
        if (StringUtils.isBlank(address)) {
            log.error("事故上报通过车辆定位从高德获取地址信息失败");
            throw new ServiceException("获取车辆实时定位信息失败,请稍后重试", I18nKeyConstant.TASK_SAVE_ERROR);
        }
        xpTask.setVehicleLocation(address);
// 临时处理
//        xpTask.setVehicleLon(new BigDecimal("104.055683"));
//        xpTask.setVehicleLat(new BigDecimal("30.585991"));
@@ -298,7 +298,7 @@
            List<Long> userIds = xpOperationsRoleResult.getData().stream().filter(x -> ids.contains(x.getOperationsUserId()))
                    .map(XpOperationsRole::getOperationsUserId)
                    .distinct().collect(Collectors.toList());
            if(CollUtil.isEmpty(userIds)){
            if (CollUtil.isEmpty(userIds)) {
                throw new ServiceException("未配置车队运维人员");
            }
            //获取首选人的实时定位,计算每个人到事故车辆位置的导航距离
@@ -306,33 +306,39 @@
            for (Long userId : userIds) {
                Operations operations = new Operations();
                operations.setUserId(userId);
                //获取运维人员实时定位
                XpOperationsUserPositionDTO operationsUserPositionDTO = mongoTemplate.findOne(new Query(Criteria.where("id").is(userId)), XpOperationsUserPositionDTO.class);
                if(null != operationsUserPositionDTO){
                if (null != operationsUserPositionDTO) {
                    LonLatDto start = new LonLatDto(operationsUserPositionDTO.getLongitude(), operationsUserPositionDTO.getLatitude());
                    LonLatDto end = new LonLatDto(xpTask.getVehicleLon().doubleValue(), xpTask.getVehicleLat().doubleValue());
                    //获取导航线路
                    RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(start, end, null, null, null, null);
                    operations.setDistance(routeVo.getDistance());
                    operationsList.add(operations);
                }
                operationsList.add(operations);
            }
            if(operationsList.isEmpty()){
                throw new ServiceException("未找到合适的运维人员");
            }
            //对距离进行排序,去距离最近的人员
            operationsList.sort((o1, o2) -> o1.getDistance().compareTo(o2.getDistance()) * -1);
            Operations operations = operationsList.get(0);
            Long userId = operations.getUserId();
            //如果多人距离相同,可按照上班状态>空闲状态>工号排序
            List<Operations> collect = operationsList.stream().filter(s -> s.getDistance().equals(operations.getDistance())).collect(Collectors.toList());
            if(collect.size() > 1){
            if (collect.size() > 1) {
                //查询已经上班打卡了的人员
                List<XpClockIn> xpClockIns = xpClockInService.list(new QueryWrapper<XpClockIn>().in("app_user_id", collect)
                        .isNull("clock_out_result").last(" and DATE(now()) = DATE(clock_in_time)"));
                if(xpClockIns.size() == 1){
                        .isNull("clock_out_result").last(" and DATE(now()) = DATE(clock_in_time) and clock_out_time is null"));
                if (xpClockIns.size() == 1) {
                    userId = xpClockIns.get(0).getAppUserId();
                }else if(xpClockIns.size() > 1){
                } else if (xpClockIns.size() > 1) {
                    //查询有任务的人员
                    List<Long> collect1 = xpClockIns.stream().map(XpClockIn::getAppUserId).collect(Collectors.toList());
                    List<XpTask> list1 = this.list(new QueryWrapper<XpTask>().eq("task_category", 2).in("handle_user_id", collect1)
                            .in("status", Arrays.asList(0, 1, 4)));
                    if(list1.size() > 0){
                    if (list1.size() > 0) {
                        //对工号进行排序
                        List<String> collect2 = list1.stream().map(XpTask::getHandleUserId).collect(Collectors.toList());
                        //找出没有任务的人员
@@ -354,7 +360,7 @@
        xpTask.setExpiredNoticeSent(0);
        xpTask.setWillTimeoutNoticeSent(0);
        this.save(xpTask);
        if (xpTask.getId() == null && StringUtils.isNotBlank(xpTask.getTaskCode())) {
        if (xpTask.getId() == null && StringUtils.isNotEmpty(xpTask.getTaskCode())) {
            XpTask savedTask = this.getOne(new LambdaQueryWrapper<XpTask>()
                    .eq(XpTask::getTaskCode, xpTask.getTaskCode())
                    .last("limit 1"));
@@ -467,11 +473,11 @@
    }
    /**
     * 异步发送事故通知
     * @param xpTask 任务信息
     * @param plateNumber 车牌号
     *
     * @param xpTask              任务信息
     * @param plateNumber         车牌号
     * @param processingTimeLimit 处理时限(分钟)
     */
    private void sendAccidentNotificationAsync(XpTask xpTask, String plateNumber, Integer processingTimeLimit) {
@@ -507,9 +513,9 @@
    /**
     * 异步发送事故任务分配通知
     *
     * @param xpTask 任务信息
     * @param handlerUserId 当前分配的处理人
     * @param plateNumber 车牌号
     * @param xpTask              任务信息
     * @param handlerUserId       当前分配的处理人
     * @param plateNumber         车牌号
     * @param processingTimeLimit 处理时限(分钟)
     */
    private void sendAssignedAccidentNotificationAsync(XpTask xpTask, Long handlerUserId, String plateNumber, Integer processingTimeLimit) {
@@ -539,8 +545,8 @@
    /**
     * 构建事故通知文案
     *
     * @param xpTask 任务信息
     * @param plateNumber 车牌号
     * @param xpTask              任务信息
     * @param plateNumber         车牌号
     * @param processingTimeLimit 处理时限(分钟)
     * @return 通知内容
     */
@@ -550,8 +556,9 @@
    /**
     * 构建事故推送 body JSON
     *
     * @param content 消息内容
     * @param xpTask 任务信息
     * @param xpTask  任务信息
     * @return JSON 字符串
     */
    private String buildAccidentPushBodyJson(String content, XpTask xpTask) {
@@ -566,9 +573,9 @@
    /**
     * 保存事故通知记录并发送阿里云推送
     *
     * @param data 接收通知的运维人员
     * @param data    接收通知的运维人员
     * @param content 通知内容
     * @param xpTask 任务信息
     * @param xpTask  任务信息
     */
    private void saveAndPushAccidentNotification(List<XpOperationsUser> data, String content, XpTask xpTask) {
        String bodyJson = buildAccidentPushBodyJson(content, xpTask);
@@ -1644,7 +1651,7 @@
        XpTaskRule taskRule = xpTaskRuleService.lambdaQuery().last("limit 1").one();
        int type = 9;
        if(task.getTaskCategory() != 2) {
        if (task.getTaskCategory() != 2) {
            type = Integer.parseInt(task.getTaskTypeId());
        }
@@ -1655,7 +1662,7 @@
        }
        List<XpTask.Reject> rejects = Optional.ofNullable(task.getExcluded()).orElse(new ArrayList<>());
        if(msg != null && Strings.isNotBlank(task.getHandleUserId())) {
        if (msg != null && Strings.isNotBlank(task.getHandleUserId())) {
            XpTask.Reject reject = task.reject(msg);
            rejects.add(reject);
            List<Long> id = Collections.singletonList(Long.parseLong(task.getHandleUserId()));
@@ -1682,13 +1689,13 @@
//        vehiclePosition.setPoint(new GeoJsonPoint(103.12615621, 30.264561));
        String handlerUser = chooseNearestAvailableOperationsUser(belongUserIds, vehiclePosition);
        task.setHandleUserId(handlerUser);
        if(handlerUser == null) {
        if (handlerUser == null) {
            task.setStatus(4);
            task.setReassignmentStatus(1);
            noticeAdministrator(task);//TODO 需要通知管理员手动处理,考虑再AliPushUtil 中给管理员发送消息
        }
        updateById(task);
        if(StringUtils.isNotBlank(task.getHandleUserId())){
        if (StringUtils.isNotBlank(task.getHandleUserId())) {
            sendAccidentNotificationAsync(task, vehicle.getPlateNumber(), taskRule.getProcessingTimeLimit());
        }
    }
@@ -1729,7 +1736,7 @@
        task.setVehicleLon(new BigDecimal(vehiclePosition.getPoint().getX()));
        String handlerUser = chooseNearestAvailableOperationsUser(belongUserIds, vehiclePosition);
        task.setHandleUserId(handlerUser);
        if(handlerUser == null) {
        if (handlerUser == null) {
            task.setStatus(4);
            task.setReassignmentStatus(1);
            noticeAdministrator(task);
@@ -1745,7 +1752,7 @@
        task.setCreateTime(LocalDateTime.now());
        this.save(task);
        // 异步发送消息通知
         sendAccidentNotificationAsync(task, vehicle.getPlateNumber(), taskRule.getProcessingTimeLimit());
        sendAccidentNotificationAsync(task, vehicle.getPlateNumber(), taskRule.getProcessingTimeLimit());
    }
    @Override
@@ -1755,7 +1762,7 @@
        XpTask task = getById(Long.valueOf(taskId));
        XpVehicle vehicle = xpVehicleClient.queryById(task.getVehicleId()).getData();
        updateTaskStatus(task.getId(), TaskScheduleConstants.TASK_STATUS_PENDING_ARRIVE, Long.valueOf(task.getHandleUserId()));
        sendAccidentNotificationAsync(getById(task.getId()), vehicle.getPlateNumber(), (int) Duration.between(LocalDateTime.now(),task.getEndTime()).toMinutes());
        sendAccidentNotificationAsync(getById(task.getId()), vehicle.getPlateNumber(), (int) Duration.between(LocalDateTime.now(), task.getEndTime()).toMinutes());
    }
    @Override
@@ -1855,7 +1862,6 @@
    }
    @Override
    public R assigneeTask(Long id, Long handlerUserId, Long assigneeUserId) {
        XpTask task = this.getById(id);
@@ -1933,7 +1939,7 @@
        for (XpTask task : saveTask) {
            reassign(task.getId(),null);
            reassign(task.getId(), null);
        }
    }
@@ -2411,15 +2417,16 @@
    /**
     * 任务改派操作
     *
     * @param vo
     */
    @Override
    public void taskReassignment(TaskReassignmentVo vo) {
        XpTask xpTask = this.getById(vo.getTaskId());
        if(null == xpTask){
        if (null == xpTask) {
            throw new ServiceException("无效的任务", I18nKeyConstant.TASK_NOT_EXIST);
        }
        if(2 == xpTask.getReassignmentStatus()){
        if (2 == xpTask.getReassignmentStatus()) {
            throw new ServiceException("任务已改派,不能重复操作", I18nKeyConstant.TASK_HAS_BEEN_REASSIGNED);
        }
        xpTask.setReassignmentStatus(2);