Pārlūkot izejas kodu

提交累计装货量和卸货量计算

chenxiaofei 3 nedēļas atpakaļ
vecāks
revīzija
4605aa66a0

+ 7 - 0
iot-platform-manager/src/main/java/com/platform/api/controller/WeighbridgeV2Controller.java

@@ -158,4 +158,11 @@ public class WeighbridgeV2Controller {
 
         }
     }
+
+    @Operation(summary = "手动过磅数据上报", description = "接收地磅设备上报的过磅数据和图片")
+    @GetMapping("/manualWeighBridgePushV2")
+    public LicensePlateValidateResponse manualWeighBridgePushV2(Integer id) {
+        // 调用业务层处理
+        return weighbridgeRecordManage.manualWeighBridgePushV2(id);
+    }
 }

+ 46 - 4
iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java

@@ -161,7 +161,7 @@ public class WeighbridgeRecordManage {
                 data.setVoice_message("数据上报成功");
                 licensePlateValidateResponse.setData(data);
                 log.info("地磅数据保存成功 - ID: {}, 车牌: {}", record.getId(), record.getLicensePlate());
-                if (StringUtils.equals(WeighbridgeYsEnum.NO2.getCode(),record.getWeighbridgeCode())){
+                if (StringUtils.equals(WeighbridgeYsEnum.NO1.getCode(),record.getWeighbridgeCode())){
                     externalWeighbridgePushService.pushWeighbridgeRecord(record);
                 }else {
                     //todo 推送下山地磅数据
@@ -204,7 +204,7 @@ public class WeighbridgeRecordManage {
                                 photoUrls != null ? photoUrls.split(",").length : 0);
                         record.setPhotoUrls(photoUrls);
                         // 更新数据库中的图片URL
-                        updatePhotoUrls(record.getId(), photoUrls);
+                        updatePhotoUrls(record.getId(), photoUrls,record.getLicensePlate());
                     })
                     .exceptionally(throwable -> {
                         log.error("异步上传图片失败,车牌号: {}", request.getLicensePlate(), throwable);
@@ -221,7 +221,7 @@ public class WeighbridgeRecordManage {
                         log.info("Base64图片保存完成,车牌号: {},照片数量: {}", request.getLicensePlate(),
                                 photoUrls != null ? photoUrls.split(",").length : 0);
                         record.setPhotoUrls(photoUrls);
-                        updatePhotoUrls(record.getId(), photoUrls);
+                        updatePhotoUrls(record.getId(), photoUrls, request.getLicensePlate());
                     })
                     .exceptionally(throwable -> {
                         log.error("异步保存Base64图片失败,车牌号: {}", request.getLicensePlate(), throwable);
@@ -299,7 +299,7 @@ public class WeighbridgeRecordManage {
     /**
      * 异步更新图片URL
      */
-    private void updatePhotoUrls(Long recordId, String photoUrls) {
+    private void updatePhotoUrls(Long recordId, String photoUrls,String licensePlate) {
         // 更新记录的图片URL
         String processedPhotoUrls = processImagePaths(photoUrls);
         log.info("处理前的图片路径-原图url: {},处理图片路径 - 图片URL: {}", photoUrls, processedPhotoUrls);
@@ -308,6 +308,9 @@ public class WeighbridgeRecordManage {
         updateRecord.setPhotoUrls(processedPhotoUrls);
         log.info("更新图片URL - ID: {}, 图片URL: {}", recordId, processedPhotoUrls);
         weighbridgeRecordService.updateById(updateRecord);
+
+        //开始将地磅数据推送到外部系统 todo 目前先在图片上传完成后推送,后续可以调整为上报数据成功后立即推送,图片URL作为后续补充信息推送
+        externalWeighbridgePushService.pushWeighbridgeUrlRecord(licensePlate,photoUrls);
     }
 
     /**
@@ -711,4 +714,43 @@ public class WeighbridgeRecordManage {
         response.setData(data);
         return response;
     }
+
+    public LicensePlateValidateResponse manualWeighBridgePushV2(Integer id) {
+        log.info("开始处理手动称重推送,记录ID:{}", id);
+        
+        // 1. 校验参数合法性
+        if (Objects.isNull(id)) {
+            log.warn("手动称重推送参数校验失败,记录ID为空");
+            throw new IotException("手动称重推送参数不合法,id为空");
+        }
+        
+        // 2. 查询地磅记录
+        WeighbridgeRecord weighbridgeRecord = weighbridgeRecordService.getById(id);
+        if (Objects.isNull(weighbridgeRecord)) {
+            log.warn("手动称重推送查询记录失败,未找到ID为 {} 的地磅记录数据", id);
+            throw new IotException("手动称重推送失败,数据不存在,ID: " + id);
+        }
+        log.info("查询到地磅记录 - ID: {}, 车牌: {}, 地磅编号: {}, 重量: {}", 
+                weighbridgeRecord.getId(), weighbridgeRecord.getLicensePlate(), weighbridgeRecord.getWeighbridgeCode(), weighbridgeRecord.getWeight());
+        
+        // 3. 调用外部服务推送记录
+        try {
+            log.info("开始调用外部服务推送地磅记录,ID: {}", id);
+            externalWeighbridgePushService.pushWeighbridgeRecord(weighbridgeRecord);
+            log.info("外部服务推送地磅记录成功,ID: {}", id);
+        } catch (Exception e) {
+            log.error("手动称重推送外部服务调用异常,记录ID: {}, 车牌: {}", id, weighbridgeRecord.getLicensePlate(), e);
+            throw new IotException("手动称重推送异常,ID: " + id);
+        }
+        
+        // 4. 构造成功响应
+        LicensePlateValidateResponse licensePlateValidateResponse = new LicensePlateValidateResponse();
+        licensePlateValidateResponse.setStatus(true);
+        licensePlateValidateResponse.setCode(200);
+        licensePlateValidateResponse.setMessage("手动称重推送成功");
+        licensePlateValidateResponse.setData(new LicensePlateValidateResponse.Data());
+        log.info("手动称重推送处理完成,返回成功响应,记录ID: {}", id);
+        
+        return licensePlateValidateResponse;
+    }
 }

+ 3 - 0
iot-platform-manager/src/main/java/com/platform/external/client/WeighbridgePushClient.java

@@ -2,6 +2,7 @@ package com.platform.external.client;
 
 import com.platform.external.request.CarInfoReq;
 import com.platform.external.request.WaybillOrderProcessParam;
+import com.platform.external.request.WaybillOrderWeighImageParam;
 import com.platform.result.BaseResult;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -44,4 +45,6 @@ public interface WeighbridgePushClient {
      */
     @PostMapping("${external-system.weighbridge.lift-gate-check-path:/validateLicensePlate}")
     BaseResult<Boolean> queryCanLiftGate(@RequestBody CarInfoReq request);
+    @PostMapping("/weighImage")
+    BaseResult<Void> pushWeighbridgeUrlRecord(WaybillOrderWeighImageParam request);
 }

+ 34 - 0
iot-platform-manager/src/main/java/com/platform/external/request/WaybillOrderWeighImageParam.java

@@ -0,0 +1,34 @@
+package com.platform.external.request;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author :donglang
+ * @version :1.0
+ * @description : 车辆过磅入参信息
+ * @create :2025-11-13 08:59:00
+ */
+@Data
+public class WaybillOrderWeighImageParam implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1038619782660342061L;
+
+    /**
+     * 车辆号
+     */
+    @Schema(description = "车辆号")
+    private String truckNo;
+
+    /**
+     * 称重重量(毛重/皮重)
+     */
+    @Schema(description = "称重重量")
+    private List<String> weighImageList;
+
+}

+ 26 - 0
iot-platform-manager/src/main/java/com/platform/external/service/WeighbridgePushService.java

@@ -12,12 +12,15 @@ import com.platform.external.config.UnloadWeighbridgePushProperties;
 import com.platform.external.config.WeighbridgePushProperties;
 import com.platform.external.request.CarInfoReq;
 import com.platform.external.request.WaybillOrderProcessParam;
+import com.platform.external.request.WaybillOrderWeighImageParam;
 import com.platform.result.BaseResult;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -160,4 +163,27 @@ public class WeighbridgePushService {
         }
     }
 
+    public void pushWeighbridgeUrlRecord(String licensePlate,String photoUrls) {
+        log.info("外部系统地磅图片推送开始,车牌: {}", licensePlate);
+        if (StringUtils.isBlank(licensePlate)){
+            log.warn("外部系统地磅图片推送参数为空,跳过推送");
+            return;
+        }
+        try {
+            WaybillOrderWeighImageParam param = new WaybillOrderWeighImageParam();
+            List<String> urlList = Arrays.asList(photoUrls.split(","));
+            param.setTruckNo(licensePlate);
+            param.setWeighImageList(urlList);
+            log.info("外部系统地磅图片推送开始,车牌: {},,请求参数:{}", licensePlate,JSON.toJSONString(param));
+            BaseResult<Void> response = weighbridgePushClient.pushWeighbridgeUrlRecord(param);
+            log.info("外部系统地磅图片推送完成,车牌: {}, 响应: {}",licensePlate, JSON.toJSONString(response));
+            if (Objects.isNull(response) || !response.isSuccess()) {
+                log.warn("外部系统地磅图片推送失败,车牌: {}, 响应: {}",licensePlate, JSON.toJSONString(response));
+            }
+        } catch (Exception e) {
+            log.error("外部地磅图片推送异常,车牌: {}",licensePlate, e);
+        }
+
+
+    }
 }