SceneProAppServiceImpl.java 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.fdkankan.common.constant.*;
  8. import com.fdkankan.common.exception.BusinessException;
  9. import com.fdkankan.common.response.ResultData;
  10. import com.fdkankan.common.util.*;
  11. import com.fdkankan.redis.util.RedisLockUtil;
  12. import com.fdkankan.scene.entity.ScenePro;
  13. import com.fdkankan.scene.entity.SceneProEdit;
  14. import com.fdkankan.scene.entity.SceneProEditExt;
  15. import com.fdkankan.scene.mapper.ISceneProMapper;
  16. import com.fdkankan.scene.service.ISceneProAppService;
  17. import com.fdkankan.scene.service.ISceneProEditExtService;
  18. import com.fdkankan.scene.service.ISceneProEditService;
  19. import com.fdkankan.scene.service.ISceneProService;
  20. import com.fdkankan.scene.vo.SceneEditVO;
  21. import lombok.extern.slf4j.Slf4j;
  22. import net.coobird.thumbnailator.Thumbnails;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.beans.factory.annotation.Qualifier;
  26. import org.springframework.beans.factory.annotation.Value;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import java.io.File;
  30. import java.io.InputStream;
  31. import java.io.PrintWriter;
  32. import java.io.StringWriter;
  33. import java.net.HttpURLConnection;
  34. import java.net.URL;
  35. import java.util.*;
  36. /**
  37. * <p>
  38. * pro场景表 服务实现类
  39. * </p>
  40. *
  41. * @author dengsixing
  42. * @since 2021-12-23
  43. */
  44. @Slf4j
  45. @Service
  46. public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProAppService {
  47. @Value("${oss.type}")
  48. private String type;
  49. @Value("${prefix.ali}")
  50. private String prefixAli;
  51. @Value("${hot.domain.list}")
  52. private String hotDomainList;
  53. @Value("${hot.delete}")
  54. private String hotDelete;
  55. @Autowired
  56. ISceneProService sceneProService;
  57. @Autowired
  58. @Qualifier("uploadToOssUtil")
  59. UploadToOssUtil uploadToOssUtil;
  60. @Autowired
  61. ISceneProEditService sceneProEditService;
  62. @Autowired
  63. RedisLockUtil redisLockUtil;
  64. @Autowired
  65. ISceneProEditExtService sceneProEditExtService;
  66. @Override
  67. public ResultData saveInitialPage(SceneEditVO base) throws Exception {
  68. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getInitialPoint())){
  69. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  70. }
  71. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  72. if(Objects.isNull(scenePro)){
  73. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  74. }
  75. SceneProEdit sceneProEdit= sceneProEditService.findByProId(scenePro.getId());
  76. StringBuffer dataBuf = new StringBuffer()
  77. .append("data").append(File.separator)
  78. .append("data").append(scenePro.getSceneCode())
  79. .append(File.separator);
  80. StringBuffer imagesBuf = new StringBuffer()
  81. .append("images").append(File.separator)
  82. .append("images").append(scenePro.getSceneCode())
  83. .append(File.separator);
  84. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  85. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  86. String path1 = imagesBuffer.toString() + "thumbBigImg.jpg";
  87. String path2 = imagesBuffer.toString() + "thumbSmallImg.jpg";
  88. //生成缩略图
  89. //按指定大小把图片进行缩和放(会遵循原图高宽比例)
  90. //此处把图片压成1024×512的缩略图
  91. Thumbnails.of(path1).size(1024,512).toFile(path2);//变为1024×512
  92. Map map = new HashMap();
  93. map.put("entry", JSONObject.parseObject(base.getInitialPoint()));
  94. map.put("thumbImg", 1);
  95. map.put("version", sceneProEdit.getVersion()+1);
  96. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  97. Map<String,String> uploadMap = new HashMap<String,String>();
  98. uploadMap.put(imagesBuffer.toString() + "thumbBigImg.jpg", imagesBuf.toString() + "thumbBigImg.jpg");
  99. uploadMap.put(imagesBuffer.toString() + "thumbFishBigImg.jpg", imagesBuf.toString() + "thumbFishBigImg.jpg");
  100. uploadMap.put(imagesBuffer.toString() + "thumbSmallImg.jpg", imagesBuf.toString() + "thumbSmallImg.jpg");
  101. uploadMap.put(imagesBuffer.toString() + "smallPic.jpg", imagesBuf.toString() + "smallPic.jpg");
  102. uploadMap.put(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  103. uploadToOssUtil.uploadMulFiles(uploadMap);
  104. sceneProEdit.setEntry(base.getInitialPoint());
  105. sceneProEdit.setThumbStatus(1);
  106. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  107. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  108. sceneProEditService.updateById(sceneProEdit);
  109. scenePro.setThumb(prefixAli + imagesBuf.toString() + "thumbSmallImg.jpg");
  110. if("s3".equals(type)){
  111. scenePro.setThumb(ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "thumbSmallImg.jpg");
  112. }
  113. sceneProService.updateById(scenePro);
  114. return ResultData.ok();
  115. }
  116. @Override
  117. public ResultData saveFloorLogo(SceneEditVO base) throws Exception {
  118. if(StrUtil.isEmpty(base.getSceneNum()) || StrUtil.isEmpty(base.getSize()) ||
  119. StrUtil.isEmpty(base.getLogoType())){
  120. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  121. }
  122. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  123. if(scenePro == null){
  124. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  125. }
  126. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  127. StringBuffer dataBuf = new StringBuffer()
  128. .append("data").append(File.separator)
  129. .append("data").append(scenePro.getSceneCode())
  130. .append(File.separator);
  131. StringBuffer imagesBuf = new StringBuffer()
  132. .append("images").append(File.separator)
  133. .append("images").append(scenePro.getSceneCode())
  134. .append(File.separator);
  135. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  136. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  137. Map map = new HashMap();
  138. map.put("floorLogo", base.getLogoType());
  139. map.put("floorLogoSize", base.getSize());
  140. map.put("version", sceneProEdit.getVersion()+1);
  141. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  142. sceneProEdit.setFloorLogo(base.getLogoType());
  143. sceneProEdit.setFloorLogoSize(Integer.parseInt(base.getSize()));
  144. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  145. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  146. sceneProEditService.updateById(sceneProEdit);
  147. uploadToOssUtil.upload(imagesBuffer.toString() + "floorLogoImg.png", imagesBuf.toString() + "floorLogoImg.png");
  148. uploadToOssUtil.upload(dataBuffer.toString() + "scene.json", dataBuf.toString() + "scene.json");
  149. return ResultData.ok();
  150. }
  151. @Override
  152. @SuppressWarnings("unchecked")
  153. public ResultData saveHot(SceneEditVO base) throws Exception {
  154. if(StrUtil.isEmpty(base.getType())){
  155. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  156. }
  157. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  158. if (scenePro == null ) {
  159. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  160. }
  161. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  162. log.info("hotData:" + base.getHotData());
  163. JSONObject jsonhot = JSONObject.parseObject(base.getHotData());
  164. StringBuffer dataBuf = new StringBuffer()
  165. .append("data").append(File.separator)
  166. .append("data").append(scenePro.getSceneCode())
  167. .append(File.separator);
  168. StringBuffer imagesBuf = new StringBuffer()
  169. .append("images").append(File.separator)
  170. .append("images").append(scenePro.getSceneCode())
  171. .append(File.separator);
  172. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  173. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  174. String sid = this.getSidFromParams(base, jsonhot);
  175. JSONArray jsonhots = this.getJsonhots(base, dataBuffer, jsonhot);
  176. //判断是否需要删除自定义热点样式
  177. String hotsids = this.deleteCustomStyleHots(base,jsonhots,jsonhot,sid);
  178. Object[] uploadFileMapAndSceneJson = this.getUploadFileMapAndSceneJson(base,jsonhots, jsonhot, sid, imagesBuf, imagesBuffer, dataBuf, dataBuffer);
  179. Map<String,String> map = (Map<String, String>) uploadFileMapAndSceneJson[0];
  180. JSONObject scenejson = (JSONObject) uploadFileMapAndSceneJson[1];
  181. uploadToOssUtil.uploadMulFiles(map);
  182. if(!StringUtils.isEmpty(base.getPlayData())){
  183. sceneProEdit.setPlayData(dataBuf.toString() + "playData.json");
  184. }
  185. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  186. sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  187. }
  188. sceneProEdit.setHotsIds(hotsids);
  189. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  190. sceneProEditService.updateById(sceneProEdit);
  191. scenejson.put("version", sceneProEdit.getVersion() + 1);
  192. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  193. return ResultData.ok();
  194. }
  195. @Override
  196. public ResultData saveBackgroundMusic(SceneEditVO base) throws Exception {
  197. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getMusicName())){
  198. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  199. }
  200. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  201. if(scenePro == null){
  202. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  203. }
  204. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  205. StringBuffer dataBuf = new StringBuffer()
  206. .append("data").append(File.separator)
  207. .append("data").append(scenePro.getSceneCode())
  208. .append(File.separator);
  209. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  210. Map map = new HashMap();
  211. map.put("bgMusic", base.getMusicName());
  212. map.put("version", sceneProEdit.getVersion()+1);
  213. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  214. sceneProEdit.setBgMusic(base.getMusicName());
  215. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  216. sceneProEditService.updateById(sceneProEdit);
  217. return ResultData.ok();
  218. }
  219. @Override
  220. public ResultData saveSceneInfo(SceneEditVO base) throws Exception{
  221. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneName()) ||
  222. StringUtils.isEmpty(base.getSceneType()) || StringUtils.isEmpty(base.getSceneDec())){
  223. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  224. }
  225. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  226. if(scenePro == null){
  227. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  228. }
  229. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  230. StringBuffer dataBuf = new StringBuffer()
  231. .append("data").append(File.separator)
  232. .append("data").append(scenePro.getSceneCode())
  233. .append(File.separator);
  234. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  235. Map map = new HashMap();
  236. map.put("sceneName", base.getSceneName());
  237. map.put("sceneDec", base.getSceneDec());
  238. if(StrUtil.isNotEmpty(base.getSceneType())){
  239. if(scenePro.getSceneType() == 99){
  240. map.put("sceneType", scenePro.getSceneType());
  241. }else {
  242. scenePro.setSceneType(Integer.parseInt(base.getSceneType()));
  243. map.put("sceneType", base.getSceneType());
  244. }
  245. }
  246. if(StrUtil.isNotEmpty(base.getSceneKey())) {
  247. map.put("sceneKey", base.getSceneKey());
  248. map.put("needKey", 1);
  249. sceneProEdit.setNeedKey(1);
  250. }else {
  251. sceneProEdit.setNeedKey(0);
  252. map.put("sceneKey", "");
  253. map.put("needKey", 0);
  254. }
  255. map.put("version", sceneProEdit.getVersion()+1);
  256. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  257. scenePro.setSceneName(base.getSceneName());
  258. scenePro.setSceneDec(base.getSceneDec());
  259. scenePro.setUpdateTime(Calendar.getInstance().getTime());
  260. this.updateById(scenePro);
  261. sceneProEdit.setSceneKey(base.getSceneKey());
  262. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  263. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  264. sceneProEditService.updateById(sceneProEdit);
  265. return ResultData.ok();
  266. }
  267. @Override
  268. public ResultData saveSceneKey(SceneEditVO base) throws Exception{
  269. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getSceneKey())){
  270. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  271. }
  272. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  273. if(scenePro == null){
  274. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  275. }
  276. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  277. StringBuffer dataBuf = new StringBuffer()
  278. .append("data").append(File.separator)
  279. .append("data").append(scenePro.getSceneCode())
  280. .append(File.separator);
  281. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  282. Map map = new HashMap();
  283. map.put("sceneKey", base.getSceneKey());
  284. map.put("needKey", 1);
  285. map.put("version", sceneProEdit.getVersion()+1);
  286. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  287. sceneProEdit.setSceneKey(base.getSceneKey());
  288. sceneProEdit.setNeedKey(1);
  289. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  290. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  291. sceneProEditService.updateById(sceneProEdit);
  292. return ResultData.ok();
  293. }
  294. @Override
  295. public ResultData saveTourList(SceneEditVO base) throws Exception{
  296. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getTourList())){
  297. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  298. }
  299. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  300. if(scenePro == null){
  301. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  302. }
  303. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  304. StringBuffer dataBuf = new StringBuffer()
  305. .append("data").append(File.separator)
  306. .append("data").append(scenePro.getSceneCode())
  307. .append(File.separator);
  308. StringBuffer imagesBuf = new StringBuffer()
  309. .append("images").append(File.separator)
  310. .append("images").append(scenePro.getSceneCode())
  311. .append(File.separator);
  312. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  313. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  314. Map<String,String> map = new HashMap<String,String>();
  315. log.info("editForApp/saveTourList:生成tourList.json文件");
  316. String tourListPath = dataBuffer.toString() + ConstantFileName.TOUR_LIST;
  317. FileUtils.writeFile(tourListPath, base.getTourList());
  318. map.put(tourListPath, dataBuf.toString() + ConstantFileName.TOUR_LIST);
  319. JSONArray tourJsons = JSONArray.parseArray(base.getTourList());
  320. String path = imagesBuffer.toString() + ConstantFileName.TOURLIST_FOLDER;
  321. for(int i=0;i<tourJsons.size();++i)
  322. {
  323. String fileName = path + File.separator +"guide"+i+".jpg";
  324. map.put(fileName, imagesBuf.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+"guide"+i+".jpg");
  325. }
  326. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  327. String[] strs = file.list();
  328. if(strs!=null) {
  329. int screencapLen = 0;
  330. for(int i=0;i<strs.length;++i){
  331. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)<=-1)
  332. continue;
  333. map.put(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i], dataBuf.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i]);
  334. ++screencapLen;
  335. }
  336. Map<String, Object> jsonMap = new HashMap();
  337. jsonMap.put("screenCapLen", screencapLen);
  338. jsonMap.put("version", sceneProEdit.getVersion() + 1);
  339. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", jsonMap);
  340. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  341. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  342. sceneProEditService.updateById(sceneProEdit);
  343. }
  344. uploadToOssUtil.uploadMulFiles(map);
  345. return ResultData.ok();
  346. }
  347. @Override
  348. public ResultData uploadPic(String sceneNum, String folderName, MultipartFile file) throws Exception{
  349. if(StringUtils.isEmpty(sceneNum)){
  350. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  351. }
  352. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  353. if(scenePro == null){
  354. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  355. }
  356. if (file.isEmpty() && file.getSize() <= 0) {
  357. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  358. }
  359. String lockKey = String.format(RedisKey.LOCK_UPLOAD_PRO_PIC, sceneNum);
  360. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
  361. if(!lock){
  362. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  363. }
  364. File targetFile = null;
  365. try {
  366. //文件上传的位置可以自定义
  367. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  368. if(StrUtil.isNotEmpty(folderName)) {
  369. path = path+File.separator + folderName;
  370. }
  371. targetFile = new File(path);
  372. if (!targetFile.exists()) {
  373. targetFile.mkdirs();
  374. }
  375. String fileName = file.getOriginalFilename();
  376. targetFile = new File(path + File.separator + fileName);
  377. // 保存
  378. if(targetFile.exists())
  379. {
  380. FileUtils.deleteFile(path + File.separator + fileName);
  381. }
  382. file.transferTo(targetFile);
  383. }catch (Exception e){
  384. log.error("上传图片失败", e);
  385. throw new BusinessException(ErrorCode.FAILURE_CODE_5037);
  386. }finally {
  387. redisLockUtil.unlock(lockKey);
  388. }
  389. return ResultData.ok(targetFile.getName());
  390. }
  391. @Override
  392. public ResultData uploadScreencapVoice(String sceneNum, MultipartFile file) throws Exception{
  393. if(StringUtils.isEmpty(sceneNum)){
  394. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  395. }
  396. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  397. if(scenePro == null){
  398. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  399. }
  400. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  401. if (file.isEmpty() && file.getSize() <= 0) {
  402. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  403. }
  404. String lockKey = String.format(RedisKey.LOCK_UPLOAD_PRO_VOICE, sceneNum);
  405. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  406. if(!lock){
  407. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  408. }
  409. String originalFileName = null;
  410. try {
  411. //文件上传的位置可以自定义
  412. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  413. File targetFile = new File(path);
  414. if (!targetFile.exists()) {
  415. targetFile.mkdirs();
  416. }
  417. originalFileName = file.getOriginalFilename();
  418. targetFile = new File(path + File.separator +originalFileName);
  419. // 保存
  420. synchronized(this) {
  421. if(targetFile.exists())
  422. {
  423. FileUtils.deleteFile(path + File.separator + originalFileName);
  424. }
  425. file.transferTo(targetFile);
  426. }
  427. uploadToOssUtil.upload(path + File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  428. Map map = new HashMap();
  429. map.put("screencapVoiceFileName", originalFileName);
  430. String voiceSrc = prefixAli + "voice/voice"+sceneNum+"/"+originalFileName;
  431. if("s3".equals(type)){
  432. voiceSrc = ConstantUrl.PREFIX_AWS + "voice/voice"+sceneNum+"/"+originalFileName;
  433. }
  434. map.put("screencapVoiceSrc", voiceSrc);
  435. map.put("screencapVoiceType", "file");
  436. map.put("version", sceneProEdit.getVersion()+1);
  437. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", map);
  438. sceneProEdit.setScreencapVoiceSrc(voiceSrc);
  439. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  440. sceneProEdit.setScreencapVoiceType("file");
  441. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  442. sceneProEditService.updateById(sceneProEdit);
  443. }catch (Exception e){
  444. log.error("上传图音频失败", e);
  445. throw new BusinessException(ErrorCode.FAILURE_CODE_5040);
  446. }finally {
  447. redisLockUtil.unlock(lockKey);
  448. }
  449. return ResultData.ok(originalFileName);
  450. }
  451. @Override
  452. public ResultData saveScreencapFile(SceneEditVO base) throws Exception{
  453. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getIndex()) ||
  454. StringUtils.isEmpty(base.getCamerasData())){
  455. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  456. }
  457. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  458. if(scenePro == null){
  459. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  460. }
  461. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  462. StringBuffer dataBuf = new StringBuffer()
  463. .append("data").append(File.separator)
  464. .append("data").append(scenePro.getSceneCode())
  465. .append(File.separator);
  466. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  467. if("1".equals(base.getIndex())){
  468. File file = new File(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER);
  469. if(file.isDirectory()){
  470. String[] strs = file.list();
  471. if(strs!=null){
  472. for(int i=0;i<strs.length;++i) {
  473. if(strs[i].indexOf(ConstantFileName.SCREEN_CRP_DATAFILE)>-1) {
  474. FileUtils.deleteFile(dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+strs[i]);
  475. }
  476. }
  477. }
  478. } else {
  479. file.mkdirs();
  480. }
  481. Map<String, Object> map = new HashMap<>();
  482. map.put("screencapLen", "0");
  483. map.put("version", sceneProEdit.getVersion()+1);
  484. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  485. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  486. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  487. sceneProEditService.updateById(sceneProEdit);
  488. }
  489. String filePath = dataBuffer.toString() + ConstantFileName.TOURLIST_FOLDER+File.separator+ConstantFileName.SCREEN_CRP_DATAFILE+base.getIndex()+"json";
  490. File file = new File(filePath);
  491. if(!file.exists())
  492. {
  493. file.createNewFile();
  494. }
  495. FileUtils.writeFile(filePath, base.getCamerasData());
  496. return ResultData.ok();
  497. }
  498. @Override
  499. public ResultData saveHotVisible(SceneEditVO base) throws Exception{
  500. if(StringUtils.isEmpty(base.getData())){
  501. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  502. }
  503. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  504. if(scenePro == null){
  505. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  506. }
  507. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  508. JSONArray visiblePanos = JSONArray.parseArray(base.getData());
  509. StringBuffer dataBuf = new StringBuffer()
  510. .append("data").append(File.separator)
  511. .append("data").append(scenePro.getSceneCode())
  512. .append(File.separator);
  513. StringBuffer imagesBuf = new StringBuffer()
  514. .append("images").append(File.separator)
  515. .append("images").append(scenePro.getSceneCode())
  516. .append(File.separator);
  517. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  518. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  519. File file = new File(dataBuffer.toString() + "hot.json");
  520. if (!file.exists()) {
  521. throw new BusinessException(ErrorCode.FAILURE_CODE_3018);
  522. }
  523. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  524. JSONArray hots = JSONArray.parseArray(str);
  525. for (int i = 0; i < hots.size(); ++i) {
  526. JSONObject hot = hots.getJSONObject(i);
  527. for (int j = 0; j < visiblePanos.size(); ++j) {
  528. if (hot.getString("sid").equals(((JSONObject) visiblePanos.get(j)).getString("sid"))) {
  529. hot.put("visiblePanos", ((JSONObject) visiblePanos.get(j)).getJSONArray("value"));
  530. }
  531. }
  532. }
  533. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  534. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  535. sceneProEditService.updateById(sceneProEdit);
  536. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  537. FileUtils.writeFile(dataBuffer.toString() + "hot.json", hots.toString());
  538. uploadToOssUtil.upload(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json");
  539. return ResultData.ok();
  540. }
  541. @Override
  542. public ResultData saveLinkPano(SceneEditVO base) throws Exception{
  543. if(StringUtils.isEmpty(base.getData()) || StringUtils.isEmpty(base.getSceneNum())){
  544. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  545. }
  546. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  547. if(scenePro == null){
  548. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  549. }
  550. JSONArray inputData = JSONObject.parseArray(base.getData());
  551. StringBuffer dataBuf = new StringBuffer()
  552. .append("data").append(File.separator)
  553. .append("data").append(scenePro.getSceneCode())
  554. .append(File.separator);
  555. StringBuffer imagesBuf = new StringBuffer()
  556. .append("images").append(File.separator)
  557. .append("images").append(scenePro.getSceneCode())
  558. .append(File.separator);
  559. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  560. File directory = new File(dataBuffer.toString());
  561. if (!directory.exists()) {
  562. directory.mkdirs();
  563. }
  564. JSONArray inputdata = JSONArray.parseArray(base.getData());
  565. String modeldataUrl = prefixAli + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  566. if("s3".equals(type)){
  567. modeldataUrl = ConstantUrl.PREFIX_AWS + imagesBuf.toString() + "vision.modeldata?t=" + System.currentTimeMillis();
  568. }
  569. FileUtils.downLoadFromUrl(modeldataUrl, "vision.modeldata", dataBuffer.toString());
  570. File file = new File(dataBuffer.toString() + "vision.modeldata");
  571. if(!file.exists()) {
  572. return ResultData.error(ErrorCode.FAILURE_CODE_5012);
  573. }
  574. ConvertUtils.convertVisionModelDataToTxt(dataBuffer.toString() + "vision.modeldata", dataBuffer.toString() + "vision.json");
  575. String str = FileUtils.readFile(dataBuffer.toString() + "vision.json");
  576. JSONObject json = JSONObject.parseObject(str);
  577. JSONArray panos = json.getJSONArray("sweepLocations");
  578. for (int i = 0; i < panos.size(); ++i) {
  579. JSONObject pano = panos.getJSONObject(i);
  580. for (int j = 0; j < inputData.size(); ++j) {
  581. JSONObject jo = inputData.getJSONObject(j);
  582. String currentPanoId = jo.getString("panoID");
  583. JSONArray visibles = jo.getJSONArray("visibles");
  584. JSONArray visibles3 = jo.getJSONArray("visibles3");
  585. if (pano.getString("uuid").equals(currentPanoId)) {
  586. pano.put("visibles", visibles);
  587. pano.put("visibles3", visibles3);
  588. }
  589. }
  590. }
  591. FileUtils.deleteFile(dataBuffer.toString() + "vision.json");
  592. FileUtils.deleteFile(dataBuffer.toString() + "vision.modeldata");
  593. FileUtils.writeFile(dataBuffer.toString() + "vision.json", json.toString());
  594. ConvertUtils.convertTxtToVisionModelData(dataBuffer.toString() + "vision.json", dataBuffer.toString() + "vision.modeldata");
  595. uploadToOssUtil.upload(dataBuffer.toString() + "vision.modeldata", imagesBuf.toString() + "vision.modeldata");
  596. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  597. JSONObject scenejson = new JSONObject();
  598. if(strsceneInfos!=null){
  599. scenejson = JSONObject.parseObject(strsceneInfos);
  600. }
  601. scenejson.put("version", scenejson.getIntValue("version") + 1);
  602. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  603. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  604. if (sceneProEdit == null ) {
  605. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  606. }
  607. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  608. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  609. sceneProEditService.updateById(sceneProEdit);
  610. return ResultData.ok();
  611. }
  612. @Override
  613. public ResultData getRecordAudioFromWeixin(SceneEditVO base) throws Exception{
  614. if(StringUtils.isEmpty(base.getSceneNum()) || StringUtils.isEmpty(base.getId())){
  615. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  616. }
  617. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  618. if(scenePro == null){
  619. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  620. }
  621. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  622. String accessToken = WeiXinUtils.getAccessToken();
  623. InputStream is = null;
  624. String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + base.getId();
  625. URL urlGet = new URL(url);
  626. HttpURLConnection http = (HttpURLConnection) urlGet
  627. .openConnection();
  628. http.setRequestMethod("GET"); // 必须是get方式请求
  629. http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  630. http.setDoOutput(true);
  631. http.setDoInput(true);
  632. System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
  633. System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
  634. http.connect();
  635. // 获取文件转化为byte流
  636. is = http.getInputStream();
  637. File dic = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum());
  638. if(!dic.exists())
  639. {
  640. dic.mkdirs();
  641. }
  642. File voice = new File(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  643. if(voice.exists())
  644. {
  645. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  646. }
  647. FileUtils.saveImageToDisk( accessToken, base.getId(), ConstantFileName.WECHAT_VOICE_NAME, ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator, is);
  648. try
  649. {
  650. FileUtils.changeVoiceToMp3(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  651. ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3");
  652. }
  653. catch(Exception e)
  654. {
  655. StringWriter trace=new StringWriter();
  656. e.printStackTrace(new PrintWriter(trace));
  657. log.error("voice:"+ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.VOICE_NAME+".amr");
  658. log.error(trace.toString());
  659. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  660. }
  661. String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3";
  662. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator +originalFileName, "voice/voice"+base.getSceneNum()+"/"+originalFileName);
  663. Map map = new HashMap();
  664. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  665. String voiceSrc = prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName;
  666. if("s3".equals(type)){
  667. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName;
  668. }
  669. map.put("screencapVoiceSoundsync", voiceSrc);
  670. log.info("微信上传的音频路径:{}", voiceSrc);
  671. map.put("screencapVoiceType", "soundsync");
  672. map.put("version", sceneProEdit.getVersion()+1);
  673. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + base.getSceneNum() + "/scene.json", map);
  674. sceneProEdit.setScreencapVoiceType("soundsync");
  675. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  676. sceneProEdit.setVersion(sceneProEdit.getVersion());
  677. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  678. sceneProEditService.updateById(sceneProEdit);
  679. FileUtils.deleteFile(ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+base.getSceneNum()+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  680. if("s3".equals(type)){
  681. return ResultData.ok(ConstantUrl.PREFIX_AWS+"voice/voice"+base.getSceneNum()+"/"+originalFileName);
  682. }
  683. return ResultData.ok(prefixAli+"voice/voice"+base.getSceneNum()+"/"+originalFileName);
  684. }
  685. @Override
  686. public ResultData getRecordAudioFromWeixinV3(String sceneNum, String id, String type, String fileName, String length, String replace, String times, String index) throws Exception {
  687. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(id)){
  688. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  689. }
  690. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  691. if(scenePro == null){
  692. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  693. }
  694. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  695. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  696. JSONObject scenejson = new JSONObject();
  697. if(strsceneInfos!=null) {
  698. scenejson = JSONObject.parseObject(strsceneInfos);
  699. }
  700. //文件上传的位置可以自定义
  701. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  702. log.info("path:" + path);
  703. this.saveImageToDisk(path, id);
  704. try
  705. {
  706. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  707. path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".mp3");
  708. }
  709. catch(Exception e)
  710. {
  711. StringWriter trace=new StringWriter();
  712. e.printStackTrace(new PrintWriter(trace));
  713. log.error("voice:"+path+File.separator+ConstantFileName.VOICE_NAME+".amr");
  714. log.error(trace.toString());
  715. return ResultData.error(ErrorCode.FAILURE_CODE_5005);
  716. }
  717. String originalFileName = ConstantFileName.WECHAT_VOICE_NAME+".mp3";
  718. //判断分房间模块文件夹是否存在
  719. String partPath = path + File.separator + "part";
  720. File partFile = new File(partPath);
  721. if(!partFile.exists()){
  722. partFile.mkdirs();
  723. }
  724. if(!"1".equals(replace)){
  725. return ResultData.ok(this.replaceForWeixinV3(sceneProEdit, scenejson,
  726. path, partPath, fileName, originalFileName, sceneNum, times));
  727. }
  728. FileUtils.delAllFile(path + File.separator + "part");
  729. //保存0.mp3文件到part
  730. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  731. partPath+File.separator+fileName);
  732. FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true);
  733. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  734. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  735. if("s3".equals(this.type)){
  736. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  737. }
  738. sceneProEdit.setScreencapVoiceType("soundsync");
  739. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  740. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  741. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  742. sceneProEditService.updateById(sceneProEdit);
  743. Map map = new HashMap();
  744. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  745. map.put("screencapVoiceSoundsync", voiceSrc);
  746. map.put("uploadVoiceSoundsync", 1);
  747. map.put("screencapVoiceType", type);
  748. map.put("version", scenejson.getIntValue("version")+1);
  749. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  750. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  751. return ResultData.ok(voiceSrc);
  752. }
  753. @Override
  754. public ResultData getRecordAudioFromAppV3(String sceneNum, String soundFile, String type, String fileName, String length, String replace, String times, String index) throws Exception {
  755. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(soundFile)){
  756. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  757. }
  758. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  759. if(scenePro == null){
  760. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  761. }
  762. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  763. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  764. JSONObject scenejson = new JSONObject();
  765. if(strsceneInfos!=null) {
  766. scenejson = JSONObject.parseObject(strsceneInfos);
  767. }
  768. String originalFileName = ConstantFileName.APP_VOICE_NAME+".mp3";
  769. //文件上传的位置可以自定义
  770. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  771. //判断分房间模块文件夹是否存在
  772. String partPath = path + File.separator + "part";
  773. File partFile = new File(partPath);
  774. if(!partFile.exists()){
  775. partFile.mkdirs();
  776. }
  777. if(!"1".equals(replace)){
  778. return ResultData.ok(this.replaceForAppV3(sceneProEdit, scenejson,
  779. path, partPath, fileName, originalFileName, sceneNum, times, soundFile));
  780. }
  781. FileUtils.delAllFile(path + File.separator + "part");
  782. if("s3".equals(this.type)){
  783. CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName);
  784. }else {
  785. CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator);
  786. new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName));
  787. }
  788. FileUtils.copyFile(partPath+File.separator+fileName, path + File.separator + originalFileName, true);
  789. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  790. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  791. if("s3".equals(this.type)){
  792. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  793. }
  794. sceneProEdit.setScreencapVoiceType("soundsync");
  795. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  796. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  797. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  798. sceneProEditService.updateById(sceneProEdit);
  799. Map map = new HashMap();
  800. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  801. map.put("screencapVoiceSoundsync", voiceSrc);
  802. map.put("uploadVoiceSoundsync", 1);
  803. map.put("screencapVoiceType", type);
  804. map.put("version", scenejson.getIntValue("version")+1);
  805. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  806. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  807. return ResultData.ok(voiceSrc);
  808. }
  809. @Override
  810. public ResultData deleteRecordAudioPart(String sceneNum, String fileName, String times, String index, String type) throws Exception {
  811. if(StringUtils.isEmpty(sceneNum)){
  812. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  813. }
  814. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  815. if(scenePro == null){
  816. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  817. }
  818. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  819. //文件上传的位置可以自定义
  820. String path = ConstantFilePath.SCENE_PATH+"voice"+File.separator+"voice"+sceneNum;
  821. File targetFile = new File(path);
  822. if (!targetFile.exists()) {
  823. targetFile.mkdirs();
  824. }
  825. //默认为app文件名
  826. String originalFileName = ConstantFileName.APP_VOICE_NAME + ".mp3";
  827. if("wechat".equals(type)){
  828. originalFileName = ConstantFileName.WECHAT_VOICE_NAME + ".mp3";
  829. }
  830. log.info("上传的音频文件名:" + originalFileName);
  831. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json");
  832. JSONObject scenejson = new JSONObject();
  833. if(strsceneInfos!=null) {
  834. scenejson = JSONObject.parseObject(strsceneInfos);
  835. }
  836. //判断分房间模块文件夹是否存在
  837. String partPath = path + File.separator + "part";
  838. File partFile = new File(partPath);
  839. if(!partFile.exists()){
  840. partFile.mkdirs();
  841. }
  842. //删除指定部分音频文件
  843. FileUtils.deleteFile(partPath + File.separator + index + ".mp3");
  844. //获取总音频多少段,每段时长
  845. String[] time = times.split(",");
  846. //删除所有音频
  847. if(StringUtils.isEmpty(times) || time.length == 0){
  848. this.deleteAudio(sceneProEdit, scenejson, sceneNum);
  849. return ResultData.ok();
  850. }
  851. //修改删除的部分视频后面部分音频名字,如删除1.MP3,则将2.mp3修改成1.mp3,往后以此类推
  852. if(Integer.parseInt(index) < time.length) {
  853. for(int i = 0, len = time.length - Integer.parseInt(index); i < len; i++){
  854. if(new File(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3").exists()){
  855. FileUtils.copyFile(partPath + File.separator + (Integer.parseInt(index) + 1 + i) + ".mp3",
  856. partPath + File.separator + (Integer.parseInt(index) + i) + ".mp3", true);
  857. }
  858. }
  859. }
  860. //遍历判断音频是否存在,不存在生成空白音效
  861. for(int i = 0, len = time.length; i < len; i++){
  862. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  863. //某部分文件不存在,直接生成一段静音后拼接文件
  864. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  865. }
  866. }
  867. //拼接所有音频文件
  868. if(time.length > 2){
  869. //若是多部分,两个两个合并,最后合成最终文件
  870. for(int i = 1, len = time.length; i < len; i++){
  871. if(i == 1){
  872. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  873. partPath + File.separator + i + "muteSound.mp3");
  874. }else if(i == len - 1){
  875. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  876. path + File.separator + originalFileName);
  877. }else {
  878. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  879. partPath + File.separator + i + "muteSound.mp3");
  880. }
  881. }
  882. }else if(time.length == 2){
  883. //若只有两部分,直接合并成最终文件
  884. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  885. }else {
  886. FileUtils.copyFile(partPath + File.separator + "0.mp3", path + File.separator + originalFileName, true);
  887. }
  888. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  889. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  890. if("s3".equals(this.type)){
  891. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  892. }
  893. Map map = new HashMap();
  894. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  895. map.put("screencapVoiceSoundsync", voiceSrc);
  896. map.put("uploadVoiceSoundsync", 0);
  897. map.put("screencapVoiceType", "soundsync");
  898. map.put("version", scenejson.getIntValue("version")+1);
  899. sceneProEdit.setScreencapVoiceType("soundsync");
  900. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  901. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  902. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  903. sceneProEditService.updateById(sceneProEdit);
  904. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  905. return ResultData.ok(voiceSrc);
  906. }
  907. @Override
  908. public ResultData uploadFloorJsonAndRebuild(SceneEditVO sceneEdit) throws Exception {
  909. String lockKey = String.format(RedisKey.LOCK_UPLOAD_FLOORJSON_REBUILD, sceneEdit.getSceneNum());
  910. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_2_HOUR);
  911. if(!lock){
  912. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  913. }
  914. try {
  915. long start = System.currentTimeMillis();
  916. log.info("画墙重建模型开始时间:{}", start);
  917. if(StringUtils.isEmpty(sceneEdit.getSceneNum())){
  918. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  919. }
  920. ScenePro scenePro = baseMapper.findByNum(sceneEdit.getSceneNum());
  921. if(scenePro == null){
  922. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  923. }
  924. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  925. if(sceneProEdit == null){
  926. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  927. }
  928. //更新scene.json文件
  929. String strsceneInfos = FileUtils.readFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json");
  930. JSONObject scenejson = new JSONObject();
  931. if(strsceneInfos!=null)
  932. {
  933. scenejson = JSONObject.parseObject(strsceneInfos);
  934. }else {
  935. new File(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + sceneEdit.getSceneNum() + File.separator + "scene.json").createNewFile();
  936. }
  937. if(!StringUtils.isEmpty(sceneEdit.getSceneData())){
  938. JSONObject sceneObject = JSONObject.parseObject(sceneEdit.getSceneData());
  939. Set<String> set =sceneObject.keySet();
  940. for(String key : set){
  941. scenejson.put(key, sceneObject.get(key));
  942. }
  943. }
  944. //保存floor.json前端下次进入需要使用
  945. if(StringUtils.isEmpty(sceneEdit.getWebFloor())){
  946. sceneEdit.setWebFloor(sceneEdit.getFloor());
  947. }
  948. //上传过模型只更新floor.json
  949. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json",
  950. new String(sceneEdit.getWebFloor().getBytes(), "UTF-8"));
  951. //更新scene.json文件
  952. if(strsceneInfos!=null)
  953. {
  954. scenejson.put("floorEditVer", sceneProEdit.getFloorPublishVer() + 1);
  955. scenejson.put("floorPublishVer", sceneProEdit.getFloorPublishVer() + 1);
  956. FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum()+File.separator+"scene.json", scenejson.toString());
  957. log.info("写入scene.json文件完成, sceneCode:{}", sceneEdit.getSceneNum());
  958. }
  959. //floorEditVer字段增加1
  960. sceneProEdit.setFloorEditVer(sceneProEdit.getFloorPublishVer() + 1);
  961. sceneProEdit.setFloorPublishVer(sceneProEdit.getFloorPublishVer() + 1);
  962. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  963. sceneProEditService.updateById(sceneProEdit);
  964. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json",
  965. "data"+File.separator+"data"+sceneEdit.getSceneNum() + File.separator + "floor.json");
  966. }catch (Exception e){
  967. log.error("画墙重建模型失败...", e);
  968. throw new BusinessException(ErrorCode.FAILURE_CODE_5039);
  969. }finally {
  970. redisLockUtil.unlock(lockKey);
  971. }
  972. return ResultData.ok();
  973. }
  974. @Override
  975. public ResultData saveScreencapData(SceneEditVO base) throws Exception {
  976. if(StringUtils.isEmpty(base.getSceneNum())){
  977. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  978. }
  979. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  980. if(scenePro == null){
  981. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  982. }
  983. StringBuffer dataBuf = new StringBuffer()
  984. .append("data").append(File.separator)
  985. .append("data").append(scenePro.getSceneCode())
  986. .append(File.separator);
  987. StringBuffer imagesBuf = new StringBuffer()
  988. .append("images").append(File.separator)
  989. .append("images").append(scenePro.getSceneCode())
  990. .append(File.separator);
  991. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  992. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  993. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  994. JSONObject scenejson = new JSONObject();
  995. if(strsceneInfos!=null) {
  996. scenejson = JSONObject.parseObject(strsceneInfos);
  997. }
  998. //上传七牛
  999. Map<String,String> map = new HashMap<String,String>();
  1000. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1001. scenejson.put("screencapVoiceSound", "");
  1002. sceneProEdit.setScreencapVoiceSound("");
  1003. if(base.getScreencapVoiceType() != null){
  1004. scenejson.put("screencapVoiceType", base.getScreencapVoiceType());
  1005. sceneProEdit.setScreencapVoiceType(base.getScreencapVoiceType());
  1006. }
  1007. if(!StringUtils.isEmpty(base.getCapData())){
  1008. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1009. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1010. }
  1011. if(!StringUtils.isEmpty(base.getFrameData())){
  1012. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1013. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1014. }
  1015. if(!StringUtils.isEmpty(base.getPlayData())){
  1016. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1017. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1018. sceneProEdit.setPlayData(dataBuf.toString() + "playData.json");
  1019. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  1020. }
  1021. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  1022. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1023. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1024. sceneProEdit.setScreencapThumb(dataBuf.toString() + "screencapThumb.json");
  1025. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  1026. }
  1027. if(!StringUtils.isEmpty(base.getRecordType())){
  1028. scenejson.put("recordType", base.getRecordType());
  1029. }
  1030. if(map.size()>0) {
  1031. uploadToOssUtil.uploadMulFiles(map);
  1032. }
  1033. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1034. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1035. sceneProEditService.updateById(sceneProEdit);
  1036. log.info("scene.json路径:" + dataBuffer.toString() + "scene.json");
  1037. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1038. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1039. return ResultData.ok();
  1040. }
  1041. public ResultData saveAllVisi(SceneEditVO base) throws Exception {
  1042. if(StrUtil.isEmpty(base.getSceneNum())){
  1043. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1044. }
  1045. ScenePro scenePro = baseMapper.findByNum(base.getSceneNum());
  1046. if(scenePro == null){
  1047. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1048. }
  1049. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1050. StringBuffer dataBuf = new StringBuffer()
  1051. .append("data").append(File.separator)
  1052. .append("data").append(scenePro.getSceneCode())
  1053. .append(File.separator);
  1054. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1055. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1056. JSONObject scenejson = new JSONObject();
  1057. if(strsceneInfos!=null) {
  1058. scenejson = JSONObject.parseObject(strsceneInfos);
  1059. }
  1060. this.updateVisiData(base, sceneProEdit, scenejson);
  1061. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1062. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1063. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1064. sceneProEditService.updateById(sceneProEdit);
  1065. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1066. return ResultData.ok();
  1067. }
  1068. @Override
  1069. public ResultData uploadFloorplanPng(String sceneNum, MultipartFile file, String cadInfo) throws Exception {
  1070. if(StringUtils.isEmpty(sceneNum)){
  1071. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1072. }
  1073. if (file.isEmpty() && file.getSize() <= 0) {
  1074. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1075. }
  1076. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1077. if(scenePro == null){
  1078. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1079. }
  1080. String lockKey = String.format(RedisKey.LOCK_UPLOAD_FLOORPLAN_PNG, sceneNum);
  1081. Boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_30_MINUTE);
  1082. if(!lock){
  1083. throw new BusinessException(ErrorCode.FAILURE_CODE_5036);
  1084. }
  1085. String fileName = "floorplan.png";
  1086. try {
  1087. StringBuffer dataBuf = new StringBuffer()
  1088. .append("data").append(File.separator)
  1089. .append("data").append(scenePro.getSceneCode())
  1090. .append(File.separator);
  1091. StringBuffer imagesBuf = new StringBuffer()
  1092. .append("images").append(File.separator)
  1093. .append("images").append(scenePro.getSceneCode())
  1094. .append(File.separator);
  1095. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1096. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1097. //文件上传的位置可以自定义
  1098. String path = ConstantFilePath.SCENE_PATH+"images"+File.separator+"images"+sceneNum;
  1099. File targetFile = new File(path);
  1100. if (!targetFile.exists()) {
  1101. targetFile.mkdirs();
  1102. }
  1103. targetFile = new File(path + File.separator + fileName);
  1104. // 保存
  1105. if(targetFile.exists())
  1106. {
  1107. FileUtils.deleteFile(path + File.separator + fileName);
  1108. }
  1109. file.transferTo(targetFile);
  1110. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1111. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1112. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1113. String floorPlanPng = "images"+File.separator+"images"+sceneNum + File.separator + fileName;
  1114. Map<String, Object> map = new HashMap<>();
  1115. map.put("floorPlanPng", floorPlanPng);
  1116. map.put("uploadFloorPlanPng", 1);
  1117. map.put("version", sceneProEdit.getVersion()+1);
  1118. if(StrUtil.isNotEmpty(cadInfo)){
  1119. map.put("cadInfo", cadInfo);
  1120. sceneProEditExt.setCadInfo(cadInfo);
  1121. }
  1122. sceneProEditExt.setFloorPlanPng(floorPlanPng + "?t=" + System.currentTimeMillis());
  1123. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1124. sceneProEditExtService.updateById(sceneProEditExt);
  1125. sceneProEdit.setVersion(sceneProEdit.getVersion() + 1);
  1126. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1127. sceneProEditService.updateById(sceneProEdit);
  1128. FileUtils.writeJsonFile(dataBuffer.toString() + "scene.json", map);
  1129. uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+floorPlanPng, floorPlanPng);
  1130. }catch (Exception e){
  1131. log.error("上传图片多媒体数据失败...", e);
  1132. throw new BusinessException(ErrorCode.FAILURE_CODE_5041);
  1133. }finally {
  1134. redisLockUtil.unlock(lockKey);
  1135. }
  1136. return ResultData.ok("images"+File.separator+"images"+sceneNum + File.separator + fileName);
  1137. }
  1138. @Override
  1139. public ResultData uploadBgMusic(String sceneNum, String fileName, MultipartFile file) throws Exception {
  1140. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(fileName)){
  1141. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1142. }
  1143. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1144. if(scenePro == null){
  1145. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1146. }
  1147. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1148. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1149. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1150. StringBuffer dataBuf = new StringBuffer()
  1151. .append("data").append(File.separator)
  1152. .append("data").append(scenePro.getSceneCode())
  1153. .append(File.separator);
  1154. StringBuffer imagesBuf = new StringBuffer()
  1155. .append("images").append(File.separator)
  1156. .append("images").append(scenePro.getSceneCode())
  1157. .append(File.separator);
  1158. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1159. StringBuffer imagesBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(imagesBuf.toString());
  1160. File buMusicFile = new File(imagesBuffer.toString() + fileName);
  1161. if(!buMusicFile.getParentFile().exists()){
  1162. buMusicFile.getParentFile().mkdirs();
  1163. }
  1164. //上传文件
  1165. file.transferTo(buMusicFile);
  1166. uploadToOssUtil.upload(imagesBuffer.toString() + fileName, imagesBuf + fileName);
  1167. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1168. JSONObject scenejson = new JSONObject();
  1169. if(strsceneInfos!=null) {
  1170. scenejson = JSONObject.parseObject(strsceneInfos);
  1171. }
  1172. sceneProEditExt.setBgMusicName(fileName);
  1173. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1174. sceneProEditExtService.updateById(sceneProEditExt);
  1175. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1176. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1177. sceneProEditService.updateById(sceneProEdit);
  1178. scenejson.put("bgMusicName", fileName);
  1179. scenejson.put("uploadBgMusic", 0);
  1180. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1181. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1182. return ResultData.ok();
  1183. }
  1184. @Override
  1185. public ResultData deleteUploadBgMusic(String sceneNum) throws Exception {
  1186. if(StringUtils.isEmpty(sceneNum)){
  1187. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  1188. }
  1189. ScenePro scenePro = baseMapper.findByNum(sceneNum);
  1190. if(scenePro == null){
  1191. throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  1192. }
  1193. SceneProEdit sceneProEdit = sceneProEditService.findByProId(scenePro.getId());
  1194. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1195. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1196. StringBuffer dataBuf = new StringBuffer()
  1197. .append("data").append(File.separator)
  1198. .append("data").append(scenePro.getSceneCode())
  1199. .append(File.separator);
  1200. StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
  1201. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1202. JSONObject scenejson = new JSONObject();
  1203. if(strsceneInfos!=null) {
  1204. scenejson = JSONObject.parseObject(strsceneInfos);
  1205. }
  1206. sceneProEditExt.setBgMusicName("");
  1207. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1208. sceneProEditExtService.updateById(sceneProEditExt);
  1209. sceneProEdit.setVersion(scenejson.getIntValue("version") + 1);
  1210. sceneProEditService.updateById(sceneProEdit);
  1211. scenejson.put("bgMusicName", "");
  1212. scenejson.put("version", scenejson.getIntValue("version") + 1);
  1213. FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
  1214. return ResultData.ok();
  1215. }
  1216. private void updateVisiData(SceneEditVO base, SceneProEdit sceneProEdit, JSONObject scenejson){
  1217. SceneProEditExt sceneProEditExt = sceneProEditExtService.getOne(
  1218. new QueryWrapper<SceneProEditExt>().eq("pro_edit_id", sceneProEdit.getId()));
  1219. if(!StringUtils.isEmpty(base.getMapVisi())){
  1220. scenejson.put("mapVisi", Integer.parseInt(base.getMapVisi()));
  1221. sceneProEditExt.setMapVisi(Integer.parseInt(base.getMapVisi()));
  1222. }
  1223. if(!StringUtils.isEmpty(base.getTourVisi())){
  1224. scenejson.put("tourVisi", Integer.parseInt(base.getTourVisi()));
  1225. sceneProEditExt.setTourVisi(Integer.parseInt(base.getTourVisi()));
  1226. }
  1227. if(!StringUtils.isEmpty(base.getVrVisi())){
  1228. scenejson.put("vrVisi", Integer.parseInt(base.getVrVisi()));
  1229. sceneProEditExt.setVrVisi(Integer.parseInt(base.getVrVisi()));
  1230. }
  1231. if(!StringUtils.isEmpty(base.getRulerVisi())){
  1232. scenejson.put("rulerVisi", Integer.parseInt(base.getRulerVisi()));
  1233. sceneProEditExt.setRulerVisi(Integer.parseInt(base.getRulerVisi()));
  1234. }
  1235. if(!StringUtils.isEmpty(base.getCadImgVisi())){
  1236. scenejson.put("cadImgVisi", Integer.parseInt(base.getCadImgVisi()));
  1237. sceneProEditExt.setCadImgVisi(Integer.parseInt(base.getCadImgVisi()));
  1238. }
  1239. if(!StringUtils.isEmpty(base.getPanoVisi())){
  1240. scenejson.put("panoVisi", Integer.parseInt(base.getPanoVisi()));
  1241. sceneProEditExt.setPanoVisi(Integer.parseInt(base.getPanoVisi()));
  1242. }
  1243. if(!StringUtils.isEmpty(base.getM2dVisi())){
  1244. scenejson.put("m2dVisi", Integer.parseInt(base.getM2dVisi()));
  1245. sceneProEditExt.setM2dVisi(Integer.parseInt(base.getM2dVisi()));
  1246. }
  1247. if(!StringUtils.isEmpty(base.getM3dVisi())){
  1248. scenejson.put("m3dVisi", Integer.parseInt(base.getM3dVisi()));
  1249. sceneProEditExt.setM3dVisi(Integer.parseInt(base.getM3dVisi()));
  1250. }
  1251. if(!StringUtils.isEmpty(base.getMeasureVisi())){
  1252. scenejson.put("measureVisi", Integer.parseInt(base.getMeasureVisi()));
  1253. sceneProEditExt.setMeasureVisi(Integer.parseInt(base.getMeasureVisi()));
  1254. }
  1255. sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1256. sceneProEditExtService.updateById(sceneProEditExt);
  1257. }
  1258. private void deleteAudio(SceneProEdit sceneProEdit, JSONObject scenejson, String sceneNum) throws Exception {
  1259. sceneProEdit.setScreencapVoiceType("");
  1260. sceneProEdit.setScreencapVoiceSoundsync("");
  1261. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1262. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1263. sceneProEditService.updateById(sceneProEdit);
  1264. Map map = new HashMap();
  1265. map.put("screencapVoiceSoundsyncFileName", "");
  1266. map.put("screencapVoiceSoundsync", "");
  1267. map.put("uploadVoiceSoundsync", 0);
  1268. map.put("screencapVoiceType", "");
  1269. map.put("version", scenejson.getIntValue("version")+1);
  1270. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1271. }
  1272. private String replaceForAppV3(SceneProEdit sceneProEdit, JSONObject scenejson,
  1273. String path, String partPath, String fileName,
  1274. String originalFileName, String sceneNum, String times, String soundFile) throws Exception {
  1275. if(new File(partPath+File.separator+fileName).exists()) {
  1276. FileUtils.deleteFile(partPath + File.separator + fileName);
  1277. }
  1278. if("s3".equals(this.type)){
  1279. CreateObjUtil.ossFileCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator + fileName);
  1280. }else {
  1281. CreateObjUtil.ossUtilCp("voice"+File.separator+"voice"+sceneNum + "/" + soundFile, partPath + File.separator);
  1282. new File(partPath + File.separator + soundFile).renameTo(new File(partPath + File.separator + fileName));
  1283. }
  1284. //获取总音频多少段,每段时长
  1285. String[] time = times.split(",");
  1286. //遍历判断音频是否存在,不存在生成空白音效
  1287. for(int i = 0, len = time.length; i < len; i++){
  1288. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1289. //某部分文件不存在,直接生成一段静音后拼接文件
  1290. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1291. }
  1292. }
  1293. //拼接所有音频文件
  1294. if(time.length > 2){
  1295. //若是多部分,两个两个合并,最后合成最终文件
  1296. for(int i = 1, len = time.length; i < len; i++){
  1297. if(i == 1){
  1298. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1299. partPath + File.separator + i + "muteSound.mp3");
  1300. }else if(i == len - 1){
  1301. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1302. path + File.separator + originalFileName);
  1303. }else {
  1304. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1305. partPath + File.separator + i + "muteSound.mp3");
  1306. }
  1307. }
  1308. }else {
  1309. //若只有两部分,直接合并成最终文件
  1310. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1311. }
  1312. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  1313. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  1314. if("s3".equals(this.type)){
  1315. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  1316. }
  1317. sceneProEdit.setScreencapVoiceType("soundsync");
  1318. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  1319. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1320. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1321. sceneProEditService.updateById(sceneProEdit);
  1322. Map map = new HashMap();
  1323. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1324. map.put("screencapVoiceSoundsync", voiceSrc);
  1325. map.put("uploadVoiceSoundsync", 1);
  1326. map.put("screencapVoiceType", type);
  1327. map.put("version", scenejson.getIntValue("version")+1);
  1328. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1329. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1330. return voiceSrc;
  1331. }
  1332. private String replaceForWeixinV3(SceneProEdit sceneProEdit, JSONObject scenejson,
  1333. String path, String partPath, String fileName,
  1334. String originalFileName, String sceneNum, String times) throws Exception {
  1335. this.dealVioce(path, partPath, fileName, originalFileName, sceneNum, times);
  1336. String voiceSrc = prefixAli+"voice/voice"+sceneNum+"/"+originalFileName;
  1337. if("s3".equals(this.type)){
  1338. voiceSrc = ConstantUrl.PREFIX_AWS+"voice/voice"+sceneNum+"/"+originalFileName;
  1339. }
  1340. Map map = new HashMap();
  1341. map.put("screencapVoiceSoundsyncFileName", originalFileName);
  1342. map.put("screencapVoiceSoundsync", voiceSrc);
  1343. map.put("uploadVoiceSoundsync", 1);
  1344. map.put("screencapVoiceType", type);
  1345. map.put("version", scenejson.getIntValue("version")+1);
  1346. sceneProEdit.setScreencapVoiceType("soundsync");
  1347. sceneProEdit.setScreencapVoiceSoundsync(voiceSrc);
  1348. sceneProEdit.setVersion(scenejson.getIntValue("version")+1);
  1349. sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1350. sceneProEditService.updateById(sceneProEdit);
  1351. FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + File.separator + "scene.json", map);
  1352. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1353. return voiceSrc;
  1354. }
  1355. private void dealVioce(String path, String partPath, String fileName, String originalFileName, String sceneNum, String times) throws Exception {
  1356. if(new File(partPath+File.separator+fileName).exists()) {
  1357. FileUtils.deleteFile(partPath + File.separator + fileName);
  1358. }
  1359. FileUtils.changeVoiceToMp3(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr",
  1360. partPath+File.separator+fileName);
  1361. //获取总音频多少段,每段时长
  1362. String[] time = times.split(",");
  1363. //遍历判断音频是否存在,不存在生成空白音效
  1364. for(int i = 0, len = time.length; i < len; i++){
  1365. if(!new File(partPath + File.separator + i + ".mp3").exists()){
  1366. //某部分文件不存在,直接生成一段静音后拼接文件
  1367. CreateObjUtil.createMuteViode(Double.valueOf(time[i]), partPath + File.separator + i + ".mp3");
  1368. }
  1369. }
  1370. //拼接所有音频文件
  1371. if(time.length > 2){
  1372. //若是多部分,两个两个合并,最后合成最终文件
  1373. for(int i = 1, len = time.length; i < len; i++){
  1374. if(i == 1){
  1375. // FileUtils.deleteFile(partPath + File.separator + i + "muteSound.mp3");
  1376. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + ".mp3", partPath + File.separator + i + ".mp3",
  1377. partPath + File.separator + i + "muteSound.mp3");
  1378. }else if(i == len - 1){
  1379. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1380. path + File.separator + originalFileName);
  1381. }else {
  1382. CreateObjUtil.mergeVideo(partPath + File.separator + (i - 1) + "muteSound.mp3", partPath + File.separator + i + ".mp3",
  1383. partPath + File.separator + i + "muteSound.mp3");
  1384. }
  1385. }
  1386. }else {
  1387. //若只有两部分,直接合并成最终文件
  1388. CreateObjUtil.mergeVideo(partPath + File.separator + "0.mp3", partPath + File.separator + "1.mp3", path + File.separator + originalFileName);
  1389. }
  1390. uploadToOssUtil.upload(path+File.separator +originalFileName, "voice/voice"+sceneNum+"/"+originalFileName);
  1391. }
  1392. private void saveImageToDisk(String path, String id) throws Exception {
  1393. String accessToken = WeiXinUtils.getAccessToken();
  1394. InputStream is = null;
  1395. String url = "https://file.api.weixin.qq.com/cgi-bin/media/get?access_token="+ accessToken + "&media_id=" + id;
  1396. log.info("url:" + url);
  1397. URL urlGet = new URL(url);
  1398. HttpURLConnection http = (HttpURLConnection) urlGet
  1399. .openConnection();
  1400. http.setRequestMethod("GET"); // 必须是get方式请求
  1401. http.setRequestProperty("Content-Type",
  1402. "application/x-www-form-urlencoded");
  1403. http.setDoOutput(true);
  1404. http.setDoInput(true);
  1405. System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
  1406. System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
  1407. http.connect();
  1408. // 获取文件转化为byte流
  1409. is = http.getInputStream();
  1410. File dic = new File(path);
  1411. if(!dic.exists())
  1412. {
  1413. dic.mkdirs();
  1414. }
  1415. File voice = new File(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1416. if(voice.exists())
  1417. {
  1418. FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
  1419. }
  1420. FileUtils.saveImageToDisk(accessToken, id, ConstantFileName.WECHAT_VOICE_NAME, path+File.separator, is);
  1421. }
  1422. private Object[] getUploadFileMapAndSceneJson(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid,
  1423. StringBuffer imagesBuf, StringBuffer imagesBuffer,
  1424. StringBuffer dataBuf, StringBuffer dataBuffer) throws Exception {
  1425. Object[] result = new Object[2];
  1426. Map<String,String> map = new HashMap<String,String>();
  1427. if(jsonhot.containsKey("media")) {
  1428. String fileType = jsonhot.getString("media");
  1429. if(fileType.contains("photo")) {
  1430. if("-1".equals(base.getType())) {
  1431. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".jpg");
  1432. }
  1433. else {
  1434. map.put(imagesBuffer.toString() + "hot"+sid+".jpg", imagesBuf.toString() + "hot"+sid+".jpg");
  1435. }
  1436. }
  1437. if(fileType.contains("audio") || fileType.contains("voice")) {
  1438. if("-1".equals(base.getType())) {
  1439. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp3");
  1440. }
  1441. else {
  1442. map.put(imagesBuffer.toString() + "hot"+sid+".mp3", imagesBuf.toString() + "hot"+sid+".mp3");
  1443. }
  1444. }
  1445. if(fileType.contains("video")) {
  1446. if("-1".equals(base.getType())) {
  1447. FileUtils.deleteFile(imagesBuffer.toString() + "hot"+sid+".mp4");
  1448. }
  1449. else
  1450. {
  1451. map.put(imagesBuffer.toString() + "hot"+sid+".mp4", imagesBuf.toString() + "hot"+sid+".mp4");
  1452. map.put(imagesBuffer.toString() + "hot"+sid+"-cut.jpg", imagesBuf.toString() + "hot"+sid+"-cut.jpg");
  1453. }
  1454. }
  1455. }
  1456. FileUtils.deleteFile(dataBuffer.toString() + "hot.json");
  1457. File dataPath = new File(dataBuffer.toString());
  1458. if(!dataPath.exists()){
  1459. dataPath.mkdirs();
  1460. }
  1461. FileUtils.writeFile(dataBuffer.toString() + "hot.json", jsonhots.toString());
  1462. map.put(dataBuffer.toString() + "hot.json", dataBuf.toString() + "hot.json");
  1463. String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
  1464. JSONObject scenejson = new JSONObject();
  1465. if(strsceneInfos!=null){
  1466. scenejson = JSONObject.parseObject(strsceneInfos);
  1467. }
  1468. if(!StringUtils.isEmpty(base.getCapData())){
  1469. FileUtils.writeFile(dataBuffer.toString() + "capData.json", new String(base.getCapData().getBytes(), "UTF-8"));
  1470. scenejson.put("capData", dataBuf.toString() + "capData.json");
  1471. }
  1472. if(!StringUtils.isEmpty(base.getFrameData())){
  1473. FileUtils.writeFile(dataBuffer.toString() + "frameData.json", new String(base.getFrameData().getBytes(), "UTF-8"));
  1474. scenejson.put("frameData", dataBuf.toString() + "frameData.json");
  1475. }
  1476. if(!StringUtils.isEmpty(base.getPlayData())){
  1477. FileUtils.writeFile(dataBuffer.toString() + "playData.json", new String(base.getPlayData().getBytes(), "UTF-8"));
  1478. scenejson.put("playData", dataBuf.toString() + "playData.json");
  1479. map.put(dataBuffer.toString() + "playData.json", dataBuf.toString() + "playData.json");
  1480. }
  1481. if(!StringUtils.isEmpty(base.getScreencapThumb())){
  1482. FileUtils.writeFile(dataBuffer.toString() + "screencapThumb.json", new String(base.getScreencapThumb().getBytes(), "UTF-8"));
  1483. scenejson.put("screencapThumb", dataBuf.toString() + "screencapThumb.json");
  1484. map.put(dataBuffer.toString() + "screencapThumb.json", dataBuf.toString() + "screencapThumb.json");
  1485. }
  1486. if(jsonhots.size()>0){
  1487. scenejson.put("hots", 1);
  1488. }
  1489. else{
  1490. scenejson.put("hots", 0);
  1491. }
  1492. result[0] = map;
  1493. result[1] = scenejson;
  1494. return result;
  1495. }
  1496. private String deleteCustomStyleHots(SceneEditVO base, JSONArray jsonhots, JSONObject jsonhot, String sid){
  1497. String hotsids = "";
  1498. String[] styles = null;
  1499. if(StrUtil.isNotEmpty(base.getStyleName())){
  1500. styles = base.getStyleName().split(",");
  1501. }
  1502. for(int i=0;i<jsonhots.size();++i) {
  1503. JSONObject ele = jsonhots.getJSONObject(i);
  1504. //名字对应上就删除
  1505. if(styles != null){
  1506. for(String style : styles){
  1507. if(style.equals(ele.getString("styleId"))){
  1508. jsonhots.getJSONObject(i).put("styleId", null);
  1509. jsonhots.getJSONObject(i).put("style", "default");
  1510. jsonhots.getJSONObject(i).put("styleImageURL", null);
  1511. }
  1512. }
  1513. }
  1514. hotsids += ele.getString("sid") +",";
  1515. if(ele.getString("sid").equals(sid)) {
  1516. if("-1".equals(base.getType())) {
  1517. jsonhots.remove(i);
  1518. jsonhot = ele;
  1519. if(!"s3".equals(this.type)){
  1520. JSONObject paramData = new JSONObject();
  1521. paramData.put("hotId", sid);
  1522. JSONObject hotListJson = JSONObject.parseObject(OkHttpUtils.httpGet(hotDomainList));
  1523. if(hotListJson != null){
  1524. JSONArray hotListArray = hotListJson.getJSONArray("data");
  1525. if(hotListArray != null){
  1526. for(int l = 0, len = hotListArray.size(); l < len; l++){
  1527. OkHttpUtils.httpPostJson(hotListArray.getString(l) + hotDelete + "?hotId=" + sid
  1528. , paramData.toJSONString());
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. else if("0".equals(base.getType())) {
  1535. jsonhots.set(i, jsonhot);
  1536. }
  1537. }
  1538. }
  1539. return hotsids;
  1540. }
  1541. private JSONArray getJsonhots(SceneEditVO base, StringBuffer dataBuffer, JSONObject jsonhot) throws Exception {
  1542. String str = FileUtils.readFile(dataBuffer.toString() + "hot.json");
  1543. JSONArray jsonhots = null;
  1544. if (StrUtil.isNotEmpty(str)) {
  1545. jsonhots = JSONArray.parseArray(str);
  1546. }else {
  1547. File file = new File(dataBuffer.toString() + "hot.json");
  1548. if(!file.getParentFile().exists()){
  1549. file.getParentFile().mkdirs();
  1550. }
  1551. if(!file.exists()){
  1552. file.createNewFile();
  1553. }
  1554. jsonhots = new JSONArray();
  1555. }
  1556. if(SceneEditType.ADD.code().equals(base.getType())){
  1557. jsonhots.add(jsonhot);
  1558. }
  1559. return jsonhots;
  1560. }
  1561. private String getSidFromParams(SceneEditVO base, JSONObject jsonhot){
  1562. String sid = base.getSid();
  1563. //添加或者修改
  1564. if(SceneEditType.ADD.code().equals(base.getType())){
  1565. sid = jsonhot.getString("sid");
  1566. if(StrUtil.isEmpty(sid)){
  1567. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1568. }
  1569. }
  1570. else if(SceneEditType.UPDATE.code().equals(base.getType())){
  1571. sid = jsonhot.getString("sid");
  1572. if(StrUtil.isEmpty(sid)){
  1573. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1574. }
  1575. }
  1576. else if(SceneEditType.DELETE.code().equals(base.getType())){
  1577. if(StrUtil.isEmpty(sid)){
  1578. throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
  1579. }
  1580. }
  1581. return sid;
  1582. }
  1583. }