|
@@ -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.model.constants.ConstantFilePath;
|
|
@@ -32,12 +33,15 @@ 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;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -63,6 +67,8 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
private RedisLockUtil redisLockUtil;
|
|
|
@Autowired
|
|
|
private OssUtil ossUtil;
|
|
|
+ @Autowired
|
|
|
+ private ISceneUploadService sceneUploadService;
|
|
|
|
|
|
@Override
|
|
|
public SceneEditInfoExt getByScenePlusId(long scenePlusId) {
|
|
@@ -93,8 +99,7 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
|
|
|
this.addOrUpdateBillboards(param.getNum(), param.getData());
|
|
|
|
|
|
- //写入本地文件,作为备份
|
|
|
- this.writeBillboardJson(param.getNum());
|
|
|
+ this.addOrUpdateBillboardsStyles(param.getNum(), param.getStyles());
|
|
|
|
|
|
//保存数据库
|
|
|
SceneEditInfoExt sceneEditInfoExt = this.getByScenePlusId(scenePlus.getId());
|
|
@@ -106,6 +111,70 @@ 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_BILLBOARDS_STYLES, num);
|
|
|
+ redisUtil.hmset(key, styleMap);
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeBillboardStylesJson(num);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncBillboardsStylesFromFileToRedis(String num) throws Exception{
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_BILLBOARDS_STYLES, num);
|
|
|
+ boolean exist = redisUtil.hasKey(key);
|
|
|
+ if(exist){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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){
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ exist = redisUtil.hasKey(key);
|
|
|
+ if(exist){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String stylesPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
+ String stylesData = FileUtils.readUtf8String(stylesPath + "billboards-styles.json");
|
|
|
+ if(StrUtil.isEmpty(stylesData)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray stylesArr = JSON.parseArray(stylesData);
|
|
|
+ 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());
|
|
@@ -131,27 +200,52 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> listBillboards(BaseSceneParamVO param) throws Exception {
|
|
|
+ public JSONObject listBillboards(BaseSceneParamVO param) throws Exception {
|
|
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ List<JSONObject> tags = new ArrayList<>();
|
|
|
+ List<JSONObject> styles = new ArrayList<>();
|
|
|
ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
SceneEditInfoExt sceneEditInfoExt = this.getByScenePlusId(scenePlus.getId());
|
|
|
- if(sceneEditInfoExt.getBillboards() == CommonStatus.NO.code().intValue()){
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
this.syncBillboardsFromFileToRedis(param.getNum());
|
|
|
+
|
|
|
+ //获取指示牌数据
|
|
|
String key = String.format(RedisKey.SCENE_BILLBOARDS, param.getNum());
|
|
|
List<String> list = redisUtil.hgetValues(key);
|
|
|
- List<TagBean> 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());
|
|
|
- return sortList.stream().map(item -> item.getTag()).collect(Collectors.toList());
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ List<TagBean> 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());
|
|
|
+ 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<String> sytlelist = redisUtil.hgetValues(key);
|
|
|
+ if(CollUtil.isNotEmpty(sytlelist)){
|
|
|
+ List<TagBean> stileSortList = sytlelist.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());
|
|
|
+ stileSortList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+ styles = stileSortList.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 {
|
|
@@ -166,27 +260,12 @@ 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;
|
|
|
- }
|
|
|
- ossUtil.deleteObject(bucket, userDataPath.concat(icon));
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- 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));
|
|
|
}
|
|
@@ -227,12 +306,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(billboardsData);
|
|
|
+ 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());
|
|
|
}
|
|
@@ -249,6 +328,9 @@ public class SceneEditInfoExtServiceImpl extends ServiceImpl<ISceneEditInfoExtMa
|
|
|
//批量写入缓存
|
|
|
String key = String.format(RedisKey.SCENE_BILLBOARDS, num);
|
|
|
redisUtil.hmset(key, addOrUpdateMap);
|
|
|
+
|
|
|
+ //写入本地文件,作为备份
|
|
|
+ this.writeBillboardJson(num);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -258,8 +340,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);
|
|
@@ -281,6 +364,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);
|
|
@@ -299,6 +404,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();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|