|
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.CommonStatus;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.FileBizType;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
@@ -25,13 +26,8 @@ import com.fdkankan.scene.entity.SceneEditInfoExt;
|
|
|
import com.fdkankan.scene.entity.ScenePlus;
|
|
|
import com.fdkankan.scene.entity.ScenePlusExt;
|
|
|
import com.fdkankan.scene.mapper.ISceneEditInfoExtMapper;
|
|
|
-import com.fdkankan.scene.service.ISceneEditInfoExtService;
|
|
|
-import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
|
-import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
-import com.fdkankan.scene.service.IScenePlusService;
|
|
|
-import com.fdkankan.scene.vo.BaseJsonArrayParamVO;
|
|
|
-import com.fdkankan.scene.vo.BaseSceneParamVO;
|
|
|
-import com.fdkankan.scene.vo.DeleteSidListParamVO;
|
|
|
+import com.fdkankan.scene.service.*;
|
|
|
+import com.fdkankan.scene.vo.*;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
|
import org.aspectj.apache.bcel.generic.RET;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -64,6 +60,8 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
private RedisLockUtil redisLockUtil;
|
|
|
@Autowired
|
|
|
private FYunFileServiceInterface fYunFileService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneUploadService sceneUploadService;
|
|
|
|
|
|
@Override
|
|
|
public SceneEditInfoExt getByScenePlusId(long scenePlusId) {
|
|
@@ -96,9 +94,6 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
|
|
|
this.addOrUpdateBillboardsStyles(param.getNum(), param.getStyles());
|
|
|
|
|
|
- //写入本地文件,作为备份
|
|
|
- this.writeBillboardJson(param.getNum());
|
|
|
-
|
|
|
//保存数据库
|
|
|
SceneEditInfoExt sceneEditInfoExt = this.getByScenePlusId(scenePlus.getId());
|
|
|
this.updateBillboards(param.getNum(), sceneEditInfoExt);
|
|
@@ -126,18 +121,21 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
styleMap.put(id, style.toJSONString());
|
|
|
});
|
|
|
|
|
|
- String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
+ String key = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, num);
|
|
|
redisUtil.hmset(key, styleMap);
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeBillboardStylesJson(num);
|
|
|
}
|
|
|
|
|
|
private void syncBillboardsStylesFromFileToRedis(String num) throws Exception{
|
|
|
|
|
|
- String key = String.format(RedisKey.SCENE_LINKPAN_STYLES, num);
|
|
|
+ String key = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, num);
|
|
|
boolean exist = redisUtil.hasKey(key);
|
|
|
if(exist){
|
|
|
return;
|
|
|
}
|
|
|
- String lockKey = String.format(RedisLockKey.LOCK_LINKPAN_STYLES_SYNC, num);
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_BILLBOARDS_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){
|
|
@@ -148,13 +146,12 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
if(exist){
|
|
|
return;
|
|
|
}
|
|
|
- String linkSceneFilePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
- String linkSceneData = FileUtils.readUtf8String(linkSceneFilePath + "links.json");
|
|
|
- if(StrUtil.isEmpty(linkSceneData)){
|
|
|
+ String stylesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
+ String stylesData = FileUtils.readUtf8String(stylesPath + "billboards-styles.json");
|
|
|
+ if(StrUtil.isEmpty(stylesData)){
|
|
|
return;
|
|
|
}
|
|
|
- JSONObject jsonObject = JSON.parseObject(linkSceneData);
|
|
|
- JSONArray stylesArr = jsonObject.getJSONArray("styles");
|
|
|
+ JSONArray stylesArr = JSON.parseArray(stylesData);
|
|
|
if(CollUtil.isEmpty(stylesArr)){
|
|
|
return;
|
|
|
}
|
|
@@ -196,7 +193,7 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> listBillboards(BaseSceneParamVO param) throws Exception {
|
|
|
+ public JSONObject listBillboards(BaseSceneParamVO param) throws Exception {
|
|
|
|
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
SceneEditInfoExt sceneEditInfoExt = this.getByScenePlusId(scenePlus.getId());
|
|
@@ -205,6 +202,10 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
}
|
|
|
|
|
|
this.syncBillboardsFromFileToRedis(param.getNum());
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+
|
|
|
+ //获取指示牌数据
|
|
|
String key = String.format(RedisKey.SCENE_BILLBOARDS, param.getNum());
|
|
|
List<String> list = redisUtil.hgetValues(key);
|
|
|
List<TagBean> sortList = list.stream().map(str -> {
|
|
@@ -216,7 +217,26 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
return tagBean;
|
|
|
}).collect(Collectors.toList());
|
|
|
sortList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
- return sortList.stream().map(item -> item.getTag()).collect(Collectors.toList());
|
|
|
+ List<JSONObject> tags = sortList.stream().map(item -> item.getTag()).collect(Collectors.toList());
|
|
|
+ result.put("tags", tags);
|
|
|
+
|
|
|
+ //获取图标数据
|
|
|
+ this.syncBillboardsStylesFromFileToRedis(param.getNum());
|
|
|
+ key = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, param.getNum());
|
|
|
+ list = redisUtil.hgetValues(key);
|
|
|
+ sortList = list.stream().map(str -> {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(str);
|
|
|
+ TagBean tagBean = new TagBean();
|
|
|
+ tagBean.setCreateTime(jsonObject.getLong("createTime"));
|
|
|
+ jsonObject.remove("createTime");
|
|
|
+ tagBean.setTag(jsonObject);
|
|
|
+ return tagBean;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sortList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+ List<JSONObject> styles = sortList.stream().map(item -> item.getTag()).collect(Collectors.toList());
|
|
|
+ result.put("styles", styles);
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private void deleteBillboards(String num, List<String> deleteSidList, String bucket) throws Exception {
|
|
@@ -231,20 +251,6 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
return;
|
|
|
//从redis中移除热点数据
|
|
|
redisUtil.hdel(key, deleteSidList.toArray());
|
|
|
-
|
|
|
- String userDataPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
- //删除图片音频视频等资源文件
|
|
|
- for (String data : deletDataList) {
|
|
|
- if(StrUtil.isBlank(data)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONObject jsonObject = JSON.parseObject(data);
|
|
|
- String icon = jsonObject.getString("icon");
|
|
|
- if(StrUtil.isEmpty(icon)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- fYunFileService.deleteFile(bucket, userDataPath.concat(icon));
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private void addOrUpdateBillboards(String num, List<JSONObject> data) throws Exception{
|
|
@@ -291,12 +297,12 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
if(StrUtil.isEmpty(billboardsData)){
|
|
|
return;
|
|
|
}
|
|
|
- JSONArray billboardArr = JSON.parseArray(billboardsData);
|
|
|
- if(CollUtil.isEmpty(billboardArr)){
|
|
|
+ JSONArray tagsArr = JSON.parseArray(billboardsFilePath);
|
|
|
+ if(CollUtil.isEmpty(tagsArr)){
|
|
|
return;
|
|
|
}
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
- for (Object o : billboardArr) {
|
|
|
+ for (Object o : tagsArr) {
|
|
|
JSONObject jo = (JSONObject)o;
|
|
|
map.put(jo.getString("sid"), jo.toJSONString());
|
|
|
}
|
|
@@ -313,6 +319,9 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
//批量写入缓存
|
|
|
String key = String.format(RedisKey.SCENE_BILLBOARDS, num);
|
|
|
redisUtil.hmset(key, addOrUpdateMap);
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeBillboardJson(num);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -322,8 +331,9 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
* </p>
|
|
|
* @author dengsixing
|
|
|
* @date 2022/3/3
|
|
|
+ *
|
|
|
**/
|
|
|
- private void writeBillboardJson(String num) throws Exception{
|
|
|
+ private void writeBillboardJson(String num){
|
|
|
String lockKey = String.format(RedisLockKey.LOCK_BILLBOARDS_SYNC, num);
|
|
|
String lockVal = cn.hutool.core.lang.UUID.randomUUID().toString();
|
|
|
boolean lock = redisLockUtil.lock(lockKey, lockVal, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
@@ -345,6 +355,28 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void writeBillboardStylesJson(String num){
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_BILLBOARDS_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){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ String dataKey = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, num);
|
|
|
+ String stylesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "billboards-styles.json";
|
|
|
+ if(!redisUtil.hasKey(dataKey)){
|
|
|
+ FileUtil.del(stylesPath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, String> billboardStylesMap = redisUtil.hmget(dataKey);
|
|
|
+ List<JSONObject> billboardStyleList = billboardStylesMap.entrySet().stream().map(entry->JSON.parseObject(entry.getValue())).collect(Collectors.toList());
|
|
|
+ FileUtil.writeUtf8String(JSON.toJSONString(billboardStyleList), stylesPath);
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey, lockVal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void updateBillboards(String num, SceneEditInfoExt sceneEditInfoExt){
|
|
|
//查询缓存是否包含热点数据
|
|
|
String key = String.format(RedisKey.SCENE_BILLBOARDS, num);
|
|
@@ -363,6 +395,36 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
this.updateById(sceneEditInfoExt);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResultData deleteBillboardsStyles(DeleteStylesParamVO param) throws Exception {
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+ if (scenePlus == null)
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+
|
|
|
+ List<String> sidList = param.getSidList();
|
|
|
+
|
|
|
+ this.syncBillboardsStylesFromFileToRedis(param.getNum());
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, param.getNum());
|
|
|
+ List<String> deleteList = redisUtil.hMultiGet(key, sidList);
|
|
|
+ redisUtil.hdel(key, sidList.toArray());
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeBillboardStylesJson(param.getNum());
|
|
|
+
|
|
|
+ //删除oss文件
|
|
|
+ List<String> deleteFileList = deleteList.stream().map(str -> {
|
|
|
+ JSONObject parse = JSON.parseObject(str);
|
|
|
+ return parse.getString("url");
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sceneUploadService.delete(
|
|
|
+ DeleteFileParamVO.builder()
|
|
|
+ .num(param.getNum())
|
|
|
+ .fileNames(deleteFileList)
|
|
|
+ .bizType(FileBizType.BILLBOARD_ICON.code()).build());
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|