liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/controller/XpVehicleDetectionController.java
@@ -1,28 +1,34 @@
package com.xiaopeng.maintenance.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.xiaopeng.api.feignClient.account.XpOperationUserClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient;
import com.xiaopeng.api.model.account.XpOperationsUser;
import com.xiaopeng.api.model.maintenance.XpChargingRecord;
import com.xiaopeng.api.model.maintenance.XpVehicleClean;
import com.xiaopeng.api.model.maintenance.XpVehicleDetection;
import com.xiaopeng.api.model.vehicleConvoy.XpVehicle;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.security.service.TokenService;
import com.xiaopeng.maintenance.dto.XpChargingRecordStartDTO;
import com.xiaopeng.evi.oss.service.AliOssService;
import com.xiaopeng.maintenance.dto.XpVehicleDetectionDTO;
import com.xiaopeng.maintenance.model.vo.XpVehicleCleanVO;
import com.xiaopeng.maintenance.model.query.XpVehicleDetectionPageQuery;
import com.xiaopeng.maintenance.model.vo.XpVehicleDetectionVO;
import com.xiaopeng.maintenance.service.IXpChargingRecordService;
import com.xiaopeng.maintenance.service.IXpVehicleDetectionService;
import com.xiaopeng.maintenance.service.XpTaskService;
import com.xiaopeng.maintenance.utils.AliOssDownloadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
@@ -33,6 +39,7 @@
 * @author xiaochen
 * @since 2026-02-06
 */
@Slf4j
@Api(tags = "车辆检测")
@RestController
@RequestMapping("")
@@ -43,33 +50,48 @@
    @Autowired
    private TokenService tokenService;
    @Autowired
    private XpVehicleClient xpVehicleClient;
    private AliOssService aliOssService;
    @Autowired
    private XpOperationUserClient xpOperationUserClient;
    @Autowired
    private XpTaskService xpTaskService;
    @Autowired
    private AliOssDownloadUtil aliOssDownloadUtil;
    /**
     * 车辆运维-车辆运维-开始自检
     */
    @ApiOperation(value = "车辆运维-车辆运维-开始自检", tags = {"运维APP-车辆管理"})
    @GetMapping("/api/v1/vehicleDetection/startDetection")
    public R<String> startDetection(@RequestParam Long vehicleId) {
    @GetMapping("/maintenance-app/api/v1/vehicleDetection/startDetection")
    public R<Map<String, Integer>> startDetection(@RequestParam Long vehicleId) {
        // TODO 开始自检
        return R.ok();
        Map<String, Integer> result = new HashMap<>(6);
        result.put("networkDetection", 1); // 网络检测
        result.put("remoteSelfCheck", 1); // 远程自检
        result.put("versionVerification", 1); // 版本验证
        result.put("collisionAvoidanceActivation", 1); // 碰撞回避激活
        result.put("communicationSelfCheck", 1); // 通信自检
        result.put("sensorSelfCheck", 1); // 传感器自检
        return R.ok(result);
    }
    /**
     * 车辆详情-车辆运维-车辆检测提交
     */
    @Transactional
    @ShardingSphereTransactionType(TransactionType.BASE)
    @ApiOperation(value = "车辆运维-车辆运维-车辆检测提交", tags = {"运维APP-车辆管理"})
    @PostMapping("/api/v1/vehicleDetection/saveDetection")
    @PostMapping("/maintenance-app/api/v1/vehicleDetection/saveDetection")
    public R<String> saveDetection(@RequestBody XpVehicleDetectionDTO dto) {
        Long id = tokenService.getLoginOperationUser().getId();
        dto.setOperationsUserId(id);
        dto.setCheckTime(LocalDateTime.now());
        xpVehicleDetectionService.save(dto);
        //更新任务状态
        xpTaskService.updateTaskStatus(dto.getTaskId(), 2, id);
        return R.ok();
    }
@@ -78,11 +100,141 @@
     * 车辆运维-车辆运维-检测记录详情
     */
    @ApiOperation(value = "车辆运维-运维记录-检测记录详情", tags = {"运维APP-车辆管理"})
    @GetMapping("/api/v1/vehicleDetection/detectionDetail")
    public R<XpVehicleDetectionVO> detectionDetail(@RequestParam Long id) {
    @GetMapping("/maintenance-app/api/v1/vehicleDetection/detectionDetail")
    public R<XpVehicleDetectionVO> detectionDetail(@RequestParam Long id) throws UnsupportedEncodingException {
        XpVehicleDetectionVO xpVehicleDetectionVO = xpVehicleDetectionService.detectionDetail(id);
        String vehiclePictures = xpVehicleDetectionVO.getVehiclePictures();
        if (vehiclePictures != null && !vehiclePictures.isEmpty()) {
            JSONObject jsonObject = JSONObject.parseObject(vehiclePictures);
            // 2
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
            jsonObject.put("url", downloadUrl);
            xpVehicleDetectionVO.setVehiclePictures(jsonObject.toJSONString());
        }
        String sensorCleaningPicture = xpVehicleDetectionVO.getSensorCleaningPicture();
        if (StringUtils.isNotBlank(sensorCleaningPicture)) {
            JSONArray jsonArray = JSONArray.parseArray(sensorCleaningPicture);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                // 1
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            xpVehicleDetectionVO.setSensorCleaningPicture(JSONArray.toJSONString(jsonArray));
        }
        String interactiveScreenPicture = xpVehicleDetectionVO.getInteractiveScreenPicture();
        if (StringUtils.isNotBlank(interactiveScreenPicture)) {
            JSONArray jsonArray = JSONArray.parseArray(interactiveScreenPicture);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                // 1
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            xpVehicleDetectionVO.setInteractiveScreenPicture(JSONArray.toJSONString(jsonArray));
        }
        String helpButtonPicture = xpVehicleDetectionVO.getHelpButtonPicture();
        if (StringUtils.isNotBlank(helpButtonPicture)) {
            JSONArray jsonArray = JSONArray.parseArray(helpButtonPicture);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                // 1
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            xpVehicleDetectionVO.setHelpButtonPicture(JSONArray.toJSONString(jsonArray));
        }
        String paymentFunctionPicture = xpVehicleDetectionVO.getPaymentFunctionPicture();
        if (StringUtils.isNotBlank(paymentFunctionPicture)) {
            JSONArray jsonArray = JSONArray.parseArray(paymentFunctionPicture);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                // 1
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            xpVehicleDetectionVO.setPaymentFunctionPicture(JSONArray.toJSONString(jsonArray));
        }
        String systemCheckPicture = xpVehicleDetectionVO.getSystemCheckPicture();
        if (StringUtils.isNotBlank(systemCheckPicture)) {
            JSONArray jsonArray = JSONArray.parseArray(systemCheckPicture);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                // 1
                String downloadUrl = jsonObject.getString("url");
                try {
                    downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            xpVehicleDetectionVO.setSystemCheckPicture(JSONArray.toJSONString(jsonArray));
        }
        return R.ok(xpVehicleDetectionVO);
    }
    /**
     * 管理后台-车辆管理-运营车辆管理 通过车辆id查询检测分页列表
     *
     * @return
     */
    @ApiOperation(value = "通过车辆id查询检测分页列表", tags = {"管理后台-车辆管理-运营车辆管理"})
    @PostMapping("/api/v1/vehicle/queryDetectionByVehicleId")
    public R<PageInfo<XpVehicleDetectionVO>> queryDetectionByVehicleId(@Valid @RequestBody XpVehicleDetectionPageQuery query) throws UnsupportedEncodingException {
        PageInfo<XpVehicleDetectionVO> pageInfo = xpVehicleDetectionService.queryDetectionByVehicleId(query);
        for (XpVehicleDetectionVO xpVehicleDetectionVO : pageInfo.getRecords()) {
            xpVehicleDetectionVO.setVehiclePictures(aliOssDownloadUtil.getPictureJSONObject(xpVehicleDetectionVO.getVehiclePictures()));
            xpVehicleDetectionVO.setSensorCleaningPicture(aliOssDownloadUtil.getPictureJsonArray(xpVehicleDetectionVO.getSensorCleaningPicture()));
            xpVehicleDetectionVO.setInteractiveScreenPicture(aliOssDownloadUtil.getPictureJsonArray(xpVehicleDetectionVO.getInteractiveScreenPicture()));
            xpVehicleDetectionVO.setHelpButtonPicture(aliOssDownloadUtil.getPictureJsonArray(xpVehicleDetectionVO.getHelpButtonPicture()));
            xpVehicleDetectionVO.setPaymentFunctionPicture(aliOssDownloadUtil.getPictureJsonArray(xpVehicleDetectionVO.getPaymentFunctionPicture()));
            xpVehicleDetectionVO.setSystemCheckPicture(aliOssDownloadUtil.getPictureJsonArray(xpVehicleDetectionVO.getSystemCheckPicture()));
        }
        return R.ok(pageInfo);
    }
}