|
@@ -95,101 +95,6 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return PageInfo.PageInfo(page);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void move(SceneParam param) {
|
|
|
- Camera camera = cameraService.getBySnCode(param.getSnCode());
|
|
|
- if(camera == null){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
|
|
|
- }
|
|
|
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
- if(cameraDetail == null){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
|
|
|
- }
|
|
|
- ScenePro scenePro = this.getByNum(param.getNum());
|
|
|
- ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
|
|
|
- if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
|
|
|
- throw new BusinessException(ResultCode.SCENE_EMPTY);
|
|
|
- }
|
|
|
- Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
|
|
|
- if(status == 0){
|
|
|
- throw new BusinessException(ResultCode.SCENE_BUILD);
|
|
|
- }
|
|
|
-
|
|
|
- Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
|
|
|
- Long space = scenePro == null ? 0 :scenePro.getSpace();
|
|
|
- if(scenePlus !=null){
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
- space = scenePlusExt.getSpace();
|
|
|
- }
|
|
|
- space = space == null ? 0 :space;
|
|
|
- Long newUseSpace = space + cameraDetail.getUsedSpace();
|
|
|
- Long totalSpace = cameraDetail.getTotalSpace();
|
|
|
- UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
|
|
|
- if(userIncrement!=null){
|
|
|
- IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
|
|
|
- if(incrementType!=null){
|
|
|
- if(incrementType.getCameraCapacity() == -1){
|
|
|
- totalSpace = -1L;
|
|
|
- }else {
|
|
|
- totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //深时场景无限容量
|
|
|
- if(cameraDetail.getType() != 10 && totalSpace !=-1 && newUseSpace > totalSpace){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- Camera oldCamera = cameraService.getById(cameraId);
|
|
|
- if(oldCamera == null){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
|
|
|
- }
|
|
|
- CameraDetail oldCameraDetail = cameraDetailService.getByCameraId(oldCamera.getId());
|
|
|
- if(oldCameraDetail == null){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
|
|
|
- }
|
|
|
- if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_TYPE_NOT_ERROR);
|
|
|
- }
|
|
|
- if(oldCameraDetail.getAgentId() == null || cameraDetail.getAgentId() == null ||
|
|
|
- !oldCameraDetail.getAgentId().equals(cameraDetail.getAgentId()) ){
|
|
|
- throw new BusinessException(ResultCode.CAMERA_SN_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
|
|
|
- oldCameraDetail.setUsedSpace(oldUseSpace);
|
|
|
- Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
|
|
|
- if(cameraDetail.getType() != 10 && subSpace >0){ //有剩余容量解封容量内场景
|
|
|
- this.lockOrUnLockBySpace(oldCameraDetail,oldCameraDetail.getCameraId(),1);
|
|
|
- }
|
|
|
- cameraDetailService.updateById(oldCameraDetail);
|
|
|
- cameraDetail.setUsedSpace(newUseSpace);
|
|
|
- cameraDetailService.updateById(cameraDetail);
|
|
|
-
|
|
|
- if(scenePro!=null){
|
|
|
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(ScenePro::getId,scenePro.getId());
|
|
|
- wrapper.set(ScenePro::getCameraId,camera.getId());
|
|
|
- wrapper.set(ScenePro::getUserId,cameraDetail.getUserId());
|
|
|
- this.update(wrapper);
|
|
|
- //场景迁移到另外的相机清除本身在的文件夹
|
|
|
- folderSceneService.delBySceneId(scenePro.getId());
|
|
|
- }
|
|
|
- if(scenePlus!=null){
|
|
|
- LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(ScenePlus::getId,scenePlus.getId());
|
|
|
- wrapper.set(ScenePlus::getCameraId,camera.getId());
|
|
|
- wrapper.set(ScenePlus::getUserId,cameraDetail.getUserId());
|
|
|
- scenePlusService.update(wrapper);
|
|
|
- folderSceneService.delBySceneId(scenePlus.getId());
|
|
|
- }
|
|
|
- if(cameraDetail.getType() == 10){ //深时场景
|
|
|
- laserService.move(param.getNum(),oldCamera.getSnCode(),camera.getSnCode());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void copy(String sceneNum) throws Exception {
|
|
@@ -226,160 +131,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
return list.get(0);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param payStatus -2 封存,为 1 解封
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
|
|
|
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
- LambdaQueryWrapper<ScenePlus> plusWr = new LambdaQueryWrapper<>();
|
|
|
- Long totalSpace = cameraDetail.getTotalSpace();
|
|
|
- UserIncrement userIncrement = userIncrementService.getByCameraId(cameraId);
|
|
|
- if(userIncrement!=null){
|
|
|
- IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
|
|
|
- if(incrementType!=null){
|
|
|
- if(incrementType.getCameraCapacity() == -1){
|
|
|
- totalSpace = -1L;
|
|
|
- }else {
|
|
|
- totalSpace = incrementType.getCameraCapacity() * 1024 * 1024L;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("lockOrUnLockBySpace---cameraId:{},payStatus:{},totalSpace:{},useSpace{}",
|
|
|
- cameraId,payStatus,totalSpace,cameraDetail.getUsedSpace());
|
|
|
- if(payStatus == 1){ //解封,判断用户权益,用户会员权益无限容量
|
|
|
- wrapper.orderByAsc(ScenePro::getCreateTime);
|
|
|
- plusWr.orderByAsc(ScenePlus::getCreateTime);
|
|
|
- wrapper.eq(ScenePro::getPayStatus,-2);
|
|
|
- plusWr.eq(ScenePlus::getPayStatus,-2);
|
|
|
- }else {
|
|
|
- if (totalSpace >= cameraDetail.getUsedSpace()) {
|
|
|
- // 总容量大于已使用容量,不予封存
|
|
|
- return;
|
|
|
- }
|
|
|
- wrapper.orderByDesc(ScenePro::getCreateTime);
|
|
|
- plusWr.orderByDesc(ScenePlus::getCreateTime);
|
|
|
- wrapper.eq(ScenePro::getPayStatus,1);
|
|
|
- plusWr.eq(ScenePlus::getPayStatus,1);
|
|
|
- }
|
|
|
-
|
|
|
- wrapper.eq(ScenePro::getCameraId,cameraId)
|
|
|
- .eq(ScenePro::getIsUpgrade,0);
|
|
|
-
|
|
|
- plusWr.eq(ScenePlus::getCameraId,cameraId);
|
|
|
-
|
|
|
- List<ScenePro> list = this.list(wrapper);
|
|
|
- List<ScenePlus> plusList = scenePlusService.list(plusWr);
|
|
|
-
|
|
|
- Long beyondSpace = Math.abs(cameraDetail.getUsedSpace() - totalSpace);
|
|
|
- Long accumulateSpace = 0L;
|
|
|
- List<Long> lockedIds = new ArrayList<>();
|
|
|
- if(payStatus == 1){
|
|
|
- Long doSpace = getScenePlusLockedIds(lockedIds, plusList, totalSpace, beyondSpace, accumulateSpace);
|
|
|
- beyondSpace -= doSpace;
|
|
|
- getSceneLockedIds(lockedIds,list,totalSpace,beyondSpace,accumulateSpace);
|
|
|
- }else {
|
|
|
- Long doSpace = getSceneLockedIds(lockedIds, list, totalSpace, beyondSpace, accumulateSpace);
|
|
|
- beyondSpace -= doSpace;
|
|
|
- getScenePlusLockedIds(lockedIds,plusList,totalSpace,beyondSpace,accumulateSpace);
|
|
|
- }
|
|
|
-
|
|
|
- lockOrUnLockScenes(lockedIds,payStatus);
|
|
|
- }
|
|
|
-
|
|
|
- private Long 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 ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
|
|
|
- return accumulateSpace - scenePro.getSpace();
|
|
|
- }
|
|
|
- lockedIds.add(scenePro.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- return accumulateSpace;
|
|
|
- }
|
|
|
- private Long 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 ==-1 && accumulateSpace.compareTo(beyondSpace) > 0){
|
|
|
- return accumulateSpace - scenePlusExt.getSpace();
|
|
|
- }
|
|
|
- lockedIds.add(scenePlus.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- return accumulateSpace;
|
|
|
- }
|
|
|
-
|
|
|
- // 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);
|
|
|
-
|
|
|
- this.updateOssStatus(lockedIds,payStatus);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改oss status.json中 payStatus
|
|
|
- */
|
|
|
- private void updateOssStatus(List<Long> lockedIds, Integer payStatus) {
|
|
|
- LambdaQueryWrapper<ScenePro> proWr = new LambdaQueryWrapper<>();
|
|
|
- proWr.eq(ScenePro::getIsUpgrade,0);
|
|
|
- proWr.in(ScenePro::getId,lockedIds);
|
|
|
- List<ScenePro> proList = this.list(proWr);
|
|
|
|
|
|
- LambdaQueryWrapper<ScenePlus> pluWr = new LambdaQueryWrapper<>();
|
|
|
- pluWr.in(ScenePlus::getId,lockedIds);
|
|
|
- List<ScenePlus> plusList = scenePlusService.list(pluWr);
|
|
|
- for (ScenePro scenePro : proList) {
|
|
|
- this.updateOssStatus(String.format(OssPath.v3_statusPath,scenePro.getNum()),payStatus);
|
|
|
- }
|
|
|
- for (ScenePlus scenePlus : plusList) {
|
|
|
- this.updateOssStatus(String.format(OssPath.v4_statusPath,scenePlus.getNum()),payStatus);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从oss中获取文件,并重写,上传替换
|
|
|
- */
|
|
|
- private void updateOssStatus(String path,Integer payStatus) {
|
|
|
- try {
|
|
|
- if(!mangerUploadToOssUtil.existKey(path)){
|
|
|
- return;
|
|
|
- }
|
|
|
- String data = mangerUploadToOssUtil.getObjectContent("4dkankan",path);
|
|
|
- if(StringUtils.isBlank(data)){
|
|
|
- return;
|
|
|
- }
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
- jsonObject.put("payStatus",payStatus);
|
|
|
- String json = JSONUtil.toJsonStr(jsonObject);
|
|
|
- FileUtils.writeFile(OssPath.localStatusPath ,json);
|
|
|
- log.info("updateOssStatus--localPath:{},ossPath:{}",OssPath.localStatusPath,path);
|
|
|
- mangerUploadToOssUtil.upload(OssPath.localStatusPath,path);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }finally {
|
|
|
- FileUtil.del(OssPath.localStatusPath);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|