|
@@ -7,7 +7,6 @@ import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
@@ -35,12 +34,12 @@ import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import com.fdkankan.scene.api.dto.SceneInfoDTO;
|
|
|
import com.fdkankan.scene.bean.BoxPhotoBean;
|
|
|
-import com.fdkankan.scene.bean.IconBean;
|
|
|
import com.fdkankan.scene.bean.PointBean;
|
|
|
import com.fdkankan.scene.bean.RequestSceneProV4;
|
|
|
import com.fdkankan.scene.bean.SceneJsonBean;
|
|
|
import com.fdkankan.scene.bean.SegmentBean;
|
|
|
import com.fdkankan.scene.bean.StyleBean;
|
|
|
+import com.fdkankan.scene.vo.SurveillanceVO;
|
|
|
import com.fdkankan.scene.bean.TagBean;
|
|
|
import com.fdkankan.scene.bean.VertexBean;
|
|
|
import com.fdkankan.scene.bean.WallBean;
|
|
@@ -68,6 +67,7 @@ import com.fdkankan.scene.service.IScenePlusService;
|
|
|
import com.fdkankan.scene.service.ISceneProExtService;
|
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
|
import com.fdkankan.scene.service.ISceneUploadService;
|
|
|
+import com.fdkankan.scene.service.ISurveillanceService;
|
|
|
import com.fdkankan.scene.vo.*;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.errorprone.annotations.Var;
|
|
@@ -89,7 +89,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
@@ -165,6 +164,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
private FdkankanMiniClient fdkankanMiniClient;
|
|
|
@Autowired
|
|
|
private ISceneUploadService sceneUploadService;
|
|
|
+ @Autowired
|
|
|
+ private ISurveillanceService surveillanceService;
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
@@ -288,6 +289,12 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
//发布场景关联相关数据
|
|
|
this.publicLinkSceneData(num);
|
|
|
|
|
|
+ //发布滤镜数据
|
|
|
+ this.publicFilterData(num, sceneEditInfoExt.getFilters());
|
|
|
+
|
|
|
+ //发布摄像头数据
|
|
|
+ this.publicSurveillance(num, sceneEditInfoExt.getSurveillances());
|
|
|
+
|
|
|
//本地写sceneJson文件
|
|
|
String localSceneJsonPath = String.format(ConstantFilePath.SCENE_DATA_PATH_V4, num) + "scene.json";
|
|
|
FileUtils.writeFile(localSceneJsonPath, JSON.toJSONString(sceneJson));
|
|
@@ -336,6 +343,16 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
|
|
|
+ private void publicSurveillance(String num, Integer surveillances) throws IOException {
|
|
|
+ String surveillanceJsonPath = String.format(UploadFilePath.USER_EDIT_PATH, num) + "surveillance.json";
|
|
|
+ if(surveillances == CommonStatus.NO.code().intValue()){
|
|
|
+ uploadToOssUtil.delete(surveillanceJsonPath);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SurveillanceVO> surveillanceList = surveillanceService.listSurveillance(num);
|
|
|
+ uploadToOssUtil.upload(JSON.toJSONString(surveillanceList).getBytes(StandardCharsets.UTF_8), surveillanceJsonPath);
|
|
|
+ }
|
|
|
+
|
|
|
public void publicLinkSceneData(String num) throws IOException {
|
|
|
|
|
|
String imgEditPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
|
|
@@ -361,6 +378,20 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void publicFilterData(String num, int filters) throws IOException {
|
|
|
+
|
|
|
+ String userEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+ if(filters == CommonStatus.NO.code()){
|
|
|
+ uploadToOssUtil.delete(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)));
|
|
|
+ uploadToOssUtil.upload(JSON.toJSONBytes(jsonArray), userEditPath + "filter.json");
|
|
|
+ }
|
|
|
+
|
|
|
private void buildVideo(SceneEditInfo sceneEditInfo, String path, String num) throws Exception{
|
|
|
if(CommonStatus.NO.equals(sceneEditInfo.getBuildVideoStatus())){
|
|
|
return;
|
|
@@ -494,6 +525,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
sceneInfoVO.setVideos(scenePlusExt.getVideos());
|
|
|
sceneInfoVO.setMosaicList(this.getMosaicList(num));
|
|
|
|
|
|
+ this.SortBoxVideos(sceneInfoVO);
|
|
|
+
|
|
|
// TODO: 2022/4/24 v3版本停机要切换---------------------------start
|
|
|
// this.setExtData(sceneInfoVO, scenePlus.getCameraId());
|
|
|
this.setExtDataFromV3(sceneInfoVO, scenePlus.getCameraId());
|
|
@@ -502,6 +535,35 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
return sceneInfoVO;
|
|
|
}
|
|
|
|
|
|
+ private void SortBoxVideos(SceneInfoVO sceneInfoVO){
|
|
|
+ String boxVideos = sceneInfoVO.getBoxVideos();
|
|
|
+ if(StrUtil.isEmpty(boxVideos)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray boxVideoArr = JSON.parseArray(boxVideos);
|
|
|
+ if(CollUtil.isEmpty(boxVideoArr)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<TagBean> tagBeanList = boxVideoArr.stream().map(o -> {
|
|
|
+ JSONObject item = (JSONObject) o;
|
|
|
+ return TagBean.builder()
|
|
|
+ .createTime(item.getLong("createTime"))
|
|
|
+ .tag(item).build();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //按创建时间倒叙排序
|
|
|
+ tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+
|
|
|
+ //移除createTime字段
|
|
|
+ List<JSONObject> boxVideoList = tagBeanList.stream().map(tagBean -> {
|
|
|
+ JSONObject tag = tagBean.getTag();
|
|
|
+ tag.remove("createTime");
|
|
|
+ return tag;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ sceneInfoVO.setBoxVideos(JSON.toJSONString(boxVideoList));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
getInfo接口返回字段扩展
|
|
@@ -1163,10 +1225,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
fileJson = array.getJSONObject(i);
|
|
|
fileName = fileJson.getString("file");
|
|
|
//文件不存在抛出异常
|
|
|
- if (!new File(target + File.separator + "results" + File.separator + fileName)
|
|
|
- .exists()) {
|
|
|
- throw new Exception(
|
|
|
- target + File.separator + "results" + File.separator + fileName + "文件不存在");
|
|
|
+ if (!new File(target + File.separator + "results" + File.separator + fileName).exists()) {
|
|
|
+ throw new Exception(target + File.separator + "results" + File.separator + fileName + "文件不存在");
|
|
|
}
|
|
|
|
|
|
//high文件夹
|
|
@@ -2392,10 +2452,24 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
boxVideosJson = new JSONArray();
|
|
|
}
|
|
|
|
|
|
+ if(boxVideosJson.size() > 0){
|
|
|
+ int i = 1;
|
|
|
+ long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
|
|
+ for (Object o : boxVideosJson) {
|
|
|
+ JSONObject item = (JSONObject)o;
|
|
|
+ if(Objects.nonNull(item.getLong("createTime"))){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ item.put("createTime", timeInMillis - (i++));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
String result = null;
|
|
|
//删除
|
|
|
if(type == OperationType.DELETE.code()){
|
|
|
- Set<String> deleteFile = new HashSet<>();
|
|
|
+ Set<String> deleteVidoeFile = new HashSet<>();
|
|
|
+ Set<String> deletePicFile = new HashSet<>();
|
|
|
if(boxVideosJson.size() == 0)
|
|
|
return null;
|
|
|
for(int i=0;i<boxVideosJson.size();++i){
|
|
@@ -2404,43 +2478,46 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
String poster = ele.getString("poster");
|
|
|
if(StrUtil.isNotEmpty(poster))
|
|
|
- deleteFile.add(poster);
|
|
|
+ deletePicFile.add(poster);
|
|
|
String url = ele.getString("url");
|
|
|
if(StrUtil.isNotEmpty(url)){
|
|
|
- deleteFile.add(url);
|
|
|
- deleteFile.add(url.replace(".mp4",".flv"));
|
|
|
+ deleteVidoeFile.add(url);
|
|
|
+ deleteVidoeFile.add(url.replace(".mp4",".flv"));
|
|
|
}
|
|
|
|
|
|
boxVideosJson.remove(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //删除资源文件
|
|
|
- if(CollUtil.isNotEmpty(deleteFile))
|
|
|
+ //删除视频文件
|
|
|
+ if(CollUtil.isNotEmpty(deleteVidoeFile))
|
|
|
sceneUploadService.delete(
|
|
|
DeleteFileParamVO.builder().num(num)
|
|
|
.bizType(FileBizType.BOX_VIDEO.code())
|
|
|
- .fileNames(new ArrayList<>(deleteFile)).build());
|
|
|
+ .fileNames(new ArrayList<>(deleteVidoeFile)).build());
|
|
|
+ //删除封面图文件
|
|
|
+ if(CollUtil.isNotEmpty(deleteVidoeFile))
|
|
|
+ sceneUploadService.delete(
|
|
|
+ DeleteFileParamVO.builder().num(num)
|
|
|
+ .bizType(FileBizType.BOX_POSTER.code())
|
|
|
+ .fileNames(new ArrayList<>(deletePicFile)).build());
|
|
|
}else{
|
|
|
|
|
|
- // TODO: 2022/3/1 目前需求只保留一个,所以这里先注释掉,sid不同时,不追加
|
|
|
- //更新
|
|
|
-// boolean exist = false;
|
|
|
-// for(int i=0;i<boxVideosJson.size();++i){
|
|
|
-// JSONObject ele = boxVideosJson.getJSONObject(i);
|
|
|
-// if(ele.getString("sid").equals(sid)){
|
|
|
-// boxVideosJson.set(i, boxVideo);
|
|
|
-// exist = true;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //新增
|
|
|
-// if(!exist){
|
|
|
-// boxVideosJson.add(boxVideo);
|
|
|
-// }
|
|
|
-
|
|
|
- boxVideosJson.clear();
|
|
|
- boxVideosJson.add(boxVideo);
|
|
|
+ boxVideo.put("createTime", Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
|
+ //更新
|
|
|
+ boolean exist = false;
|
|
|
+ for(int i=0;i<boxVideosJson.size();++i){
|
|
|
+ JSONObject ele = boxVideosJson.getJSONObject(i);
|
|
|
+ if(ele.getString("sid").equals(sid)){
|
|
|
+ boxVideosJson.set(i, boxVideo);
|
|
|
+ exist = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新增
|
|
|
+ if(!exist){
|
|
|
+ boxVideosJson.add(boxVideo);
|
|
|
+ }
|
|
|
}
|
|
|
if(boxVideosJson.size() != 0){
|
|
|
result = boxVideosJson.toJSONString();
|
|
@@ -2635,4 +2712,106 @@ 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());
|
|
|
+ redisUtil.del(key);
|
|
|
+
|
|
|
+ JSONArray filterArr = JSON.parseArray(param.getData());
|
|
|
+ int filters = CommonStatus.YES.code();
|
|
|
+ if(CollUtil.isEmpty(filterArr)){
|
|
|
+ filters = CommonStatus.NO.code();
|
|
|
+ }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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|