| | |
| | | */ |
| | | package cn.gistack.sm.skPanorama.controller; |
| | | |
| | | |
| | | |
| | | import cn.gistack.resource.entity.QieTuEntity; |
| | | import cn.gistack.resource.feign.IOssClient; |
| | | import cn.gistack.sm.skPanorama.utils.Img4JavaUtil; |
| | | import cn.gistack.sm.skPanoramaState.entity.SkPanoramaStateEntity; |
| | | import cn.gistack.sm.skPanoramaState.service.ISkPanoramaStateService; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import javax.validation.Valid; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.im4java.core.IM4JavaException; |
| | | import org.im4java.core.InfoException; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import cn.gistack.sm.skPanorama.entity.SkPanoramaEntity; |
| | |
| | | import cn.gistack.sm.skPanorama.service.ISkPanoramaService; |
| | | import org.springblade.core.boot.ctrl.BladeController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.io.*; |
| | | import java.lang.reflect.Field; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 水库全景图 控制器 |
| | |
| | | private final ISkPanoramaService skPanoramaService; |
| | | |
| | | private final ISkPanoramaStateService skPanoramaStateService; |
| | | /** |
| | | * 对象存储构建类 |
| | | */ |
| | | private final IOssClient iOssClient; |
| | | |
| | | |
| | | /** |
| | | * 水库全景图 详情 |
| | |
| | | return R.data(list); |
| | | } |
| | | |
| | | /** |
| | | * 全景图切图 |
| | | * 等比例切图 |
| | | * 长col:8 |
| | | * 宽row:4 |
| | | |
| | | @GetMapping("/cutPicture") |
| | | public void cutPicture(SkPanoramaEntity skPanorama) throws IOException { |
| | | // 临时文件路径 |
| | | String linShiBaseUrl = "/data/panorama/qietu/"; |
| | | |
| | | int col = 8; |
| | | int row = 4; |
| | | |
| | | |
| | | SkPanoramaEntity entity = skPanoramaService.getOne(Condition.getQueryWrapper(skPanorama)); |
| | | String picUrl = entity.getPicUrl(); |
| | | String picName = entity.getPicName(); |
| | | String resGuid = entity.getResGuid(); |
| | | String[] split = picName.split("\\."); |
| | | String picHeadName = split[0]; |
| | | String picLastName = split[1]; |
| | | |
| | | |
| | | HashMap<String, Integer> imgInfoRT = Img4JavaUtil.getImgInfoRT(picUrl); |
| | | |
| | | 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; |
| | | // Img4JavaUtil.cropImg(picUrl,"C:/Users/kelu/Desktop/qietuTest/"+outpicName,biliWidth,biliHeight,x,y); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | @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(); // 获取临时全景文件,准备切图 |
| | | |
| | | |
| | | /** |
| | | * 这里开始切图 |
| | | */ |
| | | HashMap<String,String> qietuHashMap = new HashMap<String,String>(); |
| | | int col = 4; |
| | | int row = 4; |
| | | String[] split = picName.split("\\."); |
| | | String picHeadName = split[0]; |
| | | String picLastName = split[1]; |
| | | |
| | | // 获取原始全景图图片信息 |
| | | HashMap<String, Integer> imgInfoRT = Img4JavaUtil.getImgInfoRT(lingshiqjfile); |
| | | 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); |
| | | |
| | | System.err.println(lastiUrl); |
| | | } |
| | | } |
| | | |
| | | // 切图完成后删除原始全景图 |
| | | if (lingshiqjfile.exists()) { |
| | | // 删除指定文件,不存在报异常 |
| | | FileUtils.forceDelete(lingshiqjfile); |
| | | } |
| | | |
| | | /************************************切图结束********************************************/ |
| | | |
| | | // 上传切片全景图 |
| | | System.err.println(qietuHashMap.size()); |
| | | System.err.println(resGuid); |
| | | QieTuEntity qieTuEntity = new QieTuEntity(); |
| | | qieTuEntity.setQietuHashMap(qietuHashMap); |
| | | qieTuEntity.setResGuid(resGuid); |
| | | R r = iOssClient.uploadQietu(qieTuEntity); |
| | | |
| | | Object data = r.getData(); |
| | | QieTuEntity result = JSONObject.parseObject(JSONObject.toJSONString(data),QieTuEntity.class); |
| | | HashMap<String, String> resultMap = result.getQietuHashMap(); |
| | | |
| | | |
| | | String qturlList = resultMap.get("qturlList"); |
| | | String urlHead = resultMap.get("urlHead"); |
| | | |
| | | |
| | | entity.setQietuurllist(qturlList); |
| | | entity.setUrlhead(urlHead); |
| | | entity.setQierow(row); |
| | | entity.setQiecol(col); |
| | | entity.setPicwidth(width); |
| | | entity.setPicheight(height); |
| | | skPanoramaService.updateById(entity); |
| | | |
| | | |
| | | return R.status(true); |
| | | } |
| | | |
| | | |
| | | |
| | | } |