|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -21,15 +22,18 @@ import com.fdkankan.common.constant.*;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.util.*;
|
|
import com.fdkankan.common.util.*;
|
|
|
|
+import com.fdkankan.fyun.constant.StorageType;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.platform.api.feign.PlatformGoodsClient;
|
|
import com.fdkankan.platform.api.feign.PlatformGoodsClient;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisLockKey;
|
|
import com.fdkankan.redis.constant.RedisLockKey;
|
|
import com.fdkankan.redis.util.RedisLockUtil;
|
|
import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.scene.entity.*;
|
|
import com.fdkankan.scene.entity.*;
|
|
import com.fdkankan.scene.mapper.ISceneProMapper;
|
|
import com.fdkankan.scene.mapper.ISceneProMapper;
|
|
import com.fdkankan.scene.service.*;
|
|
import com.fdkankan.scene.service.*;
|
|
import com.fdkankan.scene.vo.*;
|
|
import com.fdkankan.scene.vo.*;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -101,6 +105,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
@Autowired
|
|
@Autowired
|
|
RedisLockUtil redisLockUtil;
|
|
RedisLockUtil redisLockUtil;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
ISceneDataDownloadService sceneDataDownloadService;
|
|
ISceneDataDownloadService sceneDataDownloadService;
|
|
@Autowired
|
|
@Autowired
|
|
PlatformGoodsClient platformGoodsClient;
|
|
PlatformGoodsClient platformGoodsClient;
|
|
@@ -2173,170 +2179,111 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
return ResultData.ok(fileName);
|
|
return ResultData.ok(fileName);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
// @SystemServiceLog(description = "保存场景热点")
|
|
// @SystemServiceLog(description = "保存场景热点")
|
|
- public ResultData saveHot(SceneEditParamVO base) throws Exception {
|
|
|
|
- if(StrUtil.isEmpty(base.getType())){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
|
- }
|
|
|
|
|
|
+ public ResultData saveHot(SaveHotParamVO param) throws Exception {
|
|
|
|
|
|
- String sid = base.getSid();
|
|
|
|
-
|
|
|
|
- ScenePro scenePro = findBySceneNum(base.getNum());
|
|
|
|
- if (scenePro == null ) {
|
|
|
|
|
|
+ ScenePro scenePro = this.findBySceneNum(param.getNum());
|
|
|
|
+ if (scenePro == null)
|
|
return ResultData.error(ErrorCode.FAILURE_CODE_5005);
|
|
return ResultData.error(ErrorCode.FAILURE_CODE_5005);
|
|
- }
|
|
|
|
|
|
|
|
- JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
|
|
|
|
|
|
+ List<HotParamVO> hotDataList = param.getHotDataList();
|
|
|
|
+ Map<String, String> addOrUpdateMap = new HashMap<>();
|
|
|
|
+ List<String> deleteSidList = Lists.newArrayList();
|
|
|
|
+ hotDataList.stream().forEach(hotData -> {
|
|
|
|
+ if(hotData.getType().equals(OperationType.DELETE.code()))
|
|
|
|
+ deleteSidList.add(hotData.getSid());
|
|
|
|
+ else
|
|
|
|
+ addOrUpdateMap.put(hotData.getSid(), hotData.getHotData());
|
|
|
|
|
|
- StringBuffer dataBuf = new StringBuffer()
|
|
|
|
- .append("data").append(File.separator)
|
|
|
|
- .append("data").append(scenePro.getNum())
|
|
|
|
- .append(File.separator);
|
|
|
|
- StringBuffer imagesBuf = new StringBuffer()
|
|
|
|
- .append("images").append(File.separator)
|
|
|
|
- .append("images").append(scenePro.getNum())
|
|
|
|
- .append(File.separator);
|
|
|
|
|
|
+ });
|
|
|
|
|
|
- StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
|
|
|
|
- StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
|
|
|
|
|
|
+ //处理删除状态数据
|
|
|
|
+ this.deleteHotData(param.getNum(), deleteSidList);
|
|
|
|
|
|
- String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
|
|
|
|
- JSONArray jsonhots = null;
|
|
|
|
- if (StrUtil.isNotEmpty(str)) {
|
|
|
|
- jsonhots = JSONArray.parseArray(str);
|
|
|
|
- }else {
|
|
|
|
- File file = new File(dataBuffer.toString() + "hot.json");
|
|
|
|
- if(!file.getParentFile().exists()){
|
|
|
|
- file.getParentFile().mkdirs();
|
|
|
|
- }
|
|
|
|
- if(!file.exists()){
|
|
|
|
- file.createNewFile();
|
|
|
|
- }
|
|
|
|
- jsonhots = new JSONArray();
|
|
|
|
- }
|
|
|
|
|
|
+ //处理新增和修改数据
|
|
|
|
+ this.addOrUpdateHotData(param.getNum(), addOrUpdateMap);
|
|
|
|
|
|
- //添加或者修改
|
|
|
|
- if("1".equals(base.getType())){
|
|
|
|
- sid = jsonhot.getString("sid");
|
|
|
|
- if(StrUtil.isEmpty(sid)){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
|
- }
|
|
|
|
- jsonhots.add(jsonhot);
|
|
|
|
- }
|
|
|
|
- else if("0".equals(base.getType())){
|
|
|
|
- sid = jsonhot.getString("sid");
|
|
|
|
- if(StrUtil.isEmpty(sid)){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else if("-1".equals(base.getType())){
|
|
|
|
- if(StrUtil.isEmpty(sid)){
|
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //判断是否需要删除自定义热点样式
|
|
|
|
- String[] styles = null;
|
|
|
|
- if(StrUtil.isNotEmpty(base.getStyleName())){
|
|
|
|
- styles = base.getStyleName().split(",");
|
|
|
|
- }
|
|
|
|
|
|
|
|
- for(int i=0;i<jsonhots.size();++i){
|
|
|
|
- JSONObject ele = jsonhots.getJSONObject(i);
|
|
|
|
- //名字对应上就删除
|
|
|
|
- if(styles != null){
|
|
|
|
- for(String style : styles){
|
|
|
|
- if(style.equals(ele.getString("styleId"))){
|
|
|
|
- jsonhots.getJSONObject(i).put("styleId", null);
|
|
|
|
- jsonhots.getJSONObject(i).put("style", "default");
|
|
|
|
- jsonhots.getJSONObject(i).put("styleImageURL", null);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(ele.getString("sid").equals(sid)){
|
|
|
|
- if("-1".equals(base.getType())){
|
|
|
|
- jsonhots.remove(i);
|
|
|
|
- if(ele.containsKey("media")){
|
|
|
|
- String fileType = ele.getString("media");
|
|
|
|
- if(fileType.contains("photo"))
|
|
|
|
- {
|
|
|
|
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
|
|
|
|
- }
|
|
|
|
- if(fileType.contains("audio") || fileType.contains("voice"))
|
|
|
|
- {
|
|
|
|
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
|
|
|
|
- }
|
|
|
|
- if(fileType.contains("video"))
|
|
|
|
- {
|
|
|
|
- FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //更改场景编辑版本
|
|
|
|
+ sceneEditInfoService.update(
|
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfo>()
|
|
|
|
+ .setSql("version=version+"+1)
|
|
|
|
+ .eq(SceneEditInfo::getSceneProId, scenePro.getId()));
|
|
|
|
|
|
- if(!"aws".equals(this.type)){
|
|
|
|
- JSONObject paramData = new JSONObject();
|
|
|
|
- paramData.put("hotId", sid);
|
|
|
|
- JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
|
|
|
|
- if(hotListJson != null){
|
|
|
|
- JSONArray hotListArray = hotListJson.getJSONArray("data");
|
|
|
|
- if(hotListArray != null){
|
|
|
|
- for(int l = 0, len = hotListArray.size(); l < len; l++){
|
|
|
|
- OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
|
|
|
|
- , paramData.toJSONString());
|
|
|
|
- }
|
|
|
|
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ return ResultData.ok();
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
- else if("0".equals(base.getType())){
|
|
|
|
- jsonhots.set(i, jsonhot);
|
|
|
|
- }
|
|
|
|
|
|
+ private void addOrUpdateHotData(String num, Map<String, String> addOrUpdateMap){
|
|
|
|
+ if(CollUtil.isEmpty(addOrUpdateMap))
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ //数据验证,新增、修改状态,hotdata不能为空
|
|
|
|
+ for (String sid : addOrUpdateMap.keySet()) {
|
|
|
|
+ String hotData = addOrUpdateMap.get(sid);
|
|
|
|
+ if(StrUtil.isEmpty(hotData)){
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_7004);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
|
|
|
|
- File dataPath = new File(dataBuffer.toString());
|
|
|
|
- if(!dataPath.exists()){
|
|
|
|
- dataPath.mkdirs();
|
|
|
|
- }
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString());
|
|
|
|
|
|
+ //批量写入缓存
|
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
|
+ redisUtil.hmset(key, addOrUpdateMap);
|
|
|
|
+ }
|
|
|
|
|
|
- String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
|
|
|
|
- JSONObject scenejson = new JSONObject();
|
|
|
|
- if(strsceneInfos!=null){
|
|
|
|
- scenejson = JSONObject.parseObject(strsceneInfos);
|
|
|
|
- }
|
|
|
|
- if(jsonhots.size()>0){
|
|
|
|
- scenejson.put("hots", 1);
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- scenejson.put("hots", 0);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if(!StrUtil.isEmpty(base.getCapData())){
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
|
|
|
|
- scenejson.put("capData", dataBuf.toString() + "capData.json");
|
|
|
|
- }
|
|
|
|
|
|
+ private void deleteHotData(String num, List<String> deleteSidList) throws IOException {
|
|
|
|
+ //从redis中加载热点数据
|
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, num);
|
|
|
|
+ List<String> deletDataList = redisUtil.hMultiGet(key, deleteSidList);
|
|
|
|
+ if(CollUtil.isEmpty(deletDataList))
|
|
|
|
+ return;
|
|
|
|
+ String userDataPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
|
|
|
- if(!StrUtil.isEmpty(base.getFrameData())){
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
|
|
|
|
- scenejson.put("frameData", dataBuf.toString() + "frameData.json");
|
|
|
|
- }
|
|
|
|
|
|
+ //删除图片音频视频等资源文件
|
|
|
|
+ for (String data : deletDataList) {
|
|
|
|
+ if(StrUtil.isBlank(data)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(data);
|
|
|
|
+ String sid = jsonObject.getString("sid");
|
|
|
|
+ if(jsonObject.containsKey("media")){
|
|
|
|
+ String fileType = jsonObject.getString("media");
|
|
|
|
+ if(fileType.contains("photo"))
|
|
|
|
+ {
|
|
|
|
+ uploadToOssUtil.delete(userDataPath + "hot"+sid+".jpg");
|
|
|
|
+ }
|
|
|
|
+ if(fileType.contains("audio") || fileType.contains("voice"))
|
|
|
|
+ {
|
|
|
|
+ uploadToOssUtil.delete(userDataPath + "hot"+sid+".mp3");
|
|
|
|
+ }
|
|
|
|
+ if(fileType.contains("video"))
|
|
|
|
+ {
|
|
|
|
+ uploadToOssUtil.delete(userDataPath + "hot"+sid+".mp4");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!StorageType.AWS.code().equals(this.type)){
|
|
|
|
+ JSONObject paramData = new JSONObject();
|
|
|
|
+ paramData.put("hotId", sid);
|
|
|
|
+ JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
|
|
|
|
+ if(hotListJson != null){
|
|
|
|
+ JSONArray hotListArray = hotListJson.getJSONArray("data");
|
|
|
|
+ if(hotListArray != null){
|
|
|
|
+ for(int l = 0, len = hotListArray.size(); l < len; l++){
|
|
|
|
+ OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
|
|
|
|
+ , paramData.toJSONString());
|
|
|
|
+ }
|
|
|
|
|
|
- if(!StrUtil.isEmpty(base.getPlayData())){
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
|
|
|
|
- scenejson.put("playData", dataBuf.toString() + "playData.json");
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if(!StrUtil.isEmpty(base.getScreencapThumb())){
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
|
|
|
|
- scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
|
|
|
|
- }
|
|
|
|
|
|
|
|
- scenejson.put("version", scenejson.getIntValue("version") + 1);
|
|
|
|
- FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
|
|
|
|
- return ResultData.ok();
|
|
|
|
|
|
+ //从redis中移除热点数据
|
|
|
|
+ redisUtil.hdel(key, deleteSidList.toArray());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|