RepairUpXmlUrlServiceImpl.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.beans.factory.annotation.Value;
  24. import org.springframework.stereotype.Service;
  25. /**
  26. * <p>
  27. * TODO
  28. * </p>
  29. *
  30. * @author dengsixing
  31. * @since 2022/12/16
  32. **/
  33. @Service
  34. public class RepairUpXmlUrlServiceImpl implements IRepairUpXmlUrlService {
  35. @Value("${fyun.host}")
  36. private String fyunHost;
  37. @Autowired
  38. private ISceneProService sceneProService;
  39. @Autowired
  40. private IScenePlusService scenePlusService;
  41. @Autowired
  42. private IScenePlusExtService scenePlusExtService;
  43. @Autowired
  44. private FYunFileServiceInterface fYunFileServiceInterface;
  45. @Autowired
  46. private RedisUtil redisUtil;
  47. @Override
  48. public void repairSceneUpXmlUrlOfVideos() {
  49. List<String> numList = null;
  50. String nums = XxlJobHelper.getJobParam();
  51. if(StrUtil.isNotEmpty(nums)){
  52. numList = Arrays.asList(nums.split(","));
  53. }
  54. //查询场景
  55. LambdaQueryWrapper<ScenePlusExt> scenePlusExtQueryWrapper = new LambdaQueryWrapper<>();
  56. scenePlusExtQueryWrapper.isNotNull(ScenePlusExt::getVideos);
  57. if(CollUtil.isNotEmpty(numList)){
  58. List<ScenePlus> plusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getNum, numList));
  59. if(CollUtil.isEmpty(plusList)){
  60. return;
  61. }
  62. List<Long> plusIdList = plusList.stream().map(plus -> plus.getId()).collect(Collectors.toList());
  63. scenePlusExtQueryWrapper.in(ScenePlusExt::getPlusId, plusIdList);
  64. }
  65. int index = 0;
  66. int size = 200;
  67. boolean out = false;
  68. List<ScenePlusExt> plusExtList = new ArrayList<>();
  69. do {
  70. scenePlusExtQueryWrapper.last("limit " + index + "," + size);
  71. List<ScenePlusExt> subList = scenePlusExtService.list(scenePlusExtQueryWrapper);
  72. if(CollUtil.isNotEmpty(subList)){
  73. plusExtList.addAll(subList);
  74. index += size;
  75. }else{
  76. out = true;
  77. }
  78. }while (!out);
  79. if(CollUtil.isEmpty(plusExtList)){
  80. return;
  81. }
  82. List<Long> plusIdList = plusExtList.stream().map(ext -> ext.getPlusId()).collect(Collectors.toList());
  83. List<ScenePlus> plusList = scenePlusService.listByIds(plusIdList);
  84. if(CollUtil.isEmpty(plusList)){
  85. return;
  86. }
  87. Map<Long, String> idNumMap = new HashMap<>();
  88. plusList.stream().forEach(plus->{
  89. idNumMap.put(plus.getId(), plus.getNum());
  90. });
  91. List<ScenePlusExt> updateList = plusExtList.stream().filter(ext -> {
  92. String videos = ext.getVideos();
  93. String num = idNumMap.get(ext.getPlusId());
  94. if(StrUtil.isEmpty(num)){
  95. return false;
  96. }
  97. JSONObject videosJson = JSON.parseObject(videos);
  98. if(Objects.isNull(videosJson)){
  99. return false;
  100. }
  101. String upPath = videosJson.getString("upPath");
  102. if (StrUtil.isEmpty(upPath)) {
  103. return false;
  104. } else
  105. //判断是否包含
  106. if (upPath.contains("/data/data") || (upPath.contains("scene_view_data") && !upPath.contains(num))) {
  107. String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
  108. //修复数据库
  109. String fileName = "Up.txt";
  110. if(!fYunFileServiceInterface.fileExist(dataViewPath + fileName)){
  111. fileName = "Up.xml";
  112. }
  113. String upXMLUrl = fyunHost + dataViewPath + fileName;
  114. videosJson.replace("upPath", upXMLUrl);
  115. ext.setVideos(videosJson.toJSONString());
  116. //修复scene.json
  117. String sceneJsonPath =
  118. String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
  119. String sceneJsonStr = fYunFileServiceInterface.getFileContent(sceneJsonPath);
  120. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  121. sceneJson.replace("videos", ext.getVideos());
  122. fYunFileServiceInterface
  123. .uploadFile(sceneJson.toJSONString().getBytes(StandardCharsets.UTF_8),
  124. sceneJsonPath);
  125. //清除缓存
  126. redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
  127. return true;
  128. }
  129. return false;
  130. }).collect(Collectors.toList());
  131. if(CollUtil.isNotEmpty(updateList)){
  132. scenePlusExtService.updateBatchById(updateList);
  133. }
  134. }
  135. }