|
|
@@ -22,11 +22,17 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* SystemFile RESTful接口:
|
|
|
@@ -349,12 +355,22 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
String uuidType = uuidTypes[index];
|
|
|
String fileMediaType = file.getContentType();
|
|
|
String newName = uuidType.split(";")[0];
|
|
|
- if (fileMediaType != null && fileMediaType.contains("image")) {
|
|
|
- newName = uuidType.split(";")[0] + "." +fileMediaType.split("/")[1];
|
|
|
- }
|
|
|
+
|
|
|
String uuid = uuidType.split(";")[0];
|
|
|
String fileType = uuidType.split(";")[1];
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
+ if (fileMediaType != null && fileMediaType.contains("image")) {
|
|
|
+ newName = uuidType.split(";")[0] + "." +fileMediaType.split("/")[1];
|
|
|
+ ////如果是图片
|
|
|
+ //BufferedImage originalImage = ImageIO.read(inputStream);
|
|
|
+ //// 确保原始图片有效且可以读取
|
|
|
+ //if (originalImage != null) {
|
|
|
+ // // 添加水印逻辑
|
|
|
+ // inputStream = addWatermark(originalImage);
|
|
|
+ // // 保存或返回带有水印的图片
|
|
|
+ // // ...
|
|
|
+ //}
|
|
|
+ }
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("/yyyy/MM/dd");
|
|
|
String filePath = simpleDateFormat.format(new Date()) + "/" + fileType;
|
|
|
boolean result = ftpFileUtil.uploadToFtp(inputStream, filePath, newName, false);
|
|
|
@@ -375,4 +391,32 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
}
|
|
|
return success();
|
|
|
}
|
|
|
+
|
|
|
+ //private InputStream addWatermark(BufferedImage originalImage) {
|
|
|
+ // int width = originalImage.getWidth();
|
|
|
+ // int height = originalImage.getHeight();
|
|
|
+ //
|
|
|
+ // //BufferedImage watermarkedImage = Scalr.resize(originalImage, width, height, Scalr.Mode.FIT_EXACT);
|
|
|
+ //
|
|
|
+ // Graphics2D graphics = watermarkedImage.createGraphics();
|
|
|
+ //
|
|
|
+ // // 设置水印样式
|
|
|
+ // graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ // Font font = new Font("Arial", Font.BOLD, 30);
|
|
|
+ // graphics.setFont(font);
|
|
|
+ // Color color = new Color(255, 0, 0, 128);
|
|
|
+ // graphics.setColor(color);
|
|
|
+ //
|
|
|
+ // // 添加水印文字
|
|
|
+ // graphics.drawString("Your Watermark Text", 10, height - 40); // 示例位置
|
|
|
+ //
|
|
|
+ // graphics.dispose();
|
|
|
+ //
|
|
|
+ // // 将带水印的图片转为InputStream
|
|
|
+ // ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ // ImageIO.write(watermarkedImage, "jpg", baos);
|
|
|
+ // InputStream watermarkedStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
+ //
|
|
|
+ // return watermarkedStream;
|
|
|
+ //}
|
|
|
}
|