Kaynağa Gözat

提交新增存储图片接口

chenxiaofei 1 gün önce
ebeveyn
işleme
f6fb6c24f8

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

@@ -46,7 +46,7 @@ public class WeighbridgeV2Controller {
      * 地磅过磅数据上报
      */
     @Operation(summary = "地磅过磅数据上报", description = "接收地磅设备上报的过磅数据和图片")
-    @PostMapping("/weighBridgePush")
+    @PostMapping("/weighBridgePushJd")
     public LicensePlateValidateResponse weighBridgePush(
             @Parameter(description = "车牌号") @RequestParam("licensePlate") String licensePlate,
             @Parameter(description = "地磅编号") @RequestParam("weighbridgeCode") String weighbridgeCode,
@@ -69,7 +69,7 @@ public class WeighbridgeV2Controller {
         request.setImages(images);
 
         // 调用业务层处理
-        return weighbridgeRecordManage.handleWeighbridgePush(request);
+        return weighbridgeRecordManage.handleWeighbridgePushJd(request);
     }
 
     /**

+ 70 - 0
iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java

@@ -761,4 +761,74 @@ public class WeighbridgeRecordManage {
         
         return licensePlateValidateResponse;
     }
+
+    /**
+     * 处理地磅过磅数据上报
+     * @param request 地磅上报请求参数
+     * @return 是否保存成功
+     */
+    public LicensePlateValidateResponse handleWeighbridgePushJd(WeighbridgePushRequest request) {
+        log.info("[地磅过磅数据上报V2]开始地磅过磅数据上报,车牌:{}, 地磅编号:{}, 重量:{}, 时间戳:{}, 图片数量:{}",
+                request.getLicensePlate(), request.getWeighbridgeCode(), request.getGrossWeight(),
+                request.getTimestamp(), request.getImages() != null ? request.getImages().length : 0);
+        LicensePlateValidateResponse licensePlateValidateResponse = new LicensePlateValidateResponse();
+        if (StringUtils.isAnyBlank(request.getLicensePlate(), request.getWeighbridgeCode()) || Objects.isNull(request.getGrossWeight()) || Objects.isNull(request.getTimestamp())) {
+            return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
+        }
+        //查询车牌是否在验证列表中
+        ValidateLicensePlate validateLicensePlate = validateLicensePlateService.queryByLicensePlate(request.getLicensePlate());
+        try {
+            // 构建实体对象
+            WeighbridgeRecord record = buildWeighbridgeRecord(request);
+            if(Objects.isNull(validateLicensePlate)){
+                record.setCheckStatus(1);
+            }
+            LambdaQueryWrapper<KwsWeighbridge> wrapper = Wrappers.<KwsWeighbridge>lambdaQuery()
+                    .eq(KwsWeighbridge::getUniqueCode, request.getWeighbridgeCode())
+                    .eq(KwsWeighbridge::getDelFlag, 0)
+                    .last("limit 1");
+            KwsWeighbridge kwsWeighbridge = kwsWeighbridgeRepository.getOne(wrapper);
+            Long entId = Optional.ofNullable(kwsWeighbridge)
+                    .map(KwsWeighbridge::getEntId)
+                    .orElse(null);
+            // 保存到数据库
+            boolean saved = weighbridgeRecordService.save(record);
+            if (saved) {
+                // 异步处理图片上传
+                updateImageUrls(request, record);
+                licensePlateValidateResponse.setStatus(true);
+                licensePlateValidateResponse.setCode(200);
+                licensePlateValidateResponse.setMessage("数据上报成功");
+                LicensePlateValidateResponse.Data data = new LicensePlateValidateResponse.Data();
+                String timestampStr = request.getTimestamp().toString();
+                if (timestampStr.length() == 10) {
+                    // 秒级时间戳
+                    data.setTimestamp(request.getTimestamp());
+                } else if (timestampStr.length() == 13) {
+                    // 毫秒级时间戳
+                    long l = request.getTimestamp() / 1000;
+                    data.setTimestamp(l);
+                }
+                data.setScreen_message("数据上报成功");
+                data.setVoice_message("数据上报成功");
+                licensePlateValidateResponse.setData(data);
+                log.info("地磅数据保存成功 - ID: {}, 车牌: {}", record.getId(), record.getLicensePlate());
+                record.setEntId(entId);
+                externalWeighbridgePushService.pushWeighbridgeRecord(record);
+                WeighbridgeRecord weighbridgeRecord = new WeighbridgeRecord();
+                weighbridgeRecord.setId(record.getId());
+                weighbridgeRecord.setSuccessFlag(1);
+                weighbridgeRecordService.updateById(weighbridgeRecord);
+                return licensePlateValidateResponse;
+            } else {
+                log.error("地磅数据保存失败 - 车牌: {}", request.getLicensePlate());
+                return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
+            }
+
+        } catch (Exception e) {
+            log.error("地磅数据上报处理异常", e);
+            return getLicensePlateValidateResponse(request, licensePlateValidateResponse);
+            //throw new IotException(ErrorCodeEnum.SYSTEM_ERROR, "地磅数据上报异常: " + e.getMessage());
+        }
+    }
 }