HaixinServiceImpl.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fdkankan.common.util.CmdUtils;
  8. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  9. import com.fdkankan.model.constants.ConstantFilePath;
  10. import com.fdkankan.model.constants.UploadFilePath;
  11. import com.fdkankan.scene.entity.ScenePlus;
  12. import com.fdkankan.scene.httpclient.HaixinClient;
  13. import com.fdkankan.scene.service.IHaixinService;
  14. import com.fdkankan.scene.service.IScenePlusService;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.stereotype.Service;
  19. import javax.annotation.Resource;
  20. import java.io.File;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.stream.Collectors;
  26. @Slf4j
  27. @Service
  28. public class HaixinServiceImpl implements IHaixinService {
  29. private static final String API_FDFS_UPLOAD = "/fdfs/api/file/upload";
  30. private static final String API_SUBMIT_FLOORPLAN = "/ecs/api/panoramicImageService/submitFloorPlan";
  31. @Value("${haixin.host}")
  32. private String haixinHost;
  33. @Resource
  34. private FYunFileServiceInterface fileServiceInterface;
  35. @Resource
  36. private HaixinClient haixinClient;
  37. @Autowired
  38. private IScenePlusService scenePlusService;
  39. @Override
  40. public void sendCadImgToHaixin(String num) throws Exception {
  41. log.info("进入场景平面图推送方法");
  42. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  43. String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
  44. List<String> userKeyS = fileServiceInterface.listRemoteFiles(userViewPath);
  45. if(CollUtil.isEmpty(userKeyS)){
  46. return;
  47. }
  48. log.info("user列表文件:{}", JSON.toJSONString(userKeyS));
  49. List<String> cadImgKeys = userKeyS.stream().filter(v->v.contains("cad-style-3-")).collect(Collectors.toList());
  50. if(CollUtil.isEmpty(cadImgKeys)){
  51. return;
  52. }
  53. log.info("平面图列表文件:{}", JSON.toJSONString(userKeyS));
  54. String currentTimeMillis = String.valueOf(System.currentTimeMillis());
  55. String tmpPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + currentTimeMillis + "/";
  56. cadImgKeys.stream().forEach(key->{
  57. fileServiceInterface.downloadFile(key, tmpPath + FileUtil.getName(key));
  58. });
  59. String floorPlanPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "floorplan.json";
  60. String floorPlanStr = fileServiceInterface.getFileContent(floorPlanPath);
  61. JSONObject floorPlanJson = JSON.parseObject(floorPlanStr);
  62. JSONArray floors = floorPlanJson.getJSONArray("floors");
  63. List<Map<String, String>> readme = floors.stream().map(f -> {
  64. JSONObject item = (JSONObject) f;
  65. Integer subgroup = item.getInteger("subgroup");
  66. String floor_name = item.getString("name");
  67. Map<String, String> map = new HashMap<>();
  68. map.put("floor_name", floor_name);
  69. map.put("img_name", "cad-style-3-" + subgroup + ".jpg");
  70. return map;
  71. }).collect(Collectors.toList());
  72. log.info("readme.json:{}", JSON.toJSONString(readme));
  73. FileUtil.writeUtf8String(JSON.toJSONString(readme), tmpPath + "readme.json");
  74. String zipPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + currentTimeMillis + ".zip";
  75. //打压缩包
  76. this.zip(tmpPath, zipPath);
  77. //上传到fastdf
  78. String url = haixinHost.concat(API_FDFS_UPLOAD);
  79. JSONObject jsonObject = haixinClient.uploadToFdfs(url, zipPath);
  80. JSONObject data = jsonObject.getJSONObject("data");
  81. //通知计算结果
  82. this.sendResult(scenePlus.getTaskId(), data.getString("fileNameRemote"));
  83. }
  84. private void zip(String sourcePath, String zipPath) throws Exception {
  85. FileUtil.mkParentDirs(zipPath);
  86. String cmd = "cd " + sourcePath + " && zip -r " + zipPath + " *";
  87. CmdUtils.callLineSh(cmd, 200);
  88. }
  89. @Override
  90. public void sendResult(String taskId, String packetPath){
  91. String url = haixinHost.concat(API_SUBMIT_FLOORPLAN);
  92. Map<String, String> params = new HashMap<>();
  93. params.put("vendor","A0BF");
  94. params.put("projectId", taskId);
  95. params.put("packetPath", packetPath);
  96. haixinClient.postJson(url, params);
  97. }
  98. }