|
@@ -21,6 +21,7 @@ import com.fdkankan.common.constant.SceneInfoReqType;
|
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.scene.vo.BaseSceneParamVO;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
|
import com.fdkankan.model.utils.ComputerUtil;
|
|
|
import com.fdkankan.model.utils.CreateHouseJsonUtil;
|
|
@@ -279,6 +280,9 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
//发布场景关联相关数据
|
|
|
this.publicLinkSceneData(num, bucket);
|
|
|
|
|
|
+ //发布滤镜数据
|
|
|
+ this.publicFilterData(num, sceneEditInfoExt.getFilters(), bucket);
|
|
|
+
|
|
|
//本地写sceneJson文件
|
|
|
String localSceneJsonPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "scene.json";
|
|
|
FileUtils.writeFile(localSceneJsonPath, JSON.toJSONString(sceneJson));
|
|
@@ -312,6 +316,20 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ private void publicFilterData(String num, int filters, String bucket) throws IOException {
|
|
|
+
|
|
|
+ String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+ if(filters == CommonStatus.NO.code()){
|
|
|
+ fYunFileService.deleteFile(bucket, userEditPath + "filter.json");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String key = String.format(RedisKey.SCENE_filter_DATA, num);
|
|
|
+ List<String> list = redisUtil.lGet(key, 0, -1);
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ list.stream().forEach(str->jsonArray.add(JSON.parseObject(str)));
|
|
|
+ fYunFileService.uploadFile(bucket, JSON.toJSONBytes(jsonArray), userEditPath + "filter.json");
|
|
|
+ }
|
|
|
+
|
|
|
public void publicLinkSceneData(String num, String bucket) throws IOException {
|
|
|
|
|
|
String imgEditPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
|
|
@@ -2468,4 +2486,104 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData saveFilter(BaseDataParamVO param) throws Exception {
|
|
|
+
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(param.getNum());
|
|
|
+ if(Objects.isNull(scenePlus)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_filter_DATA, param.getNum());
|
|
|
+ JSONArray filterArr = JSON.parseArray(param.getData());
|
|
|
+ int filters = CommonStatus.YES.code();
|
|
|
+ if(CollUtil.isEmpty(filterArr)){
|
|
|
+ filters = CommonStatus.NO.code();
|
|
|
+ redisUtil.del(key);
|
|
|
+ }else{
|
|
|
+ List<String> filterList = filterArr.stream().map(item->JSON.toJSONString(item)).collect(Collectors.toList());
|
|
|
+ redisUtil.lRightPushAll(key, filterList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //写本地文件,作为备份
|
|
|
+ this.writeFilter(param.getNum());
|
|
|
+
|
|
|
+ //更新数据库
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExt.setFilters(filters);
|
|
|
+ sceneEditInfoExtService.updateById(sceneEditInfoExt);
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeFilter(String num) throws Exception{
|
|
|
+
|
|
|
+ String filterPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "filter.json";
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_filter_DATA, num);
|
|
|
+ List<String> filters = redisUtil.lGet(key, 0, -1);
|
|
|
+ if(CollUtil.isEmpty(filters)){
|
|
|
+ FileUtils.deleteFile(filterPath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_filter_JSON, num);
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_1_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ FileUtils.writeFile(filterPath, JSON.toJSONString(filters));
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncFiltersFromFileToRedis(String num) throws Exception{
|
|
|
+
|
|
|
+ String key = String.format(RedisKey.SCENE_filter_DATA, num);
|
|
|
+ boolean exist = redisUtil.hasKey(key);
|
|
|
+ if(exist){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_FILTER_DATA_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 filePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num);
|
|
|
+ String filterData = FileUtils.readFile(filePath + "filter.json");
|
|
|
+ if(StrUtil.isEmpty(filterData)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray jsonArray = JSON.parseArray(filterData);
|
|
|
+ if(CollUtil.isEmpty(jsonArray)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ redisUtil.lRightPushAll(key, jsonArray.stream().collect(Collectors.toList()));
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData listFilter(BaseSceneParamVO param) throws Exception {
|
|
|
+
|
|
|
+ //同步数据
|
|
|
+ this.syncFiltersFromFileToRedis(param.getNum());
|
|
|
+
|
|
|
+ //查询redis
|
|
|
+ String key = String.format(RedisKey.SCENE_filter_DATA, param.getNum());
|
|
|
+ List<String> list = redisUtil.lGet(key, 0, -1);
|
|
|
+ List<JSONObject> collect =
|
|
|
+ list.stream().map(str -> JSON.parseObject(str)).collect(Collectors.toList());
|
|
|
+ return ResultData.ok(collect);
|
|
|
+ }
|
|
|
}
|