123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package com.fdkankan.contro.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.common.constant.ErrorCode;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.contro.entity.OrigFileUpload;
- import com.fdkankan.contro.entity.OrigFileUploadBatch;
- import com.fdkankan.contro.service.IJmgaService;
- import com.fdkankan.contro.service.IOrigFileUploadBatchService;
- import com.fdkankan.contro.service.IOrigFileUploadService;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.rabbitmq.util.RabbitMqProducer;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- public class JmgaServiceImpl implements IJmgaService {
- @Autowired
- private IOrigFileUploadBatchService origFileUploadBatchService;
- @Autowired
- private IOrigFileUploadService origFileUploadService;
- @Resource
- private FYunFileServiceInterface fileServiceInterface;
- @Resource
- private RabbitMqProducer mqProducer;
- @Override
- public void checkFileWhole(String uuid, String dataSource, JSONObject fdageData) {
- int camType = fdageData.getJSONObject("cam").getIntValue("type");
- //从data.fdage中获取需要上传的文件列表
- JSONArray points = fdageData.getJSONArray("points");
- if(CollUtil.isEmpty(points)){
- return;
- }
- List<String> fileList = new ArrayList<>();
- for (Object point : points) {
- JSONObject pointJson = (JSONObject) point;
- if(camType == 5){//圆周率相机
- String name = pointJson.getString("name");
- fileList.add(name);
- }else{//四维相机
- JSONArray imgs = pointJson.getJSONArray("imgs");
- if(CollUtil.isEmpty(imgs)){
- continue;
- }
- for (Object img : imgs) {
- JSONObject imgJson = (JSONObject) img;
- String name = imgJson.getString("name");
- fileList.add(name);
- }
- }
- }
- //查询当前待通知计算批次文件是否存在
- List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
- if(CollUtil.isNotEmpty(batchList)){
- Set<String> batchIds = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toSet());
- List<OrigFileUpload> origFileList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIds));
- //过滤出不存在的
- fileList = fileList.stream().filter(v -> origFileList.stream().noneMatch(k -> k.getFileName().equals(v))).collect(Collectors.toList());
- }
- // //查询oss文件目录是否存在
- // String homePath = SceneUtil.getHomePath(dataSource);
- // List<String> ossKeyList = fileServiceInterface.listRemoteFiles(homePath);
- // fileList = fileList.stream().filter(v->ossKeyList.stream().noneMatch(k->FileUtil.getName(k).equals(v))).collect(Collectors.toList());
- //
- if(CollUtil.isNotEmpty(fileList)){
- String args = JSON.toJSONString(fileList);
- if(fileList.size() > 5){
- args = fileList.size() + "个文件";
- }
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001, args);
- }
- }
- @Override
- public void sendStatus(Map<String, Object> param) {
- mqProducer.sendByWorkQueue("jmga-event-notice", param);
- }
- @Override
- public void checkLackFile(String dataSource) {
- String dataFdagePath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("data.fdage");
- if(!FileUtil.exist(dataFdagePath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
- }
- JSONObject fdageData = null;
- try {
- fdageData = JSON.parseObject(FileUtil.readUtf8String(dataFdagePath));
- }catch (Exception e){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
- }
- int camType = fdageData.getJSONObject("cam").getIntValue("type");
- if(camType == 1 || camType == 2 || camType == 9 || camType == 10 || camType == 11){
- Integer shootCount = fdageData.getJSONArray("points").size();
- if(shootCount > 0){//有点位代表架站式
- String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("parameters.json");
- if(!FileUtil.exist(parametersPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
- }
- String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("sfm_data.bin");
- if(!FileUtil.exist(sfmDataBinPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
- }
- String upName = camType > 2 ? "Up.txt" : "Up.xml";
- String upTxtPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat(upName);
- if(!FileUtil.exist(upTxtPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(upName));
- }
- }
- }
- if(camType == 6){
- String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("images/parameters.json");
- if(!FileUtil.exist(parametersPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
- }
- String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("result/reconstructio/sfm_data.bin");
- if(!FileUtil.exist(sfmDataBinPath)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
- }
- }
- //从data.fdage中获取需要上传的文件列表
- JSONArray points = fdageData.getJSONArray("points");
- if(CollUtil.isEmpty(points)){
- return;
- }
- for (Object point : points) {
- JSONObject pointJson = (JSONObject) point;
- if(camType == 5){//圆周率相机
- String name = pointJson.getString("name");
- this.checkFileAvailable(dataSource, name);
- }else{//四维相机
- JSONArray imgs = pointJson.getJSONArray("imgs");
- for (Object img : imgs) {
- JSONObject imgJson = (JSONObject) img;
- String name = imgJson.getString("name");
- this.checkFileAvailable(dataSource, name);
- }
- }
- }
- }
- private void checkFileAvailable(String dataSource, String fileName){
- List<File> fileList = FileUtil.loopFiles(dataSource.concat(File.separator).concat("capture"));
- if(CollUtil.isEmpty(fileList)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
- }
- for (File file : fileList) {
- if(file.getName().equals(fileName) && file.length() > 0){
- return;
- }
- }
- throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
- }
- }
|