|
@@ -1812,19 +1812,23 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResultData saveLinkPan(SaveLinkPanParamVO param) throws Exception {
|
|
public ResultData saveLinkPan(SaveLinkPanParamVO param) throws Exception {
|
|
- String sceneNum = param.getNum();
|
|
|
|
|
|
+ String num = param.getNum();
|
|
String fileName = param.getFileName();
|
|
String fileName = param.getFileName();
|
|
String fileData = param.getFileData();
|
|
String fileData = param.getFileData();
|
|
String sid = param.getSid();
|
|
String sid = param.getSid();
|
|
- if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName)){
|
|
|
|
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
|
|
|
|
- }
|
|
|
|
|
|
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
if(Objects.isNull(scenePlus)){
|
|
if(Objects.isNull(scenePlus)){
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this.addOrUpdateLinPan(num, param.getLinkPans());
|
|
|
|
+
|
|
|
|
+ this.addOrUpdateLinkPanStyles(num, param.getStyles());
|
|
|
|
+
|
|
|
|
+ this.writeLinkScene(num);
|
|
|
|
+
|
|
|
|
+
|
|
StringBuffer dataBuf = new StringBuffer()
|
|
StringBuffer dataBuf = new StringBuffer()
|
|
.append("data").append(File.separator)
|
|
.append("data").append(File.separator)
|
|
.append("data").append(scenePro.getNum())
|
|
.append("data").append(scenePro.getNum())
|
|
@@ -1864,6 +1868,109 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
return ResultData.ok();
|
|
return ResultData.ok();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ 热点数据保存
|
|
|
|
+
|
|
|
|
+ * </p>
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @date 2022/3/3
|
|
|
|
+ **/
|
|
|
|
+ private void writeLinkScene(String num) throws Exception{
|
|
|
|
+
|
|
|
|
+ String dataKey = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
|
|
|
|
+ Map<String, String> tagMap = redisUtil.hmget(dataKey);
|
|
|
|
+ List<String> tagList = Lists.newArrayList();
|
|
|
|
+ tagMap.entrySet().stream().forEach(entry->{
|
|
|
|
+ if(StrUtil.isNotEmpty(entry.getValue())){
|
|
|
|
+ tagList.add(entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ JSONArray tagJsonArr = new JSONArray();
|
|
|
|
+ if(CollUtil.isNotEmpty(tagList)){
|
|
|
|
+ tagList.stream().forEach(linkPan->{
|
|
|
|
+ tagJsonArr.add(JSONObject.parseObject(linkPan));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ jsonObject.put("tags", tagJsonArr);
|
|
|
|
+
|
|
|
|
+ String stylesKey = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
|
+ Set<String> stylesList = redisUtil.sGet(stylesKey);
|
|
|
|
+ jsonObject.put("styles", stylesList);
|
|
|
|
+
|
|
|
|
+ String linkScenePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "link-scene.json";
|
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_LINK_SCENE_JSON, num);
|
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
|
+ if(!lock){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try{
|
|
|
|
+ FileUtils.writeFile(linkScenePath, jsonObject.toJSONString());
|
|
|
|
+ }finally {
|
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void addOrUpdateLinkPanStyles(String num, List<String> styles) throws Exception{
|
|
|
|
+
|
|
|
|
+ this.syncLinkPanStylesFromFileToRedis(num);
|
|
|
|
+
|
|
|
|
+ String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
|
+ redisUtil.sSet(key, styles.toArray());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
|
|
+// hotDataList.stream().forEach(hotData -> {
|
|
|
|
+// addOrUpdateMap.put(hotData.getSid(), hotData.getHotData());
|
|
|
|
+// });
|
|
|
|
+
|
|
|
|
+ //处理新增和修改数据
|
|
|
|
+// this.addOrUpdateHotData(num, addOrUpdateMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ 保证icons数据安全性,当redis宕机导致icons数据丢失时,可以从文件中读取,恢复到redis
|
|
|
|
+ * </p>
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @date 2022/3/3
|
|
|
|
+ **/
|
|
|
|
+ private void syncLinkPanStylesFromFileToRedis(String num) throws Exception{
|
|
|
|
+
|
|
|
|
+ String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
|
+ boolean exist = redisUtil.hasKey(key);
|
|
|
|
+ if(exist){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_LINKPAN_STYLES_SYNC, num);
|
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
|
+ if(!lock){
|
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
|
+ }
|
|
|
|
+ try{
|
|
|
|
+ exist = redisUtil.hasKey(key);
|
|
|
|
+ if(exist){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String linkSceneFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
|
+ String linkSceneData = cn.hutool.core.io.FileUtil.readUtf8String(linkSceneFilePath + "link-scene.json");
|
|
|
|
+ if(StrUtil.isEmpty(linkSceneData)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(linkSceneData);
|
|
|
|
+ JSONArray stylesArr = jsonObject.getJSONArray("styles");
|
|
|
|
+ if(CollUtil.isEmpty(stylesArr)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ redisUtil.sSet(key, stylesArr.toJavaList(String.class).toArray());
|
|
|
|
+ }finally {
|
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private void addOrUpdateLinPan(String num, List<LinkPanParamVO> linkPanList) throws Exception{
|
|
private void addOrUpdateLinPan(String num, List<LinkPanParamVO> linkPanList) throws Exception{
|
|
Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
int i = 0;
|
|
int i = 0;
|
|
@@ -1873,10 +1980,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
addOrUpdateMap.put(linkPan.getSid(), jsonObject.toJSONString());
|
|
addOrUpdateMap.put(linkPan.getSid(), jsonObject.toJSONString());
|
|
}
|
|
}
|
|
|
|
|
|
- this.syncHotFromFileToRedis(num);
|
|
|
|
|
|
+ this.syncLinPanFromFileToRedis(num);
|
|
|
|
|
|
//处理新增和修改数据
|
|
//处理新增和修改数据
|
|
- this.addOrUpdateHotDataHandler(num, addOrUpdateMap);
|
|
|
|
|
|
+ this.addOrUpdateLinkPanHandler(num, addOrUpdateMap);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1893,7 +2000,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
if(exist){
|
|
if(exist){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- String lockKey = String.format(RedisLockKey.LOCK_HOT_DATA_SYNC, num);
|
|
|
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_LINKPAN_DATA_SYNC, num);
|
|
boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
if(!lock){
|
|
if(!lock){
|
|
throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
@@ -1903,12 +2010,12 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
if(exist){
|
|
if(exist){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- String tagsFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
|
- String tagsData = FileUtils.readFile(tagsFilePath + "hot.json");
|
|
|
|
- if(StrUtil.isEmpty(tagsData)){
|
|
|
|
|
|
+ String linkSceneFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
|
+ String linkSceneData = cn.hutool.core.io.FileUtil.readUtf8String(linkSceneFilePath + "link-scene.json");
|
|
|
|
+ if(StrUtil.isEmpty(linkSceneData)){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- JSONObject jsonObject = JSON.parseObject(tagsData);
|
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(linkSceneData);
|
|
JSONArray tagsArr = jsonObject.getJSONArray("tags");
|
|
JSONArray tagsArr = jsonObject.getJSONArray("tags");
|
|
if(CollUtil.isEmpty(tagsArr)){
|
|
if(CollUtil.isEmpty(tagsArr)){
|
|
return;
|
|
return;
|
|
@@ -1924,6 +2031,23 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void addOrUpdateLinkPanHandler(String num, Map<String, String> addOrUpdateMap){
|
|
|
|
+ if(CollUtil.isEmpty(addOrUpdateMap))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ //数据验证,新增、修改状态,linkPan不能为空
|
|
|
|
+ for (String sid : addOrUpdateMap.keySet()) {
|
|
|
|
+ String linkPan = addOrUpdateMap.get(sid);
|
|
|
|
+ if(StrUtil.isEmpty(linkPan)){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7022);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //批量写入缓存
|
|
|
|
+ String key = String.format(RedisKey.SCENE_LINKPAN_DATA, num);
|
|
|
|
+ redisUtil.hmset(key, addOrUpdateMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
|
|
private void updateBoxVideos(SceneEditInfo sceneEditInfo, Long scenePlusId, String boxVideos){
|
|
if(Objects.isNull(sceneEditInfo)){
|
|
if(Objects.isNull(sceneEditInfo)){
|
|
sceneEditInfo = new SceneEditInfo();
|
|
sceneEditInfo = new SceneEditInfo();
|