package com.fdkankan.manage.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.constant.SceneConstant;
import com.fdkankan.fyun.face.FYunFileServiceInterface;
import com.fdkankan.manage.common.*;
import com.fdkankan.manage.exception.BusinessException;
import com.fdkankan.common.util.*;
import com.fdkankan.manage.httpClient.client.FdKKClient;
import com.fdkankan.manage.httpClient.service.LaserService;
import com.fdkankan.manage.entity.*;
import com.fdkankan.manage.mapper.ISceneProMapper;
import com.fdkankan.manage.service.*;
import com.fdkankan.manage.util.Dateutils;
import com.fdkankan.manage.util.SceneStatusUtil;
import com.fdkankan.manage.vo.request.SceneParam;
import com.fdkankan.manage.vo.response.CameraDataVo;
import com.fdkankan.manage.vo.response.GroupByCount;
import com.fdkankan.manage.vo.response.SceneVo;
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.concurrent.CompletableFuture;
import java.util.stream.Collectors;
/**
*
* pro场景表 服务实现类
*
*
* @author
* @since 2022-06-16
*/
@Service
@Slf4j
public class SceneProServiceImpl extends ServiceImpl implements ISceneProService {
@Autowired
private ICameraService cameraService;
@Autowired
ICameraDetailService cameraDetailService;
@Autowired
ISceneService sceneService;
@Autowired
ISceneCopyLogService copyLogService;
@Autowired
IUserIncrementService userIncrementService;
@Autowired
IIncrementTypeService incrementTypeService;
@Autowired
ISceneProEditService sceneProEditService;
@Autowired
FYunFileServiceInterface fYunFileServiceInterface;
@Autowired
IScenePlusService scenePlusService;
@Autowired
IScene3dNumService scene3dNumService;
@Autowired
ISceneCopyLogService sceneCopyLogService;
@Autowired
IScenePlusExtService scenePlusExtService;
@Autowired
LaserService laserService;
@Autowired
FdKKClient fdKKClient;
@Autowired
IFolderSceneService folderSceneService;
@Autowired
ISceneBuildProcessLogService sceneBuildProcessLogService;
@Override
public ScenePro getByNum(String num) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ScenePro::getNum,num);
wrapper.eq(ScenePro::getIsUpgrade,0);
List list = this.list(wrapper);
if(list == null || list.size() <=0){
return null;
}
return list.get(0);
}
@Override
public HashMap getCountGroupByUserId(List userIdList,Integer isObj) {
HashMap map = new HashMap<>();
List result = this.getBaseMapper().getCountGroupByUserId(userIdList,isObj);
result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
return map;
}
@Override
public HashMap getCountGroupByCameraId(List cameraIds) {
HashMap map = new HashMap<>();
List result = this.getBaseMapper().getCountGroupByCameraId(cameraIds);
result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
return map;
}
@Override
public void unbindCamera(Long cameraId) {
LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>();
wrapper.set(ScenePro::getUserId,null)
.eq(ScenePro::getCameraId,cameraId);
wrapper.eq(ScenePro::getIsUpgrade,0);
this.update(wrapper);
}
@Override
public List getListByCameraId(Long cameraId) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ScenePro::getCameraId,cameraId);
wrapper.eq(ScenePro::getIsUpgrade,0);
return this.list(wrapper);
}
/**
* @param payStatus -2 封存,为 1 解封
*/
@Override
public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId, Integer payStatus) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper 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* 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 == -1 || 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 list = this.list(wrapper);
List plusList = scenePlusService.list(plusWr);
List lockedIds = new ArrayList<>();
if(totalSpace == -1 && payStatus == 1){
List collect = list.stream().map(ScenePro::getId).collect(Collectors.toList());
List collect2 = plusList.stream().map(ScenePlus::getId).collect(Collectors.toList());
lockedIds.addAll(collect);
lockedIds.addAll(collect2);
lockOrUnLockScenes(lockedIds,payStatus); // 无限容量 全部解封
return;
}
Long beyondSpace = 0L;
Long accumulateSpace = 0L;
if(payStatus == 1){
beyondSpace = totalSpace - cameraDetail.getTotalSpace();
getScenePlusLockedIds(lockedIds, plusList, beyondSpace, accumulateSpace);
getSceneLockedIds(lockedIds,list,beyondSpace,accumulateSpace);
}else {
beyondSpace = cameraDetail.getUsedSpace() - totalSpace;
getSceneLockedIds(lockedIds, list, beyondSpace, accumulateSpace);
getScenePlusLockedIds(lockedIds,plusList,beyondSpace,accumulateSpace);
}
lockOrUnLockScenes(lockedIds,payStatus);
}
@Override
public void lockOrUnLockBySpace(ScenePro scenePro, ScenePlus scenePlus,Integer payStatus) {
List lockedIds = new ArrayList<>();
if(scenePro!= null){
lockedIds.add(scenePro.getId());
}
if(scenePlus!= null){
lockedIds.add(scenePlus.getId());
}
lockOrUnLockScenes(lockedIds,payStatus); // 无限容量 全部解封
}
private void getSceneLockedIds(List lockedIds , List list, Long beyondSpace, Long accumulateSpace){
if (list != null && list.size() > 0){
for (ScenePro scenePro : list){
accumulateSpace += scenePro.getSpace();
if (accumulateSpace.compareTo(beyondSpace) > 0){
break;
}
lockedIds.add(scenePro.getId());
}
}
}
private void getScenePlusLockedIds(List lockedIds , List list, Long beyondSpace, Long accumulateSpace){
if (list != null && list.size() > 0){
List plusIds = list.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
HashMap byPlusIds = scenePlusExtService.getByPlusIds(plusIds);
for (ScenePlus scenePlus : list){
ScenePlusExt scenePlusExt = byPlusIds.get(scenePlus.getId());
accumulateSpace += scenePlusExt.getSpace();
if (accumulateSpace.compareTo(beyondSpace) > 0){
break;
}
lockedIds.add(scenePlus.getId());
}
}
}
// payStatus 为 -2 封存,为 1 解封
private void lockOrUnLockScenes(List lockedIds,Integer payStatus) {
if (lockedIds == null || lockedIds.size() == 0){
return;
}
LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(ScenePro::getPayStatus,payStatus)
.eq(ScenePro::getIsUpgrade,0)
.in(ScenePro::getId,lockedIds);
this.update(updateWrapper);
LambdaUpdateWrapper 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 lockedIds, Integer payStatus) {
LambdaQueryWrapper proWr = new LambdaQueryWrapper<>();
proWr.eq(ScenePro::getIsUpgrade,0);
proWr.in(ScenePro::getId,lockedIds);
List proList = this.list(proWr);
LambdaQueryWrapper pluWr = new LambdaQueryWrapper<>();
pluWr.in(ScenePlus::getId,lockedIds);
List 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) {
String localPath = String.format(OssPath.localStatusPath, path);
try {
if(!fYunFileServiceInterface.fileExist(path)){
return;
}
String data = fYunFileServiceInterface.getFileContent("4dkankan",path);
if(StringUtils.isBlank(data)){
return;
}
JSONObject jsonObject = JSONObject.parseObject(data);
jsonObject.put("payStatus",payStatus);
String json = JSONUtil.toJsonStr(jsonObject);
FileUtils.writeFile(localPath,json);
log.info("updateOssStatus--localPath:{},ossPath:{}",localPath,path);
fYunFileServiceInterface.uploadFile(localPath,path);
}catch (Exception e){
e.printStackTrace();
}finally {
FileUtil.del(localPath);
}
}
@Override
public PageInfo pageList(SceneParam param) {
if(param.getType() == 2){ //深时
return laserService.pageList(param);
}
if(param.getType() == 3){ //双目lite
return sceneService.pageList(param);
}
Page page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
List records = page.getRecords();
HashMap map = null;
if(records.size() >0){
List numList = records.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
map = copyLogService.getByNewNumList(numList);
}
for (SceneVo record : page.getRecords()) {
record.setStatusString(SceneStatusUtil.getStatusString(record));
if(map !=null ){
SceneCopyLog sceneCopyLog = map.get(record.getNum());
if(sceneCopyLog != null){
record.setCopyTime(sceneCopyLog.getCreateTime());
record.setIsCopy(true);
}
}
if(record.getStatus() == -1){ //计算失败
SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(record.getNum());
if(sceneBuildProcessLog != null){
record.setSceneBuildProcessLog(sceneBuildProcessLog);
record.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(sceneBuildProcessLog.getProcess()));
}
}
}
return PageInfo.PageInfo(page);
}
@Override
public void move(SceneParam param) {
Camera camera = cameraService.getBySnCode(param.getSnCode());
if(camera == null){
throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
}
CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
if(cameraDetail == null){
throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXIST);
}
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(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
}
Integer status = scenePro == null ? scenePlus.getSceneStatus() : scenePro.getStatus();
if(status == 0){
throw new BusinessException(SceneConstant.FAILURE_CODE_5037, SceneConstant.FAILURE_MSG_5037);
}
Long sceneCameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
Long space = scenePro == null ? 0 :scenePro.getSpace();
String dataSource = scenePro == null ? null :scenePro.getDataSource();
if(scenePlus !=null){
ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
space = scenePlusExt.getSpace();
dataSource = scenePlusExt.getDataSource();
}
space = space == null ? 0 :space;
Long newUseSpace = space + cameraDetail.getUsedSpace();
Long totalSpace = cameraDetail.getTotalSpace();
UserIncrement userIncrement = userIncrementService.getByCameraId(camera.getId());
if(userIncrement!=null){
IncrementType incrementType = incrementTypeService.getById(userIncrement.getIncrementTypeId());
if(incrementType!=null){
if(incrementType.getCameraCapacity() == -1){
totalSpace = -1L;
}else {
totalSpace = incrementType.getCameraCapacity() * 1024 *1024 * 1024L;
}
}
}
//深时场景无限容量
if(cameraDetail.getType() != 10 && totalSpace !=-1 && newUseSpace > totalSpace){
throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
}
Camera oldCamera = cameraService.getById(sceneCameraId);
if(oldCamera == null){
throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
}
CameraDetail oldCameraDetail = cameraDetailService.getByCameraId(oldCamera.getId());
if(oldCameraDetail == null){
throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
}
if(oldCameraDetail.getCameraId().equals(cameraDetail.getCameraId())){
throw new BusinessException(ResultCode.CAMERA_NOT_MOVE);
}
if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
throw new BusinessException(ResultCode.CAMERA_TYPE_NOT_ERROR);
}
Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
oldCameraDetail.setUsedSpace(oldUseSpace);
Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
if(oldCameraDetail.getType() != 10 && subSpace >0){ //有剩余容量解封容量内场景
this.lockOrUnLockBySpace(oldCameraDetail,oldCameraDetail.getCameraId(),1);
}
Integer payStatus = scenePro == null ? scenePlus.getPayStatus() : scenePro.getPayStatus();
if(cameraDetail.getType() != 10 && payStatus!=1){ //有剩余容量解封容量内场景
this.lockOrUnLockBySpace(scenePro,scenePlus,1);
}
cameraDetailService.updateById(oldCameraDetail);
cameraDetail.setUsedSpace(newUseSpace);
cameraDetailService.updateById(cameraDetail);
if(scenePro!=null){
LambdaUpdateWrapper 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 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(),cameraDetail.getUserId());
}
updateFdageNewDataSource(oldCamera.getSnCode(),param.getSnCode(),dataSource);
}
private JSONObject updateFdageJson(JSONObject jsonObject,String newSnCode){
JSONObject cam = jsonObject.getJSONObject("cam");
if(cam != null){
cam.put("uuid",newSnCode.toLowerCase()); //替换 相机sn
}
JSONArray points = jsonObject.getJSONArray("points"); //修改点位中的相机sn
if(points !=null){
for (Object point : points) {
JSONObject jobj = (JSONObject) point;
jobj.put("camera",newSnCode.toLowerCase());
}
}
jsonObject.put("creator",newSnCode.toLowerCase());
return jsonObject;
}
public void updateFdageNewDataSource(String oldSnCode,String newSnCode,String dataSource) {
String localPathFdage = null;
try {
String fdagePaht = dataSource.replace("/mnt/data","home") +"/data.fdage";
localPathFdage = String.format(OssPath.localFdagePath,fdagePaht);
String fileContent = fYunFileServiceInterface.getFileContent(fdagePaht);
JSONObject jsonObject = updateFdageJson(JSONObject.parseObject(fileContent), newSnCode);
FileUtils.writeFile(localPathFdage ,JSONObject.toJSONString(jsonObject));
String oldFdagePaht = dataSource.replace("/mnt/data","home") ;
String[] split = oldFdagePaht.split("/");
String newFdagePath = split[0] +"/"+ newSnCode +"/"+ split[2] +"/"+ newSnCode +"_" + split[3].split("_")[1];
if(!oldFdagePaht.equals(newFdagePath)){
log.info("updateFdageCopy--复制oss资源--oldFdagePaht:{},newFdagePath:{}",oldFdagePaht,newFdagePath);
fYunFileServiceInterface.copyFileInBucket(oldFdagePaht,newFdagePath);
fYunFileServiceInterface.deleteFolder(oldFdagePaht);
}
fYunFileServiceInterface.uploadFile(localPathFdage,newFdagePath);
log.info("updateFdage--localPathFdage:{},newFdagePath:{}",localPathFdage,newFdagePath);
String newDataSource = newFdagePath.replace("home","/mnt/data");
this.updateDataSource(dataSource,newDataSource);
}catch (Exception e){
log.error("updateFdage-error:oldSnCode:{},newSnCode:{},dataSource:{}",oldSnCode,newSnCode,dataSource);
log.error("updateFdage-error:",e);
}finally {
if(localPathFdage != null){
//FileUtil.del(localPathFdage);
}
}
}
private void updateDataSource(String dataSource, String newDataSource) {
LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(ScenePro::getDataSource,dataSource);
wrapper.eq(ScenePro::getIsUpgrade,0);
wrapper.set(ScenePro::getDataSource,newDataSource);
this.update(wrapper);
LambdaUpdateWrapper wrapperPlus = new LambdaUpdateWrapper<>();
wrapperPlus.eq(ScenePlusExt::getDataSource,dataSource);
wrapperPlus.set(ScenePlusExt::getDataSource,newDataSource);
scenePlusExtService.update(wrapperPlus);
}
@Override
public void copy(String sceneNum) throws Exception {
ScenePro scenePro = this.getByNum(sceneNum);
ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
}
Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
Camera camera = cameraService.getById(cameraId);
if(camera == null){
throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
}
CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
if(detailEntity == null){
throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
}
if(detailEntity.getType() == 10){
throw new BusinessException(ResultCode.SS_NO_COPY);
}
HashMap param = new HashMap<>();
param.put("num",sceneNum);
fdKKClient.copyScene(param,"m_a_n_a_g_e");
}
@Override
public void deleteByNum(String num) {
Integer sceneSource = null;
ScenePro scenePro = this.getByNum(num);
if(scenePro!=null){
sceneSource = scenePro.getSceneSource();
this.removeById(scenePro.getId());
}
Scene scene = sceneService.getByNum(num);
if(scene!=null){
sceneService.removeById(scene.getId());
}
ScenePlus scenePlus = scenePlusService.getByNum(num);
if(scenePlus!=null){
sceneSource = scenePlus.getSceneSource();
scenePlusService.removeById(scenePlus.getId());
scenePlusExtService.delByPlus(scenePlus.getId());
}
if(sceneSource != null && sceneSource == 4){
laserService.delete(num);
}
}
@Override
public Long getKkCount(List asList, String startTime) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.in(ScenePro::getSceneSource,asList);
wrapper.eq(ScenePro::getIsUpgrade,0);
wrapper.lt(ScenePro::getCreateTime,startTime);
long count = this.count(wrapper);
LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper<>();
wrapper2.in(ScenePlus::getSceneSource,asList);
wrapper2.lt(ScenePlus::getCreateTime,startTime);
long count1 = scenePlusService.count(wrapper2);
return count + count1;
}
@Override
public Long getSsCount(List asList, String startTime) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.in(ScenePro::getSceneSource,asList);
wrapper.eq(ScenePro::getIsUpgrade,0);
wrapper.lt(ScenePro::getCreateTime,startTime);
LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper<>();
wrapper2.in(ScenePlus::getSceneSource,asList);
wrapper2.lt(ScenePlus::getCreateTime,startTime);
long count = scenePlusService.count(wrapper2);
return this.count(wrapper) + count;
}
@Override
public Long getSsObjCount(List asList, String startTime) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.in(ScenePro::getSceneSource,asList);
wrapper.eq(ScenePro::getIsUpgrade,0);
if(StringUtils.isNotBlank(startTime)){
wrapper.lt(ScenePro::getCreateTime,startTime);
}
wrapper.eq(ScenePro::getIsObj,1);
LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper<>();
wrapper2.in(ScenePlus::getSceneSource,asList);
if(StringUtils.isNotBlank(startTime)){
wrapper2.lt(ScenePlus::getCreateTime,startTime);
}
List list = scenePlusService.list(wrapper2);
List plusIds = list.stream().map(ScenePlus::getId).collect(Collectors.toList());
long count = 0L;
if(plusIds.size() >0){
LambdaQueryWrapper wrapper3 = new LambdaQueryWrapper<>();
wrapper3.in(ScenePlusExt::getPlusId,plusIds);
wrapper3.eq(ScenePlusExt::getIsObj,1);
count = scenePlusExtService.count(wrapper3);
}
return this.count(wrapper) + count;
}
@Override
public HashMap getSnCodeByNumList(Set numList) {
HashMap sceneMap = new HashMap<>();
HashMap cameraMap = new HashMap<>();
HashMap snCodeMap = new HashMap<>();
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ScenePro::getIsUpgrade,0);
wrapper.in(ScenePro::getNum,numList);
List list = this.list(wrapper);
if(list.size() >0){
list.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
}
LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper<>();
wrapper2.in(ScenePlus::getNum,numList);
List list2 = scenePlusService.list(wrapper2);
if(list2.size() >0){
list2.forEach(entity -> sceneMap.put(entity.getNum(),entity.getCameraId()));
}
if(sceneMap.size() <=0){
return snCodeMap;
}
Set cameraIds = list.stream().map(ScenePro::getCameraId).collect(Collectors.toSet());
Set cameraIds2 = list2.stream().map(ScenePlus::getCameraId).collect(Collectors.toSet());
cameraIds.addAll(cameraIds2);
if(cameraIds.size() >0){
List cameraList = cameraService.listByIds(cameraIds);
cameraList.forEach(entity -> cameraMap.put(entity.getId(),entity.getSnCode()));
for (String num : numList) {
Long cameraId = sceneMap.get(num);
if(cameraId != null){
snCodeMap.put(num,cameraMap.get(cameraId));
}
}
}
return snCodeMap;
}
}