SceneFileBuildServiceImpl.java 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.fdkankan.common.config.FileRouteConfig;
  9. import com.fdkankan.common.constant.*;
  10. import com.fdkankan.common.exception.BusinessException;
  11. import com.fdkankan.common.response.ResultData;
  12. import com.fdkankan.common.util.*;
  13. import com.fdkankan.platform.api.feign.client.PlatformClient;
  14. import com.fdkankan.scene.entity.*;
  15. import com.fdkankan.scene.mapper.ISceneFileBuildMapper;
  16. import com.fdkankan.scene.service.*;
  17. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  18. import com.fdkankan.scene.vo.ResponseSceneFile;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.apache.commons.codec.binary.Base64;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Value;
  24. import org.springframework.data.redis.core.RedisTemplate;
  25. import org.springframework.scheduling.annotation.Async;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import java.io.BufferedReader;
  29. import java.io.File;
  30. import java.io.IOException;
  31. import java.io.InputStreamReader;
  32. import java.time.LocalDate;
  33. import java.util.*;
  34. /**
  35. * <p>
  36. * 场景文件建模表 服务实现类
  37. * </p>
  38. *
  39. * @author dengsixing
  40. * @since 2021-12-23
  41. */
  42. @Slf4j
  43. @Service
  44. public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
  45. private static final String SPLICE = "#";
  46. @Value("${main.url}")
  47. private String mainUrl;
  48. @Value("${scene.url}")
  49. private String sceneUrl;
  50. @Value("${scene.pro.url}")
  51. private String sceneProUrl;
  52. @Value("${scene.pro.new.url}")
  53. private String sceneProNewUrl;
  54. @Value("${oss.type}")
  55. private String type;
  56. @Value("${prefix.ali}")
  57. private String prefixAli;
  58. @Value("${ecs.type}")
  59. private String ecsType;
  60. @Autowired
  61. PlatformClient platformClient;
  62. @Autowired
  63. ISceneFileUploadService sceneFileUploadService;
  64. @Autowired
  65. RedisTemplate redisTemplate;
  66. @Autowired
  67. ISceneProService sceneProService;
  68. @Autowired
  69. private FileRouteConfig routeConfig;
  70. @Autowired
  71. UploadToOssUtil uploadToOssUtil;
  72. @Autowired
  73. ISceneProEditService sceneProEditService;
  74. @Autowired
  75. ISceneProEditExtService sceneProEditExtService;
  76. @Autowired
  77. IScene3dNumService scene3dNumService;
  78. @Override
  79. public SceneFileBuild findByFileId(String fileId) {
  80. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  81. .eq("tb_status", TbStatus.VALID.code())
  82. .eq("rec_status", RecStatus.VALID.code())
  83. .eq("file_id", fileId)
  84. .orderByDesc("id"));
  85. if(CollUtil.isEmpty(list))
  86. return null;
  87. return list.get(0);
  88. }
  89. @Override
  90. public boolean uploadSuccess(String fileId, StringBuilder filePathBuffer) {
  91. SceneFileBuild sceneFileBuild = findByFileId(fileId);
  92. if (Objects.isNull(sceneFileBuild))
  93. return false;
  94. Long uploadSuccessCount = sceneFileUploadService.countUploadSuccessByFileId(fileId);
  95. sceneFileBuild.setUploadStatus(UploadStatus.SUCCESS.code());
  96. sceneFileBuild.setChunks(Integer.valueOf(uploadSuccessCount.toString()));
  97. sceneFileBuild.setUpdateTime(Calendar.getInstance().getTime());
  98. this.updateById(sceneFileBuild);
  99. return true;
  100. }
  101. @Override
  102. public SceneFileBuild findByUnicode(String unicode) {
  103. List<SceneFileBuild> list = this.list(new QueryWrapper<SceneFileBuild>()
  104. .eq("tb_status", TbStatus.VALID.code())
  105. .eq("rec_status", RecStatus.VALID.code())
  106. .eq("unicode", unicode)
  107. .orderByDesc("id"));
  108. if(CollUtil.isEmpty(list))
  109. return null;
  110. return list.get(0);
  111. }
  112. @Async
  113. @Override
  114. public void unzipSingleFile(String filePath) {
  115. log.info("文件路径:{}", filePath);
  116. File file = new File(filePath);
  117. if (file.exists()){
  118. log.error(filePath + ":文件不存在");
  119. throw new BusinessException(ErrorCode.FAILURE_CODE_5038);
  120. }
  121. String parentFilePath = file.getParentFile().getPath();
  122. log.info("解压目标目录:{}", parentFilePath);
  123. StringBuffer exec = new StringBuffer(" tar xvf ");
  124. exec.append(filePath);
  125. exec.append(" -C ").append(parentFilePath).append(File.separator);
  126. System.out.println(exec.toString());
  127. String[] cmdExec = new String[]{"/bin/sh", "-c", exec.toString()};
  128. int code = executeLinuxShell(cmdExec);
  129. if (code == 0){
  130. log.info("解压完成,文件路径:{}, 开始执行删除压缩文件", filePath);
  131. file.delete();
  132. }else {
  133. log.error("解压失败,文件路径:{},解压状态:{}", filePath, code);
  134. }
  135. }
  136. private int executeLinuxShell(String[] command) {
  137. Process shellProcess = null;
  138. BufferedReader shellErrorResultReader = null;
  139. BufferedReader shellInfoResultReader = null;
  140. try {
  141. shellProcess = Runtime.getRuntime().exec(command);
  142. shellErrorResultReader = new BufferedReader(new InputStreamReader(shellProcess.getErrorStream()));
  143. shellInfoResultReader = new BufferedReader(new InputStreamReader(shellProcess.getInputStream()));
  144. String infoLine;
  145. while ((infoLine = shellInfoResultReader.readLine()) != null) {
  146. log.info("linux环境脚本执行信息:{}", infoLine);
  147. }
  148. String errorLine;
  149. while ((errorLine = shellErrorResultReader.readLine()) != null) {
  150. log.warn("linux环境脚本执行信息:{}", errorLine);
  151. }
  152. // 等待程序执行结束并输出状态
  153. int exitCode = shellProcess.waitFor();
  154. if (0 == exitCode) {
  155. log.info("linux环境脚本执行成功");
  156. } else {
  157. log.error("linux环境脚本执行失败:" + exitCode);
  158. }
  159. return exitCode;
  160. } catch (Exception e) {
  161. log.error("linux环境shell脚本执行错误", e);
  162. return 1;
  163. } finally {
  164. if (null != shellInfoResultReader) {
  165. try {
  166. shellInfoResultReader.close();
  167. } catch (IOException e) {
  168. log.error("linux环境脚本流文件关闭异常:", e);
  169. }
  170. }
  171. if (null != shellErrorResultReader) {
  172. try {
  173. shellErrorResultReader.close();
  174. } catch (IOException e) {
  175. log.error("linux环境脚本流文件关闭异常:", e);
  176. }
  177. }
  178. if (null != shellProcess) {
  179. shellProcess.destroy();
  180. }
  181. }
  182. }
  183. @Override
  184. public ResponseSceneFile preUpload(String params) throws Exception {
  185. log.info("preUpload-params: "+params);
  186. if (StrUtil.isEmpty(params)){
  187. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  188. }
  189. params = params.replaceAll("%2B", "+");
  190. Base64 base64 = new Base64();
  191. String cipher = params;
  192. // 私钥解密过程
  193. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  194. base64.decode(cipher));
  195. String restr = new String(res, "UTF-8");
  196. log.debug("preUpload-params解密结果:" + restr);
  197. String[] strArr = restr.split(SPLICE);
  198. if (strArr.length != 5) {
  199. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  200. }
  201. String mac = strArr[0];
  202. String totalPicNum = strArr[1];
  203. String chunks = strArr[2];
  204. String folderName = strArr[3];
  205. if (StrUtil.isEmpty(mac)){
  206. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  207. }
  208. if (totalPicNum == null){
  209. throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
  210. }
  211. if (chunks == null){
  212. throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
  213. }
  214. if (folderName == null){
  215. throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
  216. }
  217. log.info("mac:" + mac + "准备上传文件");
  218. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + folderName, "A");
  219. if(scenePro != null && scenePro.getDataSource() != null){
  220. int n = scenePro.getDataSource().split("/").length;
  221. if(n > 1){
  222. String fileId = scenePro.getDataSource().split("/")[n - 2];
  223. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  224. responseSceneFile.setFileId(fileId);
  225. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  226. redisTemplate.opsForValue().set(fileId, folderName, 1537920000);
  227. return responseSceneFile;
  228. }
  229. }else {
  230. SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
  231. if(sceneFileBuild != null){
  232. String fileId = sceneFileBuild.getFileId();
  233. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  234. responseSceneFile.setFileId(fileId);
  235. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  236. redisTemplate.opsForValue().set(fileId, folderName, 1537920000);
  237. return responseSceneFile;
  238. }
  239. }
  240. // 构造方法设置机器码:第0个机房的第0台机器
  241. SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0);
  242. long fileId = snowflakeIdGenerator.nextId();
  243. SceneFileBuild sceneFileBuild = new SceneFileBuild();
  244. sceneFileBuild.setChildName(mac);
  245. sceneFileBuild.setFileId(String.valueOf(fileId));
  246. sceneFileBuild.setUnicode(folderName);
  247. sceneFileBuild.setUploadStatus(0);
  248. sceneFileBuild.setBuildStatus(0);
  249. sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
  250. sceneFileBuild.setChunks(Integer.valueOf(chunks));
  251. this.save(sceneFileBuild);
  252. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  253. responseSceneFile.setFileId(String.valueOf(fileId));
  254. //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
  255. redisTemplate.opsForValue().set(String.valueOf(fileId), folderName, 1537920000);
  256. return responseSceneFile;
  257. }
  258. @Override
  259. public ResponseSceneFile getProgress(String params) throws Exception {
  260. log.info("getProgress-params:{} ", params);
  261. if (StrUtil.isEmpty(params)){
  262. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  263. }
  264. params = params.replaceAll("%2B", "+");
  265. Base64 base64 = new Base64();
  266. String cipher = params;
  267. // 私钥解密过程
  268. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  269. base64.decode(cipher));
  270. String restr = new String(res, "UTF-8");
  271. log.debug("getProgress-params解密结果:{}" , restr);
  272. String[] strArr = restr.split(SPLICE);
  273. if (strArr.length != 3) {
  274. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  275. }
  276. String fileId = strArr[0];
  277. String chunk = strArr[1];
  278. chunk = chunk.split(SPLICE)[0];
  279. SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  280. ResponseSceneFile responseSceneFile = new ResponseSceneFile();
  281. responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1);
  282. return responseSceneFile;
  283. }
  284. @Override
  285. public ResultData uploadFile(MultipartFile file, String params) throws Exception{
  286. log.info("upload-params: "+params);
  287. if (StringUtils.isEmpty(params)){
  288. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  289. }
  290. params = params.replaceAll("%2B", "+");
  291. Base64 base64 = new Base64();
  292. String cipher = params;
  293. // 私钥解密过程
  294. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  295. base64.decode(cipher));
  296. String restr = new String(res, "UTF-8");
  297. log.debug("upload-params解密结果:{}", restr);
  298. String[] strArr = restr.split(SPLICE);
  299. if (strArr.length != 6) {
  300. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  301. }
  302. String mac = strArr[0];
  303. String fileId = strArr[1];
  304. String picNum = strArr[2];
  305. String md5 = strArr[3];
  306. String chunk = strArr[4];
  307. ResultData result = null;
  308. if (file.isEmpty()){
  309. throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
  310. }
  311. if (StringUtils.isEmpty(fileId)){
  312. throw new BusinessException(ErrorCode.FAILURE_CODE_5049);
  313. }
  314. if (picNum == null){
  315. throw new BusinessException(ErrorCode.FAILURE_CODE_5050);
  316. }
  317. if (StringUtils.isEmpty(mac)){
  318. throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
  319. }
  320. if (StringUtils.isEmpty(md5)){
  321. throw new BusinessException(ErrorCode.FAILURE_CODE_5051);
  322. }
  323. long size = file.getSize();
  324. log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
  325. chunk = chunk.split(SPLICE)[0];
  326. // 获取文件名
  327. String fileName = file.getOriginalFilename();
  328. log.info("上传的文件名为:" + fileName);
  329. // 获取文件的后缀名
  330. String suffixName = fileName.substring(fileName.lastIndexOf("."));
  331. log.info("上传的后缀名为:" + suffixName);
  332. String folderName = (String) redisTemplate.opsForValue().get(fileId);
  333. if(StringUtils.isEmpty(folderName)){
  334. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
  335. if(scenePro != null){
  336. folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
  337. }
  338. }
  339. // 1. 判断该文件是否已经上传过
  340. // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
  341. // 3. 如果未上传过,需要上传。
  342. StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
  343. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
  344. boolean needUpload = false;
  345. File dbFile = new File(sb.toString());
  346. if (dbFile.exists()){
  347. String fileMD5 = FileMd5Util.getFileMD5(dbFile);
  348. if (md5.equals(fileMD5) && dbFile.length() == size){
  349. log.warn("文件已存在,MD5和文件大小一致。");
  350. SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
  351. if (uploadEntity != null){
  352. uploadEntity.setSize((int) size);
  353. uploadEntity.setMd5(md5);
  354. uploadEntity.setFilePath(sb.toString());
  355. uploadEntity.setFileSourceName(fileName);
  356. uploadEntity.setUploadStatus(1);
  357. sceneFileUploadService.updateById(uploadEntity);
  358. }else{
  359. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  360. sceneFileUploadEntity.setSize((int) size);
  361. sceneFileUploadEntity.setMd5(md5);
  362. sceneFileUploadEntity.setFilePath(sb.toString());
  363. sceneFileUploadEntity.setFileSourceName(fileName);
  364. sceneFileUploadEntity.setUploadStatus(1);
  365. sceneFileUploadEntity.setFileId(fileId);
  366. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  367. sceneFileUploadService.save(sceneFileUploadEntity);
  368. }
  369. result = ResultData.ok();
  370. }else if (!md5.equals(fileMD5)) {
  371. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  372. FileUtil.delFile(sb.toString());
  373. needUpload = true;
  374. }else if (dbFile.length() != size){
  375. log.warn("文件已上传,文件大小不一致。上传失败");
  376. FileUtil.delFile(sb.toString());
  377. needUpload = true;
  378. }
  379. }else {
  380. log.warn("文件不存在,需要重新上传");
  381. needUpload = true;
  382. }
  383. // 4. 上传成功后,校验MD5和文件大小是否相等
  384. // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
  385. try {
  386. if (needUpload){
  387. String name = fileName.substring(0, fileName.lastIndexOf("."));
  388. String filePath = this.saveFile(file, filePathBuffer.toString(), name);
  389. File uploadFile = new File(filePath);
  390. String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
  391. SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
  392. sceneFileUploadEntity.setSize((int) size);
  393. sceneFileUploadEntity.setMd5(md5);
  394. sceneFileUploadEntity.setFilePath(sb.toString());
  395. sceneFileUploadEntity.setFileSourceName(fileName);
  396. sceneFileUploadEntity.setFileId(fileId);
  397. sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
  398. if (md5.equals(fileMD5) && uploadFile.length() == size){
  399. log.warn("文件已上传,MD5和文件大小一致。上传成功");
  400. sceneFileUploadEntity.setUploadStatus(1);
  401. sceneFileUploadService.save(sceneFileUploadEntity);
  402. result = ResultData.ok();
  403. }else if (!md5.equals(fileMD5)) {
  404. log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
  405. sceneFileUploadEntity.setUploadStatus(-1);
  406. sceneFileUploadService.save(sceneFileUploadEntity);
  407. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  408. }else if (uploadFile.length() != size){
  409. log.warn("文件已上传,文件大小不一致。上传失败");
  410. sceneFileUploadEntity.setUploadStatus(-1);
  411. sceneFileUploadService.save(sceneFileUploadEntity);
  412. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  413. }
  414. }
  415. }catch (IllegalStateException | IOException e) {
  416. log.error(ErrorCode.FAILURE_CODE_5052.message(), e);
  417. result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
  418. }
  419. return result;
  420. }
  421. @Override
  422. public ResultData uploadSuccess(String params) throws Exception {
  423. log.info("uploadSuccess-params: " + params);
  424. if (StrUtil.isEmpty(params)) {
  425. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  426. }
  427. params = params.replaceAll("%2B", "+");
  428. Base64 base64 = new Base64();
  429. String cipher = params;
  430. // 私钥解密过程
  431. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  432. base64.decode(cipher));
  433. String restr = new String(res, "UTF-8");
  434. log.debug("uploadSuccess-params解密结果:" + restr);
  435. String[] strArr = restr.split(SPLICE);
  436. if (strArr.length != 3) {
  437. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  438. }
  439. String mac = strArr[0];
  440. String fileId = strArr[1];
  441. String folderName = (String) redisTemplate.opsForValue().get(fileId);
  442. if(StringUtils.isEmpty(folderName)){
  443. SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
  444. if(scenePro != null){
  445. folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
  446. }
  447. if(StringUtils.isEmpty(folderName)){
  448. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  449. if(sceneFileBuild != null){
  450. folderName = sceneFileBuild.getUnicode();
  451. }
  452. }
  453. }
  454. StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
  455. boolean flag = this.uploadSuccess(fileId, filePathBuffer);
  456. if(flag){
  457. //调用建模的方法
  458. // TODO: 2021/12/31
  459. // buildScene(filePathBuffer.toString(), fileId, false, null);
  460. }
  461. return ResultData.ok();
  462. }
  463. @Override
  464. public ResultData uploadSuccessBuild(String params) throws Exception {
  465. log.info("uploadSuccessBuild-params: " + params);
  466. if (StringUtils.isEmpty(params)) {
  467. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  468. }
  469. params = params.replaceAll("%2B", "+");
  470. Base64 base64 = new Base64();
  471. String cipher = params;
  472. // 私钥解密过程
  473. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  474. base64.decode(cipher));
  475. String restr = new String(res, "UTF-8");
  476. log.debug("uploadSuccessBuild-params解密结果:" + restr);
  477. String[] strArr = restr.split(SPLICE);
  478. if (strArr.length != 3) {
  479. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  480. }
  481. String mac = strArr[0];
  482. String fileId = strArr[1];
  483. String folderName = (String)redisTemplate.opsForValue().get(fileId);
  484. if(StringUtils.isEmpty(folderName)){
  485. SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
  486. if(sceneProPO != null){
  487. folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
  488. }
  489. if(StringUtils.isEmpty(folderName)){
  490. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  491. if(sceneFileBuild != null){
  492. folderName = sceneFileBuild.getUnicode();
  493. }
  494. }
  495. }
  496. StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
  497. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  498. File filePath = new File(filePathBuffer.toString());
  499. if(!filePath.exists()){
  500. filePath.mkdirs();
  501. }
  502. if("s3".equals(type)){
  503. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  504. }else {
  505. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  506. }
  507. // TODO: 2021/12/31
  508. // buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  509. return ResultData.ok();
  510. }
  511. @Override
  512. public ResultData turntableUploadSuccess(String params) throws Exception {
  513. log.info("uploadSuccessBuild-params: " + params);
  514. if (StringUtils.isEmpty(params)) {
  515. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  516. }
  517. params = params.replaceAll("%2B", "+");
  518. Base64 base64 = new Base64();
  519. String cipher = params;
  520. // 私钥解密过程
  521. byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
  522. base64.decode(cipher));
  523. String restr = new String(res, "UTF-8");
  524. log.debug("uploadSuccessBuild-params解密结果:" + restr);
  525. String[] strArr = restr.split(SPLICE);
  526. if (strArr.length != 3) {
  527. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  528. }
  529. String mac = strArr[0];
  530. String fileId = strArr[1];
  531. String folderName = (String)redisTemplate.opsForValue().get(fileId);
  532. if(StringUtils.isEmpty(folderName)){
  533. SceneProPO sceneProPO = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
  534. if(sceneProPO != null){
  535. folderName = sceneProPO.getDataSource().substring(sceneProPO.getDataSource().lastIndexOf("/") + 1);
  536. }
  537. if(StringUtils.isEmpty(folderName)){
  538. SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
  539. if(sceneFileBuild != null){
  540. folderName = sceneFileBuild.getUnicode();
  541. }
  542. }
  543. }
  544. //判断 是否为激光相机
  545. // TODO: 2021/12/31 调用跨服务接口 获取CameraEntity CameraDetailEntity
  546. // CameraEntity cameraEntity = goodsService.findByChildName(mac);
  547. // CameraDetailEntity cameraDetailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
  548. String hardDisk = routeConfig.getHardDisk();
  549. // if(cameraDetailEntity!=null){
  550. // if(cameraDetailEntity.getType() == 10){
  551. // hardDisk = routeConfig.getHardDiskLaser();
  552. // }
  553. // }
  554. // log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetailEntity.getType());
  555. StringBuilder filePathBuffer = new StringBuilder(hardDisk).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
  556. StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
  557. File filePath = new File(filePathBuffer.toString());
  558. if(!filePath.exists()){
  559. filePath.mkdirs();
  560. }
  561. if("s3".equals(type)){
  562. CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
  563. }else {
  564. CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
  565. }
  566. // TODO: 2021/12/31
  567. // turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
  568. return ResultData.ok();
  569. }
  570. @Override
  571. public ResultData getS3UploadUrl(String params) throws Exception {
  572. if (StringUtils.isEmpty(params)) {
  573. throw new BusinessException(ErrorCode.PARAM_REQUIRED);
  574. }
  575. JSONObject jsonObject = JSON.parseObject(params);
  576. if(jsonObject == null){
  577. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  578. }
  579. JSONArray files = jsonObject.getJSONArray("Files");
  580. if(files == null){
  581. throw new BusinessException(ErrorCode.PARAM_FORMAT_ERROR);
  582. }
  583. List<String> urls = new ArrayList<>();
  584. for(int i = 0, len = files.size(); i < len; i++){
  585. urls.add(files.getJSONObject(i).getString("filename"));
  586. }
  587. return ResultData.ok(uploadToOssUtil.getUploadS3Url(urls));
  588. }
  589. @Override
  590. public ResultData buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{
  591. log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix,
  592. dataFdage, zipName, password, userName);
  593. if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) ||
  594. StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
  595. throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
  596. }
  597. // TODO: 2021/12/31 feign
  598. // CameraEntity cameraEntity = goodsService.findByChildName(userName);
  599. // if(cameraEntity == null){
  600. // // TODO: 2021/12/31 feign
  601. // cameraEntity = goodsService.findBySnCode(userName);
  602. // }
  603. // if (cameraEntity == null){
  604. // throw new BusinessException(CameraConstant.FAILURE_6003);
  605. // }
  606. // if(!password.equals(cameraEntity.getChildPassword())){
  607. // throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
  608. // }
  609. //
  610. // String unicode = prefix.substring(prefix.lastIndexOf("/") + 1);
  611. // String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
  612. //
  613. // //下载data.fdage
  614. // FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture");
  615. // String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage);
  616. // JSONObject jsonObject = JSONObject.parseObject(data);
  617. // if(jsonObject == null){
  618. // log.info("data.fdage不存在");
  619. // throw new BusinessException(CameraConstant.FAILURE_6009);
  620. // }
  621. //
  622. // String sceneNum = "";
  623. // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  624. // SceneProPO sceneProPO = sceneProService.findByFileId("/" + unicode);
  625. // int rebuild = 1;
  626. // if(StrUtil.isNotEmpty(oldNum)){
  627. // sceneNum = oldNum;
  628. // }else {
  629. //
  630. // if(sceneProPO != null){
  631. // sceneNum = sceneProPO.getSceneCode();
  632. // //重算的场景,先移除该场景对应的容量
  633. // userService.rebuildReduceSpaceBySceneNum(sceneNum);
  634. // }else {
  635. // sceneNum = sceneNumService.generateSceneNum();
  636. // rebuild = 0;
  637. // }
  638. // }
  639. //
  640. // String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  641. // log.info("查询相机:" + cameraName);
  642. // // TODO: 2021/12/31 feign
  643. // cameraEntity = goodsService.findByChildName(cameraName);
  644. //
  645. // if(cameraEntity == null){
  646. // log.error("该相机不存在:" + cameraName);
  647. // //偶现data.fdage给的相机码多了或少了4DKKPRO_
  648. // if(cameraName.contains("4DKKPRO_")){
  649. // cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", ""));
  650. // }else {
  651. // cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName);
  652. // }
  653. // if(cameraEntity == null){
  654. // throw new BusinessException(CameraConstant.FAILURE_6003);
  655. // }
  656. // }
  657. //
  658. // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
  659. // if(detailEntity == null){
  660. // log.error("该相机详情不存在:" + cameraName);
  661. // throw new BusinessException(CameraConstant.FAILURE_6003);
  662. // }
  663. //
  664. // String icon = null;
  665. // if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  666. // //下载封面图icon
  667. // FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture");
  668. // uploadToOssUtil.upload(path + File.separator + "capture" + File.separator +
  669. // jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  670. // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  671. // if("s3".equals(type)){
  672. // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  673. // }
  674. // }
  675. //
  676. // JSONObject firmwareVersion = new JSONObject();
  677. // if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  678. // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  679. // }
  680. //
  681. // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  682. // firmwareVersion.put("version", jsonObject.getString("version"));
  683. // }
  684. //
  685. // String sceneUrl = mainUrl + sceneProNewUrl;
  686. // String buildType = "V3";
  687. // //表示新款双目
  688. // Long cameraType = 5L;
  689. // if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){
  690. //
  691. // //6表示小红屋双目
  692. // cameraType = 6L;
  693. // }
  694. //
  695. // SceneProEntity scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
  696. // jsonObject.getString("pwd"), unicode,
  697. // cameraType, "", prefix, zipName, icon, "0", detailEntity.getUserId(), userName,
  698. // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  699. // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  700. // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
  701. // producer, 4, firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
  702. // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
  703. //
  704. // if(scene == null){
  705. // log.info("双目相机入库失败");
  706. // return Result.failure("双目相机异常");
  707. // }
  708. // JSONObject statusJson = new JSONObject();
  709. // //临时将-2改成1,app还没完全更新
  710. // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
  711. // statusJson.put("webSite", scene.getWebSite());
  712. // statusJson.put("sceneNum", scene.getNum());
  713. // statusJson.put("thumb", scene.getThumb());
  714. // statusJson.put("payStatus", scene.getPayStatus());
  715. // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  716. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  717. // "data/data"+sceneNum+File.separator+"status.json");
  718. //
  719. // //删除oss的houst_floor.json
  720. // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  721. //
  722. // producer.sendMsg(scene.getMqMsg());
  723. //
  724. // Map<String, String> map = new HashMap<>();
  725. // map.put("sceneNum", sceneNum);
  726. // map.put("sceneUrl", sceneUrl + sceneNum);
  727. // return ResultData.ok(map);
  728. return null;
  729. }
  730. @Override
  731. public ResultData buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{
  732. String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage");
  733. JSONObject jsonObject = JSONObject.parseObject(data);
  734. // TODO: 2021/12/31
  735. String sceneNum = null;
  736. // sceneNumService.generateSceneNum();
  737. return ResultData.ok(mainUrl + sceneProNewUrl + sceneNum);
  738. }
  739. // public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  740. // String data = FileUtils.readFile(filePath + "data.fdage");
  741. // JSONObject jsonObject = JSONObject.parseObject(data);
  742. //
  743. // //调用createScene方法生成scene数据和加入算法队列
  744. // if(jsonObject == null) {
  745. // log.info("data.fdage文件不存在");
  746. // throw new BusinessException(CameraConstant.FAILURE_6009);
  747. // }
  748. //
  749. // String sceneNum = "";
  750. //
  751. // String snCode = jsonObject.getJSONObject("cam").getString("uuid");
  752. // String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出
  753. //// sceneProService.updateRecStatus(unicode);
  754. // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  755. // SceneProPO sceneProPO = sceneProService.findByFileId("/" + fileId + "/");
  756. // int rebuild = 1;
  757. // if(sceneProPO != null){
  758. // sceneNum = sceneProPO.getSceneCode();
  759. // if(sceneProPO.getSceneStatus() == SceneStatus.wait.code()){
  760. // log.info(sceneNum + ":场景处于计算中,不能再计算");
  761. // return;
  762. // }
  763. // }else {
  764. // sceneNum = sceneNumService.generateSceneNum();
  765. // rebuild = 0;
  766. // }
  767. //
  768. // if(sceneNum == null){
  769. // log.error("大场景序号为空:" + sceneNum);
  770. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  771. // }
  772. //
  773. // log.info("查询相机:" + snCode);
  774. // // TODO: 2021/12/31 调用feign
  775. //// CameraEntity cameraEntity = goodsService.findByChildName(snCode);
  776. //
  777. // if(cameraEntity == null){
  778. // log.error("该相机不存在:" + snCode);
  779. // cameraEntity = goodsService.findBySnCode(snCode);
  780. // if(cameraEntity == null){
  781. // throw new BusinessException(CameraConstant.FAILURE_6003);
  782. // }
  783. // }
  784. //
  785. // // TODO: 2021/12/31 调用feign
  786. // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
  787. // if(detailEntity == null){
  788. // log.error("该相机详情不存在:" + snCode);
  789. // throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
  790. // }
  791. //
  792. // String userName = null;
  793. // if(detailEntity.getUserId() != null){
  794. // Result result = userService.findById(detailEntity.getUserId());
  795. // SSOUser user = mapper.convertValue(result.getData(), SSOUser.class);
  796. // if(user != null){
  797. // userName = user.getUserName();
  798. // }
  799. // }
  800. //
  801. // String icon = null;
  802. // if(jsonObject.containsKey("icon") && StringUtil.isNotEmpty(jsonObject.getString("icon"))){
  803. // CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  804. // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  805. // if("s3".equals(type)){
  806. // CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  807. // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  808. // }
  809. // uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  810. // }
  811. //
  812. // JSONObject firmwareVersion = new JSONObject();
  813. // if(jsonObject.containsKey("camSoftwareVersion") && StringUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  814. // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  815. // }
  816. //
  817. // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  818. // firmwareVersion.put("version", jsonObject.getString("version"));
  819. // }
  820. //
  821. // String sceneUrl = mainUrl + sceneProNewUrl;
  822. // String buildType = "V3";
  823. // //13表示转台
  824. // Long cameraType = 13L;
  825. //
  826. // //激光转台 八目相机占用 10 和 11
  827. // if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  828. // //激光转台
  829. // cameraType = 14L;
  830. // }
  831. //
  832. //
  833. // //重算的场景,先移除该场景对应的容量
  834. // if(rebuild == 1){
  835. // userService.rebuildReduceSpaceBySceneNum(sceneNum);
  836. // }else {
  837. // //上传log-main.png
  838. // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
  839. // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
  840. // }
  841. // SceneProEntity scene = null;
  842. // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
  843. // jsonObject.getString("pwd"), unicode,
  844. // cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName,
  845. // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  846. // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  847. // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
  848. // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
  849. // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
  850. //
  851. // if(scene != null){
  852. // JSONObject statusJson = new JSONObject();
  853. // //临时将-2改成1,app还没完全更新
  854. // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
  855. // statusJson.put("webSite", scene.getWebSite());
  856. // statusJson.put("sceneNum", scene.getNum());
  857. // statusJson.put("thumb", scene.getThumb());
  858. // statusJson.put("payStatus", scene.getPayStatus());
  859. // statusJson.put("recStatus", scene.getRecStatus());
  860. // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  861. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  862. // "data/data"+sceneNum+File.separator+"status.json");
  863. // }
  864. //
  865. // if(detailEntity.getCompanyId() != null){
  866. // CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId());
  867. // if(companyEntity != null){
  868. //
  869. // Map<String, Object> jsonMap = new HashMap<>();
  870. //
  871. // log.info("复制企业logo");
  872. // SceneProEditEntity sceneProEditEntity = sceneProEditService.findByProId(scene.getId());
  873. //
  874. // if(StringUtil.isNotEmpty(companyEntity.getTopLogo())){
  875. //
  876. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(),
  877. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
  878. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
  879. // "images/images" + sceneNum + "/logo-main.png");
  880. // }
  881. //
  882. // if(StringUtil.isNotEmpty(companyEntity.getFloorLogo())){
  883. //
  884. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(),
  885. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
  886. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
  887. // "images/images" + sceneNum + "/floorLogoImg.png");
  888. //
  889. // sceneProEditEntity.setFloorLogo("user");
  890. // jsonMap.put("floorLogoSize", sceneProEditEntity.getFloorLogoSize());
  891. // jsonMap.put("floorLogo", "user");
  892. // }
  893. //
  894. // if(StringUtil.isNotEmpty(companyEntity.getQrLogo())){
  895. //
  896. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(),
  897. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  898. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  899. // "images/images" + sceneNum + "/QRShareLogo.png");
  900. // sceneProEditEntity.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
  901. //
  902. // //生成新的分享的二维码
  903. // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  904. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  905. // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  906. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  907. // }
  908. //
  909. // if(StringUtil.isNotEmpty(companyEntity.getMarkerLogo())){
  910. //
  911. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(),
  912. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  913. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  914. // "images/images" + sceneNum + "/marker.png");
  915. //
  916. // sceneProEditEntity.setMarkerLogo("user");
  917. // jsonMap.put("markerLogo", "user");
  918. // }
  919. //
  920. // sceneProEditEntity.setShowLogoBottom(companyEntity.getShowLogo());
  921. // sceneProEditService.update(sceneProEditEntity);
  922. //
  923. // jsonMap.put("showLogoBottom", companyEntity.getShowLogo());
  924. // FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
  925. // }
  926. //
  927. // //删除oss的houst_floor.json
  928. // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  929. //
  930. // }
  931. //
  932. // //激光转台 八目相机占用 10 和 11
  933. // if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
  934. //
  935. // producer.sendMsgLaser(scene.getMqMsg());
  936. // }else if(scene != null){
  937. // producer.sendMsg(scene.getMqMsg());
  938. // }
  939. // }
  940. public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
  941. //获取解压后的资源的data.fdage中的数据
  942. String data = FileUtils.readFile(filePath + "data.fdage");
  943. JSONObject jsonObject = JSONObject.parseObject(data);
  944. //调用createScene方法生成scene数据和加入算法队列
  945. // if(jsonObject != null){
  946. // //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算
  947. // if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){
  948. // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  949. // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration";
  950. // //生成标定数据
  951. // ComputerUtil.createCalibrationData(calPath, filePath);
  952. // //开始标定计算
  953. // producer.sendMsg(calPath);
  954. //
  955. // }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){
  956. // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  957. // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis";
  958. // //生成标定数据
  959. // ComputerUtil.createCalibrationData(calPath, filePath);
  960. // //开始标定计算
  961. // Map<String,String> map = ComputerUtil.computerCalibration(calPath);
  962. // }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){
  963. // String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
  964. // String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading";
  965. // //生成标定数据
  966. // ComputerUtil.createCalibrationData(calPath, filePath);
  967. // //开始标定计算
  968. // producer.sendMsg(calPath);
  969. //
  970. // }else {
  971. //
  972. // String sceneNum = "";
  973. //
  974. // String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
  975. // String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
  976. // //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
  977. // SceneProPO proEntity = sceneProService.findByFileId("/" + fileId + "/");
  978. // int rebuild = 1;
  979. // if(proEntity != null){
  980. // sceneNum = proEntity.getSceneCode();
  981. // if(proEntity.getSceneStatus() == SceneStatus.wait.code()){
  982. // log.info(sceneNum + ":场景处于计算中,不能再计算");
  983. // return;
  984. // }
  985. // }else {
  986. // sceneNum = scene3dNumService.generateSceneNum();
  987. // rebuild = 0;
  988. // }
  989. //
  990. // if(sceneNum == null){
  991. // log.error("大场景序号为空:" + sceneNum);
  992. // throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
  993. // }
  994. //
  995. // log.info("查询相机:" + cameraName);
  996. // CameraEntity cameraEntity = goodsService.findByChildName(cameraName);
  997. //
  998. // if(cameraEntity == null){
  999. // log.error("该相机不存在:" + cameraName);
  1000. // //偶现data.fdage给的相机码多了或少了4DKKPRO_
  1001. // if(cameraName.contains("4DKKPRO_")){
  1002. // cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", ""));
  1003. // }else {
  1004. // cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName);
  1005. // }
  1006. // if(cameraEntity == null){
  1007. // throw new BusinessException(CameraConstant.FAILURE_6003);
  1008. // }
  1009. // }
  1010. //
  1011. // CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
  1012. // if(detailEntity == null){
  1013. // log.error("该相机详情不存在:" + cameraName);
  1014. // throw new BusinessException(CameraConstant.FAILURE_6003);
  1015. // }
  1016. //
  1017. // String userName = null;
  1018. // if(detailEntity.getUserId() != null){
  1019. // ResultData result = userService.findById(detailEntity.getUserId());
  1020. // SSOUser user = mapper.convertValue(result.getData(), SSOUser.class);
  1021. // if(user != null){
  1022. // userName = user.getUserName();
  1023. // }
  1024. // }
  1025. // String icon = null;
  1026. // if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
  1027. // CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
  1028. // icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  1029. // if("s3".equals(type)){
  1030. // CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
  1031. // icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
  1032. // }
  1033. // uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
  1034. // }
  1035. //
  1036. // JSONObject firmwareVersion = new JSONObject();
  1037. // if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
  1038. // firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
  1039. // }
  1040. //
  1041. // if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
  1042. // firmwareVersion.put("version", jsonObject.getString("version"));
  1043. // }
  1044. //
  1045. // String sceneUrl = mainUrl + sceneProUrl;
  1046. // String buildType = "V2";
  1047. // Long cameraType = 10L;
  1048. // //根据videoVersion判断是V2还是V3版本的算法和页面
  1049. // if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){
  1050. // if(jsonObject.getIntValue("videoVersion") >= 4){
  1051. // buildType = "V3";
  1052. // cameraType = 11L;
  1053. // sceneUrl = mainUrl + sceneProNewUrl;
  1054. // }
  1055. // }
  1056. // //重算的场景,先移除该场景对应的容量
  1057. // if(rebuild == 1){
  1058. // userService.rebuildReduceSpaceBySceneNum(sceneNum);
  1059. // }else {
  1060. // //上传log-main.png
  1061. // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
  1062. // uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
  1063. // }
  1064. // SceneProPO scene = null;
  1065. // if(fromOss){
  1066. // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
  1067. // jsonObject.getString("pwd"), unicode,
  1068. // cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName,
  1069. // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1070. // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1071. // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
  1072. // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
  1073. // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
  1074. // }else {
  1075. // scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
  1076. // jsonObject.getString("pwd"), unicode,
  1077. // detailEntity.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", detailEntity.getUserId(), userName,
  1078. // jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
  1079. // jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
  1080. // jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
  1081. // producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
  1082. // sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
  1083. // }
  1084. //
  1085. // if(scene != null){
  1086. // JSONObject statusJson = new JSONObject();
  1087. // //临时将-2改成1,app还没完全更新
  1088. // statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
  1089. // statusJson.put("webSite", scene.getWebSite());
  1090. // statusJson.put("sceneNum", scene.getNum());
  1091. // statusJson.put("thumb", scene.getThumb());
  1092. // statusJson.put("payStatus", scene.getPayStatus());
  1093. // statusJson.put("recStatus", scene.getRecStatus());
  1094. // FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
  1095. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
  1096. // "data/data"+sceneNum+File.separator+"status.json");
  1097. // }
  1098. //
  1099. // //删除oss的houst_floor.json(国际版可能会卡住)
  1100. // uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
  1101. //
  1102. // if(detailEntity.getCompanyId() != null){
  1103. // CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId());
  1104. // if(companyEntity != null){
  1105. //
  1106. // Map<String, Object> jsonMap = new HashMap<>();
  1107. //
  1108. // log.info("复制企业logo");
  1109. // SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId());
  1110. // SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
  1111. //
  1112. // if(StrUtil.isNotEmpty(companyEntity.getTopLogo())){
  1113. // //复制阿里云主服务器的图片到横琴云副服务器中
  1114. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo()).exists()){
  1115. // log.info("下载topLogo");
  1116. // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getTopLogo() + "?t=" + System.currentTimeMillis(),
  1117. // companyEntity.getTopLogo().substring(companyEntity.getTopLogo().lastIndexOf("/") + 1),
  1118. // ConstantFilePath.BASE_PATH + companyEntity.getTopLogo().substring(0, companyEntity.getTopLogo().lastIndexOf("/")));
  1119. // }
  1120. //
  1121. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(),
  1122. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
  1123. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
  1124. // "images/images" + sceneNum + "/logo-main.png");
  1125. // }
  1126. //
  1127. // if(StrUtil.isNotEmpty(companyEntity.getFloorLogo())){
  1128. // //复制阿里云主服务器的图片到横琴云副服务器中
  1129. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo()).exists()){
  1130. // log.info("下载floorLogo");
  1131. // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getFloorLogo() + "?t=" + System.currentTimeMillis(),
  1132. // companyEntity.getFloorLogo().substring(companyEntity.getFloorLogo().lastIndexOf("/") + 1),
  1133. // ConstantFilePath.BASE_PATH + companyEntity.getFloorLogo().substring(0, companyEntity.getFloorLogo().lastIndexOf("/")));
  1134. // }
  1135. //
  1136. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(),
  1137. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
  1138. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
  1139. // "images/images" + sceneNum + "/floorLogoImg.png");
  1140. //
  1141. // sceneProEdit.setFloorLogo("user");
  1142. // jsonMap.put("floorLogoSize", sceneProEdit.getFloorLogoSize());
  1143. // jsonMap.put("floorLogo", "user");
  1144. // }
  1145. //
  1146. // if(StrUtil.isNotEmpty(companyEntity.getQrLogo())){
  1147. // //复制阿里云主服务器的图片到横琴云副服务器中
  1148. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo()).exists()){
  1149. // log.info("下载qrLogo");
  1150. // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getQrLogo() + "?t=" + System.currentTimeMillis(),
  1151. // companyEntity.getQrLogo().substring(companyEntity.getQrLogo().lastIndexOf("/") + 1),
  1152. // ConstantFilePath.BASE_PATH + companyEntity.getQrLogo().substring(0, companyEntity.getQrLogo().lastIndexOf("/")));
  1153. // }
  1154. //
  1155. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(),
  1156. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
  1157. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
  1158. // "images/images" + sceneNum + "/QRShareLogo.png");
  1159. // sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
  1160. //
  1161. // //生成新的分享的二维码
  1162. // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
  1163. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1164. // MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
  1165. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
  1166. // }
  1167. //
  1168. // if(StrUtil.isNotEmpty(companyEntity.getMarkerLogo())){
  1169. // //复制阿里云主服务器的图片到横琴云副服务器中
  1170. // if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo()).exists()){
  1171. // log.info("下载floorLogo");
  1172. // FileUtils.downLoadFromUrl(mainUrl + companyEntity.getMarkerLogo() + "?t=" + System.currentTimeMillis(),
  1173. // companyEntity.getMarkerLogo().substring(companyEntity.getMarkerLogo().lastIndexOf("/") + 1),
  1174. // ConstantFilePath.BASE_PATH + companyEntity.getMarkerLogo().substring(0, companyEntity.getMarkerLogo().lastIndexOf("/")));
  1175. // }
  1176. //
  1177. // FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(),
  1178. // ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
  1179. // uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
  1180. // "images/images" + sceneNum + "/marker.png");
  1181. //
  1182. // sceneProEdit.setMarkerLogo("user");
  1183. // jsonMap.put("markerLogo", "user");
  1184. // }
  1185. //
  1186. // sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
  1187. // sceneProEditService.updateById(sceneProEdit);
  1188. //
  1189. // sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
  1190. // sceneProEditExt.setShowLogoBottom(companyEntity.getShowLogo());
  1191. // sceneProEditExtService.updateById(sceneProEditExt);
  1192. //
  1193. // jsonMap.put("showLogoBottom", companyEntity.getShowLogo());
  1194. // FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
  1195. // }
  1196. //
  1197. // }
  1198. //
  1199. // // 正顺相机不予计算
  1200. // Long companyId = detailEntity.getCompanyId();
  1201. // if(Objects.nonNull(unCalculatedCompanyIds) && Arrays.asList(unCalculatedCompanyIds).contains(companyId)){
  1202. // return;
  1203. // }
  1204. // if(scene != null){
  1205. // producer.sendMsg(scene.getMqMsg());
  1206. // }
  1207. //
  1208. // }
  1209. // }else {
  1210. // log.info("data.fdage文件不存在");
  1211. // throw new BusinessException(CameraConstant.FAILURE_6009);
  1212. // }
  1213. }
  1214. public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException {
  1215. //扩展名格式
  1216. String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
  1217. String name;
  1218. /*
  1219. 指定上传目录
  1220. */
  1221. if (filePath != null && !"".equals(filePath.trim())) {
  1222. name = designatedUp(filePath, fileId, file);
  1223. return name;
  1224. }
  1225. /*
  1226. 默认上传目录
  1227. */
  1228. //图片类型文件
  1229. if (this.inArray(routeConfig.getImageType(), extName)) {
  1230. filePath = routeConfig.getImageFolder();
  1231. }
  1232. //视频类型文件
  1233. else if (this.inArray(routeConfig.getVideoType(), extName)) {
  1234. filePath = routeConfig.getVideoFolder();
  1235. }
  1236. //文档类型文件
  1237. else if (this.inArray(routeConfig.getDocumentType(), extName)) {
  1238. filePath = routeConfig.getDocumentFolder();
  1239. }
  1240. //音频类型文件
  1241. else if (this.inArray(routeConfig.getMusicType(), extName)) {
  1242. filePath = routeConfig.getMusicFolder();
  1243. } else {
  1244. return "This upload type is not supported temporarily";
  1245. }
  1246. name = myfileUp(filePath, file);
  1247. return name;
  1248. }
  1249. /**
  1250. * 删除文件
  1251. *
  1252. * @param filePath 包含文件路径的文件名
  1253. * @return
  1254. */
  1255. public String dropFile(String filePath) {
  1256. try {
  1257. FileUtil.delFile(routeConfig.getHardDisk() + File.separator + filePath);
  1258. return "successful operation";
  1259. } catch (Exception e) {
  1260. return "drop file error";
  1261. }
  1262. }
  1263. /**
  1264. * 判断数组中是否包含某个元素
  1265. *
  1266. * @param array 类型的数组
  1267. * @param element 被检查的类型
  1268. * @return
  1269. */
  1270. private boolean inArray(String[] array, String element) {
  1271. boolean flag = false;
  1272. for (String type : array) {
  1273. if (element.equals(type)) {
  1274. flag = true;
  1275. break;
  1276. }
  1277. }
  1278. return flag;
  1279. }
  1280. /**
  1281. * 默认上传文件到文件夹
  1282. *
  1283. * @param folder 默认文件夹
  1284. * @param file 上传的文件
  1285. * @return
  1286. */
  1287. private String myfileUp(String folder, MultipartFile file) throws IOException {
  1288. LocalDate today = LocalDate.now();
  1289. String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator;
  1290. String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", "");
  1291. String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode);
  1292. saveName = folder + File.separator + saveName + File.separator + returnName;
  1293. log.warn("This file has been uploaded: " + saveName);
  1294. return saveName;
  1295. }
  1296. /**
  1297. * 指定目录上传文件
  1298. *
  1299. * @param folder 指定文件夹
  1300. * @param file 上传文件
  1301. * @return
  1302. */
  1303. private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException {
  1304. StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder);
  1305. String returnName = FileUpload.fileUp(file, sb.toString(), fileId);
  1306. String filePathName = sb.toString() + File.separator + File.separator + returnName;
  1307. log.warn("This file has been uploaded: " + filePathName);
  1308. return filePathName;
  1309. }
  1310. }