123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987 |
- package com.example.demo.controller;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.example.demo.constant.CodeConstant;
- import com.example.demo.entity.*;
- import com.example.demo.mq.TopicRabbitConfig;
- import com.example.demo.service.*;
- import com.example.demo.util.*;
- import com.example.demo.vo.request.RequestRenovationParts;
- import com.example.demo.vo.request.RequestRenovationPartsDetailManager;
- import com.example.demo.vo.response.ResponseRenovationPartsAttaching;
- import com.example.demo.vo.response.ResponseRenovationPartsDetailManager;
- import com.example.demo.vo.response.ResponseRenovationPartsSize;
- import com.github.pagehelper.Page;
- import com.github.pagehelper.PageInfo;
- import com.github.pagehelper.util.StringUtil;
- 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.apache.commons.lang.StringUtils;
- import org.springframework.amqp.rabbit.core.RabbitTemplate;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * Created by Hb_zzZ on 2020/12/1.
- */
- @Slf4j
- @RestController
- @RequestMapping("/manager")
- @Api(tags = "管理后台模块")
- public class ManagerController {
- @Value("${server.file.location}")
- private String buildPath;
- @Autowired
- private IModelUploadService modelUploadService;
- @Autowired
- private IRenovationPartsDetailService renovationPartsDetailService;
- @Autowired
- private IRenovationPartsAttachingService renovationPartsAttachingService;
- @Autowired
- private IRenovationPartsColorService renovationPartsColorService;
- @Autowired
- private IRenovationPartsTypeService renovationPartsTypeService;
- @Autowired
- private IRenovationPartsService renovationPartsService;
- @Autowired
- private IRenovationPartsShapeService renovationPartsShapeService;
- @Autowired
- private IRenovationPartsClassifyService renovationPartsClassifyService;
- @Autowired
- private IRenovationPartsStyleService renovationPartsStyleService;
- @Autowired
- private IRenovationPartsSizeService renovationPartsSizeService;
- @Autowired
- private IRenovationPartsBrandService renovationPartsBrandService;
- @Autowired
- private ICompanyService companyService;
- @Autowired
- private ObjToToolbagUtil objToToolbagUtil;
- @Value("${build.url}")
- private String buildUrl;
- @Value("${model.build.url}")
- private String modelBuildUrl;
- @Value("${prefix.ali}")
- private String prefix;
- @Value("${max.obj.url}")
- private String maxObjUrl;
- @Autowired
- private UploadToOssUtil uploadToOssUtil;
- @Autowired
- private RabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方
- /**
- * 上传模型文件
- * @param file
- * @return
- */
- @ApiOperation("上传模型文件")
- @RequestMapping(value = "/uploadModel", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
- @ApiImplicitParam(name = "userType", value = "0管理员,1普通用户", dataType = "String"),
- @ApiImplicitParam(name = "file", value = "文件", dataType = "MultipartFile")})
- public Result uploadModel(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception{
- String userId = request.getParameter("userId");
- String userType = request.getParameter("userType");
- if (StringUtil.isEmpty(userId) || StringUtil.isEmpty(userType) || file.isEmpty()){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String fileId = null;
- ModelUploadEntity modelUploadEntity = null;
- do{
- fileId = RandomUtil.generateShortUuid();
- modelUploadEntity = modelUploadService.findByFileId(fileId);
- } while (modelUploadEntity != null);
- modelUploadEntity = new ModelUploadEntity();
- modelUploadEntity.setUserId(Long.valueOf(userId));
- modelUploadEntity.setFileId(fileId);
- modelUploadEntity.setUserType(Integer.valueOf(userType));
- modelUploadEntity.setStatus(0);
- modelUploadEntity.setUploadFile(file.getOriginalFilename());
- String path = buildPath + "upload";
- File targetFile = new File(path);
- if (!targetFile.exists()){
- targetFile.mkdirs();
- }
- String filePath = path + File.separator + fileId + File.separator;
- targetFile = new File(filePath + file.getOriginalFilename());
- if(!targetFile.getParentFile().exists()){
- targetFile.getParentFile().mkdirs();
- }
- if (targetFile.exists()){
- FileUtils.deleteFile(filePath + file.getOriginalFilename());
- }
- file.transferTo(targetFile);
- if(!file.getOriginalFilename().toLowerCase().endsWith(".zip") && !file.getOriginalFilename().toLowerCase().endsWith(".rar")){
- return Result.failure(CodeConstant.FAILURE_CODE_4012, CodeConstant.FAILURE_MSG_4012);
- }
- if(file.getOriginalFilename().toLowerCase().endsWith(".zip")){
- CreateObjUtil.unZip(filePath + file.getOriginalFilename(), filePath);
- }
- if(file.getOriginalFilename().toLowerCase().endsWith(".rar")){
- CreateObjUtil.unRar(filePath + file.getOriginalFilename(), filePath);
- }
- List<String> allList = new ArrayList<>();
- FileUtils.readfilePath(filePath, allList);
- File target = null;
- String modelType = "datasmith";
- boolean falg = true;
- for (String targetPath : allList) {
- log.info("解压后的-{}文件全路径是-{}", fileId, targetPath);
- if(targetPath.toLowerCase().endsWith(".max")){
- falg = false;
- new File(targetPath).renameTo(new File(targetPath.substring(
- 0, targetPath.lastIndexOf(File.separator) + 1) + fileId + ".max"));
- break;
- }
- }
- if(falg){
- log.error("上传的数据类型不正确-{}", fileId);
- return Result.failure(CodeConstant.FAILURE_CODE_4013, CodeConstant.FAILURE_MSG_4013);
- }
- modelUploadService.save(modelUploadEntity);
- // allList = new ArrayList<>();
- // FileUtils.readfilePath(filePath, allList);
- // for (String targetPath : allList) {
- // target = new File(targetPath);
- // if(target.isFile()){
- // uploadToOssUtil.uploadTo4dTjw(targetPath, "domain/eHome/furniture/InitialData/" + modelType + "/" + fileId + "/" + target.getName());
- // }
- // }
- rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.MODEL, modelUploadEntity.getId() + ":;" + fileId + ":;" + userId + ":;" + modelType);
- return Result.success(modelUploadEntity);
- }
- /**
- * 保存模型数据
- * @return
- */
- @ApiOperation("保存模型数据")
- @RequestMapping(value = "/modelJson", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "compressionRatioHasChanged", value = "是否压缩面数,true压缩,false不压缩", dataType = "String"),
- @ApiImplicitParam(name = "jsonData", value = "json数据", dataType = "String"),
- @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
- public Result modelJson(HttpServletRequest request) throws Exception{
- String modelId = request.getParameter("modelId");
- String jsonData = request.getParameter("jsonData");
- String compressionRatioHasChanged = request.getParameter("compressionRatioHasChanged");
- if (StringUtil.isEmpty(modelId) || StringUtil.isEmpty(jsonData)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(Long.parseLong(modelId));
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- String path = buildPath + "upload/" + modelUploadEntity.getFileId() + "/data.json";
- FileUtils.writeFile(path, jsonData);
- JSONObject json = JSONObject.parseObject(jsonData);
- if(!json.containsKey("matrix")){
- return Result.failure(CodeConstant.FAILURE_CODE_4011, CodeConstant.FAILURE_MSG_4011);
- }
- // //判断是否有基础obj,无则用最初obj转换
- // if(!new File(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj")).exists()){
- // FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath(), buildPath +
- // modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
- // }else {
- // //判断是否有基础obj,有则用基础obj转换
- // FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj"), buildPath +
- // modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
- // }
- //将.obj复制一份-copy.obj用作旋转缩放处理
- if(new File(buildPath + modelUploadEntity.getObjPath()).exists()){
- FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath(), buildPath +
- modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"), true);
- }
- //将-base.obj复制一份-baseCopy.obj用作旋转缩放处理
- if(new File(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj")).exists()) {
- //判断是否有基础obj,有则用基础obj转换
- FileUtils.copyFile(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj"), buildPath +
- modelUploadEntity.getObjPath().replace(".obj", "-baseCopy.obj"), true);
- }
- //转换成最终obj
- ObjProcess.conformity3(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-copy.obj"),
- buildPath + modelUploadEntity.getObjPath() , json.getString("matrix").replace("[", "").replace("]", ""));
- //转换成基础obj
- ObjProcess.conformity3(buildPath + modelUploadEntity.getObjPath().replace(".obj", "-baseCopy.obj"),
- buildPath + modelUploadEntity.getObjPath().replace(".obj", "-base.obj") , json.getString("matrix").replace("[", "").replace("]", ""));
- if(StringUtil.isNotEmpty(compressionRatioHasChanged) &&
- Boolean.valueOf(compressionRatioHasChanged) &&
- json.containsKey("compressionRatio")){
- int compressionRatio = json.getIntValue("compressionRatio");
- String fileId = modelUploadEntity.getFileId();
- if(compressionRatio > 0 ){
- OkHttpUtils.httpGet(maxObjUrl + "objToObj?uuid=" + fileId +"&inObj=" + fileId +
- "-base.obj&outObj=" + fileId + ".obj&r=" + compressionRatio);
- }
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("name", modelUploadEntity.getFileId());
- jsonObject.put("taskId", String.valueOf(modelUploadEntity.getUserId()));
- jsonObject.put("data", json);
- log.info("保存数据,准备修改obj文件数据-{}", jsonObject.toJSONString());
- String result = OkHttpUtils.httpPostJson(modelBuildUrl + "fixmodel", jsonObject.toJSONString());
- log.info(modelBuildUrl + "fixmodel:" + result);
- return Result.success();
- }
- /**
- * 修改模型文件
- * @return
- */
- @ApiOperation("修改模型文件")
- @RequestMapping(value = "/changeModel", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
- public Result changeModel(HttpServletRequest request) throws Exception{
- String modelId = request.getParameter("modelId");
- String objPath = "";
- if (StringUtil.isEmpty(modelId)){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(Long.parseLong(modelId));
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- modelUploadEntity.setStatus(0);
- modelUploadService.update(modelUploadEntity);
- String path = buildPath + "upload";
- File targetFile = new File(path);
- if (!targetFile.exists()){
- targetFile.mkdirs();
- }
- String filePath = path + File.separator + modelUploadEntity.getFileId() + File.separator;
- List<String> allList = new ArrayList<>();
- FileUtils.readfilePath(filePath, allList);
- for (String fbxPath : allList) {
- if(fbxPath.endsWith(".fbx")){
- String filePth = fbxPath.substring(0, fbxPath.lastIndexOf("/") + 1);
- String fbxName = fbxPath.replace(filePth, "");
- // CreateObjUtil.fbxToObj(filePth, fbxName, fbxName.replace(".fbx", ".obj"));
- OkHttpUtils.httpGet(maxObjUrl + "fbxToObjNoImg?uuid=" + modelUploadEntity.getFileId() +"&fbx=" + fbxName +
- "&obj=mesh.obj&r=30");
- objPath = filePth + "mesh.obj";
- }
- if(fbxPath.endsWith(".udatasmith")){
- }
- }
- if(!new File(objPath).exists()){
- modelUploadEntity.setStatus(-1);
- modelUploadService.update(modelUploadEntity);
- log.error("转换obj数据失败-{}", modelUploadEntity.getFileId());
- return Result.failure(CodeConstant.FAILURE_CODE_4006, CodeConstant.FAILURE_MSG_4006);
- }
- modelUploadEntity.setStatus(1);
- modelUploadEntity.setObjPath(objPath.replace(buildPath, ""));
- modelUploadService.update(modelUploadEntity);
- return Result.success(modelUploadEntity);
- }
- /**
- * 获取模型列表
- * @return
- */
- @ApiOperation("获取模型列表")
- @RequestMapping(value = "/findModelList", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
- @ApiImplicitParam(name = "userName", value = "userName", dataType = "String"),
- @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
- @ApiImplicitParam(name = "pageSize", value = "页数", dataType = "String"),
- @ApiImplicitParam(name = "name", value = "模型名称", dataType = "String")})
- public Result<PageInfo<ResponseRenovationPartsDetailManager>> findModelList(@RequestBody RequestRenovationParts param){
- if (param.getUserId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- if("88888888888".equals(param.getUserName())){
- param.setUserId(null);
- }
- if(StringUtil.isEmpty(param.getName())){
- param.setName(null);
- }
- PageInfo<RenovationPartsDetailEntity> list = renovationPartsDetailService.findAllByUserId(param.getUserId(),
- param.getName(), param.getPageNum(), param.getPageSize());
- List<ResponseRenovationPartsDetailManager> resultList = new ArrayList<>();
- ResponseRenovationPartsDetailManager responseRenovationPartsDetailManager = null;
- for(RenovationPartsDetailEntity renovationPartsDetailEntity : list.getList()){
- responseRenovationPartsDetailManager = new ResponseRenovationPartsDetailManager();
- BeanUtils.copyProperties(renovationPartsDetailEntity, responseRenovationPartsDetailManager);
- RenovationPartsTypeEntity renovationPartsTypeEntity = renovationPartsTypeService.findById(renovationPartsDetailEntity.getPartsTypeId());
- if(renovationPartsTypeEntity != null){
- RenovationPartsEntity renovationPartsEntity = renovationPartsService.findById(renovationPartsTypeEntity.getPartsId());
- if(renovationPartsEntity != null){
- responseRenovationPartsDetailManager.setTypeName(renovationPartsEntity.getDescription() + " > " + renovationPartsTypeEntity.getDescription());
- }
- }
- RenovationPartsColorEntity renovationPartsColorEntity = renovationPartsColorService.findById(renovationPartsDetailEntity.getPartsColorId());
- if(renovationPartsColorEntity != null){
- responseRenovationPartsDetailManager.setColorName(renovationPartsColorEntity.getColorName());
- }
- ResponseRenovationPartsAttaching responseRenovationPartsAttaching = renovationPartsAttachingService.findAttachinByDetailId(renovationPartsDetailEntity.getId());
- if(responseRenovationPartsAttaching != null){
- if(responseRenovationPartsAttaching.isWallAttaching()){
- responseRenovationPartsDetailManager.setAttachingType("wall");
- }
- if(responseRenovationPartsAttaching.isCeilAttaching()){
- responseRenovationPartsDetailManager.setAttachingType("ceil");
- }
- if(responseRenovationPartsAttaching.isFloorAttaching()){
- responseRenovationPartsDetailManager.setAttachingType("floor");
- }
- }
- if(renovationPartsDetailEntity.getPartsClassifyId() != null){
- RenovationPartsClassifyEntity renovationPartsClassifyEntity = renovationPartsClassifyService.findById(renovationPartsDetailEntity.getPartsClassifyId());
- if(renovationPartsClassifyEntity != null){
- responseRenovationPartsDetailManager.setPartsClassifyName(renovationPartsClassifyEntity.getClassifyName());
- }
- }
- if(renovationPartsDetailEntity.getPartsStyleId() != null){
- RenovationPartsStyleEntity renovationPartsStyleEntity = renovationPartsStyleService.findById(renovationPartsDetailEntity.getPartsStyleId());
- if(renovationPartsStyleEntity != null){
- responseRenovationPartsDetailManager.setPartsStyleName(renovationPartsStyleEntity.getStyleName());
- }
- }
- if(renovationPartsDetailEntity.getPartsShapeId() != null){
- RenovationPartsShapeEntity renovationPartsShapeEntity = renovationPartsShapeService.findById(renovationPartsDetailEntity.getPartsShapeId());
- if(renovationPartsShapeEntity != null){
- responseRenovationPartsDetailManager.setPartsShapeName(renovationPartsShapeEntity.getShapeName());
- }
- }
- if(renovationPartsDetailEntity.getPartsBrandId() == null){
- renovationPartsDetailEntity.setPartsBrandId(1L);
- }
- RenovationPartsBrandEntity renovationPartsBrandEntity = renovationPartsBrandService.findById(renovationPartsDetailEntity.getPartsBrandId());
- responseRenovationPartsDetailManager.setBrandName(renovationPartsBrandEntity.getBrandName());
- responseRenovationPartsDetailManager.setPartsBrandId(renovationPartsBrandEntity.getId());
- if(renovationPartsDetailEntity.getCompanyId() != null){
- CompanyEntity companyEntity = companyService.findById(renovationPartsDetailEntity.getCompanyId());
- if(companyEntity != null){
- responseRenovationPartsDetailManager.setCompanyName(companyEntity.getCompanyName());
- }
- }
- resultList.add(responseRenovationPartsDetailManager);
- }
- Page<ResponseRenovationPartsDetailManager> a = new Page<>(param.getPageNum(), param.getPageSize());
- a.setTotal(list.getTotal());
- PageInfo<ResponseRenovationPartsDetailManager> result = a.toPageInfo();
- result.setList(resultList);
- return Result.success(result);
- }
- /**
- * 修改模型详情(编辑,是否显示,删除)
- * @return
- */
- @ApiOperation("修改模型详情(编辑,是否显示,删除)")
- @RequestMapping(value = "/updateModelDetail", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "RequestRenovationPartsDetailManager", value = "json对象里面的参数", dataType = "String")})
- public Result updateModelDetail(@RequestBody RequestRenovationPartsDetailManager param){
- if(param.getId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- if (StringUtils.isBlank(param.getZhName())) {
- return Result.failure(1, "模型名称不能为空");
- }
- RenovationPartsDetailEntity renovationPartsDetailEntity = new RenovationPartsDetailEntity();
- BeanUtils.copyProperties(param, renovationPartsDetailEntity);
- renovationPartsDetailEntity.setExamine(null);
- renovationPartsDetailService.update(renovationPartsDetailEntity);
- if("I".equals(renovationPartsDetailEntity.getRecStatus())){
- ModelUploadEntity modelUploadEntity = modelUploadService.findByPartsDetailId(renovationPartsDetailEntity.getId());
- if(modelUploadEntity != null){
- modelUploadEntity.setRecStatus("I");
- modelUploadService.update(modelUploadEntity);
- }
- }
- RenovationPartsAttachingEntity renovationPartsAttachingEntity = renovationPartsAttachingService.findByDetailId(renovationPartsDetailEntity.getId());
- if(renovationPartsAttachingEntity != null){
- if("wall".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(false);
- renovationPartsAttachingEntity.setWallAttaching(true);
- renovationPartsAttachingEntity.setFloorAttaching(false);
- }
- if("ceil".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(true);
- renovationPartsAttachingEntity.setWallAttaching(false);
- renovationPartsAttachingEntity.setFloorAttaching(false);
- }
- if("floor".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(false);
- renovationPartsAttachingEntity.setWallAttaching(false);
- renovationPartsAttachingEntity.setFloorAttaching(true);
- }
- renovationPartsAttachingService.update(renovationPartsAttachingEntity);
- }
- if(param.getX() != null && param.getY() != null && param.getZ() != null){
- ResponseRenovationPartsSize responseRenovationPartsSize = renovationPartsSizeService.findSizeByDetailId(renovationPartsDetailEntity.getId());
- RenovationPartsSizeEntity renovationPartsSizeEntity = new RenovationPartsSizeEntity();
- renovationPartsSizeEntity.setX(param.getX());
- renovationPartsSizeEntity.setY(param.getY());
- renovationPartsSizeEntity.setZ(param.getZ());
- if(responseRenovationPartsSize != null){
- renovationPartsSizeEntity.setId(responseRenovationPartsSize.getId());
- renovationPartsSizeService.update(renovationPartsSizeEntity);
- }else {
- renovationPartsSizeEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
- renovationPartsSizeService.save(renovationPartsSizeEntity);
- }
- }
- return Result.success();
- }
- /**
- * 新增模型数据
- * @return
- */
- @ApiOperation("新增模型数据")
- @RequestMapping(value = "/addModelDetail", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "RequestRenovationPartsDetailManager", value = "json对象里面的参数", dataType = "String")})
- public Result addModelDetail(@RequestBody RequestRenovationPartsDetailManager param) throws Exception{
- if(param.getModelUploadId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(param.getModelUploadId());
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- //先执行python脚本,处理obj文件
- CreateObjUtil.objHandle(buildPath + modelUploadEntity.getObjPath());
- //obj转换成glb格式
- String glbPath = buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".glb";
- log.info("obj转换成glb格式路径-{}", glbPath);
- CreateObjUtil.objToGlb(buildPath + modelUploadEntity.getObjPath(), glbPath);
- modelUploadEntity.setObjSize((int) new File(buildPath + modelUploadEntity.getObjPath()).length());
- modelUploadService.update(modelUploadEntity);
- //上传obj、mtl、jpg和glb
- String str = FileUtils.readFile(buildPath + "upload/" + modelUploadEntity.getFileId() + "/uploadList.txt");
- JSONArray jsonArray = JSON.parseArray(str);
- for(int i = 0; i < jsonArray.size(); i ++){
- if(jsonArray.getString(i).endsWith(".obj")){
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i).replace("-base.obj", ".obj"),
- "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i).replace("-base.obj", ".obj"));
- }else {
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i),
- "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + jsonArray.getString(i));
- }
- }
- // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".obj", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".obj");
- // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/mesh.mtl", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/mesh.mtl");
- // uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".jpg", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".jpg");
- uploadToOssUtil.uploadTo4dTjw(glbPath, "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + ".glb");
- //保存模型详情
- RenovationPartsDetailEntity renovationPartsDetailEntity = new RenovationPartsDetailEntity();
- BeanUtils.copyProperties(param, renovationPartsDetailEntity);
- renovationPartsDetailEntity.setExamine(0);
- renovationPartsDetailEntity.setName(modelUploadEntity.getFileId());
- renovationPartsDetailEntity.setPath(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + ".glb");
- //入库前先提交模型到模型库,失败返回提示
- String version = SnowFlakeUUidUtils.generaUUid(null, null, null);
- JSONObject jsonObject = new JSONObject();
- JSONArray array = new JSONArray();
- JSONObject object = new JSONObject();
- object.put("Name", renovationPartsDetailEntity.getName());
- object.put("UserID", modelUploadEntity.getUserId());
- String postfix = "datasmith";
- if(modelUploadEntity.getFileType() == 0){
- postfix = "fbx";
- }
- object.put("Postfix", postfix);
- object.put("ObjAliPath", "domain/eHome/furniture/simpleObj-Mtl/" + modelUploadEntity.getFileId());
- array.add(object);
- jsonObject.put("version", version);
- log.info("更新模型库,syncmodel接口参数:" + jsonObject.toJSONString());
- uploadToOssUtil.uploadTo4dTjw(array.toJSONString().getBytes(), "domain/eHome/furniture/syncdata/" +
- version + "/SyncData.json");
- // 加锁,同一个模型只能请求一次3d渲染,防止同一账号在登录多个客户端下同时操作一个模型导致出问题
- Result result;
- synchronized (param.getModelUploadId()) {
- result = synchronizedUpdateModel(param, modelUploadEntity, jsonObject, glbPath, renovationPartsDetailEntity);
- }
- return result;
- }
- private Result synchronizedUpdateModel(RequestRenovationPartsDetailManager param,
- ModelUploadEntity modelUploadEntity,
- JSONObject jsonObject, String glbPath,
- RenovationPartsDetailEntity renovationPartsDetailEntity) throws Exception {
- if (checkReaptPost(param)) {
- log.info("模型已被提交,模型id-{}", param.getModelUploadId());
- return Result.failure(9999, "模型已被提交,模型id-" + param.getModelUploadId());
- }
- String resultData = OkHttpUtils.httpPostJson(buildUrl + "syncmodel", jsonObject.toJSONString());
- JSONObject resultJson = JSONObject.parseObject(resultData);
- if("error".equals(resultJson.getString("state"))){
- log.info("更新模型库,syncmodel接口失败:" + resultData);
- return Result.failure(CodeConstant.FAILURE_CODE_4015, CodeConstant.FAILURE_MSG_4015);
- }
- //判断缩略图是否存在,在就保存缩略图
- String imgPath = glbPath.replace(modelUploadEntity.getFileId() + ".glb", modelUploadEntity.getFileId() + "_preview.jpg");
- if(new File(imgPath).exists()){
- uploadToOssUtil.uploadTo4dTjw(imgPath, "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
- renovationPartsDetailEntity.setImg(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
- renovationPartsDetailEntity.setHighImg(prefix + "domain/eHome/furniture/temp/" + modelUploadEntity.getFileId() + "_preview.jpg");
- }
- //调用obj转换成toolbag文件
- objToToolbagUtil.convertobjTomview(modelUploadEntity.getFileId());
- if(new File(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".4dage").exists()){
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + ".4dage",
- "domain/eHome/furniture/toolbag/" + modelUploadEntity.getFileId() + ".4dage");
- renovationPartsDetailEntity.setHasToolbag(1);
- }
- renovationPartsDetailService.save(renovationPartsDetailEntity);
- if(renovationPartsDetailEntity.getId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4008, CodeConstant.FAILURE_MSG_4008);
- }
- //保存模型位置信息
- RenovationPartsAttachingEntity renovationPartsAttachingEntity = new RenovationPartsAttachingEntity();
- if("wall".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(false);
- renovationPartsAttachingEntity.setWallAttaching(true);
- renovationPartsAttachingEntity.setFloorAttaching(false);
- }
- if("ceil".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(true);
- renovationPartsAttachingEntity.setWallAttaching(false);
- renovationPartsAttachingEntity.setFloorAttaching(false);
- }
- if("floor".equals(param.getAttachingType())){
- renovationPartsAttachingEntity.setCeilAttaching(false);
- renovationPartsAttachingEntity.setWallAttaching(false);
- renovationPartsAttachingEntity.setFloorAttaching(true);
- }
- renovationPartsAttachingEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
- renovationPartsAttachingService.save(renovationPartsAttachingEntity);
- if(param.getX() != null && param.getY() != null && param.getZ() != null){
- RenovationPartsSizeEntity renovationPartsSizeEntity = new RenovationPartsSizeEntity();
- renovationPartsSizeEntity.setX(param.getX());
- renovationPartsSizeEntity.setY(param.getY());
- renovationPartsSizeEntity.setZ(param.getZ());
- renovationPartsSizeEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
- renovationPartsSizeService.save(renovationPartsSizeEntity);
- }
- //修改上传信息,关联模型id
- modelUploadEntity.setPartsDetailId(renovationPartsDetailEntity.getId());
- int row = modelUploadService.update(modelUploadEntity);
- log.info("执行行数-{}", row);
- return Result.success();
- }
- private boolean checkReaptPost(RequestRenovationPartsDetailManager param) {
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(param.getModelUploadId());
- if (modelUploadEntity.getPartsDetailId() != null) {
- return true;
- }
- return false;
- }
- /**
- * 获取所有企业信息
- * @return
- */
- @ApiOperation("获取所有企业信息")
- @RequestMapping(value = "/findCompanyList", method = RequestMethod.POST)
- public Result findCompanyList(){
- return Result.success(companyService.findAll());
- }
- /**
- * 更新模型审核状态
- * @return
- */
- @ApiOperation("更新模型审核状态")
- @RequestMapping(value = "/updatePartsDetailExamine", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "模型id", dataType = "String"),
- @ApiImplicitParam(name = "examine", value = "审核,0审核中,1审核通过,-1审核失败", dataType = "String")})
- public Result updatePartsDetailExamine(@RequestBody RequestRenovationPartsDetailManager param){
- if(param.getId() == null || param.getExamine() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- RenovationPartsDetailEntity renovationPartsDetailEntity = renovationPartsDetailService.findById(param.getId());
- renovationPartsDetailEntity.setId(param.getId());
- renovationPartsDetailEntity.setExamine(param.getExamine());
- renovationPartsDetailEntity.setExamineTime(new Date());
- if(param.getExamine().intValue() == 1){
- uploadToOssUtil.copyTo4dTjw(renovationPartsDetailEntity.getImg().replace(prefix, ""),
- renovationPartsDetailEntity.getImg().replace("/temp/", "/models/").replace(prefix, ""));
- uploadToOssUtil.copyTo4dTjw(renovationPartsDetailEntity.getPath().replace(prefix, ""),
- renovationPartsDetailEntity.getPath().replace("/temp/", "/models/").replace(prefix, ""));
- uploadToOssUtil.deleteTo4dTjw(renovationPartsDetailEntity.getImg().replace(prefix, ""));
- uploadToOssUtil.deleteTo4dTjw(renovationPartsDetailEntity.getPath().replace(prefix, ""));
- renovationPartsDetailEntity.setImg(renovationPartsDetailEntity.getImg().replace("/temp/", "/models/"));
- renovationPartsDetailEntity.setHighImg(renovationPartsDetailEntity.getHighImg().replace("/temp/", "/models/"));
- renovationPartsDetailEntity.setPath(renovationPartsDetailEntity.getPath().replace("/temp/", "/models/"));
- }
- renovationPartsDetailService.update(renovationPartsDetailEntity);
- return Result.success();
- }
- /**
- * 通过id查询上传模型进度
- * @param param
- * @return
- */
- @ApiOperation("通过id查询上传模型进度")
- @RequestMapping(value = "/findUploadModelById", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
- public Result findUploadModelById(@RequestBody RequestRenovationPartsDetailManager param){
- if(param.getId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- return Result.success(modelUploadService.findById(param.getId()));
- }
- /**
- * 通过模型详情id查询上传模型的信息
- * @param param
- * @return
- */
- @ApiOperation("通过模型详情id查询上传模型的信息")
- @RequestMapping(value = "/findUploadModelByPartsDetailId", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
- public Result findUploadModelByPartsDetailId(@RequestBody RequestRenovationPartsDetailManager param){
- if(param.getId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- return Result.success(modelUploadService.findByPartsDetailId(param.getId()));
- }
- /**
- * 根据用户id,查询所有未发布的上传模型
- * @param param
- * @return
- */
- @ApiOperation("根据用户id,查询所有未发布的上传模型")
- @RequestMapping(value = "/findIsNotPartsDetailId", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")})
- public Result findIsNotPartsDetailId(@RequestBody RequestRenovationParts param){
- if(param.getUserId() == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- return Result.success(modelUploadService.findIsNotPartsDetailId(param.getUserId()));
- }
- /**
- * 根据上传id,删除上传模型
- * @param param
- * @return
- */
- @ApiOperation("根据上传id,删除上传模型")
- @RequestMapping(value = "/deleteUploadModel", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "ids", value = "id的集合用逗号分割", dataType = "String")})
- public Result deleteUploadModel(@RequestBody RequestRenovationParts param){
- if(StringUtil.isEmpty(param.getIds())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String[] idArray = param.getIds().split(",");
- ModelUploadEntity modelUploadEntity = new ModelUploadEntity();
- for (String id : idArray) {
- modelUploadEntity.setId(Long.valueOf(id));
- modelUploadEntity.setRecStatus("I");
- modelUploadService.update(modelUploadEntity);
- }
- return Result.success();
- }
- /**
- * 生成封面图
- * @return
- */
- @ApiOperation("生成封面图")
- @RequestMapping(value = "/createImg", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "jsonData", value = "json数据", dataType = "String"),
- @ApiImplicitParam(name = "modelId", value = "模型id", dataType = "String")})
- public Result createImg(Long modelId, String jsonData) throws Exception {
- if(StringUtils.isEmpty(jsonData) || modelId == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(modelId);
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- modelUploadEntity.setThumStatus(0);
- rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.LIGHT,
- modelUploadEntity.getFileId() + ":;" + modelUploadEntity.getUserId() + ":;" +
- modelUploadEntity.getId() + ":;" + jsonData + ":;modelPreview");
- modelUploadService.update(modelUploadEntity);
- return Result.success();
- }
- /**
- * 根据模型id查询模型详情
- * @return
- */
- @ApiOperation("根据模型id查询模型详情")
- @RequestMapping(value = "/findModelById", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
- public Result findModelById(Long id) throws Exception {
- if(id == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(id);
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- return Result.success(modelUploadEntity);
- }
- /**
- * 根据模型id修改模型缓存数据
- * @return
- */
- @ApiOperation("根据模型id修改模型缓存数据")
- @RequestMapping(value = "/updateModelCacheData", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "cacheData", value = "缓存的json", dataType = "String"),
- @ApiImplicitParam(name = "id", value = "模型id", dataType = "String")})
- public Result updateModelCacheData(Long id, String cacheData) throws Exception {
- if(id == null){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- ModelUploadEntity modelUploadEntity = modelUploadService.findById(id);
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- modelUploadEntity.setCacheData(cacheData);
- modelUploadService.update(modelUploadEntity);
- return Result.success(modelUploadEntity);
- }
- /**
- * 上传指定的fileId里面的obj文件
- * @return
- */
- @ApiOperation("上传指定的fileId里面的obj文件")
- @RequestMapping(value = "/uploadObj", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
- public Result uploadObj(@RequestBody RequestRenovationParts param){
- if(StringUtil.isEmpty(param.getName())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String[] fileIdArr = param.getName().split(",");
- for (String fileId : fileIdArr) {
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".obj",
- "domain/eHome/furniture/simpleObj-Mtl/" + fileId + "/" + fileId + ".obj");
- }
- return Result.success();
- }
- /**
- * 上传指定的fileId里面的obj文件
- * @return
- */
- @ApiOperation("修改glb")
- @RequestMapping(value = "/updateGlb", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
- public Result updateGlb(@RequestBody RequestRenovationParts param) throws Exception{
- if(StringUtil.isEmpty(param.getName())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- int compressionRatio = 3000;
- String[] fileIdArr = param.getName().split(",");
- for (String fileId : fileIdArr) {
- String path = buildPath + "upload/" + fileId + "/data.json";
- if(new File(path).exists()){
- JSONObject json = JSONObject.parseObject(FileUtils.readFile(path));
- compressionRatio = json.getIntValue("compressionRatio");
- }
- OkHttpUtils.httpGet(maxObjUrl + "objToObj?uuid=" + fileId +"&inObj=" + fileId +
- "-base.obj&outObj=" + fileId + ".obj&r=" + compressionRatio);
- String glbPath = buildPath + "upload/" + fileId + "/" + fileId + ".glb";
- CreateObjUtil.objToGlb(buildPath + "upload/" + fileId + "/" + fileId + ".obj", glbPath);
- log.info("glb生成完成:" + fileId);
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".glb",
- "domain/eHome/furniture/models/" + fileId + ".glb");
- uploadToOssUtil.uploadTo4dTjw(buildPath + "upload/" + fileId + "/" + fileId + ".glb",
- "domain/eHome/furniture/temp/" + fileId + ".glb");
- }
- return Result.success();
- }
- /**
- * obj转换成Toolbag文件
- * @return
- */
- @ApiOperation("obj转换成Toolbag文件")
- @RequestMapping(value = "/objToToolbag", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name", value = "多个以逗号分割", dataType = "String")})
- public Result objToToolbag(@RequestBody RequestRenovationParts param) throws Exception{
- if(StringUtil.isEmpty(param.getName())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String[] fileIdArr = param.getName().split(",");
- for (String fileId : fileIdArr) {
- objToToolbagUtil.convertobjTomview(fileId);
- log.info(fileId + "转换Toolbag结束");
- }
- return Result.success();
- }
- }
|