123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package com.fdkankan.fusion.controller;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.fusion.common.FilePath;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.ResultData;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.util.*;
- import com.fdkankan.fusion.entity.CaseFiles;
- import com.fdkankan.fusion.entity.CommonUpload;
- import com.fdkankan.fusion.entity.Model;
- import com.fdkankan.fusion.entity.ScenePlus;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.request.*;
- import com.fdkankan.fusion.response.FileInfoVo;
- import com.fdkankan.fusion.service.*;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author
- * @since 2022-08-03
- */
- @RestController
- @RequestMapping("/model")
- public class ModelController extends BaseController{
- @Autowired
- IModelService modelService;
- @Autowired
- IFusionNumService fusionNumService;
- @Autowired
- ICommonUploadService commonUploadService;
- @Autowired
- ICaseService caseService;
- @Autowired
- ICaseNumService caseNumService;
- @PostMapping("/uploadObj")
- public ResultData uploadObj(@RequestParam(required = false) MultipartFile file) throws Exception {
- return ResultData.ok(modelService.uploadObj(file,getUserName()));
- }
- @PostMapping("/addByMediaLibrary")
- public ResultData addByMediaLibrary(@RequestBody AddByMediaLibraryParam param) {
- if(param.getCaseId() == null || param.getUploadId() == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- CommonUpload commonUpload = commonUploadService.getById(param.getUploadId());
- if(commonUpload == null || StringUtils.isBlank(commonUpload.getFileUrl())){
- throw new BusinessException(ResultCode.MEDIO_NOT_EXIT);
- }
- Model model = new Model();
- model.setModelTitle(commonUpload.getFileName());
- model.setModelSize(FileWriterUtil.setFileSize(Long.valueOf(commonUpload.getFileSize())));
- model.setModelDateType(commonUpload.getFileFormat());
- model.setModelType(commonUpload.getResultFileFormat());
- model.setWgs84(commonUpload.getWgs84());
- model.setGcj02(commonUpload.getGcj02());
- model.setConvertType(commonUpload.getConvertType());
- JSONArray jsonArray = new JSONArray();
- jsonArray.add(commonUpload.getFileUrl());
- model.setModelGlbUrl(jsonArray.toJSONString());
- modelService.save(model);
- //caseNumService.addModeByCaseId(param.getCaseId(),model.getModelId());
- return ResultData.ok(model);
- }
- @GetMapping("/uploadObjProgress")
- public ResultData uploadAddVideoProgress(@RequestParam(required = false) Integer modelId) throws Exception {
- String code = modelService.uploadObjProgress(modelId);
- return ResultData.ok(Integer.valueOf(code));
- }
- @GetMapping("/cancelUpload")
- public ResultData cancelUpload(@RequestParam(required = false) Integer modelId) throws Exception {
- modelService.cancelUpload(modelId);
- return ResultData.ok();
- }
- @PostMapping("/list")
- public ResultData list(@RequestBody ModelPram param){
- return ResultData.ok(modelService.pageList(param,getUserName()));
- }
- @GetMapping("/getInfo")
- public ResultData getInfo(@RequestParam(required = false) Integer modelId){
- return ResultData.ok(modelService.getInfo(modelId));
- }
- @PostMapping("/delete")
- public ResultData delete(@RequestBody ModelPram param){
- if(param.getModelId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- modelService.delete(param.getModelId());
- return ResultData.ok();
- }
- @PostMapping("/updateTitle")
- public ResultData updateTitle(@RequestBody ModelPram param){
- if(param.getModelId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(StringUtils.isBlank(param.getModelTitle()) && StringUtils.isBlank(param.getRenderType())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- LambdaUpdateWrapper<Model> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(Model::getModelId,param.getModelId());
- if(StringUtils.isNotBlank(param.getRenderType())){
- wrapper.set(Model::getRenderType,param.getRenderType());
- }
- if(StringUtils.isNotBlank(param.getModelTitle())){
- wrapper.set(Model::getModelTitle,param.getModelTitle());
- }
- modelService.update(wrapper);
- return ResultData.ok();
- }
- @PostMapping("/copyModel")
- public ResultData copyModel(@RequestBody ModelPram param){
- if(param.getModelId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- modelService.copyModel(param.getModelId());
- return ResultData.ok();
- }
- @Value("${spring.profiles.active}")
- private String environment;
- @Autowired
- UploadToOssUtil uploadToOssUtil;
- @Value("${upload.query-path}")
- private String queryPath;
- @GetMapping("/downMD5")
- public void downMD5(@RequestParam(required = false) Integer modelId,
- HttpServletResponse res, HttpServletRequest req) throws IOException {
- OutputStream os = null;
- try {
- Model model = modelService.getById(modelId);
- if(model == null){
- throw new BusinessException(ResultCode.MODEL_NOT_EXIST);
- }
- if(StringUtils.isBlank(model.getFileNewName())){
- throw new BusinessException(ResultCode.FILE_NOT_EXIST);
- }
- String sceneObjPath = model.getFileNewName().replace(queryPath,"");
- FileInfoVo fileInfo = uploadToOssUtil.getFileInfo(sceneObjPath);
- if(fileInfo == null){
- throw new BusinessException(ResultCode.FILE_NOT_EXIST);
- }
- String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment ,modelId) ;
- File file = new File(objPath +"/"+modelId + "_hash.txt");
- res.setContentType("application/octet-stream");
- res.setHeader("Content-Disposition", "attachment; filename="+modelId + "_hash.txt");
- os = res.getOutputStream();
- FileUtil.writeString(fileInfo.toString(),file,"UTF-8");
- os.write(FileUtils.readFileToByteArray(file));
- os.flush();
- } finally {
- if(os!=null){
- os.close();
- }
- }
- }
- }
|