SceneServiceImpl.java 60 KB

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