From d2c1cbb1cb2f008b3c858485a383720da67b029f Mon Sep 17 00:00:00 2001
From: ke <893754509@qq.com>
Date: Wed, 15 May 2024 10:38:13 +0800
Subject: [PATCH] 全景图更新切图功能kl  5-15 15

---
 skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/skPanorama/controller/SkPanoramaController.java |  174 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 148 insertions(+), 26 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 a9dd7a5..0effd1d 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
@@ -18,9 +18,12 @@
 
 
 
+import cn.gistack.resource.entity.FormateTuEntity;
 import cn.gistack.resource.entity.QieTuEntity;
 import cn.gistack.resource.feign.IOssClient;
+import cn.gistack.sm.skPanorama.entity.ParamEntity;
 import cn.gistack.sm.skPanorama.utils.Img4JavaUtil;
+import cn.gistack.sm.skPanorama.utils.PanoramaUtilDict;
 import cn.gistack.sm.skPanoramaState.entity.SkPanoramaStateEntity;
 import cn.gistack.sm.skPanoramaState.service.ISkPanoramaStateService;
 import com.alibaba.fastjson.JSONObject;
@@ -245,43 +248,44 @@
 	}
 	 */
 
+
+	private static final String  linShiBaseUrl = "/data/panorama/qietu/";
 	@GetMapping("/cutPicture2")
 	public R cutPicture2(SkPanoramaEntity skPanorama)
 		throws IOException, InterruptedException, IM4JavaException, IllegalAccessException {
-		// 临时文件路径
-		String  linShiBaseUrl = "/data/panorama/qietu/";
 
 		SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
 		String picUrl = entity.getPicUrl();
 		String picName = entity.getPicName();
 		String resGuid = entity.getResGuid();
 
-
 		// 获取文件名
 		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 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);
 
 		/**
 		 * 这里开始切图
@@ -314,7 +318,7 @@
 				Img4JavaUtil.cropImg(picUrl ,lastiUrl ,biliWidth,biliHeight,x,y);// 切图存放进临时图片中
 				qietuHashMap.put(outpicName,lastiUrl);
 
-				System.err.println(lastiUrl);
+//				System.err.println(lastiUrl);
 			}
 		}
 
@@ -327,8 +331,9 @@
 		/************************************切图结束********************************************/
 
 		// 上传切片全景图
-		System.err.println(qietuHashMap.size());
-		System.err.println(resGuid);
+		System.err.println("切图的路径数量"+qietuHashMap.size());
+		System.err.println("水库编码"+resGuid);
+
 		QieTuEntity qieTuEntity = new QieTuEntity();
 		qieTuEntity.setQietuHashMap(qietuHashMap);
 		qieTuEntity.setResGuid(resGuid);
@@ -349,12 +354,129 @@
 		entity.setQiecol(col);
 		entity.setPicwidth(width);
 		entity.setPicheight(height);
+		entity.setStatus(PanoramaUtilDict.panorama_status_3);
 		skPanoramaService.updateById(entity);
 
 
 		return R.status(true);
 	}
 
+	private File getquanjingFile (String dirPath ,String linshiUrl , SkPanoramaEntity skPanorama) throws IOException {
+		SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+		String picUrl = entity.getPicUrl();
+		String picName = entity.getPicName();
+		String resGuid = entity.getResGuid();
+
+		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(linshiUrl);
+		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(linshiUrl);
+		File lingshiqjfile = lingshiqjPath.toFile(); // 获取临时全景文件
+		return  lingshiqjfile;
+	}
+
+
+	/**
+	 * 图片格式化
+	 * 将图片转化为长宽比为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();
+
+		ArrayList<SkPanoramaEntity> panoramalist = new ArrayList<SkPanoramaEntity>();
+
+		ArrayList<FormateTuEntity> list = new ArrayList<FormateTuEntity>();
+		if (idlist!= null && idlist.size()>0) {
+			for (String id : idlist ) {
+				FormateTuEntity formateTuEntity = new FormateTuEntity();
+
+				SkPanoramaEntity skPanorama = new SkPanoramaEntity();
+				skPanorama.setId(Long.valueOf(id));
+				SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama));
+				String picUrl = entity.getPicUrl();
+				String picName = entity.getPicName();
+				String resGuid = entity.getResGuid();
+
+				// 获取文件名
+				String dirPath = linShiformateBaseUrl + resGuid + "/"; //临时文件夹路径
+				String lingshiPic = linShiformateBaseUrl + resGuid + "/" + picName; //临时文件
+
+				String lingshigeshibiliPic = linShiformateBaseUrl + resGuid + "/geshibili/" + picName; //格式化后的临时文件
+
+				File lingshiqjfile = getquanjingFile(dirPath,lingshiPic,entity);
+
+				/**************进行格式化******************/
+				// 获取原始全景图图片信息
+				HashMap<String, Integer> imgInfoRT = Img4JavaUtil.getImgInfoRT(lingshiqjfile);
+				Integer width = imgInfoRT.get("width");
+				Integer height = imgInfoRT.get("height");
+
+
+				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循环结束
+			QieTuEntity qieTuEntity = new QieTuEntity();
+			qieTuEntity.setList(list);
+
+			R r = iOssClient.uploadFormate(qieTuEntity);
+			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) {
+					SkPanoramaEntity skPanoramaEntity = new SkPanoramaEntity();
+					String id = item.getId();
+					String linshiUrl = item.getLinshiUrl();// 格式化后图片路径
+					Integer picheight = item.getPicheight();
+					Integer picwidth = item.getPicwidth();
+					skPanoramaEntity.setId(Long.valueOf(id));
+					skPanoramaEntity.setPicUrl(linshiUrl);
+					skPanoramaEntity.setPicheight(picheight);
+					skPanoramaEntity.setPicwidth(picwidth);
+					skPanoramaEntity.setStatus(PanoramaUtilDict.panorama_status_2);
+					panoramalist.add(skPanoramaEntity);
+				}
+			}
+		}
+
+		boolean b = skPanoramaService.updateBatchById(panoramalist);
+
+		return R.status(true);
+	}
+
 
 
 }

--
Gitblit v1.9.3