1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219 |
- package com.example.demo.controller;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.example.demo.constant.CodeConstant;
- import com.example.demo.entity.SceneLightEntity;
- import com.example.demo.entity.SceneStyleEntity;
- import com.example.demo.mq.TopicRabbitConfig;
- import com.example.demo.service.*;
- import com.example.demo.util.*;
- import com.example.demo.vo.response.ResponseRenovationBuildDetail;
- import com.example.demo.vo.response.ResponseRenovationPartsDetail;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.amqp.rabbit.core.RabbitTemplate;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.util.ResourceUtils;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.net.URLDecoder;
- import java.util.*;
- import java.util.concurrent.atomic.AtomicBoolean;
- /**
- * Created by Hb_zzZ on 2020/6/19.
- */
- @Slf4j
- @RestController
- @RequestMapping("/change")
- @Api(tags = "生成风格模块")
- public class ImportDataController extends BaseController {
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @Autowired
- private ISceneStyleService sceneStyleService;
- @Autowired
- private ISceneLightService sceneLightService;
- @Autowired
- private IRenovationPartsDetailService partsDetailService;
- @Autowired
- private IRenovationBuildDetailService buildDetailService;
- @Autowired
- private IStatisticsService statisticsService;
- @Autowired
- RabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方
- @Value("${main.url}")
- private String mainUrl;
- @Value("${server.file.location}")
- private String buildPath;
- @Value("${build.url}")
- private String buildUrl;
- @Value("${upload.file.location}")
- private String path;
- /**
- * 导入数据生成风格场景
- * @param sceneNum
- * @param data
- * @param styleName
- * @param styleNum
- * @param file
- * @return
- */
- @ApiOperation("导入数据生成风格场景")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "sceneNum", value = "场景码", dataType = "String"),
- @ApiImplicitParam(name = "styleName", value = "风格名称", dataType = "String"),
- @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String"),
- @ApiImplicitParam(name = "file", value = "文件流", dataType = "MultipartFile"),
- @ApiImplicitParam(name = "buildTye", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String"),
- @ApiImplicitParam(name = "decoration", value = "decoration.json", dataType = "String"),
- @ApiImplicitParam(name = "rooms", value = "rooms的json内容", dataType = "String"),
- @ApiImplicitParam(name = "data", value = "json数据", dataType = "String")})
- @RequestMapping(value = "/importData", method = RequestMethod.POST)
- public Result importData(String sceneNum, String data, String styleName, String decoration,
- String styleNum, @RequestParam("file") MultipartFile file,
- String proLight, String buildType, String rooms) throws Exception{
- if(StringUtils.isEmpty(sceneNum)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String resultData = OkHttpUtils.httpGet(mainUrl + "api/scene/getInfo?num=" + sceneNum);
- JSONObject resultJson = JSON.parseObject(resultData);
- if(resultJson == null || resultJson.getInteger("code") != 0){
- return Result.failure(CodeConstant.FAILURE_CODE_4007, CodeConstant.FAILURE_MSG_4007);
- }
- String vrNum = styleNum;
- try{
- if(StringUtils.isEmpty(styleNum)){
- Integer num = sceneStyleService.findLastNum(sceneNum);
- if(num == null){
- num = 1;
- }else {
- num ++;
- }
- vrNum = "vr-" + sceneNum + "-" + String.format("%3d", num).replace(" ", "0");
- SceneStyleEntity sceneStyleEntity = new SceneStyleEntity();
- sceneStyleEntity.setNum(num.longValue());
- sceneStyleEntity.setSceneNum(sceneNum);
- sceneStyleEntity.setStyleName(styleName);
- sceneStyleEntity.setStyleNum(vrNum);
- //新生成的换装风格,未渲染
- sceneStyleEntity.setStatus(2);
- sceneStyleService.save(sceneStyleEntity);
- }else {
- LambdaQueryWrapper<SceneStyleEntity> wrapper = Wrappers.lambdaQuery();
- wrapper.eq(SceneStyleEntity::getStyleNum,styleNum);
- wrapper.orderByDesc(SceneStyleEntity::getNum);
- List<SceneStyleEntity> list = sceneStyleService.list(wrapper);
- if(list != null && list.size() > 0) {
- SceneStyleEntity sceneStyleEntity = list.get(0);
- sceneStyleEntity.setStyleName(styleName);
- sceneStyleService.updateById(sceneStyleEntity);
- }
- }
- String filePath = buildPath + "Input/" + vrNum ;
- String dataPath = "";
- String decorationPath = "";
- //灯光预览放在light文件夹
- if("light".equals(buildType)){
- filePath = filePath + "light/";
- }else if ("pano".equals(buildType)){
- filePath = filePath + "pano/";
- }
- else {
- filePath = filePath + File.separator;
- }
- //生成需要vision.txt
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + sceneNum + "/vision.modeldata",
- "vision.modeldata", filePath);
- if(!new File(filePath + "vision.modeldata").exists()){
- log.info("vision.modeldata文件不存在");
- return Result.failure(CodeConstant.FAILURE_CODE_4001, CodeConstant.FAILURE_MSG_4001);
- }
- log.info("下载vision.modeldata完成,开始转换vision.txt");
- CreateObjUtil.convertVisionmodeldataToTxt(filePath + "vision.modeldata", filePath + "vision.txt");
- //计算translationAverage,和puckAverage并重新赋予值
- Map<String, Double> averageMap = ConvertCadKjl.getAverageValue(filePath + "vision.txt");
- setAverageValue(filePath + "vision.txt", averageMap.get("translationAverage"), averageMap.get("puckAverage"));
- FileUtils.writeFile(filePath + "proLight.json", proLight);
- dataPath = filePath + "objectPosition.json";
- decorationPath = filePath + "decoration.json";
- FileUtils.writeFile(dataPath, data);
- FileUtils.writeFile(decorationPath, decoration);
- File objFile = new File(filePath + "Obj" + File.separator + file.getOriginalFilename());
- if(!objFile.getParentFile().exists()){
- objFile.getParentFile().mkdirs();
- }
- file.transferTo(objFile);
- //数据上传oss,让计算服务器下载资源
- List<String> uploadList = new ArrayList<>();
- FileUtils.readfilePath(filePath, uploadList);
- for(String uploadFile : uploadList){
- if(StringUtils.isEmpty(buildType) || "all".equals(buildType)){
- uploadToOssUtil.upload(uploadFile,
- "data/data" + vrNum + uploadFile.replace(filePath, "/changeData/"));
- }
- }
- //保存每个风格码的户型数据
- if(!new File(filePath + "house.json").exists()){
- String path = ResourceUtils.getURL("classpath:").getPath();
- path = URLDecoder.decode(path,"utf-8");
- path = path + File.separator + "data/" + sceneNum;
- System.out.println("文件路径:" + path);
- FileUtils.copyFile(path + "/kjl.json", filePath + "house.json", true);
- uploadToOssUtil.upload(filePath + "house.json", "data/data" + vrNum + "/house.json");
- }
- //有修改房间信息就更新户型数据
- if(!StringUtils.isEmpty(rooms)){
- JSONObject kjlJson = JSONObject.parseObject(FileUtils.readFile(filePath + "house.json"));
- if(kjlJson != null){
- kjlJson.put("rooms", JSONObject.parseObject(rooms));
- }
- FileUtils.writeFile(filePath + "house.json", kjlJson.toJSONString());
- uploadToOssUtil.upload(filePath + "house.json", "data/data" + vrNum + "/house.json");
- }
- }catch (Exception e){
- e.printStackTrace();
- }
- JSONObject result = new JSONObject();
- result.put("num", vrNum);
- return Result.success(result);
- }
- /**
- * 保存proLight.json数据
- * @param styleNum
- * @return
- */
- @ApiOperation("保存proLight.json数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "styleNum", value = "风格名称", dataType = "String"),
- @ApiImplicitParam(name = "proLight", value = "proLight.json的数据", dataType = "String"),
- @ApiImplicitParam(name = "buildType", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String")})
- @RequestMapping(value = "/saveProLightJson", method = RequestMethod.POST)
- public Result importData(String styleNum, String proLight, String buildType) throws Exception{
- if(StringUtils.isEmpty(styleNum)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String vrNum = styleNum;
- try{
- String filePath = buildPath + "Input/" + vrNum ;
- //灯光预览放在light文件夹
- if("light".equals(buildType)){
- filePath = filePath + "light/";
- }else if ("pano".equals(buildType)){
- filePath = filePath + "pano/";
- }
- else {
- filePath = filePath + File.separator;
- }
- log.info("保存的类型是:" + buildType + ";位置在:" + filePath);
- FileUtils.writeFile(filePath + "proLight.json", proLight);
- //数据上传oss,让计算服务器下载资源
- uploadToOssUtil.upload(filePath + "proLight.json",
- "data/data" + vrNum + "/changeData/proLight.json");
- }catch (Exception e){
- e.printStackTrace();
- }
- return Result.success();
- }
- @ApiOperation("渲染场景")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "sceneNum", value = "场景码", dataType = "String"),
- @ApiImplicitParam(name = "ratio", value = "字符串16:9", dataType = "String"),
- @ApiImplicitParam(name = "type", value = "分辨率,1024,2048", dataType = "String"),
- @ApiImplicitParam(name = "dateType", value = "day(白天),night(晚上)", dataType = "String"),
- @ApiImplicitParam(name = "buildType", value = "渲染类型,all(全屋),light(灯光预览),pano(全景图)", dataType = "String"),
- @ApiImplicitParam(name = "isShow", value = "灯光预览是否显示在相册,0不显示,1显示", dataType = "String"),
- @ApiImplicitParam(name = "quality", value = "0或1", dataType = "String"),
- @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
- @RequestMapping(value = "/buildChangeScene", method = RequestMethod.POST)
- public Result buildChangeScene(String sceneNum, String styleNum, String type,
- String dateType, String buildType, String ratio,
- String isShow, String quality){
- try{
- if(StringUtils.isEmpty(sceneNum) || StringUtils.isEmpty(styleNum)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- LambdaQueryWrapper<SceneStyleEntity> wrapper = Wrappers.lambdaQuery();
- wrapper.eq(SceneStyleEntity::getStyleNum,styleNum);
- wrapper.orderByDesc(SceneStyleEntity::getNum);
- List<SceneStyleEntity> list = sceneStyleService.list(wrapper);
- SceneStyleEntity sceneStyleEntity = null;
- if(StringUtils.isEmpty(buildType) || "all".equals(buildType)){
- if(list != null && list.size() > 0){
- sceneStyleEntity = list.get(0);
- if(sceneStyleEntity.getStatus().intValue() == 0){
- return Result.failure(CodeConstant.FAILURE_CODE_4002, CodeConstant.FAILURE_MSG_4002);
- }
- sceneStyleEntity.setStatus(0);
- sceneStyleEntity.setProgress(0);
- sceneStyleService.updateById(sceneStyleEntity);
- }else {
- return Result.failure(CodeConstant.FAILURE_CODE_4003, CodeConstant.FAILURE_MSG_4003);
- }
- //判断是否有vr+场景吗的场景,有则上传数据,无则生成;
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("type", "change");
- map.put("num", styleNum);
- map.put("oldNum", sceneNum);
- map.put("sceneName", sceneStyleEntity.getStyleName());
- map.put("resolution", type);
- HttpRequestorUtil.doPost(mainUrl + "api/scene/createChangeScene", map);
- if(StringUtils.isEmpty(type)){
- type = "1024";
- }
- // Variable.queue.offer(styleNum + ":;" + sceneNum + ":;" + type);
- if(dateType == null){
- dateType = "";
- }
- rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.CHANGE, styleNum + ":;" + sceneNum + ":;" + type + ":;" + dateType);
- }
- if("light".equals(buildType) || "pano".equals(buildType)){
- if(StringUtils.isEmpty(type)){
- type = "1024";
- }
- if(dateType == null){
- dateType = "";
- }
- if(StringUtils.isEmpty(quality)){
- quality = "0";
- }
- SceneLightEntity sceneLightEntity = new SceneLightEntity();
- if(list != null && list.size() > 0){
- sceneStyleEntity = list.get(0);
- if("light".equals(buildType)){
- log.info("灯光预览:" + styleNum);
- if(sceneStyleEntity.getLightStatus().intValue() == 0){
- return Result.failure(CodeConstant.FAILURE_CODE_4004, CodeConstant.FAILURE_MSG_4004);
- }
- sceneStyleEntity.setLightStatus(0);
- }
- if("pano".equals(buildType)){
- log.info("全景预览:" + styleNum);
- if(sceneStyleEntity.getLightStatus().intValue() == 0){
- return Result.failure(CodeConstant.FAILURE_CODE_4016, CodeConstant.FAILURE_MSG_4016);
- }
- sceneStyleEntity.setPanoStatus(0);
- }
- sceneStyleService.updateById(sceneStyleEntity);
- sceneLightEntity.setStatus(0);
- sceneLightEntity.setProgress(0);
- if(StringUtils.isEmpty(isShow)){
- isShow = "1";
- }
- sceneLightEntity.setIsShow(Integer.valueOf(isShow));
- sceneLightEntity.setSceneStyleId(sceneStyleEntity.getId());
- sceneLightEntity.setPixel(type);
- //数据上传oss,让计算服务器下载资源
- String filePath = buildPath + "Input/" + styleNum;
- if("light".equals(buildType)){
- sceneLightEntity.setType(1);
- filePath = filePath + "light/";
- }
- if("pano".equals(buildType)){
- sceneLightEntity.setType(2);
- filePath = filePath + "pano/";
- }
- sceneLightEntity.setQuality(quality);
- sceneLightService.save(sceneLightEntity);
- List<String> uploadList = new ArrayList<>();
- FileUtils.readfilePath(filePath, uploadList);
- for(String uploadFile : uploadList){
- uploadToOssUtil.upload(uploadFile,
- "data/data" + styleNum + uploadFile.replace(
- filePath, "/proLightData/" + sceneLightEntity.getId().longValue() + "/"));
- }
- }else {
- return Result.failure(CodeConstant.FAILURE_CODE_4003, CodeConstant.FAILURE_MSG_4003);
- }
- rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.LIGHT,
- styleNum + ":;" + sceneNum + ":;" + type + ":;" + dateType + ":;" +
- ratio + ":;" + sceneLightEntity.getId().longValue() + ":;" +
- quality + ":;" + buildType);
- }
- FileUtils.deleteDirectory(buildPath + "Output/" + styleNum);
- }catch (Exception e){
- e.printStackTrace();
- }
- JSONObject result = new JSONObject();
- result.put("num", styleNum);
- result.put("url", mainUrl + "spc.html?t=" + styleNum);
- return Result.success(result);
- }
- /**
- * 测试运行命令
- * @return
- */
- @ApiOperation("测试运行命令")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "fbxPath", value = "fbx文件路径", dataType = "String"),
- @ApiImplicitParam(name = "objPath", value = "obj文件路径", dataType = "String")})
- @RequestMapping(value = "/fbxToObj", method = RequestMethod.POST)
- public String fbxToObj(String fbxPath, String objPath) throws Exception{
- // String command = "D:/OneKeyDecorate/StartDecorate.exe -s " + vrNum;
- // log.info("开始建模:" + command);
- // RunCmdUtil.callshell(command);
- // log.info("计算完毕:" + command);
- String filePth = fbxPath.substring(0, fbxPath.lastIndexOf(File.pathSeparator) + 1);
- String fbxName = fbxPath.substring(fbxPath.lastIndexOf(File.pathSeparator) + 1);
- CreateObjUtil.fbxToObj(filePth, fbxName, objPath);
- return "运行完成";
- }
- /**
- * 生成房型数据
- * @param num
- * @return
- */
- @ApiOperation("生成房型数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "num", value = "四维看看场景码", dataType = "String"),
- @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
- @RequestMapping(value = "/createJson", method = RequestMethod.GET)
- public String createJson(String num, String styleNum){
- try{
- if(StringUtils.isEmpty(num)){
- return "参数不能为空";
- }
- String resultData = OkHttpUtils.httpGet(mainUrl + "api/scene/getInfo?num=" + num);
- JSONObject getInfoJson = JSON.parseObject(resultData);
- //初始画面
- String entry = null;
- if(getInfoJson != null || getInfoJson.getInteger("code") == 0){
- entry = getInfoJson.getJSONObject("data").getString("entry");
- }
- String basePath = URLDecoder.decode(path,"utf-8");
- basePath = basePath + File.separator + "data/" + num;
- System.out.println("文件路径:" + basePath);
- if(!new File(basePath).exists()){
- new File(basePath).mkdirs();
- }
- JSONObject entryJson = new JSONObject();
- if(StrUtil.isEmpty(entry)){
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + num + "/vision.modeldata?t=" + System.currentTimeMillis(),
- "vision.modeldata", basePath);
- if(!new File(basePath + "/vision.modeldata").exists()){
- log.info("vision.modeldata文件不存在");
- }else {
- log.info("下载vision.modeldata完成,开始转换vision.txt");
- CreateObjUtil.convertVisionmodeldataToTxt(basePath + "/vision.modeldata", basePath + "/vision.txt");
- JSONObject visionJson = JSON.parseObject(FileUtils.readFile(basePath + "/vision.txt"));
- JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
- if(sweepArray != null && sweepArray.size() > 0){
- entryJson.put("noSetting", sweepArray.getJSONObject(0));
- }
- }
- }else {
- entryJson.put("setting", JSON.parseObject(entry));
- }
- //下载原场景的scene.json
- if(!StringUtils.isEmpty(num)){
- FileUtils.downLoadFromUrl(mainUrl + "scene/data/data" + num + "/scene.json?t=" + System.currentTimeMillis(),
- "scene.json", basePath);
- }
- //原场景码的户型版本号
- int floorPublishVer = 0;
- String sceneStr = FileUtils.readFile(basePath + "/scene.json");
- JSONObject sceneJson = null;
- if(sceneStr != null){
- sceneJson = JSONObject.parseObject(sceneStr);
- if(sceneJson.containsKey("floorPublishVer")){
- floorPublishVer = sceneJson.getIntValue("floorPublishVer");
- }
- }
- //下载风格码保存过的house.json
- if(!StringUtils.isEmpty(styleNum)){
- String filePath = buildPath + "Input/" + styleNum +File.separator;
- if(!new File(filePath).exists()){
- new File(filePath).mkdirs();
- }
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + styleNum + "/house.json?t=" + System.currentTimeMillis(),
- "house.json", filePath);
- //oss上的户型数据
- String houseStr = FileUtils.readFile(filePath + "/house.json");
- int version = 0;
- if(houseStr != null){
- JSONObject houseJson = JSONObject.parseObject(houseStr);
- if(houseJson.containsKey("version")){
- version = houseJson.getIntValue("version");
- }
- houseJson.put("version", version);
- houseJson.put("floorPublishVer", floorPublishVer);
- houseJson.put("entry", entryJson);
- return houseJson.toJSONString();
- }
- }
- Map<String, Double> map = null;
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
- "floor.json", basePath);
- ConvertCadKjl cad = new ConvertCadKjl();
- String data = FileUtils.readFile(basePath + File.separator + "floor.json");
- JSONObject inputJson = null;
- JSONArray inputArray = null;
- JSONObject resultJson = new JSONObject();
- JSONArray resultArray = new JSONArray();
- if(StrUtil.isNotEmpty(data)){
- inputJson = JSON.parseObject(data);
- if(inputJson.containsKey("floors")) {
- inputArray = inputJson.getJSONArray("floors");
- for (int i = 0, len = inputArray.size(); i < len; i++) {
- cad = new ConvertCadKjl();
- cad.init(inputArray.getJSONObject(i));
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- //判断是否需要重复出去墙
- AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- walls = cad.removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- cad.output.put("version", floorPublishVer);
- resultArray.add(cad.output);
- }
- resultJson.put("floors", resultArray);
- }else {
- cad.init(inputJson);
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- //判断是否需要重复出去墙
- AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- walls = cad.removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- map = ConvertCadKjl.getMaxOrMinValue(inputJson);
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- cad.output.put("version", floorPublishVer);
- resultJson = cad.output;
- }
- cad.init(inputJson);
- }
- resultJson.put("entry", entryJson);
- cad.writeBinary(resultJson.toString().getBytes(), basePath + File.separator + "kjl.json");
- return resultJson.toString();
- }catch (Exception e){
- e.printStackTrace();
- return "生成json数据失败";
- }
- }
- /**
- * 修改房型数据
- * @param num
- * @return
- */
- @ApiOperation("修改房型数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "num", value = "四维看看场景码", dataType = "String"),
- @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String")})
- @RequestMapping(value = "/updateJson", method = RequestMethod.GET)
- public String updateJson(String num, String styleNum){
- try{
- if(StringUtils.isEmpty(num) || StringUtils.isEmpty(styleNum)){
- return "参数不能为空";
- }
- String path = ResourceUtils.getURL("classpath:").getPath();
- path = URLDecoder.decode(path,"utf-8");
- path = path + File.separator + "data/" + num;
- System.out.println("文件路径:" + path);
- if(!new File(path).exists()){
- new File(path).mkdirs();
- }
- //下载原场景的scene.json
- if(!StringUtils.isEmpty(num)){
- FileUtils.downLoadFromUrl(mainUrl + "data/data" + num + "/scene.json?t=" + System.currentTimeMillis(),
- "scene.json", path);
- }
- //原场景码的户型版本号
- int floorPublishVer = 0;
- String sceneStr = FileUtils.readFile(path + "/scene.json");
- JSONObject sceneJson = null;
- if(sceneStr != null){
- sceneJson = JSONObject.parseObject(sceneStr);
- if(sceneJson.containsKey("floorPublishVer")){
- floorPublishVer = sceneJson.getIntValue("floorPublishVer");
- }
- }
- Map<String, Double> map = null;
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/images/images" + num + "/vision.modeldata?t=" + System.currentTimeMillis(),
- "vision.modeldata", path);
- if(!new File(path + "/vision.modeldata").exists()){
- log.info("vision.modeldata文件不存在");
- }else {
- log.info("下载vision.modeldata完成,开始转换vision.txt");
- CreateObjUtil.convertVisionmodeldataToTxt(path + "/vision.modeldata", path + "/vision.txt");
- }
- FileUtils.downLoadFromUrl("https://4dkk.4dage.com/data/data" + num + "/floor.json?t=" + System.currentTimeMillis(),
- "floor.json", path);
- ConvertCadKjl cad = new ConvertCadKjl();
- String data = FileUtils.readFile(path + File.separator + "floor.json");
- JSONObject inputJson = null;
- JSONArray inputArray = null;
- JSONObject resultJson = new JSONObject();
- JSONArray resultArray = new JSONArray();
- if(StrUtil.isNotEmpty(data)){
- inputJson = JSON.parseObject(data);
- if(inputJson.containsKey("floors")) {
- inputArray = inputJson.getJSONArray("floors");
- for (int i = 0, len = inputArray.size(); i < len; i++) {
- cad = new ConvertCadKjl();
- cad.init(inputArray.getJSONObject(i));
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- //判断是否需要重复出去墙
- AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- walls = cad.removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- map = ConvertCadKjl.getMaxOrMinValue(inputArray.getJSONObject(i));
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- cad.output.put("version", floorPublishVer);
- resultArray.add(cad.output);
- }
- resultJson.put("floors", resultArray);
- }else {
- cad.init(inputJson);
- cad.input = cad.preHandle(cad.input);
- JSONArray beams = cad.getBeams();
- JSONArray walls = cad.getWalls();
- //判断是否需要重复出去墙
- AtomicBoolean removeAgain = new AtomicBoolean(false);
- //去除重复的墙
- walls = cad.removeRepeat(walls);
- JSONArray rooms = cad.getRooms();
- JSONArray flues = cad.getFlues();
- JSONArray holes = cad.getHoles();
- cad.output.put("holes", holes);
- cad.output.put("flues", flues);
- cad.output.put("beams", beams);
- cad.output.put("rooms", rooms);
- cad.output.put("walls", walls);
- map = ConvertCadKjl.getMaxOrMinValue(inputJson);
- if(map != null){
- JSONObject scene = new JSONObject();
- scene.put("bottom", map.get("translationAverage"));
- scene.put("top", map.get("puckAverage") == null? null : map.get("puckAverage"));
- cad.output.put("scene", scene);
- }
- cad.output.put("version", floorPublishVer);
- resultJson = cad.output;
- }
- }
- cad.writeBinary(resultJson.toString().getBytes(), path + File.separator + "kjl.json");
- uploadToOssUtil.upload(path + File.separator + "kjl.json", "data/data" + styleNum + "/house.json");
- return resultJson.toString();
- }catch (Exception e){
- e.printStackTrace();
- return "生成json数据失败";
- }
- }
- public static void setAverageValue(String visionPath, Double translationAverage, Double puckAverage) throws Exception{
- Map<String, Double> map = new HashMap<>();
- JSONObject visionJson = JSONObject.parseObject(FileUtils.readFile(visionPath));
- JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
- for(int i = 0, len = sweepLocations.size(); i < len; i++){
- sweepLocations.getJSONObject(i).getJSONObject("pose").
- getJSONObject("translation").put("z", translationAverage);
- sweepLocations.getJSONObject(i).getJSONObject("puck").put("z", puckAverage);
- }
- visionJson.put("sweepLocations", sweepLocations);
- FileUtils.writeFile(visionPath, visionJson.toString());
- }
- /**
- * 更新所有decoration.json数据
- * @return
- */
- @ApiOperation("更新所有decoration.json数据")
- @RequestMapping(value = "/updateDecorationJson", method = RequestMethod.GET)
- public Result updateDecorationJson() throws Exception{
- List<SceneStyleEntity> list = sceneStyleService.list();
- String path = "";
- String lightPath = "";
- String data = "";
- File file = null;
- File lightFile = null;
- JSONObject object = null;
- JSONObject lightObject = null;
- JSONArray furniture = null;
- JSONArray walls = null;
- JSONArray rooms = null;
- JSONArray lights = null;
- JSONArray windows = null;
- JSONArray doors = null;
- JSONObject assets = null;
- JSONArray materials = null;
- JSONObject wallpaper = null;
- JSONObject floor = null;
- JSONObject texture = null;
- String wallpaperStr = "";
- String textureStr = "";
- ResponseRenovationPartsDetail detail = null;
- ResponseRenovationBuildDetail buildDetail = null;
- for (SceneStyleEntity sceneStyleEntity : list) {
- path = buildPath + "Input/" + sceneStyleEntity.getStyleNum() + File.separator + "decoration.json";
- lightPath = buildPath + "Input/" + sceneStyleEntity.getStyleNum() + "light/decoration.json";
- file = new File(path);
- lightFile = new File(lightPath);
- if(file.exists()){
- data = FileUtils.readFile(path);
- if(data.startsWith("{") && data.endsWith("}")){
- object = JSON.parseObject(data);
- if(object != null){
- furniture = object.getJSONArray("furniture");
- walls = object.getJSONArray("walls");
- rooms = object.getJSONArray("rooms");
- lights = object.getJSONArray("lights");
- windows = object.getJSONArray("windows");
- doors = object.getJSONArray("doors");
- if(furniture != null){
- for(int i = 0, len = furniture.size(); i < len; i++){
- if(furniture.getJSONObject(i).containsKey("assets")){
- assets = furniture.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- if(walls != null){
- for(int i = 0, len = walls.size(); i < len; i++){
- if(walls.getJSONObject(i).containsKey("materials")){
- materials = walls.getJSONObject(i).getJSONArray("materials");
- for(int j = 0; j < materials.size(); j++){
- wallpaperStr = materials.getJSONObject(j).getString("wallpaper");
- wallpaper = new JSONObject();
- buildDetail = buildDetailService.findByName(wallpaperStr);
- // if(wallpaper.containsKey("name")){
- if(buildDetail != null){
- wallpaper.put("previewUrl", buildDetail.getThumbnail());
- wallpaper.put("url", buildDetail.getThumbnail());
- wallpaper.put("name", wallpaperStr);
- wallpaper.put("id", buildDetail.getId());
- // wallpaper.put("path", buildDetail.getPath());
- materials.getJSONObject(j).put("wallpaper", wallpaper);
- }
- // }
- }
- }
- }
- }
- if(rooms != null){
- for(int i = 0, len = rooms.size(); i < len; i++){
- if(rooms.getJSONObject(i).containsKey("floor")){
- floor = rooms.getJSONObject(i).getJSONObject("floor");
- textureStr = floor.getString("texture");
- texture = new JSONObject();
- buildDetail = buildDetailService.findByName(textureStr);
- // if(texture.containsKey("name")){
- if(buildDetail != null){
- texture.put("previewUrl", buildDetail.getThumbnail());
- texture.put("url", buildDetail.getThumbnail());
- texture.put("id", buildDetail.getId());
- texture.put("name", textureStr);
- // texture.put("path", buildDetail.getPath());
- floor.put("texture", texture);
- }
- // }
- }
- }
- }
- if(lights != null){
- for(int i = 0, len = lights.size(); i < len; i++){
- if(lights.getJSONObject(i).containsKey("assets")){
- assets = lights.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- if(windows != null){
- for(int i = 0, len = windows.size(); i < len; i++){
- if(windows.getJSONObject(i).containsKey("assets")){
- assets = windows.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- if(doors != null){
- for(int i = 0, len = doors.size(); i < len; i++){
- if(doors.getJSONObject(i).containsKey("assets")){
- assets = doors.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- FileUtils.writeFile(path.replace("decoration.json", "decorationBack.json"),
- JSON.toJSONString(object,SerializerFeature.WriteMapNullValue));
- uploadToOssUtil.upload(path.replace("decoration.json", "decorationBack.json"),
- "data/data" + sceneStyleEntity.getStyleNum() + "/changeData/decoration.json");
- }
- }
- }
- if(lightFile.exists()){
- data = FileUtils.readFile(lightPath);
- if(data.startsWith("{") && data.endsWith("}")){
- object = JSON.parseObject(data);
- if(object != null){
- furniture = object.getJSONArray("furniture");
- walls = object.getJSONArray("walls");
- rooms = object.getJSONArray("rooms");
- lights = object.getJSONArray("lights");
- windows = object.getJSONArray("windows");
- doors = object.getJSONArray("doors");
- if(furniture != null){
- for(int i = 0, len = furniture.size(); i < len; i++){
- if(furniture.getJSONObject(i).containsKey("assets")){
- assets = furniture.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- // if(walls != null){
- //
- // for(int i = 0, len = walls.size(); i < len; i++){
- // if(walls.getJSONObject(i).containsKey("materials") && walls.getJSONObject(i).containsKey("wallpaper")){
- //
- // materials = walls.getJSONObject(i).getJSONArray("materials");
- // for(int j = 0; j < materials.size(); j++){
- // wallpaper = materials.getJSONObject(j).getJSONObject("wallpaper");
- // if(wallpaper.containsKey("name")){
- // buildDetail = buildDetailService.findByName(wallpaper.getString("name"));
- // if(buildDetail != null){
- // wallpaper.put("previewUrl", buildDetail.getThumbnail());
- // wallpaper.put("url", buildDetail.getThumbnail());
- //// wallpaper.put("path", buildDetail.getPath());
- // }
- // }
- // }
- //
- //
- // }
- // }
- // }
- //
- // if(rooms != null){
- //
- // for(int i = 0, len = rooms.size(); i < len; i++){
- // if(rooms.getJSONObject(i).containsKey("floor") && rooms.getJSONObject(i).containsKey("texture")){
- //
- // floor = rooms.getJSONObject(i).getJSONObject("floor");
- // texture = floor.getJSONObject("texture");
- //
- // if(texture.containsKey("name")){
- // buildDetail = buildDetailService.findByName(texture.getString("name"));
- // if(buildDetail != null){
- // texture.put("previewUrl", buildDetail.getThumbnail());
- // texture.put("url", buildDetail.getThumbnail());
- //// texture.put("path", buildDetail.getPath());
- // }
- // }
- // }
- // }
- // }
- if(walls != null){
- for(int i = 0, len = walls.size(); i < len; i++){
- if(walls.getJSONObject(i).containsKey("materials")){
- materials = walls.getJSONObject(i).getJSONArray("materials");
- for(int j = 0; j < materials.size(); j++){
- wallpaperStr = materials.getJSONObject(j).getString("wallpaper");
- wallpaper = new JSONObject();
- buildDetail = buildDetailService.findByName(wallpaperStr);
- // if(wallpaper.containsKey("name")){
- if(buildDetail != null){
- wallpaper.put("previewUrl", buildDetail.getThumbnail());
- wallpaper.put("url", buildDetail.getThumbnail());
- wallpaper.put("name", wallpaperStr);
- wallpaper.put("id", buildDetail.getId());
- // wallpaper.put("path", buildDetail.getPath());
- materials.getJSONObject(j).put("wallpaper", wallpaper);
- }
- // }
- }
- }
- }
- }
- if(rooms != null){
- for(int i = 0, len = rooms.size(); i < len; i++){
- if(rooms.getJSONObject(i).containsKey("floor") ){
- floor = rooms.getJSONObject(i).getJSONObject("floor");
- textureStr = floor.getString("texture");
- texture = new JSONObject();
- buildDetail = buildDetailService.findByName(textureStr);
- // if(texture.containsKey("name")){
- if(buildDetail != null){
- texture.put("previewUrl", buildDetail.getThumbnail());
- texture.put("url", buildDetail.getThumbnail());
- texture.put("id", buildDetail.getId());
- texture.put("name", textureStr);
- // texture.put("path", buildDetail.getPath());
- floor.put("texture", texture);
- }
- // }
- }
- }
- }
- if(lights != null){
- for(int i = 0, len = lights.size(); i < len; i++){
- if(lights.getJSONObject(i).containsKey("assets")){
- assets = lights.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- if(windows != null){
- for(int i = 0, len = windows.size(); i < len; i++){
- if(windows.getJSONObject(i).containsKey("assets")){
- assets = windows.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- if(doors != null){
- for(int i = 0, len = doors.size(); i < len; i++){
- if(doors.getJSONObject(i).containsKey("assets")){
- assets = doors.getJSONObject(i).getJSONObject("assets");
- if(assets.containsKey("name")){
- detail = partsDetailService.findByName(assets.getString("name"));
- if(detail != null){
- assets.put("previewUrl", detail.getImg());
- assets.put("url", detail.getHighImg());
- assets.put("path", detail.getPath());
- }
- }
- }
- }
- }
- FileUtils.writeFile(lightPath.replace("decoration.json", "decorationBack.json"),
- JSON.toJSONString(object,SerializerFeature.WriteMapNullValue));
- uploadToOssUtil.upload(lightPath.replace("decoration.json", "decorationBack.json"),
- "data/data" + sceneStyleEntity.getStyleNum() + "/proLightData/decoration.json");
- }
- }
- }
- }
- return Result.success();
- }
- /**
- * 获取预设灯光信息
- * @return
- */
- @ApiOperation("获取预设灯光信息")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "data", value = "数据(json字符串)", dataType = "String")})
- @RequestMapping(value = "/getLightInfo", method = RequestMethod.POST)
- public Result getLightInfo(String data){
- if(StringUtils.isEmpty(data)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("obj", data);
- String result = OkHttpUtils.httpPostJson(buildUrl + "getLightInfo", jsonObject.toJSONString());
- log.info("getLightInfo返回结果:" + result);
- JSONObject resultJson = JSON.parseObject(result);
- if(resultJson.containsKey("state") && "done".equals(resultJson.getString("state"))){
- return Result.success(resultJson.getString("msg"));
- }
- return Result.failure(CodeConstant.FAILURE_CODE_4005, CodeConstant.FAILURE_MSG_4005);
- }
- /**
- * 保存json数据
- * @return
- */
- @ApiOperation("保存json数据")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "styleNum", value = "风格码", dataType = "String"),
- @ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "String"),
- @ApiImplicitParam(name = "jsonData", value = "数据(json字符串)", dataType = "String")})
- @RequestMapping(value = "/saveJsonUploadOss", method = RequestMethod.POST)
- public Result saveJsonUploadOss(String jsonData, String fileName, String styleNum) throws Exception{
- if(StringUtils.isEmpty(jsonData) || StringUtils.isEmpty(fileName) || StringUtils.isEmpty(styleNum)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String filePath = buildPath + "data/data" + styleNum + File.separator + fileName;
- log.info("保存文件路径-filePath{}:" + filePath);
- FileUtils.writeFile(filePath, jsonData);
- uploadToOssUtil.upload(filePath, "data/data" + styleNum + File.separator + fileName);
- return Result.success((Object) ("data/data" + styleNum + File.separator + fileName));
- }
- public static void main(String[] args) {
- try{
- Map<String, Double> map = ConvertCadKjl.getAverageValue("G:\\javaProject\\changeing\\vision.txt");
- System.out.println(map.get("translationAverage"));
- System.out.println(map.get("puckAverage"));
- setAverageValue("G:\\javaProject\\changeing\\vision.txt", map.get("translationAverage"), map.get("puckAverage"));
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
|