AppSceneService.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package com.fdkankan.ucenter.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.fdkankan.common.util.JwtUtil;
  5. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  6. import com.fdkankan.ucenter.common.BaseController;
  7. import com.fdkankan.ucenter.common.SceneSourceUtil;
  8. import com.fdkankan.ucenter.common.constants.ConstantFilePath;
  9. import com.fdkankan.common.constant.SceneConstant;
  10. import com.fdkankan.common.exception.BusinessException;
  11. import com.fdkankan.ucenter.common.PageInfo;
  12. import com.fdkankan.common.util.FileUtils;
  13. import com.fdkankan.redis.util.RedisUtil;
  14. import com.fdkankan.ucenter.common.OssPath;
  15. import com.fdkankan.ucenter.constant.CameraConstant;
  16. import com.fdkankan.ucenter.constant.CameraTypelEnum;
  17. import com.fdkankan.ucenter.constant.LoginConstant;
  18. import com.fdkankan.ucenter.entity.*;
  19. import com.fdkankan.ucenter.httpClient.service.LaserService;
  20. import com.fdkankan.ucenter.mapper.IScenePlusMapper;
  21. import com.fdkankan.ucenter.service.*;
  22. import com.fdkankan.ucenter.vo.request.AppSceneParam;
  23. import com.fdkankan.ucenter.vo.response.AppSceneVo;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.codec.language.Nysiis;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.beans.factory.annotation.Value;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.util.ObjectUtils;
  31. import javax.annotation.Resource;
  32. import java.io.File;
  33. import java.util.*;
  34. import java.util.stream.Collectors;
  35. @Service
  36. @Slf4j
  37. public class AppSceneService extends BaseController {
  38. @Autowired
  39. IUserService userService;
  40. @Autowired
  41. ICameraService cameraService;
  42. @Autowired
  43. ICameraDetailService cameraDetailService;
  44. @Autowired
  45. ISceneProService sceneProService;
  46. @Autowired
  47. IScenePlusService scenePlusService;
  48. @Autowired
  49. IScenePlusExtService scenePlusExtService;
  50. @Autowired
  51. ISceneEditInfoService sceneEditInfoService;
  52. @Autowired
  53. ISceneProEditService sceneProEditService;
  54. @Autowired
  55. IUserIncrementService userIncrementService;
  56. @Autowired
  57. RedisUtil redisUtil;
  58. @Autowired
  59. ISceneCooperationService sceneCooperationService;
  60. @Autowired
  61. LaserService laserService;
  62. @Autowired
  63. ISceneCopyLogService sceneCopyLogService;
  64. @Autowired
  65. IScenePlusMapper scenePlusMapper;
  66. @Autowired
  67. IExceedSpaceSceneService exceedSpaceSceneService;
  68. @Autowired
  69. FYunFileServiceInterface fYunFileServiceInterface;
  70. @Value("${fyun.host}")
  71. private String ossHost;
  72. public PageInfo pageList(AppSceneParam param) {
  73. if(StringUtils.isEmpty(param.getAppUserName()) && StringUtils.isEmpty(param.getPhoneNum())){
  74. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  75. }
  76. CameraTypelEnum cameraTypelEnum = CameraTypelEnum.getByCameraType(param.getCameraType());
  77. if(cameraTypelEnum == null){
  78. throw new BusinessException(CameraConstant.FAILURE_CODE_6028, CameraConstant.FAILURE_MSG_6028);
  79. }
  80. param.setIsLaser(cameraTypelEnum.getLaser());
  81. if(!StringUtils.isEmpty(param.getAppUserName())){
  82. Camera camera = cameraService.getByChildName(param.getAppUserName());
  83. if(camera == null){
  84. throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
  85. }
  86. CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
  87. if(cameraDetail == null){
  88. throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
  89. }
  90. param.setSnCode(camera.getSnCode());
  91. param.setCameraId(camera.getId());
  92. }
  93. List<String> cooperationNumList = new ArrayList<>();
  94. if(StringUtils.isNotBlank(param.getPhoneNum())){
  95. User user = userService.getByUserName(param.getPhoneNum());
  96. if(user == null){
  97. throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
  98. }
  99. cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()),param.getIsLaser()?"laser":"mesh");
  100. if(cooperationNumList.size() >0){
  101. param.setCooperationNumList(cooperationNumList );
  102. }
  103. param.setUserId(user.getId());
  104. }
  105. //云端场景不展示复制场景
  106. Set<String> copyNumSet = sceneCopyLogService.getCopyNumSet();
  107. param.setCopyNumSet(copyNumSet);
  108. Page<AppSceneVo> page = scenePlusMapper.pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  109. List<String> numList = page.getRecords().stream().map(AppSceneVo::getNum).collect(Collectors.toList());
  110. HashMap<String, JSONObject> ssSceneMap = new HashMap<>();
  111. if(cameraTypelEnum.getLaser() ){ //深时
  112. ssSceneMap = laserService.list(numList,cameraTypelEnum.getSceneSource().get(0));
  113. }
  114. // Set<Long> cameraIdSet = page.getRecords().stream().map(AppSceneVo::getCameraId).collect(Collectors.toSet());
  115. // List<Long> cameraIds = new ArrayList<>(cameraIdSet);
  116. // HashMap<Long, Camera> cameraHashMap = cameraService.getByIds(cameraIds);
  117. // HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
  118. //账号密码登录 sceneSourceType 取值 1用户场景,2协作场景
  119. //相机登录 sceneSourceType 取值皆为0
  120. for (AppSceneVo record : page.getRecords()) {
  121. if(cameraTypelEnum.getLaser()){ //深时
  122. JSONObject ssObj = ssSceneMap.get(record.getNum());
  123. if(ssObj!=null){
  124. record.setSceneName(ssObj.getString("title"));
  125. record.setThumb(ssObj.getString("thumb"));
  126. record.setWebSite(ssObj.getString("webSite"));
  127. record.setViewCount(ssObj.getInteger("viewCount"));
  128. }else{
  129. record.setStatus(-1);
  130. record.setWebSite(null);
  131. }
  132. }
  133. //全景看看场景重置webSite panorama/show.html?id=
  134. if(record.getLocation() != null && record.getLocation() == 7){
  135. String newWebSite = record.getWebSite().replaceAll("smg.html\\?m=","panorama/show.html?id=");
  136. record.setWebSite(newWebSite);
  137. }
  138. if (record.getStatus() == -1) {
  139. record.setStatus(0);
  140. } else if (record.getStatus() == 500) {
  141. record.setStatus(-1);
  142. }
  143. //虚拟场景
  144. if(record.getCameraId() == null && param.getUserId() != null){
  145. record.setSceneSourceType(record.getUserId().equals(param.getUserId()) ? 1 :2);
  146. continue;
  147. }
  148. //相机场景
  149. if(param.getCameraId() !=null && record.getCameraId().equals(param.getCameraId())){
  150. record.setSceneSourceType(0);
  151. continue;
  152. }
  153. //用户场景
  154. if(param.getUserId() != null && record.getUserId() != null){
  155. record.setSceneSourceType(record.getUserId().equals(param.getUserId()) ? 1 :2);
  156. }
  157. }
  158. return PageInfo.PageInfo(page);
  159. }
  160. public HashMap<String, Object> getSceneStatusByUnicode(String appUserName, String appPassword, String unicode) {
  161. if(StringUtils.isEmpty(appUserName) || StringUtils.isEmpty(appPassword) || StringUtils.isEmpty(unicode)){
  162. throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  163. }
  164. Camera camera = cameraService.getBySnCodeAndPassword(appUserName, appPassword);
  165. if(camera == null){
  166. throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
  167. }
  168. ScenePro scenePro = sceneProService.getByUnicode(unicode);
  169. ScenePlusExt plusExt = scenePlusExtService.getByUnicode(unicode);
  170. ScenePlus scenePlus = null;
  171. if(plusExt !=null){
  172. scenePlus = scenePlusService.getById(plusExt.getPlusId());
  173. }
  174. if(scenePro == null && scenePlus == null){
  175. ExceedSpaceScene exceedSpaceScene = exceedSpaceSceneService.getByUnicode(unicode);
  176. if(exceedSpaceScene == null){
  177. throw new BusinessException(SceneConstant.FAILURE_CODE_5009, SceneConstant.FAILURE_MSG_5009);
  178. }else {
  179. String sceneNum = exceedSpaceScene.getNum();
  180. String sceneCallPath = null ;
  181. String v3StatusJson = String.format(OssPath.v3_statusPath, sceneNum);
  182. String v4StatusJson = String.format(OssPath.v4_statusPath, sceneNum);
  183. if("V3".equals(exceedSpaceScene.getVersion())){
  184. sceneCallPath = v3StatusJson;
  185. }
  186. if("V4".equals(exceedSpaceScene.getVersion())){
  187. sceneCallPath = v4StatusJson;
  188. }
  189. if(StringUtils.isBlank(sceneCallPath)){
  190. if(fYunFileServiceInterface.fileExist(v3StatusJson)){
  191. sceneCallPath = v3StatusJson;
  192. }
  193. if(fYunFileServiceInterface.fileExist(v4StatusJson)){
  194. sceneCallPath = v4StatusJson;
  195. }
  196. }
  197. if(StringUtils.isBlank(sceneCallPath)){
  198. throw new BusinessException(SceneConstant.FAILURE_CODE_5009, SceneConstant.FAILURE_MSG_5009);
  199. }
  200. return getReturnMap(-1,null,sceneNum,null,
  201. "/mnt/data/"+camera.getSnCode()+"/"+exceedSpaceScene.getFileId()+"/"+exceedSpaceScene.getUnicode(),1,sceneCallPath);
  202. }
  203. }
  204. Integer payStatus = scenePro == null ? scenePlus.getPayStatus() : scenePro.getPayStatus();
  205. // 当计算时,返回给前端的状态为计算中
  206. Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
  207. if(status == -1){
  208. status = 0;
  209. }else if(status == 500){
  210. status = -1;
  211. }
  212. String webSite = scenePro == null ? plusExt.getWebSite() : scenePro.getWebSite();
  213. String sceneNum = scenePro == null ? scenePlus.getNum() : scenePro.getNum();
  214. String thumb = scenePro == null ? plusExt.getThumb() : scenePro.getThumb();
  215. String dataSource = scenePro == null ? plusExt.getDataSource() : scenePro.getDataSource();
  216. String sceneCallPath = scenePro == null ? String.format(OssPath.v4_statusPath,sceneNum) : String.format(OssPath.v3_statusPath,sceneNum);
  217. return getReturnMap(status,webSite,sceneNum,thumb,dataSource,payStatus,sceneCallPath);
  218. }
  219. private HashMap<String,Object> getReturnMap(Integer status,String webSite,String sceneNum,String thumb,String dataSource,Integer payStatus,String sceneCallPath){
  220. HashMap<String,Object> map = new HashMap<>();
  221. map.put("status",status == -2 ? 1:status);
  222. map.put("webSite",webSite);
  223. map.put("sceneNum",sceneNum);
  224. map.put("thumb",thumb);
  225. map.put("dataSource",dataSource);
  226. map.put("payStatus",payStatus);
  227. map.put("recStatus","A");
  228. map.put("sceneCallPath",ossHost+sceneCallPath);
  229. return map;
  230. }
  231. public void getScreencapVoice(String screencapMusic, String originalFileName, String sceneNum) throws Exception {
  232. if(StringUtils.isEmpty(screencapMusic) || StringUtils.isEmpty(originalFileName) || StringUtils.isEmpty(sceneNum)){
  233. throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
  234. }
  235. ScenePro scenePro = sceneProService.getByNum(sceneNum);
  236. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  237. if(scenePro == null && scenePlus == null){
  238. throw new BusinessException(SceneConstant.FAILURE_CODE_5005,SceneConstant.FAILURE_MSG_5005);
  239. }
  240. long time = System.currentTimeMillis();
  241. Map<String, Object> map = new HashMap<>();
  242. map.put("screencapVoiceSoundsyncFileName", screencapMusic + ".mp3");
  243. map.put("screencapVoiceSoundsync", originalFileName + "?t=" + time);
  244. log.info("微信上传的音频路径:" + originalFileName + "?t=" + time);
  245. map.put("screencapVoiceType", "soundsync");
  246. SceneProEdit sceneProEdit= null;
  247. SceneEditInfo editInfo = null;
  248. if(scenePro !=null){
  249. sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
  250. Integer version = sceneProEdit.getVersion() + 1;
  251. sceneProEdit.setVersion(version);
  252. sceneProEdit.setScreencapVoiceSoundsync(originalFileName + "?t=" + time);
  253. sceneProEdit.setScreencapVoiceType("soundsync");
  254. map.put("version", version);
  255. }else {
  256. editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  257. Integer version = editInfo.getVersion() + 1;
  258. editInfo.setVersion(version);
  259. //editInfo.setScreencapVoiceSoundsync(originalFileName + "?t=" + time);
  260. //editInfo.setScreencapVoiceType("soundsync");
  261. map.put("version", version);
  262. }
  263. StringBuilder dataBuffer = new StringBuilder(ConstantFilePath.SCENE_PATH)
  264. .append("data").append(File.separator)
  265. .append("data").append(sceneNum);
  266. FileUtils.writeJsonFile(dataBuffer.append(File.separator).append("scene.json").toString(), map);
  267. FileUtils.downLoadFromUrl(originalFileName + "?t=" + time, screencapMusic + ".mp3",
  268. ConstantFilePath.SCENE_PATH+ "voice" + File.separator + "voice" + sceneNum);
  269. if(sceneProEdit!=null){
  270. sceneProEditService.updateById(sceneProEdit);
  271. }
  272. if(editInfo !=null){
  273. sceneEditInfoService.updateById(editInfo);
  274. }
  275. }
  276. public void deleteForCameraName(Long cameraId, String sceneNum,Long userId) {
  277. if( StringUtils.isEmpty(sceneNum)){
  278. throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
  279. }
  280. ScenePro scenePro = sceneProService.getByNum(sceneNum);
  281. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  282. if(scenePro == null && scenePlus == null){
  283. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  284. }
  285. if(scenePro !=null && scenePro.getStatus() == 0){
  286. throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
  287. }
  288. if(scenePlus != null && scenePlus.getSceneStatus() == 0){
  289. throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
  290. }
  291. if(cameraId != null && scenePro!=null && !scenePro.getCameraId().equals(cameraId)){
  292. throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
  293. }
  294. if(cameraId != null && scenePlus!=null && !scenePlus.getCameraId().equals(cameraId)){
  295. throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
  296. }
  297. Integer sceneSource = null;
  298. List<ScenePro> proList = new ArrayList<>();
  299. if(scenePro!=null){
  300. proList.add(scenePro);
  301. sceneSource = scenePro.getSceneSource();
  302. }
  303. List<ScenePlus> plusList = new ArrayList<>();
  304. if(scenePlus!=null){
  305. plusList.add(scenePlus);
  306. sceneSource = scenePlus.getSceneSource();
  307. }
  308. sceneProService.deleteByList(proList,plusList,userId, null);
  309. if(sceneSource != null && (SceneSourceUtil.isLaser(sceneSource))){
  310. laserService.delete(sceneNum);
  311. }
  312. }
  313. }