|
@@ -476,15 +476,29 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return;
|
|
|
|
|
|
//数据验证,新增、修改状态,hotdata不能为空
|
|
|
+ Set<String> linkSids = new HashSet<>();
|
|
|
for (String sid : addOrUpdateMap.keySet()) {
|
|
|
String hotData = addOrUpdateMap.get(sid);
|
|
|
if(StrUtil.isEmpty(hotData)){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_7004);
|
|
|
}
|
|
|
+ JSONObject jsonObject = JSON.parseObject(hotData);
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
+ if("link".equals(type)){
|
|
|
+ linkSids.add(sid);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //批量写入缓存
|
|
|
+ //如果是修改,且由多媒体改成link的方式,将原有的多媒体文件删除
|
|
|
String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
+ List<String> updateList = redisUtil.hMultiGet(key, new ArrayList<>(linkSids));
|
|
|
+ try {
|
|
|
+ this.deleteHotMediaFile(num, updateList, false);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("删除多媒体文件失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量写入缓存
|
|
|
redisUtil.hmset(key, addOrUpdateMap);
|
|
|
}
|
|
|
|
|
@@ -502,34 +516,83 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
List<String> deletDataList = redisUtil.hMultiGet(key, deleteSidList);
|
|
|
if(CollUtil.isEmpty(deletDataList))
|
|
|
return;
|
|
|
- String userDataPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+
|
|
|
+ //从redis中移除热点数据
|
|
|
+ redisUtil.hdel(key, deleteSidList.toArray());
|
|
|
|
|
|
//删除图片音频视频等资源文件
|
|
|
- for (String data : deletDataList) {
|
|
|
+ this.deleteHotMediaFile(num, deletDataList, true);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteHotMediaFile(String num, List<String> hotdataList, boolean deleteBgm) throws Exception {
|
|
|
+ if(CollUtil.isEmpty(hotdataList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //删除图片音频视频等资源文件
|
|
|
+ List<String> deleteFileList = new ArrayList<>();
|
|
|
+ for (String data : hotdataList) {
|
|
|
if(StrUtil.isBlank(data)){
|
|
|
continue;
|
|
|
}
|
|
|
JSONObject jsonObject = JSON.parseObject(data);
|
|
|
- String sid = jsonObject.getString("sid");
|
|
|
- if(jsonObject.containsKey("media")){
|
|
|
- String fileType = jsonObject.getString("media");
|
|
|
- if(fileType.contains("photo"))
|
|
|
- {
|
|
|
- fYunFileService.deleteFile(bucket,userDataPath + "hot"+sid+".jpg");
|
|
|
- }
|
|
|
- if(fileType.contains("audio") || fileType.contains("voice"))
|
|
|
- {
|
|
|
- fYunFileService.deleteFile(bucket,userDataPath + "hot"+sid+".mp3");
|
|
|
+
|
|
|
+ //删除背景音乐
|
|
|
+ if(deleteBgm){
|
|
|
+ JSONObject bgm = jsonObject.getJSONObject("bgm");
|
|
|
+ if(Objects.nonNull(bgm) && StrUtil.isNotEmpty(bgm.getString("src"))){
|
|
|
+ String bgmSrc = bgm.getString("src");
|
|
|
+ deleteFileList.add(bgmSrc);
|
|
|
}
|
|
|
- if(fileType.contains("video"))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
+
|
|
|
+ if("media".equals(type)){//V4.13.0版本改成这种方式
|
|
|
+ //删除图片、视频
|
|
|
+ JSONArray media = jsonObject.getJSONArray("media");
|
|
|
+ media.stream().forEach(v->{
|
|
|
+ JSONObject o = (JSONObject) v;
|
|
|
+ String src = o.getString("src");
|
|
|
+ if(StrUtil.isNotEmpty(src)){
|
|
|
+ deleteFileList.add(src);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /* v4.12版本之前是这种方式
|
|
|
+ "media": {
|
|
|
+ "image": [
|
|
|
{
|
|
|
- fYunFileService.deleteFile(bucket,userDataPath + "hot"+sid+".mp4");
|
|
|
+ "src": "FfRdi413774.jpg"
|
|
|
}
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "type": "image"
|
|
|
+ */
|
|
|
+ if("image".equals(type) || "audio".equals(type) || "video".equals(type)){
|
|
|
+ //删除图片、视频
|
|
|
+ JSONObject media = jsonObject.getJSONObject("media");
|
|
|
+ JSONArray jsonArray = media.getJSONArray(type);
|
|
|
+ jsonArray.stream().forEach(v->{
|
|
|
+ JSONObject o = (JSONObject) v;
|
|
|
+ String src = o.getString("src");
|
|
|
+ if(StrUtil.isNotEmpty(src)){
|
|
|
+ deleteFileList.add(src);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //从redis中移除热点数据
|
|
|
- redisUtil.hdel(key, deleteSidList.toArray());
|
|
|
+ if(CollUtil.isEmpty(deleteFileList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sceneUploadService.delete(
|
|
|
+ DeleteFileParamVO.builder()
|
|
|
+ .num(num)
|
|
|
+ .fileNames(deleteFileList)
|
|
|
+ .bizType("tag-media").build());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1145,7 +1208,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
//删除本地文件
|
|
|
FileUtil.del(meshLocalPath);
|
|
|
FileUtil.del(zipFilePath);
|
|
|
- String url = "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
+ String url = "downloads/extras/" + zipName;
|
|
|
return url;
|
|
|
}
|
|
|
|
|
@@ -1201,7 +1264,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
ZipUtil.zip(meshPath, zipPath);
|
|
|
//上传压缩包
|
|
|
fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
|
|
|
- String url = "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
+ String url = "downloads/extras/" + zipName;
|
|
|
FileUtil.del(zipPath);
|
|
|
return url;
|
|
|
}
|