|
|
@@ -11,18 +11,21 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.modeldemo.bean.SceneEditControlsBean;
|
|
|
import com.fdkankan.modeldemo.bean.SceneJsonBean;
|
|
|
+import com.fdkankan.modeldemo.bean.TagBean;
|
|
|
import com.fdkankan.modeldemo.constant.Constant;
|
|
|
-import com.fdkankan.modeldemo.entity.Scene;
|
|
|
-import com.fdkankan.modeldemo.entity.SceneFileMapping;
|
|
|
-import com.fdkankan.modeldemo.service.SceneFileMappingService;
|
|
|
-import com.fdkankan.modeldemo.service.SceneService;
|
|
|
+import com.fdkankan.modeldemo.constant.RedisKey;
|
|
|
+import com.fdkankan.modeldemo.entity.*;
|
|
|
+import com.fdkankan.modeldemo.service.*;
|
|
|
+import com.fdkankan.redis.RedisClient;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -37,6 +40,16 @@ public class ConvertUtil {
|
|
|
private SceneFileMappingService sceneFileMappingService;
|
|
|
@Resource
|
|
|
private FdfsUtil fdfsUtil;
|
|
|
+ @Resource
|
|
|
+ private RedisClient redisClient;
|
|
|
+ @Autowired
|
|
|
+ private SceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private SceneEditInfoExtService sceneEditInfoExtService;
|
|
|
+ @Autowired
|
|
|
+ private SceneEditControlsService sceneEditControlsService;
|
|
|
+ @Resource
|
|
|
+ private FYunFileService fYunFileService;
|
|
|
|
|
|
private static String[] convertVisableHandler(JSONArray visibles, Map<Integer, String> uuidMap){
|
|
|
int size = visibles.size();
|
|
|
@@ -69,7 +82,7 @@ public class ConvertUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> convert(String sourcePath, String num, String stationCode, Date upTime) throws Exception {
|
|
|
+ public Map<String, String> convert(String sourcePath, String num, String stationCode, Date upTime, String convertType, String upTimeKey) throws Exception {
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
String dataViewPath = String.format(Constant.DATA_VIEW_PATH, num);
|
|
|
@@ -201,7 +214,7 @@ public class ConvertUtil {
|
|
|
}
|
|
|
// FileUtil.copy(sourcePath + "images/vision.txt", targetImagePath + "/vision.txt", true);
|
|
|
//单独上传一份全的vision.txt
|
|
|
- this.uploadVisionTxt(num, sourcePath + "images/vision.txt");
|
|
|
+ this.uploadVisionTxt(num, upTimeKey, sourcePath + "images/vision.txt");
|
|
|
|
|
|
//生成vison.modeldata
|
|
|
String visionStr = FileUtil.readUtf8String(sourcePath + "images/vision.txt");
|
|
|
@@ -273,7 +286,7 @@ public class ConvertUtil {
|
|
|
|
|
|
String finalRoomId = num;
|
|
|
map.keySet().stream().forEach(key->{
|
|
|
- List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByNumAndKey(finalRoomId, subgroup, key);
|
|
|
+ List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByScene(finalRoomId, subgroup, upTimeKey, key);
|
|
|
if(CollUtil.isNotEmpty(sceneFileMappingList)){
|
|
|
List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
|
|
|
sceneFileMappingService.removeByIds(deleteIds);
|
|
|
@@ -285,23 +298,25 @@ public class ConvertUtil {
|
|
|
sceneFileMapping.setUrl(mapping.get("http_url"));
|
|
|
sceneFileMapping.setKey(key);
|
|
|
sceneFileMapping.setSubgroup(subgroup);
|
|
|
+ sceneFileMapping.setUpTime(upTimeKey);
|
|
|
sceneFileMappingService.save(sceneFileMapping);
|
|
|
});
|
|
|
|
|
|
|
|
|
- List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup));
|
|
|
- Scene scene = null;
|
|
|
- if(CollUtil.isEmpty(list)){
|
|
|
- scene = new Scene();
|
|
|
- }else{
|
|
|
- if(list.size() > 1){
|
|
|
- sceneService.remove(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num));
|
|
|
- scene = new Scene();
|
|
|
- }else{
|
|
|
- scene = list.get(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+// List<Scene> list = sceneService.list(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num).eq(Scene::getSubgroup, subgroup).eq(Scene::getUpTimeKey, upTimeKey));
|
|
|
+// Scene scene = null;
|
|
|
+// if(CollUtil.isEmpty(list)){
|
|
|
+// scene = new Scene();
|
|
|
+// }else{
|
|
|
+// if(list.size() > 1){
|
|
|
+// sceneService.remove(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num));
|
|
|
+// scene = new Scene();
|
|
|
+// }else{
|
|
|
+// scene = list.get(0);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ Scene scene = new Scene();
|
|
|
scene.setTitle(sceneBashInfo.getString("title"));
|
|
|
scene.setNum(num);
|
|
|
scene.setFloorlogosize(100);
|
|
|
@@ -316,19 +331,150 @@ public class ConvertUtil {
|
|
|
scene.setUpTime(upTime);
|
|
|
scene.setAlgorithmTime(new Date());
|
|
|
scene.setExtinguisher(extinguisher);
|
|
|
+ scene.setUpTimeKey(upTimeKey);
|
|
|
+ scene.setCacheKeyHasTime(1);
|
|
|
sceneService.saveOrUpdate(scene);
|
|
|
+
|
|
|
+ SceneEditInfo sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfo.setScenePlusId(scene.getId());
|
|
|
+ sceneEditInfo.setTitle(scene.getTitle());
|
|
|
+ sceneEditInfo.setDescription(scene.getDescription());
|
|
|
+ sceneEditInfoService.save(sceneEditInfo);
|
|
|
+
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = new SceneEditInfoExt();
|
|
|
+ sceneEditInfoExt.setScenePlusId(scene.getId());
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditInfoExtService.save(sceneEditInfoExt);
|
|
|
+
|
|
|
+ SceneEditControls sceneEditControls = new SceneEditControls();
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControlsService.save(sceneEditControls);
|
|
|
+
|
|
|
+ //同步热点
|
|
|
+ this.keepHot(scene, sceneEditInfo);
|
|
|
}
|
|
|
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void keepHot(Scene scene, SceneEditInfo sceneEditInfo){
|
|
|
|
|
|
-// map.put(imgViewPath + "vision.modeldata", sourcePath + "images/visionmodeldata.txt");
|
|
|
+ String num = scene.getNum();
|
|
|
+ String upTimeKey = scene.getUpTimeKey();
|
|
|
+ Integer subgroup = scene.getSubgroup();
|
|
|
|
|
|
+ //查询最新的历史场景
|
|
|
+ Scene preScene = sceneService.getOne(new LambdaQueryWrapper<Scene>()
|
|
|
+ .eq(Scene::getNum, num)
|
|
|
+ .eq(Scene::getSubgroup, subgroup)
|
|
|
+ .lt(Scene::getUpTimeKey, upTimeKey)
|
|
|
+ .orderByDesc(Scene::getUpTimeKey).last("limit 1"));
|
|
|
+ if(Objects.isNull(preScene)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ //查询是否有热点
|
|
|
+ String key = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey(), preScene.getCacheKeyHasTime()));
|
|
|
+ Map<String, String> allTagsMap = redisClient.hmget("scene", key);
|
|
|
+ if(CollUtil.isEmpty(allTagsMap)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ //如果有热点,复制redis和涉及的图片
|
|
|
+ String newKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, upTimeKey, scene.getCacheKeyHasTime()));
|
|
|
+ redisClient.hmset("scene", newKey, allTagsMap);
|
|
|
|
|
|
+ sceneEditInfo.setTags(1);
|
|
|
+ sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
|
|
|
- return map;
|
|
|
+ //组装热点数据
|
|
|
+ for (String sid : allTagsMap.keySet()) {
|
|
|
+ String hot = allTagsMap.get(sid);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(hot);
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
+ if(!"image".equals(type) && !"video".equals(type) && !"audio".equals(type)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject media = jsonObject.getJSONObject("media");
|
|
|
+ JSONArray mediaDetail = media.getJSONArray(type);
|
|
|
+ List<String> keyList = mediaDetail.stream().map(v -> {
|
|
|
+ JSONObject content = (JSONObject) v;
|
|
|
+ String src = content.getString("src");
|
|
|
+ return String.format(Constant.USER_VIEW_PATH, num) + src;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(keyList)){
|
|
|
+ List<SceneFileMapping> fileMappingList = sceneFileMappingService.getBySceneBatch(num, subgroup, preScene.getUpTimeKey(), keyList);
|
|
|
+ if(CollUtil.isNotEmpty(fileMappingList)){
|
|
|
+ fileMappingList.stream().forEach(v->{
|
|
|
+ v.setId(null);
|
|
|
+ v.setUpTime(upTimeKey);
|
|
|
+ });
|
|
|
+ sceneFileMappingService.saveBatch(fileMappingList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //发布热点
|
|
|
+ this.publicHotData(scene);
|
|
|
+
|
|
|
+ //复制icon
|
|
|
+ //查询缓存是否包含icons
|
|
|
+ String iconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey() ,preScene.getCacheKeyHasTime()));
|
|
|
+ Set<String> icons = redisClient.sGet("scene", iconKey);
|
|
|
+ if(CollUtil.isNotEmpty(icons)){
|
|
|
+
|
|
|
+ String newIconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, scene.getUpTimeKey() ,scene.getCacheKeyHasTime()));
|
|
|
+ redisClient.sSet("scene", newIconKey, icons);
|
|
|
+
|
|
|
+ List<String> iconFileList = icons.stream().map(i -> {
|
|
|
+ return String.format(Constant.USER_VIEW_PATH, num) + i;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(iconFileList)){
|
|
|
+ List<SceneFileMapping> fileMappingList = sceneFileMappingService.getBySceneBatch(num, subgroup, preScene.getUpTimeKey(), iconFileList);
|
|
|
+ if(CollUtil.isNotEmpty(fileMappingList)){
|
|
|
+ fileMappingList.stream().forEach(v->{
|
|
|
+ v.setId(null);
|
|
|
+ v.setUpTime(scene.getUpTimeKey());
|
|
|
+ });
|
|
|
+ sceneFileMappingService.saveBatch(fileMappingList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void publicHotData(Scene scene) {
|
|
|
+ String sceneNum = scene.getNum();
|
|
|
+ Integer subgroup = scene.getSubgroup();
|
|
|
+ String upTime = scene.getUpTimeKey();
|
|
|
+ Integer cacheKeyHasTime = scene.getCacheKeyHasTime();
|
|
|
+
|
|
|
+ String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(sceneNum, subgroup,upTime,cacheKeyHasTime));
|
|
|
+ Map<String, String> hotMap = redisClient.hmget("scene", hotDataKey);
|
|
|
+
|
|
|
+ JSONArray tags = new JSONArray();
|
|
|
+ if(CollUtil.isNotEmpty(hotMap)){
|
|
|
+ List<TagBean> tagBeanList = hotMap.entrySet().stream().map(entry -> {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(entry.getValue());
|
|
|
+ return TagBean.builder()
|
|
|
+ .createTime(jsonObject.getLong("createTime"))
|
|
|
+ .tag(jsonObject).build();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //按创建时间倒叙排序
|
|
|
+ tagBeanList.sort(Comparator.comparingLong(TagBean::getCreateTime).reversed());
|
|
|
+
|
|
|
+ //移除createTime字段
|
|
|
+ tagBeanList.stream().forEach(tagBean -> {
|
|
|
+ tags.add(tagBean.getTag());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ String hotJsonPath = String.format(Constant.USER_VIEW_PATH, sceneNum) + "hot.json";
|
|
|
+ fYunFileService.uploadFile(sceneNum, subgroup, upTime, tags.toString().getBytes(StandardCharsets.UTF_8), hotJsonPath);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private Integer getExtinguisher(String num, String sourcePath, Map<String, String> map){
|
|
|
int extinguisher = 0;
|
|
|
try {
|
|
|
@@ -367,9 +513,9 @@ public class ConvertUtil {
|
|
|
return extinguisher;
|
|
|
}
|
|
|
|
|
|
- private void uploadVisionTxt(String num, String localVisionTxtPath){
|
|
|
+ private void uploadVisionTxt(String num, String upTime, String localVisionTxtPath){
|
|
|
String key = String.format(Constant.IMG_VIEW_PATH, num) + "vision.txt";
|
|
|
- List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key).eq(SceneFileMapping::getNum, num).eq(SceneFileMapping::getSubgroup, -1));
|
|
|
+ List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.getByScene(num, -1, upTime, key);
|
|
|
if(CollUtil.isNotEmpty(sceneFileMappingList)){
|
|
|
List<String> deleteIds = sceneFileMappingList.stream().map(v -> v.getId()).collect(Collectors.toList());
|
|
|
sceneFileMappingService.removeByIds(deleteIds);
|
|
|
@@ -381,6 +527,7 @@ public class ConvertUtil {
|
|
|
sceneFileMapping.setUrl(mapping.get("http_url"));
|
|
|
sceneFileMapping.setKey(key);
|
|
|
sceneFileMapping.setSubgroup(-1);
|
|
|
+ sceneFileMapping.setUpTime(upTime);
|
|
|
sceneFileMappingService.save(sceneFileMapping);
|
|
|
}
|
|
|
|