123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package com.fdkankan.job.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.CharUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.job.entity.ScenePlus;
- import com.fdkankan.job.entity.ScenePlusExt;
- import com.fdkankan.job.service.IRepairUpXmlUrlService;
- import com.fdkankan.job.service.IScenePlusExtService;
- import com.fdkankan.job.service.IScenePlusService;
- import com.fdkankan.job.service.ISceneProService;
- import com.fdkankan.model.constants.UploadFilePath;
- import com.fdkankan.redis.constant.RedisKey;
- import com.fdkankan.redis.util.RedisUtil;
- import java.nio.charset.StandardCharsets;
- import java.util.*;
- import java.util.stream.Collectors;
- import com.xxl.job.core.context.XxlJobHelper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/12/16
- **/
- @Service
- public class RepairUpXmlUrlServiceImpl implements IRepairUpXmlUrlService {
- @Autowired
- private ISceneProService sceneProService;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Autowired
- private FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- private RedisUtil redisUtil;
- @Override
- public void repairSceneUpXmlUrlOfVideos() {
- List<String> numList = null;
- String nums = XxlJobHelper.getJobParam();
- if(StrUtil.isNotEmpty(nums)){
- numList = Arrays.asList(nums.split(","));
- }
- //查询场景
- LambdaQueryWrapper<ScenePlusExt> scenePlusExtQueryWrapper = new LambdaQueryWrapper<>();
- scenePlusExtQueryWrapper.isNotNull(ScenePlusExt::getVideos);
- if(CollUtil.isNotEmpty(numList)){
- List<ScenePlus> plusList = scenePlusService.list(new LambdaQueryWrapper<ScenePlus>().in(ScenePlus::getNum, numList));
- if(CollUtil.isEmpty(plusList)){
- return;
- }
- List<Long> plusIdList = plusList.stream().map(plus -> plus.getId()).collect(Collectors.toList());
- scenePlusExtQueryWrapper.in(ScenePlusExt::getPlusId, plusIdList);
- }
- int index = 0;
- int size = 1;
- boolean exit = false;
- List<ScenePlusExt> plusExtList = new ArrayList<>();
- do {
- scenePlusExtQueryWrapper.last("limit " + index + " " + size);
- List<ScenePlusExt> subList = scenePlusExtService.list(scenePlusExtQueryWrapper);
- if(CollUtil.isNotEmpty(subList)){
- plusExtList.addAll(subList);
- }else{
- exit = true;
- }
- }while (exit);
- if(CollUtil.isEmpty(plusExtList)){
- return;
- }
- List<Long> plusIdList = plusExtList.stream().map(ext -> ext.getPlusId()).collect(Collectors.toList());
- List<ScenePlus> plusList = scenePlusService.listByIds(plusIdList);
- if(CollUtil.isEmpty(plusList)){
- return;
- }
- Map<Long, String> idNumMap = new HashMap<>();
- plusList.stream().forEach(plus->{
- idNumMap.put(plus.getId(), plus.getNum());
- });
- List<ScenePlusExt> updateList = plusExtList.stream().filter(ext -> {
- String videos = ext.getVideos();
- String num = idNumMap.get(ext.getPlusId());
- if(StrUtil.isEmpty(num)){
- return false;
- }
- String url = "https://4dkk.4dage.com/" + String.format(UploadFilePath.DATA_VIEW_PATH, num) + "Up.xml";
- JSONObject videosJson = JSON.parseObject(videos);
- String upPath = videosJson.getString("upPath");
- if (StrUtil.isEmpty(upPath)) {
- return false;
- } else
- //判断是否包含
- if (upPath.contains("/data/data") || (upPath.contains("scene_view_data") && !upPath
- .contains(num))) {
- //修复数据库
- videosJson.replace("upPath", url);
- ext.setVideos(videosJson.toJSONString());
- //修复scene.json
- String sceneJsonPath =
- String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
- String sceneJsonStr = fYunFileServiceInterface.getFileContent(sceneJsonPath);
- JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
- sceneJson.replace("videos", ext.getVideos());
- fYunFileServiceInterface
- .uploadFile(sceneJson.toJSONString().getBytes(StandardCharsets.UTF_8),
- sceneJsonPath);
- //清除缓存
- redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
- return true;
- }
- return false;
- }).collect(Collectors.toList());
- if(CollUtil.isNotEmpty(updateList)){
- scenePlusExtService.updateBatchById(updateList);
- }
- }
- }
|