ImportDataController.java 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. package com.example.demo.controller;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.alibaba.fastjson.serializer.SerializerFeature;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  9. import com.example.demo.constant.CodeConstant;
  10. import com.example.demo.entity.SceneLightEntity;
  11. import com.example.demo.entity.SceneStyleEntity;
  12. import com.example.demo.mq.TopicRabbitConfig;
  13. import com.example.demo.service.*;
  14. import com.example.demo.util.*;
  15. import com.example.demo.vo.response.ResponseRenovationBuildDetail;
  16. import com.example.demo.vo.response.ResponseRenovationPartsDetail;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiImplicitParam;
  19. import io.swagger.annotations.ApiImplicitParams;
  20. import io.swagger.annotations.ApiOperation;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.beans.factory.annotation.Value;
  25. import org.springframework.util.ResourceUtils;
  26. import org.springframework.util.StringUtils;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import java.io.File;
  30. import java.net.URLDecoder;
  31. import java.util.*;
  32. import java.util.concurrent.atomic.AtomicBoolean;
  33. /**
  34. * Created by Hb_zzZ on 2020/6/19.
  35. */
  36. @Slf4j
  37. @RestController
  38. @RequestMapping("/change")
  39. @Api(tags = "生成风格模块")
  40. public class ImportDataController extends BaseController {
  41. @Autowired
  42. private UploadToOssUtil uploadToOssUtil;
  43. @Autowired
  44. private ISceneStyleService sceneStyleService;
  45. @Autowired
  46. private ISceneLightService sceneLightService;
  47. @Autowired
  48. private IRenovationPartsDetailService partsDetailService;
  49. @Autowired
  50. private IRenovationBuildDetailService buildDetailService;
  51. @Autowired
  52. private IStatisticsService statisticsService;
  53. @Autowired
  54. RabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方
  55. @Value("${main.url}")
  56. private String mainUrl;
  57. @Value("${server.file.location}")
  58. private String buildPath;
  59. @Value("${build.url}")
  60. private String buildUrl;
  61. @Value("${upload.file.location}")
  62. private String path;
  63. /**
  64. * 导入数据生成风格场景
  65. * @param sceneNum
  66. * @param data
  67. * @param styleName
  68. * @param styleNum
  69. * @param file
  70. * @return
  71. */
  72. @ApiOperation("导入数据生成风格场景")
  73. @ApiImplicitParams({
  74. @ApiImplicitParam(name = "sceneNum", value = "场景码", dataType = "String"),
  75. @ApiImplicitParam(name = "styleName", value = "风格名称", dataType = "String"),
  76. @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String"),
  77. @ApiImplicitParam(name = "file", value = "文件流", dataType = "MultipartFile"),
  78. @ApiImplicitParam(name = "buildTye", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String"),
  79. @ApiImplicitParam(name = "decoration", value = "decoration.json", dataType = "String"),
  80. @ApiImplicitParam(name = "rooms", value = "rooms的json内容", dataType = "String"),
  81. @ApiImplicitParam(name = "data", value = "json数据", dataType = "String")})
  82. @RequestMapping(value = "/importData", method = RequestMethod.POST)
  83. public Result importData(String sceneNum, String data, String styleName, String decoration,
  84. String styleNum, @RequestParam("file") MultipartFile file,
  85. String proLight, String buildType, String rooms) throws Exception{
  86. if(StringUtils.isEmpty(sceneNum)){
  87. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  88. }
  89. String resultData = OkHttpUtils.httpGet(mainUrl + "api/scene/getInfo?num=" + sceneNum);
  90. JSONObject resultJson = JSON.parseObject(resultData);
  91. if(resultJson == null || resultJson.getInteger("code") != 0){
  92. return Result.failure(CodeConstant.FAILURE_CODE_4007, CodeConstant.FAILURE_MSG_4007);
  93. }
  94. String vrNum = styleNum;
  95. try{
  96. if(StringUtils.isEmpty(styleNum)){
  97. Integer num = sceneStyleService.findLastNum(sceneNum);
  98. if(num == null){
  99. num = 1;
  100. }else {
  101. num ++;
  102. }
  103. vrNum = "vr-" + sceneNum + "-" + String.format("%3d", num).replace(" ", "0");
  104. SceneStyleEntity sceneStyleEntity = new SceneStyleEntity();
  105. sceneStyleEntity.setNum(num.longValue());
  106. sceneStyleEntity.setSceneNum(sceneNum);
  107. sceneStyleEntity.setStyleName(styleName);
  108. sceneStyleEntity.setStyleNum(vrNum);
  109. //新生成的换装风格,未渲染
  110. sceneStyleEntity.setStatus(2);
  111. sceneStyleService.save(sceneStyleEntity);
  112. }else {
  113. LambdaQueryWrapper<SceneStyleEntity> wrapper = Wrappers.lambdaQuery();
  114. wrapper.eq(SceneStyleEntity::getStyleNum,styleNum);
  115. wrapper.orderByDesc(SceneStyleEntity::getNum);
  116. List<SceneStyleEntity> list = sceneStyleService.list(wrapper);
  117. if(list != null && list.size() > 0) {
  118. SceneStyleEntity sceneStyleEntity = list.get(0);
  119. sceneStyleEntity.setStyleName(styleName);
  120. sceneStyleService.updateById(sceneStyleEntity);
  121. }
  122. }
  123. String filePath = buildPath + "Input/" + vrNum ;
  124. String dataPath = "";
  125. String decorationPath = "";
  126. //灯光预览放在light文件夹
  127. if("light".equals(buildType)){
  128. filePath = filePath + "light/";
  129. }else if ("pano".equals(buildType)){
  130. filePath = filePath + "pano/";
  131. }
  132. else {
  133. filePath = filePath + File.separator;
  134. }
  135. //生成需要vision.txt
  136. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + sceneNum + "/vision.modeldata",
  137. "vision.modeldata", filePath);
  138. if(!new File(filePath + "vision.modeldata").exists()){
  139. log.info("vision.modeldata文件不存在");
  140. return Result.failure(CodeConstant.FAILURE_CODE_4001, CodeConstant.FAILURE_MSG_4001);
  141. }
  142. log.info("下载vision.modeldata完成,开始转换vision.txt");
  143. CreateObjUtil.convertVisionmodeldataToTxt(filePath + "vision.modeldata", filePath + "vision.txt");
  144. //计算translationAverage,和puckAverage并重新赋予值
  145. Map<String, Double> averageMap = ConvertCadKjl.getAverageValue(filePath + "vision.txt");
  146. setAverageValue(filePath + "vision.txt", averageMap.get("translationAverage"), averageMap.get("puckAverage"));
  147. FileUtils.writeFile(filePath + "proLight.json", proLight);
  148. dataPath = filePath + "objectPosition.json";
  149. decorationPath = filePath + "decoration.json";
  150. FileUtils.writeFile(dataPath, data);
  151. FileUtils.writeFile(decorationPath, decoration);
  152. File objFile = new File(filePath + "Obj" + File.separator + file.getOriginalFilename());
  153. if(!objFile.getParentFile().exists()){
  154. objFile.getParentFile().mkdirs();
  155. }
  156. file.transferTo(objFile);
  157. //数据上传oss,让计算服务器下载资源
  158. List<String> uploadList = new ArrayList<>();
  159. FileUtils.readfilePath(filePath, uploadList);
  160. for(String uploadFile : uploadList){
  161. if(StringUtils.isEmpty(buildType) || "all".equals(buildType)){
  162. uploadToOssUtil.upload(uploadFile,
  163. "data/data" + vrNum + uploadFile.replace(filePath, "/changeData/"));
  164. }
  165. }
  166. //保存每个风格码的户型数据
  167. if(!new File(filePath + "house.json").exists()){
  168. String path = ResourceUtils.getURL("classpath:").getPath();
  169. path = URLDecoder.decode(path,"utf-8");
  170. path = path + File.separator + "data/" + sceneNum;
  171. System.out.println("文件路径:" + path);
  172. FileUtils.copyFile(path + "/kjl.json", filePath + "house.json", true);
  173. uploadToOssUtil.upload(filePath + "house.json", "data/data" + vrNum + "/house.json");
  174. }
  175. //有修改房间信息就更新户型数据
  176. if(!StringUtils.isEmpty(rooms)){
  177. JSONObject kjlJson = JSONObject.parseObject(FileUtils.readFile(filePath + "house.json"));
  178. if(kjlJson != null){
  179. kjlJson.put("rooms", JSONObject.parseObject(rooms));
  180. }
  181. FileUtils.writeFile(filePath + "house.json", kjlJson.toJSONString());
  182. uploadToOssUtil.upload(filePath + "house.json", "data/data" + vrNum + "/house.json");
  183. }
  184. }catch (Exception e){
  185. e.printStackTrace();
  186. }
  187. JSONObject result = new JSONObject();
  188. result.put("num", vrNum);
  189. return Result.success(result);
  190. }
  191. /**
  192. * 保存proLight.json数据
  193. * @param styleNum
  194. * @return
  195. */
  196. @ApiOperation("保存proLight.json数据")
  197. @ApiImplicitParams({
  198. @ApiImplicitParam(name = "styleNum", value = "风格名称", dataType = "String"),
  199. @ApiImplicitParam(name = "proLight", value = "proLight.json的数据", dataType = "String"),
  200. @ApiImplicitParam(name = "buildType", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String")})
  201. @RequestMapping(value = "/saveProLightJson", method = RequestMethod.POST)
  202. public Result importData(String styleNum, String proLight, String buildType) throws Exception{
  203. if(StringUtils.isEmpty(styleNum)){
  204. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  205. }
  206. String vrNum = styleNum;
  207. try{
  208. String filePath = buildPath + "Input/" + vrNum ;
  209. //灯光预览放在light文件夹
  210. if("light".equals(buildType)){
  211. filePath = filePath + "light/";
  212. }else if ("pano".equals(buildType)){
  213. filePath = filePath + "pano/";
  214. }
  215. else {
  216. filePath = filePath + File.separator;
  217. }
  218. log.info("保存的类型是:" + buildType + ";位置在:" + filePath);
  219. FileUtils.writeFile(filePath + "proLight.json", proLight);
  220. //数据上传oss,让计算服务器下载资源
  221. uploadToOssUtil.upload(filePath + "proLight.json",
  222. "data/data" + vrNum + "/changeData/proLight.json");
  223. }catch (Exception e){
  224. e.printStackTrace();
  225. }
  226. return Result.success();
  227. }
  228. @ApiOperation("渲染场景")
  229. @ApiImplicitParams({
  230. @ApiImplicitParam(name = "sceneNum", value = "场景码", dataType = "String"),
  231. @ApiImplicitParam(name = "ratio", value = "字符串16:9", dataType = "String"),
  232. @ApiImplicitParam(name = "type", value = "分辨率,1024,2048", dataType = "String"),
  233. @ApiImplicitParam(name = "dateType", value = "day(白天),night(晚上)", dataType = "String"),
  234. @ApiImplicitParam(name = "buildType", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String"),
  235. @ApiImplicitParam(name = "isShow", value = "灯光预览是否显示在相册,0不显示,1显示", dataType = "String"),
  236. @ApiImplicitParam(name = "quality", value = "0或1", dataType = "String"),
  237. @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
  238. @RequestMapping(value = "/buildChangeScene", method = RequestMethod.POST)
  239. public Result buildChangeScene(String sceneNum, String styleNum, String type,
  240. String dateType, String buildType, String ratio,
  241. String isShow, String quality){
  242. try{
  243. if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(styleNum)){
  244. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  245. }
  246. LambdaQueryWrapper<SceneStyleEntity> wrapper = Wrappers.lambdaQuery();
  247. wrapper.eq(SceneStyleEntity::getStyleNum,styleNum);
  248. wrapper.orderByDesc(SceneStyleEntity::getNum);
  249. List<SceneStyleEntity> list = sceneStyleService.list(wrapper);
  250. SceneStyleEntity sceneStyleEntity = null;
  251. if(StringUtils.isEmpty(buildType) || "all".equals(buildType)){
  252. if(list != null && list.size() > 0){
  253. sceneStyleEntity = list.get(0);
  254. if(sceneStyleEntity.getStatus().intValue() == 0){
  255. return Result.failure(CodeConstant.FAILURE_CODE_4002, CodeConstant.FAILURE_MSG_4002);
  256. }
  257. sceneStyleEntity.setStatus(0);
  258. sceneStyleEntity.setProgress(0);
  259. sceneStyleService.updateById(sceneStyleEntity);
  260. }else {
  261. return Result.failure(CodeConstant.FAILURE_CODE_4003, CodeConstant.FAILURE_MSG_4003);
  262. }
  263. //判断是否有vr+场景吗的场景,有则上传数据,无则生成;
  264. Map<String, Object> map = new HashMap<String, Object>();
  265. map.put("type", "change");
  266. map.put("num", styleNum);
  267. map.put("oldNum", sceneNum);
  268. map.put("sceneName", sceneStyleEntity.getStyleName());
  269. map.put("resolution", type);
  270. HttpRequestorUtil.doPost(mainUrl + "api/scene/createChangeScene", map);
  271. if(StringUtils.isEmpty(type)){
  272. type = "1024";
  273. }
  274. // Variable.queue.offer(styleNum + ":;" + sceneNum + ":;" + type);
  275. if(dateType == null){
  276. dateType = "";
  277. }
  278. rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.CHANGE, styleNum + ":;" + sceneNum + ":;" + type + ":;" + dateType);
  279. }
  280. if("light".equals(buildType) || "pano".equals(buildType)){
  281. if(StringUtils.isEmpty(type)){
  282. type = "1024";
  283. }
  284. if(dateType == null){
  285. dateType = "";
  286. }
  287. if(StringUtils.isEmpty(quality)){
  288. quality = "0";
  289. }
  290. SceneLightEntity sceneLightEntity = new SceneLightEntity();
  291. if(list != null && list.size() > 0){
  292. sceneStyleEntity = list.get(0);
  293. if("light".equals(buildType)){
  294. log.info("灯光预览:" + styleNum);
  295. if(sceneStyleEntity.getLightStatus().intValue() == 0){
  296. return Result.failure(CodeConstant.FAILURE_CODE_4004, CodeConstant.FAILURE_MSG_4004);
  297. }
  298. sceneStyleEntity.setLightStatus(0);
  299. }
  300. if("pano".equals(buildType)){
  301. log.info("全景预览:" + styleNum);
  302. if(sceneStyleEntity.getLightStatus().intValue() == 0){
  303. return Result.failure(CodeConstant.FAILURE_CODE_4016, CodeConstant.FAILURE_MSG_4016);
  304. }
  305. sceneStyleEntity.setPanoStatus(0);
  306. }
  307. sceneStyleService.updateById(sceneStyleEntity);
  308. sceneLightEntity.setStatus(0);
  309. sceneLightEntity.setProgress(0);
  310. if(StringUtils.isEmpty(isShow)){
  311. isShow = "1";
  312. }
  313. sceneLightEntity.setIsShow(Integer.valueOf(isShow));
  314. sceneLightEntity.setSceneStyleId(sceneStyleEntity.getId());
  315. sceneLightEntity.setPixel(type);
  316. //数据上传oss,让计算服务器下载资源
  317. String filePath = buildPath + "Input/" + styleNum;
  318. if("light".equals(buildType)){
  319. sceneLightEntity.setType(1);
  320. filePath = filePath + "light/";
  321. }
  322. if("pano".equals(buildType)){
  323. sceneLightEntity.setType(2);
  324. filePath = filePath + "pano/";
  325. }
  326. sceneLightEntity.setQuality(quality);
  327. sceneLightService.save(sceneLightEntity);
  328. List<String> uploadList = new ArrayList<>();
  329. FileUtils.readfilePath(filePath, uploadList);
  330. for(String uploadFile : uploadList){
  331. uploadToOssUtil.upload(uploadFile,
  332. "data/data" + styleNum + uploadFile.replace(
  333. filePath, "/proLightData/" + sceneLightEntity.getId().longValue() + "/"));
  334. }
  335. }else {
  336. return Result.failure(CodeConstant.FAILURE_CODE_4003, CodeConstant.FAILURE_MSG_4003);
  337. }
  338. rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.LIGHT,
  339. styleNum + ":;" + sceneNum + ":;" + type + ":;" + dateType + ":;" +
  340. ratio + ":;" + sceneLightEntity.getId().longValue() + ":;" +
  341. quality + ":;" + buildType);
  342. }
  343. FileUtils.deleteDirectory(buildPath + "Output/" + styleNum);
  344. }catch (Exception e){
  345. e.printStackTrace();
  346. }
  347. JSONObject result = new JSONObject();
  348. result.put("num", styleNum);
  349. result.put("url", mainUrl + "spc.html?t=" + styleNum);
  350. return Result.success(result);
  351. }
  352. /**
  353. * 测试运行命令
  354. * @return
  355. */
  356. @ApiOperation("测试运行命令")
  357. @ApiImplicitParams({
  358. @ApiImplicitParam(name = "fbxPath", value = "fbx文件路径", dataType = "String"),
  359. @ApiImplicitParam(name = "objPath", value = "obj文件路径", dataType = "String")})
  360. @RequestMapping(value = "/fbxToObj", method = RequestMethod.POST)
  361. public String fbxToObj(String fbxPath, String objPath) throws Exception{
  362. // String command = "D:/OneKeyDecorate/StartDecorate.exe -s " + vrNum;
  363. // log.info("开始建模:" + command);
  364. // RunCmdUtil.callshell(command);
  365. // log.info("计算完毕:" + command);
  366. String filePth = fbxPath.substring(0, fbxPath.lastIndexOf(File.pathSeparator) + 1);
  367. String fbxName = fbxPath.substring(fbxPath.lastIndexOf(File.pathSeparator) + 1);
  368. CreateObjUtil.fbxToObj(filePth, fbxName, objPath);
  369. return "运行完成";
  370. }
  371. /**
  372. * 生成房型数据
  373. * @param num
  374. * @return
  375. */
  376. @ApiOperation("生成房型数据")
  377. @ApiImplicitParams({
  378. @ApiImplicitParam(name = "num", value = "四维看看场景码", dataType = "String"),
  379. @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
  380. @RequestMapping(value = "/createJson", method = RequestMethod.GET)
  381. public String createJson(String num, String styleNum){
  382. try{
  383. if(StringUtils.isEmpty(num)){
  384. return "参数不能为空";
  385. }
  386. String resultData = OkHttpUtils.httpGet(mainUrl + "api/scene/getInfo?num=" + num);
  387. JSONObject getInfoJson = JSON.parseObject(resultData);
  388. //初始画面
  389. String entry = null;
  390. if(getInfoJson != null || getInfoJson.getInteger("code") == 0){
  391. entry = getInfoJson.getJSONObject("data").getString("entry");
  392. }
  393. String basePath = URLDecoder.decode(path,"utf-8");
  394. basePath = basePath + File.separator + "data/" + num;
  395. System.out.println("文件路径:" + basePath);
  396. if(!new File(basePath).exists()){
  397. new File(basePath).mkdirs();
  398. }
  399. JSONObject entryJson = new JSONObject();
  400. if(StrUtil.isEmpty(entry)){
  401. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + num + "/vision.modeldata?t=" + System.currentTimeMillis(),
  402. "vision.modeldata", basePath);
  403. if(!new File(basePath + "/vision.modeldata").exists()){
  404. log.info("vision.modeldata文件不存在");
  405. }else {
  406. log.info("下载vision.modeldata完成,开始转换vision.txt");
  407. CreateObjUtil.convertVisionmodeldataToTxt(basePath + "/vision.modeldata", basePath + "/vision.txt");
  408. JSONObject visionJson = JSON.parseObject(FileUtils.readFile(basePath + "/vision.txt"));
  409. JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
  410. if(sweepArray != null && sweepArray.size() > 0){
  411. entryJson.put("noSetting", sweepArray.getJSONObject(0));
  412. }
  413. }
  414. }else {
  415. entryJson.put("setting", JSON.parseObject(entry));
  416. }
  417. //下载原场景的scene.json
  418. if(!StringUtils.isEmpty(num)){
  419. FileUtils.downLoadFromUrl(mainUrl + "scene/data/data" + num + "/scene.json?t=" + System.currentTimeMillis(),
  420. "scene.json", basePath);
  421. }
  422. //原场景码的户型版本号
  423. int floorPublishVer = 0;
  424. String sceneStr = FileUtils.readFile(basePath + "/scene.json");
  425. JSONObject sceneJson = null;
  426. if(sceneStr != null){
  427. sceneJson = JSONObject.parseObject(sceneStr);
  428. if(sceneJson.containsKey("floorPublishVer")){
  429. floorPublishVer = sceneJson.getIntValue("floorPublishVer");
  430. }
  431. }
  432. //下载风格码保存过的house.json
  433. if(!StringUtils.isEmpty(styleNum)){
  434. String filePath = buildPath + "Input/" + styleNum +File.separator;
  435. if(!new File(filePath).exists()){
  436. new File(filePath).mkdirs();
  437. }
  438. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + styleNum + "/house.json?t=" + System.currentTimeMillis(),
  439. "house.json", filePath);
  440. //oss上的户型数据
  441. String houseStr = FileUtils.readFile(filePath + "/house.json");
  442. int version = 0;
  443. if(houseStr != null){
  444. JSONObject houseJson = JSONObject.parseObject(houseStr);
  445. if(houseJson.containsKey("version")){
  446. version = houseJson.getIntValue("version");
  447. }
  448. houseJson.put("version", version);
  449. houseJson.put("floorPublishVer", floorPublishVer);
  450. houseJson.put("entry", entryJson);
  451. return houseJson.toJSONString();
  452. }
  453. }
  454. Map<String, Double> map = null;
  455. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
  456. "floor.json", basePath);
  457. ConvertCadKjl cad = new ConvertCadKjl();
  458. String data = FileUtils.readFile(basePath + File.separator + "floor.json");
  459. JSONObject inputJson = null;
  460. JSONArray inputArray = null;
  461. JSONObject resultJson = new JSONObject();
  462. JSONArray resultArray = new JSONArray();
  463. if(StrUtil.isNotEmpty(data)){
  464. inputJson = JSON.parseObject(data);
  465. if(inputJson.containsKey("floors")) {
  466. inputArray = inputJson.getJSONArray("floors");
  467. for (int i = 0, len = inputArray.size(); i < len; i++) {
  468. cad = new ConvertCadKjl();
  469. cad.init(inputArray.getJSONObject(i));
  470. cad.input = cad.preHandle(cad.input);
  471. JSONArray beams = cad.getBeams();
  472. JSONArray walls = cad.getWalls();
  473. //判断是否需要重复出去墙
  474. AtomicBoolean removeAgain = new AtomicBoolean(false);
  475. //去除重复的墙
  476. walls = cad.removeRepeat(walls);
  477. JSONArray rooms = cad.getRooms();
  478. JSONArray flues = cad.getFlues();
  479. JSONArray holes = cad.getHoles();
  480. cad.output.put("holes", holes);
  481. cad.output.put("flues", flues);
  482. cad.output.put("beams", beams);
  483. cad.output.put("rooms", rooms);
  484. cad.output.put("walls", walls);
  485. map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
  486. if(map != null){
  487. JSONObject scene = new JSONObject();
  488. scene.put("bottom", map.get("translationAverage"));
  489. scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
  490. cad.output.put("scene", scene);
  491. }
  492. cad.output.put("version", floorPublishVer);
  493. resultArray.add(cad.output);
  494. }
  495. resultJson.put("floors", resultArray);
  496. }else {
  497. cad.init(inputJson);
  498. cad.input = cad.preHandle(cad.input);
  499. JSONArray beams = cad.getBeams();
  500. JSONArray walls = cad.getWalls();
  501. //判断是否需要重复出去墙
  502. AtomicBoolean removeAgain = new AtomicBoolean(false);
  503. //去除重复的墙
  504. walls = cad.removeRepeat(walls);
  505. JSONArray rooms = cad.getRooms();
  506. JSONArray flues = cad.getFlues();
  507. JSONArray holes = cad.getHoles();
  508. cad.output.put("holes", holes);
  509. cad.output.put("flues", flues);
  510. cad.output.put("beams", beams);
  511. cad.output.put("rooms", rooms);
  512. cad.output.put("walls", walls);
  513. map = ConvertCadKjl.getMaxOrMinValue(inputJson);
  514. if(map != null){
  515. JSONObject scene = new JSONObject();
  516. scene.put("bottom", map.get("translationAverage"));
  517. scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
  518. cad.output.put("scene", scene);
  519. }
  520. cad.output.put("version", floorPublishVer);
  521. resultJson = cad.output;
  522. }
  523. cad.init(inputJson);
  524. }
  525. resultJson.put("entry", entryJson);
  526. cad.writeBinary(resultJson.toString().getBytes(), basePath + File.separator + "kjl.json");
  527. return resultJson.toString();
  528. }catch (Exception e){
  529. e.printStackTrace();
  530. return "生成json数据失败";
  531. }
  532. }
  533. /**
  534. * 修改房型数据
  535. * @param num
  536. * @return
  537. */
  538. @ApiOperation("修改房型数据")
  539. @ApiImplicitParams({
  540. @ApiImplicitParam(name = "num", value = "四维看看场景码", dataType = "String"),
  541. @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
  542. @RequestMapping(value = "/updateJson", method = RequestMethod.GET)
  543. public String updateJson(String num, String styleNum){
  544. try{
  545. if(StringUtils.isEmpty(num) || StringUtils.isEmpty(styleNum)){
  546. return "参数不能为空";
  547. }
  548. String path = ResourceUtils.getURL("classpath:").getPath();
  549. path = URLDecoder.decode(path,"utf-8");
  550. path = path + File.separator + "data/" + num;
  551. System.out.println("文件路径:" + path);
  552. if(!new File(path).exists()){
  553. new File(path).mkdirs();
  554. }
  555. //下载原场景的scene.json
  556. if(!StringUtils.isEmpty(num)){
  557. FileUtils.downLoadFromUrl(mainUrl + "data/data" + num + "/scene.json?t=" + System.currentTimeMillis(),
  558. "scene.json", path);
  559. }
  560. //原场景码的户型版本号
  561. int floorPublishVer = 0;
  562. String sceneStr = FileUtils.readFile(path + "/scene.json");
  563. JSONObject sceneJson = null;
  564. if(sceneStr != null){
  565. sceneJson = JSONObject.parseObject(sceneStr);
  566. if(sceneJson.containsKey("floorPublishVer")){
  567. floorPublishVer = sceneJson.getIntValue("floorPublishVer");
  568. }
  569. }
  570. Map<String, Double> map = null;
  571. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + num + "/vision.modeldata?t=" + System.currentTimeMillis(),
  572. "vision.modeldata", path);
  573. if(!new File(path + "/vision.modeldata").exists()){
  574. log.info("vision.modeldata文件不存在");
  575. }else {
  576. log.info("下载vision.modeldata完成,开始转换vision.txt");
  577. CreateObjUtil.convertVisionmodeldataToTxt(path + "/vision.modeldata", path + "/vision.txt");
  578. }
  579. FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
  580. "floor.json", path);
  581. ConvertCadKjl cad = new ConvertCadKjl();
  582. String data = FileUtils.readFile(path + File.separator + "floor.json");
  583. JSONObject inputJson = null;
  584. JSONArray inputArray = null;
  585. JSONObject resultJson = new JSONObject();
  586. JSONArray resultArray = new JSONArray();
  587. if(StrUtil.isNotEmpty(data)){
  588. inputJson = JSON.parseObject(data);
  589. if(inputJson.containsKey("floors")) {
  590. inputArray = inputJson.getJSONArray("floors");
  591. for (int i = 0, len = inputArray.size(); i < len; i++) {
  592. cad = new ConvertCadKjl();
  593. cad.init(inputArray.getJSONObject(i));
  594. cad.input = cad.preHandle(cad.input);
  595. JSONArray beams = cad.getBeams();
  596. JSONArray walls = cad.getWalls();
  597. //判断是否需要重复出去墙
  598. AtomicBoolean removeAgain = new AtomicBoolean(false);
  599. //去除重复的墙
  600. walls = cad.removeRepeat(walls);
  601. JSONArray rooms = cad.getRooms();
  602. JSONArray flues = cad.getFlues();
  603. JSONArray holes = cad.getHoles();
  604. cad.output.put("holes", holes);
  605. cad.output.put("flues", flues);
  606. cad.output.put("beams", beams);
  607. cad.output.put("rooms", rooms);
  608. cad.output.put("walls", walls);
  609. map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
  610. if(map != null){
  611. JSONObject scene = new JSONObject();
  612. scene.put("bottom", map.get("translationAverage"));
  613. scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
  614. cad.output.put("scene", scene);
  615. }
  616. cad.output.put("version", floorPublishVer);
  617. resultArray.add(cad.output);
  618. }
  619. resultJson.put("floors", resultArray);
  620. }else {
  621. cad.init(inputJson);
  622. cad.input = cad.preHandle(cad.input);
  623. JSONArray beams = cad.getBeams();
  624. JSONArray walls = cad.getWalls();
  625. //判断是否需要重复出去墙
  626. AtomicBoolean removeAgain = new AtomicBoolean(false);
  627. //去除重复的墙
  628. walls = cad.removeRepeat(walls);
  629. JSONArray rooms = cad.getRooms();
  630. JSONArray flues = cad.getFlues();
  631. JSONArray holes = cad.getHoles();
  632. cad.output.put("holes", holes);
  633. cad.output.put("flues", flues);
  634. cad.output.put("beams", beams);
  635. cad.output.put("rooms", rooms);
  636. cad.output.put("walls", walls);
  637. map = ConvertCadKjl.getMaxOrMinValue(inputJson);
  638. if(map != null){
  639. JSONObject scene = new JSONObject();
  640. scene.put("bottom", map.get("translationAverage"));
  641. scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
  642. cad.output.put("scene", scene);
  643. }
  644. cad.output.put("version", floorPublishVer);
  645. resultJson = cad.output;
  646. }
  647. }
  648. cad.writeBinary(resultJson.toString().getBytes(), path + File.separator + "kjl.json");
  649. uploadToOssUtil.upload(path + File.separator + "kjl.json", "data/data" + styleNum + "/house.json");
  650. return resultJson.toString();
  651. }catch (Exception e){
  652. e.printStackTrace();
  653. return "生成json数据失败";
  654. }
  655. }
  656. public static void setAverageValue(String visionPath, Double translationAverage, Double puckAverage) throws Exception{
  657. Map<String, Double> map = new HashMap<>();
  658. JSONObject visionJson = JSONObject.parseObject(FileUtils.readFile(visionPath));
  659. JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
  660. for(int i = 0, len = sweepLocations.size(); i < len; i++){
  661. sweepLocations.getJSONObject(i).getJSONObject("pose").
  662. getJSONObject("translation").put("z", translationAverage);
  663. sweepLocations.getJSONObject(i).getJSONObject("puck").put("z", puckAverage);
  664. }
  665. visionJson.put("sweepLocations", sweepLocations);
  666. FileUtils.writeFile(visionPath, visionJson.toString());
  667. }
  668. /**
  669. * 更新所有decoration.json数据
  670. * @return
  671. */
  672. @ApiOperation("更新所有decoration.json数据")
  673. @RequestMapping(value = "/updateDecorationJson", method = RequestMethod.GET)
  674. public Result updateDecorationJson() throws Exception{
  675. List<SceneStyleEntity> list = sceneStyleService.list();
  676. String path = "";
  677. String lightPath = "";
  678. String data = "";
  679. File file = null;
  680. File lightFile = null;
  681. JSONObject object = null;
  682. JSONObject lightObject = null;
  683. JSONArray furniture = null;
  684. JSONArray walls = null;
  685. JSONArray rooms = null;
  686. JSONArray lights = null;
  687. JSONArray windows = null;
  688. JSONArray doors = null;
  689. JSONObject assets = null;
  690. JSONArray materials = null;
  691. JSONObject wallpaper = null;
  692. JSONObject floor = null;
  693. JSONObject texture = null;
  694. String wallpaperStr = "";
  695. String textureStr = "";
  696. ResponseRenovationPartsDetail detail = null;
  697. ResponseRenovationBuildDetail buildDetail = null;
  698. for (SceneStyleEntity sceneStyleEntity : list) {
  699. path = buildPath + "Input/" + sceneStyleEntity.getStyleNum() + File.separator + "decoration.json";
  700. lightPath = buildPath + "Input/" + sceneStyleEntity.getStyleNum() + "light/decoration.json";
  701. file = new File(path);
  702. lightFile = new File(lightPath);
  703. if(file.exists()){
  704. data = FileUtils.readFile(path);
  705. if(data.startsWith("{") && data.endsWith("}")){
  706. object = JSON.parseObject(data);
  707. if(object != null){
  708. furniture = object.getJSONArray("furniture");
  709. walls = object.getJSONArray("walls");
  710. rooms = object.getJSONArray("rooms");
  711. lights = object.getJSONArray("lights");
  712. windows = object.getJSONArray("windows");
  713. doors = object.getJSONArray("doors");
  714. if(furniture != null){
  715. for(int i = 0, len = furniture.size(); i < len; i++){
  716. if(furniture.getJSONObject(i).containsKey("assets")){
  717. assets = furniture.getJSONObject(i).getJSONObject("assets");
  718. if(assets.containsKey("name")){
  719. detail = partsDetailService.findByName(assets.getString("name"));
  720. if(detail != null){
  721. assets.put("previewUrl", detail.getImg());
  722. assets.put("url", detail.getHighImg());
  723. assets.put("path", detail.getPath());
  724. }
  725. }
  726. }
  727. }
  728. }
  729. if(walls != null){
  730. for(int i = 0, len = walls.size(); i < len; i++){
  731. if(walls.getJSONObject(i).containsKey("materials")){
  732. materials = walls.getJSONObject(i).getJSONArray("materials");
  733. for(int j = 0; j < materials.size(); j++){
  734. wallpaperStr = materials.getJSONObject(j).getString("wallpaper");
  735. wallpaper = new JSONObject();
  736. buildDetail = buildDetailService.findByName(wallpaperStr);
  737. // if(wallpaper.containsKey("name")){
  738. if(buildDetail != null){
  739. wallpaper.put("previewUrl", buildDetail.getThumbnail());
  740. wallpaper.put("url", buildDetail.getThumbnail());
  741. wallpaper.put("name", wallpaperStr);
  742. wallpaper.put("id", buildDetail.getId());
  743. // wallpaper.put("path", buildDetail.getPath());
  744. materials.getJSONObject(j).put("wallpaper", wallpaper);
  745. }
  746. // }
  747. }
  748. }
  749. }
  750. }
  751. if(rooms != null){
  752. for(int i = 0, len = rooms.size(); i < len; i++){
  753. if(rooms.getJSONObject(i).containsKey("floor")){
  754. floor = rooms.getJSONObject(i).getJSONObject("floor");
  755. textureStr = floor.getString("texture");
  756. texture = new JSONObject();
  757. buildDetail = buildDetailService.findByName(textureStr);
  758. // if(texture.containsKey("name")){
  759. if(buildDetail != null){
  760. texture.put("previewUrl", buildDetail.getThumbnail());
  761. texture.put("url", buildDetail.getThumbnail());
  762. texture.put("id", buildDetail.getId());
  763. texture.put("name", textureStr);
  764. // texture.put("path", buildDetail.getPath());
  765. floor.put("texture", texture);
  766. }
  767. // }
  768. }
  769. }
  770. }
  771. if(lights != null){
  772. for(int i = 0, len = lights.size(); i < len; i++){
  773. if(lights.getJSONObject(i).containsKey("assets")){
  774. assets = lights.getJSONObject(i).getJSONObject("assets");
  775. if(assets.containsKey("name")){
  776. detail = partsDetailService.findByName(assets.getString("name"));
  777. if(detail != null){
  778. assets.put("previewUrl", detail.getImg());
  779. assets.put("url", detail.getHighImg());
  780. assets.put("path", detail.getPath());
  781. }
  782. }
  783. }
  784. }
  785. }
  786. if(windows != null){
  787. for(int i = 0, len = windows.size(); i < len; i++){
  788. if(windows.getJSONObject(i).containsKey("assets")){
  789. assets = windows.getJSONObject(i).getJSONObject("assets");
  790. if(assets.containsKey("name")){
  791. detail = partsDetailService.findByName(assets.getString("name"));
  792. if(detail != null){
  793. assets.put("previewUrl", detail.getImg());
  794. assets.put("url", detail.getHighImg());
  795. assets.put("path", detail.getPath());
  796. }
  797. }
  798. }
  799. }
  800. }
  801. if(doors != null){
  802. for(int i = 0, len = doors.size(); i < len; i++){
  803. if(doors.getJSONObject(i).containsKey("assets")){
  804. assets = doors.getJSONObject(i).getJSONObject("assets");
  805. if(assets.containsKey("name")){
  806. detail = partsDetailService.findByName(assets.getString("name"));
  807. if(detail != null){
  808. assets.put("previewUrl", detail.getImg());
  809. assets.put("url", detail.getHighImg());
  810. assets.put("path", detail.getPath());
  811. }
  812. }
  813. }
  814. }
  815. }
  816. FileUtils.writeFile(path.replace("decoration.json", "decorationBack.json"),
  817. JSON.toJSONString(object,SerializerFeature.WriteMapNullValue));
  818. uploadToOssUtil.upload(path.replace("decoration.json", "decorationBack.json"),
  819. "data/data" + sceneStyleEntity.getStyleNum() + "/changeData/decoration.json");
  820. }
  821. }
  822. }
  823. if(lightFile.exists()){
  824. data = FileUtils.readFile(lightPath);
  825. if(data.startsWith("{") && data.endsWith("}")){
  826. object = JSON.parseObject(data);
  827. if(object != null){
  828. furniture = object.getJSONArray("furniture");
  829. walls = object.getJSONArray("walls");
  830. rooms = object.getJSONArray("rooms");
  831. lights = object.getJSONArray("lights");
  832. windows = object.getJSONArray("windows");
  833. doors = object.getJSONArray("doors");
  834. if(furniture != null){
  835. for(int i = 0, len = furniture.size(); i < len; i++){
  836. if(furniture.getJSONObject(i).containsKey("assets")){
  837. assets = furniture.getJSONObject(i).getJSONObject("assets");
  838. if(assets.containsKey("name")){
  839. detail = partsDetailService.findByName(assets.getString("name"));
  840. if(detail != null){
  841. assets.put("previewUrl", detail.getImg());
  842. assets.put("url", detail.getHighImg());
  843. assets.put("path", detail.getPath());
  844. }
  845. }
  846. }
  847. }
  848. }
  849. // if(walls != null){
  850. //
  851. // for(int i = 0, len = walls.size(); i < len; i++){
  852. // if(walls.getJSONObject(i).containsKey("materials") && walls.getJSONObject(i).containsKey("wallpaper")){
  853. //
  854. // materials = walls.getJSONObject(i).getJSONArray("materials");
  855. // for(int j = 0; j < materials.size(); j++){
  856. // wallpaper = materials.getJSONObject(j).getJSONObject("wallpaper");
  857. // if(wallpaper.containsKey("name")){
  858. // buildDetail = buildDetailService.findByName(wallpaper.getString("name"));
  859. // if(buildDetail != null){
  860. // wallpaper.put("previewUrl", buildDetail.getThumbnail());
  861. // wallpaper.put("url", buildDetail.getThumbnail());
  862. //// wallpaper.put("path", buildDetail.getPath());
  863. // }
  864. // }
  865. // }
  866. //
  867. //
  868. // }
  869. // }
  870. // }
  871. //
  872. // if(rooms != null){
  873. //
  874. // for(int i = 0, len = rooms.size(); i < len; i++){
  875. // if(rooms.getJSONObject(i).containsKey("floor") && rooms.getJSONObject(i).containsKey("texture")){
  876. //
  877. // floor = rooms.getJSONObject(i).getJSONObject("floor");
  878. // texture = floor.getJSONObject("texture");
  879. //
  880. // if(texture.containsKey("name")){
  881. // buildDetail = buildDetailService.findByName(texture.getString("name"));
  882. // if(buildDetail != null){
  883. // texture.put("previewUrl", buildDetail.getThumbnail());
  884. // texture.put("url", buildDetail.getThumbnail());
  885. //// texture.put("path", buildDetail.getPath());
  886. // }
  887. // }
  888. // }
  889. // }
  890. // }
  891. if(walls != null){
  892. for(int i = 0, len = walls.size(); i < len; i++){
  893. if(walls.getJSONObject(i).containsKey("materials")){
  894. materials = walls.getJSONObject(i).getJSONArray("materials");
  895. for(int j = 0; j < materials.size(); j++){
  896. wallpaperStr = materials.getJSONObject(j).getString("wallpaper");
  897. wallpaper = new JSONObject();
  898. buildDetail = buildDetailService.findByName(wallpaperStr);
  899. // if(wallpaper.containsKey("name")){
  900. if(buildDetail != null){
  901. wallpaper.put("previewUrl", buildDetail.getThumbnail());
  902. wallpaper.put("url", buildDetail.getThumbnail());
  903. wallpaper.put("name", wallpaperStr);
  904. wallpaper.put("id", buildDetail.getId());
  905. // wallpaper.put("path", buildDetail.getPath());
  906. materials.getJSONObject(j).put("wallpaper", wallpaper);
  907. }
  908. // }
  909. }
  910. }
  911. }
  912. }
  913. if(rooms != null){
  914. for(int i = 0, len = rooms.size(); i < len; i++){
  915. if(rooms.getJSONObject(i).containsKey("floor") ){
  916. floor = rooms.getJSONObject(i).getJSONObject("floor");
  917. textureStr = floor.getString("texture");
  918. texture = new JSONObject();
  919. buildDetail = buildDetailService.findByName(textureStr);
  920. // if(texture.containsKey("name")){
  921. if(buildDetail != null){
  922. texture.put("previewUrl", buildDetail.getThumbnail());
  923. texture.put("url", buildDetail.getThumbnail());
  924. texture.put("id", buildDetail.getId());
  925. texture.put("name", textureStr);
  926. // texture.put("path", buildDetail.getPath());
  927. floor.put("texture", texture);
  928. }
  929. // }
  930. }
  931. }
  932. }
  933. if(lights != null){
  934. for(int i = 0, len = lights.size(); i < len; i++){
  935. if(lights.getJSONObject(i).containsKey("assets")){
  936. assets = lights.getJSONObject(i).getJSONObject("assets");
  937. if(assets.containsKey("name")){
  938. detail = partsDetailService.findByName(assets.getString("name"));
  939. if(detail != null){
  940. assets.put("previewUrl", detail.getImg());
  941. assets.put("url", detail.getHighImg());
  942. assets.put("path", detail.getPath());
  943. }
  944. }
  945. }
  946. }
  947. }
  948. if(windows != null){
  949. for(int i = 0, len = windows.size(); i < len; i++){
  950. if(windows.getJSONObject(i).containsKey("assets")){
  951. assets = windows.getJSONObject(i).getJSONObject("assets");
  952. if(assets.containsKey("name")){
  953. detail = partsDetailService.findByName(assets.getString("name"));
  954. if(detail != null){
  955. assets.put("previewUrl", detail.getImg());
  956. assets.put("url", detail.getHighImg());
  957. assets.put("path", detail.getPath());
  958. }
  959. }
  960. }
  961. }
  962. }
  963. if(doors != null){
  964. for(int i = 0, len = doors.size(); i < len; i++){
  965. if(doors.getJSONObject(i).containsKey("assets")){
  966. assets = doors.getJSONObject(i).getJSONObject("assets");
  967. if(assets.containsKey("name")){
  968. detail = partsDetailService.findByName(assets.getString("name"));
  969. if(detail != null){
  970. assets.put("previewUrl", detail.getImg());
  971. assets.put("url", detail.getHighImg());
  972. assets.put("path", detail.getPath());
  973. }
  974. }
  975. }
  976. }
  977. }
  978. FileUtils.writeFile(lightPath.replace("decoration.json", "decorationBack.json"),
  979. JSON.toJSONString(object,SerializerFeature.WriteMapNullValue));
  980. uploadToOssUtil.upload(lightPath.replace("decoration.json", "decorationBack.json"),
  981. "data/data" + sceneStyleEntity.getStyleNum() + "/proLightData/decoration.json");
  982. }
  983. }
  984. }
  985. }
  986. return Result.success();
  987. }
  988. /**
  989. * 获取预设灯光信息
  990. * @return
  991. */
  992. @ApiOperation("获取预设灯光信息")
  993. @ApiImplicitParams({
  994. @ApiImplicitParam(name = "data", value = "数据(json字符串)", dataType = "String")})
  995. @RequestMapping(value = "/getLightInfo", method = RequestMethod.POST)
  996. public Result getLightInfo(String data){
  997. if(StringUtils.isEmpty(data)){
  998. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  999. }
  1000. JSONObject jsonObject = new JSONObject();
  1001. jsonObject.put("obj", data);
  1002. String result = OkHttpUtils.httpPostJson(buildUrl + "getLightInfo", jsonObject.toJSONString());
  1003. log.info("getLightInfo返回结果:" + result);
  1004. JSONObject resultJson = JSON.parseObject(result);
  1005. if(resultJson.containsKey("state") && "done".equals(resultJson.getString("state"))){
  1006. return Result.success(resultJson.getString("msg"));
  1007. }
  1008. return Result.failure(CodeConstant.FAILURE_CODE_4005, CodeConstant.FAILURE_MSG_4005);
  1009. }
  1010. /**
  1011. * 保存json数据
  1012. * @return
  1013. */
  1014. @ApiOperation("保存json数据")
  1015. @ApiImplicitParams({
  1016. @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String"),
  1017. @ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "String"),
  1018. @ApiImplicitParam(name = "jsonData", value = "数据(json字符串)", dataType = "String")})
  1019. @RequestMapping(value = "/saveJsonUploadOss", method = RequestMethod.POST)
  1020. public Result saveJsonUploadOss(String jsonData, String fileName, String styleNum) throws Exception{
  1021. if(StringUtils.isEmpty(jsonData) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(styleNum)){
  1022. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  1023. }
  1024. String filePath = buildPath + "data/data" + styleNum + File.separator + fileName;
  1025. log.info("保存文件路径-filePath{}:" + filePath);
  1026. FileUtils.writeFile(filePath, jsonData);
  1027. uploadToOssUtil.upload(filePath, "data/data" + styleNum + File.separator + fileName);
  1028. return Result.success((Object) ("data/data" + styleNum + File.separator + fileName));
  1029. }
  1030. public static void main(String[] args) {
  1031. try{
  1032. Map<String, Double> map = ConvertCadKjl.getAverageValue("G:\\javaProject\\changeing\\vision.txt");
  1033. System.out.println(map.get("translationAverage"));
  1034. System.out.println(map.get("puckAverage"));
  1035. setAverageValue("G:\\javaProject\\changeing\\vision.txt", map.get("translationAverage"), map.get("puckAverage"));
  1036. }catch (Exception e){
  1037. e.printStackTrace();
  1038. }
  1039. }
  1040. }