ModelController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package com.fdkankan.fusion.controller;
  2. import cn.hutool.core.io.FileUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  5. import com.fdkankan.fusion.common.FilePath;
  6. import com.fdkankan.fusion.common.ResultCode;
  7. import com.fdkankan.fusion.common.ResultData;
  8. import com.fdkankan.fusion.common.ResultCode;
  9. import com.fdkankan.fusion.common.util.*;
  10. import com.fdkankan.fusion.entity.CaseFiles;
  11. import com.fdkankan.fusion.entity.CommonUpload;
  12. import com.fdkankan.fusion.entity.Model;
  13. import com.fdkankan.fusion.entity.ScenePlus;
  14. import com.fdkankan.fusion.exception.BusinessException;
  15. import com.fdkankan.fusion.request.*;
  16. import com.fdkankan.fusion.response.FileInfoVo;
  17. import com.fdkankan.fusion.service.*;
  18. import org.apache.commons.io.FileUtils;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.web.bind.annotation.*;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import java.io.File;
  27. import java.io.IOException;
  28. import java.io.OutputStream;
  29. import java.util.ArrayList;
  30. import java.util.Arrays;
  31. import java.util.List;
  32. /**
  33. * <p>
  34. * 前端控制器
  35. * </p>
  36. *
  37. * @author
  38. * @since 2022-08-03
  39. */
  40. @RestController
  41. @RequestMapping("/model")
  42. public class ModelController extends BaseController{
  43. @Autowired
  44. IModelService modelService;
  45. @Autowired
  46. IFusionNumService fusionNumService;
  47. @Autowired
  48. ICommonUploadService commonUploadService;
  49. @Autowired
  50. ICaseService caseService;
  51. @Autowired
  52. ICaseNumService caseNumService;
  53. @PostMapping("/uploadObj")
  54. public ResultData uploadObj(@RequestParam(required = false) MultipartFile file) throws Exception {
  55. return ResultData.ok(modelService.uploadObj(file,getUserName()));
  56. }
  57. @PostMapping("/addByMediaLibrary")
  58. public ResultData addByMediaLibrary(@RequestBody AddByMediaLibraryParam param) {
  59. if(param.getCaseId() == null || param.getUploadId() == null ){
  60. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  61. }
  62. CommonUpload commonUpload = commonUploadService.getById(param.getUploadId());
  63. if(commonUpload == null || StringUtils.isBlank(commonUpload.getFileUrl())){
  64. throw new BusinessException(ResultCode.MEDIO_NOT_EXIT);
  65. }
  66. Model model = new Model();
  67. model.setModelTitle(commonUpload.getFileName());
  68. model.setModelSize(FileWriterUtil.setFileSize(Long.valueOf(commonUpload.getFileSize())));
  69. model.setModelDateType(commonUpload.getFileFormat());
  70. model.setModelType(commonUpload.getResultFileFormat());
  71. model.setWgs84(commonUpload.getWgs84());
  72. model.setGcj02(commonUpload.getGcj02());
  73. model.setConvertType(commonUpload.getConvertType());
  74. JSONArray jsonArray = new JSONArray();
  75. jsonArray.add(commonUpload.getFileUrl());
  76. model.setModelGlbUrl(jsonArray.toJSONString());
  77. modelService.save(model);
  78. //caseNumService.addModeByCaseId(param.getCaseId(),model.getModelId());
  79. return ResultData.ok(model);
  80. }
  81. @GetMapping("/uploadObjProgress")
  82. public ResultData uploadAddVideoProgress(@RequestParam(required = false) Integer modelId) throws Exception {
  83. String code = modelService.uploadObjProgress(modelId);
  84. return ResultData.ok(Integer.valueOf(code));
  85. }
  86. @GetMapping("/cancelUpload")
  87. public ResultData cancelUpload(@RequestParam(required = false) Integer modelId) throws Exception {
  88. modelService.cancelUpload(modelId);
  89. return ResultData.ok();
  90. }
  91. @PostMapping("/list")
  92. public ResultData list(@RequestBody ModelPram param){
  93. return ResultData.ok(modelService.pageList(param,getUserName()));
  94. }
  95. @GetMapping("/getInfo")
  96. public ResultData getInfo(@RequestParam(required = false) Integer modelId){
  97. return ResultData.ok(modelService.getInfo(modelId));
  98. }
  99. @PostMapping("/delete")
  100. public ResultData delete(@RequestBody ModelPram param){
  101. if(param.getModelId() == null){
  102. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  103. }
  104. modelService.delete(param.getModelId());
  105. return ResultData.ok();
  106. }
  107. @PostMapping("/updateTitle")
  108. public ResultData updateTitle(@RequestBody ModelPram param){
  109. if(param.getModelId() == null){
  110. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  111. }
  112. if(StringUtils.isBlank(param.getModelTitle()) && StringUtils.isBlank(param.getRenderType())){
  113. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  114. }
  115. LambdaUpdateWrapper<Model> wrapper = new LambdaUpdateWrapper<>();
  116. wrapper.eq(Model::getModelId,param.getModelId());
  117. if(StringUtils.isNotBlank(param.getRenderType())){
  118. wrapper.set(Model::getRenderType,param.getRenderType());
  119. }
  120. if(StringUtils.isNotBlank(param.getModelTitle())){
  121. wrapper.set(Model::getModelTitle,param.getModelTitle());
  122. }
  123. modelService.update(wrapper);
  124. return ResultData.ok();
  125. }
  126. @PostMapping("/copyModel")
  127. public ResultData copyModel(@RequestBody ModelPram param){
  128. if(param.getModelId() == null){
  129. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  130. }
  131. modelService.copyModel(param.getModelId());
  132. return ResultData.ok();
  133. }
  134. @Value("${spring.profiles.active}")
  135. private String environment;
  136. @Autowired
  137. UploadToOssUtil uploadToOssUtil;
  138. @Value("${upload.query-path}")
  139. private String queryPath;
  140. @GetMapping("/downMD5")
  141. public void downMD5(@RequestParam(required = false) Integer modelId,
  142. HttpServletResponse res, HttpServletRequest req) throws IOException {
  143. OutputStream os = null;
  144. try {
  145. Model model = modelService.getById(modelId);
  146. if(model == null){
  147. throw new BusinessException(ResultCode.MODEL_NOT_EXIST);
  148. }
  149. if(StringUtils.isBlank(model.getFileNewName())){
  150. throw new BusinessException(ResultCode.FILE_NOT_EXIST);
  151. }
  152. String sceneObjPath = model.getFileNewName().replace(queryPath,"");
  153. FileInfoVo fileInfo = uploadToOssUtil.getFileInfo(sceneObjPath);
  154. if(fileInfo == null){
  155. throw new BusinessException(ResultCode.FILE_NOT_EXIST);
  156. }
  157. String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment ,modelId) ;
  158. File file = new File(objPath +"/"+modelId + "_hash.txt");
  159. res.setContentType("application/octet-stream");
  160. res.setHeader("Content-Disposition", "attachment; filename="+modelId + "_hash.txt");
  161. os = res.getOutputStream();
  162. FileUtil.writeString(fileInfo.toString(),file,"UTF-8");
  163. os.write(FileUtils.readFileToByteArray(file));
  164. os.flush();
  165. } finally {
  166. if(os!=null){
  167. os.close();
  168. }
  169. }
  170. }
  171. }