Browse Source

同步接口增加文件推送ESC任务

xiewenjie 3 years ago
parent
commit
57333ca5fb

+ 2 - 2
sxz-application/src/main/resources/application-dev.properties

@@ -19,9 +19,9 @@ spring.servlet.multipart.enabled=true
 spring.mvc.async.request-timeout=600000
 spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/data/, classpath:/static/, file:${server.file.location}
 #数据库配置
-spring.datasource.url=jdbc:mysql://192.168.0.47:3306/change_clothes_x?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+spring.datasource.url=jdbc:mysql://47.115.41.194:3306/change_clothes?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
 spring.datasource.username=root
-spring.datasource.password=123123
+spring.datasource.password=4dyjkz%
 # Hikari will use the above plus the following to setup connection pooling
 spring.datasource.type=com.zaxxer.hikari.HikariDataSource
 spring.datasource.hikari.minimum-idle=5

+ 7 - 1
sxz-core/src/main/java/com/fdkk/sxz/other/listener/RunBuild.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.file.FileReader;
 import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
@@ -20,6 +21,7 @@ import com.fdkk.sxz.util.*;
 import com.fdkk.sxz.webApi.service.*;
 import com.fdkk.sxz.webApi.service.custom.ICustomComponentService;
 import lombok.extern.slf4j.Slf4j;
+import org.slf4j.MDC;
 import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -110,7 +112,10 @@ public class RunBuild {
     @RabbitListener(queues = TopicRabbitConfig.MODEL)
     public void model(String str) {
         RunBuild.log.info("模型转换:" + str);
+        String traceId = IdUtil.getSnowflake().nextIdStr();
+        MDC.put("TRACE_ID", traceId);
         modelBuild(str);
+        MDC.clear();
     }
 
     @RabbitHandler
@@ -800,7 +805,7 @@ public class RunBuild {
         //上锁保证只有一个在消费,加锁一个钟,成功消费就解锁了
         String token = RedisUtil.tryLock(fileId, 60 * 60 * 1000);
         if (token != null) {
-            RunBuild.log.info("暂无的fileId:" + fileId + "消费,继续执行处理逻辑");
+            RunBuild.log.info("暂无的fileId:" + fileId + "消费,继续执行处理逻辑模型上传逻辑");
             try {
                 String path = buildPath + "upload";
                 String filePath = path + File.separator + fileId + File.separator;
@@ -1190,6 +1195,7 @@ public class RunBuild {
 
 
             } finally {
+                MDC.clear();
                 if (token != null) {
                     RedisUtil.unlock(fileId, token);
                 }

+ 22 - 2
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/DataBucketController.java

@@ -1,9 +1,13 @@
 package com.fdkk.sxz.webApi.controller;
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.TimeInterval;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RuntimeUtil;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.fdkk.sxz.annotation.auth.NoAuthentication;
 import com.fdkk.sxz.annotation.log.AroundLog;
 import com.fdkk.sxz.base.Result;
@@ -23,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.File;
+import java.util.List;
 
 /**
  * @author Xiewj
@@ -90,10 +95,25 @@ public class DataBucketController {
             //step 2 数据上传到OSS
             DataBucketController.log.info("上传开始");
             String version = IdUtil.getSnowflake().nextIdStr();
-            uploadToOssUtil.uploadTo4dTjw(res.toJSONString().getBytes(), "domain/sxz/DataBucket/syncData/" + version + "/SyncData.json");
+            String FileName = "domain/sxz/DataBucket/syncData/" + version + "/SyncData.json";
+            uploadToOssUtil.uploadTo4dTjw(res.toJSONString().getBytes(), FileName);
             DataBucketController.log.info("上传结束,上传版本号={}", version);
             //step 3 返回json地址
-
+            if (uploadToOssUtil.existFileToOSS(FileName, "4d-tjw")) {
+                res.forEach(a -> {
+                    JSONObject json = (JSONObject) JSONObject.toJSON(a);
+                    if (json.containsKey("escFilePath")) {
+                        String escFilePath = json.getString("escFilePath");
+                        TimeInterval timer = DateUtil.timer();
+                        timer.start();
+                        List<String> cmdRes = RuntimeUtil.execForLines("bash /home/uploadToEsc.sh ", escFilePath);
+                        DataBucketController.log.info("上传耗时{}", timer.intervalMs());
+                        cmdRes.forEach(c -> {
+                            DataBucketController.log.info("上传文件至ESC{}", c);
+                        });
+                    }
+                });
+            }
             ////step 4 发送到任务处理
             //String resultData = OkHttpUtils.httpGet(mainUrl + "/change/data/dataPush/" + version + "/type/" + param.getType());
             //JSONObject resultJson = JSON.parseObject(resultData)    ;

+ 1 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/custom/impl/CustomComponentServiceImpl.java

@@ -172,6 +172,7 @@ public class CustomComponentServiceImpl extends BaseServiceImpl<ICustomComponent
             /****1:处理 tb_custom_component 表 *****/
             JSONObject entity = (JSONObject) JSONObject.toJSON(a);
             entity.remove("id");
+            entity.put("escFilePath", a.getFileId());
             res.add(entity);
         });
         CustomComponentServiceImpl.log.info("数据准备完毕");

+ 29 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/custom/impl/CustomProductServiceImpl.java

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fdkk.sxz.base.Result;
 import com.fdkk.sxz.base.impl.BaseServiceImpl;
 import com.fdkk.sxz.entity.ComponentModelUploadEntity;
+import com.fdkk.sxz.entity.ModelUploadEntity;
 import com.fdkk.sxz.entity.custuom.CustomComponentClassifyEntity;
 import com.fdkk.sxz.entity.custuom.CustomComponentEntity;
 import com.fdkk.sxz.entity.custuom.CustomProductEntity;
@@ -216,9 +217,20 @@ public class CustomProductServiceImpl extends BaseServiceImpl<ICustomProductMapp
                         componentsEntity.remove("id");
                         entityChild.add(componentsEntity);
                     }
+                    /****4:处理 tb_model_upload 表 *****/
+                    ModelUploadEntity uploadModel = modelUploadService.findByFileId(a.getName());
+                    if (ObjectUtil.isNotNull(uploadModel)) {
+                        entity.put("escFilePath", uploadModel.getFileId());
+                        JSONObject cache = JSON.parseObject(uploadModel.getCacheData());
+                        JSONObject uploadModelJson = (JSONObject) JSONObject.toJSON(uploadModel);
+                        uploadModelJson.put("cacheData", cache);
+                        entity.put("uploadModel", uploadModelJson);
+                    }
                 });
             }
             entity.put("child", entityChild);
+
+
             res.add(entity);
         });
         CustomProductServiceImpl.log.info("数据准备完毕");
@@ -253,6 +265,23 @@ public class CustomProductServiceImpl extends BaseServiceImpl<ICustomProductMapp
                                 }
                             });
                         }
+                        /****4:处理 tb_model_upload 表 *****/
+                        if (customProductJson.containsKey("uploadModel")) {
+                            JSONObject uploadModelJson = customProductJson.getJSONObject("uploadModel");
+                            ModelUploadEntity uploadModel = JSONObject.toJavaObject(uploadModelJson, ModelUploadEntity.class);
+                            ModelUploadEntity uploadModelS = modelUploadService.findByFileId(uploadModel.getFileId());
+                            if (ObjectUtil.isNull(uploadModelS)) {
+                                uploadModel.setPartsDetailId(entity.getId());
+                                uploadModel.setUserId(371L);
+                                boolean saveAttaching = modelUploadService.save(uploadModel);
+                                if (saveAttaching && uploadModelJson.containsKey("cacheData")) {
+                                    JSONObject cache = uploadModelJson.getJSONObject("cacheData");
+                                    uploadModel.setCacheData(cache.toJSONString());
+                                    modelUploadService.updateById(uploadModel);
+                                }
+                                CustomProductServiceImpl.log.info("tb_model_upload保存结果{}", saveAttaching);
+                            }
+                        }
                     }
                     CustomProductServiceImpl.log.info("定制模型保存ids数量{}", ids.size());
                     if (ids.size() > 0) {

+ 11 - 3
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/ModelUploadServiceImpl.java

@@ -295,9 +295,17 @@ public class ModelUploadServiceImpl extends BaseServiceImpl<IModelUploadMapper,
 
         if (ObjectUtil.isNotNull(entity.getCacheData())) {
             JSONObject cache = JSONObject.parseObject(entity.getCacheData());
-            responseModelCustomUpload.setWidth(cache.getDouble("width"));
-            responseModelCustomUpload.setDepth(cache.getDouble("depth"));
-            responseModelCustomUpload.setHeight(cache.getDouble("height"));
+            if (cache.containsKey("cacheData")) {
+                JSONObject cacheData = cache.getJSONObject("cacheData");
+                responseModelCustomUpload.setWidth(cacheData.getDouble("width"));
+                responseModelCustomUpload.setDepth(cacheData.getDouble("depth"));
+                responseModelCustomUpload.setHeight(cacheData.getDouble("height"));
+            } else {
+                responseModelCustomUpload.setWidth(cache.getDouble("width"));
+                responseModelCustomUpload.setDepth(cache.getDouble("depth"));
+                responseModelCustomUpload.setHeight(cache.getDouble("height"));
+            }
+
         }
         if (entity.getStatus() != -1) {
             JSONArray componentArray = new JSONArray();

+ 1 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/service/impl/RenovationPartsDetailServiceImpl.java

@@ -106,6 +106,7 @@ public class RenovationPartsDetailServiceImpl extends BaseServiceImpl<IRenovatio
             /****1:处理 tb_renovation_parts_detail 表 *****/
             JSONObject entity = (JSONObject) JSONObject.toJSON(a);
             entity.remove("id");
+            entity.put("escFilePath", a.getName());
             /****2:处理 tb_renovation_parts_size 表 *****/
             ResponseRenovationPartsSize partsSize = renovationPartsSizeService.findSizeByDetailId(a.getId());
             if (ObjectUtil.isNotNull(partsSize)) {