|
@@ -33,10 +33,7 @@ import org.springframework.util.StringUtils;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -66,19 +63,24 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileDao, SysFile> impleme
|
|
// 2:阿里云:
|
|
// 2:阿里云:
|
|
// 3:抖音云: https://www.volcengine.com/docs/6349/153626
|
|
// 3:抖音云: https://www.volcengine.com/docs/6349/153626
|
|
private SysFile setThumbUrl(SysFile sysFile, Integer width, Integer height, String backgroundColor) {
|
|
private SysFile setThumbUrl(SysFile sysFile, Integer width, Integer height, String backgroundColor) {
|
|
- if (StrUtil.isEmpty(sysFile.getUpload_id())) {
|
|
|
|
- // 本地上传
|
|
|
|
- if (sysFile.getTarget() == -1) {
|
|
|
|
- sysFile.setUrl_thumb(sysFile.getUrl() + "?w=" + width + "&h=" + height);
|
|
|
|
- }
|
|
|
|
- // 腾讯云 (color值通过base64加密, #f8f8f8)
|
|
|
|
- if (sysFile.getTarget() == 1) {
|
|
|
|
- System.out.println("base64 encode: " + Base64.encode(backgroundColor));
|
|
|
|
- sysFile.setUrl_thumb(sysFile.getUrl() + "?imageMogr2/thumbnail/" + width + "x" + height + "/pad/1/color/" + Base64.encode(backgroundColor));
|
|
|
|
- }
|
|
|
|
- // 抖音云
|
|
|
|
- if (sysFile.getTarget() == 3) {
|
|
|
|
- sysFile.setUrl_thumb(sysFile.getUrl() + "?x-tos-process=image/resize,w_" + width + ",h_" + height + ",m_pad,color_" + backgroundColor);
|
|
|
|
|
|
+ if (sysFile.getContent_type() != null) {
|
|
|
|
+ if (sysFile.getContent_type().toLowerCase().contains("image")) {
|
|
|
|
+ if (StrUtil.isEmpty(sysFile.getUpload_id())) {
|
|
|
|
+ // 本地上传
|
|
|
|
+ if (sysFile.getTarget() == -1) {
|
|
|
|
+ sysFile.setUrl_thumb(sysFile.getUrl() + "?w=" + width + "&h=" + height);
|
|
|
|
+ }
|
|
|
|
+ // 腾讯云 (color值通过base64加密, #f8f8f8)
|
|
|
|
+ if (sysFile.getTarget() == 1) {
|
|
|
|
+ backgroundColor = "#" + backgroundColor;
|
|
|
|
+ System.out.println("base64 encode: " + Base64.encode(backgroundColor));
|
|
|
|
+ sysFile.setUrl_thumb(sysFile.getUrl() + "?imageMogr2/thumbnail/" + width + "x" + height + "/pad/1/color/" + Base64.encode(backgroundColor));
|
|
|
|
+ }
|
|
|
|
+ // 抖音云
|
|
|
|
+ if (sysFile.getTarget() == 3) {
|
|
|
|
+ sysFile.setUrl_thumb(sysFile.getUrl() + "?x-tos-process=image/resize,w_" + width + ",h_" + height + ",m_pad,color_" + backgroundColor);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return sysFile;
|
|
return sysFile;
|
|
@@ -92,39 +94,25 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileDao, SysFile> impleme
|
|
PageUtils.startPage(); // 分页
|
|
PageUtils.startPage(); // 分页
|
|
List<SysFile> sysFileList = sysFileDao.selectUploadFileList(sysFile);
|
|
List<SysFile> sysFileList = sysFileDao.selectUploadFileList(sysFile);
|
|
|
|
|
|
- Integer UPLOAD_THUMB_SIZE = Convert.toInt(sysCommonService.getCommonByTag("UPLOAD_THUMB_SIZE"));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 要写成方便调用的封装方法?
|
|
|
|
-
|
|
|
|
- // 根据 Tag 获得 Options
|
|
|
|
- JSONArray options = sysCommonService.getCommonOptionByTag("UPLOAD_TARGET");
|
|
|
|
- System.out.println(options);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // 完成分页渲染
|
|
|
|
+ PageEntity pageEntity = new PageInfoResult(sysFileList).toEntity();
|
|
|
|
|
|
|
|
+ // -- 完成分页渲染之后,再做列表格式化 -----------------------------------
|
|
|
|
+ // [Common] 根据 Tag 获得 Options
|
|
|
|
+ JSONArray COMMON_OPTIONS = sysCommonService.getCommonOptionByTag("UPLOAD_TARGET");
|
|
|
|
+ // 遍历列表,赋值公共值翻译
|
|
sysFileList = sysFileList.stream().map(item -> {
|
|
sysFileList = sysFileList.stream().map(item -> {
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 根据 Tag Options 查询出 Label
|
|
|
|
- for (Object opt : options) {
|
|
|
|
- JSONObject opt_obj = JSONUtil.parseObj(opt);
|
|
|
|
- Integer value = Convert.toInt(opt_obj.get("value"));
|
|
|
|
- if (item.getTarget() == value) {
|
|
|
|
- item.setTarget_label(Convert.toStr(opt_obj.get("label")));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 不是图片不应该有 url_thumb?
|
|
|
|
-
|
|
|
|
- setThumbUrl(item, UPLOAD_THUMB_SIZE, UPLOAD_THUMB_SIZE, StyleEnums.THUMB_BACKGROUND.getValue());
|
|
|
|
|
|
+ // 查询出 上传存储介质(target) 的翻译
|
|
|
|
+ String target_label = Convert.toStr(sysCommonService.getLabelByValue(COMMON_OPTIONS, item.getTarget()));
|
|
|
|
+ item.setTarget_label(target_label);
|
|
return item;
|
|
return item;
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- return new PageInfoResult(sysFileList).toEntity();
|
|
|
|
|
|
+ List<Object> objectList = sysFileList.stream().map(file -> (Object) file).collect(Collectors.toList());
|
|
|
|
+ pageEntity.setList(objectList);
|
|
|
|
+ // -----------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ return pageEntity;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -200,6 +188,23 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileDao, SysFile> impleme
|
|
sysFileEntity.setMd5(uploadResult.getE_tag().replace("\"", ""));
|
|
sysFileEntity.setMd5(uploadResult.getE_tag().replace("\"", ""));
|
|
}
|
|
}
|
|
sysFileEntity.setTarget(target);
|
|
sysFileEntity.setTarget(target);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获得公共配置
|
|
|
|
+ List<SysCommon> sysCommonList = sysCommonService.getCommonByCategory("UPLOAD");
|
|
|
|
+ AtomicReference<Integer> UPLOAD_TARGET = new AtomicReference<>();
|
|
|
|
+ AtomicReference<Integer> UPLOAD_THUMB_SIZE = new AtomicReference<>();
|
|
|
|
+ sysCommonList.stream().forEach(sysCommon -> {
|
|
|
|
+ if (sysCommon.getTag().equals("UPLOAD_TARGET")) UPLOAD_TARGET.set(Convert.toInt(sysCommon.getValue()));
|
|
|
|
+ if (sysCommon.getTag().equals("UPLOAD_THUMB_SIZE")) UPLOAD_THUMB_SIZE.set(Convert.toInt(sysCommon.getValue()));
|
|
|
|
+ });
|
|
|
|
+ System.out.println("[系统配置] 上传目标(-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云): " + UPLOAD_TARGET);
|
|
|
|
+ System.out.println("[系统配置] 图片的缩略图宽高尺寸 (px): " + UPLOAD_THUMB_SIZE);
|
|
|
|
+
|
|
|
|
+ // 设置缩略图
|
|
|
|
+ sysFileEntity = setThumbUrl(sysFileEntity, UPLOAD_THUMB_SIZE.get(), UPLOAD_THUMB_SIZE.get(), StyleEnums.THUMB_BACKGROUND.getValue());
|
|
|
|
+
|
|
|
|
+
|
|
sysFileEntity.setCreate_time(DateUtil.now());
|
|
sysFileEntity.setCreate_time(DateUtil.now());
|
|
sysFileEntity.setUpdate_time(DateUtil.now());
|
|
sysFileEntity.setUpdate_time(DateUtil.now());
|
|
sysFileDao.insert(sysFileEntity);
|
|
sysFileDao.insert(sysFileEntity);
|