|
@@ -5,6 +5,8 @@ import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.gis.common.config.RabbitConfig;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
+import com.gis.common.constant.MsgCode;
|
|
|
+import com.gis.common.exception.BaseRuntimeException;
|
|
|
import com.gis.common.task.AsyncTask;
|
|
|
import com.gis.common.util.*;
|
|
|
import com.gis.domain.dto.*;
|
|
@@ -69,7 +71,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result upload(MultipartFile file, String type) {
|
|
|
+ public Result upload(MultipartFile file, String type) {
|
|
|
// 检查非法文件上传
|
|
|
boolean checkFile = FileUtils.checkFile(file);
|
|
|
if (!checkFile) {
|
|
@@ -96,18 +98,22 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
String ossPreviewIcon = null;
|
|
|
|
|
|
FodderEntity entity = new FodderEntity();
|
|
|
+ try {
|
|
|
if (type.equals("pano")) {
|
|
|
String sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
newName = sceneCode+"." + suffix;
|
|
|
savePath =savePath + sceneCode + "/" + newName;
|
|
|
|
|
|
- try {
|
|
|
+
|
|
|
+
|
|
|
FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
- log.info("pano serverPath: " + savePath);
|
|
|
+
|
|
|
+ log.info("pano serverPath: " + savePath);
|
|
|
log.info("全景图片写入完成");
|
|
|
|
|
|
// 压缩图片并上传oss
|
|
|
- iconPath = fileUtils.compressImgAndUploadOss2(savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain);
|
|
|
+ iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
+ savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 600, 300, "/thumb_"+sceneCode+".jpg");
|
|
|
|
|
|
// 全景图的预览图
|
|
|
ossPreviewIcon = fileUtils.compressImgAndUploadOss2(
|
|
@@ -116,9 +122,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
|
|
|
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
entity.setSceneCode(sceneCode);
|
|
|
entity.setFilePath(savePath);
|
|
@@ -126,7 +130,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
} else {
|
|
|
ossUrl = configConstant.ossDomain+ossPath;
|
|
|
- try {
|
|
|
+
|
|
|
if (type.equals("image")) {
|
|
|
// 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
|
|
|
if (size > 1024) {
|
|
@@ -143,35 +147,35 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
// 普通素材直接上传oss, 服务器不保留文件
|
|
|
aliyunOssUtil.upload(file.getBytes(), ossPath);
|
|
|
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- entity.setType(type);
|
|
|
- entity.setName(fileName);
|
|
|
- entity.setFileName(newName);
|
|
|
- log.info("ossUrl: " + ossUrl);
|
|
|
- log.info("iconPath:" + iconPath);
|
|
|
-
|
|
|
- entity.setOssPath(ossUrl);
|
|
|
- entity.setIcon(iconPath);
|
|
|
- entity.setUserId(getUserNameForToken());
|
|
|
- entity.setFileSize(size+"");
|
|
|
- entity.setDpi(dpi);
|
|
|
- entity.setPreviewIcon(ossPreviewIcon);
|
|
|
-
|
|
|
- save(entity);
|
|
|
-
|
|
|
-
|
|
|
- if (type.equals("pano")) {
|
|
|
+ }
|
|
|
+ entity.setType(type);
|
|
|
+ entity.setName(fileName);
|
|
|
+ entity.setFileName(newName);
|
|
|
+ log.info("ossUrl: " + ossUrl);
|
|
|
+ log.info("iconPath:" + iconPath);
|
|
|
+
|
|
|
+ entity.setOssPath(ossUrl);
|
|
|
+ entity.setIcon(iconPath);
|
|
|
+ entity.setUserId(getUserNameForToken());
|
|
|
+ entity.setFileSize(size+"");
|
|
|
+ entity.setDpi(dpi);
|
|
|
+ entity.setPreviewIcon(ossPreviewIcon);
|
|
|
+
|
|
|
+ save(entity);
|
|
|
+
|
|
|
+ if (type.equals("pano")) {
|
|
|
//发消息到mq
|
|
|
rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
log.info("发送消息到队列完成: " + entity.getId());
|
|
|
}
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new BaseRuntimeException(MsgCode.e5003, "不支持此图片");
|
|
|
+ }
|
|
|
+
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|