SceneServiceImpl.java 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. return sceneVO;
  713. }).collect(Collectors.toList());
  714. return sceneVOs;
  715. }
  716. @Override
  717. public List<ScenePO> findAllByYesterday() throws Exception {
  718. return baseMapper.findAllByYesterday();
  719. }
  720. @Override
  721. public ScenePO findBySceneNum(String sceneNum) {
  722. return baseMapper.findByNum(sceneNum);
  723. }
  724. @Override
  725. public Scene getSceneBySceneCode(String sceneCode) {
  726. List<Scene> list = this.list(new LambdaQueryWrapper<Scene>()
  727. .eq(Scene::getTbStatus, TbStatus.VALID.code())
  728. .eq(Scene::getNum, sceneCode));
  729. if(CollUtil.isEmpty(list)){
  730. return null;
  731. }
  732. return list.get(0);
  733. }
  734. @Override
  735. public ResultData recover(String sceneNum) throws Exception {
  736. ScenePO scene = baseMapper.findByNum(sceneNum);
  737. if (scene == null){
  738. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  739. }
  740. scene.setPayStatus(1);
  741. this.update(new LambdaUpdateWrapper<Scene>()
  742. .eq(Scene::getId, scene.getId())
  743. .set(Scene::getPayStatus, PayStatus.PAY.code()));
  744. SceneVO SceneVO = new SceneVO();
  745. BeanUtils.copyProperties(scene, SceneVO);
  746. return ResultData.ok(SceneVO);
  747. }
  748. // public int getSceneCount(Long cameraId) {
  749. // return sceneMapper.getSceneCount(cameraId);
  750. // }
  751. @Override
  752. public Scene getSceneStatusByUnicode(String unicode, int tbStatus) {
  753. return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getTbStatus, tbStatus).like(Scene::getDataSource, "%"+unicode+"%"));
  754. }
  755. public void updateStatus(String sceneNum, int status) {
  756. this.update(new LambdaUpdateWrapper<Scene>().eq(Scene::getNum, sceneNum).set(Scene::getSceneStatus, status));
  757. }
  758. @Override
  759. public void updateTime(String sceneNum, Long space, int payStatus) {
  760. List<Scene> sceneList = this.list(new LambdaQueryWrapper<Scene>()
  761. .select(Scene::getId)
  762. .eq(Scene::getNum, sceneNum));
  763. if(CollUtil.isEmpty(sceneList))
  764. return ;
  765. this.update(new LambdaUpdateWrapper<Scene>()
  766. .eq(Scene::getNum, sceneNum)
  767. .set(Scene::getCreateTime, Calendar.getInstance().getTime())
  768. .set(Scene::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
  769. List<Long> sceneIds = sceneList.stream().map(scene -> {
  770. return scene.getId();
  771. }).collect(Collectors.toList());
  772. sceneExtService.update(new LambdaUpdateWrapper<SceneExt>().in(SceneExt::getSceneId, sceneIds).set(SceneExt::getSpace, space));
  773. }
  774. @Override
  775. public ResultData addHotMediaInfo(SceneEditParamVO base) throws Exception{
  776. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getType()) ||
  777. StrUtil.isEmpty(base.getInfo())){
  778. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  779. }
  780. ScenePO scene = findBySceneNum(base.getNum());
  781. if(scene == null){
  782. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  783. }
  784. StringBuffer dataBuf = new StringBuffer()
  785. .append("data").append(File.separator)
  786. .append("data").append(scene.getNum())
  787. .append(File.separator);
  788. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  789. String infoData = FileUtils.readFile(dataBuffer.append("mediaInfo.json").toString());
  790. JSONArray medias = null;
  791. if(infoData != null){
  792. medias= JSONArray.parseArray(infoData);
  793. }
  794. if("1".equals(base.getType())){
  795. JSONObject jo = JSONObject.parseObject(base.getInfo());
  796. medias.add(jo);
  797. }else if("1".equals(base.getType())){
  798. for(int i=0;i<medias.size();++i){
  799. JSONObject ob = medias.getJSONObject(i);
  800. if(ob.getString("file").equals(base.getName())){
  801. medias.remove(i);
  802. break;
  803. }
  804. }
  805. }else{
  806. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  807. }
  808. FileUtils.writeFile(dataBuffer.append("mediaInfo.json").toString(), medias.toString());
  809. return ResultData.ok();
  810. }
  811. @Override
  812. public ResultData saveScreencapFile(SceneEditParamVO base) throws Exception{
  813. if(StrUtil.isEmpty(base.getNum()) || StrUtil.isEmpty(base.getIndex()) ||
  814. StrUtil.isEmpty(base.getCamerasData())){
  815. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  816. }
  817. ScenePO scene = findBySceneNum(base.getNum());
  818. if(scene == null){
  819. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  820. }
  821. StringBuffer dataBuf = new StringBuffer()
  822. .append("data").append(File.separator)
  823. .append("data").append(scene.getNum())
  824. .append(File.separator);
  825. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  826. if("1".equals(base.getIndex())){
  827. File file = new File(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).toString());
  828. if(file.isDirectory()){
  829. String[] strs = file.list();
  830. if(strs!=null){
  831. for(int i=0;i<strs.length;++i) {
  832. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  833. FileUtils.deleteFile(dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(strs[i]).toString());
  834. }
  835. }
  836. }
  837. } else {
  838. file.mkdirs();
  839. }
  840. Map<String, Object> map = new HashMap<>();
  841. map.put("screencapLen", "0");
  842. map.put("version", scene.getVersion()+1);
  843. FileUtils.writeJsonFile(dataBuffer.append("scene.json").toString(), map);
  844. //sceneService.updateScreencapLen(sceneNum, 0);
  845. }
  846. String filePath = dataBuffer.append(ConstantFileName.TOURLIST_FOLDER).append(File.separator).append(ConstantFileName.SCREEN_CRP_DATAFILE).append(base.getIndex()).append("json").toString();
  847. File file = new File(filePath);
  848. if(!file.exists())
  849. {
  850. file.createNewFile();
  851. }
  852. FileUtils.writeFile(filePath, base.getCamerasData());
  853. return ResultData.ok();
  854. }
  855. @Override
  856. public Page<SceneProPO> findAllScene(SceneParamVO param) {
  857. Page<SceneProPO> page = new Page<>(param.getPageNum(), param.getPageSize());
  858. return baseMapper.findAllScene(page, param);
  859. }
  860. @Override
  861. public Page<ScenePO> unionSearchBySceneName(SceneParamVO param) {
  862. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  863. return baseMapper.unionSearchBySceneName(page, param.getSearchKey());
  864. }
  865. @Override
  866. public List<SceneProPO> getOnlySceneList(SceneParamVO param) throws Exception {
  867. return baseMapper.getOnlySceneList(param);
  868. }
  869. @Override
  870. public ResultData updateViewCount(String sceneNum) {
  871. String key = String.format(RedisKey.SCENE_VISIT_CNT, sceneNum);
  872. Object countObject = redisUtil.get(key);
  873. int count = 0;
  874. if(countObject == null){
  875. String lockKey = String.format(RedisLockKey.LOCK_SCENE_VISIT_CNT, sceneNum);
  876. boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
  877. try {
  878. if(!lock){
  879. throw new BusinessException(ErrorCode.SYSTEM_BUSY);
  880. }
  881. countObject = redisUtil.get(key);
  882. if(countObject == null){
  883. Scene scene = this.getSceneBySceneCode(sceneNum);
  884. if(scene == null){
  885. ScenePro scenePro = sceneProMapper.findByNum(sceneNum);
  886. if(scenePro != null){
  887. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  888. count = sceneProExt.getViewCount();
  889. }
  890. }else {
  891. count = scene.getViewCount();
  892. }
  893. redisUtil.set(key, String.valueOf(count));
  894. }
  895. }finally {
  896. redisLockUtil.unlockLua(lockKey);
  897. }
  898. }
  899. redisUtil.incr(key, 1);
  900. return ResultData.ok();
  901. }
  902. @Override
  903. public void updatePv(){
  904. Boolean lock = redisLockUtil.lock(RedisLockKey.LOCK_SCENE_VISIT_UPDATE, RedisKey.EXPIRE_TIME_2_HOUR);
  905. if(!lock){
  906. return;
  907. }
  908. try {
  909. Map<String, Integer> pvMap = redisUtil.hmget(RedisKey.SCENE_VISIT_CNT);
  910. if(CollUtil.isEmpty(pvMap)){
  911. return;
  912. }
  913. for (Map.Entry<String, Integer> entry : pvMap.entrySet()) {
  914. Scene scene = this.getSceneBySceneCode(entry.getKey());
  915. if (Objects.nonNull(scene)){
  916. scene.setViewCount(entry.getValue());
  917. scene.setUpdateTime(Calendar.getInstance().getTime());
  918. this.updateById(scene);
  919. continue;
  920. }
  921. ScenePro scenePro = sceneProMapper.findByNum(entry.getKey());
  922. if(scenePro != null){
  923. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  924. sceneProExt.setViewCount(entry.getValue());
  925. sceneProExt.setUpdateTime(Calendar.getInstance().getTime());
  926. sceneProExtService.updateById(sceneProExt);
  927. }
  928. }
  929. }finally {
  930. redisLockUtil.unlockLua(RedisLockKey.LOCK_SCENE_VISIT_UPDATE);
  931. }
  932. }
  933. @Override
  934. public Page search(@RequestBody SceneParamVO param) {
  935. param.setOrderBy("view_count desc");
  936. Page<ScenePO> scenePOPage = this.unionSearchBySceneName(param);
  937. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  938. return scenePOPage;
  939. }
  940. List<SceneVO> voList = this.convert(scenePOPage.getRecords());
  941. for (SceneVO vo : voList){
  942. if (vo.getUserId() != null){
  943. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  944. String nickName = nickNameResult.getData().getNickName();
  945. vo.setNickName(nickName);
  946. }
  947. }
  948. Page<SceneVO> result= new Page<>(param.getPageNum(), param.getPageSize());
  949. result.setTotal(scenePOPage.getTotal());
  950. result.setRecords(voList);
  951. return result;
  952. }
  953. @Override
  954. public Page loadScene(SceneParamVO param){
  955. String orderBy = null;
  956. if (StringUtils.isEmpty(param.getSceneInterest()) || "1".equals(param.getSceneInterest())){
  957. orderBy = " recommend desc, create_time ";
  958. }else if ("2".equals(param.getSceneInterest())){
  959. orderBy = " create_time desc ";
  960. }else if ("3".equals(param.getSceneInterest())){
  961. orderBy = " view_count desc ";
  962. }
  963. param.setOrderBy(orderBy);
  964. Page<SceneProPO> page = this.findAllScene(param);
  965. if(CollUtil.isEmpty(page.getRecords())){
  966. return page;
  967. }
  968. List<SceneVO> voList = this.convertPro(page.getRecords());
  969. for (SceneVO vo : voList){
  970. ResultData<User> nickNameResult = platformUserClient.getUserByUserId(vo.getUserId());
  971. vo.setNickName(nickNameResult.getData().getNickName());
  972. }
  973. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  974. result.setTotal(page.getTotal());
  975. result.setRecords(voList);
  976. return result;
  977. }
  978. @Override
  979. public Page loadAllScene2(SceneParamVO param) {
  980. param.setOrderBy("create_time desc");
  981. if(param.getSceneScheme()!= null && param.getSceneScheme() == 4){
  982. Page<ScenePro> page = new Page<>(param.getPageNum(), param.getPageSize());
  983. Page<ScenePro> sceneProPage = sceneProService.page(page, new LambdaQueryWrapper<ScenePro>()
  984. .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
  985. .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
  986. .and(wrapper -> wrapper.or().like(ScenePro::getSceneName, "%" + param.getSceneKey() + "%")
  987. .or().like(ScenePro::getNum, "%" + param.getSceneKey() + "%")).orderByDesc(ScenePro::getId));
  988. if(CollUtil.isEmpty(sceneProPage.getRecords())){
  989. return sceneProPage;
  990. }
  991. List<SceneVO> sceneList = sceneProService.convert(sceneProPage.getRecords());
  992. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  993. result.setTotal(sceneProPage.getTotal());
  994. result.setRecords(sceneList);
  995. return result;
  996. }
  997. Page<ScenePO> page = new Page<>(param.getPageNum(), param.getPageSize());
  998. Page<ScenePO> scenePOPage = baseMapper.selectScenePoByCondition(page, param);
  999. if(CollUtil.isEmpty(scenePOPage.getRecords())){
  1000. return scenePOPage;
  1001. }
  1002. List<SceneVO> sceneList = sceneService.convert(scenePOPage.getRecords());
  1003. Page<SceneVO> result = new Page<>(param.getPageNum(), param.getPageSize());
  1004. result.setTotal(scenePOPage.getTotal());
  1005. result.setRecords(sceneList);
  1006. return result;
  1007. }
  1008. @Override
  1009. public ResultData querySceneDataSource(SceneParamVO param){
  1010. log.info("querySceneDataSource:查询模型数据");
  1011. String num = param.getNum();
  1012. if(StrUtil.isEmpty(num))
  1013. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1014. ScenePO scene = sceneService.findBySceneNum(num);
  1015. String data = null;
  1016. if(scene == null) {
  1017. ScenePro scenePro = sceneProService.findBySceneNum(num);
  1018. if(scenePro == null)
  1019. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1020. SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
  1021. data = sceneProExt.getDataSource();
  1022. }else {
  1023. data = scene.getDataSource();
  1024. }
  1025. if(data != null && !"".equals(data) && data.startsWith("http")){
  1026. data = ConstantFilePath.BUILD_MODEL_PATH + data.split("/")[data.split("/").length - 2];
  1027. }
  1028. return ResultData.ok(data);
  1029. }
  1030. @Override
  1031. public ResultData querySceneNum(SceneParamVO param){
  1032. log.info("querySceneDataSource:查询模型数据");
  1033. String path = param.getPath();
  1034. if(path==null&&path.trim().equals(""))
  1035. throw new BusinessException(ErrorCode.FAILURE_CODE_7002);
  1036. path = path.split("/")[path.split("/").length - 1];
  1037. Scene scene = sceneService.getSceneStatusByUnicode(path, TbStatus.VALID.code());
  1038. String sceneNum = null;
  1039. if(scene == null)
  1040. {
  1041. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode(path, "A");
  1042. if(scenePro == null)
  1043. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1044. sceneNum = scenePro.getNum();
  1045. }else {
  1046. sceneNum = scene.getNum();
  1047. }
  1048. return ResultData.ok(sceneNum);
  1049. }
  1050. }