InnerServiceImpl.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.http.ContentType;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.fdkankan.common.constant.*;
  9. import com.fdkankan.common.exception.BusinessException;
  10. import com.fdkankan.common.util.FileUtils;
  11. import com.fdkankan.contro.bean.SyncLaserResultBean;
  12. import com.fdkankan.contro.constant.UserEditDataType;
  13. import com.fdkankan.contro.entity.*;
  14. import com.fdkankan.contro.service.*;
  15. import com.fdkankan.fyun.config.FYunFileConfig;
  16. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  17. import com.fdkankan.model.constants.ConstantFileName;
  18. import com.fdkankan.model.constants.ConstantFilePath;
  19. import com.fdkankan.model.constants.UploadFilePath;
  20. import com.fdkankan.model.enums.ModelTypeEnums;
  21. import com.fdkankan.model.utils.CreateHouseJsonUtil;
  22. import com.fdkankan.model.utils.SceneUtil;
  23. import org.apache.commons.lang3.ObjectUtils;
  24. import org.apache.http.HttpHeaders;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.stereotype.Service;
  28. import javax.annotation.Resource;
  29. import java.io.File;
  30. import java.io.IOException;
  31. import java.util.*;
  32. @Service
  33. public class InnerServiceImpl implements IInnerService {
  34. @Value("${model.type:#{null}}")
  35. private String modelType;
  36. @Autowired
  37. private IScenePlusService scenePlusService;
  38. @Autowired
  39. private IScenePlusExtService scenePlusExtService;
  40. @Autowired
  41. private ICommonService commonService;
  42. @Resource
  43. private FYunFileServiceInterface fYunFileService;
  44. @Autowired
  45. private IFdkkLaserService fdkkLaserService;
  46. @Autowired
  47. private ICameraDetailService cameraDetailService;
  48. @Autowired
  49. private ICompanyService companyService;
  50. @Resource
  51. private FYunFileConfig fYunFileConfig;
  52. @Override
  53. public void uploadArtificialResult(String num) throws Exception {
  54. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  55. if(Objects.isNull(scenePlus)){
  56. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  57. }
  58. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  59. String path = scenePlusExt.getDataSource();
  60. JSONObject fdageData = commonService.getFdageData(path + File.separator + "capture" +File.separator+"data.fdage");
  61. Integer cameraType = 10;
  62. if(scenePlus.getSceneSource() == SceneSource.ZT.code()){
  63. cameraType = 13;
  64. }else{
  65. cameraType = 14;
  66. }
  67. Map<String, String> uploadFiles = commonService.getUploadFiles(scenePlus,path,cameraType,fdageData);
  68. scenePlus.setPayStatus(PayStatus.PAY.code());
  69. scenePlus.setUpdateTime(new Date());
  70. scenePlus.setSceneStatus(SceneStatus.NO_DISPLAY.code());
  71. Integer videoVersion = fdageData.getInteger("videoVersion");
  72. //读取计算结果文件生成videosJson
  73. JSONObject videosJson = commonService.getVideosJson(path, videoVersion, num, cameraType);
  74. boolean isObj = fdageData.containsKey("exportMeshObj") && fdageData.getIntValue("exportMeshObj") == 1;
  75. //上传全景图俯视图
  76. this.uploadFloorCad(path, num, uploadFiles);
  77. //由于3dtiles算法mesh文件发生变化,所以这里需要先清除一下oss的mesh目录,避免存在旧算法obj文件
  78. fYunFileService.deleteFolder(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh");
  79. fYunFileService.deleteFolder(String.format(UploadFilePath.IMG_VIEW_PATH, num) + ModelKind.THREE_D_TILE.code());
  80. //上传文件
  81. fYunFileService.uploadMulFiles(uploadFiles);
  82. //修改oss上dam的内容编码
  83. Map<String,String> damFileHeaders = new HashMap<>();
  84. damFileHeaders.put("Content-Encoding","gzip");
  85. String damPath = path + File.separator + "results" + File.separator + ConstantFileName.modelUUID + "_50k.dam";
  86. fYunFileService.uploadFile(damPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + ConstantFileName.modelUUID + "_50k.dam", damFileHeaders);
  87. //拷贝部分文件到编辑目录,用于用户编辑
  88. this.copyToEditDir(num);
  89. //计算完毕后,同步全景图到缓存目录
  90. // this.cachePanorama(path, sceneCode);
  91. //生成houseTypejson并上传
  92. boolean existHouseType = this.uploadHouseTypeJson(num, path);
  93. scenePlus.setHouseType(existHouseType ? CommonStatus.YES.code().intValue() : CommonStatus.NO.code().intValue());
  94. //生成floorpan.json
  95. commonService.uploadFloorplanJson(num, path);
  96. //重置异步操作记录
  97. commonService.removeSceneAsynOperLog(num);
  98. //清除用户编辑业务数据
  99. Set<String> bizs = new HashSet<>();
  100. bizs.add(UserEditDataType.BOX_MODEL.message());
  101. bizs.add(UserEditDataType.FLOORPLAN.message());
  102. bizs.add(UserEditDataType.FILTERS.message());
  103. commonService.initUserEditData(num, bizs, null);
  104. //上传计算结果文件
  105. commonService.uploadBuildResultData(num, path, SceneVersionType.V4.code());
  106. //容量统计
  107. Long space = commonService.getSpace(num);
  108. //写入数据库
  109. this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), 0L,isObj,scenePlusExt);
  110. Object[] editInfoArr = commonService.updateEditInfo(scenePlus);
  111. SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
  112. SceneEditInfoExt sceneEditInfoExt = (SceneEditInfoExt)editInfoArr[1];
  113. SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[2];
  114. //更新场景主表
  115. //如果相机容量不足,需要把场景的paystatus改为容量不足状态
  116. scenePlus.setPayStatus(commonService.getPayStatus(scenePlus.getCameraId(), space, fdageData));
  117. //统计原始资源大小
  118. scenePlusExt.setOrigSpace(FileUtil.size(new File(path.concat(File.separator).concat("capture"))));
  119. if (cameraType == 14) {
  120. //计算成功 激光转台相机 同步 请求
  121. fdkkLaserService.syncBuildResult(
  122. SyncLaserResultBean.builder()
  123. .num(num).dataSource(path)
  124. .sceneStatus(2)
  125. .createTime(scenePlus.getCreateTime())
  126. .shootCount(scenePlusExt.getShootCount())
  127. .payStatus(scenePlus.getPayStatus())
  128. .mixture(scenePlusExt.getMixture())
  129. .version(SceneVersionType.V4.code()).build());
  130. sceneEditControls.setShowMap(0);
  131. } else if (new File(path + "/results/laserData/vision_edit.txt").exists()) {
  132. fdkkLaserService.cloudPointBuild(num,path);
  133. }
  134. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  135. Company company = !ObjectUtils.isEmpty(cameraDetail.getCompanyId()) ? companyService.getById(cameraDetail.getCompanyId()) : null;
  136. //写scene.json
  137. commonService.writeSceneJson(num,sceneEditInfo, sceneEditInfoExt, sceneEditControls, scenePlus,scenePlusExt,company);
  138. this.uploadStatusJson(scenePlus, scenePlusExt);
  139. scenePlusService.updateById(scenePlus);
  140. scenePlusExtService.updateById(scenePlusExt);
  141. }
  142. private void uploadStatusJson(ScenePlus scenePlus, ScenePlusExt scenePlusExt){
  143. String num = scenePlus.getNum();
  144. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  145. Integer status = 1;
  146. if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){//如果是激光场景,需要激光系统那边完全处理好之后再发mq通知更新状态
  147. status = 0;
  148. }
  149. // 上传status JSON.
  150. JSONObject statusJson = new JSONObject();
  151. //临时将-2改成1,app还没完全更新
  152. statusJson.put("status", status);
  153. statusJson.put("webSite", scenePlusExt.getWebSite());
  154. statusJson.put("sceneNum", num);
  155. statusJson.put("thumb", scenePlusExt.getThumb());
  156. statusJson.put("payStatus", scenePlus.getPayStatus());
  157. statusJson.put("sceneScheme", scenePlusExt.getSceneScheme());
  158. FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", statusJson.toString());
  159. Map<String,String> headers = new HashMap<>();
  160. headers.put(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
  161. fYunFileService.uploadFile(ConstantFilePath.SCENE_PATH + "data/data" + num + File.separator + "status.json", dataViewPath + "status.json", headers);
  162. }
  163. private void uploadFloorCad(String path, String num, Map<String, String> uploadFiles){
  164. //户型图上传
  165. String dataViewPath = UploadFilePath.DATA_VIEW_PATH + "floor-cad-%s.%s";
  166. String floorCadPath = path + "/results/floorplan_cad";
  167. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  168. if(CollUtil.isNotEmpty(floorCadList)){
  169. floorCadList.stream().forEach(str->{
  170. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  171. String[] arr = substring.split("floor");
  172. String[] arr2 = arr[1].split("\\.");
  173. uploadFiles.put(str, String.format(dataViewPath, num, arr2[0], arr2[1]));
  174. });
  175. }
  176. }
  177. private void copyToEditDir(String num) throws IOException {
  178. String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
  179. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
  180. String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
  181. String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  182. Map<String, String> map = new HashMap<>();
  183. map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
  184. map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
  185. map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
  186. for (Map.Entry<String, String> entry : map.entrySet()) {
  187. fYunFileService.copyFileInBucket(entry.getValue(), entry.getKey());
  188. }
  189. }
  190. public boolean uploadHouseTypeJson(String num, String dataSource) {
  191. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  192. if (!new File(floorPlanCardFilePath).exists()) {
  193. return false;
  194. }
  195. JSONObject json = CreateHouseJsonUtil.createHouseTypeJsonByCad(floorPlanCardFilePath);
  196. if(Objects.isNull(json)){
  197. return false;
  198. }
  199. String hourseTypeJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "houseType.json";
  200. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  201. hourseTypeJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "houseType.json";
  202. fYunFileService.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  203. return true;
  204. }
  205. private void updateDbPlus(int sceneSource,Long space,String videosJson, Long computeTime,boolean isObj,ScenePlusExt scenePlusExt){
  206. scenePlusExt.setSpace(space);
  207. scenePlusExt.setComputeTime(computeTime.toString());
  208. scenePlusExt.setAlgorithmTime(new Date());
  209. scenePlusExt.setVideos(videosJson);
  210. scenePlusExt.setIsObj(isObj ? 1 : 0);
  211. if(ModelTypeEnums.TILE_CODE.equals(modelType)){
  212. scenePlusExt.setSceneScheme(3);
  213. }
  214. switch (SceneSource.get(sceneSource)){
  215. case BM:
  216. scenePlusExt.setSceneResolution(SceneResolution.two_K.code());
  217. scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
  218. break;
  219. case SM:
  220. scenePlusExt.setSceneResolution(SceneResolution.one_k.code());
  221. scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
  222. break;
  223. case ZT:
  224. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  225. scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
  226. break;
  227. case JG:
  228. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  229. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  230. break;
  231. case SG:
  232. scenePlusExt.setSceneResolution(SceneResolution.four_K.code());
  233. scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
  234. break;
  235. }
  236. String sceneKind = scenePlusExt.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  237. scenePlusExt.setSceneKind(sceneKind);
  238. // scenePlusExt.setModelKind(modelKind);
  239. //统计点位数量
  240. Map<String, Integer> result = this.getShootCount(scenePlusExt);
  241. Integer shootCount = result.get("shootCount");
  242. Integer mixture = result.get("mixture");
  243. scenePlusExt.setShootCount(shootCount);
  244. scenePlusExt.setMixture(mixture);
  245. scenePlusExtService.updateById(scenePlusExt);
  246. }
  247. private Map<String, Integer> getShootCount(ScenePlusExt scenePlusExt){
  248. Map<String, Integer> result = new HashMap<>();
  249. Integer shootCount = 0;
  250. Integer mixture = Objects.isNull(scenePlusExt.getMixture()) ? 0 : scenePlusExt.getMixture();
  251. String homePath = SceneUtil.getHomePath(scenePlusExt.getDataSource());
  252. JSONObject dataFdageObj = JSON.parseObject(fYunFileService.getFileContent(homePath.concat("data.fdage")));
  253. if(Objects.nonNull(dataFdageObj)){
  254. JSONArray points = dataFdageObj.getJSONArray("points");
  255. if(CollUtil.isNotEmpty(points)){
  256. shootCount = points.size();
  257. }
  258. }
  259. if(Objects.nonNull(shootCount) && shootCount > 0){
  260. if(Objects.nonNull(scenePlusExt.getLocation()) && scenePlusExt.getLocation() == 6){
  261. mixture = CommonStatus.YES.code().intValue();
  262. }
  263. }else{
  264. String slamDataStr = fYunFileService.getFileContent(homePath.concat("slam_data.json"));
  265. JSONObject slamDataObj = JSON.parseObject(slamDataStr);
  266. if(Objects.nonNull(slamDataObj)){
  267. JSONArray viewsInfo = slamDataObj.getJSONArray("views_info");
  268. if(CollUtil.isNotEmpty(viewsInfo)){
  269. shootCount = viewsInfo.stream().mapToInt(info -> {
  270. return ((JSONObject) info).getJSONArray("list_pose").size();
  271. }).sum();
  272. }
  273. }
  274. mixture = CommonStatus.NO.code().intValue();
  275. }
  276. result.put("shootCount", shootCount);
  277. result.put("mixture", mixture);
  278. return result;
  279. }
  280. }