|
@@ -14,6 +14,7 @@ import com.platform.utils.FileUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
@@ -21,6 +22,7 @@ import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 地磅记录业务编排类
|
|
* 地磅记录业务编排类
|
|
@@ -57,8 +59,9 @@ public class WeighbridgeRecordManage {
|
|
|
}
|
|
}
|
|
|
// 保存到数据库
|
|
// 保存到数据库
|
|
|
boolean saved = weighbridgeRecordService.save(record);
|
|
boolean saved = weighbridgeRecordService.save(record);
|
|
|
-
|
|
|
|
|
if (saved) {
|
|
if (saved) {
|
|
|
|
|
+ // 异步处理图片上传
|
|
|
|
|
+ updateImageUrls(request, record);
|
|
|
licensePlateValidateResponse.setStatus(true);
|
|
licensePlateValidateResponse.setStatus(true);
|
|
|
licensePlateValidateResponse.setCode(200);
|
|
licensePlateValidateResponse.setCode(200);
|
|
|
licensePlateValidateResponse.setMessage("上报成功,请放行");
|
|
licensePlateValidateResponse.setMessage("上报成功,请放行");
|
|
@@ -81,6 +84,24 @@ public class WeighbridgeRecordManage {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void updateImageUrls(WeighbridgePushRequest request, WeighbridgeRecord record) {
|
|
|
|
|
+ if (request.getImages() != null && request.getImages().length > 0) {
|
|
|
|
|
+ log.info("开始处理 {} 张图片上传,车牌号: {}", request.getImages().length, request.getLicensePlate());
|
|
|
|
|
+ processImageFilesAsync(request.getImages())
|
|
|
|
|
+ .thenAccept(photoUrls -> {
|
|
|
|
|
+ log.info("图片上传完成,车牌号: {},照片数量: {}", request.getLicensePlate(),
|
|
|
|
|
+ photoUrls != null ? photoUrls.split(",").length : 0);
|
|
|
|
|
+ record.setPhotoUrls(photoUrls);
|
|
|
|
|
+ // 更新数据库中的图片URL
|
|
|
|
|
+ updatePhotoUrls(record.getId(), photoUrls);
|
|
|
|
|
+ })
|
|
|
|
|
+ .exceptionally(throwable -> {
|
|
|
|
|
+ log.error("异步上传图片失败,车牌号: {}", request.getLicensePlate(), throwable);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static LicensePlateValidateResponse getLicensePlateValidateResponse(WeighbridgePushRequest request, LicensePlateValidateResponse licensePlateValidateResponse) {
|
|
private static LicensePlateValidateResponse getLicensePlateValidateResponse(WeighbridgePushRequest request, LicensePlateValidateResponse licensePlateValidateResponse) {
|
|
|
|
|
|
|
|
licensePlateValidateResponse.setStatus(false);
|
|
licensePlateValidateResponse.setStatus(false);
|
|
@@ -100,8 +121,8 @@ public class WeighbridgeRecordManage {
|
|
|
*/
|
|
*/
|
|
|
private WeighbridgeRecord buildWeighbridgeRecord(WeighbridgePushRequest request) {
|
|
private WeighbridgeRecord buildWeighbridgeRecord(WeighbridgePushRequest request) {
|
|
|
WeighbridgeRecord record = new WeighbridgeRecord();
|
|
WeighbridgeRecord record = new WeighbridgeRecord();
|
|
|
-
|
|
|
|
|
- // 基础信息
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 基础信息设置
|
|
|
record.setLicensePlate(request.getLicensePlate());
|
|
record.setLicensePlate(request.getLicensePlate());
|
|
|
record.setWeighbridgeCode(request.getWeighbridgeCode());
|
|
record.setWeighbridgeCode(request.getWeighbridgeCode());
|
|
|
String weighbridgeName = WeighbridgeEnum.getByCode(request.getWeighbridgeCode());
|
|
String weighbridgeName = WeighbridgeEnum.getByCode(request.getWeighbridgeCode());
|
|
@@ -109,21 +130,48 @@ public class WeighbridgeRecordManage {
|
|
|
record.setWeight(request.getGrossWeight());
|
|
record.setWeight(request.getGrossWeight());
|
|
|
record.setTag(request.getTag());
|
|
record.setTag(request.getTag());
|
|
|
|
|
|
|
|
- // 时间戳转换:自动识别秒/毫秒
|
|
|
|
|
|
|
+ // 时间戳转换
|
|
|
LocalDateTime weighTime = convertTimestamp(request.getTimestamp());
|
|
LocalDateTime weighTime = convertTimestamp(request.getTimestamp());
|
|
|
- log.info("称重时间戳:{};转换 - 时间: {}",request.getTimestamp(), weighTime);
|
|
|
|
|
|
|
+ log.info("称重时间戳:{};转换 - 时间: {}", request.getTimestamp(), weighTime);
|
|
|
record.setWeighTime(weighTime);
|
|
record.setWeighTime(weighTime);
|
|
|
|
|
|
|
|
- // 处理图片文件名(仅保存文件名,逗号分隔)
|
|
|
|
|
- if (request.getImages() != null && request.getImages().length > 0) {
|
|
|
|
|
- String photoUrls = processImageFiles(request.getImages());
|
|
|
|
|
- record.setPhotoUrls(photoUrls);
|
|
|
|
|
- log.info("处理图片文件 - 数量: {}, 文件名: {}", request.getImages().length, photoUrls);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return record;
|
|
return record;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 异步处理图片文件上传
|
|
|
|
|
+ */
|
|
|
|
|
+ @Async("taskExecutor")
|
|
|
|
|
+ public CompletableFuture<String> processImageFilesAsync(MultipartFile[] images) {
|
|
|
|
|
+ List<String> resultList = new ArrayList<>();
|
|
|
|
|
+ Arrays.stream(images).forEach(image -> {
|
|
|
|
|
+ String ossUrl = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ ossUrl = FileUtils.uploadFile(image);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("上传文件异常", e);
|
|
|
|
|
+ throw new IotException(ErrorCodeEnum.SYSTEM_ERROR, "上传文件异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(ossUrl)) {
|
|
|
|
|
+ resultList.add(ossUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return CompletableFuture.completedFuture(String.join(",", resultList));
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 异步更新图片URL
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updatePhotoUrls(Long recordId, String photoUrls) {
|
|
|
|
|
+ // 更新记录的图片URL
|
|
|
|
|
+ WeighbridgeRecord updateRecord = new WeighbridgeRecord();
|
|
|
|
|
+ updateRecord.setId(recordId);
|
|
|
|
|
+ updateRecord.setPhotoUrls(photoUrls);
|
|
|
|
|
+ log.info("更新图片URL - ID: {}, 图片URL: {}", recordId, photoUrls);
|
|
|
|
|
+ weighbridgeRecordService.updateById(updateRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 处理图片文件,提取文件名并拼接
|
|
* 处理图片文件,提取文件名并拼接
|
|
|
* @param images 图片文件数组
|
|
* @param images 图片文件数组
|