puzhibing
2026-08-21 3f6d5b788670170da195be8d8cee814069b3b224
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/XpuVinController.java
@@ -1,15 +1,27 @@
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 org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Slf4j
@RestController
@RequestMapping("")
public class XpuVinController {
@@ -17,15 +29,121 @@
    @Resource
    private XPUUtil xpuUtil;
    @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);
    }
    /**
     * 判断车辆是否能启动L4自动驾驶能力
     */
    @PostMapping("/xpu/v1/autopilot/L4/checkAvailable")
    public XpCommonResponse<L4CapabilityVO> checkL4Available(@RequestBody @Valid CheckL4AvailableRequest request) {
        log.info("Check L4 available request: {}", request);
        L4CapabilityVO vo = new L4CapabilityVO();
        vo.setVin(request.getVin());
        vo.setUid(request.getUserId());
        List<String> capabilities = new ArrayList<>();
        capabilities.add("VPD");
        L4CapabilityVO.Config config = new L4CapabilityVO.Config();
        config.setOrderArrivalTriggerDistance(autopilotProperties.getOrderArrivalTriggerDistance());
        try {
            R<XpVehicle> vehicleR = xpVehicleClient.findByVehicleVin(request.getVin());
            if (vehicleR != null && vehicleR.getCode() == 200 && vehicleR.getData() != null) {
                XpVehicle vehicle = vehicleR.getData();
                if (Objects.equals(vehicle.getVehicleType(), 2)) {
                    capabilities.add("RT");
                }
                if (Objects.equals(vehicle.getAcceptOrTest(), 2)) {
                    config.setTestMode(1);
                    L4CapabilityVO.TestModeFeatures features = new L4CapabilityVO.TestModeFeatures();
                    features.setAutoChainNextOrderAtDest(autopilotProperties.getAutoChainNextOrderAtDest());
                    features.setAutoConfirmDropoff(autopilotProperties.getTestModeAutoConfirmDropoff());
                    config.setTestModeFeatures(features);
                }
                // 测试车辆处理
                if (Objects.equals(vehicle.getVehicleAttribute(), 1)) {
                    config.setTestMode(1);
                    L4CapabilityVO.TestModeFeatures features = new L4CapabilityVO.TestModeFeatures();
                    features.setAutoChainNextOrderAtDest(autopilotProperties.getAutoChainNextOrderAtDest());
                    features.setAutoConfirmDropoff(autopilotProperties.getTestModeAutoConfirmDropoff());
                    config.setTestModeFeatures(features);
                }
            } else {
                log.warn("Vehicle not found for vin: {}", request.getVin());
            }
        } catch (Exception e) {
            log.error("Error querying vehicle info", e);
        }
        vo.setL4Capability(capabilities);
        vo.setConfig(config);
        return XpCommonResponse.ok(vo);
    }
    /**
     * XPU初始化状态上报
     */
    @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);
        }
    }
}