From 9acb17a6871d84a85c373eb90b980f98894e30e0 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 18 二月 2025 17:58:48 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OssController.java | 136 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 113 insertions(+), 23 deletions(-)
diff --git a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OssController.java b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OssController.java
index f1db1a7..7f84359 100644
--- a/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OssController.java
+++ b/ruoyi-service/ruoyi-worker/src/main/java/com/ruoyi/worker/controller/OssController.java
@@ -10,8 +10,11 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
+import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -29,6 +32,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
+import java.util.concurrent.CompletableFuture;
/**
@@ -70,40 +74,126 @@
return R.ok(tencentCosUtil.upLoadFile(file));
}
+// @PostMapping(value = "/pic", produces = "application/json;charset=UTF-8")
+// @ApiOperation(value = "文件上传加水印", tags = "师傅端-文件上传")
+// @ApiImplicitParams({
+// @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true)
+// })
+// public R<String> pic(@RequestParam("file") MultipartFile file,String longitude,
+// String latitude) {
+//// Result<String> address = GaoDeMapUtil.getAddress(longitude, latitude);
+////// return R.fail();
+////
+//// // 获取当前时间
+////
+//// LocalDateTime date = LocalDateTime.now();
+////
+//// // 设置日期格式
+////
+//// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+////
+//// // 通过format调用转换的方法
+////
+//// String dateWatermark = formatter.format(date);
+////// System.err.println("==========="+LocalDateTime.now());
+//// log.error("==========="+LocalDateTime.now());
+////
+//// MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file,dateWatermark,address.getDatas());
+////// System.err.println("==========="+LocalDateTime.now());
+//// log.error("==========="+LocalDateTime.now());
+////
+////
+//// String url = tencentCosUtil.upLoadFile(watermarkFile);
+////// String url = tencentCosUtil.upLoadFile(file);
+//// log.error("==========="+LocalDateTime.now());
+//// return R.ok(url);
+//
+//
+// // 参数校验
+// if (file == null || file.isEmpty()) {
+// return R.fail("文件不能为空");
+// }
+// if (longitude == null || longitude.isEmpty() || latitude == null || latitude.isEmpty()) {
+// return R.fail("经纬度参数不能为空");
+// }
+//
+// try {
+// // 获取地址信息
+// Result<String> addressResult = GaoDeMapUtil.getAddress(longitude, latitude);
+// if (addressResult == null || addressResult.getDatas() == null) {
+// return R.fail("无法获取地址信息");
+// }
+//
+// // 获取当前时间
+// LocalDateTime date = LocalDateTime.now();
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+// String dateWatermark = formatter.format(date);
+// log.info("===========" + dateWatermark);
+//
+// // 给图片加水印
+// MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file, dateWatermark, addressResult.getDatas());
+// log.info("水印添加成功");
+//
+// // 上传到腾讯云COS
+// String url = tencentCosUtil.upLoadFile(watermarkFile);
+// log.info("文件上传成功,URL: " + url);
+//
+// return R.ok(url);
+// } catch (Exception e) {
+// log.error("文件上传加水印失败: ", e);
+// return R.fail("文件上传加水印失败: " + e.getMessage());
+// }
+// }
+
+ @Autowired
+ private ThreadPoolTaskExecutor taskExecutor;
@PostMapping(value = "/pic", produces = "application/json;charset=UTF-8")
@ApiOperation(value = "文件上传加水印", tags = "师傅端-文件上传")
@ApiImplicitParams({
@ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true)
})
- public R<String> pic(@RequestParam("file") MultipartFile file,@RequestParam String longitude,@RequestParam String address,
- @RequestParam String latitude) {
-// Result<String> address = GaoDeMapUtil.getAddress(longitude, latitude);
+ public CompletableFuture<R<String>> pic(@RequestParam("file") MultipartFile file, String longitude, String latitude) {
+ System.out.println("文件上传加水印=====>"+longitude+"====>"+latitude);
+ // 参数校验
+ if (file == null || file.isEmpty()) {
+ return CompletableFuture.completedFuture(R.fail("文件不能为空"));
+ }
+ if (longitude == null || longitude.isEmpty() || latitude == null || latitude.isEmpty()) {
+ return CompletableFuture.completedFuture(R.fail("经纬度参数不能为空"));
+ }
+ return CompletableFuture.supplyAsync(() -> {
+ try {
+ // 获取地址信息
+ Result<String> addressResult = GaoDeMapUtil.getAddress(longitude, latitude);
+ if (addressResult == null || addressResult.getDatas() == null) {
+ return R.fail("无法获取地址信息");
+ }
- // 获取当前时间
+ // 获取当前时间
+ LocalDateTime date = LocalDateTime.now();
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ String dateWatermark = formatter.format(date);
+ log.info("===========" + dateWatermark);
- LocalDateTime date = LocalDateTime.now();
+ // 给图片加水印
+ MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file, dateWatermark, addressResult.getDatas());
+ log.info("水印添加成功");
- // 设置日期格式
+ // 上传到腾讯云COS
+ String url = tencentCosUtil.upLoadFile(watermarkFile);
+ log.info("文件上传成功,URL: " + url);
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
- // 通过format调用转换的方法
-
- String dateWatermark = formatter.format(date);
-// System.err.println("==========="+LocalDateTime.now());
- log.error("==========="+LocalDateTime.now());
-
- MultipartFile watermarkFile = FileImageWatermarkUtils.markWithContent(file,dateWatermark,address);
-// System.err.println("==========="+LocalDateTime.now());
- log.error("==========="+LocalDateTime.now());
-
-
- String url = tencentCosUtil.upLoadFile(watermarkFile);
- log.error("==========="+LocalDateTime.now());
- return R.ok(url);
-
+ return R.ok(url);
+ } catch (Exception e) {
+ log.error("文件上传加水印失败: ", e);
+ return R.fail("文件上传加水印失败: " + e.getMessage());
+ }
+ }, taskExecutor);
}
+
+
+
}
--
Gitblit v1.7.1