JmgaServiceImpl.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.fdkankan.common.constant.ErrorCode;
  9. import com.fdkankan.common.exception.BusinessException;
  10. import com.fdkankan.contro.entity.OrigFileUpload;
  11. import com.fdkankan.contro.entity.OrigFileUploadBatch;
  12. import com.fdkankan.contro.service.IJmgaService;
  13. import com.fdkankan.contro.service.IOrigFileUploadBatchService;
  14. import com.fdkankan.contro.service.IOrigFileUploadService;
  15. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  16. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import javax.annotation.Resource;
  21. import java.io.File;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Set;
  26. import java.util.stream.Collectors;
  27. @Slf4j
  28. @Service
  29. public class JmgaServiceImpl implements IJmgaService {
  30. @Autowired
  31. private IOrigFileUploadBatchService origFileUploadBatchService;
  32. @Autowired
  33. private IOrigFileUploadService origFileUploadService;
  34. @Resource
  35. private FYunFileServiceInterface fileServiceInterface;
  36. @Resource
  37. private RabbitMqProducer mqProducer;
  38. @Override
  39. public void checkFileWhole(String uuid, String dataSource, JSONObject fdageData) {
  40. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  41. //从data.fdage中获取需要上传的文件列表
  42. JSONArray points = fdageData.getJSONArray("points");
  43. if(CollUtil.isEmpty(points)){
  44. return;
  45. }
  46. List<String> fileList = new ArrayList<>();
  47. for (Object point : points) {
  48. JSONObject pointJson = (JSONObject) point;
  49. if(camType == 5){//圆周率相机
  50. String name = pointJson.getString("name");
  51. fileList.add(name);
  52. }else{//四维相机
  53. JSONArray imgs = pointJson.getJSONArray("imgs");
  54. if(CollUtil.isEmpty(imgs)){
  55. continue;
  56. }
  57. for (Object img : imgs) {
  58. JSONObject imgJson = (JSONObject) img;
  59. String name = imgJson.getString("name");
  60. fileList.add(name);
  61. }
  62. }
  63. }
  64. //查询当前待通知计算批次文件是否存在
  65. List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
  66. if(CollUtil.isNotEmpty(batchList)){
  67. Set<String> batchIds = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toSet());
  68. List<OrigFileUpload> origFileList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIds));
  69. //过滤出不存在的
  70. fileList = fileList.stream().filter(v -> origFileList.stream().noneMatch(k -> k.getFileName().equals(v))).collect(Collectors.toList());
  71. }
  72. // //查询oss文件目录是否存在
  73. // String homePath = SceneUtil.getHomePath(dataSource);
  74. // List<String> ossKeyList = fileServiceInterface.listRemoteFiles(homePath);
  75. // fileList = fileList.stream().filter(v->ossKeyList.stream().noneMatch(k->FileUtil.getName(k).equals(v))).collect(Collectors.toList());
  76. //
  77. if(CollUtil.isNotEmpty(fileList)){
  78. String args = JSON.toJSONString(fileList);
  79. if(fileList.size() > 5){
  80. args = fileList.size() + "个文件";
  81. }
  82. throw new BusinessException(ErrorCode.FAILURE_CODE_4001, args);
  83. }
  84. }
  85. @Override
  86. public void sendStatus(Map<String, Object> param) {
  87. mqProducer.sendByWorkQueue("jmga-event-notice", param);
  88. }
  89. @Override
  90. public void checkLackFile(String dataSource) {
  91. String dataFdagePath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("data.fdage");
  92. if(!FileUtil.exist(dataFdagePath)){
  93. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
  94. }
  95. JSONObject fdageData = null;
  96. try {
  97. fdageData = JSON.parseObject(FileUtil.readUtf8String(dataFdagePath));
  98. }catch (Exception e){
  99. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
  100. }
  101. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  102. if(camType == 1 || camType == 2 || camType == 9 || camType == 10 || camType == 11){
  103. Integer shootCount = fdageData.getJSONArray("points").size();
  104. if(shootCount > 0){//有点位代表架站式
  105. String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("parameters.json");
  106. if(!FileUtil.exist(parametersPath)){
  107. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
  108. }
  109. String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("sfm_data.bin");
  110. if(!FileUtil.exist(sfmDataBinPath)){
  111. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
  112. }
  113. String upName = camType > 2 ? "Up.txt" : "Up.xml";
  114. String upTxtPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat(upName);
  115. if(!FileUtil.exist(upTxtPath)){
  116. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(upName));
  117. }
  118. }
  119. }
  120. if(camType == 6){
  121. String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("images/parameters.json");
  122. if(!FileUtil.exist(parametersPath)){
  123. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
  124. }
  125. String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("result/reconstructio/sfm_data.bin");
  126. if(!FileUtil.exist(sfmDataBinPath)){
  127. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
  128. }
  129. }
  130. //从data.fdage中获取需要上传的文件列表
  131. JSONArray points = fdageData.getJSONArray("points");
  132. if(CollUtil.isEmpty(points)){
  133. return;
  134. }
  135. for (Object point : points) {
  136. JSONObject pointJson = (JSONObject) point;
  137. if(camType == 5){//圆周率相机
  138. String name = pointJson.getString("name");
  139. this.checkFileAvailable(dataSource, name);
  140. }else{//四维相机
  141. JSONArray imgs = pointJson.getJSONArray("imgs");
  142. for (Object img : imgs) {
  143. JSONObject imgJson = (JSONObject) img;
  144. String name = imgJson.getString("name");
  145. this.checkFileAvailable(dataSource, name);
  146. }
  147. }
  148. }
  149. }
  150. private void checkFileAvailable(String dataSource, String fileName){
  151. List<File> fileList = FileUtil.loopFiles(dataSource.concat(File.separator).concat("capture"));
  152. if(CollUtil.isEmpty(fileList)){
  153. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
  154. }
  155. for (File file : fileList) {
  156. if(file.getName().equals(fileName) && file.length() > 0){
  157. return;
  158. }
  159. }
  160. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
  161. }
  162. }