|
@@ -6,30 +6,35 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisClient;
|
|
|
+import com.fdkankan.scene.bean.IconBean;
|
|
|
import com.fdkankan.scene.bean.ResultData;
|
|
|
+import com.fdkankan.scene.bean.TagBean;
|
|
|
import com.fdkankan.scene.entity.Scene;
|
|
|
import com.fdkankan.scene.entity.SceneEditInfo;
|
|
|
import com.fdkankan.scene.service.FYunFileService;
|
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
|
import com.fdkankan.scene.service.SceneEditInfoService;
|
|
|
import com.fdkankan.scene.service.SceneService;
|
|
|
-import com.fdkankan.scene.vo.DeleteHotParamVO;
|
|
|
-import com.fdkankan.scene.vo.FileNameAndDataParamVO;
|
|
|
-import com.fdkankan.scene.vo.HotParamVO;
|
|
|
-import com.fdkankan.scene.vo.SaveTagsParamVO;
|
|
|
+import com.fdkankan.scene.vo.*;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -128,6 +133,8 @@ public class SceneProServiceImpl implements ISceneProService {
|
|
|
sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
|
|
|
sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
|
|
|
+ this.publicHotData(param.getNum());
|
|
|
+
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
@@ -178,11 +185,13 @@ public class SceneProServiceImpl implements ISceneProService {
|
|
|
sceneEditInfoService.saveTagsToSceneEditInfo(param.getNum(), sceneEditInfo);
|
|
|
sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
|
|
|
+ this.publicHotData(param.getNum());
|
|
|
+
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
private void deleteHotDataFromTourJson(String num, List<String> sidList) throws IOException {
|
|
|
- String key = String.format(UploadFilePath.USER_EDIT_PATH, num) + "tour.json";
|
|
|
+ String key = String.format(UploadFilePath.USER_VIEW_PATH, num) + "tour.json";
|
|
|
String tourJson = fYunFileService.getFileContent(key);
|
|
|
if(StrUtil.isEmpty(tourJson)){
|
|
|
return;
|
|
@@ -202,108 +211,126 @@ public class SceneProServiceImpl implements ISceneProService {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
- fYunFileService.uploadFile(bucket, jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8), key);
|
|
|
+ fYunFileService.uploadFile(num, jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8), key);
|
|
|
}
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public ResultData deleteIcons(DeleteHotIconParamVO param) throws Exception {
|
|
|
-//
|
|
|
-// ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
-// if (scenePlus == null)
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
-//
|
|
|
-// List<String> fileNameList = param.getFileNameList();
|
|
|
-//
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData deleteIcons(DeleteHotIconParamVO param) throws Exception {
|
|
|
+
|
|
|
+ Scene scenePlus = scenePlusService.getByNum(param.getNum());
|
|
|
+ if (scenePlus == null)
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+
|
|
|
+ List<String> fileNameList = param.getFileNameList();
|
|
|
+
|
|
|
// this.syncIconsFromFileToRedis(param.getNum());
|
|
|
-//
|
|
|
-// String key = String.format(RedisKey.SCENE_HOT_ICONS, param.getNum());
|
|
|
-// redisUtil.setRemove(key, fileNameList.toArray());
|
|
|
-//
|
|
|
-// //写入本地文件,作为备份
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_ICONS, param.getNum());
|
|
|
+ redisClient.setRemove(key, new HashSet<>(fileNameList));
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
// this.writeHotJson(param.getNum());
|
|
|
-//
|
|
|
-// //删除oss文件
|
|
|
-// sceneUploadService.delete(
|
|
|
-// DeleteFileParamVO.builder()
|
|
|
-// .num(param.getNum())
|
|
|
-// .fileNames(fileNameList)
|
|
|
-// .bizType(FileBizType.TAG_ICON.code()).build());
|
|
|
-//
|
|
|
-// return ResultData.ok();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public ResultData listTags(String num) throws Exception{
|
|
|
-//
|
|
|
-// //保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData listTags(String num) throws Exception{
|
|
|
+
|
|
|
+ //保证热点数据安全性,当redis宕机导致热点数据丢失时,可以从文件中读取,恢复到redis
|
|
|
// this.syncHotFromFileToRedis(num);
|
|
|
-//
|
|
|
-// //保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
|
|
|
+
|
|
|
+ //保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
|
|
|
// this.syncIconsFromFileToRedis(num);
|
|
|
-//
|
|
|
-// JSONObject result = new JSONObject();
|
|
|
-//
|
|
|
-// //查询缓存是否包含热点数据
|
|
|
-// String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
-// Map<String, String> allTagsMap = redisUtil.hmget(key);
|
|
|
-// List<JSONObject> tags = Lists.newArrayList();
|
|
|
-// List<TagBean> tagBeanList = new ArrayList<>();
|
|
|
-// if(CollUtil.isNotEmpty(allTagsMap)){
|
|
|
-// allTagsMap.entrySet().stream().forEach(entry -> {
|
|
|
-// JSONObject jsonObject = JSON.parseObject(entry.getValue());
|
|
|
-// tagBeanList.add(
|
|
|
-// TagBean.builder()
|
|
|
-// .createTime(jsonObject.getLong("createTime"))
|
|
|
-// .tag(jsonObject).build());
|
|
|
-// });
|
|
|
-// //按创建时间倒叙排序
|
|
|
-// tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
-//
|
|
|
-// //移除createTime字段
|
|
|
-// tags = tagBeanList.stream().map(tagBean -> {
|
|
|
-// JSONObject tag = tagBean.getTag();
|
|
|
-// tag.remove("createTime");
|
|
|
-// return tag;
|
|
|
-// }).collect(Collectors.toList());
|
|
|
-// }
|
|
|
-// result.put("tags", tags);
|
|
|
-//
|
|
|
-// //查询缓存是否包含icons
|
|
|
-// key = String.format(RedisKey.SCENE_HOT_ICONS, num);
|
|
|
-// Set<String> icons = redisUtil.sGet(key);
|
|
|
-// if(icons == null){
|
|
|
-// icons = Sets.newHashSet();
|
|
|
-// }
|
|
|
-// List<String> iconList = this.sortIcons(tags, icons);
|
|
|
-// result.put("icons", iconList);
|
|
|
-//
|
|
|
-// return ResultData.ok(result);
|
|
|
-// }
|
|
|
-//
|
|
|
-// private List<String> sortIcons(List<JSONObject> tags, Set<String> icons){
|
|
|
-//
|
|
|
-// //统计使用频次
|
|
|
-// List<IconBean> iconBeans = Lists.newArrayList();
|
|
|
-// for (String icon : icons) {
|
|
|
-// int count = 0;
|
|
|
-// for (JSONObject tag : tags) {
|
|
|
-// String sid = tag.getString("icon");
|
|
|
-// if(StrUtil.isEmpty(sid) || !icon.equals(sid)){
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// ++count;
|
|
|
-// }
|
|
|
-// iconBeans.add(IconBean.builder().icon(icon).count(count).build());
|
|
|
-// }
|
|
|
-//
|
|
|
-// //排序
|
|
|
-// List<String> iconList = iconBeans.stream().sorted(Comparator.comparing(IconBean::getCount).reversed())
|
|
|
-// .map(item -> {
|
|
|
-// return item.getIcon();
|
|
|
-// }).collect(Collectors.toList());
|
|
|
-//
|
|
|
-// return iconList;
|
|
|
-// }
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+
|
|
|
+ //查询缓存是否包含热点数据
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
+ Map<String, String> allTagsMap = redisClient.hmget(key);
|
|
|
+ List<JSONObject> tags = Lists.newArrayList();
|
|
|
+ List<TagBean> tagBeanList = new ArrayList<>();
|
|
|
+ if(CollUtil.isNotEmpty(allTagsMap)){
|
|
|
+ allTagsMap.entrySet().stream().forEach(entry -> {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(entry.getValue());
|
|
|
+ tagBeanList.add(
|
|
|
+ TagBean.builder()
|
|
|
+ .createTime(jsonObject.getLong("createTime"))
|
|
|
+ .tag(jsonObject).build());
|
|
|
+ });
|
|
|
+ //按创建时间倒叙排序
|
|
|
+ tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+
|
|
|
+ //移除createTime字段
|
|
|
+ tags = tagBeanList.stream().map(tagBean -> {
|
|
|
+ JSONObject tag = tagBean.getTag();
|
|
|
+ tag.remove("createTime");
|
|
|
+ return tag;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ result.put("tags", tags);
|
|
|
+
|
|
|
+ //查询缓存是否包含icons
|
|
|
+ key = String.format(RedisKey.SCENE_HOT_ICONS, num);
|
|
|
+ Set<String> icons = redisClient.sGet(key);
|
|
|
+ if(icons == null){
|
|
|
+ icons = Sets.newHashSet();
|
|
|
+ }
|
|
|
+ List<String> iconList = this.sortIcons(tags, icons);
|
|
|
+ result.put("icons", iconList);
|
|
|
+
|
|
|
+ return ResultData.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> sortIcons(List<JSONObject> tags, Set<String> icons){
|
|
|
+
|
|
|
+ //统计使用频次
|
|
|
+ List<IconBean> iconBeans = Lists.newArrayList();
|
|
|
+ for (String icon : icons) {
|
|
|
+ int count = 0;
|
|
|
+ for (JSONObject tag : tags) {
|
|
|
+ String sid = tag.getString("icon");
|
|
|
+ if(StrUtil.isEmpty(sid) || !icon.equals(sid)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ++count;
|
|
|
+ }
|
|
|
+ iconBeans.add(IconBean.builder().icon(icon).count(count).build());
|
|
|
+ }
|
|
|
+
|
|
|
+ //排序
|
|
|
+ List<String> iconList = iconBeans.stream().sorted(Comparator.comparing(IconBean::getCount).reversed())
|
|
|
+ .map(item -> {
|
|
|
+ return item.getIcon();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return iconList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void publicHotData(String sceneNum) {
|
|
|
+ String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, sceneNum);
|
|
|
+ Map<String, String> hotMap = redisClient.hmget(hotDataKey);
|
|
|
+
|
|
|
+ JSONArray tags = new JSONArray();
|
|
|
+ if(CollUtil.isNotEmpty(hotMap)){
|
|
|
+ List<TagBean> tagBeanList = hotMap.entrySet().stream().map(entry -> {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(entry.getValue());
|
|
|
+ return TagBean.builder()
|
|
|
+ .createTime(jsonObject.getLong("createTime"))
|
|
|
+ .tag(jsonObject).build();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //按创建时间倒叙排序
|
|
|
+ tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+
|
|
|
+ //移除createTime字段
|
|
|
+ tagBeanList.stream().forEach(tagBean -> {
|
|
|
+ tags.add(tagBean.getTag());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ String hotJsonPath = String.format(UploadFilePath.USER_VIEW_PATH, sceneNum) + "hot.json";
|
|
|
+ fYunFileService.uploadFile(sceneNum, tags.toString().getBytes(StandardCharsets.UTF_8), hotJsonPath);
|
|
|
+ }
|
|
|
//
|
|
|
// /**
|
|
|
// * <p>
|
|
@@ -472,73 +499,70 @@ public class SceneProServiceImpl implements ISceneProService {
|
|
|
redisClient.hdel(key, deleteSidList);
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public ResultData saveTagsVisible(SaveTagsVisibleParamVO param) throws Exception {
|
|
|
-//
|
|
|
-// ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
-// if (scenePlus == null ) {
|
|
|
-// return ResultData.error(ErrorCode.FAILURE_CODE_5005);
|
|
|
-// }
|
|
|
-// JSONArray visiblePanos = JSONArray.parseArray(param.getData());
|
|
|
-//
|
|
|
-// //如果redis找不到,就从本地文件中reload
|
|
|
+ @Override
|
|
|
+ public ResultData saveTagsVisible(SaveTagsVisibleParamVO param) throws Exception {
|
|
|
+
|
|
|
+ Scene scenePlus = scenePlusService.getByNum(param.getNum());
|
|
|
+ if (scenePlus == null ) {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ JSONArray visiblePanos = JSONArray.parseArray(param.getData());
|
|
|
+
|
|
|
+ //如果redis找不到,就从本地文件中reload
|
|
|
// this.syncHotFromFileToRedis(param.getNum());
|
|
|
-//
|
|
|
-// //从缓存中获取热点数据,如果为空,抛出异常
|
|
|
-// String key = String.format(RedisKey.SCENE_HOT_DATA, param.getNum());
|
|
|
-// Map<String, String> map = redisUtil.hmget(key);
|
|
|
-// if (CollUtil.isEmpty(map)) {
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
|
|
|
-// }
|
|
|
-// List<Entry<String, String>> allTags = map.entrySet().stream().filter(item -> {
|
|
|
-// if (StrUtil.isBlank(item.getValue())) {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// return true;
|
|
|
-// }).collect(Collectors.toList());
|
|
|
-//
|
|
|
-// if (CollUtil.isEmpty(allTags)) {
|
|
|
-// throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
|
|
|
-// }
|
|
|
-//
|
|
|
-// allTags.stream().forEach(entry->{
|
|
|
-// JSONObject hot = JSON.parseObject(entry.getValue());
|
|
|
-// visiblePanos.stream().forEach(item->{
|
|
|
-// if (hot.getString("sid").equals(((JSONObject) item).getString("sid"))) {
|
|
|
-// hot.put("visiblePanos", ((JSONObject) item).getJSONArray("value"));
|
|
|
-// hot.put("isHidden", ((JSONObject) item).getBoolean("isHidden"));
|
|
|
-// entry.setValue(hot.toJSONString());
|
|
|
-// }
|
|
|
-// });
|
|
|
-// });
|
|
|
-//
|
|
|
-// //更新版本号
|
|
|
-// SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
-// sceneEditInfoService.upgradeVersionById(editInfo.getId());
|
|
|
-//
|
|
|
-// //放入缓存
|
|
|
-// Map<String, String> finalMap = new HashMap<>();
|
|
|
-// allTags.stream().forEach(entry->{
|
|
|
-// finalMap.put(entry.getKey(), entry.getValue());
|
|
|
-// });
|
|
|
-// redisUtil.hmset(key, finalMap);
|
|
|
-//
|
|
|
-// //写入本地文件,作为备份,以防redis数据丢失
|
|
|
+
|
|
|
+ //从缓存中获取热点数据,如果为空,抛出异常
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, param.getNum());
|
|
|
+ Map<String, String> map = redisClient.hmget(key);
|
|
|
+ if (CollUtil.isEmpty(map)) {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
|
|
|
+ }
|
|
|
+ List<Map.Entry<String, String>> allTags = map.entrySet().stream().filter(item -> {
|
|
|
+ if (StrUtil.isBlank(item.getValue())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(allTags)) {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7005);
|
|
|
+ }
|
|
|
+
|
|
|
+ allTags.stream().forEach(entry->{
|
|
|
+ JSONObject hot = JSON.parseObject(entry.getValue());
|
|
|
+ visiblePanos.stream().forEach(item->{
|
|
|
+ if (hot.getString("sid").equals(((JSONObject) item).getString("sid"))) {
|
|
|
+ hot.put("visiblePanos", ((JSONObject) item).getJSONArray("value"));
|
|
|
+ hot.put("isHidden", ((JSONObject) item).getBoolean("isHidden"));
|
|
|
+ entry.setValue(hot.toJSONString());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ //更新版本号
|
|
|
+ SceneEditInfo editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoService.upgradeVersionById(editInfo.getId());
|
|
|
+
|
|
|
+ //放入缓存
|
|
|
+ Map<String, String> finalMap = new HashMap<>();
|
|
|
+ allTags.stream().forEach(entry->{
|
|
|
+ finalMap.put(entry.getKey(), entry.getValue());
|
|
|
+ });
|
|
|
+ redisClient.hmset(key, finalMap);
|
|
|
+
|
|
|
+ //写入本地文件,作为备份,以防redis数据丢失
|
|
|
// this.writeHotJson(param.getNum());
|
|
|
-//
|
|
|
-// return ResultData.ok();
|
|
|
-// }
|
|
|
-//
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
// @Override
|
|
|
// public ResultData saveRoam(BaseDataParamVO param) throws Exception {
|
|
|
//
|
|
|
-//// ScenePro scenePro = this.findBySceneNum(param.getNum());
|
|
|
-// ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+// Scene scenePlus = scenePlusService.getByNum(param.getNum());
|
|
|
// if (scenePlus == null ) {
|
|
|
-// return ResultData.error(ErrorCode.FAILURE_CODE_5005);
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
// }
|
|
|
-// ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
-// String bucket = scenePlusExt.getYunFileBucket();
|
|
|
//
|
|
|
// JSONArray inputData = JSONObject.parseArray(param.getData());
|
|
|
//
|