ManagerController.java 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. package com.example.demo.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.example.demo.constant.CodeConstant;
  6. import com.example.demo.entity.*;
  7. import com.example.demo.mq.TopicRabbitConfig;
  8. import com.example.demo.service.*;
  9. import com.example.demo.util.*;
  10. import com.example.demo.vo.request.RequestRenovationParts;
  11. import com.example.demo.vo.request.RequestRenovationPartsDetailManager;
  12. import com.example.demo.vo.response.ResponseRenovationPartsAttaching;
  13. import com.example.demo.vo.response.ResponseRenovationPartsDetailManager;
  14. import com.example.demo.vo.response.ResponseRenovationPartsSize;
  15. import com.github.pagehelper.Page;
  16. import com.github.pagehelper.PageInfo;
  17. import com.github.pagehelper.util.StringUtil;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiImplicitParam;
  20. import io.swagger.annotations.ApiImplicitParams;
  21. import io.swagger.annotations.ApiOperation;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.commons.lang.StringUtils;
  24. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.web.bind.annotation.*;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.servlet.http.HttpServletRequest;
  31. import java.io.File;
  32. import java.util.ArrayList;
  33. import java.util.Date;
  34. import java.util.List;
  35. /**
  36. * Created by Hb_zzZ on 2020/12/1.
  37. */
  38. @Slf4j
  39. @RestController
  40. @RequestMapping("/manager")
  41. @Api(tags = "管理后台模块")
  42. public class ManagerController {
  43. @Value("${server.file.location}")
  44. private String buildPath;
  45. @Autowired
  46. private IModelUploadService modelUploadService;
  47. @Autowired
  48. private IRenovationPartsDetailService renovationPartsDetailService;
  49. @Autowired
  50. private IRenovationPartsAttachingService renovationPartsAttachingService;
  51. @Autowired
  52. private IRenovationPartsColorService renovationPartsColorService;
  53. @Autowired
  54. private IRenovationPartsTypeService renovationPartsTypeService;
  55. @Autowired
  56. private IRenovationPartsService renovationPartsService;
  57. @Autowired
  58. private IRenovationPartsShapeService renovationPartsShapeService;
  59. @Autowired
  60. private IRenovationPartsClassifyService renovationPartsClassifyService;
  61. @Autowired
  62. private IRenovationPartsStyleService renovationPartsStyleService;
  63. @Autowired
  64. private IRenovationPartsSizeService renovationPartsSizeService;
  65. @Autowired
  66. private IRenovationPartsBrandService renovationPartsBrandService;
  67. @Autowired
  68. private ICompanyService companyService;
  69. @Autowired
  70. private ObjToToolbagUtil objToToolbagUtil;
  71. @Value("${build.url}")
  72. private String buildUrl;
  73. @Value("${model.build.url}")
  74. private String modelBuildUrl;
  75. @Value("${prefix.ali}")
  76. private String prefix;
  77. @Value("${max.obj.url}")
  78. private String maxObjUrl;
  79. @Autowired
  80. private UploadToOssUtil uploadToOssUtil;
  81. @Autowired
  82. private RabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方
  83. /**
  84. * 上传模型文件
  85. * @param file
  86. * @return
  87. */
  88. @ApiOperation("上传模型文件")
  89. @RequestMapping(value = "/uploadModel", method = RequestMethod.POST)
  90. @ApiImplicitParams({
  91. @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
  92. @ApiImplicitParam(name = "userType", value = "0管理员,1普通用户", dataType = "String"),
  93. @ApiImplicitParam(name = "file", value = "文件", dataType = "MultipartFile")})
  94. public Result uploadModel(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception{
  95. String userId = request.getParameter("userId");
  96. String userType = request.getParameter("userType");
  97. if (StringUtil.isEmpty(userId) || StringUtil.isEmpty(userType) || file.isEmpty()){
  98. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  99. }
  100. String fileId = null;
  101. ModelUploadEntity modelUploadEntity = null;
  102. do{
  103. fileId = RandomUtil.generateShortUuid();
  104. modelUploadEntity = modelUploadService.findByFileId(fileId);
  105. } while (modelUploadEntity != null);
  106. modelUploadEntity = new ModelUploadEntity();
  107. modelUploadEntity.setUserId(Long.valueOf(userId));
  108. modelUploadEntity.setFileId(fileId);
  109. modelUploadEntity.setUserType(Integer.valueOf(userType));
  110. modelUploadEntity.setStatus(0);
  111. modelUploadEntity.setUploadFile(file.getOriginalFilename());
  112. String path = buildPath + "upload";
  113. File targetFile = new File(path);
  114. if (!targetFile.exists()){
  115. targetFile.mkdirs();
  116. }
  117. String filePath = path + File.separator + fileId + File.separator;
  118. targetFile = new File(filePath + file.getOriginalFilename());
  119. if(!targetFile.getParentFile().exists()){
  120. targetFile.getParentFile().mkdirs();
  121. }
  122. if (targetFile.exists()){
  123. FileUtils.deleteFile(filePath + file.getOriginalFilename());
  124. }
  125. file.transferTo(targetFile);
  126. if(!file.getOriginalFilename().toLowerCase().endsWith(".zip") && !file.getOriginalFilename().toLowerCase().endsWith(".rar")){
  127. return Result.failure(CodeConstant.FAILURE_CODE_4012, CodeConstant.FAILURE_MSG_4012);
  128. }
  129. if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
  130. CreateObjUtil.unZip(filePath + file.getOriginalFilename(), filePath);
  131. }
  132. if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
  133. CreateObjUtil.unRar(filePath + file.getOriginalFilename(), filePath);
  134. }
  135. List<String> allList = new ArrayList<>();
  136. FileUtils.readfilePath(filePath, allList);
  137. File target = null;
  138. String modelType = "datasmith";
  139. boolean falg = true;
  140. for (String targetPath : allList) {
  141. log.info("解压后的-{}文件全路径是-{}", fileId, targetPath);
  142. if(targetPath.toLowerCase().endsWith(".max")){
  143. falg = false;
  144. new File(targetPath).renameTo(new File(targetPath.substring(
  145. 0, targetPath.lastIndexOf(File.separator) + 1) + fileId + ".max"));
  146. break;
  147. }
  148. }
  149. if(falg){
  150. log.error("上传的数据类型不正确-{}", fileId);
  151. return Result.failure(CodeConstant.FAILURE_CODE_4013, CodeConstant.FAILURE_MSG_4013);
  152. }
  153. modelUploadService.save(modelUploadEntity);
  154. // allList = new ArrayList<>();
  155. // FileUtils.readfilePath(filePath, allList);
  156. // for (String targetPath : allList) {
  157. // target = new File(targetPath);
  158. // if(target.isFile()){
  159. // uploadToOssUtil.uploadTo4dTjw(targetPath, "domain/eHome/furniture/InitialData/" + modelType + "/" + fileId + "/" + target.getName());
  160. // }
  161. // }
  162. rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.MODEL, modelUploadEntity.getId() + ":;" + fileId + ":;" + userId + ":;" + modelType);
  163. return Result.success(modelUploadEntity);
  164. }
  165. /**
  166. * 保存模型数据
  167. * @return
  168. */
  169. @ApiOperation("保存模型数据")
  170. @RequestMapping(value = "/modelJson", method = RequestMethod.POST)
  171. @ApiImplicitParams({
  172. @ApiImplicitParam(name = "compressionRatioHasChanged", value = "是否压缩面数,true压缩,false不压缩", dataType = "String"),
  173. @ApiImplicitParam(name = "jsonData", value = "json数据", dataType = "String"),
  174. @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
  175. public Result modelJson(HttpServletRequest request) throws Exception{
  176. String modelId = request.getParameter("modelId");
  177. String jsonData = request.getParameter("jsonData");
  178. String compressionRatioHasChanged = request.getParameter("compressionRatioHasChanged");
  179. if (StringUtil.isEmpty(modelId) || StringUtil.isEmpty(jsonData)){
  180. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  181. }
  182. ModelUploadEntity modelUploadEntity = modelUploadService.findById(Long.parseLong(modelId));
  183. if(modelUploadEntity == null){
  184. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  185. }
  186. String path = buildPath + "upload/" + modelUploadEntity.getFileId() + "/data.json";
  187. FileUtils.writeFile(path, jsonData);
  188. JSONObject json = JSONObject.parseObject(jsonData);
  189. if(!json.containsKey("matrix")){
  190. return Result.failure(CodeConstant.FAILURE_CODE_4011, CodeConstant.FAILURE_MSG_4011);
  191. }
  192. // //判断是否有基础obj,无则用最初obj转换
  193. // if(!new File(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj")).exists()){
  194. // FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath(), buildPath +
  195. // modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
  196. // }else {
  197. // //判断是否有基础obj,有则用基础obj转换
  198. // FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj"), buildPath +
  199. // modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
  200. // }
  201. //将.obj复制一份-copy.obj用作旋转缩放处理
  202. if(new File(buildPath + modelUploadEntity.getObjPath()).exists()){
  203. FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath(), buildPath +
  204. modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
  205. }
  206. //将-base.obj复制一份-baseCopy.obj用作旋转缩放处理
  207. if(new File(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj")).exists()) {
  208. //判断是否有基础obj,有则用基础obj转换
  209. FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj"), buildPath +
  210. modelUploadEntity.getObjPath().replace(".obj", "-baseCopy.obj"), true);
  211. }
  212. //转换成最终obj
  213. ObjProcess.conformity3(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"),
  214. buildPath + modelUploadEntity.getObjPath() , json.getString("matrix").replace("[", "").replace("]", ""));
  215. //转换成基础obj
  216. ObjProcess.conformity3(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-baseCopy.obj"),
  217. buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj") , json.getString("matrix").replace("[", "").replace("]", ""));
  218. if(StringUtil.isNotEmpty(compressionRatioHasChanged) &&
  219. Boolean.valueOf(compressionRatioHasChanged) &&
  220. json.containsKey("compressionRatio")){
  221. int compressionRatio = json.getIntValue("compressionRatio");
  222. String fileId = modelUploadEntity.getFileId();
  223. if(compressionRatio > 0 ){
  224. OkHttpUtils.httpGet(maxObjUrl + "objToObj?uuid=" + fileId +"&inObj=" + fileId +
  225. "-base.obj&outObj=" + fileId + ".obj&r=" + compressionRatio);
  226. }
  227. }
  228. JSONObject jsonObject = new JSONObject();
  229. jsonObject.put("name", modelUploadEntity.getFileId());
  230. jsonObject.put("taskId", String.valueOf(modelUploadEntity.getUserId()));
  231. jsonObject.put("data", json);
  232. log.info("保存数据,准备修改obj文件数据-{}", jsonObject.toJSONString());
  233. String result = OkHttpUtils.httpPostJson(modelBuildUrl + "fixmodel", jsonObject.toJSONString());
  234. log.info(modelBuildUrl + "fixmodel:" + result);
  235. return Result.success();
  236. }
  237. /**
  238. * 修改模型文件
  239. * @return
  240. */
  241. @ApiOperation("修改模型文件")
  242. @RequestMapping(value = "/changeModel", method = RequestMethod.POST)
  243. @ApiImplicitParams({
  244. @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
  245. public Result changeModel(HttpServletRequest request) throws Exception{
  246. String modelId = request.getParameter("modelId");
  247. String objPath = "";
  248. if (StringUtil.isEmpty(modelId)){
  249. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  250. }
  251. ModelUploadEntity modelUploadEntity = modelUploadService.findById(Long.parseLong(modelId));
  252. if(modelUploadEntity == null){
  253. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  254. }
  255. modelUploadEntity.setStatus(0);
  256. modelUploadService.update(modelUploadEntity);
  257. String path = buildPath + "upload";
  258. File targetFile = new File(path);
  259. if (!targetFile.exists()){
  260. targetFile.mkdirs();
  261. }
  262. String filePath = path + File.separator + modelUploadEntity.getFileId() + File.separator;
  263. List<String> allList = new ArrayList<>();
  264. FileUtils.readfilePath(filePath, allList);
  265. for (String fbxPath : allList) {
  266. if(fbxPath.endsWith(".fbx")){
  267. String filePth = fbxPath.substring(0, fbxPath.lastIndexOf("/") + 1);
  268. String fbxName = fbxPath.replace(filePth, "");
  269. // CreateObjUtil.fbxToObj(filePth, fbxName, fbxName.replace(".fbx", ".obj"));
  270. OkHttpUtils.httpGet(maxObjUrl + "fbxToObjNoImg?uuid=" + modelUploadEntity.getFileId() +"&fbx=" + fbxName +
  271. "&obj=mesh.obj&r=30");
  272. objPath = filePth + "mesh.obj";
  273. }
  274. if(fbxPath.endsWith(".udatasmith")){
  275. }
  276. }
  277. if(!new File(objPath).exists()){
  278. modelUploadEntity.setStatus(-1);
  279. modelUploadService.update(modelUploadEntity);
  280. log.error("转换obj数据失败-{}", modelUploadEntity.getFileId());
  281. return Result.failure(CodeConstant.FAILURE_CODE_4006, CodeConstant.FAILURE_MSG_4006);
  282. }
  283. modelUploadEntity.setStatus(1);
  284. modelUploadEntity.setObjPath(objPath.replace(buildPath, ""));
  285. modelUploadService.update(modelUploadEntity);
  286. return Result.success(modelUploadEntity);
  287. }
  288. /**
  289. * 获取模型列表
  290. * @return
  291. */
  292. @ApiOperation("获取模型列表")
  293. @RequestMapping(value = "/findModelList", method = RequestMethod.POST)
  294. @ApiImplicitParams({
  295. @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
  296. @ApiImplicitParam(name = "userName", value = "userName", dataType = "String"),
  297. @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
  298. @ApiImplicitParam(name = "pageSize", value = "页数", dataType = "String"),
  299. @ApiImplicitParam(name = "name", value = "模型名称", dataType = "String")})
  300. public Result<PageInfo<ResponseRenovationPartsDetailManager>> findModelList(@RequestBody RequestRenovationParts param){
  301. if (param.getUserId() == null){
  302. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  303. }
  304. if("88888888888".equals(param.getUserName())){
  305. param.setUserId(null);
  306. }
  307. if(StringUtil.isEmpty(param.getName())){
  308. param.setName(null);
  309. }
  310. PageInfo<RenovationPartsDetailEntity> list = renovationPartsDetailService.findAllByUserId(param.getUserId(),
  311. param.getName(), param.getPageNum(), param.getPageSize());
  312. List<ResponseRenovationPartsDetailManager> resultList = new ArrayList<>();
  313. ResponseRenovationPartsDetailManager responseRenovationPartsDetailManager = null;
  314. for(RenovationPartsDetailEntity renovationPartsDetailEntity : list.getList()){
  315. responseRenovationPartsDetailManager = new ResponseRenovationPartsDetailManager();
  316. BeanUtils.copyProperties(renovationPartsDetailEntity, responseRenovationPartsDetailManager);
  317. RenovationPartsTypeEntity renovationPartsTypeEntity = renovationPartsTypeService.findById(renovationPartsDetailEntity.getPartsTypeId());
  318. if(renovationPartsTypeEntity != null){
  319. RenovationPartsEntity renovationPartsEntity = renovationPartsService.findById(renovationPartsTypeEntity.getPartsId());
  320. if(renovationPartsEntity != null){
  321. responseRenovationPartsDetailManager.setTypeName(renovationPartsEntity.getDescription() + " > " + renovationPartsTypeEntity.getDescription());
  322. }
  323. }
  324. RenovationPartsColorEntity renovationPartsColorEntity = renovationPartsColorService.findById(renovationPartsDetailEntity.getPartsColorId());
  325. if(renovationPartsColorEntity != null){
  326. responseRenovationPartsDetailManager.setColorName(renovationPartsColorEntity.getColorName());
  327. }
  328. ResponseRenovationPartsAttaching responseRenovationPartsAttaching = renovationPartsAttachingService.findAttachinByDetailId(renovationPartsDetailEntity.getId());
  329. if(responseRenovationPartsAttaching != null){
  330. if(responseRenovationPartsAttaching.isWallAttaching()){
  331. responseRenovationPartsDetailManager.setAttachingType("wall");
  332. }
  333. if(responseRenovationPartsAttaching.isCeilAttaching()){
  334. responseRenovationPartsDetailManager.setAttachingType("ceil");
  335. }
  336. if(responseRenovationPartsAttaching.isFloorAttaching()){
  337. responseRenovationPartsDetailManager.setAttachingType("floor");
  338. }
  339. }
  340. if(renovationPartsDetailEntity.getPartsClassifyId() != null){
  341. RenovationPartsClassifyEntity renovationPartsClassifyEntity = renovationPartsClassifyService.findById(renovationPartsDetailEntity.getPartsClassifyId());
  342. if(renovationPartsClassifyEntity != null){
  343. responseRenovationPartsDetailManager.setPartsClassifyName(renovationPartsClassifyEntity.getClassifyName());
  344. }
  345. }
  346. if(renovationPartsDetailEntity.getPartsStyleId() != null){
  347. RenovationPartsStyleEntity renovationPartsStyleEntity = renovationPartsStyleService.findById(renovationPartsDetailEntity.getPartsStyleId());
  348. if(renovationPartsStyleEntity != null){
  349. responseRenovationPartsDetailManager.setPartsStyleName(renovationPartsStyleEntity.getStyleName());
  350. }
  351. }
  352. if(renovationPartsDetailEntity.getPartsShapeId() != null){
  353. RenovationPartsShapeEntity renovationPartsShapeEntity = renovationPartsShapeService.findById(renovationPartsDetailEntity.getPartsShapeId());
  354. if(renovationPartsShapeEntity != null){
  355. responseRenovationPartsDetailManager.setPartsShapeName(renovationPartsShapeEntity.getShapeName());
  356. }
  357. }
  358. if(renovationPartsDetailEntity.getPartsBrandId() == null){
  359. renovationPartsDetailEntity.setPartsBrandId(1L);
  360. }
  361. RenovationPartsBrandEntity renovationPartsBrandEntity = renovationPartsBrandService.findById(renovationPartsDetailEntity.getPartsBrandId());
  362. responseRenovationPartsDetailManager.setBrandName(renovationPartsBrandEntity.getBrandName());
  363. responseRenovationPartsDetailManager.setPartsBrandId(renovationPartsBrandEntity.getId());
  364. if(renovationPartsDetailEntity.getCompanyId() != null){
  365. CompanyEntity companyEntity = companyService.findById(renovationPartsDetailEntity.getCompanyId());
  366. if(companyEntity != null){
  367. responseRenovationPartsDetailManager.setCompanyName(companyEntity.getCompanyName());
  368. }
  369. }
  370. resultList.add(responseRenovationPartsDetailManager);
  371. }
  372. Page<ResponseRenovationPartsDetailManager> a = new Page<>(param.getPageNum(), param.getPageSize());
  373. a.setTotal(list.getTotal());
  374. PageInfo<ResponseRenovationPartsDetailManager> result = a.toPageInfo();
  375. result.setList(resultList);
  376. return Result.success(result);
  377. }
  378. /**
  379. * 修改模型详情(编辑,是否显示,删除)
  380. * @return
  381. */
  382. @ApiOperation("修改模型详情(编辑,是否显示,删除)")
  383. @RequestMapping(value = "/updateModelDetail", method = RequestMethod.POST)
  384. @ApiImplicitParams({
  385. @ApiImplicitParam(name = "RequestRenovationPartsDetailManager", value = "json对象里面的参数", dataType = "String")})
  386. public Result updateModelDetail(@RequestBody RequestRenovationPartsDetailManager param){
  387. if(param.getId() == null){
  388. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  389. }
  390. if (StringUtils.isBlank(param.getZhName())) {
  391. return Result.failure(1, "模型名称不能为空");
  392. }
  393. RenovationPartsDetailEntity renovationPartsDetailEntity = new RenovationPartsDetailEntity();
  394. BeanUtils.copyProperties(param, renovationPartsDetailEntity);
  395. renovationPartsDetailEntity.setExamine(null);
  396. renovationPartsDetailService.update(renovationPartsDetailEntity);
  397. if("I".equals(renovationPartsDetailEntity.getRecStatus())){
  398. ModelUploadEntity modelUploadEntity = modelUploadService.findByPartsDetailId(renovationPartsDetailEntity.getId());
  399. if(modelUploadEntity != null){
  400. modelUploadEntity.setRecStatus("I");
  401. modelUploadService.update(modelUploadEntity);
  402. }
  403. }
  404. RenovationPartsAttachingEntity renovationPartsAttachingEntity = renovationPartsAttachingService.findByDetailId(renovationPartsDetailEntity.getId());
  405. if(renovationPartsAttachingEntity != null){
  406. if("wall".equals(param.getAttachingType())){
  407. renovationPartsAttachingEntity.setCeilAttaching(false);
  408. renovationPartsAttachingEntity.setWallAttaching(true);
  409. renovationPartsAttachingEntity.setFloorAttaching(false);
  410. }
  411. if("ceil".equals(param.getAttachingType())){
  412. renovationPartsAttachingEntity.setCeilAttaching(true);
  413. renovationPartsAttachingEntity.setWallAttaching(false);
  414. renovationPartsAttachingEntity.setFloorAttaching(false);
  415. }
  416. if("floor".equals(param.getAttachingType())){
  417. renovationPartsAttachingEntity.setCeilAttaching(false);
  418. renovationPartsAttachingEntity.setWallAttaching(false);
  419. renovationPartsAttachingEntity.setFloorAttaching(true);
  420. }
  421. renovationPartsAttachingService.update(renovationPartsAttachingEntity);
  422. }
  423. if(param.getX() != null && param.getY() != null && param.getZ() != null){
  424. ResponseRenovationPartsSize responseRenovationPartsSize = renovationPartsSizeService.findSizeByDetailId(renovationPartsDetailEntity.getId());
  425. RenovationPartsSizeEntity renovationPartsSizeEntity = new RenovationPartsSizeEntity();
  426. renovationPartsSizeEntity.setX(param.getX());
  427. renovationPartsSizeEntity.setY(param.getY());
  428. renovationPartsSizeEntity.setZ(param.getZ());
  429. if(responseRenovationPartsSize != null){
  430. renovationPartsSizeEntity.setId(responseRenovationPartsSize.getId());
  431. renovationPartsSizeService.update(renovationPartsSizeEntity);
  432. }else {
  433. renovationPartsSizeEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
  434. renovationPartsSizeService.save(renovationPartsSizeEntity);
  435. }
  436. }
  437. return Result.success();
  438. }
  439. /**
  440. * 新增模型数据
  441. * @return
  442. */
  443. @ApiOperation("新增模型数据")
  444. @RequestMapping(value = "/addModelDetail", method = RequestMethod.POST)
  445. @ApiImplicitParams({
  446. @ApiImplicitParam(name = "RequestRenovationPartsDetailManager", value = "json对象里面的参数", dataType = "String")})
  447. public Result addModelDetail(@RequestBody RequestRenovationPartsDetailManager param) throws Exception{
  448. if(param.getModelUploadId() == null){
  449. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  450. }
  451. ModelUploadEntity modelUploadEntity = modelUploadService.findById(param.getModelUploadId());
  452. if(modelUploadEntity == null){
  453. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  454. }
  455. //先执行python脚本,处理obj文件
  456. CreateObjUtil.objHandle(buildPath + modelUploadEntity.getObjPath());
  457. //obj转换成glb格式
  458. String glbPath = buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".glb";
  459. log.info("obj转换成glb格式路径-{}", glbPath);
  460. CreateObjUtil.objToGlb(buildPath + modelUploadEntity.getObjPath(), glbPath);
  461. modelUploadEntity.setObjSize((int) new File(buildPath + modelUploadEntity.getObjPath()).length());
  462. modelUploadService.update(modelUploadEntity);
  463. //上传obj、mtl、jpg和glb
  464. String str = FileUtils.readFile(buildPath + "upload/" + modelUploadEntity.getFileId() + "/uploadList.txt");
  465. JSONArray jsonArray = JSON.parseArray(str);
  466. for(int i = 0; i < jsonArray.size(); i ++){
  467. if(jsonArray.getString(i).endsWith(".obj")){
  468. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i).replace("-base.obj", ".obj"),
  469. "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i).replace("-base.obj", ".obj"));
  470. }else {
  471. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i),
  472. "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i));
  473. }
  474. }
  475. // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".obj", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".obj");
  476. // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/mesh.mtl", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/mesh.mtl");
  477. // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".jpg", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".jpg");
  478. uploadToOssUtil.uploadTo4dTjw(glbPath, "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + ".glb");
  479. //保存模型详情
  480. RenovationPartsDetailEntity renovationPartsDetailEntity = new RenovationPartsDetailEntity();
  481. BeanUtils.copyProperties(param, renovationPartsDetailEntity);
  482. renovationPartsDetailEntity.setExamine(0);
  483. renovationPartsDetailEntity.setName(modelUploadEntity.getFileId());
  484. renovationPartsDetailEntity.setPath(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + ".glb");
  485. //入库前先提交模型到模型库,失败返回提示
  486. String version = SnowFlakeUUidUtils.generaUUid(null, null, null);
  487. JSONObject jsonObject = new JSONObject();
  488. JSONArray array = new JSONArray();
  489. JSONObject object = new JSONObject();
  490. object.put("Name", renovationPartsDetailEntity.getName());
  491. object.put("UserID", modelUploadEntity.getUserId());
  492. String postfix = "datasmith";
  493. if(modelUploadEntity.getFileType() == 0){
  494. postfix = "fbx";
  495. }
  496. object.put("Postfix", postfix);
  497. object.put("ObjAliPath", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId());
  498. array.add(object);
  499. jsonObject.put("version", version);
  500. log.info("更新模型库,syncmodel接口参数:" + jsonObject.toJSONString());
  501. uploadToOssUtil.uploadTo4dTjw(array.toJSONString().getBytes(), "domain/eHome/furniture/syncdata/" +
  502. version + "/SyncData.json");
  503. // 加锁,同一个模型只能请求一次3d渲染,防止同一账号在登录多个客户端下同时操作一个模型导致出问题
  504. Result result;
  505. synchronized (param.getModelUploadId()) {
  506. result = synchronizedUpdateModel(param, modelUploadEntity, jsonObject, glbPath, renovationPartsDetailEntity);
  507. }
  508. return result;
  509. }
  510. private Result synchronizedUpdateModel(RequestRenovationPartsDetailManager param,
  511. ModelUploadEntity modelUploadEntity,
  512. JSONObject jsonObject, String glbPath,
  513. RenovationPartsDetailEntity renovationPartsDetailEntity) throws Exception {
  514. if (checkReaptPost(param)) {
  515. log.info("模型已被提交,模型id-{}", param.getModelUploadId());
  516. return Result.failure(9999, "模型已被提交,模型id-" + param.getModelUploadId());
  517. }
  518. String resultData = OkHttpUtils.httpPostJson(buildUrl + "syncmodel", jsonObject.toJSONString());
  519. JSONObject resultJson = JSONObject.parseObject(resultData);
  520. if("error".equals(resultJson.getString("state"))){
  521. log.info("更新模型库,syncmodel接口失败:" + resultData);
  522. return Result.failure(CodeConstant.FAILURE_CODE_4015, CodeConstant.FAILURE_MSG_4015);
  523. }
  524. //判断缩略图是否存在,在就保存缩略图
  525. String imgPath = glbPath.replace(modelUploadEntity.getFileId() + ".glb", modelUploadEntity.getFileId() + "_preview.jpg");
  526. if(new File(imgPath).exists()){
  527. uploadToOssUtil.uploadTo4dTjw(imgPath, "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
  528. renovationPartsDetailEntity.setImg(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
  529. renovationPartsDetailEntity.setHighImg(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
  530. }
  531. //调用obj转换成toolbag文件
  532. objToToolbagUtil.convertobjTomview(modelUploadEntity.getFileId());
  533. if(new File(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".4dage").exists()){
  534. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".4dage",
  535. "domain/eHome/furniture/toolbag/" + modelUploadEntity.getFileId() + ".4dage");
  536. renovationPartsDetailEntity.setHasToolbag(1);
  537. }
  538. renovationPartsDetailService.save(renovationPartsDetailEntity);
  539. if(renovationPartsDetailEntity.getId() == null){
  540. return Result.failure(CodeConstant.FAILURE_CODE_4008, CodeConstant.FAILURE_MSG_4008);
  541. }
  542. //保存模型位置信息
  543. RenovationPartsAttachingEntity renovationPartsAttachingEntity = new RenovationPartsAttachingEntity();
  544. if("wall".equals(param.getAttachingType())){
  545. renovationPartsAttachingEntity.setCeilAttaching(false);
  546. renovationPartsAttachingEntity.setWallAttaching(true);
  547. renovationPartsAttachingEntity.setFloorAttaching(false);
  548. }
  549. if("ceil".equals(param.getAttachingType())){
  550. renovationPartsAttachingEntity.setCeilAttaching(true);
  551. renovationPartsAttachingEntity.setWallAttaching(false);
  552. renovationPartsAttachingEntity.setFloorAttaching(false);
  553. }
  554. if("floor".equals(param.getAttachingType())){
  555. renovationPartsAttachingEntity.setCeilAttaching(false);
  556. renovationPartsAttachingEntity.setWallAttaching(false);
  557. renovationPartsAttachingEntity.setFloorAttaching(true);
  558. }
  559. renovationPartsAttachingEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
  560. renovationPartsAttachingService.save(renovationPartsAttachingEntity);
  561. if(param.getX() != null && param.getY() != null && param.getZ() != null){
  562. RenovationPartsSizeEntity renovationPartsSizeEntity = new RenovationPartsSizeEntity();
  563. renovationPartsSizeEntity.setX(param.getX());
  564. renovationPartsSizeEntity.setY(param.getY());
  565. renovationPartsSizeEntity.setZ(param.getZ());
  566. renovationPartsSizeEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
  567. renovationPartsSizeService.save(renovationPartsSizeEntity);
  568. }
  569. //修改上传信息,关联模型id
  570. modelUploadEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
  571. int row = modelUploadService.update(modelUploadEntity);
  572. log.info("执行行数-{}", row);
  573. return Result.success();
  574. }
  575. private boolean checkReaptPost(RequestRenovationPartsDetailManager param) {
  576. ModelUploadEntity modelUploadEntity = modelUploadService.findById(param.getModelUploadId());
  577. if (modelUploadEntity.getPartsDetailId() != null) {
  578. return true;
  579. }
  580. return false;
  581. }
  582. /**
  583. * 获取所有企业信息
  584. * @return
  585. */
  586. @ApiOperation("获取所有企业信息")
  587. @RequestMapping(value = "/findCompanyList", method = RequestMethod.POST)
  588. public Result findCompanyList(){
  589. return Result.success(companyService.findAll());
  590. }
  591. /**
  592. * 更新模型审核状态
  593. * @return
  594. */
  595. @ApiOperation("更新模型审核状态")
  596. @RequestMapping(value = "/updatePartsDetailExamine", method = RequestMethod.POST)
  597. @ApiImplicitParams({
  598. @ApiImplicitParam(name = "id", value = "模型id", dataType = "String"),
  599. @ApiImplicitParam(name = "examine", value = "审核,0审核中,1审核通过,-1审核失败", dataType = "String")})
  600. public Result updatePartsDetailExamine(@RequestBody RequestRenovationPartsDetailManager param){
  601. if(param.getId() == null || param.getExamine() == null){
  602. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  603. }
  604. RenovationPartsDetailEntity renovationPartsDetailEntity = renovationPartsDetailService.findById(param.getId());
  605. renovationPartsDetailEntity.setId(param.getId());
  606. renovationPartsDetailEntity.setExamine(param.getExamine());
  607. renovationPartsDetailEntity.setExamineTime(new Date());
  608. if(param.getExamine().intValue() == 1){
  609. uploadToOssUtil.copyTo4dTjw(renovationPartsDetailEntity.getImg().replace(prefix, ""),
  610. renovationPartsDetailEntity.getImg().replace("/temp/", "/models/").replace(prefix, ""));
  611. uploadToOssUtil.copyTo4dTjw(renovationPartsDetailEntity.getPath().replace(prefix, ""),
  612. renovationPartsDetailEntity.getPath().replace("/temp/", "/models/").replace(prefix, ""));
  613. uploadToOssUtil.deleteTo4dTjw(renovationPartsDetailEntity.getImg().replace(prefix, ""));
  614. uploadToOssUtil.deleteTo4dTjw(renovationPartsDetailEntity.getPath().replace(prefix, ""));
  615. renovationPartsDetailEntity.setImg(renovationPartsDetailEntity.getImg().replace("/temp/", "/models/"));
  616. renovationPartsDetailEntity.setHighImg(renovationPartsDetailEntity.getHighImg().replace("/temp/", "/models/"));
  617. renovationPartsDetailEntity.setPath(renovationPartsDetailEntity.getPath().replace("/temp/", "/models/"));
  618. }
  619. renovationPartsDetailService.update(renovationPartsDetailEntity);
  620. return Result.success();
  621. }
  622. /**
  623. * 通过id查询上传模型进度
  624. * @param param
  625. * @return
  626. */
  627. @ApiOperation("通过id查询上传模型进度")
  628. @RequestMapping(value = "/findUploadModelById", method = RequestMethod.POST)
  629. @ApiImplicitParams({
  630. @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
  631. public Result findUploadModelById(@RequestBody RequestRenovationPartsDetailManager param){
  632. if(param.getId() == null){
  633. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  634. }
  635. return Result.success(modelUploadService.findById(param.getId()));
  636. }
  637. /**
  638. * 通过模型详情id查询上传模型的信息
  639. * @param param
  640. * @return
  641. */
  642. @ApiOperation("通过模型详情id查询上传模型的信息")
  643. @RequestMapping(value = "/findUploadModelByPartsDetailId", method = RequestMethod.POST)
  644. @ApiImplicitParams({
  645. @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
  646. public Result findUploadModelByPartsDetailId(@RequestBody RequestRenovationPartsDetailManager param){
  647. if(param.getId() == null){
  648. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  649. }
  650. return Result.success(modelUploadService.findByPartsDetailId(param.getId()));
  651. }
  652. /**
  653. * 根据用户id,查询所有未发布的上传模型
  654. * @param param
  655. * @return
  656. */
  657. @ApiOperation("根据用户id,查询所有未发布的上传模型")
  658. @RequestMapping(value = "/findIsNotPartsDetailId", method = RequestMethod.POST)
  659. @ApiImplicitParams({
  660. @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")})
  661. public Result findIsNotPartsDetailId(@RequestBody RequestRenovationParts param){
  662. if(param.getUserId() == null){
  663. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  664. }
  665. return Result.success(modelUploadService.findIsNotPartsDetailId(param.getUserId()));
  666. }
  667. /**
  668. * 根据上传id,删除上传模型
  669. * @param param
  670. * @return
  671. */
  672. @ApiOperation("根据上传id,删除上传模型")
  673. @RequestMapping(value = "/deleteUploadModel", method = RequestMethod.POST)
  674. @ApiImplicitParams({
  675. @ApiImplicitParam(name = "ids", value = "id的集合用逗号分割", dataType = "String")})
  676. public Result deleteUploadModel(@RequestBody RequestRenovationParts param){
  677. if(StringUtil.isEmpty(param.getIds())){
  678. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  679. }
  680. String[] idArray = param.getIds().split(",");
  681. ModelUploadEntity modelUploadEntity = new ModelUploadEntity();
  682. for (String id : idArray) {
  683. modelUploadEntity.setId(Long.valueOf(id));
  684. modelUploadEntity.setRecStatus("I");
  685. modelUploadService.update(modelUploadEntity);
  686. }
  687. return Result.success();
  688. }
  689. /**
  690. * 生成封面图
  691. * @return
  692. */
  693. @ApiOperation("生成封面图")
  694. @RequestMapping(value = "/createImg", method = RequestMethod.POST)
  695. @ApiImplicitParams({
  696. @ApiImplicitParam(name = "jsonData", value = "json数据", dataType = "String"),
  697. @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
  698. public Result createImg(Long modelId, String jsonData) throws Exception {
  699. if(StringUtils.isEmpty(jsonData) || modelId == null){
  700. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  701. }
  702. ModelUploadEntity modelUploadEntity = modelUploadService.findById(modelId);
  703. if(modelUploadEntity == null){
  704. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  705. }
  706. modelUploadEntity.setThumStatus(0);
  707. rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.LIGHT,
  708. modelUploadEntity.getFileId() + ":;" + modelUploadEntity.getUserId() + ":;" +
  709. modelUploadEntity.getId() + ":;" + jsonData + ":;modelPreview");
  710. modelUploadService.update(modelUploadEntity);
  711. return Result.success();
  712. }
  713. /**
  714. * 根据模型id查询模型详情
  715. * @return
  716. */
  717. @ApiOperation("根据模型id查询模型详情")
  718. @RequestMapping(value = "/findModelById", method = RequestMethod.POST)
  719. @ApiImplicitParams({
  720. @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
  721. public Result findModelById(Long id) throws Exception {
  722. if(id == null){
  723. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  724. }
  725. ModelUploadEntity modelUploadEntity = modelUploadService.findById(id);
  726. if(modelUploadEntity == null){
  727. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  728. }
  729. return Result.success(modelUploadEntity);
  730. }
  731. /**
  732. * 根据模型id修改模型缓存数据
  733. * @return
  734. */
  735. @ApiOperation("根据模型id修改模型缓存数据")
  736. @RequestMapping(value = "/updateModelCacheData", method = RequestMethod.POST)
  737. @ApiImplicitParams({
  738. @ApiImplicitParam(name = "cacheData", value = "缓存的json", dataType = "String"),
  739. @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
  740. public Result updateModelCacheData(Long id, String cacheData) throws Exception {
  741. if(id == null){
  742. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  743. }
  744. ModelUploadEntity modelUploadEntity = modelUploadService.findById(id);
  745. if(modelUploadEntity == null){
  746. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  747. }
  748. modelUploadEntity.setCacheData(cacheData);
  749. modelUploadService.update(modelUploadEntity);
  750. return Result.success(modelUploadEntity);
  751. }
  752. /**
  753. * 上传指定的fileId里面的obj文件
  754. * @return
  755. */
  756. @ApiOperation("上传指定的fileId里面的obj文件")
  757. @RequestMapping(value = "/uploadObj", method = RequestMethod.POST)
  758. @ApiImplicitParams({
  759. @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
  760. public Result uploadObj(@RequestBody RequestRenovationParts param){
  761. if(StringUtil.isEmpty(param.getName())){
  762. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  763. }
  764. String[] fileIdArr = param.getName().split(",");
  765. for (String fileId : fileIdArr) {
  766. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".obj",
  767. "domain/eHome/furniture/simpleObj-Mtl/" + fileId + "/" + fileId + ".obj");
  768. }
  769. return Result.success();
  770. }
  771. /**
  772. * 上传指定的fileId里面的obj文件
  773. * @return
  774. */
  775. @ApiOperation("修改glb")
  776. @RequestMapping(value = "/updateGlb", method = RequestMethod.POST)
  777. @ApiImplicitParams({
  778. @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
  779. public Result updateGlb(@RequestBody RequestRenovationParts param) throws Exception{
  780. if(StringUtil.isEmpty(param.getName())){
  781. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  782. }
  783. int compressionRatio = 3000;
  784. String[] fileIdArr = param.getName().split(",");
  785. for (String fileId : fileIdArr) {
  786. String path = buildPath + "upload/" + fileId + "/data.json";
  787. if(new File(path).exists()){
  788. JSONObject json = JSONObject.parseObject(FileUtils.readFile(path));
  789. compressionRatio = json.getIntValue("compressionRatio");
  790. }
  791. OkHttpUtils.httpGet(maxObjUrl + "objToObj?uuid=" + fileId +"&inObj=" + fileId +
  792. "-base.obj&outObj=" + fileId + ".obj&r=" + compressionRatio);
  793. String glbPath = buildPath + "upload/" + fileId + "/" + fileId + ".glb";
  794. CreateObjUtil.objToGlb(buildPath + "upload/" + fileId + "/" + fileId + ".obj", glbPath);
  795. log.info("glb生成完成:" + fileId);
  796. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".glb",
  797. "domain/eHome/furniture/models/" + fileId + ".glb");
  798. uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".glb",
  799. "domain/eHome/furniture/temp/" + fileId + ".glb");
  800. }
  801. return Result.success();
  802. }
  803. /**
  804. * obj转换成Toolbag文件
  805. * @return
  806. */
  807. @ApiOperation("obj转换成Toolbag文件")
  808. @RequestMapping(value = "/objToToolbag", method = RequestMethod.POST)
  809. @ApiImplicitParams({
  810. @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
  811. public Result objToToolbag(@RequestBody RequestRenovationParts param) throws Exception{
  812. if(StringUtil.isEmpty(param.getName())){
  813. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  814. }
  815. String[] fileIdArr = param.getName().split(",");
  816. for (String fileId : fileIdArr) {
  817. objToToolbagUtil.convertobjTomview(fileId);
  818. log.info(fileId + "转换Toolbag结束");
  819. }
  820. return Result.success();
  821. }
  822. }