SceneProServiceImpl.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.fdkankan.common.constant.*;
  8. import com.fdkankan.common.exception.BusinessException;
  9. import com.fdkankan.contro.common.Result;
  10. import com.fdkankan.contro.entity.ScenePlus;
  11. import com.fdkankan.contro.entity.ScenePlusExt;
  12. import com.fdkankan.contro.entity.ScenePro;
  13. import com.fdkankan.contro.httpclient.LaserClient;
  14. import com.fdkankan.contro.mapper.ISceneProMapper;
  15. import com.fdkankan.contro.mapper.ISceneUpgradeMapper;
  16. import com.fdkankan.contro.service.IScenePlusExtService;
  17. import com.fdkankan.contro.service.IScenePlusService;
  18. import com.fdkankan.contro.service.ISceneProService;
  19. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  20. import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
  21. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.http.HttpStatus;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.util.ObjectUtils;
  28. import javax.annotation.Resource;
  29. import java.util.List;
  30. import java.util.Objects;
  31. /**
  32. * <p>
  33. * pro场景表 服务实现类
  34. * </p>
  35. *
  36. * @author dengsixing
  37. * @since 2021-12-23
  38. */
  39. @Slf4j
  40. @Service
  41. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  42. @Value("${queue.modeling.obj.modeling-pre}")
  43. private String queueObjModelingPre;
  44. @Autowired
  45. private IScenePlusService scenePlusService;
  46. @Resource
  47. private FYunFileServiceInterface fYunFileService;
  48. @Resource
  49. private LaserClient laserClient;
  50. @Autowired
  51. private ISceneUpgradeMapper sceneUpgradeMapper;
  52. @Resource
  53. private RabbitMqProducer mqProducer;
  54. @Autowired
  55. private IScenePlusExtService scenePlusExtService;
  56. @Override
  57. public ScenePro getByNum(String num) {
  58. return this.getOne(new LambdaQueryWrapper<ScenePro>().eq(ScenePro::getNum, num));
  59. }
  60. @Override
  61. public Long sumUsedSpaceByCameraId(Long cameraId, String spaceTypeStr) {
  62. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<ScenePro>()
  63. .eq(ScenePro::getCameraId, cameraId)
  64. .in(ScenePro::getStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code())
  65. .eq(ScenePro::getIsUpgrade, CommonStatus.NO.code());
  66. SpaceType spaceType = SpaceType.get(spaceTypeStr);
  67. switch (spaceType){
  68. case GB:
  69. wrapper.select(ScenePro::getSpace);
  70. List<ScenePro> list = this.list(wrapper);
  71. if(CollUtil.isEmpty(list)){
  72. return 0L;
  73. }
  74. return list.stream().mapToLong(pro -> {
  75. Long space = pro.getSpace();
  76. return Objects.isNull(space) ? 0L : space;
  77. }).sum();
  78. case SP:
  79. wrapper.eq(ScenePro::getPayStatus, PayStatus.PAY.code());
  80. return this.count(wrapper);
  81. }
  82. return 0L;
  83. }
  84. @Override
  85. public void generateObjFile(String num) {
  86. ScenePro sceneProEntity = this.getByNum(num);
  87. if(ObjectUtils.isEmpty(sceneProEntity) || sceneProEntity.getIsUpgrade() == 1){
  88. generatePlusObjFile(num);
  89. return;
  90. }
  91. if(sceneProEntity.getSceneSource() != 4 && sceneProEntity.getSceneSource() != 5){
  92. throw new BusinessException(ErrorCode.FAILURE_CODE_3003, "只能操作激光场景");
  93. }
  94. // 拷贝文件
  95. String path = sceneProEntity.getDataSource();
  96. String ossPath = path.replace("/mnt/data","home")+"/data.fdage";
  97. if(!fYunFileService.fileExist(ossPath)){
  98. throw new BusinessException(ErrorCode.FAILURE_CODE_3037);
  99. }
  100. // 获取最新的场景名称
  101. Result laserSceneByNum = laserClient.getSceneByNum(num);
  102. if(laserSceneByNum.getCode() != HttpStatus.OK.value()){
  103. throw new RuntimeException("获取激光转台场景失败!");
  104. }
  105. JSONObject sceneInfo = JSONObject.parseObject(JSONObject.toJSONString(laserSceneByNum.getData()));
  106. LambdaUpdateWrapper<ScenePro> updateWrapper = new LambdaUpdateWrapper<>();
  107. updateWrapper
  108. .set(ScenePro::getStatus, 0)
  109. .set(ScenePro::getIsObj, 1)
  110. .set(ScenePro::getIsUpgrade, 2) // 升级中
  111. .set(ScenePro::getSceneName, sceneInfo.getString("title"))
  112. .eq(ScenePro::getNum, sceneProEntity.getNum());
  113. this.update(updateWrapper);
  114. //同步到scenePlus、scenePlus
  115. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  116. if(Objects.nonNull(scenePlus)){
  117. sceneUpgradeMapper.deleteScenePlus(num);
  118. sceneUpgradeMapper.deleteScenePlusExt(scenePlus.getId());
  119. }
  120. sceneUpgradeMapper.transferScenePlus(num);
  121. scenePlus = scenePlusService.getScenePlusByNum(num);
  122. String sceneKind = sceneProEntity.getSceneScheme() == 3 ? SceneKind.FACE.code():SceneKind.TILES.code();
  123. sceneUpgradeMapper.transferScenePlusExt(num, scenePlus.getId(), sceneKind);
  124. log.info("开始发送激光场景生成obj mq消息");
  125. // 发送MQ
  126. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  127. mqMsg.setSceneNum(sceneProEntity.getNum());
  128. mqMsg.setAlgorithm(sceneProEntity.getAlgorithm());
  129. mqMsg.setBuildType(sceneProEntity.getBuildType());
  130. mqMsg.setPath(sceneProEntity.getDataSource());
  131. mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
  132. }
  133. public void generatePlusObjFile(String num) {
  134. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  135. if(ObjectUtils.isEmpty(scenePlus)){
  136. throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
  137. }
  138. if(scenePlus.getSceneSource() != 4 && scenePlus.getSceneSource() !=5){
  139. throw new BusinessException(ErrorCode.FAILURE_CODE_3003, "只能操作激光场景");
  140. }
  141. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  142. String ossPath = scenePlusExt.getDataSource().replace("/mnt/data","home")+"/data.fdage";
  143. if(!fYunFileService.fileExist(ossPath)){
  144. throw new BusinessException(ErrorCode.FAILURE_CODE_3037);
  145. }
  146. // 获取最新的场景名称
  147. Result laserSceneByNum = laserClient.getSceneByNum(num);
  148. if(laserSceneByNum.getCode() != HttpStatus.OK.value()){
  149. throw new RuntimeException("获取激光转台场景失败!");
  150. }
  151. JSONObject sceneInfo = JSONObject.parseObject(JSONObject.toJSONString(laserSceneByNum.getData()));
  152. LambdaUpdateWrapper<ScenePlus> updateWrapper = new LambdaUpdateWrapper<>();
  153. updateWrapper
  154. .set(ScenePlus::getSceneStatus, 0)
  155. .set(ScenePlus::getTitle, sceneInfo.getString("title"))
  156. .eq(ScenePlus::getNum, num);
  157. scenePlusService.update(updateWrapper);
  158. LambdaUpdateWrapper<ScenePlusExt> plusExtUpdateWrapper = new LambdaUpdateWrapper<>();
  159. plusExtUpdateWrapper
  160. .set(ScenePlusExt::getIsObj, 1)
  161. .eq(ScenePlusExt::getPlusId, scenePlus.getId());
  162. scenePlusExtService.update(plusExtUpdateWrapper);
  163. log.info("开始发送激光场景生成obj mq消息");
  164. // 发送MQ
  165. BuildSceneCallMessage mqMsg = new BuildSceneCallMessage();
  166. mqMsg.setSceneNum(num);
  167. mqMsg.setAlgorithm(scenePlusExt.getAlgorithm());
  168. mqMsg.setBuildType(scenePlusExt.getBuildType());
  169. mqMsg.setPath(scenePlusExt.getDataSource());
  170. mqProducer.sendByWorkQueue(queueObjModelingPre,mqMsg);
  171. }
  172. public JSONObject getSceneByNum(String num) {
  173. Result result = laserClient.getSceneByNum(num);
  174. if(result.getCode() != HttpStatus.OK.value()){
  175. log.error("获取激光转台场景失败!");
  176. return null;
  177. }
  178. return JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
  179. }
  180. }