CameraDetailServiceImpl.java 10 KB

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