|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.gis.common.config.RabbitConfig;
|
|
|
+import com.gis.common.constant.CmdConstant;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.constant.MsgCode;
|
|
|
import com.gis.common.exception.BaseRuntimeException;
|
|
@@ -67,8 +68,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result upload2(MultipartFile file, String type) {
|
|
|
- log.info("now time: " + new Date());
|
|
|
+ public Result upload(MultipartFile file, String type, String tempId) {
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
// 检查非法文件上传
|
|
@@ -111,29 +111,22 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
savePath =savePath + sceneCode + "/" + newName;
|
|
|
|
|
|
|
|
|
- log.info("准备写入全景图: " + new Date());
|
|
|
- Thread.sleep(10000);
|
|
|
|
|
|
FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
|
|
|
log.info("pano serverPath: " + savePath);
|
|
|
log.info("全景图片写入完成");
|
|
|
|
|
|
- log.info("睡眠10s: " + new Date());
|
|
|
- Thread.sleep(10000);
|
|
|
-
|
|
|
- log.info("准备执行压缩图片: " + new Date());
|
|
|
- // 压缩图片并上传oss
|
|
|
- iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
- savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 600, 300, "/thumb_"+sceneCode+".jpg");
|
|
|
-
|
|
|
+ // 压缩图片并上传oss, 以后内存不够,或者内存溢出改用算法提供的切图
|
|
|
+// iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
+// savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 600, 300, "/thumb_"+sceneCode+".jpg");
|
|
|
|
|
|
- log.info("压缩图片2: " + new Date());
|
|
|
// 全景图的预览图
|
|
|
- ossPreviewIcon = fileUtils.compressImgAndUploadOss2(
|
|
|
+ ossPreviewIcon = convertAndUploadOss(
|
|
|
savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
|
|
|
-
|
|
|
+ // 使用oss截取缩略图
|
|
|
+ iconPath = ossPreviewIcon ;
|
|
|
ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
|
|
|
|
|
|
|
|
@@ -147,13 +140,15 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
if (type.equals("image")) {
|
|
|
// 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
|
|
|
- if (size > 1024) {
|
|
|
- savePath = savePath + dirType + newName;
|
|
|
- FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
- iconPath = fileUtils.scaleImgAndUploadOss(savePath, configConstant.ossBasePath + dirType , configConstant.ossDomain);
|
|
|
- } else {
|
|
|
- iconPath = ossUrl;
|
|
|
- }
|
|
|
+// if (size > 1024) {
|
|
|
+//// savePath = savePath + dirType + newName;
|
|
|
+//// FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+//// iconPath = fileUtils.scaleImgAndUploadOss(savePath, configConstant.ossBasePath + dirType , configConstant.ossDomain);
|
|
|
+// // 使用oss做缩略图
|
|
|
+// iconPath = ossUrl ;
|
|
|
+// } else {
|
|
|
+// }
|
|
|
+ iconPath = ossUrl;
|
|
|
|
|
|
dpi = ImageUtil.dpi(file);
|
|
|
|
|
@@ -172,18 +167,19 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
entity.setOssPath(ossUrl);
|
|
|
entity.setIcon(iconPath);
|
|
|
- entity.setUserId("15015980188");
|
|
|
+ entity.setUserId(getUserNameForToken());
|
|
|
entity.setFileSize(size+"");
|
|
|
entity.setDpi(dpi);
|
|
|
entity.setPreviewIcon(ossPreviewIcon);
|
|
|
+ entity.setTempId(tempId);
|
|
|
|
|
|
-// save(entity);
|
|
|
+ save(entity);
|
|
|
|
|
|
-// if (type.equals("pano")) {
|
|
|
-// //发消息到mq
|
|
|
-// rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
-// log.info("发送消息到队列完成: " + entity.getId());
|
|
|
-// }
|
|
|
+ if (type.equals("pano")) {
|
|
|
+ //发消息到mq
|
|
|
+ rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
+ log.info("发送消息到队列完成: " + entity.getId());
|
|
|
+ }
|
|
|
long end = System.currentTimeMillis();
|
|
|
log.info("上传完成,耗时: {} s" , (end-start)/1000);
|
|
|
} catch (Exception e) {
|
|
@@ -198,8 +194,55 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 2021-04-27
|
|
|
+ * 压缩图片 使用convert 工具
|
|
|
+ * 固定名称: 名称固定是xxx.jpg
|
|
|
+ * @param inputFilePath
|
|
|
+ * @param ossBasePath
|
|
|
+ * @param ossDomain
|
|
|
+ * @param width 宽
|
|
|
+ * @param height 高
|
|
|
+ * @return 完整的oss访问地址
|
|
|
+ */
|
|
|
+ public String convertAndUploadOss(String inputFilePath, String ossBasePath, String ossDomain, Integer width, Integer height, String imgName){
|
|
|
+ String serverBasePath = StringUtils.substringBeforeLast(inputFilePath, "/");
|
|
|
+
|
|
|
+ // 保存图片位置
|
|
|
+ String saveCompressImgPath = serverBasePath + imgName;
|
|
|
+ String ossUrl = null;
|
|
|
+
|
|
|
+// Img.from(new File(inputFilePath)).scale(width, height).write(new File(saveCompressImgPath));
|
|
|
+// log.info("图片压缩成功: " + saveCompressImgPath);
|
|
|
+ // 使用convert压缩图片
|
|
|
+ String cmd = CmdConstant.CONVERT;
|
|
|
+ String size = width + "x" + height;
|
|
|
+ cmd = cmd.replace("@size", size);
|
|
|
+ cmd = cmd.replace("@input", inputFilePath);
|
|
|
+ cmd = cmd.replace("@output", saveCompressImgPath);
|
|
|
+
|
|
|
+ // 开始压缩
|
|
|
+ CmdUtils.callShell(cmd);
|
|
|
+
|
|
|
+
|
|
|
+ if (FileUtil.isFile(saveCompressImgPath)) {
|
|
|
+ // 上传oss
|
|
|
+ String ossPath = ossBasePath + imgName;
|
|
|
+ log.info("ossPath: " + ossPath);
|
|
|
+ aliyunOssUtil.upload(saveCompressImgPath, ossPath);
|
|
|
+ ossUrl = ossDomain + ossPath;
|
|
|
+ log.info("图片上传成功: " + ossUrl);
|
|
|
+ } else {
|
|
|
+ log.error("缩略图不存在: " + saveCompressImgPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ossUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public Result upload(MultipartFile file, String type, String tempId) {
|
|
|
+ public Result upload2(MultipartFile file, String type) {
|
|
|
+ log.info("now time: " + new Date());
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
// 检查非法文件上传
|
|
@@ -231,42 +274,50 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
FodderEntity entity = new FodderEntity();
|
|
|
try {
|
|
|
- if (type.equals("pano")) {
|
|
|
+ if (type.equals("pano")) {
|
|
|
|
|
|
- if ((size/1024) >= 120) {
|
|
|
- return Result.failure(MsgCode.e3004, "全景图文件不能超过120MB");
|
|
|
- }
|
|
|
+ if ((size/1024) >= 120) {
|
|
|
+ return Result.failure(MsgCode.e3004, "全景图文件不能超过120MB");
|
|
|
+ }
|
|
|
|
|
|
- String sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
- newName = sceneCode+"." + suffix;
|
|
|
- savePath =savePath + sceneCode + "/" + newName;
|
|
|
+ String sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
+ newName = sceneCode+"." + suffix;
|
|
|
+ savePath =savePath + sceneCode + "/" + newName;
|
|
|
|
|
|
|
|
|
+ log.info("准备写入全景图: " + new Date());
|
|
|
+ Thread.sleep(10000);
|
|
|
|
|
|
- FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+ FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
|
|
|
- log.info("pano serverPath: " + savePath);
|
|
|
+ log.info("pano serverPath: " + savePath);
|
|
|
log.info("全景图片写入完成");
|
|
|
|
|
|
- // 压缩图片并上传oss, 以后内存不够,或者内存溢出改用算法提供的切图
|
|
|
+ log.info("睡眠10s: " + new Date());
|
|
|
+ Thread.sleep(10000);
|
|
|
+
|
|
|
+ log.info("准备执行压缩图片: " + new Date());
|
|
|
+ // 压缩图片并上传oss
|
|
|
iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 600, 300, "/thumb_"+sceneCode+".jpg");
|
|
|
|
|
|
+
|
|
|
+ log.info("压缩图片2: " + new Date());
|
|
|
// 全景图的预览图
|
|
|
ossPreviewIcon = fileUtils.compressImgAndUploadOss2(
|
|
|
- savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
+ savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
|
|
|
|
|
|
ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
|
|
|
|
|
|
|
|
|
|
|
|
- entity.setSceneCode(sceneCode);
|
|
|
- entity.setFilePath(savePath);
|
|
|
- entity.setStatus(1);
|
|
|
+ entity.setSceneCode(sceneCode);
|
|
|
+ entity.setFilePath(savePath);
|
|
|
+ entity.setStatus(1);
|
|
|
|
|
|
- } else {
|
|
|
- ossUrl = configConstant.ossDomain+ossPath;
|
|
|
+ } else {
|
|
|
+ ossUrl = configConstant.ossDomain+ossPath;
|
|
|
|
|
|
if (type.equals("image")) {
|
|
|
// 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
|
|
@@ -285,7 +336,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
aliyunOssUtil.upload(file.getBytes(), ossPath);
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
entity.setType(type);
|
|
|
// 用前缀做名称
|
|
|
entity.setName(prefix);
|
|
@@ -295,19 +346,18 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
entity.setOssPath(ossUrl);
|
|
|
entity.setIcon(iconPath);
|
|
|
- entity.setUserId(getUserNameForToken());
|
|
|
+ entity.setUserId("15015980188");
|
|
|
entity.setFileSize(size+"");
|
|
|
entity.setDpi(dpi);
|
|
|
entity.setPreviewIcon(ossPreviewIcon);
|
|
|
- entity.setTempId(tempId);
|
|
|
|
|
|
- save(entity);
|
|
|
+// save(entity);
|
|
|
|
|
|
- if (type.equals("pano")) {
|
|
|
- //发消息到mq
|
|
|
- rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
- log.info("发送消息到队列完成: " + entity.getId());
|
|
|
- }
|
|
|
+// if (type.equals("pano")) {
|
|
|
+// //发消息到mq
|
|
|
+// rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
+// log.info("发送消息到队列完成: " + entity.getId());
|
|
|
+// }
|
|
|
long end = System.currentTimeMillis();
|
|
|
log.info("上传完成,耗时: {} s" , (end-start)/1000);
|
|
|
} catch (Exception e) {
|
|
@@ -322,6 +372,130 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
|
|
|
|
|
|
+// @Override
|
|
|
+// public Result upload(MultipartFile file, String type, String tempId) {
|
|
|
+//
|
|
|
+// long start = System.currentTimeMillis();
|
|
|
+// // 检查非法文件上传
|
|
|
+// boolean checkFile = FileUtils.checkFile(file);
|
|
|
+// if (!checkFile) {
|
|
|
+// return Result.failure("上传文件格式有误, 请重新上传");
|
|
|
+// }
|
|
|
+//
|
|
|
+// String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
|
+// String fileName = file.getOriginalFilename();
|
|
|
+// // 文件名校验长度
|
|
|
+// String prefix = StringUtils.substringBeforeLast(fileName, ".");
|
|
|
+// if (prefix.length() > 50) {
|
|
|
+// return Result.failure(3003, "文件名称不允许超过50个字节");
|
|
|
+// }
|
|
|
+// String suffix = StringUtils.substringAfterLast(fileName, ".");
|
|
|
+// String newName = time + "." +suffix;
|
|
|
+// String dirType = "fodder/";
|
|
|
+// long size = file.getSize();
|
|
|
+// size = size/1024;
|
|
|
+// log.info("fileSize: " + size);
|
|
|
+//
|
|
|
+// String ossUrl = null;
|
|
|
+// String iconPath = "0";
|
|
|
+// String dpi = "0";
|
|
|
+// String ossPath = configConstant.ossBasePath+dirType+newName;
|
|
|
+// String savePath = configConstant.serverBasePath;
|
|
|
+// String ossPreviewIcon = null;
|
|
|
+//
|
|
|
+// FodderEntity entity = new FodderEntity();
|
|
|
+// try {
|
|
|
+// if (type.equals("pano")) {
|
|
|
+//
|
|
|
+// if ((size/1024) >= 120) {
|
|
|
+// return Result.failure(MsgCode.e3004, "全景图文件不能超过120MB");
|
|
|
+// }
|
|
|
+//
|
|
|
+// String sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
+// newName = sceneCode+"." + suffix;
|
|
|
+// savePath =savePath + sceneCode + "/" + newName;
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+//
|
|
|
+// log.info("pano serverPath: " + savePath);
|
|
|
+// log.info("全景图片写入完成");
|
|
|
+//
|
|
|
+// // 压缩图片并上传oss, 以后内存不够,或者内存溢出改用算法提供的切图
|
|
|
+// iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
+// savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 600, 300, "/thumb_"+sceneCode+".jpg");
|
|
|
+//
|
|
|
+// // 全景图的预览图
|
|
|
+// ossPreviewIcon = fileUtils.compressImgAndUploadOss2(
|
|
|
+// savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
+//
|
|
|
+//
|
|
|
+// ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// entity.setSceneCode(sceneCode);
|
|
|
+// entity.setFilePath(savePath);
|
|
|
+// entity.setStatus(1);
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// ossUrl = configConstant.ossDomain+ossPath;
|
|
|
+//
|
|
|
+// if (type.equals("image")) {
|
|
|
+// // 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
|
|
|
+// if (size > 1024) {
|
|
|
+// savePath = savePath + dirType + newName;
|
|
|
+// FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+// iconPath = fileUtils.scaleImgAndUploadOss(savePath, configConstant.ossBasePath + dirType , configConstant.ossDomain);
|
|
|
+// } else {
|
|
|
+// iconPath = ossUrl;
|
|
|
+// }
|
|
|
+//
|
|
|
+// dpi = ImageUtil.dpi(file);
|
|
|
+//
|
|
|
+// }
|
|
|
+// // 普通素材直接上传oss, 服务器不保留文件
|
|
|
+// aliyunOssUtil.upload(file.getBytes(), ossPath);
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+// entity.setType(type);
|
|
|
+// // 用前缀做名称
|
|
|
+// entity.setName(prefix);
|
|
|
+// 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);
|
|
|
+// entity.setTempId(tempId);
|
|
|
+//
|
|
|
+// save(entity);
|
|
|
+//
|
|
|
+// if (type.equals("pano")) {
|
|
|
+// //发消息到mq
|
|
|
+// rabbitTemplate.convertAndSend(RabbitConfig.PANO_EXCHANGE, RabbitConfig.PANO_QUEUE_ROUTING, entity.getId());
|
|
|
+// log.info("发送消息到队列完成: " + entity.getId());
|
|
|
+// }
|
|
|
+// long end = System.currentTimeMillis();
|
|
|
+// log.info("上传完成,耗时: {} s" , (end-start)/1000);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// log.error(e.getMessage());
|
|
|
+// throw new BaseRuntimeException(MsgCode.e5003, "不支持此图片");
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// return Result.success(entity);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Result search(FodderPageDto param) {
|
|
|
startPage(param);
|