CameraDetailServiceImpl.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package com.fdkankan.manage.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.fdkankan.common.constant.Constant;
  5. import com.fdkankan.common.constant.ErrorCode;
  6. import com.fdkankan.common.exception.BusinessException;
  7. import com.fdkankan.manage.common.CameraTypeEnum;
  8. import com.fdkankan.manage.entity.Camera;
  9. import com.fdkankan.manage.entity.CameraDetail;
  10. import com.fdkankan.manage.entity.User;
  11. import com.fdkankan.manage.mapper.ICameraDetailMapper;
  12. import com.fdkankan.manage.service.*;
  13. import com.fdkankan.manage.vo.response.GroupByCount;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Set;
  20. import java.util.stream.Collectors;
  21. /**
  22. * <p>
  23. * 相机子表 服务实现类
  24. * </p>
  25. *
  26. * @author
  27. * @since 2022-06-16
  28. */
  29. @Service
  30. public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, CameraDetail> implements ICameraDetailService {
  31. @Autowired
  32. ICameraService cameraService;
  33. @Autowired
  34. ISceneCooperationService sceneCooperationService;
  35. @Autowired
  36. ISceneProService sceneProService;
  37. @Autowired
  38. ISceneService sceneService;
  39. @Autowired
  40. IFdkkLaserService fdkkLaserService;
  41. @Autowired
  42. IUserService userService;
  43. @Override
  44. public void unbindCamera(Long cameraId) {
  45. CameraDetail cameraDetail = this.getByCameraId(cameraId);
  46. if(cameraDetail == null){
  47. throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST);
  48. }
  49. User user = userService.getById(cameraDetail.getUserId());
  50. if(user == null){
  51. throw new BusinessException(ErrorCode.USER_NOT_EXIST);
  52. }
  53. String snCode = null;
  54. String cooperationUserName = null;
  55. if(cameraDetail.getType() == CameraTypeEnum.LASER_TURN.getType()){
  56. Camera cameraEntity = cameraService.getById(cameraDetail.getCameraId());
  57. snCode = cameraEntity.getSnCode();
  58. cooperationUserName = user.getUserName();
  59. fdkkLaserService.disableCooperation(snCode,cooperationUserName); //通知深时删除协作场景
  60. }
  61. sceneCooperationService.deleteCooperation(cameraId); //删除协作场景关系
  62. cameraDetail.setUserId(null);
  63. cameraDetail.setCooperationUser(null);
  64. //恢复10G基本容量
  65. cameraDetail.setTotalSpace(Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
  66. this.updateById(cameraDetail);
  67. sceneProService.lockOrUnLockBySpace(cameraDetail,cameraId,-2); //封存场景
  68. }
  69. @Override
  70. public CameraDetail getByCameraId(Long cameraId) {
  71. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  72. wrapper.eq(CameraDetail::getCameraId,cameraId);
  73. List<CameraDetail> list = this.list(wrapper);
  74. if(list == null || list.size() <=0){
  75. return null;
  76. }
  77. return list.get(0);
  78. }
  79. @Override
  80. public List<CameraDetail> getByCameraIds(List<Long> cameraIds) {
  81. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  82. wrapper.in(CameraDetail::getCameraId,cameraIds);
  83. return this.list(wrapper);
  84. }
  85. @Override
  86. public void deleteByCameraId(Long cameraId) {
  87. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  88. wrapper.eq(CameraDetail::getCameraId,cameraId);
  89. this.remove(wrapper);
  90. }
  91. @Override
  92. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
  93. HashMap<Long,Long> map = new HashMap<>();
  94. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
  95. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  96. return map;
  97. }
  98. @Override
  99. public HashMap<Long, Long> getCountGroupByCompanyId() {
  100. List<GroupByCount> result = this.getBaseMapper().getCountGroupByCompanyId();
  101. HashMap<Long,Long> map = new HashMap<>();
  102. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  103. return map;
  104. }
  105. @Override
  106. public HashMap<Long, Long> getSceneCountGroupByCameraId() {
  107. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  108. wrapper.isNotNull(CameraDetail::getCompanyId);
  109. List<CameraDetail> list = this.list(wrapper);
  110. Set<Long> cameraIds = list.parallelStream().map(CameraDetail::getCameraId).collect(Collectors.toSet());
  111. HashMap<Long, Long> resultMap = new HashMap<>();
  112. HashMap<Long, Long> sceneProMap = sceneProService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
  113. HashMap<Long, Long> sceneMap = sceneService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
  114. for (CameraDetail cameraDetail : list) {
  115. Long sceneProCount = sceneProMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneProMap.get(cameraDetail.getCameraId());
  116. Long sceneCount = sceneMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneMap.get(cameraDetail.getCameraId());
  117. Long count = sceneProCount + sceneCount;
  118. resultMap.merge(cameraDetail.getCompanyId(), count, Long::sum);
  119. }
  120. return resultMap;
  121. }
  122. @Override
  123. public Long getCountByCompanyId(Long companyId) {
  124. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  125. wrapper.eq(CameraDetail::getCompanyId,companyId);
  126. return this.count(wrapper);
  127. }
  128. }