|
@@ -12,17 +12,22 @@ import com.gis.common.exception.BaseRuntimeException;
|
|
|
import com.gis.common.util.*;
|
|
|
import com.gis.domain.dto.*;
|
|
|
import com.gis.domain.entity.FodderEntity;
|
|
|
+import com.gis.domain.entity.WorkEntity;
|
|
|
import com.gis.mapper.FodderMapper;
|
|
|
import com.gis.mapper.IBaseMapper;
|
|
|
import com.gis.service.FodderService;
|
|
|
import com.gis.service.SceneService;
|
|
|
+import com.gis.service.WorkService;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
@@ -61,6 +66,9 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
@Autowired
|
|
|
AliyunOssUtil aliyunOssUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ WorkService workService;
|
|
|
+
|
|
|
// 用户最大空间3G
|
|
|
static int MAX_SIZE = 1024 * 1024 * 3;
|
|
|
|
|
@@ -72,7 +80,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result upload(MultipartFile file, String type, String tempId) {
|
|
|
+ public Result upload(MultipartFile file, String type, String tempId) {
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
String phone = getUserNameForToken();
|
|
@@ -93,16 +101,16 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
return Result.failure(3003, "文件名称不允许超过50个字节");
|
|
|
}
|
|
|
String suffix = StringUtils.substringAfterLast(fileName, ".");
|
|
|
- String newName = time + "." +suffix;
|
|
|
+ String newName = time + "." + suffix;
|
|
|
String dirType = "fodder/";
|
|
|
long size = file.getSize();
|
|
|
- size = size/1024;
|
|
|
+ size = size / 1024;
|
|
|
log.info("fileSize: " + size);
|
|
|
|
|
|
String ossUrl = null;
|
|
|
String iconPath = "0";
|
|
|
String dpi = "0";
|
|
|
- String ossPath = configConstant.ossBasePath+dirType+newName;
|
|
|
+ String ossPath = configConstant.ossBasePath + dirType + newName;
|
|
|
String savePath = configConstant.serverBasePath;
|
|
|
String ossPreviewIcon = null;
|
|
|
|
|
@@ -110,7 +118,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
try {
|
|
|
if (type.equals("pano")) {
|
|
|
|
|
|
- if ((size/1024) >= 120) {
|
|
|
+ if ((size / 1024) >= 120) {
|
|
|
return Result.failure(MsgCode.e3004, "全景图文件不能超过120MB");
|
|
|
}
|
|
|
|
|
@@ -123,9 +131,8 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
}
|
|
|
|
|
|
String sceneCode = RandomUtils.getSceneCode("fd720_");
|
|
|
- newName = sceneCode+"." + suffix;
|
|
|
- savePath =savePath + sceneCode + "/" + newName;
|
|
|
-
|
|
|
+ newName = sceneCode + "." + suffix;
|
|
|
+ savePath = savePath + sceneCode + "/" + newName;
|
|
|
|
|
|
|
|
|
FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
@@ -136,12 +143,11 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
|
|
|
// 全景图的预览图
|
|
|
ossPreviewIcon = convertAndUploadOss(
|
|
|
- savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
+ savePath, configConstant.ossBasePath + sceneCode, configConstant.ossDomain, 1920, 960, "/preview.jpg");
|
|
|
|
|
|
// 使用oss截取缩略图
|
|
|
- iconPath = ossPreviewIcon ;
|
|
|
- ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
|
|
|
-
|
|
|
+ iconPath = ossPreviewIcon;
|
|
|
+ ossUrl = configConstant.ossDomain + configConstant.ossBasePath + sceneCode;
|
|
|
|
|
|
|
|
|
entity.setSceneCode(sceneCode);
|
|
@@ -149,7 +155,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
entity.setStatus(1);
|
|
|
|
|
|
} else {
|
|
|
- ossUrl = configConstant.ossDomain+ossPath;
|
|
|
+ ossUrl = configConstant.ossDomain + ossPath;
|
|
|
|
|
|
if (type.equals("image")) {
|
|
|
// 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
|
|
@@ -176,7 +182,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
entity.setOssPath(ossUrl);
|
|
|
entity.setIcon(iconPath);
|
|
|
entity.setUserId(phone);
|
|
|
- entity.setFileSize(size+"");
|
|
|
+ entity.setFileSize(size + "");
|
|
|
entity.setDpi(dpi);
|
|
|
entity.setPreviewIcon(ossPreviewIcon);
|
|
|
entity.setTempId(tempId);
|
|
@@ -190,7 +196,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
log.info("发送消息到队列完成: " + entity.getId());
|
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
|
- log.info("上传完成,耗时: {} s" , (end-start)/1000);
|
|
|
+ log.info("上传完成,耗时: {} s", (end - start) / 1000);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error(e.getMessage());
|
|
@@ -202,19 +208,19 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 2021-04-27
|
|
|
* 压缩图片 使用convert 工具
|
|
|
* 固定名称: 名称固定是xxx.jpg
|
|
|
+ *
|
|
|
* @param inputFilePath
|
|
|
* @param ossBasePath
|
|
|
* @param ossDomain
|
|
|
- * @param width 宽
|
|
|
- * @param height 高
|
|
|
+ * @param width 宽
|
|
|
+ * @param height 高
|
|
|
* @return 完整的oss访问地址
|
|
|
*/
|
|
|
- public String convertAndUploadOss(String inputFilePath, String ossBasePath, String ossDomain, Integer width, Integer height, String imgName){
|
|
|
+ public String convertAndUploadOss(String inputFilePath, String ossBasePath, String ossDomain, Integer width, Integer height, String imgName) {
|
|
|
String serverBasePath = StringUtils.substringBeforeLast(inputFilePath, "/");
|
|
|
|
|
|
// 保存图片位置
|
|
@@ -247,10 +253,6 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public Result search(FodderPageDto param) {
|
|
|
startPage(param);
|
|
@@ -259,8 +261,6 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public Result selectFodderPano(PageDto param, String workId) {
|
|
|
startPage(param);
|
|
@@ -277,7 +277,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
List<FodderEntity> fodderList = pageInfo.getList();
|
|
|
for (FodderEntity entity : fodderList) {
|
|
|
String sceneCode = entity.getSceneCode();
|
|
|
- if (useScenes.contains(sceneCode)){
|
|
|
+ if (useScenes.contains(sceneCode)) {
|
|
|
entity.setIsUse(1);
|
|
|
}
|
|
|
result.add(entity);
|
|
@@ -293,19 +293,46 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
|
|
|
return Result.success(list);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result remove(Long id) {
|
|
|
+ FodderEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure("对象不存在, id: " + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查全景图是否被引用
|
|
|
+ if ("pano".equals(entity.getType())) {
|
|
|
+
|
|
|
+ if (entity.getStatus() == 1) {
|
|
|
+ return Result.failure("计算中的场景不能删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WorkEntity> list = workService.likeSceneCode(entity.getSceneCode());
|
|
|
+ if (list.size() > 0) {
|
|
|
+ return Result.failure(MsgCode.e3007, "素材已经被引用, 不能删除");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2022-06-09 删除服务器文件, 目前只有全景图
|
|
|
+ fileUtils.del(entity.getSceneCode());
|
|
|
+ entity.setIsDelete(1);
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ this.update(entity);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 2022-05-31 by owen
|
|
|
* 检查用户空间, 最大3G
|
|
|
+ *
|
|
|
* @param phone
|
|
|
*/
|
|
|
- private void checkUserSize(String phone){
|
|
|
+ private void checkUserSize(String phone) {
|
|
|
Integer size = entityMapper.countSize(phone);
|
|
|
log.info("当前用户空间: {} M", (size / 1024));
|
|
|
BaseRuntimeException.isTrue(size >= MAX_SIZE, null, "该用户空间已满");
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|