RepairUpXmlUrlServiceImpl.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package com.fdkankan.job.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.CharUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  9. import com.fdkankan.job.entity.ScenePlus;
  10. import com.fdkankan.job.entity.ScenePlusExt;
  11. import com.fdkankan.job.service.IRepairUpXmlUrlService;
  12. import com.fdkankan.job.service.IScenePlusExtService;
  13. import com.fdkankan.job.service.IScenePlusService;
  14. import com.fdkankan.job.service.ISceneProService;
  15. import com.fdkankan.model.constants.UploadFilePath;
  16. import com.fdkankan.redis.constant.RedisKey;
  17. import com.fdkankan.redis.util.RedisUtil;
  18. import java.nio.charset.StandardCharsets;
  19. import java.util.*;
  20. import java.util.stream.Collectors;
  21. import com.xxl.job.core.context.XxlJobHelper;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. /**
  25. * <p>
  26. * TODO
  27. * </p>
  28. *
  29. * @author dengsixing
  30. * @since 2022/12/16
  31. **/
  32. @Service
  33. public class RepairUpXmlUrlServiceImpl implements IRepairUpXmlUrlService {
  34. @Autowired
  35. private ISceneProService sceneProService;
  36. @Autowired
  37. private IScenePlusService scenePlusService;
  38. @Autowired
  39. private IScenePlusExtService scenePlusExtService;
  40. @Autowired
  41. private FYunFileServiceInterface fYunFileServiceInterface;
  42. @Autowired
  43. private RedisUtil redisUtil;
  44. @Override
  45. public void repairSceneUpXmlUrlOfVideos() {
  46. List<String> numList = null;
  47. String nums = XxlJobHelper.getJobParam();
  48. if(StrUtil.isNotEmpty(nums)){
  49. numList = Arrays.asList(nums.split(","));
  50. }
  51. //查询场景
  52. LambdaQueryWrapper<ScenePlusExt> scenePlusExtQueryWrapper = new LambdaQueryWrapper<>();
  53. scenePlusExtQueryWrapper.isNotNull(ScenePlusExt::getVideos);
  54. if(CollUtil.isNotEmpty(numList)){
  55. List<ScenePlus> plusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getNum, numList));
  56. if(CollUtil.isEmpty(plusList)){
  57. return;
  58. }
  59. List<Long> plusIdList = plusList.stream().map(plus -> plus.getId()).collect(Collectors.toList());
  60. scenePlusExtQueryWrapper.in(ScenePlusExt::getPlusId, plusIdList);
  61. }
  62. int index = 0;
  63. int size = 1;
  64. boolean exit = false;
  65. List<ScenePlusExt> plusExtList = new ArrayList<>();
  66. do {
  67. scenePlusExtQueryWrapper.last("limit " + index + " " + size);
  68. List<ScenePlusExt> subList = scenePlusExtService.list(scenePlusExtQueryWrapper);
  69. if(CollUtil.isNotEmpty(subList)){
  70. plusExtList.addAll(subList);
  71. }else{
  72. exit = true;
  73. }
  74. }while (exit);
  75. if(CollUtil.isEmpty(plusExtList)){
  76. return;
  77. }
  78. List<Long> plusIdList = plusExtList.stream().map(ext -> ext.getPlusId()).collect(Collectors.toList());
  79. List<ScenePlus> plusList = scenePlusService.listByIds(plusIdList);
  80. if(CollUtil.isEmpty(plusList)){
  81. return;
  82. }
  83. Map<Long, String> idNumMap = new HashMap<>();
  84. plusList.stream().forEach(plus->{
  85. idNumMap.put(plus.getId(), plus.getNum());
  86. });
  87. List<ScenePlusExt> updateList = plusExtList.stream().filter(ext -> {
  88. String videos = ext.getVideos();
  89. String num = idNumMap.get(ext.getPlusId());
  90. if(StrUtil.isEmpty(num)){
  91. return false;
  92. }
  93. String url = "https://4dkk.4dage.com/" + String.format(UploadFilePath.DATA_VIEW_PATH, num) + "Up.xml";
  94. JSONObject videosJson = JSON.parseObject(videos);
  95. String upPath = videosJson.getString("upPath");
  96. if (StrUtil.isEmpty(upPath)) {
  97. return false;
  98. } else
  99. //判断是否包含
  100. if (upPath.contains("/data/data") || (upPath.contains("scene_view_data") && !upPath
  101. .contains(num))) {
  102. //修复数据库
  103. videosJson.replace("upPath", url);
  104. ext.setVideos(videosJson.toJSONString());
  105. //修复scene.json
  106. String sceneJsonPath =
  107. String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  108. String sceneJsonStr = fYunFileServiceInterface.getFileContent(sceneJsonPath);
  109. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  110. sceneJson.replace("videos", ext.getVideos());
  111. fYunFileServiceInterface
  112. .uploadFile(sceneJson.toJSONString().getBytes(StandardCharsets.UTF_8),
  113. sceneJsonPath);
  114. //清除缓存
  115. redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
  116. return true;
  117. }
  118. return false;
  119. }).collect(Collectors.toList());
  120. if(CollUtil.isNotEmpty(updateList)){
  121. scenePlusExtService.updateBatchById(updateList);
  122. }
  123. }
  124. }