Sfoglia il codice sorgente

钉钉告警添加-未完成
ManagerController-重复提交问题

zhujinghui 4 anni fa
parent
commit
1beb69cf4c

+ 11 - 2
src/main/java/com/example/demo/controller/ManagerController.java

@@ -601,8 +601,18 @@ public class ManagerController {
         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;
+    }
 
-        //todo 判断是否已经重复提交, 后续删掉这个判断,看log日志,现临时解决,
+    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());
@@ -615,7 +625,6 @@ public class ManagerController {
             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()){

+ 106 - 55
src/main/java/com/example/demo/listener/RunBuild.java

@@ -94,6 +94,10 @@ public class RunBuild {
     }
 
 
+    /**
+     * 场景渲染
+     * @param data
+     */
     private void buildCopy(String data) {
         String[] datas = data.split(":;");
         String vrNum = datas[0];
@@ -546,7 +550,7 @@ public class RunBuild {
 
                                 if(objectJson.containsKey("progress")){
                                     Integer progress = objectJson.getInteger("progress");
-                                    log.info("第{}次获取上传进度,进度为{}%", times++, progress);
+                                    log.info("第{}次获取渲染进度,进度为{}%", times++, progress);
                                     SceneLightEntity sceneLightEntity = new SceneLightEntity();
                                     sceneLightEntity.setId(Long.valueOf(taskId));
                                     sceneLightEntity.setProgress(progress);
@@ -645,6 +649,10 @@ public class RunBuild {
         }
     }
 
+    /**
+     * 模型上传
+     * @param data
+     */
     private void modelBuild(String data){
         String[] datas = data.split(":;");
         String modelUploadId = datas[0];
@@ -873,6 +881,10 @@ public class RunBuild {
         }
     }
 
+    /**
+     * 生成封面图
+     * @param data
+     */
     private void modelCreatThum(String data){
         String[] datas = data.split(":;");
         String fileId = datas[0];
@@ -892,63 +904,12 @@ public class RunBuild {
             jsonObject.put("taskType", taskType);
             jsonObject.put("taskId", userId);
             jsonObject.put("params1", JSONObject.parseObject(dataJson).getJSONObject("Param1"));
-            while (true){
-                String buildResult = OkHttpUtils.httpPostJson(modelBuildUrl + "pro", jsonObject.toJSONString());
-                JSONObject buildJson = JSONObject.parseObject(buildResult);
-
-                if("isBusy".equals(buildJson.getString("msg"))){
-                    Thread.sleep(2000L);
-                    continue;
-                }
-
-                if("error".equals(buildJson.getString("state"))){
-                    FileUtils.writeFile(filePath + "/error-pro-thum.json", buildJson.toJSONString());
-                    throw new RuntimeException(fileId + ":" + taskType + "方式pro接口返回error错误");
-                }
 
-                break;
-            }
+            postExaggerateSurace(fileId, modelId, taskType, filePath, jsonObject);
 
             Thread.sleep(1000L);
-            boolean over = false;
-            while (true) {
-                String checkResult = OkHttpUtils.httpPostJson(modelBuildUrl + "check", jsonObject.toJSONString());
-                JSONObject checkJson = JSONObject.parseObject(checkResult);
-
-                JSONArray checkArray = checkJson.getJSONArray("msg");
-
-                if (checkArray.size() == 0) {
-                    FileUtils.writeFile(filePath + "/error-check-thum.json", checkJson.toJSONString());
-                    throw new RuntimeException(fileId + ":" + taskType + "方式check接口返回error错误");
-                }
-
-                for(int i = 0, len = checkArray.size(); i < len; i++){
-                    JSONObject objectJson = checkArray.getJSONObject(i);
-
-                    if("error".equals(objectJson.getString("state"))){
-                        FileUtils.writeFile(filePath + "/error-check-thum.json", checkJson.toJSONString());
-                        throw new RuntimeException(fileId + ":" + taskType + "方式check接口返回error错误");
-                    }
-
-                    if(objectJson.containsKey("state") && ("".equals(objectJson.getString("state")) ||
-                            "done".equals(objectJson.getString("state")) )){
-                        over = true;
-                    }
-
-                    if(objectJson.containsKey("progress")){
-                        modelUploadEntity = new ModelUploadEntity();
-                        modelUploadEntity.setId(Long.valueOf(modelId));
-                        modelUploadEntity.setProgress(objectJson.getInteger("progress"));
-                        modelUploadService.update(modelUploadEntity);
-                    }
-                }
-
-                if(over){
-                    break;
-                }
 
-                Thread.sleep(1000L);
-            }
+            checkExaggerateSurace(jsonObject, filePath, fileId, modelId, taskType);
 
             uploadToOssUtil.downloadFileTo4dTjw("domain/eHome/furniture/ue4data/" + fileId + "/" + fileId + "_preview.jpg", filePath + fileId + "_preview.jpg");
             modelUploadEntity = new ModelUploadEntity();
@@ -957,7 +918,7 @@ public class RunBuild {
             modelUploadEntity.setProgress(100);
             modelUploadService.update(modelUploadEntity);
         }catch (Exception e){
-            e.printStackTrace();
+            log.error("生成封面失败-{}", e);
             modelUploadEntity = new ModelUploadEntity();
             modelUploadEntity.setId(Long.valueOf(modelId));
             modelUploadEntity.setThumStatus(-1);
@@ -965,4 +926,94 @@ public class RunBuild {
         }
 
     }
+
+    /**
+     * 轮询检查渲染接口
+     * @param jsonObject
+     * @param filePath
+     * @param fileId
+     * @param modelId
+     * @param taskType
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    private void checkExaggerateSurace(JSONObject jsonObject,
+                                       String filePath,
+                                       String fileId,
+                                       String modelId,
+                                       String taskType
+                                       ) throws IOException, InterruptedException {
+        boolean over = false;
+        while (true) {
+            String checkResult = OkHttpUtils.httpPostJson(modelBuildUrl + "check", jsonObject.toJSONString());
+            JSONObject checkJson = JSONObject.parseObject(checkResult);
+
+            JSONArray checkArray = checkJson.getJSONArray("msg");
+
+            if (checkArray.size() == 0) {
+                FileUtils.writeFile(filePath + "/error-check-thum.json", checkJson.toJSONString());
+                throw new RuntimeException(fileId + ":" + taskType + "方式check接口返回error错误");
+            }
+
+            for(int i = 0, len = checkArray.size(); i < len; i++){
+                JSONObject objectJson = checkArray.getJSONObject(i);
+
+                if("error".equals(objectJson.getString("state"))){
+                    FileUtils.writeFile(filePath + "/error-check-thum.json", checkJson.toJSONString());
+                    throw new RuntimeException(fileId + ":" + taskType + "方式check接口返回error错误");
+                }
+
+                if(objectJson.containsKey("state") && ("".equals(objectJson.getString("state")) ||
+                        "done".equals(objectJson.getString("state")) )){
+                    over = true;
+                }
+
+                if(objectJson.containsKey("progress")){
+                    ModelUploadEntity modelUploadEntity = new ModelUploadEntity();
+                    modelUploadEntity.setId(Long.valueOf(modelId));
+                    modelUploadEntity.setProgress(objectJson.getInteger("progress"));
+                    modelUploadService.update(modelUploadEntity);
+                }
+            }
+
+            if(over){
+                break;
+            }
+
+            Thread.sleep(1000L);
+        }
+    }
+
+    /**
+     * 请求封面渲染接口获取接口数据
+     * @param fileId
+     * @param modelId
+     * @param taskType
+     * @param filePath
+     * @param jsonObject
+     * @throws InterruptedException
+     * @throws IOException
+     */
+    private void postExaggerateSurace(String fileId, String modelId, String taskType, String filePath, JSONObject jsonObject) throws InterruptedException, IOException {
+        while (true){
+            String url = modelBuildUrl + "pro";
+            String json = jsonObject.toJSONString();
+            log.info("modelId-{}, 请求封面渲染接口获取接口数据-{},参数-{}", modelId, json);
+            String buildResult = OkHttpUtils.httpPostJson(url, json);
+            JSONObject buildJson = JSONObject.parseObject(buildResult);
+            log.info("请求封面渲染接口返回数据-{}", buildJson);
+
+            if("isBusy".equals(buildJson.getString("msg"))){
+                Thread.sleep(2000L);
+                continue;
+            }
+
+            if("error".equals(buildJson.getString("state"))){
+                FileUtils.writeFile(filePath + "/error-pro-thum.json", buildJson.toJSONString());
+                throw new RuntimeException(fileId + ":" + taskType + "方式pro接口返回error错误");
+            }
+
+            break;
+        }
+    }
 }