|
@@ -16,16 +16,23 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
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.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SystemFile RESTful接口:
|
|
* SystemFile RESTful接口:
|
|
@@ -157,11 +164,11 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
public RESTfulResult insertFiles(String[] fileUuids, String[] fileNames, String[] fileTypes, Map<Object, MultipartFile> FileList, MultipartRequest request) throws Exception {
|
|
public RESTfulResult insertFiles(String[] fileUuids, String[] fileNames, String[] fileTypes, Map<Object, MultipartFile> FileList, MultipartRequest request) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
|
- List<MultipartFile> files = new ArrayList<>();
|
|
|
|
|
- int index=-1;
|
|
|
|
|
- for(int j = 0 ; j < fileTypes.length ; j ++ ) {
|
|
|
|
|
- for(int i=0;i<21;i++) {
|
|
|
|
|
- MultipartFile file = request.getFile("file" +j +"" + i);
|
|
|
|
|
|
|
+ List<MultipartFile> files = new ArrayList<>();
|
|
|
|
|
+ int index = -1;
|
|
|
|
|
+ for (int j = 0; j < fileTypes.length; j++) {
|
|
|
|
|
+ for (int i = 0; i < 21; i++) {
|
|
|
|
|
+ MultipartFile file = request.getFile("file" + j + "" + i);
|
|
|
if (file != null) {
|
|
if (file != null) {
|
|
|
files.add(file);
|
|
files.add(file);
|
|
|
if (index < 0) {
|
|
if (index < 0) {
|
|
@@ -171,7 +178,7 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(files.size() == 0) {
|
|
|
|
|
|
|
+ if (files.size() == 0) {
|
|
|
return failed("传输失败");
|
|
return failed("传输失败");
|
|
|
}
|
|
}
|
|
|
for (int i = 0; i < fileUuids.length; i++) {
|
|
for (int i = 0; i < fileUuids.length; i++) {
|
|
@@ -233,22 +240,22 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
|
|
|
|
|
SystemFile value = systemFileMapper.selectByPrimaryKey(parmas.get("id").toString());
|
|
SystemFile value = systemFileMapper.selectByPrimaryKey(parmas.get("id").toString());
|
|
|
|
|
|
|
|
- String fileName = value.getFilename();
|
|
|
|
|
- String filepath = value.getFilepath();
|
|
|
|
|
- if (fileName == null || fileName.isEmpty()) {
|
|
|
|
|
- return failed("该图片不存在!");
|
|
|
|
|
- }
|
|
|
|
|
- if (filepath == null || filepath.isEmpty()) {
|
|
|
|
|
- return failed("该图片地址不存在!");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String fileName = value.getFilename();
|
|
|
|
|
+ String filepath = value.getFilepath();
|
|
|
|
|
+ if (fileName == null || fileName.isEmpty()) {
|
|
|
|
|
+ return failed("该图片不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (filepath == null || filepath.isEmpty()) {
|
|
|
|
|
+ return failed("该图片地址不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- String result = ftpFileUtil.downloadFile(fileName, filepath);
|
|
|
|
|
- return success(result);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- e.getMessage();
|
|
|
|
|
- return failed();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ String result = ftpFileUtil.downloadFile(fileName, filepath);
|
|
|
|
|
+ return success(result);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.getMessage();
|
|
|
|
|
+ return failed();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -303,22 +310,24 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
|
|
|
|
|
@PostMapping("/previewfileList")
|
|
@PostMapping("/previewfileList")
|
|
|
public RESTfulResult previewfileList(@RequestBody HashMap map) {
|
|
public RESTfulResult previewfileList(@RequestBody HashMap map) {
|
|
|
- String uuid = map.get("uuid").toString();
|
|
|
|
|
|
|
+ String uuid = map.get("uuid").toString();
|
|
|
String[] uuidList = uuid.split(";");
|
|
String[] uuidList = uuid.split(";");
|
|
|
//遍历数组,去找文件名称和路径
|
|
//遍历数组,去找文件名称和路径
|
|
|
- List<Map<String,Object>> mapList = systemFileMapper.getFileInfo(uuidList);
|
|
|
|
|
- List<Map<String,Object>> resultList = new ArrayList<>();
|
|
|
|
|
- for (Map<String,Object> parmas : mapList) {
|
|
|
|
|
|
|
+ List<Map<String, Object>> mapList = systemFileMapper.getFileInfo(uuidList);
|
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
+ for (Map<String, Object> parmas : mapList) {
|
|
|
String filename = parmas.get("FILENAME").toString();
|
|
String filename = parmas.get("FILENAME").toString();
|
|
|
String filepath = parmas.get("FILEPATH").toString();
|
|
String filepath = parmas.get("FILEPATH").toString();
|
|
|
- if (filename == null ||filename.isEmpty()) {
|
|
|
|
|
|
|
+ if (filename == null || filename.isEmpty()) {
|
|
|
return failed("该图片不存在!");
|
|
return failed("该图片不存在!");
|
|
|
}
|
|
}
|
|
|
- if (filepath == null ||filepath.isEmpty()) {
|
|
|
|
|
|
|
+ if (filepath == null || filepath.isEmpty()) {
|
|
|
return failed("该图片地址不存在!");
|
|
return failed("该图片地址不存在!");
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- Map<String,Object> result = ftpFileUtil.downloadFileNew(filename, filepath);
|
|
|
|
|
|
|
+ Map<String, Object> result = ftpFileUtil.downloadFileNew(filename, filepath);
|
|
|
|
|
+ //如果是返回base64,则给这个;网络路径则给netUrl
|
|
|
|
|
+ result.put("dataType","base");
|
|
|
resultList.add(result);
|
|
resultList.add(result);
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
e.getMessage();
|
|
e.getMessage();
|
|
@@ -330,4 +339,84 @@ public class SystemFileController extends BaseRESTfulController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ @PostMapping("/insertFilesReal")
|
|
|
|
|
+ public RESTfulResult insertFilesReal(MultipartRequest request, String[] uuidTypes) throws Exception {
|
|
|
|
|
+ //List<MultipartFile> files = new ArrayList<>();
|
|
|
|
|
+ //获取多个文件
|
|
|
|
|
+ MultiValueMap<String, MultipartFile> multiFileMap = request.getMultiFileMap();
|
|
|
|
|
+ List<MultipartFile> files = multiFileMap.get("file");
|
|
|
|
|
+ System.out.println(uuidTypes + "uuidTypes");
|
|
|
|
|
+ System.out.println(request);
|
|
|
|
|
+ if (files.size() == 0) {
|
|
|
|
|
+ return failed("传输失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ for (MultipartFile file : files) {
|
|
|
|
|
+ String uuidType = uuidTypes[index];
|
|
|
|
|
+ String fileMediaType = file.getContentType();
|
|
|
|
|
+ String newName = uuidType.split(";")[0];
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ if (result) {
|
|
|
|
|
+ SystemFile uploadFile = new SystemFile();
|
|
|
|
|
+ uploadFile.setFilename(newName);
|
|
|
|
|
+ uploadFile.setFilepath(filePath + "/" + newName);
|
|
|
|
|
+ uploadFile.setId(uuid);
|
|
|
|
|
+ SystemFile modela = systemFileService.add(uploadFile);
|
|
|
|
|
+ if (modela != null) {
|
|
|
|
|
+ uuid += "," + modela.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return failed(null, "上传文件失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ index++;
|
|
|
|
|
+ }
|
|
|
|
|
+ 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;
|
|
|
|
|
+ //}
|
|
|
}
|
|
}
|