|
|
@@ -106,6 +106,60 @@ public class WeighbridgeRecordManage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public LicensePlateValidateResponse handleWeighbridgePushV2(WeighbridgePushRequest request) {
|
|
|
+ log.info("处理地磅数据上报 - 车牌:{}, 地磅编号:{}, 重量:{}, 时间戳:{}",
|
|
|
+ request.getLicensePlate(),
|
|
|
+ request.getWeighbridgeCode(),
|
|
|
+ request.getGrossWeight(),
|
|
|
+ request.getTimestamp());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ // 保存到数据库
|
|
|
+ boolean saved = weighbridgeRecordService.save(record);
|
|
|
+ if (saved) {
|
|
|
+ // 异步处理图片上传
|
|
|
+ updateBase64ImageUrls(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());
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void updateImageUrls(WeighbridgePushRequest request, WeighbridgeRecord record) {
|
|
|
if (request.getImages() != null && request.getImages().length > 0) {
|
|
|
log.info("开始处理 {} 张图片上传,车牌号: {}", request.getImages().length, request.getLicensePlate());
|
|
|
@@ -133,6 +187,23 @@ public class WeighbridgeRecordManage {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void updateBase64ImageUrls(WeighbridgePushRequest request, WeighbridgeRecord record) {
|
|
|
+ if (request.getBase64Images() != null && !request.getBase64Images().isEmpty()) {
|
|
|
+ log.info("开始处理 {} 张Base64图片保存,车牌号: {}", request.getBase64Images().size(), request.getLicensePlate());
|
|
|
+ uploadService.processBase64ImagesToLocalAsync(request.getBase64Images(), request.getLicensePlate())
|
|
|
+ .thenAccept(photoUrls -> {
|
|
|
+ log.info("Base64图片保存完成,车牌号: {},照片数量: {}", request.getLicensePlate(),
|
|
|
+ photoUrls != null ? photoUrls.split(",").length : 0);
|
|
|
+ record.setPhotoUrls(photoUrls);
|
|
|
+ updatePhotoUrls(record.getId(), photoUrls);
|
|
|
+ })
|
|
|
+ .exceptionally(throwable -> {
|
|
|
+ log.error("异步保存Base64图片失败,车牌号: {}", request.getLicensePlate(), throwable);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static LicensePlateValidateResponse getLicensePlateValidateResponse(WeighbridgePushRequest request, LicensePlateValidateResponse licensePlateValidateResponse) {
|
|
|
|
|
|
licensePlateValidateResponse.setStatus(false);
|