|
@@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -93,6 +94,8 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
|
|
|
this.addOrUpdateBillboards(param.getNum(), param.getData());
|
|
|
|
|
|
+ this.addOrUpdateBillboardsStyles(param.getNum(), param.getStyles());
|
|
|
+
|
|
|
//写入本地文件,作为备份
|
|
|
this.writeBillboardJson(param.getNum());
|
|
|
|
|
@@ -106,6 +109,68 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ private void addOrUpdateBillboardsStyles(String num, List<JSONObject> styles) throws Exception{
|
|
|
+
|
|
|
+ this.syncBillboardsStylesFromFileToRedis(num);
|
|
|
+
|
|
|
+ if(CollUtil.isEmpty(styles)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ long time = Calendar.getInstance().getTimeInMillis();
|
|
|
+ Map<String, String> styleMap = new HashMap<>();
|
|
|
+ AtomicInteger index = new AtomicInteger();
|
|
|
+ styles.stream().forEach(style->{
|
|
|
+ String id = style.getString("sid");
|
|
|
+ style.put("createTime", time + index.getAndIncrement());
|
|
|
+ styleMap.put(id, style.toJSONString());
|
|
|
+ });
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
+ redisUtil.hmset(key, styleMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncBillboardsStylesFromFileToRedis(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);
|
|
|
+ String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, lockVal, 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 = FileUtils.readUtf8String(linkSceneFilePath + "links.json");
|
|
|
+ if(StrUtil.isEmpty(linkSceneData)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(linkSceneData);
|
|
|
+ JSONArray stylesArr = jsonObject.getJSONArray("styles");
|
|
|
+ if(CollUtil.isEmpty(stylesArr)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> styleMap = new HashMap<>();
|
|
|
+ for (Object style : stylesArr) {
|
|
|
+ JSONObject styleObj = (JSONObject)style;
|
|
|
+ String id = styleObj.getString("sid");
|
|
|
+ styleMap.put(id, styleObj.toJSONString());
|
|
|
+ }
|
|
|
+ redisUtil.hmset(key, styleMap);
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey, lockVal);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ResultData deleteBillboards(DeleteSidListParamVO param) throws Exception {
|
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
@@ -182,11 +247,10 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void addOrUpdateBillboards(String num, JSONArray data) throws Exception{
|
|
|
+ private void addOrUpdateBillboards(String num, List<JSONObject> data) throws Exception{
|
|
|
Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
|
int i = 0;
|
|
|
- for (Object item : data) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(item));
|
|
|
+ for (JSONObject jsonObject : data) {
|
|
|
jsonObject.put("createTime", Calendar.getInstance().getTimeInMillis() + i++);
|
|
|
addOrUpdateMap.put(jsonObject.getString("sid"), JSON.toJSONString(jsonObject));
|
|
|
}
|