SceneServiceImpl.java 50 KB

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