CameraDetailServiceImpl.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package com.fdkankan.ucenter.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  5. import com.fdkankan.common.constant.Constant;
  6. import com.fdkankan.ucenter.common.constants.NacosProperty;
  7. import com.fdkankan.ucenter.entity.*;
  8. import com.fdkankan.ucenter.httpClient.service.LaserService;
  9. import com.fdkankan.ucenter.mapper.ICameraDetailMapper;
  10. import com.fdkankan.ucenter.service.*;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.ucenter.vo.response.CameraAppVo;
  13. import com.fdkankan.ucenter.vo.response.CameraExcelVo;
  14. import com.fdkankan.ucenter.vo.response.CameraSpaceVo;
  15. import org.joda.time.DateTime;
  16. import org.joda.time.Days;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.*;
  20. /**
  21. * <p>
  22. * 相机子表 服务实现类
  23. * </p>
  24. *
  25. * @author
  26. * @since 2022-07-04
  27. */
  28. @Service
  29. public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, CameraDetail> implements ICameraDetailService {
  30. @Autowired
  31. IUserService userService;
  32. @Autowired
  33. ICameraSpaceService cameraSpaceService;
  34. @Autowired
  35. LaserService fdkkLaserService;
  36. @Autowired
  37. ICameraService cameraService;
  38. @Autowired
  39. ISceneCooperationService sceneCooperationService;
  40. @Autowired
  41. ISceneProService sceneProService;
  42. @Autowired
  43. IScenePlusService scenePlusService;
  44. @Override
  45. public CameraDetail getByCameraId(Long cameraId) {
  46. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  47. wrapper.eq(CameraDetail::getCameraId,cameraId);
  48. List<CameraDetail> list = this.list(wrapper);
  49. if(list!=null && list.size() >0){
  50. return list.get(0);
  51. }
  52. return null;
  53. }
  54. @Override
  55. public HashMap<Long, CameraDetail> getByCameraIds(List<Long> cameraIds) {
  56. HashMap<Long, CameraDetail> map = new HashMap<>();
  57. if(cameraIds.size() >0){
  58. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  59. wrapper.in(CameraDetail::getCameraId,cameraIds);
  60. List<CameraDetail> list = this.list(wrapper);
  61. list.forEach(entity -> map.put(entity.getCameraId(),entity));
  62. }
  63. return map;
  64. }
  65. @Override
  66. public Long getCountByUserId(Long userId,Integer type) {
  67. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  68. wrapper.eq(CameraDetail::getUserId,userId);
  69. if(type != null){
  70. wrapper.eq(CameraDetail::getGoodsId,type);
  71. }
  72. return this.count(wrapper);
  73. }
  74. @Override
  75. public Integer deadlineNumber(String username) {
  76. User user = userService.getByUserName(username);
  77. QueryWrapper<CameraDetail> queryWrapper = new QueryWrapper<>();
  78. queryWrapper.lambda().eq(CameraDetail::getUserId,user.getId());
  79. List<CameraDetail> list = this.list(queryWrapper);
  80. Integer number = 0;
  81. List<CameraSpaceVo> cameraList = null;
  82. for (CameraDetail cameraDetailEntity : list) {
  83. cameraList = cameraSpaceService.getVoListByCameraId(cameraDetailEntity.getCameraId());
  84. if(cameraList != null && cameraList.size() > 0){
  85. if(Days.daysBetween(new DateTime(), new DateTime(cameraList.get(0).getSpaceEndTime())).getDays() < 30){
  86. number++;
  87. }
  88. }
  89. }
  90. return number;
  91. }
  92. @Override
  93. public void unbindCamera(List<Long> cameraIds) {
  94. HashMap<Long, CameraDetail> detailMap = this.getByCameraIds(cameraIds);
  95. HashMap<Long, Camera> cameraMap = cameraService.getByIds(cameraIds);
  96. for (CameraDetail cameraDetail : detailMap.values()) {
  97. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  98. wrapper.eq(CameraDetail::getId,cameraDetail.getId());
  99. wrapper.set(CameraDetail::getUserId,null);
  100. wrapper.set(CameraDetail::getCooperationUser,null);
  101. wrapper.set(CameraDetail::getTotalSpace,Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
  102. this.update(wrapper);
  103. cameraDetail.setTotalSpace(Long.parseLong(Constant.EXPANSION_SPACE_VALUE_1G ) * 10L);
  104. if(!"local".equals(NacosProperty.uploadType) && cameraDetail.getType()!=10){
  105. sceneProService.lockOrUnLockBySpace(cameraDetail,cameraDetail.getCameraId(),-2); //封存场景
  106. }
  107. if(cameraDetail.getType() == 10){
  108. fdkkLaserService.toBind(false,cameraMap.get(cameraDetail.getCameraId()).getSnCode(),null,null);
  109. }
  110. }
  111. //恢复10G基本容量
  112. //删除场景协作信息
  113. List<ScenePro> sceneProList = sceneProService.getListByCameraIds(cameraIds);
  114. List<ScenePlus> scenePlusList = scenePlusService.getListByCameraIds(cameraIds);
  115. sceneCooperationService.deleteCooperationList(sceneProList,scenePlusList);
  116. fdkkLaserService.disableCooperation(detailMap, cameraMap);
  117. }
  118. @Override
  119. public void bindCamera(List<Long> cameraIds,User user) {
  120. if(cameraIds.size() >0){
  121. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  122. wrapper.in(CameraDetail::getCameraId,cameraIds)
  123. .set(CameraDetail::getUserId,user.getId());
  124. this.update(wrapper);
  125. HashMap<Long, CameraDetail> detailMap = this.getByCameraIds(cameraIds);
  126. HashMap<Long, Camera> cameraMap = cameraService.getByIds(cameraIds);
  127. for (CameraDetail cameraDetail : detailMap.values()) {
  128. if(cameraDetail.getType() == 10){
  129. fdkkLaserService.toBind(true,cameraMap.get(cameraDetail.getCameraId()).getSnCode(),user.getUserName(),user.getId());
  130. }
  131. }
  132. }
  133. }
  134. @Override
  135. public void updateCooperationByIds(List<Long> cameraIds, Long userId) {
  136. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  137. wrapper.in(CameraDetail::getCameraId,cameraIds)
  138. .set(CameraDetail::getCooperationUser,userId);
  139. this.update(wrapper);
  140. }
  141. @Override
  142. public void addUsedSpace(HashMap<Long, Long> cameraMap) {
  143. Set<Long> cameraIds = cameraMap.keySet();
  144. LambdaQueryWrapper<CameraDetail> wrapper = new LambdaQueryWrapper<>();
  145. wrapper.in(CameraDetail::getCameraId,cameraIds);
  146. List<CameraDetail> list = this.list(wrapper);
  147. for (CameraDetail cameraDetail : list) {
  148. long subSpace = cameraMap.get(cameraDetail.getCameraId()) == null ? 0L : cameraMap.get(cameraDetail.getCameraId());
  149. long usedSpace = cameraDetail.getUsedSpace() - subSpace ;
  150. cameraDetail.setUsedSpace(usedSpace < 0 ? 0L :usedSpace);
  151. //解封封存场景
  152. sceneProService.lockOrUnLockBySpace(cameraDetail,cameraDetail.getCameraId(),1);
  153. }
  154. this.updateBatchById(list);
  155. }
  156. @Override
  157. public List<CameraAppVo> getListByUserAndType(Long userId, Integer cameraType) {
  158. return this.getBaseMapper().getListByUserAndType(userId,cameraType);
  159. }
  160. @Override
  161. public List<CameraAppVo> getListByUserIdsAndType(List<Long> userId, Integer cameraType) {
  162. return this.getBaseMapper().getListByUserIdsAndType(userId,cameraType);
  163. }
  164. @Override
  165. public boolean updateCameraBalance(Long cameraId, int body, Integer points) {
  166. CameraDetail detailEntity = this.getByCameraId(cameraId);
  167. int sub = Integer.parseInt(detailEntity.getBalance());
  168. if (0 == body){
  169. sub += points;
  170. }else if (-2 == body){
  171. sub -= points;
  172. }
  173. detailEntity.setBalance(String.valueOf(sub));
  174. return this.updateById(detailEntity);
  175. }
  176. @Override
  177. public void uploadUserCameraInfo(Long id, String cameraVersion, String appVersion) {
  178. LambdaUpdateWrapper<CameraDetail> wrapper = new LambdaUpdateWrapper<>();
  179. wrapper.eq(CameraDetail::getCameraId,id)
  180. .set(CameraDetail::getUserCameraVersion,cameraVersion)
  181. .set(CameraDetail::getAppVersion,appVersion)
  182. .set(CameraDetail::getLastRequestTime,new Date());
  183. this.update(wrapper);
  184. }
  185. @Override
  186. public List<CameraExcelVo> getListByUserAndTypeEx(Long userId) {
  187. return this.getBaseMapper().getListByUserAndTypeEx(userId);
  188. }
  189. }