|
@@ -237,27 +237,22 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
@Override
|
|
|
public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId) {
|
|
|
|
|
|
- Long totalSpace = cameraDetail.getTotalSpace();
|
|
|
- UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
|
|
|
- if(userIncrement!=null && userIncrement.getIsExpired()==0){
|
|
|
- IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
|
|
|
- if(incrementType!=null){
|
|
|
- if(incrementType.getCameraCapacity() == -1){
|
|
|
- totalSpace = -1L;
|
|
|
- }else {
|
|
|
- totalSpace = incrementType.getCameraCapacity() * 1024* 1024 * 1024L;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Long usedSpace = 0L;
|
|
|
List<SimpleSceneVo> voList = this.getSimpleSceneVo(cameraId);
|
|
|
if(voList .size() <=0){
|
|
|
return;
|
|
|
}
|
|
|
+ Long totalSpace = cameraDetailService.getTotalSpaceByCameraId(cameraDetail);
|
|
|
+ Long usedSpace = 0L;
|
|
|
+
|
|
|
//获取未被封存的场景容量
|
|
|
List<Long> spaceList = voList.stream().filter(entity -> entity.getPayStatus() == 1).map(SimpleSceneVo::getSpace).collect(Collectors.toList());
|
|
|
- for (Long aLong : spaceList) {
|
|
|
- usedSpace += aLong;
|
|
|
+ if("SP".equals(cameraDetail.getUnit())){
|
|
|
+ usedSpace = (long) spaceList.size();
|
|
|
+ }
|
|
|
+ if("GB".equals(cameraDetail.getUnit())){
|
|
|
+ for (Long aLong : spaceList) {
|
|
|
+ usedSpace += aLong;
|
|
|
+ }
|
|
|
}
|
|
|
//计算时间倒序
|
|
|
List<SimpleSceneVo> sceneVos = voList.stream().sorted(Comparator.comparing(SimpleSceneVo::getCreateTime).reversed()).collect(Collectors.toList());
|
|
@@ -272,7 +267,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
List<Long> lockedIds = new ArrayList<>();
|
|
|
if(usedSpace > totalSpace){
|
|
|
sceneVos = sceneVos.stream().filter(entity -> entity.getPayStatus() ==1).collect(Collectors.toList());
|
|
|
- Long space = getSceneLockedIds(lockedIds, sceneVos, usedSpace - totalSpace);
|
|
|
+ Long space = getSceneLockedIds(lockedIds, sceneVos, usedSpace - totalSpace,cameraDetail.getUnit());
|
|
|
log.info("lockOrUnLockBySpace---cameraId:{},totalSpace:{},useSpace{},space:{},payStatus:{}", cameraId,totalSpace,usedSpace,space,-2);
|
|
|
lockOrUnLockScenes(lockedIds,-2);
|
|
|
return;
|
|
@@ -281,17 +276,20 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
if(usedSpace < totalSpace){ //使用容量小于总容量,解封
|
|
|
sceneVos = sceneVos.stream().filter(entity -> entity.getPayStatus() !=1).collect(Collectors.toList());
|
|
|
CollectionUtil.reverse(sceneVos);
|
|
|
- Long space = getSceneUnLockedIds(lockedIds, sceneVos, totalSpace - usedSpace);
|
|
|
+ Long space = getSceneUnLockedIds(lockedIds, sceneVos, totalSpace - usedSpace,cameraDetail.getUnit());
|
|
|
log.info("lockOrUnLockBySpace---cameraId:{},totalSpace:{},useSpace{},space:{},payStatus:{}", cameraId,totalSpace,usedSpace,space,1);
|
|
|
lockOrUnLockScenes(lockedIds,1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Long getSceneUnLockedIds(List<Long> lockedIds ,List<SimpleSceneVo> list,Long beyondSpace){
|
|
|
+ private Long getSceneUnLockedIds(List<Long> lockedIds ,List<SimpleSceneVo> list,Long beyondSpace,String unit){
|
|
|
Long space = 0L;
|
|
|
if (list != null && list.size() > 0){
|
|
|
for (SimpleSceneVo scenePro : list){
|
|
|
Long sceneSpace = scenePro.getSpace()== null ? 0 : scenePro.getSpace();
|
|
|
+ if("SP".equals(unit)){
|
|
|
+ sceneSpace = 1L;
|
|
|
+ }
|
|
|
if (space + sceneSpace > beyondSpace){
|
|
|
continue;
|
|
|
}
|
|
@@ -302,11 +300,14 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return space;
|
|
|
}
|
|
|
|
|
|
- private Long getSceneLockedIds(List<Long> lockedIds ,List<SimpleSceneVo> list,Long beyondSpace){
|
|
|
+ private Long getSceneLockedIds(List<Long> lockedIds ,List<SimpleSceneVo> list,Long beyondSpace,String unit){
|
|
|
Long space = 0L;
|
|
|
if (list != null && list.size() > 0){
|
|
|
for (SimpleSceneVo scenePro : list){
|
|
|
Long sceneSpace = scenePro.getSpace()== null ? 0 : scenePro.getSpace();
|
|
|
+ if("SP".equals(unit)){
|
|
|
+ sceneSpace = 1L;
|
|
|
+ }
|
|
|
space += sceneSpace;
|
|
|
lockedIds.add(scenePro.getId());
|
|
|
if (space > beyondSpace){
|
|
@@ -650,25 +651,26 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
|
|
|
}
|
|
|
UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
|
|
|
- if(userIncrement == null){
|
|
|
+ if(userIncrement == null || userIncrement.getIsExpired() == 1){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3030, LoginConstant.FAILURE_MSG_3030);
|
|
|
}
|
|
|
IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
|
|
|
if(incrementType == null){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3030, LoginConstant.FAILURE_MSG_3030);
|
|
|
}
|
|
|
+ Long space = null;
|
|
|
+ if( scenePro != null ){
|
|
|
+ space = scenePro.getSpace();
|
|
|
+ }
|
|
|
+ if( scenePlus != null ){
|
|
|
+ ScenePlusExt ext = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
+ space = ext.getSpace();
|
|
|
+ }
|
|
|
|
|
|
- if(incrementType.getCameraCapacity() != -1){
|
|
|
- Long usedSpace = detailEntity.getUsedSpace();
|
|
|
- if( scenePro != null && scenePro.getSpace() + usedSpace > incrementType.getCameraCapacity() * 1024 * 1024 * 1024L){
|
|
|
- throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
|
|
|
- }
|
|
|
- if( scenePlus != null ){
|
|
|
- ScenePlusExt ext = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
- if(ext.getSpace() + usedSpace > incrementType.getCameraCapacity() * 1024 * 1024 * 1024L){
|
|
|
- throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
|
|
|
- }
|
|
|
- }
|
|
|
+ Boolean canSpace = cameraDetailService.checkSpace(detailEntity,incrementType,space);
|
|
|
+
|
|
|
+ if(!canSpace){
|
|
|
+ throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
|
|
|
}
|
|
|
this.copySceneNoCheck(sceneNum);
|
|
|
|
|
@@ -803,15 +805,11 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
scenePro.setStatus(-2);
|
|
|
this.updateById(scenePro);
|
|
|
|
|
|
- cameraDetailService.addUsedSpace(cameraDetail.getId(),scenePro.getSpace());
|
|
|
+ cameraDetailService.addUsedSpace(cameraDetail,scenePro.getSpace());
|
|
|
sceneCopyLogService.saveByNum(oldNum,newNum,scenePro.getUserId());
|
|
|
|
|
|
- Long totalSpace = cameraDetail.getTotalSpace();
|
|
|
- Long totalSpace1 = cameraDetailService.getTotalSpaceByCameraId(cameraDetail.getCameraId());
|
|
|
- if(totalSpace1 != null ){
|
|
|
- totalSpace = totalSpace1;
|
|
|
- }
|
|
|
- if(totalSpace >0 && cameraDetail.getUsedSpace() + scenePro.getSpace() > totalSpace ){
|
|
|
+ Boolean checkSpace = cameraDetailService.checkSpace(cameraDetail.getCameraId(), scenePro.getSpace());
|
|
|
+ if(!checkSpace){
|
|
|
this.lockOrUnLockScenes(Arrays.asList(scenePro.getId()),-2);
|
|
|
}
|
|
|
|