|
@@ -3,15 +3,27 @@ package com.fdkankan.app.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
-import com.fdkankan.common.util.FileUtils;
|
|
|
-import com.fdkankan.common.util.JwtUtil;
|
|
|
-import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.app.common.RedisKeyUtil;
|
|
|
+import com.fdkankan.app.constant.LoginConstant;
|
|
|
import com.fdkankan.app.entity.*;
|
|
|
import com.fdkankan.app.mapper.ISceneProMapper;
|
|
|
import com.fdkankan.app.service.*;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.app.util.DateUserUtil;
|
|
|
+import com.fdkankan.app.vo.request.SceneParam;
|
|
|
+import com.fdkankan.app.vo.response.GroupByCount;
|
|
|
+import com.fdkankan.app.vo.response.SceneInfoVo;
|
|
|
+import com.fdkankan.app.vo.response.SceneVo;
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -25,16 +37,473 @@ import java.util.stream.Collectors;
|
|
|
* </p>
|
|
|
*
|
|
|
* @author
|
|
|
- * @since 2022-07-04
|
|
|
+ * @since 2022-07-15
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ ISceneProEditService sceneProEditService;
|
|
|
+ @Autowired
|
|
|
+ IUserIncrementService userIncrementService;
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public Long getCountByUserId(Long userId, List<Integer> resourceList) {
|
|
|
LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(ScenePro::getUserId,userId);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
wrapper.in(ScenePro::getSceneSource,resourceList);
|
|
|
return this.count(wrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getCountByUserId(Long id, Integer cameraType) {
|
|
|
+ return this.getBaseMapper().getCountByUserId(id,cameraType);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo pageList(SceneParam 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<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
|
|
|
+ for (SceneVo 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScenePro getByNum(String num) {
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(ScenePro::getNum,num);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
+ if(list!= null && list.size() >0){
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SceneInfoVo getInfo(String num) {
|
|
|
+ if(StringUtils.isEmpty(num)){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ ScenePro scenePro = this.getByNum(num);
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
+ if(scenePro == null && scenePlus == null){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
+ }
|
|
|
+ if(scenePro!=null && scenePro.getStatus() != 1 && scenePro.getStatus() != -2){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
|
|
|
+ }
|
|
|
+ if(scenePlus!=null && scenePlus.getSceneStatus() != 1 && scenePlus.getSceneStatus() != -2){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
|
|
|
+ }
|
|
|
+ if(scenePro!=null && scenePro.getPayStatus() != 1){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
|
|
|
+ }
|
|
|
+ if(scenePlus!=null && scenePlus.getPayStatus() != 1){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5034, SceneConstant.FAILURE_MSG_5034);
|
|
|
+ }
|
|
|
+ SceneInfoVo infoVo = new SceneInfoVo();
|
|
|
+ if(scenePro!=null){
|
|
|
+ SceneProEdit sceneProEdit = sceneProEditService.getByProId(scenePro.getId());
|
|
|
+ if(sceneProEdit !=null){
|
|
|
+ BeanUtils.copyProperties(sceneProEdit, infoVo);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(scenePro,infoVo);
|
|
|
+ if(StringUtils.isNotEmpty(scenePro.getGps())){
|
|
|
+ infoVo.setGps(JSONObject.parseObject(scenePro.getGps()).toJSONString());
|
|
|
+ }
|
|
|
+ infoVo.setSceneKey("");
|
|
|
+ infoVo.setCreateDate(DateUserUtil.getDate(scenePro.getCreateTime()).getTime());
|
|
|
+ }else {
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByPlusId(scenePlus.getId());
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
+ if(sceneEditInfo != null){
|
|
|
+ BeanUtils.copyProperties(sceneEditInfo,infoVo);
|
|
|
+ }
|
|
|
+ if(scenePlusExt !=null){
|
|
|
+ BeanUtils.copyProperties(scenePlusExt,infoVo);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(scenePlus,infoVo);
|
|
|
+ infoVo.setSceneName(scenePlus.getTitle());
|
|
|
+ infoVo.setStatus(scenePlus.getSceneStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(infoVo.getEntry())){
|
|
|
+ infoVo.setEntry(JSONObject.parseObject(infoVo.getEntry()).toJSONString());
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(infoVo.getSceneKey())){
|
|
|
+ infoVo.setIsPublic(0);
|
|
|
+ }else {
|
|
|
+ infoVo.setIsPublic(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询是否有随心装场景
|
|
|
+ if(num.contains("vr-")){
|
|
|
+ infoVo.setVrNum(null);
|
|
|
+ infoVo.setVideosUser(null);
|
|
|
+ infoVo.setBgMusicName(null);
|
|
|
+ infoVo.setBgMusic(null);
|
|
|
+ }
|
|
|
+ this.updateViewCount(num);
|
|
|
+ return infoVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateViewCount(String num) {
|
|
|
+ String redisKey = RedisKeyUtil.SCENE_VIEW_COUNT + num;
|
|
|
+ if(!redisUtil.hasKey(redisKey)){
|
|
|
+ Integer count = null;
|
|
|
+ ScenePro pro = this.getByNum(num);
|
|
|
+ if(pro !=null){
|
|
|
+ count = pro.getViewCount();
|
|
|
+ }else {
|
|
|
+ ScenePlus plus = scenePlusService.getByNum(num);
|
|
|
+ if(plus !=null){
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(plus.getId());
|
|
|
+ count = scenePlusExt.getViewCount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count !=null){
|
|
|
+ redisUtil.set(redisKey,String.valueOf(count));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
+ redisUtil.incr(redisKey,1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ScenePro> getListByCameraIds(List<Long> cameraIds) {
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(ScenePro::getCameraId,cameraIds)
|
|
|
+ .eq(ScenePro::getIsUpgrade,0);
|
|
|
+ return this.list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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 = this.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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScenePro getByUnicode(String unicode) {
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.like(ScenePro::getDataSource,unicode);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
+ wrapper.orderByDesc(ScenePro::getCreateTime);
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
+ if(list !=null && list.size() >0){
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bindOrUnCamera(List<Long> cameraIds, Long userId) {
|
|
|
+ LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(ScenePro::getCameraId,cameraIds)
|
|
|
+ .eq(ScenePro::getIsUpgrade,0)
|
|
|
+ .set(ScenePro::getUserId,userId);
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, int payStatus) {
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
|
|
|
+ Long count = 0L;
|
|
|
+ if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
|
|
|
+ count = userIncrementService.getValidCountByCameraId(cameraId);
|
|
|
+ wrapper.orderByAsc(ScenePro::getCreateTime);
|
|
|
+ plusWr.orderByAsc(ScenePlus::getCreateTime);
|
|
|
+ }else {
|
|
|
+ wrapper.orderByDesc(ScenePro::getCreateTime);
|
|
|
+ plusWr.orderByDesc(ScenePlus::getCreateTime);
|
|
|
+ }
|
|
|
+ wrapper.eq(ScenePro::getCameraId,cameraId)
|
|
|
+ .eq(ScenePro::getPayStatus,payStatus)
|
|
|
+ .eq(ScenePro::getSceneScheme,4)
|
|
|
+ .eq(ScenePro::getIsUpgrade,0);
|
|
|
+ plusWr.eq(ScenePlus::getCameraId,cameraId)
|
|
|
+ .eq(ScenePlus::getPayStatus,payStatus);
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
+ List<ScenePlus> plusList = scenePlusService.list(plusWr);
|
|
|
+ Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - cameraDetail.getTotalSpace());
|
|
|
+ Long accumulateSpace = 0L;
|
|
|
+ List<Long> lockedIds = new ArrayList<>();
|
|
|
+ if(payStatus == 1){
|
|
|
+ getScenePlusLockedIds(lockedIds,plusList,count,beyondSpace,accumulateSpace);
|
|
|
+ getSceneLockedIds(lockedIds,list,count,beyondSpace,accumulateSpace);
|
|
|
+ }else {
|
|
|
+ getSceneLockedIds(lockedIds,list,count,beyondSpace,accumulateSpace);
|
|
|
+ getScenePlusLockedIds(lockedIds,plusList,count,beyondSpace,accumulateSpace);
|
|
|
+ }
|
|
|
+
|
|
|
+ lockOrUnLockScenes(lockedIds,payStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getSceneLockedIds(List<Long> lockedIds ,List<ScenePro> list,Long count,Long beyondSpace,Long accumulateSpace){
|
|
|
+ if (list != null && list.size() > 0){
|
|
|
+ for (ScenePro scenePro : list){
|
|
|
+ accumulateSpace += scenePro.getSpace();
|
|
|
+ if (count ==0 && accumulateSpace.compareTo(beyondSpace) > 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ lockedIds.add(scenePro.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void getScenePlusLockedIds(List<Long> lockedIds ,List<ScenePlus> list,Long count,Long beyondSpace,Long accumulateSpace){
|
|
|
+ if (list != null && list.size() > 0){
|
|
|
+ List<Long> plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
|
|
|
+ HashMap<Long, ScenePlusExt> byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
|
|
|
+ for (ScenePlus scenePlus : list){
|
|
|
+ ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
|
|
|
+ accumulateSpace += scenePlusExt.getSpace();
|
|
|
+ if (count ==0 && accumulateSpace.compareTo(beyondSpace) > 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ lockedIds.add(scenePlus.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // payStatus 为 -2 封存,为 1 解封
|
|
|
+ private void lockOrUnLockScenes(List<Long> lockedIds,Integer payStatus) {
|
|
|
+ if (lockedIds == null || lockedIds.size() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(ScenePro::getPayStatus,payStatus)
|
|
|
+ .eq(ScenePro::getIsUpgrade,0)
|
|
|
+ .in(ScenePro::getId,lockedIds);
|
|
|
+ this.update(updateWrapper);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<ScenePlus> updatePlusWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updatePlusWrapper.set(ScenePlus::getPayStatus,payStatus)
|
|
|
+ .in(ScenePlus::getId,lockedIds);
|
|
|
+ scenePlusService.update(updatePlusWrapper);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HashMap<Long, GroupByCount> findSceneNumByCameraIds(List<Long> cameraIdList) {
|
|
|
+ HashMap<Long,GroupByCount> map = new HashMap<>();
|
|
|
+ List<GroupByCount> result = this.getBaseMapper().findSceneProNumByCameraIds(cameraIdList);
|
|
|
+ List<GroupByCount> result2 = this.getBaseMapper().findScenePlusNumByCameraIds(cameraIdList);
|
|
|
+ result.forEach(entity ->map.put(entity.getId(),entity));
|
|
|
+ for (GroupByCount groupByCount : result2) {
|
|
|
+ if (map.get(groupByCount.getId()) != null) {
|
|
|
+ Long totalCount = map.get(groupByCount.getId()).getCount() + groupByCount.getCount();
|
|
|
+ String lastTime = DateUserUtil.getLastTime(map.get(groupByCount.getId()).getLastTime(), groupByCount.getLastTime());
|
|
|
+ groupByCount.setCount(totalCount);
|
|
|
+ groupByCount.setLastTime(lastTime);
|
|
|
+ }
|
|
|
+ map.put(groupByCount.getId(),groupByCount);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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 = this.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.getByPlusId(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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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 = this.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);
|
|
|
+ }
|
|
|
+ this.deleteByList(proList,plusList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteByList(List<ScenePro> proList,List<ScenePlus> plusList) {
|
|
|
+ HashMap<Long ,Long >cameraMap = new HashMap<>();
|
|
|
+ if(proList.size() >0){
|
|
|
+ for (ScenePro scenePro : proList) {
|
|
|
+ cameraMap.merge(scenePro.getCameraId(), scenePro.getSpace(), Long::sum);
|
|
|
+ }
|
|
|
+ List<Long> proIds = proList.parallelStream().map(ScenePro::getId).collect(Collectors.toList());
|
|
|
+ this.removeByIds(proIds);
|
|
|
+ }
|
|
|
+ if(plusList.size() >0){
|
|
|
+ List<Long> plusIds = plusList.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
|
|
|
+ HashMap<Long, ScenePlusExt> plusMap = scenePlusExtService.getByPlusIds(plusIds);
|
|
|
+
|
|
|
+ for (ScenePlus scenePlus : plusList) {
|
|
|
+ cameraMap.merge(scenePlus.getCameraId(), plusMap.get(scenePlus.getId()).getSpace(), Long::sum);
|
|
|
+ }
|
|
|
+ scenePlusService.removeByIds(plusIds);
|
|
|
+ }
|
|
|
+ //恢复相机使用容量
|
|
|
+ if(cameraMap.size() >0){
|
|
|
+ cameraDetailService.addUsedSpace(cameraMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|