123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- package com.fdkankan.ucenter.service.impl;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.common.util.JwtUtil;
- import com.fdkankan.ucenter.common.constants.ConstantFilePath;
- import com.fdkankan.common.constant.SceneConstant;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.ucenter.common.PageInfo;
- import com.fdkankan.common.util.FileUtils;
- import com.fdkankan.redis.util.RedisUtil;
- import com.fdkankan.ucenter.common.OssPath;
- import com.fdkankan.ucenter.constant.LoginConstant;
- import com.fdkankan.ucenter.entity.*;
- import com.fdkankan.ucenter.httpClient.service.LaserService;
- 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.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import javax.annotation.Resource;
- import java.io.File;
- import java.util.*;
- import java.util.stream.Collectors;
- @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;
- @Autowired
- ISceneCooperationService sceneCooperationService;
- @Autowired
- LaserService laserService;
- @Autowired
- IScenePlusMapper scenePlusMapper;
- @Value("${fyun.host}")
- private String ossHost;
- public PageInfo pageList(AppSceneParam param) {
- if(StringUtils.isEmpty(param.getAppUserName()) && StringUtils.isEmpty(param.getPhoneNum()) && param.getCameraId() == null){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
- }
- if(!StringUtils.isEmpty(param.getAppUserName()) && !StringUtils.isEmpty(param.getAppPassword())){
- 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);
- }
- param.setSnCode(camera.getSnCode());
- param.setCameraId(camera.getId());
- }
- List<String> cooperationNumList = new ArrayList<>();
- if(StringUtils.isNotBlank(param.getPhoneNum())){
- User user = userService.getByUserName(param.getPhoneNum());
- if(user == null){
- throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
- }
- cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()));
- if(cooperationNumList.size() >0){
- param.setCooperationNumList(cooperationNumList );
- }
- param.setUserId(user.getId());
- }
- Page<AppSceneVo> page = scenePlusMapper.pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- Set<Long> cameraIdSet = page.getRecords().stream().map(AppSceneVo::getCameraId).collect(Collectors.toSet());
- List<Long> cameraIds = new ArrayList<>(cameraIdSet);
- HashMap<Long, Camera> cameraHashMap = cameraService.getByIds(cameraIds);
- HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
- for (AppSceneVo record : page.getRecords()) {
- record.setChildName(record.getSnCode());
- if (record.getStatus() == -1) {
- record.setStatus(0);
- } else if (record.getStatus() == 500) {
- record.setStatus(-1);
- }
- if(record.getCameraId() == null){
- record.setSceneSourceType(record.getUserId().longValue() == param.getUserId() ? 1 : 2);
- }else {
- record.setSceneSourceType(0);
- Camera camera = cameraHashMap.get(record.getCameraId());
- if(camera == null){
- continue;
- }
- CameraDetail cameraDetail = detailHashMap.get(camera.getId());
- if(cameraDetail == null){
- continue;
- }
- record.setChildName(camera.getChildName());
- record.setSnCode(camera.getSnCode());
- if(cooperationNumList.contains(record.getNum())){
- record.setSceneSourceType(2);
- continue ;
- }
- //相机的userId为空,表示相机的场景
- if (cameraDetail.getUserId() == null || param.getUserId() == null ) {
- record.setSceneSourceType(0);
- continue;
- }
- if (cameraDetail.getUserId().equals(param.getUserId())) {
- //相机用户id等于该用户id,既为用户的场景
- record.setSceneSourceType(1);
- continue;
- }
- if (param.getCameraId()!=null && cameraDetail.getCameraId().equals(param.getCameraId())) {
- if (cameraDetail.getCooperationUser() == null) {
- //场景相机id等于该相机id
- record.setSceneSourceType(0);
- } else if (cameraDetail.getCooperationUser().equals(param.getUserId())) {
- record.setSceneSourceType(2);
- }
- }
- }
- }
- 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();
- // 当计算时,返回给前端的状态为计算中
- 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.getNum() : scenePro.getNum();
- String thumb = scenePro == null ? plusExt.getThumb() : scenePro.getThumb();
- String dataSource = scenePro == null ? plusExt.getDataSource() : scenePro.getDataSource();
- String sceneCallPath = scenePro == null ? String.format(OssPath.v4_statusPath,sceneNum) : String.format(OssPath.v3_statusPath,sceneNum);
- 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");
- map.put("sceneCallPath",ossHost+sceneCallPath);
- 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,Long userId) {
- if( 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(cameraId != null && scenePro!=null && !scenePro.getCameraId().equals(cameraId)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
- }
- if(cameraId != null && scenePlus!=null && !scenePlus.getCameraId().equals(cameraId)){
- throw new BusinessException(SceneConstant.FAILURE_CODE_5010, SceneConstant.FAILURE_MSG_5010);
- }
- Integer sceneSource = null;
- List<ScenePro> proList = new ArrayList<>();
- if(scenePro!=null){
- proList.add(scenePro);
- sceneSource = scenePro.getSceneSource();
- }
- List<ScenePlus> plusList = new ArrayList<>();
- if(scenePlus!=null){
- plusList.add(scenePlus);
- sceneSource = scenePlus.getSceneSource();
- }
- sceneProService.deleteByList(proList,plusList,userId);
- if(sceneSource != null && sceneSource == 4){
- laserService.delete(sceneNum);
- }
- }
- }
|