package com.fdkankan.contro.controller; import cn.hutool.core.collection.CollUtil; 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.CommonSuccessStatus; import com.fdkankan.common.constant.ErrorCode; import com.fdkankan.common.constant.SceneSource; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.contro.annotation.SignVerification; import com.fdkankan.contro.entity.ScenePlus; import com.fdkankan.contro.entity.SceneZxgd; import com.fdkankan.contro.service.*; import com.fdkankan.contro.vo.ReportFailLogVO; import com.fdkankan.contro.vo.ResponseSceneFile; import com.fdkankan.contro.vo.SceneParam; import com.fdkankan.contro.vo.SceneUploadCountParamVO; import com.fdkankan.fyun.config.FYunFileConfig; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.web.response.ResultData; import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; /** * 场景文件上传模块 */ @Log4j2 @RestController @RequestMapping("/api/scene/file") public class SceneFileController{ @Autowired private ISceneFileBuildService sceneFileBuildService; @Resource private FYunFileServiceInterface fYunFileService; @Autowired private ISceneUploadCountService sceneUploadCountService; @Autowired private IAppCameraFailLogService appCameraFailLogService; @Autowired private IScenePlusService scenePlusService; @Autowired ISceneProService sceneProService; /** * 场景文件上传之前先获取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 */ @SignVerification @PostMapping("reverseScene") public ResultData reverseScene(@RequestBody JSONObject params) throws Exception { return sceneFileBuildService.reverseScene(params); } @SignVerification @GetMapping("rebuildScene") public ResultData rebuildScene(@RequestParam(value = "num") String num, @RequestParam(value = "force",defaultValue = "false") Boolean force , @RequestParam(value = "deleteExtras",defaultValue = "true") Boolean deleteExtras, @RequestParam(value = "from", defaultValue = "api") String from) throws IOException { ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num); if(Objects.nonNull(scenePlus) && scenePlus.getSceneSource() == SceneSource.E57.code()){ return sceneFileBuildService.rebuildSceneE57(num,force,deleteExtras, from); } return sceneFileBuildService.rebuildScene(num,force,deleteExtras, from); } /** * 国际八目相机调用 * @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 urls = new ArrayList<>(); for(int i = 0, len = files.size(); i < len; i++){ urls.add(files.getJSONObject(i).getString("filename")); } Map uploadS3Url = getUploadS3Url(urls); return ResultData.ok(uploadS3Url); } private Map getUploadS3Url(List urls) { if(urls == null || urls.size() <= 0){ return null; } Map map = new HashMap(); for(String path : urls){ map.put(path, fYunFileService.getPresignedUrl(path).toString()); } return map; } @SignVerification @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); } /** * 记录app触发上传场景 * @param param * @return */ @SignVerification @PostMapping("/increSceneUploadCount") public ResultData increSceneUploadCount(@RequestBody @Valid SceneUploadCountParamVO param){ sceneUploadCountService.increSceneUploadCount(param); return ResultData.ok(); } @SignVerification @PostMapping("/reportFailLog") public ResultData reportFailLog(@RequestBody @Valid ReportFailLogVO param){ appCameraFailLogService.reportFailLog(param); return ResultData.ok(); } /** * 计算理光相机格式场景 * @return */ @SignVerification @PostMapping("uploadLiguang") public ResultData uploadLiguang(String num, String snCode, String ossPath) throws Exception { return sceneFileBuildService.uploadLiguang(num, snCode, ossPath); } /** * * 激光场景生成obj文件 */ @SignVerification @PostMapping(value = "/generateObjFile") public ResultData generateObjFile(@RequestBody SceneParam requestScene) throws Exception{ String num = requestScene.getSceneNum(); if (StringUtils.isEmpty(num)) { throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } sceneProService.generateObjFile(num); return ResultData.ok(); } @Autowired private ISceneZxgdService sceneZxgdService; @Resource FYunFileConfig fYunFileConfig; @GetMapping("/getZxgd/{search}") public ResultData getZxgd(@PathVariable(value = "search") String search) throws Exception{ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.like(SceneZxgd::getTitle, search).or().like(SceneZxgd::getUnicode, search); List list = sceneZxgdService.list(wrapper); if(CollUtil.isEmpty(list)){ return ResultData.ok(); } List collect = list.stream().map(v -> { JSONObject jsonObject = new JSONObject(); jsonObject.put("名称", v.getTitle()); jsonObject.put("unicode", v.getUnicode()); jsonObject.put("状态", CommonSuccessStatus.get(v.getStatus()).message()); jsonObject.put("原始资源路径", "home/" + v.getUnicode().split("_")[0] + "/" + v.getFileId() + "/" + v.getUnicode()); jsonObject.put("下载地址", fYunFileConfig.getHost() + "zxgd/" + v.getUnicode() + "/mesh.ply?v=" + Calendar.getInstance().getTimeInMillis()); return jsonObject; }).collect(Collectors.toList()); return ResultData.ok(collect); } }