SceneServiceImpl.java 58 KB

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