puzhibing
2026-04-10 ed838e62602c0a63a64ff4bd144a0d16cc9a7cf8
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/XpuVinController.java
@@ -1,15 +1,18 @@
package com.xiaopeng.automaticPilot.controller;
import com.xiaopeng.api.feignClient.map.AdcFencePushClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
import com.xiaopeng.automaticPilot.dto.CheckL4AvailableRequest;
import com.xiaopeng.automaticPilot.dto.L4CapabilityVO;
import com.xiaopeng.automaticPilot.dto.XpCommonResponse;
import com.xiaopeng.automaticPilot.dto.XpuInitStatusRequest;
import com.xiaopeng.automaticPilot.config.AutopilotProperties;
import com.xiaopeng.automaticPilot.util.XPUUtil;
import com.xiaopeng.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -29,15 +32,21 @@
    @Resource
    private XpVehicleClient xpVehicleClient;
    @Resource
    private AutopilotProperties autopilotProperties;
    @Autowired
    private AdcFencePushClient adcFencePushClient;
    /**
     * 根据车辆VIN查询XPUID
     * @param vin
     * @return
     */
    @GetMapping("/xpu/getXpuIdByVin")
    @GetMapping("/logan/xpu/getXpuIdByVin")
    public R<String> getXpuIdByVin(@RequestParam("vin") String vin){
        String xpuId = xpuUtil.getXpuIdByVin(vin);
        String xpuId = xpuUtil.getXpuIdByVinForVehicleControl(vin);
        return R.ok(xpuId);
    }
@@ -72,6 +81,7 @@
        }
        
        vo.setL4Capability(capabilities);
        vo.setConfig(autopilotProperties);
        return XpCommonResponse.ok(vo);
    }
@@ -81,6 +91,43 @@
    @PostMapping("/xpu/v1/autopilot/L4/init")
    public XpCommonResponse<Void> initXpuStatus(@RequestBody @Valid XpuInitStatusRequest request) {
        log.info("XPU init status report: {}", request);
        // 校验车端地图版本是否最新,版本不一致或未下载均设置运营状态为4(异常),但始终返回成功
        try {
            R<String> versionR = adcFencePushClient.getMapVersion(request.getVin());
            if (versionR != null && versionR.getCode() == 200 && versionR.getData() != null) {
                String serverVersion = versionR.getData();
                String clientVersion = request.getRobotaxiAreaInfo().getMapVersion();
                if (!serverVersion.equals(clientVersion)) {
                    log.warn("车端地图版本不一致, vin={}, clientVersion={}, serverVersion={}",
                            request.getVin(), clientVersion, serverVersion);
                    setVehicleAbnormal(request.getVin());
                    return XpCommonResponse.ok(null);
                }
            }
        } catch (Exception e) {
            log.error("查询地图版本失败, vin={}", request.getVin(), e);
        }
        if (Boolean.FALSE.equals(request.getRobotaxiAreaInfo().getDownloaded())) {
            setVehicleAbnormal(request.getVin());
        }
        return XpCommonResponse.ok(null);
    }
    private void setVehicleAbnormal(String vin) {
        try {
            R<XpVehicle> vehicleR = xpVehicleClient.findByVehicleVin(vin);
            if (vehicleR != null && vehicleR.getCode() == 200 && vehicleR.getData() != null) {
                XpVehicle vehicle = vehicleR.getData();
                vehicle.setOperatingStatus(4);
                xpVehicleClient.updateVehicleById(vehicle);
                log.info("Vehicle operatingStatus set to 4 (abnormal), vin: {}", vin);
            } else {
                log.warn("Vehicle not found when updating operatingStatus, vin: {}", vin);
            }
        } catch (Exception e) {
            log.error("Failed to update vehicle operatingStatus, vin: {}", vin, e);
        }
    }
}