|
@@ -0,0 +1,224 @@
|
|
|
+package com.fdkankan.ucenter.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
+import com.fdkankan.common.constant.SceneConstant;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.response.PageInfo;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.ucenter.constant.LoginConstant;
|
|
|
+import com.fdkankan.ucenter.entity.*;
|
|
|
+import com.fdkankan.ucenter.mapper.IScenePlusMapper;
|
|
|
+import com.fdkankan.ucenter.service.*;
|
|
|
+import com.fdkankan.ucenter.vo.request.AppSceneParam;
|
|
|
+import com.fdkankan.ucenter.vo.response.AppSceneVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AppSceneService {
|
|
|
+ @Autowired
|
|
|
+ IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProEditService sceneProEditService;
|
|
|
+ @Autowired
|
|
|
+ IUserIncrementService userIncrementService;
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ IScenePlusMapper scenePlusMapper;
|
|
|
+
|
|
|
+ public PageInfo pageList(AppSceneParam param) {
|
|
|
+ if(StringUtils.isEmpty(param.getAppUserName()) && StringUtils.isEmpty(param.getPhoneNum()) ){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(), param.getAppPassword());
|
|
|
+ if(camera == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(cameraDetail == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ User user = userService.getByUserName(param.getPhoneNum());
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+ //param.setUserId(user.getId());
|
|
|
+ param.setSnCode(camera.getSnCode());
|
|
|
+ Page<AppSceneVo> page = scenePlusMapper.pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
|
|
|
+ for (AppSceneVo record : page.getRecords()) {
|
|
|
+
|
|
|
+ if (record.getStatus() == -1) {
|
|
|
+ record.setStatus(0);
|
|
|
+ } else if (record.getStatus() == 500) {
|
|
|
+ record.setStatus(-1);
|
|
|
+ }
|
|
|
+ //相机的userId为空,表示相机的场景
|
|
|
+ if (cameraDetail.getUserId() == null || user.getId() == null) {
|
|
|
+ record.setSceneSourceType(0);
|
|
|
+ } else if (cameraDetail.getUserId().longValue() == user.getId().longValue()) {
|
|
|
+ //相机用户id等于该用户id,既为用户的场景
|
|
|
+ record.setSceneSourceType(1);
|
|
|
+ } else if (camera.getId() != null && cameraDetail.getCameraId().longValue() == camera.getId().longValue()) {
|
|
|
+ if (cameraDetail.getCooperationUser() == null) {
|
|
|
+ //场景相机id等于该相机id
|
|
|
+ record.setSceneSourceType(0);
|
|
|
+ } else if (cameraDetail.getCooperationUser().longValue() == user.getId().longValue()) {
|
|
|
+ record.setSceneSourceType(2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ record.setSceneSourceType(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ public HashMap<String, Object> getSceneStatusByUnicode(String appUserName, String appPassword, String unicode) {
|
|
|
+ if(StringUtils.isEmpty(appPassword) || StringUtils.isEmpty(appPassword) || StringUtils.isEmpty(unicode)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ Camera camera = cameraService.getBySnCodeAndPassword(appUserName, appPassword);
|
|
|
+ if(camera == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ ScenePro scenePro = sceneProService.getByUnicode(unicode);
|
|
|
+ ScenePlusExt plusExt = scenePlusExtService.getByUnicode(unicode);
|
|
|
+ ScenePlus scenePlus = null;
|
|
|
+ if(plusExt !=null){
|
|
|
+ scenePlus = scenePlusService.getById(plusExt.getPlusId());
|
|
|
+ }
|
|
|
+ if(scenePro == null && scenePlus == null){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5009, SceneConstant.FAILURE_MSG_5009);
|
|
|
+ }
|
|
|
+ Integer payStatus = scenePro == null ? scenePlus.getPayStatus() : scenePro.getPayStatus();
|
|
|
+ if(payStatus == -2){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5006, SceneConstant.FAILURE_MSG_5006);
|
|
|
+ }
|
|
|
+ // 当计算时,返回给前端的状态为计算中
|
|
|
+ Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
|
|
|
+ if(status == -1){
|
|
|
+ status = 0;
|
|
|
+ }else if(status == 500){
|
|
|
+ status = -1;
|
|
|
+ }
|
|
|
+ String webSite = scenePro == null ? plusExt.getWebSite() : scenePro.getWebSite();
|
|
|
+ String sceneNum = scenePro == null ? scenePlus.getTitle() : scenePro.getSceneName();
|
|
|
+ String thumb = scenePro == null ? plusExt.getThumb() : scenePro.getThumb();
|
|
|
+ String dataSource = scenePro == null ? plusExt.getDataSource() : scenePro.getDataSource();
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ map.put("status",status == -2 ? 1:status);
|
|
|
+ map.put("webSite",webSite);
|
|
|
+ map.put("sceneNum",sceneNum);
|
|
|
+ map.put("thumb",thumb);
|
|
|
+ map.put("dataSource",dataSource);
|
|
|
+ map.put("payStatus",payStatus);
|
|
|
+ map.put("recStatus","A");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getScreencapVoice(String screencapMusic, String originalFileName, String sceneNum) throws Exception {
|
|
|
+ if(StringUtils.isEmpty(screencapMusic) || StringUtils.isEmpty(originalFileName) || StringUtils.isEmpty(sceneNum)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ ScenePro scenePro = sceneProService.getByNum(sceneNum);
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
|
|
|
+ if(scenePro == null && scenePlus == null){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005,SceneConstant.FAILURE_MSG_5005);
|
|
|
+ }
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ map.put("screencapVoiceSoundsyncFileName", screencapMusic + ".mp3");
|
|
|
+ map.put("screencapVoiceSoundsync", originalFileName + "?t=" + time);
|
|
|
+ log.info("微信上传的音频路径:" + originalFileName + "?t=" + time);
|
|
|
+ map.put("screencapVoiceType", "soundsync");
|
|
|
+
|
|
|
+ SceneProEdit sceneProEdit= null;
|
|
|
+ SceneEditInfo editInfo = null;
|
|
|
+ if(scenePro !=null){
|
|
|
+ sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
|
|
|
+ Integer version = sceneProEdit.getVersion() + 1;
|
|
|
+ sceneProEdit.setVersion(version);
|
|
|
+ sceneProEdit.setScreencapVoiceSoundsync(originalFileName + "?t=" + time);
|
|
|
+ sceneProEdit.setScreencapVoiceType("soundsync");
|
|
|
+ map.put("version", version);
|
|
|
+ }else {
|
|
|
+ editInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ Integer version = editInfo.getVersion() + 1;
|
|
|
+ editInfo.setVersion(version);
|
|
|
+ //editInfo.setScreencapVoiceSoundsync(originalFileName + "?t=" + time);
|
|
|
+ //editInfo.setScreencapVoiceType("soundsync");
|
|
|
+ map.put("version", version);
|
|
|
+ }
|
|
|
+ StringBuilder dataBuffer = new StringBuilder(ConstantFilePath.SCENE_PATH)
|
|
|
+ .append("data").append(File.separator)
|
|
|
+ .append("data").append(sceneNum);
|
|
|
+ FileUtils.writeJsonFile(dataBuffer.append(File.separator).append("scene.json").toString(), map);
|
|
|
+
|
|
|
+ FileUtils.downLoadFromUrl(originalFileName + "?t=" + time, screencapMusic + ".mp3",
|
|
|
+ ConstantFilePath.SCENE_PATH+ "voice" + File.separator + "voice" + sceneNum);
|
|
|
+ if(sceneProEdit!=null){
|
|
|
+ sceneProEditService.updateById(sceneProEdit);
|
|
|
+ }
|
|
|
+ if(editInfo !=null){
|
|
|
+ sceneEditInfoService.updateById(editInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteForCameraName(Long cameraId, String sceneNum) {
|
|
|
+ if(cameraId == null || StringUtils.isEmpty(sceneNum)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001,LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ ScenePro scenePro = sceneProService.getByNum(sceneNum);
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
|
|
|
+ if(scenePro == null && scenePlus == null){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
+ }
|
|
|
+ if(scenePro !=null && scenePro.getStatus() == 0){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
|
|
|
+ }
|
|
|
+ if(scenePlus != null && scenePlus.getSceneStatus() == 0){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
|
|
|
+ }
|
|
|
+ if(scenePro!=null && !scenePro.getCameraId().equals(cameraId)){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
|
|
|
+ }
|
|
|
+ if(scenePlus!=null && !scenePlus.getCameraId().equals(cameraId)){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
|
|
|
+ }
|
|
|
+ List<ScenePro> proList = new ArrayList<>();
|
|
|
+ if(scenePro!=null){
|
|
|
+ proList.add(scenePro);
|
|
|
+ }
|
|
|
+ List<ScenePlus> plusList = new ArrayList<>();
|
|
|
+ if(scenePlus!=null){
|
|
|
+ plusList.add(scenePlus);
|
|
|
+ }
|
|
|
+ sceneProService.deleteByList(proList,plusList);
|
|
|
+ }
|
|
|
+}
|