AppSceneService.java 16 KB

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