|
@@ -0,0 +1,224 @@
|
|
|
|
+package com.fdkk.sxz.other.listener;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.fdkk.sxz.base.Result;
|
|
|
|
+import com.fdkk.sxz.constant.CodeConstant;
|
|
|
|
+import com.fdkk.sxz.entity.ModelUploadEntity;
|
|
|
|
+import com.fdkk.sxz.entity.RenovationPartsAttachingEntity;
|
|
|
|
+import com.fdkk.sxz.entity.RenovationPartsDetailEntity;
|
|
|
|
+import com.fdkk.sxz.entity.RenovationPartsSizeEntity;
|
|
|
|
+import com.fdkk.sxz.other.mq.TopicRabbitConfig;
|
|
|
|
+import com.fdkk.sxz.util.*;
|
|
|
|
+import com.fdkk.sxz.vo.request.RequestRenovationPartsDetailManager;
|
|
|
|
+import com.fdkk.sxz.webApi.service.*;
|
|
|
|
+import com.fdkk.sxz.webApi.service.custom.ICustomComponentService;
|
|
|
|
+import com.fdkk.sxz.webApi.service.custom.ICustomProductService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.messaging.Message;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author Xiewj
|
|
|
|
+ * @date 2021/11/12
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+@Slf4j
|
|
|
|
+public class AddMoldelBuild {
|
|
|
|
+
|
|
|
|
+ @Value("${server.file.location}")
|
|
|
|
+ private String buildPath;
|
|
|
|
+ @Value("${build.url}")
|
|
|
|
+ private String buildUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${max.obj.url}")
|
|
|
|
+ private String maxObjUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${prefix.ali}")
|
|
|
|
+ private String prefix;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IRenovationPartsAttachingService renovationPartsAttachingService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IRenovationPartsSizeService renovationPartsSizeService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IComponentModelUploadService componentModelUploadService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IModelUploadService modelUploadService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IRenovationPartsDetailService renovationPartsDetailService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICustomProductService customProductService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICustomComponentService customComponentService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ObjToToolbagUtil objToToolbagUtil;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @RabbitHandler
|
|
|
|
+ @RabbitListener(queues = TopicRabbitConfig.ADDMODEL)
|
|
|
|
+ public void syncModel(Message<RequestRenovationPartsDetailManager> message) {
|
|
|
|
+ AddMoldelBuild.log.info("模型syncmodel:" + message.getPayload() + ",开始同步");
|
|
|
|
+ syncModelHandler(message.getPayload());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void syncModelHandler(RequestRenovationPartsDetailManager param) {
|
|
|
|
+ String token = RedisUtil.tryLock(param.getModelUploadId().toString(), 60 * 1000);
|
|
|
|
+ ModelUploadEntity modelUploadEntity = modelUploadService.findById(param.getModelUploadId());
|
|
|
|
+ try {
|
|
|
|
+ if (token != null) {
|
|
|
|
+ //上锁保证只有一个在消费,加锁一分钟,成功消费就解锁了
|
|
|
|
+ if (modelUploadEntity == null) {
|
|
|
|
+ throw new RuntimeException("模型不存在!");
|
|
|
|
+ }
|
|
|
|
+ //先执行python-NewResortForOne脚本,处理obj文件
|
|
|
|
+ CreateObjUtil.objHandle(buildPath + modelUploadEntity.getObjPath());
|
|
|
|
+
|
|
|
|
+ //上传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));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //保存模型详情
|
|
|
|
+ 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 imgPath = buildPath + "upload/" + modelUploadEntity.getFileId() + "/" + modelUploadEntity.getFileId() + "_preview.jpg";
|
|
|
|
+
|
|
|
|
+ // 加锁,同一个模型只能请求一次3d渲染,防止同一账号在登录多个客户端下同时操作一个模型导致出问题
|
|
|
|
+ Result result;
|
|
|
|
+ synchronized (param.getModelUploadId()) {
|
|
|
|
+ result = synchronizedupdateByIdModel(param, modelUploadEntity, imgPath, renovationPartsDetailEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ AddMoldelBuild.log.error("提交模型保存-{}", e.getMessage());
|
|
|
|
+ if (ObjectUtil.isNotNull(modelUploadEntity)) {
|
|
|
|
+ modelUploadEntity.setAddStatus(-1);
|
|
|
|
+ modelUploadService.updateById(modelUploadEntity);
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
|
|
+ if (token != null) {
|
|
|
|
+ RedisUtil.unlock(param.getModelUploadId().toString(), token);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Result synchronizedupdateByIdModel(RequestRenovationPartsDetailManager param,
|
|
|
|
+ ModelUploadEntity modelUploadEntity, String imgPath,
|
|
|
|
+ RenovationPartsDetailEntity renovationPartsDetailEntity) throws Exception {
|
|
|
|
+ if (checkReaptPost(param)) {
|
|
|
|
+ AddMoldelBuild.log.info("模型已被提交,模型id-{}", param.getModelUploadId());
|
|
|
|
+ return Result.failure(9999, "模型已被提交,模型id-" + param.getModelUploadId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //判断缩略图是否存在,在就保存缩略图
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ renovationPartsDetailEntity.setMviewStatus(1);
|
|
|
|
+ Boolean saveFlag = renovationPartsDetailService.save(renovationPartsDetailEntity);
|
|
|
|
+ if (!saveFlag) {
|
|
|
|
+ return Result.failure(CodeConstant.FAILURE_CODE_4008, CodeConstant.FAILURE_MSG_4008);
|
|
|
|
+ }
|
|
|
|
+ String messageStr = renovationPartsDetailEntity.getId() + ":;1:;" + buildPath + modelUploadEntity.getObjPath().replace(
|
|
|
|
+ ".obj", ".fdage") + ":;" + modelUploadEntity.getFileId();
|
|
|
|
+ AddMoldelBuild.log.info("配件obj转换成mview格式");
|
|
|
|
+ Map<String, String> paramsMap = new HashMap<>();
|
|
|
|
+ paramsMap.put("uuid", modelUploadEntity.getFileId());
|
|
|
|
+ paramsMap.put("inObj", buildPath + modelUploadEntity.getObjPath());
|
|
|
|
+ paramsMap.put("outFilePath", buildPath + modelUploadEntity.getObjPath().replace(".obj", ""));
|
|
|
|
+ paramsMap.put("resData", messageStr);
|
|
|
|
+ OkHttpUtils.httpPostForm(maxObjUrl + "toToolbag", paramsMap);
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ //保存模型位置信息
|
|
|
|
+ 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());
|
|
|
|
+ modelUploadEntity.setAddStatus(2);
|
|
|
|
+ Boolean row = modelUploadService.updateById(modelUploadEntity);
|
|
|
|
+ AddMoldelBuild.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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|