From 2cba01a6b6f67cfa97d0c4e0cc589302fab817ba Mon Sep 17 00:00:00 2001
From: aix <vip_xiaobin810@163.com>
Date: Wed, 24 Jul 2024 11:41:37 +0800
Subject: [PATCH] 查询有变形水库
---
skjcmanager/skjcmanager-ops/skjcmanager-resource/src/main/java/cn/gistack/resource/endpoint/OssEndpoint.java | 196 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 196 insertions(+), 0 deletions(-)
diff --git a/skjcmanager/skjcmanager-ops/skjcmanager-resource/src/main/java/cn/gistack/resource/endpoint/OssEndpoint.java b/skjcmanager/skjcmanager-ops/skjcmanager-resource/src/main/java/cn/gistack/resource/endpoint/OssEndpoint.java
index 5255973..12bcb5e 100644
--- a/skjcmanager/skjcmanager-ops/skjcmanager-resource/src/main/java/cn/gistack/resource/endpoint/OssEndpoint.java
+++ b/skjcmanager/skjcmanager-ops/skjcmanager-resource/src/main/java/cn/gistack/resource/endpoint/OssEndpoint.java
@@ -17,10 +17,15 @@
package cn.gistack.resource.endpoint;
import cn.gistack.resource.builder.oss.OssBuilder;
+import cn.gistack.resource.entity.TextualResearchAttach;
+import cn.gistack.resource.panoramaUtils.Img4JavaUtil;
+import cn.gistack.resource.panoramaUtils.QietuResult;
import cn.gistack.resource.service.IAttachService;
+import cn.gistack.resource.service.TextualResearchAttachService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
+import org.apache.commons.io.FileUtils;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.oss.model.OssFile;
import org.springblade.core.secure.annotation.PreAuth;
@@ -32,6 +37,12 @@
import cn.gistack.resource.entity.Attach;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
/**
* 对象存储端点
@@ -54,6 +65,11 @@
* 附件表服务
*/
private final IAttachService attachService;
+
+ /**
+ * 附件表服务
+ */
+ private final TextualResearchAttachService textualResearchAttachService;
/**
* 创建存储桶
@@ -149,6 +165,184 @@
}
/**
+ * 自定义前缀上传文件
+ *
+ * @param file 文件
+ * @param prefixPath 文件
+ * @return ObjectStat
+ */
+ @SneakyThrows
+ @PostMapping("/put-file-by-prefix-path")
+ public R<BladeFile> putFileByPrefixPath(@RequestParam MultipartFile file,@RequestParam String prefixPath) {
+ BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
+ return R.data(bladeFile);
+ }
+
+ /**
+ * 批量自定义前缀上传文件
+ *
+ * @param files 文件
+ * @param prefixPath 文件
+ * @return ObjectStat
+ */
+ @SneakyThrows
+ @PostMapping("/batch-put-file-by-prefix-path")
+ public R batchPutFileByPrefixPath(@RequestParam MultipartFile[] files,@RequestParam String prefixPath) {
+ List<BladeFile> list = new ArrayList<>();
+ for (MultipartFile file : files) {
+ BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
+ list.add(bladeFile);
+ }
+ return R.data(list);
+ }
+
+ /**
+ * 考证附件上传并保存
+ * @param file 文件
+ * @param resGuid 水库编号
+ * @return
+ */
+ @SneakyThrows
+ @PostMapping("/put-file-by-textualResearchAttach")
+ public R putFileByPrefixTextualResearchAttach(@RequestParam MultipartFile file,String resGuid,Integer type) {
+ BladeFile bladeFile = ossBuilder.templateByPrefixPath("textualResearchAttach").putFile(file.getOriginalFilename(), file.getInputStream());
+ buildTextualResearchAttach(resGuid,bladeFile,type);
+ return R.data(bladeFile);
+ }
+
+ /**
+ * 全景图片上传,并切图
+ * @param multipartFile 文件
+ * @param resGuid 水库编号
+ * @return
+ */
+ @SneakyThrows
+ @PostMapping("/put-file-by-panorama")
+ public R putFileByPanorama(@RequestParam MultipartFile multipartFile, String resGuid) {
+
+ // 临时文件路径
+ String linShiBaseUrl = "/data/panorama/qietu/";
+// String fileName = multipartFile.getOriginalFilename();
+ // 获取文件名
+ String picName = multipartFile.getOriginalFilename();// 原始全景图名称
+ String dirPath = linShiBaseUrl + resGuid + "/"; //临时文件夹路径
+
+ File dir = new File(dirPath);
+ if (dir.isDirectory()) {
+ // 清除该目录下的文件及子目录文件而不删除该目录文件夹。该目录不存在会报错
+ FileUtils.cleanDirectory(dir);
+ } else {
+ dir.mkdirs();
+ }
+ String picUrl = dirPath + picName; // 原始全景图文件路径
+ File file = new File(picUrl); // 文件上传的原始全景图,存入临时路径
+ multipartFile.transferTo(file);
+ FileInputStream ysfileInputStream = new FileInputStream(file);
+ BladeFile qjbladeFile = ossBuilder.templateByPrefixPathPanorama("panorama", resGuid).putFile(picName, ysfileInputStream);
+ String yuanshiQJurl = qjbladeFile.getLink();
+ ysfileInputStream.close();
+
+ /**
+ * 这里开始切图
+ */
+ HashMap<String,String> qietuHashMap = new HashMap<String,String>();
+ int col = 8;
+ int row = 4;
+ String[] split = picName.split("\\.");
+ String picHeadName = split[0];
+ String picLastName = split[1];
+
+ // 获取原始全景图图片信息
+ HashMap<String, Integer> imgInfoRT = Img4JavaUtil.getImgInfoRT(file);
+ Integer width = imgInfoRT.get("width");
+ Integer height = imgInfoRT.get("height");
+ // 计算切成小图的长和宽
+ Integer biliWidth = width/col;
+ Integer biliHeight = height/row;
+
+ for (int i=0 ; i < col ; i++) {
+ // 计算图片的横坐标(长边)
+ int x = i * biliWidth;
+ for (int j=0 ; j<row ; j++){
+ // 计算图片的纵坐标(宽边)
+ int y = j * biliHeight;
+ // 切图名称
+ String outpicName = picHeadName + "_" + i + "_" +j + "." + picLastName;
+ // 切图后临时图片的的路径
+ String lastiUrl = dirPath + outpicName;
+ Img4JavaUtil.cropImg(picUrl ,lastiUrl ,biliWidth,biliHeight,x,y);// 切图存放进临时图片中
+ qietuHashMap.put(outpicName,lastiUrl);
+ }
+ }
+
+ // 切图完成后删除原始全景图
+ if (file.exists()) {
+ // 删除指定文件,不存在报异常
+ FileUtils.forceDelete(file);
+ }
+ /************************************切图结束********************************************/
+
+
+ List<String> qieTuUrlList = new ArrayList<String>();
+ String urlHead = null;
+ Set<String> mapKey = qietuHashMap.keySet();
+ if(qietuHashMap != null && qietuHashMap.size()>0) {
+ for (String picQName : mapKey) {
+ String url = qietuHashMap.get(picQName);
+ Path qietuPath = Paths.get(url);
+ File qietufile = qietuPath.toFile();
+ FileInputStream fileInputStream = new FileInputStream(qietufile);
+ BladeFile bladeFile = ossBuilder.templateByPrefixPathPanorama("panorama", resGuid).putFile(picQName, fileInputStream);
+ fileInputStream.close(); // 关闭文件流
+
+ // 切图上传完成后删除
+ if (qietufile.exists()) {
+ // 删除指定文件,不存在报异常
+ FileUtils.forceDelete(qietufile);
+ }
+ String link = bladeFile.getLink();
+ qieTuUrlList.add(link);// 上传后的图片路径
+ urlHead = link.replace(picQName,"");
+ }
+ }
+ QietuResult qietuResult = new QietuResult();
+ qietuResult.setQieTuUrlList(qieTuUrlList);
+ qietuResult.setUrlHead(urlHead);
+ qietuResult.setRow(row);
+ qietuResult.setCol(col);
+ qietuResult.setQuanJingWidth(width);
+ qietuResult.setQuanJingHeight(height);
+ qietuResult.setQjName(picName);
+ qietuResult.setQjUrl(yuanshiQJurl);
+
+
+ return R.data(qietuResult) ;
+ }
+
+ @SneakyThrows
+ @PostMapping("/put-file-by-panorama2")
+ public R putFileByPanorama2(@RequestParam MultipartFile multipartFile, String resGuid){
+
+ return null;
+ }
+
+
+ /**
+ * 保存考证附件上传数据
+ * @param bladeFile
+ */
+ private void buildTextualResearchAttach(String resGuid,BladeFile bladeFile,Integer type) {
+ TextualResearchAttach attach = new TextualResearchAttach();
+ attach.setResGuid(resGuid);
+ attach.setType(type);
+ attach.setPath(bladeFile.getName());
+ attach.setName(bladeFile.getOriginalName());
+ attach.setCreateTime(new Date());
+ // 保存
+ textualResearchAttachService.save(attach);
+ }
+
+ /**
* 上传文件
*
* @param fileName 存储桶对象名称
@@ -178,6 +372,8 @@
return R.data(bladeFile);
}
+
+
/**
* 上传文件并保存至附件表
*
--
Gitblit v1.9.3