SceneServiceImpl.java 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  11. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  12. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  13. import com.baomidou.mybatisplus.core.metadata.IPage;
  14. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  15. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  16. import com.fdkankan.common.constant.*;
  17. import com.fdkankan.common.exception.BusinessException;
  18. import com.fdkankan.common.response.ResultData;
  19. import com.fdkankan.common.util.ConvertUtils;
  20. import com.fdkankan.common.util.DateExtUtil;
  21. import com.fdkankan.common.util.FileUtils;
  22. import com.fdkankan.common.util.MatrixToImageWriterUtil;
  23. import com.fdkankan.fyun.oss.UploadToOssUtil;
  24. import com.fdkankan.fyun.qiniu.QiniuUpload;
  25. import com.fdkankan.platform.api.dto.User;
  26. import com.fdkankan.platform.api.feign.PlatformUserClient;
  27. import com.fdkankan.redis.constant.RedisKey;
  28. import com.fdkankan.redis.constant.RedisLockKey;
  29. import com.fdkankan.redis.util.RedisLockUtil;
  30. import com.fdkankan.redis.util.RedisUtil;
  31. import com.fdkankan.scene.bean.SceneJsonBean;
  32. import com.fdkankan.scene.entity.*;
  33. import com.fdkankan.scene.mapper.ISceneMapper;
  34. import com.fdkankan.scene.mapper.ISceneProMapper;
  35. import com.fdkankan.scene.service.*;
  36. import com.fdkankan.scene.vo.*;
  37. import lombok.extern.slf4j.Slf4j;
  38. import org.apache.commons.lang3.ObjectUtils;
  39. import org.apache.commons.lang3.StringUtils;
  40. import org.joda.time.DateTime;
  41. import org.springframework.beans.BeanUtils;
  42. import org.springframework.beans.factory.annotation.Autowired;
  43. import org.springframework.beans.factory.annotation.Qualifier;
  44. import org.springframework.beans.factory.annotation.Value;
  45. import org.springframework.stereotype.Service;
  46. import org.springframework.web.bind.annotation.RequestBody;
  47. import org.springframework.web.multipart.MultipartFile;
  48. import javax.annotation.Resource;
  49. import java.io.File;
  50. import java.io.IOException;
  51. import java.util.*;
  52. import java.util.stream.Collectors;
  53. /**
  54. * <p>
  55. * 场景表 服务实现类
  56. * </p>
  57. *
  58. * @author dengsixing
  59. * @since 2021-12-23
  60. */
  61. @Slf4j
  62. @Service
  63. public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implements ISceneService {
  64. @Value("${upload.type}")
  65. private String type;
  66. @Value("${oss.prefix.ali}")
  67. private String prefixAli;
  68. @Resource
  69. ISceneProMapper sceneProMapper;
  70. @Autowired
  71. ISceneProService sceneProService;
  72. @Autowired
  73. ISceneExtService sceneExtService;
  74. @Autowired
  75. @Qualifier("uploadToOssUtil")
  76. UploadToOssUtil uploadToOssUtil;
  77. @Autowired
  78. RedisUtil redisUtil;
  79. @Autowired
  80. RedisLockUtil redisLockUtil;
  81. @Autowired
  82. ISceneProExtService sceneProExtService;
  83. @Autowired
  84. PlatformUserClient platformUserClient;
  85. @Autowired
  86. ISceneService sceneService;
  87. @Autowired
  88. private IScenePlusService scenePlusService;
  89. @Autowired
  90. private IScenePlusExtService scenePlusExtService;
  91. @Autowired
  92. private ISceneEditInfoService sceneEditInfoService;
  93. @Autowired
  94. private ISceneEditInfoExtService sceneEditInfoExtService;
  95. @Autowired
  96. private ISceneEditControlsService sceneEditControlsService;
  97. @Autowired
  98. private ISceneDataDownloadService sceneDataDownloadService;
  99. @Autowired
  100. private ISurveillanceService surveillanceService;
  101. @Value("${main.url}")
  102. private String mainUrl;
  103. @Value("${scene.pro.new.url}")
  104. private String sceneProNewUrl;
  105. @Override
  106. public void updateUserIdByCameraId(Long userId, Long cameraId) {
  107. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getCameraId, cameraId).set(Scene::getUserId, userId));
  108. }
  109. @Override
  110. // @SystemServiceLog(description = "上传场景的热点媒体文件")
  111. public void uploadHotMedia(String sceneNum, MultipartFile file) throws IOException {
  112. if(StrUtil.isEmpty(sceneNum)){
  113. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  114. }
  115. ScenePO scene = findBySceneNum(sceneNum);
  116. if(scene == null){
  117. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  118. }
  119. if (!file.isEmpty()){
  120. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum() + "hot";
  121. File targetFile = new File(path);
  122. if (!targetFile.exists()){
  123. targetFile.mkdirs();
  124. }
  125. String fileName = file.getOriginalFilename();
  126. targetFile = new File(path + File.separator + fileName);
  127. if (targetFile.exists()){
  128. FileUtils.deleteFile(path + File.separator + fileName);
  129. }
  130. file.transferTo(targetFile);
  131. }
  132. }
  133. @Override
  134. // @SystemServiceLog(description = "上传场景的导览图片")
  135. public void uploadGuidePic(String sceneId, MultipartFile file) throws IOException {
  136. Scene scene = this.getValidById(Long.valueOf(sceneId));
  137. if (scene != null && !file.isEmpty()){
  138. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum()
  139. + File.separator + ConstantFileName.GUIDE_MEDIA_FOLDER;
  140. File targetFile = new File(path);
  141. if (!targetFile.exists()){
  142. targetFile.mkdirs();
  143. }
  144. String fileName = file.getOriginalFilename();
  145. targetFile = new File(path + File.separator + fileName);
  146. int count = 1;
  147. while (targetFile.exists()){
  148. targetFile = new File(path + File.separator + fileName.substring(0, fileName.lastIndexOf("."))+"("+count+")"+fileName.substring(fileName.lastIndexOf(".")));
  149. ++count;
  150. }
  151. file.transferTo(targetFile);
  152. }
  153. }
  154. @Override
  155. // @SystemServiceLog(description = "保存热点的导览信息")
  156. public ResultData saveGuideInfo(SceneParamVO base) throws Exception {
  157. ResultData result = null;
  158. Scene scene = getValidById(base.getSceneId());
  159. if (scene != null){
  160. String path = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum()
  161. + File.separator + ConstantFileName.GUIDE_DATAFILE;
  162. File file = new File(path);
  163. String guideData = null;
  164. if(file.exists()) {
  165. guideData = FileUtils.readFile(path);
  166. }
  167. if (StrUtil.isEmpty(guideData)){
  168. result = ResultData.error(ErrorCode.FAILURE_CODE_5001);
  169. }else{
  170. JSONObject guideJo = JSONObject.parseObject(guideData);
  171. if ("1".equals(base.getType())) {
  172. if (StrUtil.isEmpty(base.getOrder())) {
  173. result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
  174. }else{
  175. if(!StrUtil.isEmpty(base.getItem())) {
  176. JSONObject jo = new JSONObject();
  177. JSONArray jy = guideJo.getJSONArray("images");
  178. jy.add(JSONObject.parse(base.getItem()));
  179. }
  180. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  181. }
  182. } else if ("2".equals(base.getType())) {
  183. if (StrUtil.isEmpty(base.getOrder()) || StrUtil.isEmpty(base.getGuideSid())) {
  184. result = ResultData.error(ErrorCode.FAILURE_CODE_5003);
  185. }else{
  186. JSONArray jy = guideJo.getJSONArray("images");
  187. for (int i = 0; i < jy.size(); ++i) {
  188. JSONObject itemData = jy.getJSONObject(i);
  189. if (itemData.getString("sid").equals(base.getGuideSid())) {
  190. jy.remove(i);
  191. break;
  192. }
  193. }
  194. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  195. }
  196. } else if ("3".equals(base.getType())) {
  197. if (StrUtil.isEmpty(base.getOrder())) {
  198. result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
  199. } else {
  200. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  201. }
  202. } else if ("4".equals(base.getType())) {
  203. if (StrUtil.isEmpty(base.getGuideName()) || StrUtil.isEmpty(base.getGuideSid())) {
  204. result = ResultData.error(ErrorCode.FAILURE_CODE_5004);
  205. }else{
  206. JSONArray jy = guideJo.getJSONArray("images");
  207. for (int i = 0; i < jy.size(); ++i) {
  208. JSONObject itemData = jy.getJSONObject(i);
  209. if (itemData.getString("sid").equals(base.getGuideSid())) {
  210. itemData.put("name", base.getGuideName());
  211. break;
  212. }
  213. }
  214. }
  215. }
  216. FileUtils.deleteFile(path);
  217. FileUtils.writeFileContent(path, guideJo.toString());
  218. result = ResultData.ok();
  219. }
  220. }else{
  221. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  222. }
  223. return result;
  224. }
  225. @Override
  226. // @SystemServiceLog(description = "恢复场景的户型图")
  227. public ResultData recoveryFloor(SceneParamVO base) throws Exception {
  228. ResultData result = null;
  229. Scene scene = this.getValidById(base.getSceneId());
  230. if (scene != null) {
  231. String unicode = scene.getDataSource();
  232. if (StrUtil.isNotEmpty(unicode)) {
  233. unicode = unicode.substring(0, unicode.lastIndexOf("/"));
  234. unicode = unicode.replace(ConstantUrl.DEFAULT_PREFIX_QINIU_PIC, "");
  235. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode + File.separator + "tex" + File.separator + "floor.json";
  236. FileUtils.copyFile(path, ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum() + File.separator + "floor.json", true);
  237. }
  238. result = ResultData.ok();
  239. } else {
  240. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  241. }
  242. return result;
  243. }
  244. @Override
  245. // @SystemServiceLog(description = "保存场景编辑信息")
  246. public ResultData saveEditInfo(SceneParamVO base) throws Exception {
  247. ResultData result = ResultData.ok();
  248. Scene scene = this.getValidById(base.getSceneId());
  249. if (scene != null) {
  250. JSONObject json = new JSONObject();
  251. json.put("sceneName", base.getSceneName());
  252. json.put("sceneDec", base.getSceneDec());
  253. json.put("sceneType", base.getSceneType());
  254. json.put("scenePsd", base.getSceneKey());
  255. json.put("version", base.getVersion());
  256. json.put("thumbImg", base.getThumbImg());
  257. json.put("currentPanoId", base.getCurrentPanoId());
  258. json.put("floorLogo", base.getFloorLogo());
  259. json.put("floorLogoSize", base.getFloorLogoSize());
  260. json.put("entry", base.getEntry());
  261. json.put("index", base.getIndex());
  262. json.put("sceneIndex", base.getSceneIndex());
  263. JSONObject json2 = new JSONObject();
  264. json2.put("geoData", base.getGeoData());
  265. json2.put("center", base.getCenter());
  266. json2.put("zoom", base.getZoom());
  267. json2.put("realScale", base.getRealScale());
  268. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
  269. .append("images").append(File.separator)
  270. .append("images").append(base.getIndex());
  271. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
  272. .append("data").append(File.separator)
  273. .append("data").append(base.getIndex());
  274. File imagesFile = new File(imagesBuffer.toString());
  275. if(!imagesFile.exists() || !imagesFile.isDirectory()) {
  276. imagesFile.mkdirs();
  277. }
  278. File dataFile = new File(dataBuffer.toString());
  279. if(!dataFile.exists() || !dataFile.isDirectory()) {
  280. dataFile.mkdirs();
  281. }
  282. if (StrUtil.isNotEmpty(base.getThumbFishBigImg()) && !"undefined".equals(base.getThumbFishBigImg())){
  283. StringBuffer sb = new StringBuffer(imagesBuffer);
  284. String thumbFishBigImgPath = sb.append(File.separator).append("thumbFishBigImg.jpg").toString();
  285. FileUtils.deleteFile(thumbFishBigImgPath);
  286. FileUtils.uploadImg(thumbFishBigImgPath, base.getThumbFishBigImg());
  287. }
  288. if (StrUtil.isNotEmpty(base.getThumbBigImg()) && !"undefined".equals(base.getThumbBigImg())) {
  289. StringBuffer sb = new StringBuffer(imagesBuffer);
  290. String thumbBigImgPath = sb.append(File.separator).append("thumbBigImg.jpg").toString();
  291. FileUtils.deleteFile(thumbBigImgPath);
  292. FileUtils.uploadImg(thumbBigImgPath, base.getThumbBigImg());
  293. }
  294. if (StrUtil.isNotEmpty(base.getThumbSmallImg()) && !"undefined".equals(base.getThumbSmallImg())) {
  295. StringBuffer sb = new StringBuffer(imagesBuffer);
  296. String thumbSmallImgPath = sb.append(File.separator).append("thumbSmallImg.jpg").toString();
  297. FileUtils.deleteFile(thumbSmallImgPath);
  298. FileUtils.uploadImg(thumbSmallImgPath, base.getThumbSmallImg());
  299. }
  300. if (StrUtil.isNotEmpty(base.getFloorLogoImg()) && !"undefined".equals(base.getFloorLogoImg())) {
  301. StringBuffer sb = new StringBuffer(imagesBuffer);
  302. String floorLogoImgPath = sb.append(File.separator).append("floorLogoImg.png").toString();
  303. FileUtils.deleteFile(floorLogoImgPath);
  304. FileUtils.uploadImg(floorLogoImgPath, base.getFloorLogoImg());
  305. }
  306. if (StrUtil.isNotEmpty(base.getImgData()) && !"undefined".equals(base.getImgData())) {
  307. StringBuffer sb = new StringBuffer(imagesBuffer);
  308. String floorPlanPath = sb.append(File.separator).append("floorplan.png").toString();
  309. FileUtils.deleteFile(floorPlanPath);
  310. FileUtils.uploadImg(floorPlanPath, base.getImgData());
  311. if (base.getFloorPlaneInfo() != null) {
  312. String floorPath = dataBuffer.append(File.separator).append("floor.json").toString();
  313. FileUtils.deleteFile(floorPath);
  314. JSONObject info = JSONObject.parseObject(base.getFloorPlaneInfo());
  315. if (info.containsKey("height")) {
  316. json2.put("height", info.getString("height"));
  317. }
  318. if (info.containsKey("width")) {
  319. json2.put("width", info.getString("width"));
  320. }
  321. if (info.containsKey("position")) {
  322. json2.put("position", info.getJSONObject("position"));
  323. }
  324. FileUtils.writeFileContent(floorPath, json2.toString());
  325. }
  326. }
  327. String floorFilepath = imagesBuffer.append(File.separator).append("scene.json").toString();
  328. FileUtils.writeFileContent(floorFilepath, json.toString());
  329. } else {
  330. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  331. }
  332. return result;
  333. }
  334. @Override
  335. // @SystemServiceLog(description = "发布场景")
  336. public ResultData publishScene(SceneParamVO base) throws Exception {
  337. ResultData result = ResultData.ok();
  338. Scene scene = this.getValidById(base.getSceneId());
  339. if (scene != null) {
  340. SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
  341. StringBuffer dataBuf = new StringBuffer()
  342. .append("data").append(File.separator)
  343. .append("data").append(scene.getNum())
  344. .append(File.separator);
  345. StringBuffer imagesBuf = new StringBuffer()
  346. .append("images").append(File.separator)
  347. .append("images").append(scene.getNum())
  348. .append(File.separator);
  349. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  350. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  351. String str = FileUtils.readFile(dataBuffer.append("scene.json").toString());
  352. JSONObject json = JSONObject.parseObject(str);
  353. String sceneIndex = json.getString("sceneIndex") == null ? "0" : json.getString("sceneIndex");
  354. String index = json.getString("index");
  355. if(json.containsKey("entry")) {
  356. String entry = json.getString("entry");
  357. sceneExt.setEntry(entry);
  358. }
  359. String sceneType = json.getString("sceneType");
  360. int type = sceneType != null ? Integer.valueOf(sceneType) : 0;
  361. scene.setNum(index);
  362. scene.setSceneName(json.getString("sceneName"));
  363. scene.setSceneDec(json.getString("sceneDec"));
  364. scene.setSceneType(type);
  365. scene.setSceneKey(json.getString("scenePsd"));
  366. scene.setVersion(json.getInteger("version")+1);
  367. scene.setThumbStatus(json.getInteger("thumbImg"));
  368. scene.setFloorLogo(json.getString("floorLogo"));
  369. scene.setFloorLogoSize(json.getInteger("floorLogoSize"));
  370. sceneExt.setStyle(Integer.valueOf(sceneIndex));
  371. if (scene.getThumbStatus() == 1) {
  372. scene.setThumb(ConstantUrl.PREFIX_QINIU + imagesBuf.append("thumbSmallImg.jpg").toString());
  373. } else {
  374. scene.setThumb(ConstantUrl.PREFIX_QINIU + "loading/pc.jpg");
  375. }
  376. //上传文件到七牛云
  377. QiniuUpload.setFilesToBucket(imagesBuf.toString(), imagesBuffer.toString());
  378. QiniuUpload.setFilesToBucket(dataBuf.toString(), dataBuffer.toString());
  379. scene.setUpdateTime(Calendar.getInstance().getTime());
  380. this.updateById(scene);
  381. sceneExt.setUpdateTime(Calendar.getInstance().getTime());
  382. sceneExtService.updateById(sceneExt);
  383. } else {
  384. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  385. }
  386. return result;
  387. }
  388. @Override
  389. // @SystemServiceLog(description = "删除场景热点")
  390. public ResultData deleteHot(SceneParamVO base) throws Exception {
  391. ResultData result = ResultData.ok();
  392. Scene scene = getValidById(base.getSceneId());
  393. if (scene != null && StrUtil.isNotEmpty(base.getIndex())) {
  394. SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
  395. StringBuffer dataBuf = new StringBuffer()
  396. .append("data").append(File.separator)
  397. .append("data").append(scene.getNum())
  398. .append(File.separator);
  399. StringBuffer imagesBuf = new StringBuffer()
  400. .append("images").append(File.separator)
  401. .append("images").append(scene.getNum())
  402. .append(File.separator);
  403. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  404. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()).append("hot.json");
  405. String str = FileUtils.readFile(dataBuffer.toString());
  406. JSONArray jsonhots = null;
  407. if (StrUtil.isNotEmpty(str)){
  408. jsonhots = JSONArray.parseArray(str);
  409. for (int i = 0; i < jsonhots.size(); ++i) {
  410. JSONObject ele = jsonhots.getJSONObject(i);
  411. if (ele.getString("sid").equals(base.getIndex())) {
  412. jsonhots.remove(i);
  413. break;
  414. }
  415. }
  416. }
  417. String sPath = null;
  418. File file = new File(imagesBuffer.toString());
  419. if (file.isDirectory()){
  420. String[] strs = file.list();
  421. if (strs != null) {
  422. for (int i = 0; i < strs.length; ++i) {
  423. if (strs[i].contains("hot" + base.getIndex())) {
  424. sPath = imagesBuffer.toString() + strs[i];
  425. break;
  426. }
  427. }
  428. }
  429. }
  430. if (sPath != null){
  431. FileUtils.deleteFile(sPath);
  432. }
  433. FileUtils.deleteFile(dataBuffer.toString());
  434. if (jsonhots != null){
  435. FileUtils.writeFileContent(dataBuffer.toString(), jsonhots.toString());
  436. }
  437. String hotsIds = sceneExt.getHotsIds();
  438. if (StrUtil.isNotEmpty(hotsIds)) {
  439. String updateHotsIds = "";
  440. String[] sids = hotsIds.split(",");
  441. boolean flag = false;
  442. for (int i = 0; i < sids.length; ++i) {
  443. String s = sids[i];
  444. if (s.equals(base.getIndex())) {
  445. flag = true;
  446. } else {
  447. updateHotsIds += s + ",";
  448. }
  449. }
  450. if (!flag) {
  451. scene.setVersion(scene.getVersion() + 1);
  452. scene.setUpdateTime(Calendar.getInstance().getTime());
  453. this.updateById(scene);
  454. sceneExt.setHotsIds(updateHotsIds);
  455. sceneExt.setUpdateTime(Calendar.getInstance().getTime());
  456. sceneExtService.updateById(sceneExt);
  457. }
  458. }
  459. } else {
  460. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  461. }
  462. return result;
  463. }
  464. @Override
  465. // @SystemServiceLog(description = "保存场景热点")
  466. public ResultData saveHot(SceneEditParamVO base) throws Exception {
  467. if(StrUtil.isEmpty(base.getHotData()) || StrUtil.isEmpty(base.getType())){
  468. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  469. }
  470. String sid = base.getSid();
  471. ScenePO scene = findBySceneNum(base.getNum());
  472. if (scene == null ) {
  473. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  474. }
  475. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  476. StringBuffer dataBuf = new StringBuffer()
  477. .append("data").append(File.separator)
  478. .append("data").append(scene.getNum())
  479. .append(File.separator);
  480. StringBuffer imagesBuf = new StringBuffer()
  481. .append("images").append(File.separator)
  482. .append("images").append(scene.getNum())
  483. .append(File.separator);
  484. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  485. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  486. String str = FileUtils.readFile(dataBuffer.append("hot.json").toString());
  487. JSONArray jsonhots = null;
  488. if (StrUtil.isNotEmpty(str)) {
  489. jsonhots = JSONArray.parseArray(str);
  490. }else {
  491. File file = new File(dataBuffer.append("hot.json").toString());
  492. if(!file.getParentFile().exists()){
  493. file.getParentFile().mkdirs();
  494. }
  495. if(!file.exists()){
  496. file.createNewFile();
  497. }
  498. }
  499. //添加或者修改
  500. if("1".equals(base.getType())){
  501. sid = jsonhot.getString("sid");
  502. if(StrUtil.isEmpty(sid)){
  503. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  504. }
  505. jsonhots.add(jsonhot);
  506. }
  507. else if("0".equals(base.getType())){
  508. sid = jsonhot.getString("sid");
  509. if(StrUtil.isEmpty(sid)){
  510. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  511. }
  512. }
  513. else if("-1".equals(base.getType())){
  514. if(StrUtil.isEmpty(sid)){
  515. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  516. }
  517. }
  518. for(int i=0;i<jsonhots.size();++i){
  519. JSONObject ele = jsonhots.getJSONObject(i);
  520. if(ele.getString("sid").equals(sid)){
  521. if("-1".equals(base.getType())){
  522. jsonhots.remove(i);
  523. if(ele.containsKey("media")){
  524. String fileType = ele.getString("media");
  525. if(fileType.contains("photo"))
  526. {
  527. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".jpg").toString());
  528. }
  529. if(fileType.contains("audio"))
  530. {
  531. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp3").toString());
  532. }
  533. if(fileType.contains("video"))
  534. {
  535. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp4").toString());
  536. }
  537. }
  538. }
  539. else if("0".equals(base.getType())){
  540. jsonhots.set(i, jsonhot);
  541. }
  542. break;
  543. }
  544. }
  545. FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
  546. File dataPath = new File(dataBuffer.toString());
  547. if(!dataPath.exists()){
  548. dataPath.mkdirs();
  549. }
  550. FileUtils.writeFile(dataBuffer.append("hot.json").toString(), jsonhots.toString());
  551. String strsceneInfos = FileUtils.readFile(dataBuffer.append("scene.json").toString());
  552. JSONObject scenejson = new JSONObject();
  553. if(strsceneInfos!=null){
  554. scenejson = JSONObject.parseObject(strsceneInfos);
  555. }
  556. if(jsonhots.size()>0){
  557. scenejson.put("hots", 1);
  558. }
  559. else{
  560. scenejson.put("hots", 0);
  561. }
  562. FileUtils.writeFile(dataBuffer.append("scene.json").toString(), scenejson.toString());
  563. return ResultData.ok();
  564. }
  565. @Override
  566. // @SystemServiceLog(description = "漫游可行")
  567. public ResultData saveLinkPano(SceneEditParamVO base) throws Exception {
  568. if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getNum())){
  569. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  570. }
  571. ScenePO scene = baseMapper.findByNum(base.getNum());
  572. if (scene == null ) {
  573. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  574. }
  575. JSONArray inputData = JSONObject.parseArray(base.getData());
  576. StringBuffer dataBuf = new StringBuffer()
  577. .append("data").append(File.separator)
  578. .append("data").append(scene.getNum())
  579. .append(File.separator);
  580. StringBuffer imagesBuf = new StringBuffer()
  581. .append("images").append(File.separator)
  582. .append("images").append(scene.getNum())
  583. .append(File.separator);
  584. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  585. File directory = new File(dataBuffer.toString());
  586. if (!directory.exists()) {
  587. directory.mkdirs();
  588. }
  589. JSONArray inputdata = JSONArray.parseArray(base.getData());
  590. String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  591. if("aws".equals(type)){
  592. modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  593. }
  594. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  595. File file = new File(dataBuffer.append("vision.modeldata").toString());
  596. if(file.exists()) {
  597. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  598. }
  599. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.append("vision.modeldata").toString(), dataBuffer.append("vision.json").toString());
  600. String str = FileUtils.readFile(dataBuffer.append("vision.json").toString());
  601. JSONObject json = JSONObject.parseObject(str);
  602. JSONArray panos = json.getJSONArray("sweepLocations");
  603. for (int i = 0; i < panos.size(); ++i) {
  604. JSONObject pano = panos.getJSONObject(i);
  605. for (int j = 0; j < inputData.size(); ++j) {
  606. JSONObject jo = inputData.getJSONObject(j);
  607. String currentPanoId = jo.getString("panoID");
  608. JSONArray visibles = jo.getJSONArray("visibles");
  609. JSONArray visibles3 = jo.getJSONArray("visibles3");
  610. if (pano.getString("uuid").equals(currentPanoId)) {
  611. pano.put("visibles", visibles);
  612. pano.put("visibles3", visibles3);
  613. }
  614. }
  615. }
  616. FileUtils.deleteFile(dataBuffer.append("vision.json").toString());
  617. FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
  618. FileUtils.writeFileContent(dataBuffer.toString() + "vision.json", json.toString());
  619. ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
  620. uploadToOssUtil.upload(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
  621. return ResultData.ok();
  622. }
  623. @Override
  624. // @SystemServiceLog(description = "保存热点可见性的数据")
  625. public ResultData saveHotVisible(SceneEditParamVO base) throws Exception {
  626. if(StrUtil.isEmpty(base.getData())){
  627. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  628. }
  629. // ScenePO scene = findBySceneNum(base.getNum());
  630. Scene scene = this.getSceneBySceneCode(base.getNum());
  631. if (scene == null ) {
  632. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  633. }
  634. JSONArray visiblePanos = JSONArray.parseArray(base.getData());
  635. StringBuffer dataBuf = new StringBuffer()
  636. .append("data").append(File.separator)
  637. .append("data").append(scene.getNum())
  638. .append(File.separator);
  639. StringBuffer imagesBuf = new StringBuffer()
  640. .append("images").append(File.separator)
  641. .append("images").append(scene.getNum())
  642. .append(File.separator);
  643. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  644. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  645. File file = new File(dataBuffer.toString() + "hot.json");
  646. if (!file.exists()) {
  647. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  648. }
  649. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  650. JSONArray hots = JSONArray.parseArray(str);
  651. for (int i = 0; i < hots.size(); ++i) {
  652. JSONObject hot = hots.getJSONObject(i);
  653. for (int j = 0; j < visiblePanos.size(); ++j) {
  654. if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
  655. hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
  656. }
  657. }
  658. }
  659. scene.setVersion(scene.getVersion() + 1);
  660. scene.setUpdateTime(Calendar.getInstance().getTime());
  661. this.updateById(scene);
  662. FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
  663. FileUtils.writeFileContent(dataBuffer.append("hot.json").toString(), hots.toString());
  664. return ResultData.ok();
  665. }
  666. @Override
  667. public IPage<SceneVO> queryByParam(SceneParamVO param) {
  668. int pageNum = param.getPageNum();
  669. int pageSize = param.getPageSize();
  670. Page<SceneVO> page = new Page<>(pageNum, pageSize);
  671. if(StrUtil.isEmpty(param.getUserIds())){
  672. param.setUserIds("0");
  673. }
  674. if(StrUtil.isEmpty(param.getCameraIds())){
  675. param.setCameraIds("0");
  676. }
  677. List<SceneVO> list = baseMapper.queryByParam(page, param);
  678. page.setRecords(list);
  679. return page;
  680. }
  681. @Override
  682. public IPage<SceneVO> queryByParamNew(SceneParamVO param) {
  683. int pageNum = param.getPageNum();
  684. int pageSize = param.getPageSize();
  685. Page<SceneVO> page = new Page<>(pageNum, pageSize);
  686. if(StrUtil.isEmpty(param.getUserIds())){
  687. param.setUserIds("0");
  688. }
  689. if(StrUtil.isEmpty(param.getCameraIds())){
  690. param.setCameraIds("0");
  691. }
  692. List<SceneVO> list = baseMapper.queryByParamNew(page, param);
  693. page.setRecords(list);
  694. return page;
  695. }
  696. // @Override
  697. // public List<SceneVO> findSceneProBySnCode(SceneParamVO param) {
  698. // return sceneMapper.findSceneProBySnCode(param);
  699. // }
  700. @Override
  701. public Scene getValidById(long id) {
  702. return this.getOne(new LambdaQueryWrapper<Scene>()
  703. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  704. .eq(Scene::getId, id));
  705. }
  706. @Override
  707. public List<SceneVO> convert(List<ScenePO> list) {
  708. List<SceneVO> sceneVOs = list.stream().map(po -> {
  709. SceneVO sceneVO = new SceneVO();
  710. BeanUtils.copyProperties(po, sceneVO);
  711. if (po.getCreateTime() != null) {
  712. sceneVO.setCreateTime(DateUtil.format(po.getCreateTime(), DateExtUtil.dateStyle4));
  713. sceneVO.setCreateDate(po.getCreateTime().getTime());
  714. }
  715. return sceneVO;
  716. }).collect(Collectors.toList());
  717. return sceneVOs;
  718. }
  719. @Override
  720. public List<SceneVO> convertPro(List<SceneProPO> list) {
  721. List<SceneVO> sceneVOs = list.stream().map(po -> {
  722. SceneVO sceneVO = new SceneVO();
  723. BeanUtils.copyProperties(po, sceneVO);
  724. if (po.getCreateTime() != null) {
  725. sceneVO.setCreateTime(new DateTime(po.getCreateTime()).toString("yyyy-MM-dd"));
  726. if ("aws".equals(this.type)) {
  727. sceneVO.setCreateTime(new DateTime(DateExtUtil.hoursCalculate(po.getCreateTime(), 8)).toString("yyyy-MM-dd"));
  728. }
  729. sceneVO.setCreateDate(po.getCreateTime().getTime());
  730. }
  731. sceneVO.setIsFolder(0);
  732. sceneVO.setStatus(po.getSceneStatus());
  733. return sceneVO;
  734. }).collect(Collectors.toList());
  735. return sceneVOs;
  736. }
  737. @Override
  738. public List<ScenePO> findAllByYesterday() throws Exception {
  739. return baseMapper.findAllByYesterday();
  740. }
  741. @Override
  742. public ScenePO findBySceneNum(String sceneNum) {
  743. return baseMapper.findByNum(sceneNum);
  744. }
  745. @Override
  746. public Scene getSceneBySceneCode(String sceneCode) {
  747. List<Scene> list = this.list(new LambdaQueryWrapper<Scene>()
  748. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  749. .eq(Scene::getNum, sceneCode));
  750. if(CollUtil.isEmpty(list)){
  751. return null;
  752. }
  753. return list.get(0);
  754. }
  755. @Override
  756. public ResultData recover(String sceneNum) throws Exception {
  757. ScenePO scene = baseMapper.findByNum(sceneNum);
  758. if (scene == null){
  759. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  760. }
  761. scene.setPayStatus(1);
  762. this.update(new LambdaUpdateWrapper<Scene>()
  763. .eq(Scene::getId, scene.getId())
  764. .set(Scene::getPayStatus, PayStatus.PAY.code()));
  765. SceneVO SceneVO = new SceneVO();
  766. BeanUtils.copyProperties(scene, SceneVO);
  767. return ResultData.ok(SceneVO);
  768. }
  769. // public int getSceneCount(Long cameraId) {
  770. // return sceneMapper.getSceneCount(cameraId);
  771. // }
  772. @Override
  773. public Scene getSceneStatusByUnicode(String unicode, int tbStatus) {
  774. return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getTbStatus, tbStatus).like(Scene::getDataSource, "%"+unicode+"%"));
  775. }
  776. public void updateStatus(String sceneNum, int status) {
  777. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getSceneStatus, status));
  778. }
  779. public void updatePayStatus(String sceneNum, int status) {
  780. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getPayStatus, status));
  781. }
  782. @Override
  783. public void updateTime(String sceneNum, Long space, int payStatus) {
  784. List<Scene> sceneList = this.list(new LambdaQueryWrapper<Scene>()
  785. .select(Scene::getId)
  786. .eq(Scene::getNum, sceneNum));
  787. if(CollUtil.isEmpty(sceneList))
  788. return ;
  789. List<Long> sceneIds = sceneList.stream().map(scene -> {
  790. return scene.getId();
  791. }).collect(Collectors.toList());
  792. this.update(new LambdaUpdateWrapper<Scene>()
  793. .in(Scene::getId, sceneIds)
  794. .set(Scene::getCreateTime, Calendar.getInstance().getTime())
  795. .set(Scene::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
  796. sceneExtService.update(new LambdaUpdateWrapper<SceneExt>().in(SceneExt::getSceneId, sceneIds).set(SceneExt::getSpace, space));
  797. }
  798. @Override
  799. public ResultData addHotMediaInfo(SceneEditParamVO base) throws Exception{
  800. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getType()) ||
  801. StrUtil.isEmpty(base.getInfo())){
  802. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  803. }
  804. ScenePO scene = findBySceneNum(base.getNum());
  805. if(scene == null){
  806. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  807. }
  808. StringBuffer dataBuf = new StringBuffer()
  809. .append("data").append(File.separator)
  810. .append("data").append(scene.getNum())
  811. .append(File.separator);
  812. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  813. String infoData = FileUtils.readFile(dataBuffer.append("mediaInfo.json").toString());
  814. JSONArray medias = null;
  815. if(infoData != null){
  816. medias= JSONArray.parseArray(infoData);
  817. }
  818. if("1".equals(base.getType())){
  819. JSONObject jo = JSONObject.parseObject(base.getInfo());
  820. medias.add(jo);
  821. }else if("1".equals(base.getType())){
  822. for(int i=0;i<medias.size();++i){
  823. JSONObject ob = medias.getJSONObject(i);
  824. if(ob.getString("file").equals(base.getName())){
  825. medias.remove(i);
  826. break;
  827. }
  828. }
  829. }else{
  830. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  831. }
  832. FileUtils.writeFile(dataBuffer.append("mediaInfo.json").toString(), medias.toString());
  833. return ResultData.ok();
  834. }
  835. @Override
  836. public ResultData saveScreencapFile(SceneEditParamVO base) throws Exception{
  837. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getIndex()) ||
  838. StrUtil.isEmpty(base.getCamerasData())){
  839. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  840. }
  841. ScenePO scene = findBySceneNum(base.getNum());
  842. if(scene == null){
  843. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  844. }
  845. StringBuffer dataBuf = new StringBuffer()
  846. .append("data").append(File.separator)
  847. .append("data").append(scene.getNum())
  848. .append(File.separator);
  849. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  850. if("1".equals(base.getIndex())){
  851. File file = new File(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).toString());
  852. if(file.isDirectory()){
  853. String[] strs = file.list();
  854. if(strs!=null){
  855. for(int i=0;i<strs.length;++i) {
  856. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  857. FileUtils.deleteFile(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(strs[i]).toString());
  858. }
  859. }
  860. }
  861. } else {
  862. file.mkdirs();
  863. }
  864. Map<String, Object> map = new HashMap<>();
  865. map.put("screencapLen", "0");
  866. map.put("version", scene.getVersion()+1);
  867. FileUtils.writeJsonFile(dataBuffer.append("scene.json").toString(), map);
  868. //sceneService.updateScreencapLen(sceneNum, 0);
  869. }
  870. String filePath = dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(ConstantFileName.SCREEN_CRP_DATAFILE).append(base.getIndex()).append("json").toString();
  871. File file = new File(filePath);
  872. if(!file.exists())
  873. {
  874. file.createNewFile();
  875. }
  876. FileUtils.writeFile(filePath, base.getCamerasData());
  877. return ResultData.ok();
  878. }
  879. @Override
  880. public Page<SceneProPO> findAllScene(SceneParamVO param) {
  881. Page<SceneProPO> page = new Page<>(param.getPageNum(), param.getPageSize());
  882. return baseMapper.findAllScene(page, param);
  883. }
  884. @Override
  885. public Page<ScenePO> unionSearchBySceneName(SceneParamVO param) {
  886. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  887. return baseMapper.unionSearchBySceneName(page, param.getSearchKey());
  888. }
  889. @Override
  890. public List<SceneProPO> getOnlySceneList(SceneParamVO param) throws Exception {
  891. return baseMapper.getOnlySceneList(param);
  892. }
  893. @Override
  894. public ResultData updateViewCount(String sceneNum) {
  895. String key = String.format(RedisKey.SCENE_VISIT_CNT, sceneNum);
  896. Object countObject = redisUtil.get(key);
  897. int count = 0;
  898. if(countObject == null){
  899. String lockKey = String.format(RedisLockKey.LOCK_SCENE_VISIT_CNT, sceneNum);
  900. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
  901. try {
  902. if(!lock){
  903. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  904. }
  905. countObject = redisUtil.get(key);
  906. if(countObject == null){
  907. Scene scene = this.getSceneBySceneCode(sceneNum);
  908. if(scene == null){
  909. ScenePro scenePro = sceneProMapper.findByNum(sceneNum);
  910. if(scenePro != null){
  911. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  912. count = sceneProExt.getViewCount();
  913. }
  914. }else {
  915. count = scene.getViewCount();
  916. }
  917. redisUtil.set(key, String.valueOf(count));
  918. }
  919. }finally {
  920. redisLockUtil.unlockLua(lockKey);
  921. }
  922. }
  923. redisUtil.incr(key, 1);
  924. return ResultData.ok();
  925. }
  926. @Override
  927. public void updatePv(){
  928. Boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_SCENE_VISIT_UPDATE, RedisKey.EXPIRE_TIME_2_HOUR);
  929. if(!lock){
  930. return;
  931. }
  932. try {
  933. Map<String, Integer> pvMap = redisUtil.hmget(RedisKey.SCENE_VISIT_CNT);
  934. if(CollUtil.isEmpty(pvMap)){
  935. return;
  936. }
  937. for (Map.Entry<String, Integer> entry : pvMap.entrySet()) {
  938. Scene scene = this.getSceneBySceneCode(entry.getKey());
  939. if (Objects.nonNull(scene)){
  940. scene.setViewCount(entry.getValue());
  941. scene.setUpdateTime(Calendar.getInstance().getTime());
  942. this.updateById(scene);
  943. continue;
  944. }
  945. ScenePro scenePro = sceneProMapper.findByNum(entry.getKey());
  946. if(scenePro != null){
  947. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  948. sceneProExt.setViewCount(entry.getValue());
  949. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  950. sceneProExtService.updateById(sceneProExt);
  951. }
  952. }
  953. }finally {
  954. redisLockUtil.unlockLua(RedisLockKey.LOCK_SCENE_VISIT_UPDATE);
  955. }
  956. }
  957. @Override
  958. public Page search(@RequestBody SceneParamVO param) {
  959. param.setOrderBy("view_count desc");
  960. Page<ScenePO> scenePOPage = this.unionSearchBySceneName(param);
  961. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  962. return scenePOPage;
  963. }
  964. List<SceneVO> voList = this.convert(scenePOPage.getRecords());
  965. for (SceneVO vo : voList){
  966. if (vo.getUserId() != null){
  967. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  968. String nickName = nickNameResult.getData().getNickName();
  969. vo.setNickName(nickName);
  970. }
  971. }
  972. Page<SceneVO> result= new Page<>(param.getPageNum(), param.getPageSize());
  973. result.setTotal(scenePOPage.getTotal());
  974. result.setRecords(voList);
  975. return result;
  976. }
  977. @Override
  978. public Page loadScene(SceneParamVO param){
  979. String orderBy = null;
  980. if (StringUtils.isEmpty(param.getSceneInterest()) || "1".equals(param.getSceneInterest())){
  981. orderBy = " recommend desc, create_time ";
  982. }else if ("2".equals(param.getSceneInterest())){
  983. orderBy = " create_time desc ";
  984. }else if ("3".equals(param.getSceneInterest())){
  985. orderBy = " view_count desc ";
  986. }
  987. param.setOrderBy(orderBy);
  988. Page<SceneProPO> page = this.findAllScene(param);
  989. if(CollUtil.isEmpty(page.getRecords())){
  990. return page;
  991. }
  992. List<SceneVO> voList = this.convertPro(page.getRecords());
  993. for (SceneVO vo : voList){
  994. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  995. vo.setNickName(nickNameResult.getData().getNickName());
  996. }
  997. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  998. result.setTotal(page.getTotal());
  999. result.setRecords(voList);
  1000. return result;
  1001. }
  1002. @Override
  1003. public Page loadAllScene2(SceneParamVO param) {
  1004. param.setOrderBy("create_time desc");
  1005. if(param.getSceneScheme()!= null && param.getSceneScheme() == 4){
  1006. Page<ScenePro> page = new Page<>(param.getPageNum(), param.getPageSize());
  1007. Page<ScenePro> sceneProPage = sceneProService.page(page, new LambdaQueryWrapper<ScenePro>()
  1008. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  1009. .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
  1010. .and(wrapper -> wrapper.or().like(ScenePro::getSceneName, "%" + param.getSceneKey() + "%")
  1011. .or().like(ScenePro::getNum, "%" + param.getSceneKey() + "%")).orderByDesc(ScenePro::getId));
  1012. if(CollUtil.isEmpty(sceneProPage.getRecords())){
  1013. return sceneProPage;
  1014. }
  1015. List<SceneVO> sceneList = sceneProService.convert(sceneProPage.getRecords());
  1016. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  1017. result.setTotal(sceneProPage.getTotal());
  1018. result.setRecords(sceneList);
  1019. return result;
  1020. }
  1021. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  1022. Page<ScenePO> scenePOPage = baseMapper.selectScenePoByCondition(page, param);
  1023. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  1024. return scenePOPage;
  1025. }
  1026. List<SceneVO> sceneList = sceneService.convert(scenePOPage.getRecords());
  1027. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  1028. result.setTotal(scenePOPage.getTotal());
  1029. result.setRecords(sceneList);
  1030. return result;
  1031. }
  1032. @Override
  1033. public ResultData querySceneDataSource(SceneParamVO param){
  1034. log.info("querySceneDataSource:查询模型数据");
  1035. String num = param.getNum();
  1036. if(StrUtil.isEmpty(num))
  1037. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1038. ScenePO scene = sceneService.findBySceneNum(num);
  1039. String data = null;
  1040. if(scene == null) {
  1041. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1042. if(scenePro == null)
  1043. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1044. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1045. data = sceneProExt.getDataSource();
  1046. }else {
  1047. data = scene.getDataSource();
  1048. }
  1049. if(data != null && !"".equals(data) && data.startsWith("http")){
  1050. data = ConstantFilePath.BUILD_MODEL_PATH + data.split("/")[data.split("/").length - 2];
  1051. }
  1052. return ResultData.ok(data);
  1053. }
  1054. @Override
  1055. public ResultData querySceneNum(SceneParamVO param){
  1056. log.info("querySceneDataSource:查询模型数据");
  1057. String path = param.getPath();
  1058. if(path==null&&path.trim().equals(""))
  1059. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1060. path = path.split("/")[path.split("/").length - 1];
  1061. Scene scene = sceneService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
  1062. String sceneNum = null;
  1063. if(scene == null)
  1064. {
  1065. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
  1066. if(scenePro == null)
  1067. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1068. sceneNum = scenePro.getNum();
  1069. }else {
  1070. sceneNum = scene.getNum();
  1071. }
  1072. return ResultData.ok(sceneNum);
  1073. }
  1074. @Override
  1075. public ResultData downLoadZSData(BaseSceneParamVO param) throws Exception {
  1076. String num = param.getNum();
  1077. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1078. if(scenePro == null){
  1079. throw new BusinessException(ServerCode.PARAM_REQUIRED, "num");
  1080. }
  1081. SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
  1082. if(sceneDataDownload == null){
  1083. throw new BusinessException(ErrorCode.FAILURE_CODE_5025);
  1084. }
  1085. return ResultData.ok(BeanUtil.copyProperties(sceneDataDownload, SceneDataDownloadVO.class));
  1086. }
  1087. @Override
  1088. public ResultData getScenes(DeviceSceneParamVO param) {
  1089. QueryWrapper queryWrapper = new QueryWrapper();
  1090. if(param.getCameraType() == null || param.getCameraType() == 0){
  1091. queryWrapper.setEntityClass(Scene.class);
  1092. }else {
  1093. queryWrapper.setEntityClass(ScenePro.class);
  1094. }
  1095. queryWrapper.eq("tb_status",TbStatus.VALID);
  1096. queryWrapper.orderByDesc("create_time");
  1097. if (param.getCameraId() != null) {
  1098. if (StringUtils.isNotEmpty(param.getStartTime()) && StringUtils.isNotEmpty(param.getEndTime())) {
  1099. queryWrapper.between("create_time", com.fdkankan.common.util.DateUtil.convert2CST(Long.parseLong(param.getStartTime())),
  1100. com.fdkankan.common.util.DateUtil.convert2CST(Long.parseLong(param.getEndTime())));
  1101. }
  1102. if(StringUtils.isNotEmpty(param.getSceneType())){
  1103. queryWrapper.eq("scene_type",param.getSceneType());
  1104. }else{
  1105. queryWrapper.ne("scene_type",99);
  1106. }
  1107. queryWrapper.eq("camera_id", param.getCameraId());
  1108. if(StringUtils.isNotEmpty(param.getSearchKey())){
  1109. queryWrapper.like("scene_name", "%" + param.getSearchKey() + "%");
  1110. }
  1111. }
  1112. Page page = new Page(param.getPageNum(), param.getPageSize());
  1113. if(param.getCameraType() == null || param.getCameraType() == 0){
  1114. page = this.page(page, queryWrapper);
  1115. }else {
  1116. page = sceneProService.page(page,queryWrapper);
  1117. }
  1118. return ResultData.ok(page);
  1119. }
  1120. @Override
  1121. public ResultData deleteScene(String sceneNum) throws IOException {
  1122. ScenePO bySceneNum = this.findBySceneNum(sceneNum);
  1123. if(bySceneNum != null){
  1124. UpdateWrapper<Scene> updateWrapper = new UpdateWrapper<>();
  1125. updateWrapper.lambda()
  1126. .eq(Scene::getNum,sceneNum).set(Scene::getTbStatus,TbStatus.DELETE.code());
  1127. sceneService.update(updateWrapper);
  1128. return ResultData.ok();
  1129. }
  1130. UpdateWrapper<ScenePro> updateWrapper = new UpdateWrapper<>();
  1131. updateWrapper.lambda()
  1132. .eq(ScenePro::getNum,sceneNum).set(ScenePro::getTbStatus,TbStatus.DELETE.code());
  1133. sceneProService.update(updateWrapper);
  1134. ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum);
  1135. JSONObject statusJson = new JSONObject();
  1136. //临时将-2改成1,app还没完全更新
  1137. statusJson.put("status", sceneProEntity.getSceneStatus() == -2? 1 : sceneProEntity.getSceneStatus());
  1138. statusJson.put("webSite", sceneProEntity.getWebSite());
  1139. statusJson.put("sceneNum", sceneProEntity.getNum());
  1140. statusJson.put("thumb", sceneProEntity.getThumb());
  1141. statusJson.put("payStatus", sceneProEntity.getPayStatus());
  1142. statusJson.put("recStatus", sceneProEntity.getTbStatus() == 0 ? "A" :"I");
  1143. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  1144. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  1145. "data/data"+sceneNum+File.separator+"status.json");
  1146. return ResultData.ok();
  1147. }
  1148. @Override
  1149. public Long getSceneCount(Long cameraId,Long userId) {
  1150. LambdaQueryWrapper<Scene> queryWrapper = new LambdaQueryWrapper<Scene>()
  1151. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  1152. .notIn(Scene::getSceneType, SceneType.YJHZXNFY.code());
  1153. if(cameraId !=null){
  1154. queryWrapper.eq(Scene::getCameraId ,cameraId);
  1155. }
  1156. if(userId !=null){
  1157. queryWrapper.eq(Scene::getUserId ,userId);
  1158. }
  1159. return this.count(queryWrapper);
  1160. }
  1161. @Override
  1162. public void copyScene(CopySceneParamVO paramVO) throws Exception {
  1163. String num = paramVO.getOldNum();
  1164. String newNum = paramVO.getNewNum();
  1165. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1166. if (ObjectUtils.isEmpty(scenePro)) {
  1167. return;
  1168. }
  1169. // 拷贝场景编辑资源
  1170. String oldEditPath = String.format(UploadFilePath.EDIT_PATH, num);
  1171. String newEditPath = String.format(UploadFilePath.EDIT_PATH, newNum);
  1172. uploadToOssUtil.copyFiles(oldEditPath, newEditPath);
  1173. // 拷贝场景展示资源
  1174. String oldViewPath = String.format(UploadFilePath.VIEW_PATH, num);
  1175. String newViewPath = String.format(UploadFilePath.VIEW_PATH, newNum);
  1176. uploadToOssUtil.copyFiles(oldViewPath, newViewPath);
  1177. // 拷贝本地资源
  1178. String oldPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", num);
  1179. String newPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", newNum);
  1180. if(new File(oldPath).exists()){
  1181. FileUtils.copyDirectiory(oldPath, newPath);
  1182. }
  1183. String scenePath = ConstantFilePath.SCENE_V4_PATH + num;
  1184. File file = new File(scenePath);
  1185. if(file.exists()){
  1186. String newScenePath = ConstantFilePath.SCENE_V4_PATH + newNum;
  1187. FileUtils.copyDirectiory(scenePath, newScenePath);
  1188. }
  1189. // 拷贝数据
  1190. Long proId = scenePro.getId();
  1191. scenePro.setId(paramVO.getNewSceneProId());
  1192. scenePro.setWebSite(scenePro.getWebSite().replace(num, newNum));
  1193. scenePro.setSceneName(paramVO.getNewSceneName());
  1194. scenePro.setThumb(scenePro.getThumb().replace(num, newNum));
  1195. scenePro.setVideos(scenePro.getVideos().replaceAll("https://4dkk.4dage.com/data/data" + num, "https://4dkk.4dage.com/scene_view_data/" + newNum + "/data"));
  1196. scenePro.setNum(newNum);
  1197. sceneProService.saveOrUpdate(scenePro);
  1198. SceneProExt proExt = sceneProExtService.findBySceneProId(proId);
  1199. proExt.setDataSource(paramVO.getDatasource());
  1200. proExt.setId(null);
  1201. proExt.setViewCount(0);
  1202. proExt.setSceneProId(scenePro.getId());
  1203. sceneProExtService.save(proExt);
  1204. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  1205. Long plusId = scenePlus.getId();
  1206. scenePlus.setNum(newNum);
  1207. scenePlus.setId(paramVO.getNewSceneProId());
  1208. scenePlus.setTitle(scenePro.getSceneName());
  1209. scenePlusService.saveOrUpdate(scenePlus);
  1210. ScenePlusExt plusExt = scenePlusExtService.getScenePlusExtByPlusId(plusId);
  1211. plusExt.setId(null);
  1212. plusExt.setPlusId(scenePlus.getId());
  1213. plusExt.setDataSource(paramVO.getDatasource());
  1214. plusExt.setWebSite(plusExt.getWebSite().replace(num, newNum));
  1215. plusExt.setThumb(plusExt.getThumb().replace(num, newNum));
  1216. plusExt.setVideos(scenePro.getVideos());
  1217. scenePlusExtService.save(plusExt);
  1218. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plusId);
  1219. Long sceneEditInfoId = sceneEditInfo.getId();
  1220. sceneEditInfo.setId(null);
  1221. sceneEditInfo.setScenePlusId(scenePlus.getId());
  1222. sceneEditInfo.setSceneProId(scenePro.getId());
  1223. sceneEditInfo.setTitle(paramVO.getNewSceneName());
  1224. sceneEditInfoService.save(sceneEditInfo);
  1225. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoId);
  1226. sceneEditInfoExt.setId(null);
  1227. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  1228. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  1229. sceneEditInfoExt.setSceneProId(scenePro.getId());
  1230. sceneEditInfoExtService.save(sceneEditInfoExt);
  1231. SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfoId);
  1232. sceneEditControls.setId(null);
  1233. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  1234. sceneEditControlsService.save(sceneEditControls);
  1235. List<Surveillance> list = surveillanceService.list(new LambdaQueryWrapper<Surveillance>().eq(Surveillance::getNum, num));
  1236. if (!Objects.isNull(list)) {
  1237. list.stream().forEach(item -> {
  1238. item.setNum(newNum);
  1239. item.setId(null);
  1240. surveillanceService.save(item);
  1241. });
  1242. }
  1243. // 生成scene.json
  1244. SceneJsonBean sceneJson = new SceneJsonBean();
  1245. BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
  1246. BeanUtil.copyProperties(sceneEditInfo, sceneJson);
  1247. SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
  1248. sceneJson.setControls(sceneEditControlsVO);
  1249. sceneJson.setNum(newNum);
  1250. sceneJson.setCreateTime(scenePlus.getCreateTime());
  1251. sceneJson.setSceneResolution(plusExt.getSceneResolution());
  1252. sceneJson.setSceneFrom(plusExt.getSceneFrom());
  1253. sceneJson.setSceneKind(plusExt.getSceneKind());
  1254. if(StrUtil.isNotEmpty(plusExt.getVideos())){
  1255. sceneJson.setVideos(plusExt.getVideos());
  1256. }
  1257. sceneJson.setMosaicList(sceneEditInfoService.getMosaicList(num));
  1258. log.info("开始生成本地json文件……");
  1259. String sceneJsonLocalPath = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + newNum + File.separator + "scene.json";
  1260. FileUtils.writeFile(sceneJsonLocalPath,JSON.toJSONString(sceneJson));
  1261. String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", newNum);
  1262. uploadToOssUtil.upload(JSON.toJSONBytes(sceneJson), sceneJsonPath);
  1263. //删除scenejson缓存
  1264. redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
  1265. // 生成二维码
  1266. String sceneUrl = mainUrl + "/" + sceneProNewUrl;
  1267. String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + ".png";
  1268. String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + "_en.png";
  1269. MatrixToImageWriterUtil.createQRCode(sceneUrl + newNum, outPathZh, false,null);
  1270. MatrixToImageWriterUtil.createQRCode(sceneUrl + newNum + "&lang=en", outPathEn, false, null);
  1271. uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + ".png");
  1272. uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + "_en.png");
  1273. }
  1274. }