CameraDetailServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package com.fdkankan.manage.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.fdkankan.common.constant.Constant;
  6. import com.fdkankan.manage.common.CacheUtil;
  7. import com.fdkankan.manage.common.PageInfo;
  8. import com.fdkankan.manage.common.ResultCode;
  9. import com.fdkankan.manage.entity.*;
  10. import com.fdkankan.manage.exception.BusinessException;
  11. import com.fdkankan.manage.common.CameraTypeEnum;
  12. import com.fdkankan.manage.httpClient.service.LaserService;
  13. import com.fdkankan.manage.httpClient.vo.LaserUpdateUserVo;
  14. import com.fdkankan.manage.mapper.ICameraDetailMapper;
  15. import com.fdkankan.manage.service.*;
  16. import com.fdkankan.manage.vo.request.SceneParam;
  17. import com.fdkankan.manage.vo.response.GroupByCount;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Set;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 相机子表 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2022-06-16
  32. */
  33. @Service
  34. public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, CameraDetail> implements ICameraDetailService {
  35. @Autowired
  36. ICameraService cameraService;
  37. @Autowired
  38. ISceneCooperationService sceneCooperationService;
  39. @Autowired
  40. ISceneProService sceneProService;
  41. @Autowired
  42. ISceneService sceneService;
  43. @Autowired
  44. IScenePlusService scenePlusService;
  45. @Autowired
  46. LaserService fdkkLaserService;
  47. @Autowired
  48. IUserService userService;
  49. @Autowired
  50. LaserService laserService;
  51. @Override
  52. public void unbindCamera(Long cameraId) {
  53. CameraDetail cameraDetail = this.getByCameraId(cameraId);
  54. if(cameraDetail == null){
  55. throw new BusinessException(ResultCode.CAMERA_NOT_EXIST);
  56. }
  57. User user = userService.getById(cameraDetail.getUserId());
  58. if(user == null){
  59. throw new BusinessException(ResultCode.USER_NOT_EXIST);
  60. }
  61. String snCode = null;
  62. String cooperationUserName = null;
  63. if(cameraDetail.getType() == CameraTypeEnum.LASER_TURN.getType()){
  64. Camera cameraEntity = cameraService.getById(cameraDetail.getCameraId());
  65. snCode = cameraEntity.getSnCode();
  66. cooperationUserName = user.getUserName();
  67. fdkkLaserService.disableCooperation(snCode,cooperationUserName); //通知深时删除协作场景
  68. }
  69. sceneCooperationService.deleteCooperation(cameraId); //删除协作场景关系
  70. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  71. wrapper.eq(CameraDetail::getCameraId,cameraId);
  72. wrapper.set(CameraDetail::getUserId,null);
  73. wrapper.set(CameraDetail::getCooperationUser,null);
  74. //恢复10G基本容量
  75. wrapper.set(CameraDetail::getTotalSpace,Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
  76. this.update(wrapper);
  77. if(!"local".equals(CacheUtil.uploadType)){
  78. sceneProService.lockOrUnLockBySpace(cameraDetail,cameraId,-2); //封存场景
  79. }
  80. }
  81. @Override
  82. public CameraDetail getByCameraId(Long cameraId) {
  83. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  84. wrapper.eq(CameraDetail::getCameraId,cameraId);
  85. List<CameraDetail> list = this.list(wrapper);
  86. if(list == null || list.size() <=0){
  87. return null;
  88. }
  89. return list.get(0);
  90. }
  91. @Override
  92. public List<CameraDetail> getByCameraIds(List<Long> cameraIds) {
  93. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  94. wrapper.in(CameraDetail::getCameraId,cameraIds);
  95. return this.list(wrapper);
  96. }
  97. @Override
  98. public void deleteByCameraId(Long cameraId) {
  99. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  100. wrapper.eq(CameraDetail::getCameraId,cameraId);
  101. this.remove(wrapper);
  102. }
  103. @Override
  104. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
  105. HashMap<Long,Long> map = new HashMap<>();
  106. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
  107. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  108. return map;
  109. }
  110. @Override
  111. public HashMap<Long, Long> getCountGroupByCompanyId() {
  112. List<GroupByCount> result = this.getBaseMapper().getCountGroupByCompanyId();
  113. HashMap<Long,Long> map = new HashMap<>();
  114. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  115. return map;
  116. }
  117. @Override
  118. public HashMap<Long, Long> getSceneCountGroupByCameraId() {
  119. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  120. wrapper.isNotNull(CameraDetail::getCompanyId);
  121. List<CameraDetail> list = this.list(wrapper);
  122. Set<Long> cameraIds = list.parallelStream().map(CameraDetail::getCameraId).collect(Collectors.toSet());
  123. HashMap<Long, Long> resultMap = new HashMap<>();
  124. if(cameraIds.size() >0){
  125. HashMap<Long, Long> sceneProMap = sceneProService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
  126. HashMap<Long, Long> sceneMap = sceneService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
  127. HashMap<Long, Long> scenePlusMap = scenePlusService.getCountGroupByCameraId(new ArrayList<>(cameraIds));
  128. HashMap<Long,Camera> cameraHashMap = new HashMap<>();
  129. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  130. cameraList.forEach(entity -> cameraHashMap.put(entity.getId(),entity));
  131. HashMap<Long,List<String>> companySnCodeMap = new HashMap<>();
  132. for (CameraDetail cameraDetail : list) {
  133. Long sceneProCount = sceneProMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneProMap.get(cameraDetail.getCameraId());
  134. Long sceneCount = sceneMap.get(cameraDetail.getCameraId()) == null ? 0L : sceneMap.get(cameraDetail.getCameraId());
  135. Long scenePlusCount = scenePlusMap.get(cameraDetail.getCameraId()) == null ? 0L : scenePlusMap.get(cameraDetail.getCameraId());
  136. Long count = sceneProCount + sceneCount + scenePlusCount;
  137. List<String> snCodeList = companySnCodeMap.computeIfAbsent(cameraDetail.getCompanyId(), k -> new ArrayList<>());
  138. Camera camera = cameraHashMap.get(cameraDetail.getCameraId());
  139. if(camera != null){
  140. snCodeList.add(camera.getSnCode());
  141. }
  142. resultMap.merge(cameraDetail.getCompanyId(), count, Long::sum);
  143. }
  144. for (Long companyId : companySnCodeMap.keySet()) {
  145. List<String> snCodeList = companySnCodeMap.get(companyId);
  146. if(snCodeList == null || snCodeList.size() <=0){
  147. continue;
  148. }
  149. SceneParam param = new SceneParam();
  150. param.setSnCodes(snCodeList);
  151. //PageInfo pageInfo = laserService.pageList(param);
  152. //resultMap.merge(companyId, pageInfo.getTotal(), Long::sum);
  153. }
  154. }
  155. return resultMap;
  156. }
  157. @Override
  158. public Long getCountByCompanyId(Long companyId) {
  159. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  160. wrapper.eq(CameraDetail::getCompanyId,companyId);
  161. return this.count(wrapper);
  162. }
  163. @Override
  164. public List<CameraDetail> getListByCompanyId(Integer companyId) {
  165. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  166. wrapper.eq(CameraDetail::getCompanyId,companyId);
  167. return this.list(wrapper);
  168. }
  169. @Override
  170. public List<CameraDetail> getByUserName(String userName) {
  171. LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
  172. wrapper.like(User::getUserName,userName);
  173. List<User> list = userService.list(wrapper);
  174. if(list.size() >0){
  175. List<Long> userIds = list.stream().map(User::getId).collect(Collectors.toList());
  176. if(userIds.size() >0){
  177. LambdaQueryWrapper<CameraDetail> dtW = new LambdaQueryWrapper<>();
  178. dtW.in(CameraDetail::getUserId,userIds);
  179. return this.list(dtW);
  180. }
  181. }
  182. return null;
  183. }
  184. @Override
  185. public void delAgentId(Integer agentId) {
  186. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  187. wrapper.eq(CameraDetail::getAgentId,agentId);
  188. wrapper.set(CameraDetail::getAgentId,null);
  189. this.update(wrapper);
  190. }
  191. @Override
  192. public List<CameraDetail> getByUserId(Long userId) {
  193. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  194. wrapper.eq(CameraDetail::getUserId,userId);
  195. return this.list(wrapper);
  196. }
  197. @Override
  198. public void addUsedSpace(Long cameraId,Long space) {
  199. if(space == null){
  200. return;
  201. }
  202. CameraDetail cameraDetail = this.getByCameraId(cameraId);
  203. long usedSpace = cameraDetail.getUsedSpace() - space ;
  204. cameraDetail.setUsedSpace(usedSpace < 0 ? 0L :usedSpace);
  205. //解封封存场景
  206. if(!CacheUtil.uploadType.equals("local") && cameraDetail.getType() != 10 ){
  207. sceneProService.lockOrUnLockBySpace(cameraDetail,cameraDetail.getCameraId(),1);
  208. }
  209. this.updateById(cameraDetail);
  210. }
  211. @Override
  212. public void giveSuperAdmin(Long userId) {
  213. //删除用户通知深时修改场景归属
  214. laserService.updateUser(new LaserUpdateUserVo(userId,"admin",818L));
  215. LambdaUpdateWrapper<ScenePro> wrapper1 = new LambdaUpdateWrapper<>();
  216. wrapper1.eq(ScenePro::getUserId,userId);
  217. wrapper1.set(ScenePro::getUserId,818L);
  218. sceneProService.update(wrapper1);
  219. LambdaUpdateWrapper<ScenePlus> wrapper2 = new LambdaUpdateWrapper<>();
  220. wrapper2.eq(ScenePlus::getUserId,userId);
  221. wrapper2.set(ScenePlus::getUserId,818L);
  222. scenePlusService.update(wrapper2);
  223. }
  224. }