SceneServiceImpl.java 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  9. import com.baomidou.mybatisplus.core.metadata.IPage;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.common.constant.*;
  13. import com.fdkankan.common.exception.BusinessException;
  14. import com.fdkankan.common.response.ResultData;
  15. import com.fdkankan.common.util.ConvertUtils;
  16. import com.fdkankan.common.util.DateExtUtil;
  17. import com.fdkankan.common.util.FileUtils;
  18. import com.fdkankan.fyun.oss.UploadToOssUtil;
  19. import com.fdkankan.fyun.qiniu.QiniuUpload;
  20. import com.fdkankan.platform.api.feign.PlatformUserClient;
  21. import com.fdkankan.platform.api.vo.User;
  22. import com.fdkankan.redis.constant.RedisKey;
  23. import com.fdkankan.redis.constant.RedisLockKey;
  24. import com.fdkankan.redis.util.RedisLockUtil;
  25. import com.fdkankan.redis.util.RedisUtil;
  26. import com.fdkankan.scene.entity.*;
  27. import com.fdkankan.scene.mapper.ISceneMapper;
  28. import com.fdkankan.scene.mapper.ISceneProMapper;
  29. import com.fdkankan.scene.service.ISceneExtService;
  30. import com.fdkankan.scene.service.ISceneProExtService;
  31. import com.fdkankan.scene.service.ISceneProService;
  32. import com.fdkankan.scene.service.ISceneService;
  33. import com.fdkankan.scene.vo.SceneEditParamVO;
  34. import com.fdkankan.scene.vo.SceneParamVO;
  35. import com.fdkankan.scene.vo.SceneVO;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang3.StringUtils;
  38. import org.joda.time.DateTime;
  39. import org.springframework.beans.BeanUtils;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.beans.factory.annotation.Qualifier;
  42. import org.springframework.beans.factory.annotation.Value;
  43. import org.springframework.stereotype.Service;
  44. import org.springframework.web.bind.annotation.RequestBody;
  45. import org.springframework.web.multipart.MultipartFile;
  46. import javax.annotation.Resource;
  47. import java.io.File;
  48. import java.io.IOException;
  49. import java.util.*;
  50. import java.util.stream.Collectors;
  51. /**
  52. * <p>
  53. * 场景表 服务实现类
  54. * </p>
  55. *
  56. * @author dengsixing
  57. * @since 2021-12-23
  58. */
  59. @Slf4j
  60. @Service
  61. public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implements ISceneService {
  62. @Value("${upload.type}")
  63. private String type;
  64. @Value("${oss.prefix.ali}")
  65. private String prefixAli;
  66. @Resource
  67. ISceneProMapper sceneProMapper;
  68. @Autowired
  69. ISceneProService sceneProService;
  70. @Autowired
  71. ISceneExtService sceneExtService;
  72. @Autowired
  73. @Qualifier("uploadToOssUtil")
  74. UploadToOssUtil uploadToOssUtil;
  75. @Autowired
  76. RedisUtil redisUtil;
  77. @Autowired
  78. RedisLockUtil redisLockUtil;
  79. @Autowired
  80. ISceneProExtService sceneProExtService;
  81. @Autowired
  82. PlatformUserClient platformUserClient;
  83. @Autowired
  84. ISceneService sceneService;
  85. @Override
  86. public void updateUserIdByCameraId(Long userId, Long cameraId) {
  87. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getCameraId, cameraId).set(Scene::getUserId, userId));
  88. }
  89. @Override
  90. // @SystemServiceLog(description = "上传场景的热点媒体文件")
  91. public void uploadHotMedia(String sceneNum, MultipartFile file) throws IOException {
  92. if(StrUtil.isEmpty(sceneNum)){
  93. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  94. }
  95. ScenePO scene = findBySceneNum(sceneNum);
  96. if(scene == null){
  97. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  98. }
  99. if (!file.isEmpty()){
  100. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum() + "hot";
  101. File targetFile = new File(path);
  102. if (!targetFile.exists()){
  103. targetFile.mkdirs();
  104. }
  105. String fileName = file.getOriginalFilename();
  106. targetFile = new File(path + File.separator + fileName);
  107. if (targetFile.exists()){
  108. FileUtils.deleteFile(path + File.separator + fileName);
  109. }
  110. file.transferTo(targetFile);
  111. }
  112. }
  113. @Override
  114. // @SystemServiceLog(description = "上传场景的导览图片")
  115. public void uploadGuidePic(String sceneId, MultipartFile file) throws IOException {
  116. Scene scene = this.getValidById(Long.valueOf(sceneId));
  117. if (scene != null && !file.isEmpty()){
  118. String path = ConstantFilePath.SCENE_PATH + "images" + File.separator + "images" + scene.getNum()
  119. + File.separator + ConstantFileName.GUIDE_MEDIA_FOLDER;
  120. File targetFile = new File(path);
  121. if (!targetFile.exists()){
  122. targetFile.mkdirs();
  123. }
  124. String fileName = file.getOriginalFilename();
  125. targetFile = new File(path + File.separator + fileName);
  126. int count = 1;
  127. while (targetFile.exists()){
  128. targetFile = new File(path + File.separator + fileName.substring(0, fileName.lastIndexOf("."))+"("+count+")"+fileName.substring(fileName.lastIndexOf(".")));
  129. ++count;
  130. }
  131. file.transferTo(targetFile);
  132. }
  133. }
  134. @Override
  135. // @SystemServiceLog(description = "保存热点的导览信息")
  136. public ResultData saveGuideInfo(SceneParamVO base) throws Exception {
  137. ResultData result = null;
  138. Scene scene = getValidById(base.getSceneId());
  139. if (scene != null){
  140. String path = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum()
  141. + File.separator + ConstantFileName.GUIDE_DATAFILE;
  142. File file = new File(path);
  143. String guideData = null;
  144. if(file.exists()) {
  145. guideData = FileUtils.readFile(path);
  146. }
  147. if (StrUtil.isEmpty(guideData)){
  148. result = ResultData.error(ErrorCode.FAILURE_CODE_5001);
  149. }else{
  150. JSONObject guideJo = JSONObject.parseObject(guideData);
  151. if ("1".equals(base.getType())) {
  152. if (StrUtil.isEmpty(base.getOrder())) {
  153. result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
  154. }else{
  155. if(!StrUtil.isEmpty(base.getItem())) {
  156. JSONObject jo = new JSONObject();
  157. JSONArray jy = guideJo.getJSONArray("images");
  158. jy.add(JSONObject.parse(base.getItem()));
  159. }
  160. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  161. }
  162. } else if ("2".equals(base.getType())) {
  163. if (StrUtil.isEmpty(base.getOrder()) || StrUtil.isEmpty(base.getGuideSid())) {
  164. result = ResultData.error(ErrorCode.FAILURE_CODE_5003);
  165. }else{
  166. JSONArray jy = guideJo.getJSONArray("images");
  167. for (int i = 0; i < jy.size(); ++i) {
  168. JSONObject itemData = jy.getJSONObject(i);
  169. if (itemData.getString("sid").equals(base.getGuideSid())) {
  170. jy.remove(i);
  171. break;
  172. }
  173. }
  174. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  175. }
  176. } else if ("3".equals(base.getType())) {
  177. if (StrUtil.isEmpty(base.getOrder())) {
  178. result = ResultData.error(ErrorCode.FAILURE_CODE_5002);
  179. } else {
  180. guideJo.put("imagesOrder", JSONArray.parse(base.getOrder()));
  181. }
  182. } else if ("4".equals(base.getType())) {
  183. if (StrUtil.isEmpty(base.getGuideName()) || StrUtil.isEmpty(base.getGuideSid())) {
  184. result = ResultData.error(ErrorCode.FAILURE_CODE_5004);
  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. itemData.put("name", base.getGuideName());
  191. break;
  192. }
  193. }
  194. }
  195. }
  196. FileUtils.deleteFile(path);
  197. FileUtils.writeFileContent(path, guideJo.toString());
  198. result = ResultData.ok();
  199. }
  200. }else{
  201. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  202. }
  203. return result;
  204. }
  205. @Override
  206. // @SystemServiceLog(description = "恢复场景的户型图")
  207. public ResultData recoveryFloor(SceneParamVO base) throws Exception {
  208. ResultData result = null;
  209. Scene scene = this.getValidById(base.getSceneId());
  210. if (scene != null) {
  211. String unicode = scene.getDataSource();
  212. if (StrUtil.isNotEmpty(unicode)) {
  213. unicode = unicode.substring(0, unicode.lastIndexOf("/"));
  214. unicode = unicode.replace(ConstantUrl.DEFAULT_PREFIX_QINIU_PIC, "");
  215. String path = ConstantFilePath.BUILD_MODEL_PATH + unicode + File.separator + "tex" + File.separator + "floor.json";
  216. FileUtils.copyFile(path, ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + scene.getNum() + File.separator + "floor.json", true);
  217. }
  218. result = ResultData.ok();
  219. } else {
  220. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  221. }
  222. return result;
  223. }
  224. @Override
  225. // @SystemServiceLog(description = "保存场景编辑信息")
  226. public ResultData saveEditInfo(SceneParamVO base) throws Exception {
  227. ResultData result = ResultData.ok();
  228. Scene scene = this.getValidById(base.getSceneId());
  229. if (scene != null) {
  230. JSONObject json = new JSONObject();
  231. json.put("sceneName", base.getSceneName());
  232. json.put("sceneDec", base.getSceneDec());
  233. json.put("sceneType", base.getSceneType());
  234. json.put("scenePsd", base.getSceneKey());
  235. json.put("version", base.getVersion());
  236. json.put("thumbImg", base.getThumbImg());
  237. json.put("currentPanoId", base.getCurrentPanoId());
  238. json.put("floorLogo", base.getFloorLogo());
  239. json.put("floorLogoSize", base.getFloorLogoSize());
  240. json.put("entry", base.getEntry());
  241. json.put("index", base.getIndex());
  242. json.put("sceneIndex", base.getSceneIndex());
  243. JSONObject json2 = new JSONObject();
  244. json2.put("geoData", base.getGeoData());
  245. json2.put("center", base.getCenter());
  246. json2.put("zoom", base.getZoom());
  247. json2.put("realScale", base.getRealScale());
  248. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
  249. .append("images").append(File.separator)
  250. .append("images").append(base.getIndex());
  251. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH)
  252. .append("data").append(File.separator)
  253. .append("data").append(base.getIndex());
  254. File imagesFile = new File(imagesBuffer.toString());
  255. if(!imagesFile.exists() || !imagesFile.isDirectory()) {
  256. imagesFile.mkdirs();
  257. }
  258. File dataFile = new File(dataBuffer.toString());
  259. if(!dataFile.exists() || !dataFile.isDirectory()) {
  260. dataFile.mkdirs();
  261. }
  262. if (StrUtil.isNotEmpty(base.getThumbFishBigImg()) && !"undefined".equals(base.getThumbFishBigImg())){
  263. StringBuffer sb = new StringBuffer(imagesBuffer);
  264. String thumbFishBigImgPath = sb.append(File.separator).append("thumbFishBigImg.jpg").toString();
  265. FileUtils.deleteFile(thumbFishBigImgPath);
  266. FileUtils.uploadImg(thumbFishBigImgPath, base.getThumbFishBigImg());
  267. }
  268. if (StrUtil.isNotEmpty(base.getThumbBigImg()) && !"undefined".equals(base.getThumbBigImg())) {
  269. StringBuffer sb = new StringBuffer(imagesBuffer);
  270. String thumbBigImgPath = sb.append(File.separator).append("thumbBigImg.jpg").toString();
  271. FileUtils.deleteFile(thumbBigImgPath);
  272. FileUtils.uploadImg(thumbBigImgPath, base.getThumbBigImg());
  273. }
  274. if (StrUtil.isNotEmpty(base.getThumbSmallImg()) && !"undefined".equals(base.getThumbSmallImg())) {
  275. StringBuffer sb = new StringBuffer(imagesBuffer);
  276. String thumbSmallImgPath = sb.append(File.separator).append("thumbSmallImg.jpg").toString();
  277. FileUtils.deleteFile(thumbSmallImgPath);
  278. FileUtils.uploadImg(thumbSmallImgPath, base.getThumbSmallImg());
  279. }
  280. if (StrUtil.isNotEmpty(base.getFloorLogoImg()) && !"undefined".equals(base.getFloorLogoImg())) {
  281. StringBuffer sb = new StringBuffer(imagesBuffer);
  282. String floorLogoImgPath = sb.append(File.separator).append("floorLogoImg.png").toString();
  283. FileUtils.deleteFile(floorLogoImgPath);
  284. FileUtils.uploadImg(floorLogoImgPath, base.getFloorLogoImg());
  285. }
  286. if (StrUtil.isNotEmpty(base.getImgData()) && !"undefined".equals(base.getImgData())) {
  287. StringBuffer sb = new StringBuffer(imagesBuffer);
  288. String floorPlanPath = sb.append(File.separator).append("floorplan.png").toString();
  289. FileUtils.deleteFile(floorPlanPath);
  290. FileUtils.uploadImg(floorPlanPath, base.getImgData());
  291. if (base.getFloorPlaneInfo() != null) {
  292. String floorPath = dataBuffer.append(File.separator).append("floor.json").toString();
  293. FileUtils.deleteFile(floorPath);
  294. JSONObject info = JSONObject.parseObject(base.getFloorPlaneInfo());
  295. if (info.containsKey("height")) {
  296. json2.put("height", info.getString("height"));
  297. }
  298. if (info.containsKey("width")) {
  299. json2.put("width", info.getString("width"));
  300. }
  301. if (info.containsKey("position")) {
  302. json2.put("position", info.getJSONObject("position"));
  303. }
  304. FileUtils.writeFileContent(floorPath, json2.toString());
  305. }
  306. }
  307. String floorFilepath = imagesBuffer.append(File.separator).append("scene.json").toString();
  308. FileUtils.writeFileContent(floorFilepath, json.toString());
  309. } else {
  310. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  311. }
  312. return result;
  313. }
  314. @Override
  315. // @SystemServiceLog(description = "发布场景")
  316. public ResultData publishScene(SceneParamVO base) throws Exception {
  317. ResultData result = ResultData.ok();
  318. Scene scene = this.getValidById(base.getSceneId());
  319. if (scene != null) {
  320. SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
  321. StringBuffer dataBuf = new StringBuffer()
  322. .append("data").append(File.separator)
  323. .append("data").append(scene.getNum())
  324. .append(File.separator);
  325. StringBuffer imagesBuf = new StringBuffer()
  326. .append("images").append(File.separator)
  327. .append("images").append(scene.getNum())
  328. .append(File.separator);
  329. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  330. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  331. String str = FileUtils.readFile(dataBuffer.append("scene.json").toString());
  332. JSONObject json = JSONObject.parseObject(str);
  333. String sceneIndex = json.getString("sceneIndex") == null ? "0" : json.getString("sceneIndex");
  334. String index = json.getString("index");
  335. if(json.containsKey("entry")) {
  336. String entry = json.getString("entry");
  337. sceneExt.setEntry(entry);
  338. }
  339. String sceneType = json.getString("sceneType");
  340. int type = sceneType != null ? Integer.valueOf(sceneType) : 0;
  341. scene.setNum(index);
  342. scene.setSceneName(json.getString("sceneName"));
  343. scene.setSceneDec(json.getString("sceneDec"));
  344. scene.setSceneType(type);
  345. scene.setSceneKey(json.getString("scenePsd"));
  346. scene.setVersion(json.getInteger("version")+1);
  347. scene.setThumbStatus(json.getInteger("thumbImg"));
  348. scene.setFloorLogo(json.getString("floorLogo"));
  349. scene.setFloorLogoSize(json.getInteger("floorLogoSize"));
  350. sceneExt.setStyle(Integer.valueOf(sceneIndex));
  351. if (scene.getThumbStatus() == 1) {
  352. scene.setThumb(ConstantUrl.PREFIX_QINIU + imagesBuf.append("thumbSmallImg.jpg").toString());
  353. } else {
  354. scene.setThumb(ConstantUrl.PREFIX_QINIU + "loading/pc.jpg");
  355. }
  356. //上传文件到七牛云
  357. QiniuUpload.setFilesToBucket(imagesBuf.toString(), imagesBuffer.toString());
  358. QiniuUpload.setFilesToBucket(dataBuf.toString(), dataBuffer.toString());
  359. scene.setUpdateTime(Calendar.getInstance().getTime());
  360. this.updateById(scene);
  361. sceneExt.setUpdateTime(Calendar.getInstance().getTime());
  362. sceneExtService.updateById(sceneExt);
  363. } else {
  364. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  365. }
  366. return result;
  367. }
  368. @Override
  369. // @SystemServiceLog(description = "删除场景热点")
  370. public ResultData deleteHot(SceneParamVO base) throws Exception {
  371. ResultData result = ResultData.ok();
  372. Scene scene = getValidById(base.getSceneId());
  373. if (scene != null && StrUtil.isNotEmpty(base.getIndex())) {
  374. SceneExt sceneExt = sceneExtService.getBySceneId(scene.getId());
  375. StringBuffer dataBuf = new StringBuffer()
  376. .append("data").append(File.separator)
  377. .append("data").append(scene.getNum())
  378. .append(File.separator);
  379. StringBuffer imagesBuf = new StringBuffer()
  380. .append("images").append(File.separator)
  381. .append("images").append(scene.getNum())
  382. .append(File.separator);
  383. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  384. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString()).append("hot.json");
  385. String str = FileUtils.readFile(dataBuffer.toString());
  386. JSONArray jsonhots = null;
  387. if (StrUtil.isNotEmpty(str)){
  388. jsonhots = JSONArray.parseArray(str);
  389. for (int i = 0; i < jsonhots.size(); ++i) {
  390. JSONObject ele = jsonhots.getJSONObject(i);
  391. if (ele.getString("sid").equals(base.getIndex())) {
  392. jsonhots.remove(i);
  393. break;
  394. }
  395. }
  396. }
  397. String sPath = null;
  398. File file = new File(imagesBuffer.toString());
  399. if (file.isDirectory()){
  400. String[] strs = file.list();
  401. if (strs != null) {
  402. for (int i = 0; i < strs.length; ++i) {
  403. if (strs[i].contains("hot" + base.getIndex())) {
  404. sPath = imagesBuffer.toString() + strs[i];
  405. break;
  406. }
  407. }
  408. }
  409. }
  410. if (sPath != null){
  411. FileUtils.deleteFile(sPath);
  412. }
  413. FileUtils.deleteFile(dataBuffer.toString());
  414. if (jsonhots != null){
  415. FileUtils.writeFileContent(dataBuffer.toString(), jsonhots.toString());
  416. }
  417. String hotsIds = sceneExt.getHotsIds();
  418. if (StrUtil.isNotEmpty(hotsIds)) {
  419. String updateHotsIds = "";
  420. String[] sids = hotsIds.split(",");
  421. boolean flag = false;
  422. for (int i = 0; i < sids.length; ++i) {
  423. String s = sids[i];
  424. if (s.equals(base.getIndex())) {
  425. flag = true;
  426. } else {
  427. updateHotsIds += s + ",";
  428. }
  429. }
  430. if (!flag) {
  431. scene.setVersion(scene.getVersion() + 1);
  432. scene.setUpdateTime(Calendar.getInstance().getTime());
  433. this.updateById(scene);
  434. sceneExt.setHotsIds(updateHotsIds);
  435. sceneExt.setUpdateTime(Calendar.getInstance().getTime());
  436. sceneExtService.updateById(sceneExt);
  437. }
  438. }
  439. } else {
  440. result = ResultData.error(ErrorCode.FAILURE_CODE_5005);
  441. }
  442. return result;
  443. }
  444. @Override
  445. // @SystemServiceLog(description = "保存场景热点")
  446. public ResultData saveHot(SceneEditParamVO base) throws Exception {
  447. if(StrUtil.isEmpty(base.getHotData()) || StrUtil.isEmpty(base.getType())){
  448. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  449. }
  450. String sid = base.getSid();
  451. ScenePO scene = findBySceneNum(base.getNum());
  452. if (scene == null ) {
  453. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  454. }
  455. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  456. StringBuffer dataBuf = new StringBuffer()
  457. .append("data").append(File.separator)
  458. .append("data").append(scene.getNum())
  459. .append(File.separator);
  460. StringBuffer imagesBuf = new StringBuffer()
  461. .append("images").append(File.separator)
  462. .append("images").append(scene.getNum())
  463. .append(File.separator);
  464. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  465. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  466. String str = FileUtils.readFile(dataBuffer.append("hot.json").toString());
  467. JSONArray jsonhots = null;
  468. if (StrUtil.isNotEmpty(str)) {
  469. jsonhots = JSONArray.parseArray(str);
  470. }else {
  471. File file = new File(dataBuffer.append("hot.json").toString());
  472. if(!file.getParentFile().exists()){
  473. file.getParentFile().mkdirs();
  474. }
  475. if(!file.exists()){
  476. file.createNewFile();
  477. }
  478. }
  479. //添加或者修改
  480. if("1".equals(base.getType())){
  481. sid = jsonhot.getString("sid");
  482. if(StrUtil.isEmpty(sid)){
  483. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  484. }
  485. jsonhots.add(jsonhot);
  486. }
  487. else if("0".equals(base.getType())){
  488. sid = jsonhot.getString("sid");
  489. if(StrUtil.isEmpty(sid)){
  490. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  491. }
  492. }
  493. else if("-1".equals(base.getType())){
  494. if(StrUtil.isEmpty(sid)){
  495. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  496. }
  497. }
  498. for(int i=0;i<jsonhots.size();++i){
  499. JSONObject ele = jsonhots.getJSONObject(i);
  500. if(ele.getString("sid").equals(sid)){
  501. if("-1".equals(base.getType())){
  502. jsonhots.remove(i);
  503. if(ele.containsKey("media")){
  504. String fileType = ele.getString("media");
  505. if(fileType.contains("photo"))
  506. {
  507. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".jpg").toString());
  508. }
  509. if(fileType.contains("audio"))
  510. {
  511. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp3").toString());
  512. }
  513. if(fileType.contains("video"))
  514. {
  515. FileUtils.deleteFile(imagesBuffer.append("hot").append(sid).append(".mp4").toString());
  516. }
  517. }
  518. }
  519. else if("0".equals(base.getType())){
  520. jsonhots.set(i, jsonhot);
  521. }
  522. break;
  523. }
  524. }
  525. FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
  526. File dataPath = new File(dataBuffer.toString());
  527. if(!dataPath.exists()){
  528. dataPath.mkdirs();
  529. }
  530. FileUtils.writeFile(dataBuffer.append("hot.json").toString(), jsonhots.toString());
  531. String strsceneInfos = FileUtils.readFile(dataBuffer.append("scene.json").toString());
  532. JSONObject scenejson = new JSONObject();
  533. if(strsceneInfos!=null){
  534. scenejson = JSONObject.parseObject(strsceneInfos);
  535. }
  536. if(jsonhots.size()>0){
  537. scenejson.put("hots", 1);
  538. }
  539. else{
  540. scenejson.put("hots", 0);
  541. }
  542. FileUtils.writeFile(dataBuffer.append("scene.json").toString(), scenejson.toString());
  543. return ResultData.ok();
  544. }
  545. @Override
  546. // @SystemServiceLog(description = "漫游可行")
  547. public ResultData saveLinkPano(SceneEditParamVO base) throws Exception {
  548. if(StrUtil.isEmpty(base.getData()) || StrUtil.isEmpty(base.getNum())){
  549. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  550. }
  551. ScenePO scene = baseMapper.findByNum(base.getNum());
  552. if (scene == null ) {
  553. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  554. }
  555. JSONArray inputData = JSONObject.parseArray(base.getData());
  556. StringBuffer dataBuf = new StringBuffer()
  557. .append("data").append(File.separator)
  558. .append("data").append(scene.getNum())
  559. .append(File.separator);
  560. StringBuffer imagesBuf = new StringBuffer()
  561. .append("images").append(File.separator)
  562. .append("images").append(scene.getNum())
  563. .append(File.separator);
  564. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  565. File directory = new File(dataBuffer.toString());
  566. if (!directory.exists()) {
  567. directory.mkdirs();
  568. }
  569. JSONArray inputdata = JSONArray.parseArray(base.getData());
  570. String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  571. if("aws".equals(type)){
  572. modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  573. }
  574. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  575. File file = new File(dataBuffer.append("vision.modeldata").toString());
  576. if(file.exists()) {
  577. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  578. }
  579. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.append("vision.modeldata").toString(), dataBuffer.append("vision.json").toString());
  580. String str = FileUtils.readFile(dataBuffer.append("vision.json").toString());
  581. JSONObject json = JSONObject.parseObject(str);
  582. JSONArray panos = json.getJSONArray("sweepLocations");
  583. for (int i = 0; i < panos.size(); ++i) {
  584. JSONObject pano = panos.getJSONObject(i);
  585. for (int j = 0; j < inputData.size(); ++j) {
  586. JSONObject jo = inputData.getJSONObject(j);
  587. String currentPanoId = jo.getString("panoID");
  588. JSONArray visibles = jo.getJSONArray("visibles");
  589. JSONArray visibles3 = jo.getJSONArray("visibles3");
  590. if (pano.getString("uuid").equals(currentPanoId)) {
  591. pano.put("visibles", visibles);
  592. pano.put("visibles3", visibles3);
  593. }
  594. }
  595. }
  596. FileUtils.deleteFile(dataBuffer.append("vision.json").toString());
  597. FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
  598. FileUtils.writeFileContent(dataBuffer.toString() + "vision.json", json.toString());
  599. ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
  600. uploadToOssUtil.upload(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
  601. return ResultData.ok();
  602. }
  603. @Override
  604. // @SystemServiceLog(description = "保存热点可见性的数据")
  605. public ResultData saveHotVisible(SceneEditParamVO base) throws Exception {
  606. if(StrUtil.isEmpty(base.getData())){
  607. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  608. }
  609. // ScenePO scene = findBySceneNum(base.getNum());
  610. Scene scene = this.getSceneBySceneCode(base.getNum());
  611. if (scene == null ) {
  612. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  613. }
  614. JSONArray visiblePanos = JSONArray.parseArray(base.getData());
  615. StringBuffer dataBuf = new StringBuffer()
  616. .append("data").append(File.separator)
  617. .append("data").append(scene.getNum())
  618. .append(File.separator);
  619. StringBuffer imagesBuf = new StringBuffer()
  620. .append("images").append(File.separator)
  621. .append("images").append(scene.getNum())
  622. .append(File.separator);
  623. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  624. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  625. File file = new File(dataBuffer.toString() + "hot.json");
  626. if (!file.exists()) {
  627. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  628. }
  629. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  630. JSONArray hots = JSONArray.parseArray(str);
  631. for (int i = 0; i < hots.size(); ++i) {
  632. JSONObject hot = hots.getJSONObject(i);
  633. for (int j = 0; j < visiblePanos.size(); ++j) {
  634. if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
  635. hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
  636. }
  637. }
  638. }
  639. scene.setVersion(scene.getVersion() + 1);
  640. scene.setUpdateTime(Calendar.getInstance().getTime());
  641. this.updateById(scene);
  642. FileUtils.deleteFile(dataBuffer.append("hot.json").toString());
  643. FileUtils.writeFileContent(dataBuffer.append("hot.json").toString(), hots.toString());
  644. return ResultData.ok();
  645. }
  646. @Override
  647. public IPage<SceneVO> queryByParam(SceneParamVO param) {
  648. int pageNum = param.getPageNum();
  649. int pageSize = param.getPageSize();
  650. Page<SceneVO> page = new Page<>(pageNum, pageSize);
  651. if(StrUtil.isEmpty(param.getUserIds())){
  652. param.setUserIds("0");
  653. }
  654. if(StrUtil.isEmpty(param.getCameraIds())){
  655. param.setCameraIds("0");
  656. }
  657. List<SceneVO> list = baseMapper.queryByParam(page, param);
  658. page.setRecords(list);
  659. return page;
  660. }
  661. @Override
  662. public IPage<SceneVO> queryByParamNew(SceneParamVO param) {
  663. int pageNum = param.getPageNum();
  664. int pageSize = param.getPageSize();
  665. Page<SceneVO> page = new Page<>(pageNum, pageSize);
  666. if(StrUtil.isEmpty(param.getUserIds())){
  667. param.setUserIds("0");
  668. }
  669. if(StrUtil.isEmpty(param.getCameraIds())){
  670. param.setCameraIds("0");
  671. }
  672. List<SceneVO> list = baseMapper.queryByParamNew(page, param);
  673. page.setRecords(list);
  674. return page;
  675. }
  676. // @Override
  677. // public List<SceneVO> findSceneProBySnCode(SceneParamVO param) {
  678. // return sceneMapper.findSceneProBySnCode(param);
  679. // }
  680. @Override
  681. public Scene getValidById(long id) {
  682. return this.getOne(new LambdaQueryWrapper<Scene>()
  683. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  684. .eq(Scene::getId, id));
  685. }
  686. @Override
  687. public List<SceneVO> convert(List<ScenePO> list) {
  688. List<SceneVO> sceneVOs = list.stream().map(po -> {
  689. SceneVO sceneVO = new SceneVO();
  690. BeanUtils.copyProperties(po, sceneVO);
  691. if (po.getCreateTime() != null) {
  692. sceneVO.setCreateTime(DateUtil.format(po.getCreateTime(), DateExtUtil.dateStyle4));
  693. sceneVO.setCreateDate(po.getCreateTime().getTime());
  694. }
  695. return sceneVO;
  696. }).collect(Collectors.toList());
  697. return sceneVOs;
  698. }
  699. @Override
  700. public List<SceneVO> convertPro(List<SceneProPO> list) {
  701. List<SceneVO> sceneVOs = list.stream().map(po -> {
  702. SceneVO sceneVO = new SceneVO();
  703. BeanUtils.copyProperties(po, sceneVO);
  704. if (po.getCreateTime() != null) {
  705. sceneVO.setCreateTime(new DateTime(po.getCreateTime()).toString("yyyy-MM-dd"));
  706. if ("aws".equals(this.type)) {
  707. sceneVO.setCreateTime(new DateTime(DateExtUtil.hoursCalculate(po.getCreateTime(), 8)).toString("yyyy-MM-dd"));
  708. }
  709. sceneVO.setCreateDate(po.getCreateTime().getTime());
  710. }
  711. sceneVO.setIsFolder(0);
  712. sceneVO.setStatus(po.getSceneStatus());
  713. return sceneVO;
  714. }).collect(Collectors.toList());
  715. return sceneVOs;
  716. }
  717. @Override
  718. public List<ScenePO> findAllByYesterday() throws Exception {
  719. return baseMapper.findAllByYesterday();
  720. }
  721. @Override
  722. public ScenePO findBySceneNum(String sceneNum) {
  723. return baseMapper.findByNum(sceneNum);
  724. }
  725. @Override
  726. public Scene getSceneBySceneCode(String sceneCode) {
  727. List<Scene> list = this.list(new LambdaQueryWrapper<Scene>()
  728. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  729. .eq(Scene::getNum, sceneCode));
  730. if(CollUtil.isEmpty(list)){
  731. return null;
  732. }
  733. return list.get(0);
  734. }
  735. @Override
  736. public ResultData recover(String sceneNum) throws Exception {
  737. ScenePO scene = baseMapper.findByNum(sceneNum);
  738. if (scene == null){
  739. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  740. }
  741. scene.setPayStatus(1);
  742. this.update(new LambdaUpdateWrapper<Scene>()
  743. .eq(Scene::getId, scene.getId())
  744. .set(Scene::getPayStatus, PayStatus.PAY.code()));
  745. SceneVO SceneVO = new SceneVO();
  746. BeanUtils.copyProperties(scene, SceneVO);
  747. return ResultData.ok(SceneVO);
  748. }
  749. // public int getSceneCount(Long cameraId) {
  750. // return sceneMapper.getSceneCount(cameraId);
  751. // }
  752. @Override
  753. public Scene getSceneStatusByUnicode(String unicode, int tbStatus) {
  754. return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getTbStatus, tbStatus).like(Scene::getDataSource, "%"+unicode+"%"));
  755. }
  756. public void updateStatus(String sceneNum, int status) {
  757. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getSceneStatus, status));
  758. }
  759. @Override
  760. public void updateTime(String sceneNum, Long space, int payStatus) {
  761. List<Scene> sceneList = this.list(new LambdaQueryWrapper<Scene>()
  762. .select(Scene::getId)
  763. .eq(Scene::getNum, sceneNum));
  764. if(CollUtil.isEmpty(sceneList))
  765. return ;
  766. List<Long> sceneIds = sceneList.stream().map(scene -> {
  767. return scene.getId();
  768. }).collect(Collectors.toList());
  769. this.update(new LambdaUpdateWrapper<Scene>()
  770. .in(Scene::getId, sceneIds)
  771. .set(Scene::getCreateTime, Calendar.getInstance().getTime())
  772. .set(Scene::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
  773. sceneExtService.update(new LambdaUpdateWrapper<SceneExt>().in(SceneExt::getSceneId, sceneIds).set(SceneExt::getSpace, space));
  774. }
  775. @Override
  776. public ResultData addHotMediaInfo(SceneEditParamVO base) throws Exception{
  777. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getType()) ||
  778. StrUtil.isEmpty(base.getInfo())){
  779. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  780. }
  781. ScenePO scene = findBySceneNum(base.getNum());
  782. if(scene == null){
  783. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  784. }
  785. StringBuffer dataBuf = new StringBuffer()
  786. .append("data").append(File.separator)
  787. .append("data").append(scene.getNum())
  788. .append(File.separator);
  789. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  790. String infoData = FileUtils.readFile(dataBuffer.append("mediaInfo.json").toString());
  791. JSONArray medias = null;
  792. if(infoData != null){
  793. medias= JSONArray.parseArray(infoData);
  794. }
  795. if("1".equals(base.getType())){
  796. JSONObject jo = JSONObject.parseObject(base.getInfo());
  797. medias.add(jo);
  798. }else if("1".equals(base.getType())){
  799. for(int i=0;i<medias.size();++i){
  800. JSONObject ob = medias.getJSONObject(i);
  801. if(ob.getString("file").equals(base.getName())){
  802. medias.remove(i);
  803. break;
  804. }
  805. }
  806. }else{
  807. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  808. }
  809. FileUtils.writeFile(dataBuffer.append("mediaInfo.json").toString(), medias.toString());
  810. return ResultData.ok();
  811. }
  812. @Override
  813. public ResultData saveScreencapFile(SceneEditParamVO base) throws Exception{
  814. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getIndex()) ||
  815. StrUtil.isEmpty(base.getCamerasData())){
  816. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  817. }
  818. ScenePO scene = findBySceneNum(base.getNum());
  819. if(scene == null){
  820. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  821. }
  822. StringBuffer dataBuf = new StringBuffer()
  823. .append("data").append(File.separator)
  824. .append("data").append(scene.getNum())
  825. .append(File.separator);
  826. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  827. if("1".equals(base.getIndex())){
  828. File file = new File(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).toString());
  829. if(file.isDirectory()){
  830. String[] strs = file.list();
  831. if(strs!=null){
  832. for(int i=0;i<strs.length;++i) {
  833. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  834. FileUtils.deleteFile(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(strs[i]).toString());
  835. }
  836. }
  837. }
  838. } else {
  839. file.mkdirs();
  840. }
  841. Map<String, Object> map = new HashMap<>();
  842. map.put("screencapLen", "0");
  843. map.put("version", scene.getVersion()+1);
  844. FileUtils.writeJsonFile(dataBuffer.append("scene.json").toString(), map);
  845. //sceneService.updateScreencapLen(sceneNum, 0);
  846. }
  847. String filePath = dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(ConstantFileName.SCREEN_CRP_DATAFILE).append(base.getIndex()).append("json").toString();
  848. File file = new File(filePath);
  849. if(!file.exists())
  850. {
  851. file.createNewFile();
  852. }
  853. FileUtils.writeFile(filePath, base.getCamerasData());
  854. return ResultData.ok();
  855. }
  856. @Override
  857. public Page<SceneProPO> findAllScene(SceneParamVO param) {
  858. Page<SceneProPO> page = new Page<>(param.getPageNum(), param.getPageSize());
  859. return baseMapper.findAllScene(page, param);
  860. }
  861. @Override
  862. public Page<ScenePO> unionSearchBySceneName(SceneParamVO param) {
  863. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  864. return baseMapper.unionSearchBySceneName(page, param.getSearchKey());
  865. }
  866. @Override
  867. public List<SceneProPO> getOnlySceneList(SceneParamVO param) throws Exception {
  868. return baseMapper.getOnlySceneList(param);
  869. }
  870. @Override
  871. public ResultData updateViewCount(String sceneNum) {
  872. String key = String.format(RedisKey.SCENE_VISIT_CNT, sceneNum);
  873. Object countObject = redisUtil.get(key);
  874. int count = 0;
  875. if(countObject == null){
  876. String lockKey = String.format(RedisLockKey.LOCK_SCENE_VISIT_CNT, sceneNum);
  877. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
  878. try {
  879. if(!lock){
  880. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  881. }
  882. countObject = redisUtil.get(key);
  883. if(countObject == null){
  884. Scene scene = this.getSceneBySceneCode(sceneNum);
  885. if(scene == null){
  886. ScenePro scenePro = sceneProMapper.findByNum(sceneNum);
  887. if(scenePro != null){
  888. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  889. count = sceneProExt.getViewCount();
  890. }
  891. }else {
  892. count = scene.getViewCount();
  893. }
  894. redisUtil.set(key, String.valueOf(count));
  895. }
  896. }finally {
  897. redisLockUtil.unlockLua(lockKey);
  898. }
  899. }
  900. redisUtil.incr(key, 1);
  901. return ResultData.ok();
  902. }
  903. @Override
  904. public void updatePv(){
  905. Boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_SCENE_VISIT_UPDATE, RedisKey.EXPIRE_TIME_2_HOUR);
  906. if(!lock){
  907. return;
  908. }
  909. try {
  910. Map<String, Integer> pvMap = redisUtil.hmget(RedisKey.SCENE_VISIT_CNT);
  911. if(CollUtil.isEmpty(pvMap)){
  912. return;
  913. }
  914. for (Map.Entry<String, Integer> entry : pvMap.entrySet()) {
  915. Scene scene = this.getSceneBySceneCode(entry.getKey());
  916. if (Objects.nonNull(scene)){
  917. scene.setViewCount(entry.getValue());
  918. scene.setUpdateTime(Calendar.getInstance().getTime());
  919. this.updateById(scene);
  920. continue;
  921. }
  922. ScenePro scenePro = sceneProMapper.findByNum(entry.getKey());
  923. if(scenePro != null){
  924. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  925. sceneProExt.setViewCount(entry.getValue());
  926. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  927. sceneProExtService.updateById(sceneProExt);
  928. }
  929. }
  930. }finally {
  931. redisLockUtil.unlockLua(RedisLockKey.LOCK_SCENE_VISIT_UPDATE);
  932. }
  933. }
  934. @Override
  935. public Page search(@RequestBody SceneParamVO param) {
  936. param.setOrderBy("view_count desc");
  937. Page<ScenePO> scenePOPage = this.unionSearchBySceneName(param);
  938. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  939. return scenePOPage;
  940. }
  941. List<SceneVO> voList = this.convert(scenePOPage.getRecords());
  942. for (SceneVO vo : voList){
  943. if (vo.getUserId() != null){
  944. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  945. String nickName = nickNameResult.getData().getNickName();
  946. vo.setNickName(nickName);
  947. }
  948. }
  949. Page<SceneVO> result= new Page<>(param.getPageNum(), param.getPageSize());
  950. result.setTotal(scenePOPage.getTotal());
  951. result.setRecords(voList);
  952. return result;
  953. }
  954. @Override
  955. public Page loadScene(SceneParamVO param){
  956. String orderBy = null;
  957. if (StringUtils.isEmpty(param.getSceneInterest()) || "1".equals(param.getSceneInterest())){
  958. orderBy = " recommend desc, create_time ";
  959. }else if ("2".equals(param.getSceneInterest())){
  960. orderBy = " create_time desc ";
  961. }else if ("3".equals(param.getSceneInterest())){
  962. orderBy = " view_count desc ";
  963. }
  964. param.setOrderBy(orderBy);
  965. Page<SceneProPO> page = this.findAllScene(param);
  966. if(CollUtil.isEmpty(page.getRecords())){
  967. return page;
  968. }
  969. List<SceneVO> voList = this.convertPro(page.getRecords());
  970. for (SceneVO vo : voList){
  971. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  972. vo.setNickName(nickNameResult.getData().getNickName());
  973. }
  974. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  975. result.setTotal(page.getTotal());
  976. result.setRecords(voList);
  977. return result;
  978. }
  979. @Override
  980. public Page loadAllScene2(SceneParamVO param) {
  981. param.setOrderBy("create_time desc");
  982. if(param.getSceneScheme()!= null && param.getSceneScheme() == 4){
  983. Page<ScenePro> page = new Page<>(param.getPageNum(), param.getPageSize());
  984. Page<ScenePro> sceneProPage = sceneProService.page(page, new LambdaQueryWrapper<ScenePro>()
  985. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  986. .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
  987. .and(wrapper -> wrapper.or().like(ScenePro::getSceneName, "%" + param.getSceneKey() + "%")
  988. .or().like(ScenePro::getNum, "%" + param.getSceneKey() + "%")).orderByDesc(ScenePro::getId));
  989. if(CollUtil.isEmpty(sceneProPage.getRecords())){
  990. return sceneProPage;
  991. }
  992. List<SceneVO> sceneList = sceneProService.convert(sceneProPage.getRecords());
  993. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  994. result.setTotal(sceneProPage.getTotal());
  995. result.setRecords(sceneList);
  996. return result;
  997. }
  998. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  999. Page<ScenePO> scenePOPage = baseMapper.selectScenePoByCondition(page, param);
  1000. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  1001. return scenePOPage;
  1002. }
  1003. List<SceneVO> sceneList = sceneService.convert(scenePOPage.getRecords());
  1004. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  1005. result.setTotal(scenePOPage.getTotal());
  1006. result.setRecords(sceneList);
  1007. return result;
  1008. }
  1009. @Override
  1010. public ResultData querySceneDataSource(SceneParamVO param){
  1011. log.info("querySceneDataSource:查询模型数据");
  1012. String num = param.getNum();
  1013. if(StrUtil.isEmpty(num))
  1014. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1015. ScenePO scene = sceneService.findBySceneNum(num);
  1016. String data = null;
  1017. if(scene == null) {
  1018. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1019. if(scenePro == null)
  1020. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1021. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1022. data = sceneProExt.getDataSource();
  1023. }else {
  1024. data = scene.getDataSource();
  1025. }
  1026. if(data != null && !"".equals(data) && data.startsWith("http")){
  1027. data = ConstantFilePath.BUILD_MODEL_PATH + data.split("/")[data.split("/").length - 2];
  1028. }
  1029. return ResultData.ok(data);
  1030. }
  1031. @Override
  1032. public ResultData querySceneNum(SceneParamVO param){
  1033. log.info("querySceneDataSource:查询模型数据");
  1034. String path = param.getPath();
  1035. if(path==null&&path.trim().equals(""))
  1036. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1037. path = path.split("/")[path.split("/").length - 1];
  1038. Scene scene = sceneService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
  1039. String sceneNum = null;
  1040. if(scene == null)
  1041. {
  1042. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
  1043. if(scenePro == null)
  1044. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1045. sceneNum = scenePro.getNum();
  1046. }else {
  1047. sceneNum = scene.getNum();
  1048. }
  1049. return ResultData.ok(sceneNum);
  1050. }
  1051. }