chenxiaofei il y a 1 mois
Parent
commit
156207880b

+ 34 - 3
iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java

@@ -27,6 +27,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -53,7 +54,8 @@ public class WeighbridgeRecordManage {
     private final ValidateLicensePlateService validateLicensePlateService;
 
     private final WeighbridgePushService externalWeighbridgePushService;
-    
+    @Value("${weighbridge.image.storage-prefix-path:/www/wwwroot/resources}")
+    private String oreStoragePath;
 
     @Resource
     private UploadService uploadService;
@@ -297,13 +299,42 @@ public class WeighbridgeRecordManage {
      */
     private void updatePhotoUrls(Long recordId, String photoUrls) {
         // 更新记录的图片URL
+        String processedPhotoUrls = processImagePaths(photoUrls);
+        log.info("处理前的图片路径-原图url: {},处理图片路径 - 图片URL: {}", photoUrls, processedPhotoUrls);
         WeighbridgeRecord updateRecord = new WeighbridgeRecord();
         updateRecord.setId(recordId);
-        updateRecord.setPhotoUrls(photoUrls);
-        log.info("更新图片URL - ID: {}, 图片URL: {}", recordId, photoUrls);
+        updateRecord.setPhotoUrls(processedPhotoUrls);
+        log.info("更新图片URL - ID: {}, 图片URL: {}", recordId, processedPhotoUrls);
         weighbridgeRecordService.updateById(updateRecord);
     }
 
+    /**
+     * 批量截取图片路径,去掉 /www/wwwroot/resources 前缀
+     * @param fullImagePaths 逗号分隔的完整路径
+     * @return 截取后的相对路径(逗号分隔)
+     */
+    public String processImagePaths(String fullImagePaths) {
+        if (fullImagePaths == null || fullImagePaths.isBlank()) {
+            return fullImagePaths;
+        }
+
+        String prefix = oreStoragePath;
+        StringBuilder result = new StringBuilder();
+
+        // 按逗号分割
+        String[] paths = fullImagePaths.split(",");
+        for (String path : paths) {
+            // 去掉前缀并拼接
+            result.append(path.replace(prefix, "")).append(",");
+        }
+
+        // 去掉最后多余的逗号
+        if (result.length() > 0) {
+            result.deleteCharAt(result.length() - 1);
+        }
+
+        return result.toString();
+    }
     /**
      * 时间戳转换:自动识别秒/毫秒
      * @param timestamp 时间戳(秒或毫秒)