ScenePlusServiceImpl.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.fdkankan.common.constant.ErrorCode;
  7. import com.fdkankan.common.constant.PayStatus;
  8. import com.fdkankan.common.constant.SceneStatus;
  9. import com.fdkankan.common.constant.SpaceType;
  10. import com.fdkankan.contro.entity.CameraDetail;
  11. import com.fdkankan.contro.entity.ScenePlus;
  12. import com.fdkankan.contro.entity.ScenePlusExt;
  13. import com.fdkankan.contro.entity.ScenePro;
  14. import com.fdkankan.contro.mapper.IScenePlusMapper;
  15. import com.fdkankan.contro.service.ICameraDetailService;
  16. import com.fdkankan.contro.service.IScenePlusExtService;
  17. import com.fdkankan.contro.service.IScenePlusService;
  18. import com.fdkankan.web.response.ResultData;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.util.ObjectUtils;
  24. import java.util.List;
  25. import java.util.Objects;
  26. import java.util.stream.Collectors;
  27. /**
  28. * <p>
  29. * 场景主表 服务实现类
  30. * </p>
  31. *
  32. * @author
  33. * @since 2022-03-16
  34. */
  35. @Slf4j
  36. @Service
  37. public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
  38. @Autowired
  39. private IScenePlusExtService scenePlusExtService;
  40. @Autowired
  41. private ICameraDetailService cameraDetailService;
  42. @Override
  43. public ScenePlus getScenePlusByNum(String num) {
  44. return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
  45. }
  46. @Override
  47. public ResultData resetSpace(String num){
  48. ScenePlus scenePlus = this.getScenePlusByNum(num);
  49. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  50. if(Objects.isNull(scenePlus)){
  51. log.info("该场景不存在无法重置容量,场景码为:" + num);
  52. return ResultData.error(ErrorCode.FAILURE_CODE_5058);
  53. }
  54. if(scenePlus.getSceneStatus() == SceneStatus.EXCEED_SPACE.code()){//超出容量的场景不需要更新容量
  55. return ResultData.ok();
  56. }
  57. if(!ObjectUtils.isEmpty(scenePlusExt) && !ObjectUtils.isEmpty(scenePlusExt.getSpace())){
  58. Long space = -scenePlusExt.getSpace();
  59. CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
  60. String spaceType = cameraDetail.getUnit();
  61. if(spaceType.equals(SpaceType.SP.code())){
  62. space = -1L;
  63. }
  64. cameraDetailService.updateCameraDetailByCameraIdAndSpace(scenePlus.getCameraId(), space);
  65. }
  66. scenePlusExt.setSpace(Long.parseLong("0"));
  67. scenePlusExtService.updateById(scenePlusExt);
  68. return ResultData.ok();
  69. }
  70. @Override
  71. public String getDataSourceLikeUnicode(String unicode) {
  72. // 防止plus表删除,ext表未删除
  73. ScenePlusExt scenePlusExt = scenePlusExtService.getOne(
  74. new LambdaQueryWrapper<ScenePlusExt>().select(ScenePlusExt::getPlusId, ScenePlusExt::getDataSource).like(ScenePlusExt::getDataSource, unicode));
  75. if (Objects.isNull(scenePlusExt)) {
  76. return null;
  77. }
  78. ScenePlus plus = getById(scenePlusExt.getPlusId());
  79. if (Objects.nonNull(plus)) {
  80. return scenePlusExt.getDataSource();
  81. }
  82. scenePlusExtService.removeById(scenePlusExt);
  83. return null;
  84. }
  85. @Override
  86. public ScenePlus getByFileId(String fileId) {
  87. // 防止plus表删除,ext表未删除
  88. List<ScenePlusExt> scenePlusExts = scenePlusExtService.list(
  89. new LambdaQueryWrapper<ScenePlusExt>().like(ScenePlusExt::getDataSource, fileId)
  90. .eq(ScenePlusExt::getRecStatus, "A"));
  91. if (ObjectUtils.isEmpty(scenePlusExts)) {
  92. return null;
  93. }
  94. for (ScenePlusExt scenePlusExt : scenePlusExts) {
  95. ScenePlus plus = getById(scenePlusExt.getPlusId());
  96. if (!ObjectUtils.isEmpty(plus) && plus.getRecStatus().equals("A")) {
  97. return plus;
  98. }
  99. }
  100. return null;
  101. }
  102. @Override
  103. public Long sumUsedSpaceByCameraId(Long cameraId, String spaceTypeStr) {
  104. LambdaQueryWrapper<ScenePlus> wrapper = new LambdaQueryWrapper<ScenePlus>()
  105. .eq(ScenePlus::getCameraId, cameraId)
  106. .in(ScenePlus::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code());
  107. SpaceType spaceType = SpaceType.get(spaceTypeStr);
  108. switch (spaceType){
  109. case GB:
  110. List<ScenePlus> list = this.list(wrapper);
  111. if(CollUtil.isEmpty(list)){
  112. return 0L;
  113. }
  114. List<Long> plusIdList = list.stream().map(scenePlus -> scenePlus.getId()).collect(Collectors.toList());
  115. List<ScenePlusExt> scenePlusExtList = scenePlusExtService.list(new LambdaQueryWrapper<ScenePlusExt>().in(ScenePlusExt::getPlusId, plusIdList));
  116. return scenePlusExtList.stream().mapToLong(pro -> {
  117. Long space = pro.getSpace();
  118. return Objects.isNull(space) ? 0L : space;
  119. }).sum();
  120. case SP:
  121. wrapper.eq(ScenePlus::getPayStatus, PayStatus.PAY.code());
  122. return this.count(wrapper);
  123. }
  124. return null;
  125. }
  126. }