|
@@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
@@ -198,7 +199,7 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
boolean isNewAdd = false;
|
|
|
HouseEntity house = null;
|
|
|
- if (param.getId() == null) {
|
|
|
+ if (null != param.getIsCreate() && param.getIsCreate().compareTo(0) == 0) {
|
|
|
isNewAdd = true;
|
|
|
}
|
|
|
house = updateOrInsertHouse(param);
|
|
@@ -214,12 +215,68 @@ public class HouseController extends BaseController {
|
|
|
String imageHighPath = null;
|
|
|
String imageLowPath = null;
|
|
|
for (String filename : fileNames) {
|
|
|
- filename = checkAndChangeFileName(filename);
|
|
|
- imageHighPath = OUTPATH + sceneCode + "/output_img/" + filename;
|
|
|
- imageLowPath = OUTPATH + sceneCode + "/output_img_low/" + filename;
|
|
|
+
|
|
|
+// filename = checkAndChangeFileName(filename);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(filename);
|
|
|
+ if(null == jsonObject){
|
|
|
+ log.error("转换json对象失败:{}" , filename);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String origin = jsonObject.getString("origin");
|
|
|
+ String newFileName = jsonObject.getString("name");
|
|
|
+ if(!StringUtils.isNoneEmpty(origin , newFileName)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将文件复制到本地,成新的文件名,将数据库中的原照片,都修改成新的文件名
|
|
|
+ ImageEntity imageEntity = imageService2.findByFileName(origin);
|
|
|
+ if(null == imageEntity){
|
|
|
+ log.warn("照片[{}]不存在" , origin);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 获取图片房间类型
|
|
|
+ String imageType = StringUtils.substringBefore(filename, "_");
|
|
|
+ imageEntity.setType(imageType);
|
|
|
+ if(StringUtils.isNotBlank(imageEntity.getLocalPath())){
|
|
|
+ String localPath = imageEntity.getLocalPath();
|
|
|
+ int index = localPath.indexOf(imageEntity.getFileName());
|
|
|
+ if(index == -1){
|
|
|
+ log.warn("照片本地路径格式有误");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String localDirectory = localPath.substring(index , localPath.length());
|
|
|
+ String newFileFullPath = localDirectory + newFileName;
|
|
|
+ File oldImage = new File(localPath);
|
|
|
+ File newImage = new File(newFileFullPath);
|
|
|
+ try {
|
|
|
+ FileCopyUtils.copy(oldImage , newImage);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("复制本地照片出现异常");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ imageEntity.setLocalPath(newFileFullPath);
|
|
|
+ imageEntity.setPath(newFileFullPath);
|
|
|
+ }
|
|
|
+ imageEntity.setFileName(newFileName);
|
|
|
+ if(StringUtils.isNotBlank(imageEntity.getVerticalPath())){
|
|
|
+ String verticalPath = imageEntity.getVerticalPath();
|
|
|
+ int tmpIndex = verticalPath.indexOf(origin);
|
|
|
+ if(tmpIndex != -1){
|
|
|
+ String newVerticalPath = verticalPath.substring(0 ,tmpIndex);
|
|
|
+ newVerticalPath += newFileName;
|
|
|
+ imageEntity.setVerticalPath(newVerticalPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int update = imageService2.update(imageEntity);
|
|
|
+ if(update != 1){
|
|
|
+ log.error("更新照片[{}]的数据失败" , origin);
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 ,"更新照片数据失败");
|
|
|
+ }
|
|
|
+ imageHighPath = OUTPATH + sceneCode + "/output_img/" + newFileName;
|
|
|
+ imageLowPath = OUTPATH + sceneCode + "/output_img_low/" + newFileName;
|
|
|
// 提前把算法的图片路径存到数据库,但不代表算法运行成功,最后好是要看house的状态;
|
|
|
- String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/"+ filename;
|
|
|
- String ossVerticalLowPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/low/"+ filename;
|
|
|
+ String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/"+ newFileName;
|
|
|
+ String ossVerticalLowPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/low/"+ newFileName;
|
|
|
// 封装垂直校验后的图片到信息到oss
|
|
|
ossVerticalImageHighMap.put(imageHighPath, ossVerticalHighPath);
|
|
|
ossVerticalImageLowMap.put(imageLowPath, ossVerticalLowPath);
|
|
@@ -255,6 +312,7 @@ public class HouseController extends BaseController {
|
|
|
return new R(MsgCode.SUCCESS_CODE, house);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// @RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
|
|
|
@ApiOperation("生成houseId和场景码")
|
|
|
@PostMapping(value = "addPosition")
|
|
@@ -279,7 +337,8 @@ public class HouseController extends BaseController {
|
|
|
String filename = file.getOriginalFilename();
|
|
|
filename = checkAndChangeFileName(filename);
|
|
|
String directoryName = OUTPATH + sceneCode + File.separator + "input_img"+ File.separator;
|
|
|
- String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/"+ filename;
|
|
|
+// String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/"+ filename;
|
|
|
+ String ossVerticalHighPath = ConstantFilePath.OSS_IMAGE_PATH+ sceneCode+"/pan/high/";
|
|
|
try {
|
|
|
imageResult = addAndGetResolutionRate(file , filename , directoryName ,
|
|
|
ossVerticalHighPath , houseId);
|
|
@@ -330,17 +389,21 @@ public class HouseController extends BaseController {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
// 获取图片房间类型
|
|
|
- String imageType = StringUtils.substringBefore(filename, "_");
|
|
|
+// String imageType = StringUtils.substringBefore(filename, "_");
|
|
|
|
|
|
File dir = new File(directoryName);
|
|
|
if(!dir.exists()){
|
|
|
dir.mkdirs();
|
|
|
}
|
|
|
// 本地图片保存位置: /root/data/kanfang/场景码/input_img/xxxx.jpg
|
|
|
- String fileFullPath = directoryName + filename;
|
|
|
+ String newFileName = generalRandFileName(filename);
|
|
|
+ log.info("修改后的文件名称为:{}" , newFileName);
|
|
|
+ String fileFullPath = directoryName + newFileName;
|
|
|
+ String oldFileFullPath = directoryName + filename;
|
|
|
+ ossVerticalHighPath = ossVerticalHighPath + newFileName;
|
|
|
ImageEntity image = new ImageEntity();
|
|
|
image.setVerticalPath(ossVerticalHighPath);
|
|
|
- image.setFileName(filename);
|
|
|
+ image.setFileName(newFileName);
|
|
|
// 这个参数给前端用,只要有文件名就可以了
|
|
|
image.setPath(fileFullPath);
|
|
|
image.setLocalPath(fileFullPath);
|
|
@@ -348,17 +411,26 @@ public class HouseController extends BaseController {
|
|
|
image.setHouseId(houseId);
|
|
|
// 默认所有图片都是一楼
|
|
|
image.setFloor(1);
|
|
|
- image.setType(imageType);
|
|
|
+// image.setType(imageType);
|
|
|
//将图片保存到本地指定目录filePath eg: /root/data/kanfang/d_9iRDUgn3l/input_img/xxx.jpg
|
|
|
saveFileToLocal(file , fileFullPath);
|
|
|
+ boolean delResult = FileUtils.deleteFile(oldFileFullPath);
|
|
|
+ if(!delResult){
|
|
|
+ log.error("删除旧文件[{}]失败" , delResult);
|
|
|
+ }
|
|
|
File localFile = new File(fileFullPath);
|
|
|
//生成缩略图,并上传到oss
|
|
|
- String scalImageFullPath = directoryName + "scal_" + filename;
|
|
|
+ String scalImageFullPath = directoryName + "scal_" + newFileName;
|
|
|
Thumbnails.of(localFile).size(128 , 256).outputQuality(0.8f).toFile(scalImageFullPath);
|
|
|
- String imageOssPath = ossPath + file.getOriginalFilename();
|
|
|
+ String imageOssPath = ossPath + "scal_" + newFileName;
|
|
|
log.info("生成的照片上传oss的路径:{}" , imageOssPath);
|
|
|
ossCheckPointUploadUtil.upload2(scalImageFullPath, imageOssPath);
|
|
|
String imageTotalOssUrl = ossQueryUrl + imageOssPath;
|
|
|
+ //删除缩略图的本地文件
|
|
|
+ boolean delScalResult = FileUtils.deleteFile(scalImageFullPath);
|
|
|
+ if(!delScalResult){
|
|
|
+ log.error("删除本地缩略图[{}]失败" , scalImageFullPath);
|
|
|
+ }
|
|
|
//照片分辨率
|
|
|
int totalResolutinRate = getImageResolutinoRate(localFile);
|
|
|
ImageResolutionRate maxResolutionRate = ImageResolutionRate.getResolutionRateByRate(totalResolutinRate);
|
|
@@ -370,10 +442,30 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
Map<String , Object> result = new HashMap<>();
|
|
|
result.put("rate" , maxResolutionRate.name());
|
|
|
+ result.put("fileName" , newFileName);
|
|
|
result.put("ossUrl" , imageTotalOssUrl);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private String generalRandFileName(String fileName){
|
|
|
+ if(StringUtils.isBlank(fileName)){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ int index = fileName.lastIndexOf(".");
|
|
|
+ if(index != -1){
|
|
|
+ String name = fileName.substring(0 , index);
|
|
|
+ String form = fileName.substring(index , fileName.length());
|
|
|
+ log.info("照片存名字部分为:{}" , name);
|
|
|
+ if(StringUtils.isNotBlank(name)){
|
|
|
+ Random random = new Random(10);
|
|
|
+ name += System.currentTimeMillis() + random.nextInt(10);
|
|
|
+ name += form;
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
private int getImageResolutinoRate(File localFile) throws IOException {
|
|
|
if(null != localFile){
|
|
|
int totalResolutinRate = -1;
|