|
@@ -14,6 +14,7 @@ import com.fdkankan.common.constant.*;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
|
+import com.fdkankan.fyun.constant.StorageType;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
@@ -60,6 +61,10 @@ import java.util.Objects;
|
|
@Service
|
|
@Service
|
|
public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
|
|
public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
|
|
|
|
|
|
|
|
+ @Value("${oss.prefix.ali}")
|
|
|
|
+ private String prefixAli;
|
|
|
|
+ @Value("${upload.type}")
|
|
|
|
+ private String type;
|
|
@Value("${oss.bucket:4dkankan}")
|
|
@Value("${oss.bucket:4dkankan}")
|
|
private String bucket;
|
|
private String bucket;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -290,67 +295,114 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
ScenePro scenePro = sceneProService.findBySceneNum(num);
|
|
ScenePro scenePro = sceneProService.findBySceneNum(num);
|
|
if(Objects.isNull(scenePro))
|
|
if(Objects.isNull(scenePro))
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
|
+
|
|
|
|
+ String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
|
|
|
|
+ String editUserPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
|
+ String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
|
|
|
|
+
|
|
JSONObject fileInfoJson = JSON.parseObject(param.getData());
|
|
JSONObject fileInfoJson = JSON.parseObject(param.getData());
|
|
- //户型图文件路径
|
|
|
|
|
|
+
|
|
|
|
+ String floors = fileInfoJson.getString("floors");
|
|
String cadInfo = fileInfoJson.getString("cadInfo");
|
|
String cadInfo = fileInfoJson.getString("cadInfo");
|
|
String floorJsonData = fileInfoJson.getString("floorJsonData");
|
|
String floorJsonData = fileInfoJson.getString("floorJsonData");
|
|
-
|
|
|
|
String filePaths = fileInfoJson.getString("filePaths");
|
|
String filePaths = fileInfoJson.getString("filePaths");
|
|
- cn.hutool.json.JSONArray filePathsArrs = JSONUtil.parseArray(filePaths);
|
|
|
|
- List<String> filePathsList = filePathsArrs.toList(String.class);
|
|
|
|
- StringBuilder filePathBuilder = new StringBuilder();
|
|
|
|
- filePathsList.parallelStream().forEach(path -> {
|
|
|
|
- filePathBuilder.append(",").append(path);
|
|
|
|
- });
|
|
|
|
|
|
+ Byte reSet = fileInfoJson.getByte("reSet");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String filePathStr = null;
|
|
|
|
+ //如果floors不为空,只需要根据对应楼层id修改楼层名称
|
|
|
|
+ if(StrUtil.isNotEmpty(floors)){
|
|
|
|
+ //从编辑目录中下载floorplan_cad.json、floorplan_user.json到本地
|
|
|
|
+ String floorCadUrl = prefixAli + editDataPath + "floorplan_cad.json?t=" + System.currentTimeMillis();
|
|
|
|
+ String floorUserUrl = prefixAli + editUserPath + "floorplan_user.json?t=" + System.currentTimeMillis();
|
|
|
|
+ //如果是云存储,将vision.modeldata下载到本地,如果是本地存储,场景计算完就已经将这个文件拷贝到编辑目录了存在这个文件了,不需要再下载
|
|
|
|
+ if(!StorageType.LOCAL.code().equals(this.type)){// TODO: 2022/2/15 这里有可能有问题,可能还需要考虑本地部署的情况
|
|
|
|
+ FileUtils.downLoadFromUrl(floorCadUrl, "floorplan_cad.json", localDataPath);
|
|
|
|
+ FileUtils.downLoadFromUrl(floorUserUrl, "floorplan_user.json", localDataPath);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ String floorCadStr = FileUtils.readFile(localDataPath + "floorplan_cad.json");
|
|
|
|
+ if(StrUtil.isNotEmpty(floorCadStr)){
|
|
|
|
+ JSONObject floorCadJson = this.updateFloorName(floors, floorCadStr);
|
|
|
|
+ FileUtils.writeFile(localDataPath + "floorplan_cad.json", floorCadJson.toString());
|
|
|
|
+ uploadToOssUtil.upload(localDataPath + "floorplan_cad.json", editDataPath+"floorplan_cad.json");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String floorUserStr = FileUtils.readFile(localDataPath + "floorplan_user.json");
|
|
|
|
+ if(StrUtil.isNotEmpty(floorUserStr)) {
|
|
|
|
+ JSONObject floorUserJson = this.updateFloorName(floors, floorUserStr);
|
|
|
|
+ FileUtils.writeFile(localDataPath + "floorplan_user.json", floorUserJson.toString());
|
|
|
|
+ uploadToOssUtil.upload(localDataPath + "floorplan_user.json",editUserPath + "floorplan_user.json");
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ //户型图文件路径
|
|
|
|
+ cn.hutool.json.JSONArray filePathsArrs = JSONUtil.parseArray(filePaths);
|
|
|
|
+ List<String> filePathsList = filePathsArrs.toList(String.class);
|
|
|
|
+ StringBuilder filePathBuilder = new StringBuilder();
|
|
|
|
+ filePathsList.parallelStream().forEach(path -> {
|
|
|
|
+ filePathBuilder.append(",").append(path);
|
|
|
|
+ });
|
|
|
|
+ filePathStr = filePathBuilder.substring(1);
|
|
|
|
+
|
|
|
|
+ //上传houst_floor.json文件
|
|
|
|
+ FileUtils.writeFile(localDataPath + "floorplan_user.json", floorJsonData);
|
|
|
|
+ uploadToOssUtil.upload(localDataPath + "floorplan_user.json", editUserPath + "floorplan_user.json");
|
|
|
|
+ }
|
|
|
|
|
|
//写入数据库
|
|
//写入数据库
|
|
|
|
+ Byte floorPlanUser = null;
|
|
|
|
+ if(StrUtil.isNotEmpty(floorJsonData)){
|
|
|
|
+ floorPlanUser = CommonStatus.YES.code();
|
|
|
|
+ }
|
|
|
|
+ if(CommonStatus.YES.code().equals(reSet)){
|
|
|
|
+ floorPlanUser = CommonStatus.NO.code();
|
|
|
|
+ }
|
|
SceneEditInfo sceneEditInfoDb = this.getBySceneProId(scenePro.getId());
|
|
SceneEditInfo sceneEditInfoDb = this.getBySceneProId(scenePro.getId());
|
|
if(Objects.nonNull(sceneEditInfoDb)){
|
|
if(Objects.nonNull(sceneEditInfoDb)){
|
|
- this.update(new LambdaUpdateWrapper<SceneEditInfo>()
|
|
|
|
- .setSql("version=version+"+1)
|
|
|
|
- .set(SceneEditInfo::getFloorPlanPath, filePathBuilder.substring(1))
|
|
|
|
- .set(SceneEditInfo::getCadInfo, cadInfo)
|
|
|
|
- .eq(SceneEditInfo::getId, sceneEditInfoDb.getId()));
|
|
|
|
|
|
+ LambdaUpdateWrapper<SceneEditInfo> updateWrapper = new LambdaUpdateWrapper<SceneEditInfo>()
|
|
|
|
+ .setSql("version=version+" + 1)
|
|
|
|
+ .eq(SceneEditInfo::getId, sceneEditInfoDb.getId());
|
|
|
|
+ if(StrUtil.isNotEmpty(filePathStr)){
|
|
|
|
+ updateWrapper.set(SceneEditInfo::getFloorPlanPath, filePathStr);
|
|
|
|
+ }
|
|
|
|
+ if(StrUtil.isNotEmpty(cadInfo)){
|
|
|
|
+ updateWrapper.set(SceneEditInfo::getCadInfo, cadInfo);
|
|
|
|
+ }
|
|
|
|
+ if(floorPlanUser != null){
|
|
|
|
+ updateWrapper.set(SceneEditInfo::getFloorPlanUser, floorPlanUser);
|
|
|
|
+ }
|
|
|
|
+ this.update(updateWrapper);
|
|
}else{
|
|
}else{
|
|
sceneEditInfoDb = new SceneEditInfo();
|
|
sceneEditInfoDb = new SceneEditInfo();
|
|
sceneEditInfoDb.setSceneProId(scenePro.getId());
|
|
sceneEditInfoDb.setSceneProId(scenePro.getId());
|
|
- sceneEditInfoDb.setFloorPlanPath(filePaths);
|
|
|
|
|
|
+ sceneEditInfoDb.setFloorPlanPath(filePathStr);
|
|
sceneEditInfoDb.setCadInfo(cadInfo);
|
|
sceneEditInfoDb.setCadInfo(cadInfo);
|
|
|
|
+ sceneEditInfoDb.setFloorPlanUser(floorPlanUser);
|
|
this.save(sceneEditInfoDb);
|
|
this.save(sceneEditInfoDb);
|
|
}
|
|
}
|
|
|
|
|
|
- //上传houst_floor.json文件
|
|
|
|
- String localDataPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num);
|
|
|
|
- String dataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
|
|
|
+ return ResultData.ok();
|
|
|
|
|
|
- // TODO: 2022/1/27 旧版本目录,待删除
|
|
|
|
- String oldDataPath = String.format(ConstantFilePath.DATA_PATH_FORMAT, num);
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if(StrUtil.isEmpty(floorJsonData)){
|
|
|
|
- if(scenePro == null){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
|
|
|
+ private JSONObject updateFloorName(String sourceFloors, String targeFloors){
|
|
|
|
+ JSONArray sourceFloorsJson = JSON.parseArray(sourceFloors);
|
|
|
|
+ JSONObject targeFloorsJson = JSONObject.parseObject(targeFloors);
|
|
|
|
+ JSONArray array = targeFloorsJson.getJSONArray("floors");
|
|
|
|
+ for (int i = 0; i < array.size(); ++i) {
|
|
|
|
+ JSONObject targetFloor = array.getJSONObject(i);
|
|
|
|
+ int targetId = targetFloor.getIntValue("id");
|
|
|
|
+ for (int j = 0; j < sourceFloorsJson.size(); ++j) {
|
|
|
|
+ JSONObject floor = sourceFloorsJson.getJSONObject(j);
|
|
|
|
+ int id = floor.getIntValue("id");
|
|
|
|
+ String name = floor.getString("name");
|
|
|
|
+ if (targetId != id)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ targetFloor.put("name", name);
|
|
}
|
|
}
|
|
- SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
|
|
|
|
- // TODO: 2022/1/27 老版本数据目录挂在nas,新版本目前流程尚不清楚,先暂时按照老版本写,以后再调整
|
|
|
|
- FileUtils.copyFile(sceneProExt.getDataSource() + "/results/floor.json", localDataPath + "houst_floor.json", true);
|
|
|
|
- uploadToOssUtil.upload(localDataPath + "houst_floor.json", dataPath + "houst_floor.json");
|
|
|
|
-
|
|
|
|
- // TODO: 2022/1/27 老版本上传目录 待删除
|
|
|
|
- uploadToOssUtil.upload(localDataPath + "houst_floor.json", oldDataPath + "houst_floor.json");
|
|
|
|
-
|
|
|
|
- String result = FileUtils.readFile(localDataPath + "houst_floor.json");
|
|
|
|
- return ResultData.ok(result);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- FileUtils.writeFile(localDataPath + "houst_floor.json", floorJsonData);
|
|
|
|
- uploadToOssUtil.upload(localDataPath + "houst_floor.json", dataPath + "houst_floor.json");
|
|
|
|
-
|
|
|
|
- // TODO: 2022/1/27 老版本上传目录 待删除
|
|
|
|
- uploadToOssUtil.upload(localDataPath + "houst_floor.json", oldDataPath + "houst_floor.json");
|
|
|
|
-
|
|
|
|
- return ResultData.ok();
|
|
|
|
-
|
|
|
|
|
|
+ return targeFloorsJson;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|