123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package com.fdkankan.contro.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.core.util.StrUtil;
- 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.constant.RecStatus;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.common.util.CmdUtils;
- import com.fdkankan.common.util.DateExtUtil;
- import com.fdkankan.contro.entity.SceneFileBuild;
- import com.fdkankan.contro.service.GzZcdjzxService;
- import com.fdkankan.contro.service.ISceneFileBuildService;
- import com.fdkankan.contro.vo.ResponseSceneFile;
- import com.fdkankan.fyun.config.FYunFileConfig;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.fyun.local.constant.LocalConstants;
- import com.fdkankan.model.constants.ConstantFilePath;
- import com.fdkankan.model.utils.SceneUtil;
- import com.fdkankan.web.response.ResultData;
- import com.fdkankan.web.util.RSAEncrypt;
- import lombok.extern.log4j.Log4j2;
- import org.apache.commons.codec.binary.Base64;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import java.io.IOException;
- import java.nio.charset.StandardCharsets;
- import java.util.*;
- /**
- * 场景文件上传模块
- */
- @Log4j2
- @RestController
- @RequestMapping("/api/scene/file")
- public class SceneFileController{
- @Autowired
- private ISceneFileBuildService sceneFileBuildService;
- @Autowired
- private FYunFileServiceInterface fYunFileService;
- /**
- * 场景文件上传之前先获取fileId
- * @param params
- * @return
- * @throws Exception
- */
- @PostMapping("preUpload")
- public ResponseSceneFile preUpload(String params) throws Exception {
- return sceneFileBuildService.preUpload(params);
- }
- /**
- * 更新fileid文件的上传状态 - 后端八目上传逻辑
- *
- * @param params
- * @return
- */
- @PostMapping("uploadSuccessBuild")
- public ResultData uploadSuccessBuild(String params) throws Exception {
- return sceneFileBuildService.uploadSuccessBuild(params);
- }
- /**
- *
- *
- * @param params
- * @return
- */
- @PostMapping("turntableUploadSuccess")
- public ResultData turntableUploadSuccess(String params) throws Exception {
- return sceneFileBuildService.turntableUploadSuccess(params);
- }
- /**
- *
- *
- * @param params
- * @return
- */
- @PostMapping("reverseScene")
- public ResultData reverseScene(@RequestBody JSONObject params) throws Exception {
- return sceneFileBuildService.reverseScene(params);
- }
- @GetMapping("rebuildScene")
- public ResultData rebuildScene(@RequestParam(value = "num") String num,@RequestParam(value = "force",defaultValue = "false") Boolean force ,@RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras) throws IOException {
- return sceneFileBuildService.rebuildScene(num,force,deleteExtras);
- }
- /**
- * 单个文件上传
- * @param file
- * @param params
- * @return
- */
- @PostMapping("upload")
- public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
- String params) throws Exception {
- return sceneFileBuildService.uploadFile(file, params);
- }
- /**
- * 国际八目相机调用
- * @param params
- * @return
- * @throws Exception
- */
- @PostMapping("getS3UploadUrl")
- public ResultData getS3UploadUrl(String params) throws Exception {
- log.info("getS3UploadUrl 参数:{}",params);
- if (StringUtils.isEmpty(params)) {
- throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
- }
- JSONObject jsonObject = JSON.parseObject(params);
- if(jsonObject == null){
- throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
- }
- JSONArray files = jsonObject.getJSONArray("Files");
- if(files == null){
- throw new BusinessException(ErrorCode.PARAM_ERROR,"params为空。");
- }
- List<String> urls = new ArrayList<>();
- for(int i = 0, len = files.size(); i < len; i++){
- urls.add(files.getJSONObject(i).getString("filename"));
- }
- Map<String, String> uploadS3Url = getUploadS3Url(urls);
- return ResultData.ok(uploadS3Url);
- }
- private Map<String, String> getUploadS3Url(List<String> urls) {
- if(urls == null || urls.size() <= 0){
- return null;
- }
- Map<String, String> map = new HashMap();
- for(String path : urls){
- map.put(path, fYunFileService.getPresignedUrl(path).toString());
- }
- return map;
- }
- @GetMapping("copyDataAndBuild")
- public ResultData copyDataAndBuild(@RequestParam(value = "dataSource") String dataSource,@RequestParam(value = "sceneVer") String sceneVer,
- @RequestParam(value = "sourceBucket") String sourceBucket) throws Exception {
- return sceneFileBuildService.copyDataAndBuild(sourceBucket,dataSource ,sceneVer);
- }
- @Autowired
- private GzZcdjzxService gzZcdjzxService;
- @GetMapping("bd")
- public ResultData test(){
- gzZcdjzxService.bd();
- return ResultData.ok();
- }
- @Resource
- private FYunFileConfig fYunFileConfig;
- @GetMapping("bd2")
- public ResultData bd2(String taskId, String kNo, String fileId, String snCode, String unicode) throws Exception {
- String dataSource = ConstantFilePath.BUILD_MODEL_PATH + snCode + "/" + fileId + "/" + unicode;
- String ossHomePath = SceneUtil.getHomePath(dataSource);
- String ossHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + ossHomePath;
- LambdaQueryWrapper<SceneFileBuild> wrapper = new LambdaQueryWrapper<>();
- if(StrUtil.isNotEmpty(taskId)){
- wrapper.eq(SceneFileBuild::getTaskId, taskId);
- }
- if(StrUtil.isNotEmpty(kNo)){
- wrapper.eq(SceneFileBuild::getKNo, kNo);
- }
- SceneFileBuild sceneFileBuild = sceneFileBuildService.getOne(wrapper);
- String realFileId = null;
- if(Objects.isNull(sceneFileBuild)){
- realFileId = fileId + "_" + DateExtUtil.format(new Date(), "yyyyMMddHHmmss");
- sceneFileBuild = new SceneFileBuild();
- sceneFileBuild.setFileId(realFileId);
- sceneFileBuild.setUnicode(unicode);
- sceneFileBuild.setChildName(snCode);
- sceneFileBuild.setCreateTime(new Date());
- sceneFileBuild.setRecStatus(RecStatus.VALID.code());
- sceneFileBuild.setTaskId(taskId);
- sceneFileBuild.setKNo(kNo);
- sceneFileBuildService.save(sceneFileBuild);
- }else{
- realFileId = sceneFileBuild.getFileId();
- }
- String realDataSource = ConstantFilePath.BUILD_MODEL_PATH + snCode + "/" + realFileId + "/" + unicode;
- String realOssHomePath = SceneUtil.getHomePath(realDataSource);
- String realOssHomeAbsolutePath = LocalConstants.BASE_PATH + fYunFileConfig.getBucket() + "/" + realOssHomePath;
- FileUtil.listFileNames(ossHomeAbsolutePath).stream().forEach(fileName -> {
- FileUtil.copy(ossHomeAbsolutePath + "/" + fileName, realOssHomeAbsolutePath + "/" + fileName, true);
- });
- // 私钥解密过程
- String paramsStr = snCode + "#" + realFileId + "#" + unicode;
- byte[] res = RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile()),
- paramsStr.getBytes(StandardCharsets.UTF_8));
- String params = new Base64().encodeToString(res);
- sceneFileBuildService.turntableUploadSuccess(params);
- return ResultData.ok();
- }
- }
|