|
@@ -1,9 +1,11 @@
|
|
package com.gis.service.impl;
|
|
package com.gis.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.img.Img;
|
|
import cn.hutool.core.io.FileTypeUtil;
|
|
import cn.hutool.core.io.FileTypeUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.gis.common.constant.CmdConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.RabbitConfig;
|
|
import com.gis.common.constant.RabbitConfig;
|
|
import com.gis.common.task.AsyncTask;
|
|
import com.gis.common.task.AsyncTask;
|
|
@@ -114,19 +116,18 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, String> impl
|
|
SceneEntity entity = new SceneEntity();
|
|
SceneEntity entity = new SceneEntity();
|
|
|
|
|
|
|
|
|
|
- InputStream inputStream = null;
|
|
|
|
String basePath = null;
|
|
String basePath = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- inputStream = file.getInputStream();
|
|
|
|
|
|
|
|
|
|
|
|
- String type = FileTypeUtil.getType(inputStream);
|
|
|
|
|
|
+ String type = FileTypeUtil.getType(file.getInputStream());
|
|
if (!FileUtils.getType(type).equals("image")) {
|
|
if (!FileUtils.getType(type).equals("image")) {
|
|
log.error("非图片类型");
|
|
log.error("非图片类型");
|
|
return Result.failure(7001, "非图片类型");
|
|
return Result.failure(7001, "非图片类型");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // todo 下次发版,建议前端判断图片大小比例,后端耗性能,不处理
|
|
if (!FileUtils.checkScale(file.getInputStream())) {
|
|
if (!FileUtils.checkScale(file.getInputStream())) {
|
|
log.error("图片比例非2:1");
|
|
log.error("图片比例非2:1");
|
|
return Result.failure(7007, "图片比例非2:1");
|
|
return Result.failure(7007, "图片比例非2:1");
|
|
@@ -164,7 +165,10 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, String> impl
|
|
// 缩略图,使用切图那个thumb.jpg
|
|
// 缩略图,使用切图那个thumb.jpg
|
|
// 压缩图片并上传oss
|
|
// 压缩图片并上传oss
|
|
// 全景图缩略图统一命名规则: http:// oss/cms_pano_fcb/image/thumb_sceneCode.jpg
|
|
// 全景图缩略图统一命名规则: http:// oss/cms_pano_fcb/image/thumb_sceneCode.jpg
|
|
- String iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
|
|
|
+// String iconPath = fileUtils.compressImgAndUploadOss2(
|
|
|
|
+// panoPath, configConstant.filePath, configConstant.ossBasePath, configConstant.ossDomain, 600, 300, "image/thumb_"+sceneCode+".jpg");
|
|
|
|
+
|
|
|
|
+ String iconPath = convertAndUploadOss(
|
|
panoPath, configConstant.filePath, configConstant.ossBasePath, configConstant.ossDomain, 600, 300, "image/thumb_"+sceneCode+".jpg");
|
|
panoPath, configConstant.filePath, configConstant.ossBasePath, configConstant.ossDomain, 600, 300, "image/thumb_"+sceneCode+".jpg");
|
|
log.info("iconPath:" + iconPath);
|
|
log.info("iconPath:" + iconPath);
|
|
entity.setIcon(iconPath);
|
|
entity.setIcon(iconPath);
|
|
@@ -196,6 +200,53 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, String> impl
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 2021-04-27
|
|
|
|
+ * 使用convert 生成缩略图
|
|
|
|
+ * @param inputFilePath
|
|
|
|
+ * @param ossBasePath
|
|
|
|
+ * @param ossDomain
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String convertAndUploadOss(
|
|
|
|
+ String inputFilePath, String serverBasePath, String ossBasePath, String ossDomain, Integer width, Integer height, String fileName){
|
|
|
|
+
|
|
|
|
+ // 保存图片位置
|
|
|
|
+ String saveCompressImgPath = serverBasePath + fileName;
|
|
|
|
+ log.info("saveCompressImgPath: " + saveCompressImgPath);
|
|
|
|
+ String ossUrl = null;
|
|
|
|
+ try {
|
|
|
|
+// Img.from(new File(inputFilePath)).scale(width, height).write(new File(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);
|
|
|
|
+ log.info("图片压缩成功: " + saveCompressImgPath);
|
|
|
|
+
|
|
|
|
+ if (FileUtil.isFile(saveCompressImgPath)) {
|
|
|
|
+ // 上传oss
|
|
|
|
+ String ossPath = ossBasePath + fileName;
|
|
|
|
+ log.info("ossPath: " + ossPath);
|
|
|
|
+ asyncTask.uploadOss(saveCompressImgPath, ossPath);
|
|
|
|
+ ossUrl = ossDomain + ossPath;
|
|
|
|
+ log.info("图片上传成功: " + ossUrl);
|
|
|
|
+ } else {
|
|
|
|
+ log.error("缩略图不存在: " + saveCompressImgPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("图片格式有误,不支持此图片");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return ossUrl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询VR项目状态
|
|
* 查询VR项目状态
|