123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package com.fdkankan.manage.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.common.constant.Constant;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.manage.common.CameraTypeEnum;
- import com.fdkankan.manage.entity.Camera;
- import com.fdkankan.manage.entity.CameraDetail;
- import com.fdkankan.manage.entity.User;
- import com.fdkankan.manage.mapper.ICameraDetailMapper;
- import com.fdkankan.manage.service.*;
- import com.fdkankan.manage.vo.response.GroupByCount;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 相机子表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-06-16
- */
- @Service
- public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, CameraDetail> implements ICameraDetailService {
- @Autowired
- ICameraService cameraService;
- @Autowired
- ISceneCooperationService sceneCooperationService;
- @Autowired
- ISceneProService sceneProService;
- @Autowired
- ISceneService sceneService;
- @Autowired
- IFdkkLaserService fdkkLaserService;
- @Autowired
- IUserService userService;
- @Override
- public void unbindCamera(Long cameraId) {
- CameraDetail cameraDetail = this.getByCameraId(cameraId);
- if(cameraDetail == null){
- throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST);
- }
- User user = userService.getById(cameraDetail.getUserId());
- if(user == null){
- throw new BusinessException(ErrorCode.USER_NOT_EXIST);
- }
- String snCode = null;
- String cooperationUserName = null;
- if(cameraDetail.getType() == CameraTypeEnum.LASER_TURN.getType()){
- Camera cameraEntity = cameraService.getById(cameraDetail.getCameraId());
- snCode = cameraEntity.getSnCode();
- cooperationUserName = user.getUserName();
- fdkkLaserService.disableCooperation(snCode,cooperationUserName); //通知深时删除协作场景
- }
- sceneCooperationService.deleteCooperation(cameraId); //删除协作场景关系
- cameraDetail.setUserId(null);
- cameraDetail.setCooperationUser(null);
- //恢复10G基本容量
- cameraDetail.setTotalSpace(Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
- this.updateById(cameraDetail);
- sceneProService.lockOrUnLockBySpace(cameraDetail,cameraId,-2); //封存场景
- }
- @Override
- public CameraDetail getByCameraId(Long cameraId) {
- LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CameraDetail::getCameraId,cameraId);
- List<CameraDetail> list = this.list(wrapper);
- if(list == null || list.size() <=0){
- return null;
- }
- return list.get(0);
- }
- @Override
- public List<CameraDetail> getByCameraIds(List<Long> cameraIds) {
- LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(CameraDetail::getCameraId,cameraIds);
- return this.list(wrapper);
- }
- @Override
- public void deleteByCameraId(Long cameraId) {
- LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CameraDetail::getCameraId,cameraId);
- this.remove(wrapper);
- }
- @Override
- public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
- HashMap<Long,Long> map = new HashMap<>();
- List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
- result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
- return map;
- }
- @Override
- public HashMap<Long, Long> getCountGroupByCompanyId() {
- List<GroupByCount> result = this.getBaseMapper().getCountGroupByCompanyId();
- HashMap<Long,Long> map = new HashMap<>();
- result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
- return map;
- }
- @Override
- public HashMap<Long, Long> getSceneCountGroupByCameraId() {
- LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
- wrapper.isNotNull(CameraDetail::getCompanyId);
- List<CameraDetail> list = this.list(wrapper);
- Set<Long> cameraIds = list.parallelStream().map(CameraDetail::getCameraId).collect(Collectors.toSet());
- HashMap<Long, Long> resultMap = new HashMap<>();
- HashMap<Long, Long> sceneProMap = sceneProService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
- HashMap<Long, Long> sceneMap = sceneService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
- for (CameraDetail cameraDetail : list) {
- Long sceneProCount = sceneProMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneProMap.get(cameraDetail.getCameraId());
- Long sceneCount = sceneMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneMap.get(cameraDetail.getCameraId());
- Long count = sceneProCount + sceneCount;
- resultMap.merge(cameraDetail.getCompanyId(), count, Long::sum);
- }
- return resultMap;
- }
- @Override
- public Long getCountByCompanyId(Long companyId) {
- LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CameraDetail::getCompanyId,companyId);
- return this.count(wrapper);
- }
- }
|