CommonServiceImpl.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package com.fdkankan.contro.mq.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.fdkankan.common.util.FileUtils;
  8. import com.fdkankan.contro.entity.*;
  9. import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
  10. import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
  11. import com.fdkankan.contro.mq.service.ICommonService;
  12. import com.fdkankan.contro.service.*;
  13. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  14. import com.fdkankan.model.constants.UploadFilePath;
  15. import com.fdkankan.model.utils.FloorPlanUserUtil;
  16. import com.fdkankan.sms.SendMailAcceUtils;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.cloud.context.config.annotation.RefreshScope;
  21. import org.springframework.stereotype.Service;
  22. import java.io.File;
  23. import java.util.*;
  24. @Slf4j
  25. @Service
  26. @RefreshScope
  27. public class CommonServiceImpl implements ICommonService {
  28. @Value("${main.url}")
  29. private String mainUrl;
  30. @Value("${env:gn}")
  31. private String env;
  32. @Value("${helpLink.zh-cn:https://docs.4dkankan.com/#/product/4dkk/zh-cn/README}")
  33. private String helpLinkZh;
  34. @Value("${helpLink.en-us:https://docs.4dkankan.com/#/product/4dkk/en-us/README}")
  35. private String helpLinkEn;
  36. @Autowired
  37. private FYunFileServiceInterface fYunFileServiceInterface;
  38. @Autowired
  39. private IScenePlusService scenePlusService;
  40. @Autowired
  41. private IScenePlusExtService scenePlusExtService;
  42. @Autowired
  43. private IMailTemplateService mailTemplateService;
  44. @Autowired
  45. private IUserService userService;
  46. @Autowired
  47. private ISceneProService sceneProService;
  48. @Override
  49. public void uploadBuildResultData(String num, String dataSource, String version) {
  50. Map<String, String> uploadMap = new HashMap<>();
  51. String ossResultPath = String.format(UploadFilePath.scene_result_data_path, num);
  52. //删除旧的文件目录
  53. fYunFileServiceInterface.deleteFolder(ossResultPath);
  54. //上传caches/images
  55. String localCachesImagePath = dataSource + "/caches/images/";
  56. String ossCachesImagePath = ossResultPath + "caches/images/";
  57. //先清除旧的全景图
  58. if(FileUtil.exist(localCachesImagePath)){
  59. fYunFileServiceInterface.uploadFileByCommand(localCachesImagePath, ossCachesImagePath);
  60. }
  61. //上传project.json
  62. String localProjectJsonPath = dataSource + "/project.json";
  63. String ossProjectJsonPath = ossResultPath + "project.json";
  64. if(FileUtil.exist(localProjectJsonPath)){
  65. uploadMap.put(localProjectJsonPath, ossProjectJsonPath);
  66. }
  67. //上传data.json
  68. String localDataJsonPath = dataSource + "/data.json";
  69. String ossDataJsonPath = ossResultPath + "data.json";
  70. if(FileUtil.exist(localDataJsonPath)){
  71. uploadMap.put(localDataJsonPath, ossDataJsonPath);
  72. }
  73. //户型图上传
  74. String floorplanCadPath = ossResultPath + "floorplan_cad";
  75. String cadPicPathFormat = floorplanCadPath + "/floor-cad-%s.%s";
  76. String floorCadPath = dataSource + "/results/floorplan_cad";
  77. //清除原有旧的cad图
  78. fYunFileServiceInterface.deleteFolder(floorplanCadPath);
  79. List<String> floorCadList = FileUtils.getFileList(floorCadPath);
  80. if(CollUtil.isNotEmpty(floorCadList)){
  81. floorCadList.stream().forEach(str->{
  82. String substring = str.substring(str.lastIndexOf(File.separator) + 1);
  83. String[] arr = substring.split("floor");
  84. String[] arr2 = arr[1].split("\\.");
  85. //上传到用户编辑目录
  86. uploadMap.put(str, String.format(cadPicPathFormat, arr2[0], arr2[1]));
  87. });
  88. }
  89. //上传深时场景生成obj需要的文件
  90. String localReconstruction = dataSource + "/caches/reconstruction/";
  91. String ossReconstruction = ossResultPath + "caches/reconstruction/";
  92. if(FileUtil.exist(localReconstruction)){
  93. fYunFileServiceInterface.uploadFileByCommand(localReconstruction, ossReconstruction);
  94. }
  95. String localDepthmap = dataSource + "/caches/depthmap/";
  96. String ossDepthmap = ossResultPath + "caches/depthmap/";
  97. if(FileUtil.exist(localDepthmap)){
  98. fYunFileServiceInterface.uploadFileByCommand(localDepthmap, ossDepthmap);
  99. }
  100. String localDepthmapAsc = dataSource + "/caches/depthmap_csc/";
  101. String ossDepthmapAsc = ossResultPath + "caches/depthmap_csc/";
  102. if(FileUtil.exist(localDepthmapAsc)){
  103. fYunFileServiceInterface.uploadFileByCommand(localDepthmapAsc, ossDepthmapAsc);
  104. }
  105. String localPanoramaJson = dataSource + "/caches/panorama.json";
  106. String ossPanoramaJson = ossResultPath + "caches/panorama.json";
  107. if(FileUtil.exist(localPanoramaJson)){
  108. fYunFileServiceInterface.uploadFile(localPanoramaJson, ossPanoramaJson);
  109. }
  110. String localLaserPly = dataSource + "/results/laserData/laser.ply";
  111. String ossLaserPly = ossResultPath + "results/laserData/laser.ply";
  112. if(FileUtil.exist(localLaserPly)){
  113. fYunFileServiceInterface.uploadFile(localLaserPly, ossLaserPly);
  114. }
  115. String localFloorGroupFixJson = dataSource + "/caches/floor_group_fix.json";
  116. String ossFloorGroupFixJson = ossResultPath + "caches/floor_group_fix.json";
  117. if(FileUtil.exist(localFloorGroupFixJson)){
  118. fYunFileServiceInterface.uploadFile(localFloorGroupFixJson, ossFloorGroupFixJson);
  119. }
  120. String localDepthmapVis = dataSource + "/caches/depthmap_vis";
  121. String ossDepthmapVis = ossResultPath + "caches/depthmap_vis";
  122. if(FileUtil.exist(localDepthmapVis)){
  123. fYunFileServiceInterface.uploadFileByCommand(localDepthmapVis, ossDepthmapVis);
  124. }
  125. //开始上传
  126. fYunFileServiceInterface.uploadMulFiles(uploadMap);
  127. }
  128. @Override
  129. public void initUserEditData(String num, Set<String> bizs, Map<String, Map<String ,Object>> params) {
  130. if(StrUtil.isEmpty(num) || CollUtil.isEmpty(bizs)){
  131. return;
  132. }
  133. for (String biz : bizs) {
  134. UserEditDataHandler handler = UserEditDataHandlerFactory.getHandler(biz);
  135. handler.init(num, CollUtil.isEmpty(params) ? null : params.get(biz));
  136. }
  137. }
  138. @Override
  139. public void uploadFloorplanJson(String num, String dataSource) throws Exception{
  140. String floorPlanCardFilePath = dataSource + File.separator + "results/floorplan_cad.json";
  141. if (!new File(floorPlanCardFilePath).exists()) {
  142. log.warn("floorplan_cad.json 文件不存在,文件路径:{}", floorPlanCardFilePath);
  143. return;
  144. }
  145. JSONObject json = FloorPlanUserUtil.createFloorPlanUserJson(floorPlanCardFilePath);
  146. if(Objects.isNull(json)){
  147. log.error("生成floorplan.json失败,cadPath:", floorPlanCardFilePath);
  148. throw new Exception("生成floorplan.json失败,cadPath:" + floorPlanCardFilePath);
  149. }
  150. String hourseTypeJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan.json";
  151. fYunFileServiceInterface.uploadFile(json.toJSONString().getBytes(), hourseTypeJsonPath);
  152. }
  153. @Override
  154. public void sendEmail(String num) {
  155. try {
  156. Long userId = null;
  157. String websize = "";
  158. String title = "";
  159. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  160. if(Objects.isNull(scenePlus)){
  161. ScenePro scenePro = sceneProService.getByNum(num);
  162. if(Objects.isNull(scenePro)){
  163. return;
  164. }
  165. userId = scenePro.getUserId();
  166. websize = scenePro.getWebSite();
  167. title = scenePro.getSceneName();
  168. }else{
  169. userId = scenePlus.getUserId();
  170. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  171. websize = scenePlusExt.getWebSite();
  172. title = scenePlus.getTitle();
  173. }
  174. if(Objects.isNull(userId)){
  175. return;
  176. }
  177. User user = userService.getById(userId);
  178. if(Objects.isNull(user) || StrUtil.isEmpty(user.getUserName())){
  179. return;
  180. }
  181. String toEmail = user.getUserName();
  182. String helpLink = helpLinkEn;
  183. String lang = "en";
  184. if("gn".equals(env)){
  185. lang = "zh";
  186. helpLink = helpLinkZh;
  187. }
  188. websize += "&lang=" + lang;
  189. MailTemplate mailTemplate = mailTemplateService.getOne(new LambdaQueryWrapper<MailTemplate>().eq(MailTemplate::getRemark, "计算完成").eq(MailTemplate::getLang, lang));
  190. String content = mailTemplate.getMsg().replaceAll("scene_name", title).replaceAll("scene_link", websize).replaceAll("help_link", helpLink);
  191. SendMailAcceUtils.sendMail(mailTemplate.getSendMail(), mailTemplate.getSendPassword(), mailTemplate.getSendHost(), toEmail, mailTemplate.getSubject(), content, null);
  192. }catch (Exception e){
  193. log.error("发送邮件失败,num:" + num, e);
  194. }
  195. }
  196. }