SceneServiceImpl.java 48 KB

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