SceneProServiceImpl.java 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. package com.fdkankan.scene.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 cn.hutool.core.util.ZipUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.common.constant.ErrorCode;
  13. import com.fdkankan.common.constant.FileBizType;
  14. import com.fdkankan.common.exception.BusinessException;
  15. import com.fdkankan.common.util.FileUtils;
  16. import com.fdkankan.model.constants.ConstantFileName;
  17. import com.fdkankan.model.constants.ConstantFilePath;
  18. import com.fdkankan.model.constants.UploadFilePath;
  19. import com.fdkankan.model.utils.ComputerUtil;
  20. import com.fdkankan.model.utils.ConvertUtils;
  21. import com.fdkankan.model.utils.CreateObjUtil;
  22. import com.fdkankan.redis.constant.RedisKey;
  23. import com.fdkankan.redis.constant.RedisLockKey;
  24. import com.fdkankan.redis.util.RedisLockUtil;
  25. import com.fdkankan.redis.util.RedisUtil;
  26. import com.fdkankan.scene.bean.IconBean;
  27. import com.fdkankan.scene.bean.LaserSceneBean;
  28. import com.fdkankan.scene.bean.TagBean;
  29. import com.fdkankan.scene.entity.SceneEditInfo;
  30. import com.fdkankan.scene.entity.ScenePlus;
  31. import com.fdkankan.scene.entity.ScenePlusExt;
  32. import com.fdkankan.scene.entity.ScenePro;
  33. import com.fdkankan.scene.mapper.ISceneProMapper;
  34. import com.fdkankan.scene.oss.OssUtil;
  35. import com.fdkankan.scene.service.*;
  36. import com.fdkankan.scene.vo.*;
  37. import com.fdkankan.web.response.ResultData;
  38. import com.google.common.collect.Lists;
  39. import com.google.common.collect.Sets;
  40. import lombok.extern.slf4j.Slf4j;
  41. import org.springframework.beans.factory.annotation.Autowired;
  42. import org.springframework.beans.factory.annotation.Value;
  43. import org.springframework.stereotype.Service;
  44. import org.springframework.transaction.annotation.Transactional;
  45. import org.springframework.web.multipart.MultipartFile;
  46. import java.io.File;
  47. import java.io.IOException;
  48. import java.nio.charset.StandardCharsets;
  49. import java.util.*;
  50. import java.util.Map.Entry;
  51. import java.util.stream.Collectors;
  52. /**
  53. * <p>
  54. * pro场景表 服务实现类
  55. * </p>
  56. *
  57. * @author dengsixing
  58. * @since 2021-12-23
  59. */
  60. @Slf4j
  61. @Service
  62. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  63. @Value("${fyun.host}")
  64. private String ossUrlPrefix;
  65. @Value("${fyun.type}")
  66. private String fyunType;
  67. @Value("${main.url}")
  68. private String mainUrl;
  69. @Value("${scene.url}")
  70. private String sceneUrl;
  71. @Value("${scene.pro.url}")
  72. private String sceneProUrl;
  73. @Value("${scene.pro.new.url}")
  74. private String sceneProNewUrl;
  75. @Value("${ecs.checkFile.maxTimes:5}")
  76. private int maxCheckTimes;
  77. @Value("${ecs.checkFile.waitTime:5000}")
  78. private int waitTime;
  79. @Autowired
  80. private RedisLockUtil redisLockUtil;
  81. @Autowired
  82. private RedisUtil redisUtil;
  83. @Autowired
  84. private ISceneDataDownloadService sceneDataDownloadService;
  85. @Autowired
  86. private ISceneProService sceneProService;
  87. @Autowired
  88. private ISceneEditInfoService sceneEditInfoService;
  89. @Autowired
  90. private ISceneEditControlsService sceneEditControlsService;
  91. @Autowired
  92. private IScenePlusService scenePlusService;
  93. @Autowired
  94. private IScenePlusExtService scenePlusExtService;
  95. @Autowired
  96. private ISceneUploadService sceneUploadService;
  97. @Autowired
  98. private OssUtil ossUtil;
  99. @Autowired
  100. private ILaserService laserService;
  101. @Transactional
  102. @Override
  103. public ResultData saveInitialPage(FileNameAndDataParamVO param) throws Exception{
  104. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  105. if(scenePlus == null){
  106. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  107. }
  108. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  109. //更新缩略图url
  110. String thumbUrl = String.format(UploadFilePath.USER_EDIT_PATH, param.getNum()) + param.getFileName();
  111. scenePlusExt.setThumb(thumbUrl);
  112. scenePlusExtService.updateById(scenePlusExt);
  113. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  114. if(sceneEditInfo == null){
  115. sceneEditInfo = new SceneEditInfo();
  116. sceneEditInfo.setScenePlusId(scenePlus.getId());
  117. sceneEditInfo.setEntry(param.getData());
  118. sceneEditInfoService.save(sceneEditInfo);
  119. }else{
  120. sceneEditInfoService.update(
  121. new LambdaUpdateWrapper<SceneEditInfo>()
  122. .set(SceneEditInfo::getEntry, param.getData())
  123. .setSql("version = version + 1")
  124. .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  125. }
  126. //修改laser场景主表的缩略图地址
  127. laserService.editScene(param.getNum(), LaserSceneBean.builder().thumb(thumbUrl).build());
  128. return ResultData.ok();
  129. }
  130. @Override
  131. public ResultData addOrUpdateTag(SaveTagsParamVO param) throws Exception {
  132. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  133. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  134. if (scenePlus == null)
  135. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  136. this.addOrUpdateHotData(param.getNum(), param.getHotDataList());
  137. this.addOrUpdateIcons(param.getNum(), param.getIcons());
  138. //写入本地文件,作为备份
  139. this.writeHotJson(param.getNum());
  140. //保存数据库
  141. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  142. sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
  143. sceneEditInfoService.updateById(sceneEditInfo);
  144. return ResultData.ok();
  145. }
  146. private void addOrUpdateHotData(String num, List<HotParamVO> hotDataList) throws Exception{
  147. Map<String, String> addOrUpdateMap = new HashMap<>();
  148. int i = 0;
  149. for (HotParamVO hotParamVO : hotDataList) {
  150. JSONObject jsonObject = JSON.parseObject(hotParamVO.getHotData());
  151. jsonObject.put("createTime", Calendar.getInstance().getTimeInMillis() + i++);
  152. addOrUpdateMap.put(hotParamVO.getSid(), jsonObject.toJSONString());
  153. }
  154. this.syncHotFromFileToRedis(num);
  155. //处理新增和修改数据
  156. this.addOrUpdateHotDataHandler(num, addOrUpdateMap);
  157. }
  158. private void addOrUpdateIcons(String num, List<String> icons) throws Exception{
  159. if(CollUtil.isEmpty(icons)){
  160. return;
  161. }
  162. this.syncIconsFromFileToRedis(num);
  163. String key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  164. redisUtil.sSet(key, icons.toArray());
  165. }
  166. @Override
  167. public ResultData deleteTag(DeleteHotParamVO param) throws Exception {
  168. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  169. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  170. if (scenePlus == null)
  171. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  172. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  173. String bucket = scenePlusExt.getYunFileBucket();
  174. List<String> deleteSidList = param.getSidList();
  175. //处理删除状态数据
  176. this.deleteHotData(param.getNum(), deleteSidList, bucket);
  177. //删除导览中的热点数据
  178. this.deleteHotDataFromTourJson(param.getNum(), param.getSidList(), bucket);
  179. //写入本地文件,作为备份
  180. this.writeHotJson(param.getNum());
  181. //保存数据库
  182. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  183. sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
  184. sceneEditInfoService.updateById(sceneEditInfo);
  185. return ResultData.ok();
  186. }
  187. private void deleteHotDataFromTourJson(String num, List<String> sidList, String bucket){
  188. String key = String.format(UploadFilePath.USER_EDIT_PATH, num) + "tour.json";
  189. String tourJson = ossUtil.getFileContent(key);
  190. if(StrUtil.isEmpty(tourJson)){
  191. return;
  192. }
  193. JSONArray jsonArray = JSON.parseArray(tourJson);
  194. if(CollUtil.isEmpty(jsonArray)){
  195. return;
  196. }
  197. jsonArray.stream().forEach(tour->{
  198. JSONObject obj = (JSONObject) tour;
  199. JSONArray itemArra = obj.getJSONArray("list");
  200. itemArra.stream().forEach(item->{
  201. JSONObject itemObj = (JSONObject) item;
  202. String tagId = itemObj.getString("tagId");
  203. if(tagId != null && sidList.contains(tagId)){
  204. itemObj.remove("tagId");
  205. }
  206. });
  207. });
  208. ossUtil.uploadFileBytes(key, jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8));
  209. }
  210. @Override
  211. public ResultData deleteIcons(DeleteHotIconParamVO param) throws Exception {
  212. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  213. if (scenePlus == null)
  214. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  215. List<String> fileNameList = param.getFileNameList();
  216. this.syncIconsFromFileToRedis(param.getNum());
  217. String key = String.format(RedisKey.SCENE_HOT_ICONS, param.getNum());
  218. redisUtil.setRemove(key, fileNameList.toArray());
  219. //写入本地文件,作为备份
  220. this.writeHotJson(param.getNum());
  221. //删除oss文件
  222. sceneUploadService.delete(
  223. DeleteFileParamVO.builder()
  224. .num(param.getNum())
  225. .fileNames(fileNameList)
  226. .bizType(FileBizType.TAG_ICON.code()).build());
  227. return ResultData.ok();
  228. }
  229. @Override
  230. public ResultData listTags(String num) throws Exception{
  231. //保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  232. this.syncHotFromFileToRedis(num);
  233. //保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
  234. this.syncIconsFromFileToRedis(num);
  235. JSONObject result = new JSONObject();
  236. //查询缓存是否包含热点数据
  237. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  238. Map<String, String> allTagsMap = redisUtil.hmget(key);
  239. List<JSONObject> tags = Lists.newArrayList();
  240. List<TagBean> tagBeanList = new ArrayList<>();
  241. if(CollUtil.isNotEmpty(allTagsMap)){
  242. allTagsMap.entrySet().stream().forEach(entry -> {
  243. JSONObject jsonObject = JSON.parseObject(entry.getValue());
  244. tagBeanList.add(
  245. TagBean.builder()
  246. .createTime(jsonObject.getLong("createTime"))
  247. .tag(jsonObject).build());
  248. });
  249. //按创建时间倒叙排序
  250. tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
  251. //移除createTime字段
  252. tags = tagBeanList.stream().map(tagBean -> {
  253. JSONObject tag = tagBean.getTag();
  254. tag.remove("createTime");
  255. return tag;
  256. }).collect(Collectors.toList());
  257. }
  258. result.put("tags", tags);
  259. //查询缓存是否包含icons
  260. key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  261. Set<String> icons = redisUtil.sGet(key);
  262. if(icons == null){
  263. icons = Sets.newHashSet();
  264. }
  265. List<String> iconList = this.sortIcons(tags, icons);
  266. result.put("icons", iconList);
  267. return ResultData.ok(result);
  268. }
  269. private List<String> sortIcons(List<JSONObject> tags, Set<String> icons){
  270. //统计使用频次
  271. List<IconBean> iconBeans = Lists.newArrayList();
  272. for (String icon : icons) {
  273. int count = 0;
  274. for (JSONObject tag : tags) {
  275. String sid = tag.getString("icon");
  276. if(StrUtil.isEmpty(sid) || !icon.equals(sid)){
  277. continue;
  278. }
  279. ++count;
  280. }
  281. iconBeans.add(IconBean.builder().icon(icon).count(count).build());
  282. }
  283. //排序
  284. List<String> iconList = iconBeans.stream().sorted(Comparator.comparing(IconBean::getCount).reversed())
  285. .map(item -> {
  286. return item.getIcon();
  287. }).collect(Collectors.toList());
  288. return iconList;
  289. }
  290. /**
  291. * <p>
  292. 保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
  293. * </p>
  294. * @author dengsixing
  295. * @date 2022/3/3
  296. **/
  297. private void syncHotFromFileToRedis(String num) throws Exception{
  298. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  299. boolean exist = redisUtil.hasKey(key);
  300. if(exist){
  301. return;
  302. }
  303. String lockKey = String.format(RedisLockKey.LOCK_HOT_DATA_SYNC, num);
  304. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  305. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  306. if(!lock){
  307. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  308. }
  309. try{
  310. exist = redisUtil.hasKey(key);
  311. if(exist){
  312. return;
  313. }
  314. String tagsFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot.json";
  315. String tagsData = FileUtils.readUtf8String(tagsFilePath);
  316. if(StrUtil.isEmpty(tagsData)){
  317. return;
  318. }
  319. JSONObject jsonObject = JSON.parseObject(tagsData);
  320. JSONArray tagsArr = jsonObject.getJSONArray("tags");
  321. if(CollUtil.isEmpty(tagsArr)){
  322. return;
  323. }
  324. Map<String, String> map = new HashMap<>();
  325. for (Object o : tagsArr) {
  326. JSONObject jo = (JSONObject)o;
  327. map.put(jo.getString("sid"), jo.toJSONString());
  328. }
  329. redisUtil.hmset(key, map);
  330. }finally {
  331. redisLockUtil.unlockLua(lockKey, lockVal);
  332. }
  333. }
  334. /**
  335. * <p>
  336. 保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
  337. * </p>
  338. * @author dengsixing
  339. * @date 2022/3/3
  340. **/
  341. private void syncIconsFromFileToRedis(String num) throws Exception{
  342. String key = String.format(RedisKey.SCENE_HOT_ICONS, num);
  343. boolean exist = redisUtil.hasKey(key);
  344. if(exist){
  345. return;
  346. }
  347. String lockKey = String.format(RedisLockKey.LOCK_HOT_ICONS_SYNC, num);
  348. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  349. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  350. if(!lock){
  351. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  352. }
  353. try{
  354. exist = redisUtil.hasKey(key);
  355. if(exist){
  356. return;
  357. }
  358. String tagsFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot.json";
  359. String tagsData = FileUtils.readUtf8String(tagsFilePath);
  360. if(StrUtil.isEmpty(tagsData)){
  361. return;
  362. }
  363. JSONObject jsonObject = JSON.parseObject(tagsData);
  364. JSONArray iconArr = jsonObject.getJSONArray("icons");
  365. if(CollUtil.isEmpty(iconArr)){
  366. return;
  367. }
  368. redisUtil.sSet(key, iconArr.toJavaList(String.class).toArray());
  369. }finally {
  370. redisLockUtil.unlockLua(lockKey, lockVal);
  371. }
  372. }
  373. /**
  374. * <p>
  375. 热点数据保存
  376. * </p>
  377. * @author dengsixing
  378. * @date 2022/3/3
  379. **/
  380. private void writeHotJson(String num) throws Exception{
  381. String dataKey = String.format(RedisKey.SCENE_HOT_DATA, num);
  382. Map<String, String> tagMap = redisUtil.hmget(dataKey);
  383. List<String> tagList = Lists.newArrayList();
  384. tagMap.entrySet().stream().forEach(entry->{
  385. if(StrUtil.isNotEmpty(entry.getValue())){
  386. tagList.add(entry.getValue());
  387. }
  388. });
  389. JSONObject jsonObject = new JSONObject();
  390. JSONArray tagJsonArr = new JSONArray();
  391. if(CollUtil.isNotEmpty(tagList)){
  392. tagList.stream().forEach(hot->{
  393. tagJsonArr.add(JSONObject.parseObject(hot));
  394. });
  395. }
  396. jsonObject.put("tags", tagJsonArr);
  397. String iconsKey = String.format(RedisKey.SCENE_HOT_ICONS, num);
  398. Set<String> iconList = redisUtil.sGet(iconsKey);
  399. jsonObject.put("icons", iconList);
  400. String hotJsonPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "hot.json";
  401. String lockKey = String.format(RedisLockKey.LOCK_HOT_JSON, num);
  402. String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
  403. boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
  404. if(!lock){
  405. return;
  406. }
  407. try{
  408. FileUtils.writeFile(hotJsonPath, jsonObject.toJSONString());
  409. }finally {
  410. redisLockUtil.unlockLua(lockKey, lockVal);
  411. }
  412. }
  413. private void addOrUpdateHotDataHandler(String num, Map<String, String> addOrUpdateMap){
  414. if(CollUtil.isEmpty(addOrUpdateMap))
  415. return;
  416. //数据验证,新增、修改状态,hotdata不能为空
  417. for (String sid : addOrUpdateMap.keySet()) {
  418. String hotData = addOrUpdateMap.get(sid);
  419. if(StrUtil.isEmpty(hotData)){
  420. throw new BusinessException(ErrorCode.FAILURE_CODE_7004);
  421. }
  422. }
  423. //批量写入缓存
  424. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  425. redisUtil.hmset(key, addOrUpdateMap);
  426. }
  427. private void deleteHotData(String num, List<String> deleteSidList, String bucket) throws Exception {
  428. this.syncHotFromFileToRedis(num);
  429. if(CollUtil.isEmpty(deleteSidList)){
  430. return;
  431. }
  432. //从redis中加载热点数据
  433. String key = String.format(RedisKey.SCENE_HOT_DATA, num);
  434. List<String> deletDataList = redisUtil.hMultiGet(key, deleteSidList);
  435. if(CollUtil.isEmpty(deletDataList))
  436. return;
  437. String userDataPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
  438. //删除图片音频视频等资源文件
  439. for (String data : deletDataList) {
  440. if(StrUtil.isBlank(data)){
  441. continue;
  442. }
  443. JSONObject jsonObject = JSON.parseObject(data);
  444. String sid = jsonObject.getString("sid");
  445. if(jsonObject.containsKey("media")){
  446. String fileType = jsonObject.getString("media");
  447. if(fileType.contains("photo"))
  448. {
  449. ossUtil.deleteObject(userDataPath + "hot"+sid+".jpg");
  450. }
  451. if(fileType.contains("audio") || fileType.contains("voice"))
  452. {
  453. ossUtil.deleteObject(userDataPath + "hot"+sid+".mp3");
  454. }
  455. if(fileType.contains("video"))
  456. {
  457. ossUtil.deleteObject(userDataPath + "hot"+sid+".mp4");
  458. }
  459. }
  460. }
  461. //从redis中移除热点数据
  462. redisUtil.hdel(key, deleteSidList.toArray());
  463. }
  464. @Override
  465. public ResultData saveTagsVisible(SaveTagsVisibleParamVO param) throws Exception {
  466. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  467. if (scenePlus == null ) {
  468. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  469. }
  470. JSONArray visiblePanos = JSONArray.parseArray(param.getData());
  471. //如果redis找不到,就从本地文件中reload
  472. this.syncHotFromFileToRedis(param.getNum());
  473. //从缓存中获取热点数据,如果为空,抛出异常
  474. String key = String.format(RedisKey.SCENE_HOT_DATA, param.getNum());
  475. Map<String, String> map = redisUtil.hmget(key);
  476. if (CollUtil.isEmpty(map)) {
  477. throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
  478. }
  479. List<Entry<String, String>> allTags = map.entrySet().stream().filter(item -> {
  480. if (StrUtil.isBlank(item.getValue())) {
  481. return false;
  482. }
  483. return true;
  484. }).collect(Collectors.toList());
  485. if (CollUtil.isEmpty(allTags)) {
  486. throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
  487. }
  488. allTags.stream().forEach(entry->{
  489. JSONObject hot = JSON.parseObject(entry.getValue());
  490. visiblePanos.stream().forEach(item->{
  491. if (hot.getString("sid").equals(((JSONObject) item).getString("sid"))) {
  492. hot.put("visiblePanos", ((JSONObject) item).getJSONArray("value"));
  493. hot.put("isHidden", ((JSONObject) item).getBoolean("isHidden"));
  494. entry.setValue(hot.toJSONString());
  495. }
  496. });
  497. });
  498. //更新版本号
  499. SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  500. sceneEditInfoService.upgradeVersionById(editInfo.getId());
  501. //放入缓存
  502. Map<String, String> finalMap = new HashMap<>();
  503. allTags.stream().forEach(entry->{
  504. finalMap.put(entry.getKey(), entry.getValue());
  505. });
  506. redisUtil.hmset(key, finalMap);
  507. //写入本地文件,作为备份,以防redis数据丢失
  508. this.writeHotJson(param.getNum());
  509. return ResultData.ok();
  510. }
  511. @Override
  512. public ResultData saveRoam(BaseDataParamVO param) throws Exception {
  513. // ScenePro scenePro = this.findBySceneNum(param.getNum());
  514. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
  515. if (scenePlus == null ) {
  516. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  517. }
  518. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  519. String bucket = scenePlusExt.getYunFileBucket();
  520. JSONArray inputData = JSONObject.parseArray(param.getData());
  521. String localDataPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, param.getNum());
  522. File directory = new File(localDataPath);
  523. if (!directory.exists()) {
  524. directory.mkdirs();
  525. }
  526. //如果是云存储,将vision.modeldata下载到本地,如果是本地存储,场景计算完就已经将这个文件拷贝到编辑目录了存在这个文件了,不需要再下载
  527. String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, param.getNum());
  528. ossUtil.downloadFile(viewImagesPath + "vision.modeldata", localDataPath + "vision.modeldata");
  529. //检查vision.modeldata本地是否存在,不存在抛出异常
  530. File file = new File(localDataPath + "vision.modeldata");
  531. if(!file.exists()) {
  532. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  533. }
  534. //将vision.modeldata解压缩至vision.json
  535. ConvertUtils.convertVisionModelDataToTxt(localDataPath + "vision.modeldata", localDataPath + "vision.json");
  536. String str = FileUtils.readFile(localDataPath + "vision.json");
  537. JSONObject json = JSONObject.parseObject(str);
  538. JSONArray panos = json.getJSONArray("sweepLocations");
  539. for (int i = 0; i < panos.size(); ++i) {
  540. JSONObject pano = panos.getJSONObject(i);
  541. for (int j = 0; j < inputData.size(); ++j) {
  542. JSONObject jo = inputData.getJSONObject(j);
  543. String currentPanoId = jo.getString("panoID");
  544. JSONArray visibles = jo.getJSONArray("visibles");
  545. JSONArray visibles3 = jo.getJSONArray("visibles3");
  546. if (pano.getString("uuid").equals(currentPanoId)) {
  547. pano.put("visibles", visibles);
  548. pano.put("visibles3", visibles3);
  549. }
  550. }
  551. }
  552. FileUtils.deleteFile(localDataPath + "vision.json");
  553. FileUtils.deleteFile(localDataPath + "vision.modeldata");
  554. FileUtils.writeFile(localDataPath + "vision.json", json.toString());
  555. ConvertUtils.convertTxtToVisionModelData(localDataPath + "vision.json", localDataPath + "vision.modeldata");
  556. ossUtil.uploadFile(viewImagesPath + "vision.modeldata", localDataPath + "vision.modeldata", false);
  557. //更新版本号
  558. SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  559. if(Objects.isNull(editInfo)){
  560. editInfo = new SceneEditInfo();
  561. editInfo.setScenePlusId(scenePlus.getId());
  562. sceneEditInfoService.save(editInfo);
  563. }else{
  564. sceneEditInfoService.upgradeVersionAndImgVersionById(editInfo.getId());
  565. //更新scenejson缓存和oss文件版本号
  566. sceneEditInfoService.upgradeSceneJsonVersion(param.getNum(), editInfo.getVersion() + 1, editInfo.getImgVersion() + 1, bucket);
  567. }
  568. return ResultData.ok();
  569. }
  570. @Override
  571. public void updateUserIdByCameraId(Long userId, Long cameraId) {
  572. this.update(new LambdaUpdateWrapper<ScenePro>()
  573. .eq(ScenePro::getCameraId, cameraId)
  574. .set(ScenePro::getUserId, userId));
  575. }
  576. // @Override
  577. // public ResultData uploadObjAndImg(String num, MultipartFile file) throws Exception{
  578. // if(StrUtil.isEmpty(num)){
  579. // throw new BusinessException(ServerCode.PARAM_REQUIRED, "num");
  580. // }
  581. // if(!file.getOriginalFilename().endsWith(".zip")){
  582. // throw new BusinessException(ErrorCode.FAILURE_CODE_7015);
  583. // }
  584. //
  585. // ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  586. // if(scenePlus == null){
  587. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  588. // }
  589. // ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  590. // String bucket = scenePlusExt.getYunFileBucket();
  591. //
  592. // //文件上传的位置可以自定义
  593. // String path = scenePlusExt.getDataSource() + "_obj2txt";
  594. // String zipPath = path + "/zip/";
  595. // String filePath = path + "/extras/";
  596. // String resultPath = path + "/results/";
  597. //
  598. // //压缩文件处理:解压缩,解压缩后复制等操作
  599. // this.objAndImgFileHandler(resultPath, filePath, zipPath, file);
  600. //
  601. // //创建data.json
  602. // this.writeDataJson(path);
  603. //
  604. // //调用算法,不同的类型调用不同的算法
  605. // if("V2".equals(scenePlusExt.getBuildType())){
  606. // CreateObjUtil.objToTxt(path , "1");
  607. // }
  608. // if("V3".equals(scenePlusExt.getBuildType())){
  609. // CreateObjUtil.build3dModel(path , "1");
  610. // }
  611. //
  612. // //算法计算完后,生成压缩文件,上传到oss
  613. // this.uploadFileofterRebuildPanoram(path, num, bucket);
  614. //
  615. // //更新版本信息
  616. // SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  617. // if(Objects.isNull(sceneEditInfo)){
  618. // sceneEditInfo = new SceneEditInfo();
  619. // sceneEditInfo.setScenePlusId(scenePlus.getId());
  620. // sceneEditInfo.setFloorPublishVer(1);
  621. // sceneEditInfo.setFloorEditVer(1);
  622. // sceneEditInfo.setIsUploadObj(CommonStatus.YES.code());
  623. // sceneEditInfoService.save(sceneEditInfo);
  624. // }else{
  625. // sceneEditInfoService.update(
  626. // new LambdaUpdateWrapper<SceneEditInfo>()
  627. // .setSql("version = version + 1")
  628. // .setSql("floor_edit_ver = floor_edit_ver + 1")
  629. // .setSql("floor_publish_ver = floor_publish_ver + 1")
  630. // .setSql("img_version = img_version + 1")
  631. // .set(SceneEditInfo::getIsUploadObj, CommonStatus.YES.code())
  632. // .eq(SceneEditInfo::getId, sceneEditInfo.getId()));
  633. //
  634. // sceneEditInfoService.upgradeSceneJsonVersion(num, sceneEditInfo.getVersion() + 1, sceneEditInfo.getImgVersion() + 1, bucket); }
  635. //
  636. // return ResultData.ok();
  637. // }
  638. @Override
  639. public ScenePro getByNum(String num) {
  640. return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
  641. }
  642. // /**
  643. // * 老算法(dam)上传模型逻辑
  644. // * @param num
  645. // * @param bucket
  646. // * @param dataSource
  647. // * @param buildType
  648. // * @throws Exception
  649. // */
  650. // private void buildModel4Dam(String num, String bucket, String dataSource, String buildType, MultipartFile file) throws Exception {
  651. // //文件上传的位置可以自定义
  652. // String path = dataSource + "_obj2txt";
  653. // String zipPath = path + "/zip/";
  654. // String filePath = path + "/extras/";
  655. // String resultPath = path + "/results/";
  656. //
  657. // //压缩文件处理:解压缩,解压缩后复制等操作
  658. // this.objAndImgFileHandler(resultPath, filePath, zipPath, file);
  659. //
  660. // //创建data.json
  661. // this.writeDataJson(path);
  662. //
  663. // //调用算法,不同的类型调用不同的算法
  664. // if("V2".equals(buildType)){
  665. // CreateObjUtil.objToTxt(path , "1");
  666. // }
  667. // if("V3".equals(buildType)){
  668. // CreateObjUtil.build3dModel(path , "1");
  669. // }
  670. //
  671. // //算法计算完后,生成压缩文件,上传到oss
  672. // this.uploadFileofterRebuildPanoram(path, filePath, num, bucket);
  673. // }
  674. /**
  675. * 新算法(3dtiles)上传模型逻辑
  676. * @param num
  677. * @param bucket
  678. * @param dataSource
  679. * @throws Exception
  680. */
  681. private void buildModel43dtiles(String num, String bucket, String dataSource, MultipartFile file) throws Exception {
  682. //文件上传的位置可以自定义
  683. String path = dataSource + "_obj2Tiles" + File.separator;
  684. String meshPath = path + "mesh";
  685. String zipPath = path + "zip" + File.separator;
  686. String zipFilePath = zipPath + file.getOriginalFilename();
  687. //压缩文件处理:解压缩,解压缩后复制等操作
  688. FileUtil.del(path);
  689. FileUtil.mkdir(zipPath);
  690. File zipFile = new File(zipFilePath);
  691. file.transferTo(zipFile);
  692. ZipUtil.unzip(zipFilePath, meshPath);
  693. //检测文件
  694. String floorsJsonPath = meshPath + File.separator + "floors.json";
  695. if(!FileUtil.exist(floorsJsonPath)){
  696. throw new BusinessException(ErrorCode.FAILURE_CODE_5068);
  697. }
  698. String floorsJsonStr = FileUtil.readUtf8String(floorsJsonPath);
  699. JSONObject floorsJsonObj = JSON.parseObject(floorsJsonStr);
  700. JSONArray floorArr = floorsJsonObj.getJSONArray("floors");
  701. if(CollUtil.isEmpty(floorArr)){
  702. throw new BusinessException(ErrorCode.FAILURE_CODE_5069);
  703. }
  704. Set<String> floorNameSet = new HashSet<>();
  705. floorArr.stream().forEach(item->{
  706. JSONObject itemObj = (JSONObject) item;
  707. //楼层目录是否存在
  708. String name = itemObj.getString("name");
  709. if(StrUtil.isEmpty(name) || !FileUtil.exist(meshPath + File.separator + name)){
  710. throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
  711. }
  712. //检测obj文件是否存在
  713. String objPath = itemObj.getString("objPath");
  714. if(StrUtil.isEmpty(objPath) || !FileUtil.exist(path + objPath)){
  715. throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
  716. }
  717. if(floorNameSet.contains(name)){
  718. throw new BusinessException(ErrorCode.FAILURE_CODE_5069);
  719. }
  720. floorNameSet.add(name);
  721. });
  722. //读取oss上的floors.jsoon用于校验用户上传的模型楼层数是否一一对应
  723. String ossFloorsJson = ossUtil.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh/floors.json");
  724. JSONObject orginFloorsJsonObj = JSON.parseObject(ossFloorsJson);
  725. JSONArray orginFloorArr = orginFloorsJsonObj.getJSONArray("floors");
  726. Set<String> orginFloorNameSet = orginFloorArr.stream().map(item -> {
  727. JSONObject itemObj = (JSONObject) item;
  728. return itemObj.getString("name");
  729. }).collect(Collectors.toSet());
  730. if(floorNameSet.size() != orginFloorNameSet.size()){
  731. throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
  732. }
  733. orginFloorNameSet.stream().forEach(orginName->{
  734. if(!floorNameSet.contains(orginName)){
  735. throw new BusinessException(ErrorCode.FAILURE_CODE_5070);
  736. }
  737. });
  738. //调用算法
  739. String command = "bash /home/ubuntu/bin/Obj2Tiles.sh " + path;
  740. log.info("上传3dtiles模型开始, num:{}, targetPath:{}", num, path);
  741. // RuntimeUtil.exec(command);
  742. CreateObjUtil.callshell(command);
  743. log.info("上传3dtiles模型结束, num:{}, targetPath:{}", num, path);
  744. //检测计算结果
  745. String tilesPath = path + "3dtiles";
  746. String tilesetJsonPath = tilesPath + File.separator + "tileset.json";
  747. boolean success = ComputerUtil.checkComputeCompleted(tilesetJsonPath, maxCheckTimes, waitTime);
  748. if(!success){
  749. throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  750. }
  751. //删除logs
  752. FileUtil.del(tilesPath + File.separator + "logs");
  753. //算法计算完后,生成压缩文件,上传到oss
  754. //上传3dtiles
  755. ossUtil.deleteObject(String.format(UploadFilePath.IMG_VIEW_PATH, num) + "3dtiles");
  756. ossUtil.uploadFileDirCmd(tilesPath, String.format(UploadFilePath.IMG_VIEW_PATH, num) + "3dtiles", false);
  757. //上传mesh
  758. ossUtil.deleteObject(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh");
  759. ossUtil.uploadFileDirCmd(meshPath, String.format(UploadFilePath.DATA_VIEW_PATH, num) + "mesh", false);
  760. }
  761. // private void uploadFileofterRebuildPanoram(String path, String filePath, String sceneNum, String bucket) throws Exception {
  762. // //因为共享目录有延迟,这里循环检测算法是否计算完毕3次,每次隔五秒
  763. // String uploadJsonPath = path + File.separator + "results" +File.separator+"upload.json";
  764. // boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
  765. // if(!exist){
  766. // throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  767. // }
  768. // String uploadData = FileUtils.readFile(uploadJsonPath);
  769. // JSONObject uploadJson = null;
  770. // JSONArray array = null;
  771. // if(uploadData!=null) {
  772. // uploadJson = JSONObject.parseObject(uploadData);
  773. // array = uploadJson.getJSONArray("upload");
  774. // }
  775. //
  776. // Map<String,String> map = new HashMap<String,String>();
  777. // JSONObject fileJson = null;
  778. // String fileName = "";
  779. // String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, sceneNum);
  780. // for(int i = 0, len = array.size(); i < len; i++) {
  781. // fileJson = array.getJSONObject(i);
  782. // fileName = fileJson.getString("file");
  783. // //文件不存在抛出异常
  784. // if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
  785. // throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
  786. // }
  787. //
  788. // //tex文件夹
  789. // if (fileJson.getIntValue("clazz") == 15) {
  790. // map.put(path + File.separator + "results" + File.separator + fileName,
  791. // imgViewPath + ConstantFileName.modelUUID + "_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
  792. // continue;
  793. // }
  794. // }
  795. //
  796. // String damPath = path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam";
  797. // CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", damPath);
  798. // boolean existDam = ComputerUtil.checkComputeCompleted(damPath, 5, 2);
  799. // if(!existDam){
  800. // throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
  801. // }
  802. //// CreateObjUtil.convertDamToLzma(path + File.separator + "results");
  803. //// CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
  804. //// map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", imgViewPath +ConstantFileName.modelUUID+"_50k.dam.lzma");
  805. // map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", imgViewPath+ConstantFileName.modelUUID+"_50k.dam");
  806. //
  807. // String ossMeshPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneNum) + "mesh";
  808. // //删除oss中的mesh
  809. // ossUtil.deleteObject(ossMeshPath);
  810. // //上传obj相关文件
  811. // List<String> fileNames = FileUtil.listFileNames(filePath);
  812. // fileNames.stream().forEach(name->map.put(filePath + name, ossMeshPath + File.separator + name));
  813. //
  814. // ossUtil.uploadMulFiles(bucket, map);
  815. // }
  816. private void writeDataJson(String path) throws IOException {
  817. JSONObject dataJson = new JSONObject();
  818. dataJson.put("obj2txt", true);
  819. dataJson.put("split_type", "SPLIT_V6");
  820. dataJson.put("data_describe", "double spherical");
  821. dataJson.put("skybox_type", "SKYBOX_V5");
  822. FileUtils.writeFile(path + "/data.json", dataJson.toString());
  823. }
  824. private void objAndImgFileHandler(String resultPath, String filePath, String zipPath, MultipartFile file)
  825. throws Exception {
  826. FileUtils.delAllFile(resultPath);
  827. File targetFile = new File(filePath);
  828. if (!targetFile.exists()) {
  829. targetFile.mkdirs();
  830. }else {
  831. FileUtils.delAllFile(filePath);
  832. }
  833. targetFile = new File(zipPath);
  834. if (!targetFile.exists()) {
  835. targetFile.mkdirs();
  836. }else {
  837. FileUtils.delAllFile(zipPath);
  838. }
  839. targetFile = new File(zipPath + file.getOriginalFilename());
  840. if(!targetFile.getParentFile().exists()){
  841. targetFile.getParentFile().mkdirs();
  842. }
  843. // 保存压缩包到本地
  844. if(targetFile.exists())
  845. {
  846. FileUtils.deleteFile(zipPath + file.getOriginalFilename());
  847. }
  848. file.transferTo(targetFile);
  849. ZipUtil.unzip(zipPath + file.getOriginalFilename(), zipPath + "data/");
  850. //源文件数据,判断是否有多个文件夹,有多个就提示错误,有一个就将文件夹里数据迁移到extras目录,无直接迁移到extras目录
  851. boolean flag = false;
  852. //目录名称,如果不为空,则压缩文件第一层是目录
  853. String targetName = "";
  854. File dataFile = new File(zipPath + "data/");
  855. for(File data : dataFile.listFiles()){
  856. if(data.isDirectory() && flag){
  857. throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
  858. }
  859. if(data.isDirectory() && !flag){
  860. flag = true;
  861. targetName = data.getName();
  862. }
  863. }
  864. //是否包含obj文件
  865. boolean objFlag = false;
  866. //是否包含mtl文件
  867. boolean mtlFlag = false;
  868. File[] files = null;
  869. String dataPath = null;
  870. if(StrUtil.isEmpty(targetName)){
  871. files = dataFile.listFiles();
  872. dataPath = zipPath + "data/";
  873. }else{
  874. files = new File(zipPath + "data/" + targetName).listFiles();
  875. dataPath = zipPath + "data/" + targetName + File.separator;
  876. }
  877. for(File data : files){
  878. if(data.isDirectory()){
  879. throw new BusinessException(ErrorCode.FAILURE_CODE_5018);
  880. }
  881. if(data.getName().endsWith(".jpg") || data.getName().endsWith(".png")){
  882. if(!FileUtils.checkFileSizeIsLimit(data.length(), 1.5, "M")){
  883. throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
  884. }
  885. }
  886. if(data.getName().endsWith(".obj")){
  887. if(objFlag){
  888. throw new BusinessException(ErrorCode.FAILURE_CODE_5019);
  889. }
  890. if(!data.getName().equals("mesh.obj")){
  891. throw new BusinessException(ErrorCode.FAILURE_CODE_5060);
  892. }
  893. if(!FileUtils.checkFileSizeIsLimit(data.length(), 20, "M")){
  894. throw new BusinessException(ErrorCode.FAILURE_CODE_5020);
  895. }
  896. objFlag = true;
  897. FileUtils.copyFile(dataPath + data.getName(), filePath + "mesh.obj", true);
  898. continue;
  899. }
  900. if(data.getName().endsWith(".mtl")){
  901. mtlFlag = true;
  902. }
  903. FileUtils.copyFile(dataPath + data.getName(), filePath + data.getName(), true);
  904. }
  905. //压缩文件中必须有且仅有一个obj和mtl文件,否则抛出异常
  906. if(!mtlFlag || !objFlag){
  907. throw new BusinessException(ErrorCode.FAILURE_CODE_5059);
  908. }
  909. }
  910. // public ResultData downloadTexData(String num) throws Exception {
  911. //
  912. // if(StrUtil.isEmpty(num)){
  913. // throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  914. // }
  915. // ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  916. // if(scenePlus == null){
  917. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  918. // }
  919. // ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  920. // String bucket = scenePlusExt.getYunFileBucket();
  921. //
  922. // SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  923. //
  924. // String localImagePath = String.format(ConstantFilePath.IMAGESBUFFER_FORMAT, num);
  925. // if(!new File(localImagePath).exists()){
  926. // new File(localImagePath).mkdirs();
  927. // }
  928. //
  929. //
  930. // String newData = scenePlusExt.getDataSource() + "_obj2txt/extras";
  931. // String newResultData = scenePlusExt.getDataSource() + "_obj2txt/results/upload.json";
  932. // String zipName = num + "_extras.zip";
  933. // String zipPath = localImagePath + zipName;
  934. // //如果用户上传过模型,就打包上传到oss,直接返回
  935. // if(CommonStatus.YES.code().equals(sceneEditInfo.getIsUploadObj())
  936. // && new File(newData).exists()
  937. // && new File(newResultData).exists()){
  938. // //打包
  939. // ZipUtil.zip(newData, zipPath);
  940. // //上传压缩包
  941. // fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
  942. // String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  943. // return ResultData.ok(url);
  944. // }
  945. //
  946. //
  947. // String buildType = scenePlusExt.getBuildType();
  948. // if("V3".equals(buildType)){
  949. // String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  950. // //V3版本去oss下载2048模型
  951. // String meshPath = String.format(ConstantFilePath.DATABUFFER_FORMAT, num) + "mesh";
  952. // FileUtils.deleteDirectory(meshPath);
  953. // CreateObjUtil.ossUtilCp(dataViewPath + "mesh", meshPath);
  954. // log.info("meshPath="+meshPath);
  955. // if(!new File(meshPath).exists()){
  956. // throw new BusinessException(ErrorCode.FAILURE_CODE_7006);
  957. // }
  958. // log.info(new File(meshPath).listFiles().toString());
  959. // if(new File(meshPath).listFiles().length > 0){
  960. // for(File file : new File(meshPath).listFiles()){
  961. // if(file.isDirectory()){
  962. // for (File item : file.listFiles()) {
  963. // if(item.getName().endsWith(".obj") && !"output.house.obj".equals(item.getName()) &&
  964. // !"mesh.obj".equals(item.getName())){
  965. // item.delete();
  966. // }
  967. // if(item.getName().endsWith(".mtl") && !"output.house.mtl".equals(item.getName()) &&
  968. // !"mesh.mtl".equals(item.getName())){
  969. // item.delete();
  970. // }
  971. // }
  972. // continue;
  973. // }
  974. // if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  975. // !"mesh.obj".equals(file.getName())){
  976. // file.delete();
  977. // }
  978. // if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  979. // !"mesh.mtl".equals(file.getName())){
  980. // file.delete();
  981. // }
  982. // }
  983. // //打包
  984. // ZipUtil.zip(meshPath, zipPath);
  985. // //上传压缩包
  986. // fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
  987. // String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  988. //// FileUtil.del(zipPath);
  989. // return ResultData.ok(url);
  990. // }
  991. // }
  992. //
  993. // //V2版本在本地获取模型资源
  994. // //修改过的资源
  995. // String editData = scenePlusExt.getDataSource() + "_edit/caches/tex";
  996. // String results = scenePlusExt.getDataSource() + "_edit/results";
  997. // if (new File(editData).exists() && new File(results).exists()){
  998. // for(File file : new File(editData).listFiles()){
  999. // if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  1000. // !"mesh.obj".equals(file.getName())){
  1001. // file.delete();
  1002. // }
  1003. // if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  1004. // !"mesh.mtl".equals(file.getName())){
  1005. // file.delete();
  1006. // }
  1007. // }
  1008. //
  1009. // ZipUtil.zip(editData, zipPath);
  1010. // //上传压缩包
  1011. // fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
  1012. // String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  1013. // return ResultData.ok(url);
  1014. // }
  1015. //
  1016. // //没上传过返回源资源
  1017. // String dataPath = scenePlusExt.getDataSource() + "/caches/tex";
  1018. // File dataFile = new File(dataPath);
  1019. // if(!dataFile.exists()){
  1020. // throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  1021. // }
  1022. // for(File file : dataFile.listFiles()){
  1023. // if(file.getName().endsWith(".obj") && !"output.house.obj".equals(file.getName()) &&
  1024. // !"mesh.obj".equals(file.getName())){
  1025. // file.delete();
  1026. // }
  1027. // if(file.getName().endsWith(".mtl") && !"output.house.mtl".equals(file.getName()) &&
  1028. // !"mesh.mtl".equals(file.getName())){
  1029. // file.delete();
  1030. // }
  1031. // }
  1032. //
  1033. // ZipUtil.zip(dataPath, zipPath);
  1034. // //上传压缩包
  1035. // fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
  1036. // String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
  1037. // return ResultData.ok(url);
  1038. // }
  1039. }