chenxiaofei 1 ماه پیش
والد
کامیت
54dfb15625

+ 33 - 1
iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java

@@ -26,6 +26,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;
 
@@ -52,7 +53,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;
@@ -271,6 +273,9 @@ 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);
@@ -278,6 +283,33 @@ public class WeighbridgeRecordManage {
         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 时间戳(秒或毫秒)

+ 7 - 2
iot-platform-manager/src/main/java/com/platform/service/XpCloudPrintService.java

@@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
@@ -53,6 +54,10 @@ public class XpCloudPrintService {
     private final PrintReceiptContentClient printReceiptContentClient;
 
     private final KwsPrintReceiptRecordRepository kwsPrintReceiptRecordRepository;
+    @Value("weigh.weigher")
+    private String weigher;
+    @Value("weigh.copies")
+    private Integer weighbridgeCopies;
 
     /**
      * 调用芯烨云 {@code open.xpyun.net} 开放接口(小票 {@code /xprinter/print})的 HTTP 客户端。
@@ -306,7 +311,7 @@ public class XpCloudPrintService {
                 new AbstractMap.SimpleEntry<>("taskNo", content.getTaskNo()),                 // 任务单号
                 new AbstractMap.SimpleEntry<>("acceptTime", content.getAcceptTime()),         // 接单时间
                 new AbstractMap.SimpleEntry<>("finishTime", content.getFinishTime()),         // 完成时间
-                new AbstractMap.SimpleEntry<>("weigher", content.getWeigher()),               // 计重人
+                new AbstractMap.SimpleEntry<>("weigher", weigher),               // 计重人
                 new AbstractMap.SimpleEntry<>("driverName", content.getDriverName()),         // 司机姓名
                 new AbstractMap.SimpleEntry<>("driverMobile", content.getDriverMobile()),     // 司机手机号
                 new AbstractMap.SimpleEntry<>("driverIdCard", content.getDriverIdCard()),     // 司机身份证
@@ -622,7 +627,7 @@ public class XpCloudPrintService {
         body.put("content", xmlContent);     // 打印内容(XML 格式)
 
         // 5. 处理打印份数:若未指定则默认为 1 份
-        int copies = reqVo.getCopies() != null ? reqVo.getCopies() : 1;
+        Integer copies = Objects.nonNull(weighbridgeCopies) ? weighbridgeCopies : 1;
         body.put("copies", copies);
 
         // 6. 可选参数:打印模式(0:云端排队, 1:即时打印)