From 0abe157e660dea46eb50cfb6e8064ec583cba75f Mon Sep 17 00:00:00 2001
From: ke <893754509@qq.com>
Date: Sun, 19 May 2024 15:43:37 +0800
Subject: [PATCH] 全景图更新切图功能kl 5-19 15
---
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java | 129 ++++++++++++++++++++++++++-----------------
1 files changed, 78 insertions(+), 51 deletions(-)
diff --git a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java
index 0effd1d..7e5c00d 100644
--- a/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java
+++ b/skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java
@@ -36,6 +36,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
import org.im4java.core.IM4JavaException;
import org.im4java.core.InfoException;
import org.springblade.core.secure.BladeUser;
@@ -44,6 +45,8 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.gistack.sm.skPanorama.entity.SkPanoramaEntity;
@@ -84,6 +87,7 @@
/**
* 对象存储构建类
*/
+ @Autowired
private final IOssClient iOssClient;
@@ -102,7 +106,9 @@
@GetMapping("/list")
@ApiOperation(value = "分页", notes = "传入skPanorama")
public R<IPage<SkPanoramaVO>> list(SkPanoramaEntity skPanorama, Query query) {
- IPage<SkPanoramaEntity> pages = skPanoramaService.page(Condition.getPage(query), Condition.getQueryWrapper(skPanorama));
+ QueryWrapper<SkPanoramaEntity> queryWrapper = Condition.getQueryWrapper(skPanorama);
+ queryWrapper.orderBy(true,false,"res_guid","sort" );
+ IPage<SkPanoramaEntity> pages = skPanoramaService.page(Condition.getPage(query), queryWrapper);
return R.data(SkPanoramaWrapper.build().pageVO(pages));
}
@@ -178,7 +184,24 @@
@PostMapping("/submit")
@ApiOperation(value = "新增或修改", notes = "传入skPanorama")
public R submit(@Valid @RequestBody SkPanoramaEntity skPanorama) {
+ if (skPanorama.getId() == null ) { // 新增
+ if (StringUtils.isBlank(skPanorama.getPicUrl())) {
+ skPanorama.setStatus(PanoramaUtilDict.panorama_status_0);
+ }
+ picIfFormate(skPanorama);
+ } else { // 修改
+ picIfFormate(skPanorama);
+ }
return R.status(skPanoramaService.saveOrUpdate(skPanorama));
+ }
+
+ private SkPanoramaEntity picIfFormate(SkPanoramaEntity skPanorama) {
+ Integer picwidth = skPanorama.getPicwidth();
+ Integer picheight = skPanorama.getPicheight();
+ if (picwidth == picheight * 2) {
+ skPanorama.setStatus(PanoramaUtilDict.panorama_status_2);
+ }
+ return skPanorama;
}
/**
@@ -254,7 +277,7 @@
public R cutPicture2(SkPanoramaEntity skPanorama)
throws IOException, InterruptedException, IM4JavaException, IllegalAccessException {
- SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+ SkPanoramaEntity entity = skPanoramaService.getById(skPanorama.getId());
String picUrl = entity.getPicUrl();
String picName = entity.getPicName();
String resGuid = entity.getResGuid();
@@ -263,29 +286,7 @@
String dirPath = linShiBaseUrl + resGuid + "/"; //临时文件夹路径
String lingshiPic = linShiBaseUrl + resGuid + "/" + picName; //临时文件
-// File dir = new File(dirPath);
-// if (dir.isDirectory()) {
-// // 清除该目录下的文件及子目录文件而不删除该目录文件夹。该目录不存在会报错
-// FileUtils.cleanDirectory(dir);
-// } else {
-// dir.mkdirs();
-// }
-// // 线上全景图路径,下载到临时路径
-// URL url = new URL(picUrl);
-// InputStream inputStream = url.openStream();
-// OutputStream outputStream = new FileOutputStream(lingshiPic);
-// byte[] buffer = new byte[4096];
-// int bytesRead;
-// while ((bytesRead = inputStream.read(buffer)) != -1) {
-// outputStream.write(buffer, 0, bytesRead);
-// }
-// inputStream.close();
-// outputStream.close();
-
-// Path lingshiqjPath = Paths.get(lingshiPic);
-// File lingshiqjfile = lingshiqjPath.toFile(); // 获取临时全景文件,准备切图
-
- File lingshiqjfile = getquanjingFile(dirPath,lingshiPic,entity);
+ File lingshiqjfile = getquanjingFile(dirPath,lingshiPic,entity.getId());
/**
* 这里开始切图
@@ -361,8 +362,10 @@
return R.status(true);
}
- private File getquanjingFile (String dirPath ,String linshiUrl , SkPanoramaEntity skPanorama) throws IOException {
- SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+ private File getquanjingFile (String dirPath ,String linshiUrl , Long id) throws IOException {
+
+// SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+ SkPanoramaEntity entity = skPanoramaService.getById(id);
String picUrl = entity.getPicUrl();
String picName = entity.getPicName();
String resGuid = entity.getResGuid();
@@ -397,20 +400,21 @@
* 将图片转化为长宽比为2:1的比例
*/
private static final String linShiformateBaseUrl = "/data/panorama/formate/";
- @GetMapping("/formatePic")
- public R formatePic(ParamEntity param) throws IOException, InterruptedException, IM4JavaException {
- List<String> idlist = param.getSkPanoramaIdList();
+ @PostMapping("/formatePic")
+ public R formatePic(@RequestParam String ids) throws IOException, InterruptedException, IM4JavaException {
+ List<Long> idlist = Func.toLongList(ids);
ArrayList<SkPanoramaEntity> panoramalist = new ArrayList<SkPanoramaEntity>();
ArrayList<FormateTuEntity> list = new ArrayList<FormateTuEntity>();
if (idlist!= null && idlist.size()>0) {
- for (String id : idlist ) {
+ for (Long id : idlist ) {
FormateTuEntity formateTuEntity = new FormateTuEntity();
- SkPanoramaEntity skPanorama = new SkPanoramaEntity();
- skPanorama.setId(Long.valueOf(id));
- SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+// SkPanoramaEntity skPanorama = new SkPanoramaEntity();
+// skPanorama.setId(id);
+// SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+ SkPanoramaEntity entity = skPanoramaService.getById(id);
String picUrl = entity.getPicUrl();
String picName = entity.getPicName();
String resGuid = entity.getResGuid();
@@ -419,30 +423,54 @@
String dirPath = linShiformateBaseUrl + resGuid + "/"; //临时文件夹路径
String lingshiPic = linShiformateBaseUrl + resGuid + "/" + picName; //临时文件
- String lingshigeshibiliPic = linShiformateBaseUrl + resGuid + "/geshibili/" + picName; //格式化后的临时文件
+ String lingshigeshibilipath = linShiformateBaseUrl + resGuid + "/geshibili/" ;
+ String lingshigeshibiliPic = lingshigeshibilipath + picName; //格式化后的临时文件
- File lingshiqjfile = getquanjingFile(dirPath,lingshiPic,entity);
+ File lingshiqjfile = getquanjingFile(dirPath,lingshiPic,id);
+
+ // 创建文件夹
+ File lingshigeshibilidir = new File(lingshigeshibilipath);
+ if (lingshigeshibilidir.isDirectory()) {
+ // 清除该目录下的文件及子目录文件而不删除该目录文件夹。该目录不存在会报错
+ FileUtils.cleanDirectory(lingshigeshibilidir);
+ } else {
+ lingshigeshibilidir.mkdirs();
+ }
/**************进行格式化******************/
// 获取原始全景图图片信息
HashMap<String, Integer> imgInfoRT = Img4JavaUtil.getImgInfoRT(lingshiqjfile);
Integer width = imgInfoRT.get("width");
Integer height = imgInfoRT.get("height");
+ if (width == height * 2) {
+ // 已经符合格式化标准
+ entity.setStatus(PanoramaUtilDict.panorama_status_2);
+ boolean b = skPanoramaService.updateBatchById(panoramalist);
+ return R.status( b);
+ } else {
+ Integer newWidth = height * 2;
+ // 图片格式化
+ Img4JavaUtil.sampleImg(lingshiPic,lingshigeshibiliPic, newWidth , height,null);
+ Path lingshiformPath = Paths.get(lingshigeshibiliPic);
+ File lingshiformFile = lingshiformPath.toFile(); // 获取临时全景文件
+ if(lingshiformFile.exists()) {
+ formateTuEntity.setPicName(picName);
+ formateTuEntity.setId(Long.toString(id));
+ formateTuEntity.setResGuid(resGuid);
+ formateTuEntity.setLinshiUrl(lingshigeshibiliPic);
+ formateTuEntity.setPicheight(height);
+ formateTuEntity.setPicwidth(newWidth);
+ list.add(formateTuEntity);
+ }
+ // 完成格式化后删除原始临时图片
+ Path qietuPath = Paths.get(lingshiPic);
+ File yuanspic = qietuPath.toFile();
+ if (yuanspic.exists()) {
+ // 删除指定文件,不存在报异常
+ FileUtils.forceDelete(yuanspic);
+ }
- Integer newWidth = height * 2;
- Img4JavaUtil.resizeImg(lingshiPic,lingshigeshibiliPic, newWidth , height);
-
- Path lingshiformPath = Paths.get(lingshigeshibiliPic);
- File lingshiformFile = lingshiformPath.toFile(); // 获取临时全景文件
- if(lingshiformFile.exists()) {
- formateTuEntity.setPicName(picName);
- formateTuEntity.setId(id);
- formateTuEntity.setResGuid(resGuid);
- formateTuEntity.setLinshiUrl(lingshigeshibiliPic);
- formateTuEntity.setPicheight(height);
- formateTuEntity.setPicwidth(newWidth);
- list.add(formateTuEntity);
}
} // for循环结束
@@ -453,7 +481,6 @@
Object data = r.getData();
QieTuEntity result = JSONObject.parseObject(JSONObject.toJSONString(data),QieTuEntity.class);
ArrayList<FormateTuEntity> newList = result.getList();
-
if (newList != null && newList.size()>0) {
for (FormateTuEntity item : newList) {
@@ -474,7 +501,7 @@
boolean b = skPanoramaService.updateBatchById(panoramalist);
- return R.status(true);
+ return R.status( b);
}
--
Gitblit v1.9.3