SceneProServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.fdkankan.agent.service.impl;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fdkankan.agent.common.OssPath;
  9. import com.fdkankan.agent.common.PageInfo;
  10. import com.fdkankan.agent.common.ResultCode;
  11. import com.fdkankan.agent.entity.*;
  12. import com.fdkankan.agent.exception.BusinessException;
  13. import com.fdkankan.agent.httpClient.client.FdKKClient;
  14. import com.fdkankan.agent.httpClient.service.LaserService;
  15. import com.fdkankan.agent.mapper.ISceneProMapper;
  16. import com.fdkankan.agent.request.SceneParam;
  17. import com.fdkankan.agent.response.SceneVo;
  18. import com.fdkankan.agent.service.*;
  19. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  20. import com.fdkankan.agent.util.MangerUploadToOssUtil;
  21. import com.fdkankan.agent.util.SceneStatusUtil;
  22. import com.fdkankan.common.constant.SceneConstant;
  23. import com.fdkankan.common.util.FileUtils;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import javax.annotation.Resource;
  29. import java.util.ArrayList;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.stream.Collectors;
  33. /**
  34. * <p>
  35. * pro场景表 服务实现类
  36. * </p>
  37. *
  38. * @author
  39. * @since 2022-11-09
  40. */
  41. @Service
  42. @Slf4j
  43. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  44. @Autowired
  45. LaserService laserService;
  46. @Autowired
  47. IScenePlusService scenePlusService;
  48. @Autowired
  49. IScenePlusExtService scenePlusExtService;
  50. @Resource
  51. FdKKClient fdKKClient;
  52. @Autowired
  53. ICameraService cameraService;
  54. @Autowired
  55. ICameraDetailService cameraDetailService;
  56. @Autowired
  57. IUserIncrementService userIncrementService;
  58. @Autowired
  59. IIncrementTypeService incrementTypeService;
  60. @Autowired
  61. MangerUploadToOssUtil mangerUploadToOssUtil;
  62. @Autowired
  63. IFolderSceneService folderSceneService;
  64. @Autowired
  65. ISceneService sceneService;
  66. @Autowired
  67. ISceneCopyLogService sceneCopyLogService;
  68. @Override
  69. public Object pageList(SceneParam param) {
  70. if(param.getType() == 2){ //深时
  71. return laserService.pageList(param);
  72. }
  73. Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  74. HashMap<String,SceneCopyLog> map = null;
  75. if(page.getRecords().size() >0){
  76. List<String> numList = page.getRecords().parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  77. map = sceneCopyLogService.getByNewNumList(numList);
  78. }
  79. for (SceneVo record : page.getRecords()) {
  80. record.setStatusString(SceneStatusUtil.getStatusString(record));
  81. if(map !=null ){
  82. SceneCopyLog sceneCopyLog = map.get(record.getNum());
  83. if(sceneCopyLog != null){
  84. record.setCopyTime(sceneCopyLog.getCreateTime());
  85. record.setIsCopy(true);
  86. }
  87. }
  88. }
  89. return PageInfo.PageInfo(page);
  90. }
  91. @Override
  92. public void copy(String sceneNum) throws Exception {
  93. ScenePro scenePro = this.getByNum(sceneNum);
  94. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  95. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  96. throw new BusinessException(ResultCode.SCENE_EMPTY);
  97. }
  98. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  99. Camera camera = cameraService.getById(cameraId);
  100. if(camera == null){
  101. throw new BusinessException(ResultCode.CAMERA_EMPTY);
  102. }
  103. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  104. if(detailEntity == null){
  105. throw new BusinessException(ResultCode.CAMERA_EMPTY);
  106. }
  107. Long needSpace = 0L;
  108. if(scenePro != null){
  109. needSpace = scenePro.getSpace();
  110. }
  111. if(scenePlus != null){
  112. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  113. if(scenePlusExt != null && scenePlusExt.getSpace() != null){
  114. needSpace = scenePlusExt.getSpace();
  115. }
  116. }
  117. Boolean checkSpace = cameraDetailService.checkSpace(detailEntity, needSpace);
  118. if(!checkSpace){
  119. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  120. }
  121. HashMap<String, Object> param = new HashMap<>();
  122. param.put("num",sceneNum);
  123. JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
  124. Integer code = jsonObject.getInteger("code");
  125. if(code != 0){
  126. throw new BusinessException(jsonObject.getInteger("code"),jsonObject.getString("msg"));
  127. }
  128. }
  129. @Override
  130. public ScenePro getByNum(String num) {
  131. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  132. wrapper.eq(ScenePro::getNum,num);
  133. wrapper.eq(ScenePro::getIsUpgrade,0);
  134. List<ScenePro> list = this.list(wrapper);
  135. if(list == null || list.size() <=0){
  136. return null;
  137. }
  138. return list.get(0);
  139. }
  140. @Override
  141. public Long getCountByCameraId(Long cameraId) {
  142. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  143. wrapper.eq(ScenePro::getIsUpgrade,0);
  144. wrapper.eq(ScenePro::getCameraId,cameraId);
  145. wrapper.in(ScenePro::getStatus,0,-2);
  146. return this.count(wrapper);
  147. }
  148. }