“mitao”
2026-03-25 9bc644081322396aac7980aebabb48aeb7a427d7
fix:图片回显问题
1个文件已添加
1个文件已修改
92 ■■■■■ 已修改文件
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/service/impl/XpOperationsUserServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/util/AliOssDownloadUtil.java 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/service/impl/XpOperationsUserServiceImpl.java
@@ -22,6 +22,7 @@
import com.xiaopeng.account.service.IXpOperationsUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaopeng.account.service.IXpQualificationAuditService;
import com.xiaopeng.account.util.AliOssDownloadUtil;
import com.xiaopeng.api.feignClient.maintenance.XpClockInClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetClient;
import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient;
@@ -89,6 +90,8 @@
    private ISysRoleService iSysRoleService;
    @Autowired
    private AliOssService aliOssService;
    @Autowired
    private AliOssDownloadUtil aliOssDownloadUtil;
    @Override
    public List<XpOperationsUser> listByName(String nickName) {
@@ -116,7 +119,7 @@
        XpOperationsUserProfileVO vo = new XpOperationsUserProfileVO();
        BeanUtils.copyProperties(user, vo);
        vo.setAvatar(aliOssDownloadUtil.getPictureJSONObject(vo.getAvatar()));
        // 2. 查询关联的车队ID列表(一个运维人员只能关联一个车队)
        R<List<Long>> fleetIdsResult = xpFleetOperationsClient.getFleetIdsByUserId(userId);
        List<Long> fleetIds = fleetIdsResult.getData();
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/util/AliOssDownloadUtil.java
New file
@@ -0,0 +1,87 @@
package com.xiaopeng.account.util;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.xiaopeng.evi.oss.service.AliOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.util.Objects;
/**
 * @author MiTao
 * @date 2026-03-25 11:24
 *
 */
@Slf4j
@Component
public class AliOssDownloadUtil {
    @Autowired
    private AliOssService aliOssService;
    public String getPictureJsonArray(String json) {
        JSONArray res = new JSONArray();
        if (json == null || json.isEmpty()) {
            return res.toJSONString();
        }
        if (json.startsWith("{")) {
            JSONObject jsonObject = JSONObject.parseObject(json);
            if (Objects.isNull(jsonObject)) {
                return res.toJSONString();
            }
            String downloadUrl = "";
            try {
                downloadUrl = aliOssService.getDownloadUrl(
                        jsonObject.getString("id"), jsonObject.getString("name"), true);
            } catch (UnsupportedEncodingException e) {
                log.error("获取图片下载地址失败", e);
            }
            jsonObject.put("url", downloadUrl);
            res.add(jsonObject);
        } else if (json.startsWith("[")) {
            JSONArray jsonArray = JSONArray.parseArray(json);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                if (Objects.isNull(jsonObject)) {
                    continue;
                }
                String downloadUrl = "";
                try {
                    downloadUrl = aliOssService.getDownloadUrl(
                            jsonObject.getString("id"), jsonObject.getString("name"), true);
                } catch (UnsupportedEncodingException e) {
                    log.error("获取图片下载地址失败", e);
                }
                jsonObject.put("url", downloadUrl);
            }
            res = jsonArray;
        }
        return res.toJSONString();
    }
    /**
     * JSONObject类型图片
     * @param json
     * @return
     */
    public String getPictureJSONObject(String json){
        JSONObject jsonObject = JSONObject.parseObject(json);
        if (Objects.isNull(jsonObject)) {
            return new JSONObject().toJSONString();
        }
        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);
        return jsonObject.toJSONString();
    }
}