|
@@ -282,10 +282,13 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
ImageResolutionRate maxResolutionRate = ImageResolutionRate.getResolutionRateByRate(totalResolutinRate);
|
|
|
log.info("照片{}的像素为:{}", newFilePath, totalResolutinRate);
|
|
|
+ if(null == maxResolutionRate){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "照片分辨率超过识别范围");
|
|
|
+ }
|
|
|
if (null == maxTotalResolutionRate) {
|
|
|
maxTotalResolutionRate = maxResolutionRate;
|
|
|
} else {
|
|
|
- if (null != maxResolutionRate && maxResolutionRate.getRate() > maxTotalResolutionRate.getRate()) {
|
|
|
+ if (null != maxResolutionRate && maxResolutionRate.getOrder() > maxTotalResolutionRate.getOrder()) {
|
|
|
maxTotalResolutionRate = maxResolutionRate;
|
|
|
}
|
|
|
}
|
|
@@ -393,9 +396,12 @@ public class HouseController extends BaseController {
|
|
|
if (ImageResolutionRate.TWO_K.name().equals(maxResolutionRate)) {
|
|
|
//2k
|
|
|
sceneProEntity.setSceneScheme(11);
|
|
|
- } else {
|
|
|
+ }else if(ImageResolutionRate.FOUR_K.name().equals(maxResolutionRate)){
|
|
|
//4k
|
|
|
sceneProEntity.setSceneScheme(10);
|
|
|
+ }else{
|
|
|
+ //1k
|
|
|
+ sceneProEntity.setSceneScheme(12);
|
|
|
}
|
|
|
sceneProEntity.setNum(house.getSceneCode());
|
|
|
//TODO:不知道为何数据库设置的默认不生效
|
|
@@ -514,72 +520,6 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
-// public ImageResolutionRate addAndGetResolutionRate(MultipartFile file , String filename,String directoryName ,
|
|
|
- public Map<String, Object> addAndGetResolutionRate(CommonsMultipartFile file, String filename,
|
|
|
- String directoryName,
|
|
|
- String ossVerticalHighPath,
|
|
|
- Long houseId) throws IOException {
|
|
|
- if (null == file || null == houseId) {
|
|
|
- log.error("房源id或者文件为空,无法生成image记录");
|
|
|
- return new HashMap<>();
|
|
|
- }
|
|
|
- File dir = new File(directoryName);
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
- }
|
|
|
- // 本地图片保存位置: /root/data/kanfang/场景码/input_img/xxxx.jpg
|
|
|
- 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(newFileName);
|
|
|
- // 这个参数给前端用,只要有文件名就可以了
|
|
|
- image.setPath(fileFullPath);
|
|
|
- image.setLocalPath(fileFullPath);
|
|
|
-
|
|
|
- image.setHouseId(houseId);
|
|
|
- // 默认所有图片都是一楼
|
|
|
- image.setFloor(1);
|
|
|
-// 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("删除旧文件[{}]失败", oldFileFullPath);
|
|
|
- }
|
|
|
- File localFile = new File(fileFullPath);
|
|
|
- //生成缩略图,并上传到oss
|
|
|
- String scalImageFullPath = directoryName + "scal_" + newFileName;
|
|
|
- Thumbnails.of(localFile).size(128, 256).outputQuality(0.8f).toFile(scalImageFullPath);
|
|
|
- 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);
|
|
|
- log.info("照片{}的像素为:{}", fileFullPath, totalResolutinRate);
|
|
|
- image.setResolutionRate(null != maxResolutionRate ? maxResolutionRate.name() : "TWO_K");
|
|
|
- int insert = imageService2.save(image);
|
|
|
- if (insert != 1) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101, "新增image记录失败");
|
|
|
- }
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("rate", maxResolutionRate.name());
|
|
|
- result.put("fileName", newFileName);
|
|
|
- result.put("ossUrl", imageTotalOssUrl);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
private void addNewImage(long houseId,
|
|
|
String imageFileName, String imageLocalPath,
|
|
|
String ossVerticalHighPath,
|
|
@@ -598,7 +538,7 @@ public class HouseController extends BaseController {
|
|
|
// 默认所有图片都是一楼
|
|
|
image.setFloor(1);
|
|
|
|
|
|
- image.setResolutionRate(null != maxResolutionRate ? maxResolutionRate.name() : "TWO_K");
|
|
|
+ image.setResolutionRate(null != maxResolutionRate ? maxResolutionRate.name() : null);
|
|
|
int insert = imageService2.save(image);
|
|
|
if (insert != 1) {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D101, "新增image记录失败");
|
|
@@ -1097,9 +1037,14 @@ public class HouseController extends BaseController {
|
|
|
if (ImageResolutionRate.TWO_K.name().equals(imageResolution)) {
|
|
|
//2 K 照片
|
|
|
dataJson.put("skybox_type", "SKYBOX_V7");
|
|
|
- } else {
|
|
|
+ } else if(ImageResolutionRate.FOUR_K.name().equals(imageResolution)){
|
|
|
//4 k照片
|
|
|
dataJson.put("skybox_type", "SKYBOX_V6");
|
|
|
+ }else if(ImageResolutionRate.ONE_K.name().equals(imageResolution)){
|
|
|
+ //1 k照片
|
|
|
+ dataJson.put("skybox_type", "SKYBOX_V9");
|
|
|
+ }else{
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "照片的分辨率非法,无法决策模型类别");
|
|
|
}
|
|
|
dataJson.put("extras", null);
|
|
|
JSONObject extrasJson = new JSONObject();
|
|
@@ -1228,8 +1173,8 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
List<ImageEntity> imageEntities = imageService2.findByHouseId(houseEntity.getId());
|
|
|
if (CollectionUtils.isEmpty(imageEntities)) {
|
|
|
- log.error("房源[{}]下面无照片,默认返回2k的分辨率");
|
|
|
- return ImageResolutionRate.TWO_K.name();
|
|
|
+ log.error("房源[{}]下面无照片");
|
|
|
+ return null;
|
|
|
}
|
|
|
int sort = 0;
|
|
|
ImageResolutionRate maxResolution = null;
|
|
@@ -1247,7 +1192,7 @@ public class HouseController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
log.info("房源[{}]的照片最大的分辨率为:{}", houseEntity.getId(), null != maxResolution ? maxResolution.name() : "空值");
|
|
|
- return null != maxResolution ? maxResolution.name() : ImageResolutionRate.TWO_K.name();
|
|
|
+ return null != maxResolution ? maxResolution.name() : null;
|
|
|
}
|
|
|
|
|
|
|