Explorar o código

解耦接口调用

xiewenjie %!s(int64=3) %!d(string=hai) anos
pai
achega
77b87de122

+ 2 - 55
sxz-application/src/main/java/com.fdkk.sxz/main.java

@@ -1,15 +1,10 @@
 package com.fdkk.sxz;
 
 
-import okhttp3.*;
-import okio.ByteString;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import cn.hutool.http.HttpUtil;
 
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
 
 public class main {
     //public static void main(String[] args) {
@@ -192,56 +187,8 @@ public class main {
 
 
     public static void main(String[] args) throws URISyntaxException, ExecutionException, InterruptedException {
-        URI uri = new URI("ws://192.168.0.75:8223/wss/maxToDataSmith/");
-        synchronized (uri.getPath()) {
-            main.getsocket();
-        }
-        System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
-    }
-
-    private synchronized static void getsocket() {
-        Request request = new Request.Builder().url("ws://127.0.0.1:8223/wss/maxToDataSmith/").build();
-        OkHttpClient mOkHttpClient = new OkHttpClient.Builder()
-                .readTimeout(3, TimeUnit.SECONDS)//设置读取超时时间
-                .writeTimeout(3, TimeUnit.SECONDS)//设置写的超时时间
-                .connectTimeout(3, TimeUnit.SECONDS)//设置连接超时时间
-                .build();
-
-        WebSocketListener socketListener = new WebSocketListener() {
-            @Override
-            public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
-                super.onClosed(webSocket, code, reason);
-            }
-
-            @Override
-            public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
-                super.onClosing(webSocket, code, reason);
-            }
-
-            @Override
-            public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) {
-                super.onFailure(webSocket, t, response);
-            }
-
-            @Override
-            public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
-                super.onMessage(webSocket, text);
-                System.out.println(text);
-            }
-
-            @Override
-            public void onMessage(@NotNull WebSocket webSocket, @NotNull ByteString bytes) {
-                super.onMessage(webSocket, bytes);
-            }
+        String result = HttpUtil.get("http://192.168.0.26:8081/" + "change/fbxToObj/dataPush/asdasdasdasd");
 
-            @Override
-            public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
-                super.onOpen(webSocket, response);
-                webSocket.send("{\"uuid\":\"111222333\",\"max\":\"111222333.max\",\"flag\":\"false\"}");
-            }
-        };
-        mOkHttpClient.newWebSocket(request, socketListener);
-        mOkHttpClient.dispatcher().executorService().shutdown();
     }
 
 

+ 72 - 5
sxz-core/src/main/java/com/fdkk/sxz/other/listener/RunBuild.java

@@ -116,12 +116,20 @@ public class RunBuild {
     @RabbitHandler
     @RabbitListener(queues = TopicRabbitConfig.MODEL)
     public void model(String str) {
-        RunBuild.log.info("模型转换:" + str);
+        RunBuild.log.info("模型转换初始请求业务:" + str);
         modelBuild(str);
         MDC.clear();
     }
 
     @RabbitHandler
+    @RabbitListener(queues = TopicRabbitConfig.MODEL_BIZ)
+    public void modelBiz(String str) {
+        RunBuild.log.info("模型转换业务:" + str);
+        modelBuildBiz(str);
+        MDC.clear();
+    }
+
+    @RabbitHandler
     @RabbitListener(queues = TopicRabbitConfig.MVIEW, concurrency = "5")
     public void modelMviewPath(String str) {
         RunBuild.log.info("处理Mview:" + str);
@@ -829,9 +837,7 @@ public class RunBuild {
                 }
 
                 maxName = maxPath.replace(filePath, "");
-
                 String max = new File(maxPath).getName();
-                Thread.sleep(1000);
                 RunBuild.log.info("开始运行maxToDatasmith");
                 ModelHandelStepEntity modelHandelStep = new ModelHandelStepEntity();
                 modelHandelStep.setStep(1);
@@ -843,13 +849,75 @@ public class RunBuild {
                 //开始计时
                 timer.start();
                 timer.start("global");
-                String maxUrl = maxObjUrl + "maxToDatasmith?uuid=" + fileId + "&max=" + maxName + "&flag=" + flag;
+                String maxUrl = maxObjUrl + "maxToDatasmith?uuid=" + fileId + "&max=" + maxName + "&flag=" + flag + "&resData=" + data;
                 RunBuild.log.info("请求maxToDataSmith地址-{}", maxUrl);
                 OkHttpUtils.httpGet(maxUrl);
                 RunBuild.log.info("运行maxToDataSmith结束-{}", fileId);
                 modelHandelStep.setUseTime(String.valueOf(timer.intervalMs()));
                 modelHandelStepService.updateById(modelHandelStep);
 
+            } finally {
+                MDC.clear();
+                if (token != null) {
+                    RedisUtil.unlock(fileId, token);
+                }
+            }
+        }
+
+
+    }
+
+    /**
+     * 模型上传
+     *
+     * @param data
+     */
+    private void modelBuildBiz(String data) {
+        String[] datas = data.split(":;");
+        String modelUploadId = datas[0];
+        String fileId = datas[1];
+        String userId = datas[2];
+        String modelType = datas[3];
+        //true表示定制,FALSE表示成品
+        String flag = datas[4];
+        //1 成品  2 定制  3 组件
+        String UploadType = datas[5];
+
+        ModelUploadEntity modelUploadEntity = null;
+        MDC.put("TRACE_ID", fileId);
+
+
+        ComponentModelUploadEntity componentModelUploadEntity = null;
+
+        //上锁保证只有一个在消费,加锁一个钟,成功消费就解锁了
+        String token = RedisUtil.tryLock(fileId, 60 * 60 * 1000);
+        if (token != null) {
+            RunBuild.log.info("暂无的fileId:" + fileId + "消费,继续执行处理逻辑模型上传逻辑");
+            try {
+                String path = buildPath + "upload";
+                String filePath = path + File.separator + fileId + File.separator;
+
+                List<String> allList = new ArrayList<>();
+                FileUtils.readfilePath(filePath, allList);
+                String maxPath = "";
+                String maxName = "";
+                for (String targetPath : allList) {
+                    if (targetPath.toLowerCase().endsWith(".max")) {
+                        maxPath = targetPath;
+                        break;
+                    }
+                }
+
+                maxName = maxPath.replace(filePath, "");
+
+                String max = new File(maxPath).getName();
+                Thread.sleep(1000);
+                RunBuild.log.info("解耦后跳过maxToDatasmith");
+                ModelHandelStepEntity modelHandelStep = new ModelHandelStepEntity();
+                TimeInterval timer = cn.hutool.core.date.DateUtil.timer();
+                //开始计时
+                timer.start("global");
+
                 String filesTxt = filePath + max.replace(".max", "") + "/files.txt";
                 if (!new File(filesTxt).exists()) {
                     RunBuild.log.info("运行maxToDataSmith失败,没有files.txt文件:" + filesTxt);
@@ -1310,7 +1378,6 @@ public class RunBuild {
 
     }
 
-
     /**
      * 循环检查3d渲染
      *

+ 18 - 6
sxz-core/src/main/java/com/fdkk/sxz/other/mq/TopicRabbitConfig.java

@@ -23,19 +23,21 @@ public class TopicRabbitConfig {
 //
 //    public final static String TOPICE = "topicExchangeCopy";
 
-    public final static String CHANGE = "topic.chang";
+    public final static String CHANGE = "topic.chang.dev";
     //灯光预览
-    public final static String LIGHT = "topic.light";
+    public final static String LIGHT = "topic.light.dev";
 
-    public final static String MODEL = "topic.model";
+    public final static String MODEL = "topic.model.dev";
+
+    public final static String MODEL_BIZ = "topic.modelBiz.dev";
 
     //"更新模型库,syncmodel
-    public final static String SYNCMODEL = "topic.syncmodel";
+    public final static String SYNCMODEL = "topic.syncmodel.dev";
 
     //处理
-    public final static String MVIEW = "delay.mview";
+    public final static String MVIEW = "delay.mview.dev";
 
-    public final static String TOPICE = "topicExchange";
+    public final static String TOPICE = "topicExchange.dev";
     /**
      * 延迟消息交换机
      */
@@ -65,6 +67,11 @@ public class TopicRabbitConfig {
     }
 
     @Bean
+    public Queue modelBizQueue() {
+        return new Queue(TopicRabbitConfig.MODEL_BIZ);
+    }
+
+    @Bean
     public Queue syncModelQueue() {
         return new Queue(TopicRabbitConfig.SYNCMODEL);
     }
@@ -108,4 +115,9 @@ public class TopicRabbitConfig {
         return BindingBuilder.bind(syncModelQueue()).to(exchange()).with(TopicRabbitConfig.SYNCMODEL);
     }
 
+    @Bean
+    Binding bindingExchangeMessage6() {
+        return BindingBuilder.bind(modelBizQueue()).to(exchange()).with(TopicRabbitConfig.MODEL_BIZ);
+    }
+
 }

+ 48 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/fbxToObjController.java

@@ -0,0 +1,48 @@
+package com.fdkk.sxz.webApi.controller;
+
+import com.fdkk.sxz.annotation.auth.NoAuthentication;
+import com.fdkk.sxz.annotation.log.AroundLog;
+import com.fdkk.sxz.base.Result;
+import com.fdkk.sxz.other.mq.TopicRabbitConfig;
+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.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+@Slf4j
+@RestController
+@RequestMapping("/change/fbxToObj")
+@Api(tags = "fbxToObj回调处理接口")
+public class fbxToObjController {
+    @Autowired
+    private RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方
+
+    /**
+     * 数据上传
+     *
+     * @return
+     */
+    @ApiOperation("队列数据处理任务接收")
+    @RequestMapping(value = "/dataPush/{resData}", method = RequestMethod.GET)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "resData", value = "版本号", dataType = "String")})
+    @NoAuthentication
+    @AroundLog(name = "数据处理任务接收")
+    public Result dataGetHandler(@PathVariable String resData) {
+        System.out.println(resData);
+        fbxToObjController.log.info("数据处理任务接收:{}", resData);
+        rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPICE, TopicRabbitConfig.MODEL_BIZ, resData);
+        return Result.success("发送队列成功");
+    }
+}

+ 165 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/actionSocket.java

@@ -0,0 +1,165 @@
+package com.fdkk.sxz.webApi.socket;
+
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.fdkk.sxz.util.RedisUtil;
+import com.fdkk.sxz.webApi.service.IComponentModelUploadService;
+import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
+import com.fdkk.sxz.webApi.socket.service.ComponentBizImpl;
+import com.fdkk.sxz.webApi.socket.service.ComponentCreateImgBizImpl;
+import com.fdkk.sxz.webApi.socket.service.CreateImgBizImpl;
+import com.fdkk.sxz.webApi.socket.service.ModelUploadBizImpl;
+import io.netty.handler.codec.http.HttpHeaders;
+import io.netty.handler.timeout.IdleStateEvent;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.yeauty.annotation.*;
+import org.yeauty.pojo.Session;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author XieWj
+ */
+@ServerEndpoint(path = "/wss/action/", port = "${ws.port}")
+@Slf4j
+public class actionSocket {
+
+    @Value("${main.url}")
+    private String mainUrl;
+
+
+    private static Map<String, actionSocket> componentSocketMap = new ConcurrentHashMap<>();
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Autowired
+    private IComponentModelUploadService componentModelUploadService;
+
+
+    Thread thread = null;
+
+    static boolean isStop = true;
+
+    private String region = "customWSS";
+
+
+    @BeforeHandshake
+    public void handshake(Session session, HttpHeaders headers, @PathVariable Map<String, String> pathMap) {
+        String token = pathMap.get("token");
+        session.setSubprotocols("stomp");
+//        JSONObject req=OkHttpUtils.httpPostFormReturnJson(mainUrl + "api/scene/isLogin", paramsMap, postHeaders);
+        if (1 == 0) {
+            actionSocket.log.info("Authentication failed!");
+            session.close();
+        }
+    }
+
+    @OnOpen
+    public void onOpen(Session session, HttpHeaders headers, @PathVariable Map pathMap) {
+        actionSocket.log.info("new connection, sessionId-{},Host-{}", session.id(), headers.get("Host"));
+    }
+
+    @OnClose
+    public void onClose(Session session) throws IOException, InterruptedException {
+        actionSocket.log.info("one connection closed");
+        if (thread != null) {
+            Thread.sleep(1000);
+            thread.interrupt();
+        }
+    }
+
+    @OnError
+    public void onError(Session session, Throwable throwable) {
+        throwable.printStackTrace();
+        if (thread != null) {
+            thread.interrupt();
+        }
+    }
+
+    @OnMessage
+    public void onMessage(Session session, String message) throws InterruptedException {
+        actionSocket.log.info(message);
+        JSONObject res = JSONUtil.createObj();
+        JSONObject data = JSONUtil.parseObj(message);
+        String action = data.getStr("action");
+        res.set("code", 0);
+        res.set("action", action);
+        //业务处理 调用异步线程,处理成功返回消息,连接断开,销毁线程
+        if (JSONUtil.isJson(message)) {
+            switch (action) {
+                case "componentBiz":
+                    ComponentBizImpl componentBiz = new ComponentBizImpl();
+                    String componentBizCallId = componentBiz.getCallId();
+                    componentBiz.todo(session, message, componentBizCallId);
+                    componentBiz.listenResult(this::sendMessage, componentBizCallId, new ParamContext("session", session));
+                    break;
+                case "modelUploadBiz":
+                    ModelUploadBizImpl modelUploadBiz = new ModelUploadBizImpl();
+                    String modelUploadBizCallId = modelUploadBiz.getCallId();
+                    modelUploadBiz.todo(session, message, modelUploadBizCallId);
+                    modelUploadBiz.listenResult(this::sendMessage, modelUploadBizCallId, new ParamContext("session", session));
+                    break;
+                case "createImgBiz":
+                    CreateImgBizImpl createImgBiz = new CreateImgBizImpl();
+                    String createImgBizCallId = createImgBiz.getCallId();
+                    createImgBiz.todo(session, message, createImgBizCallId);
+                    createImgBiz.listenResult(this::sendMessage, createImgBizCallId, new ParamContext("session", session));
+                    break;
+                case "componentCreateImgBiz":
+                    ComponentCreateImgBizImpl componentCreateImgBiz = new ComponentCreateImgBizImpl();
+                    String componentCreateImgBizCallId = componentCreateImgBiz.getCallId();
+                    componentCreateImgBiz.todo(session, message, componentCreateImgBizCallId);
+                    componentCreateImgBiz.listenResult(this::sendMessage, componentCreateImgBizCallId, new ParamContext("session", session));
+                    break;
+            }
+
+        } else {
+            res.set("code", 400);
+            res.set("msg", "Not for Json");
+            res.set("status", "error");
+            session.sendText(res.toString());
+        }
+    }
+
+
+    private void sendMessage(ParamContext paramContext, ParamContext paramContext1) {
+        String msg = paramContext.get("msg");
+        Session session = paramContext1.get("session");
+        session.sendText(msg.toString());
+
+    }
+
+
+    @OnBinary
+    public void onBinary(Session session, byte[] bytes) {
+        for (byte b : bytes) {
+            System.out.println(b);
+        }
+        session.sendBinary(bytes);
+    }
+
+    @OnEvent
+    public void onEvent(Session session, Object evt) {
+        if (evt instanceof IdleStateEvent) {
+            IdleStateEvent idleStateEvent = (IdleStateEvent) evt;
+            switch (idleStateEvent.state()) {
+                case READER_IDLE:
+                    actionSocket.log.info("read idle");
+                    break;
+                case WRITER_IDLE:
+                    actionSocket.log.info("write idle");
+                    break;
+                case ALL_IDLE:
+                    actionSocket.log.info("all idle");
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+}

+ 54 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/bizRunable/ListenCall.java

@@ -0,0 +1,54 @@
+package com.fdkk.sxz.webApi.socket.bizRunable;
+
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+public class ListenCall {
+    ConcurrentHashMap<String, SocketBiz<ParamContext, ParamContext>> methodMap = new ConcurrentHashMap<String, SocketBiz<ParamContext, ParamContext>>();
+    ConcurrentHashMap<String, ParamContext> paramMap = new ConcurrentHashMap<String, ParamContext>();
+
+    /**
+     * 获取请求编号
+     *
+     * @return
+     */
+    public String getCallId() {
+        UUID uuid = UUID.randomUUID();
+        return uuid.toString();
+    }
+
+    /**
+     * 监听返回值
+     *
+     * @param method
+     * @param callId
+     * @param context
+     */
+    public void listenResult(SocketBiz<ParamContext, ParamContext> method, String callId, ParamContext context) {
+        methodMap.put(callId, method);
+        paramMap.put(callId, context);
+    }
+
+    /**
+     * 等待处理结果
+     *
+     * @param result
+     * @param callId
+     */
+    public void waitForResult(ParamContext result, String callId) {
+        SocketBiz<ParamContext, ParamContext> funtion = methodMap.get(callId);
+        if (funtion != null) {
+            ParamContext context = paramMap.get(callId);
+            if (context == null) {
+                context = new ParamContext();
+            }
+            funtion.execute(result, context);
+        }
+
+    }
+
+}

+ 27 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/bizRunable/ParamContext.java

@@ -0,0 +1,27 @@
+package com.fdkk.sxz.webApi.socket.bizRunable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+public class ParamContext {
+    private Map<String, Object> datas = new HashMap<String, Object>();
+
+    public ParamContext(Object... params) {
+        if (params == null || params.length == 0) {
+            return;
+        }
+        for (int i = 0; i < params.length; ) {
+            datas.put((String) params[i], params[i + 1]);
+            i += 2;
+        }
+    }
+
+    public <R> R get(String key) {
+        return (R) datas.get(key);
+    }
+
+}

+ 12 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/bizRunable/SocketBiz.java

@@ -0,0 +1,12 @@
+package com.fdkk.sxz.webApi.socket.bizRunable;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+public interface SocketBiz<T1, T2> {
+
+    public void execute(T1 t1, T2 t2);
+
+
+}

+ 106 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/service/ComponentBizImpl.java

@@ -0,0 +1,106 @@
+package com.fdkk.sxz.webApi.socket.service;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.fdkk.sxz.entity.ComponentModelUploadEntity;
+import com.fdkk.sxz.util.RedisUtil;
+import com.fdkk.sxz.webApi.service.IComponentModelUploadService;
+import com.fdkk.sxz.webApi.socket.bizRunable.ListenCall;
+import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
+import com.fdkk.sxz.webApi.socket.bizRunable.SocketBiz;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.yeauty.pojo.Session;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+@Slf4j
+@Component
+public class ComponentBizImpl {
+
+    private ListenCall listenCall = new ListenCall();
+
+    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
+
+    private IComponentModelUploadService componentModelUploadService = SpringUtil.getBean(IComponentModelUploadService.class);
+
+
+    public void todo(Session session, String msgData, String callId) throws InterruptedException {
+        new Thread(new Runnable() {
+            @SneakyThrows
+            @Override
+            public void run() {
+                boolean flag = true;
+                JSONObject data = JSONUtil.parseObj(msgData);
+                Long id = data.getLong("id");
+                String action = data.getStr("action");
+                String status = data.getStr("status");
+                while (flag) {
+                    Thread.sleep(3000);
+                    ComponentBizImpl.log.warn("查询" + session.id() + "|----------" + id);
+                    if (StrUtil.equals(status, "query")) {
+                        if (redisUtil.hasKey("componentUploadStatus:id:" + id)) {
+                            String ObjStatus = redisUtil.get("componentUploadStatus:id:" + id);
+                            if (StrUtil.equals(ObjStatus, "done") || StrUtil.equals(ObjStatus, "error")) {
+                                waitForResult(new ParamContext("msg", extracted(id, ObjStatus, action)), callId);
+                                flag = false;
+                            }
+                        } else {
+                            ComponentModelUploadEntity entity = componentModelUploadService.findById(id);
+                            Thread.sleep(2000);
+                            if (ObjectUtil.isNotNull(entity)) {
+                                if (entity.getStatus() == 1 && entity.getProgress() == 100) {
+                                    redisUtil.setEx("componentUploadStatus:id:" + id, "done", 5, TimeUnit.MINUTES);
+                                    waitForResult(new ParamContext("msg", extracted(id, "done", action)), callId);
+                                    flag = false;
+                                } else if (entity.getStatus() == -1) {
+                                    redisUtil.delete("modelUploadStatus:id:" + id);
+                                    waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                    flag = false;
+                                }
+                            } else {
+                                //查不到直接返回错误
+                                waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                flag = false;
+                            }
+                        }
+                    }
+                }
+            }
+        }).start();
+    }
+
+    private String extracted(Long id, String status, String action) {
+        JSONObject res = JSONUtil.createObj();
+        JSONObject resData = JSONUtil.createObj();
+        res.set("status", status);
+        res.set("action", action);
+        resData.set("id", id);
+        resData.set("status", status);
+        res.set("msg", "done");
+        res.set("data", resData);
+        res.set("code", 0);
+        return res.toString();
+    }
+
+    public String getCallId() {
+        return listenCall.getCallId();
+    }
+
+    public void waitForResult(ParamContext p, String callId) {
+        listenCall.waitForResult(p, callId);
+    }
+
+    public void listenResult(SocketBiz<ParamContext, ParamContext> method, String callId, ParamContext context) {
+        listenCall.listenResult(method, callId, context);
+    }
+
+}

+ 106 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/service/ComponentCreateImgBizImpl.java

@@ -0,0 +1,106 @@
+package com.fdkk.sxz.webApi.socket.service;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.fdkk.sxz.entity.ComponentModelUploadEntity;
+import com.fdkk.sxz.util.RedisUtil;
+import com.fdkk.sxz.webApi.service.IComponentModelUploadService;
+import com.fdkk.sxz.webApi.socket.bizRunable.ListenCall;
+import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
+import com.fdkk.sxz.webApi.socket.bizRunable.SocketBiz;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.yeauty.pojo.Session;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+@Slf4j
+@Component
+public class ComponentCreateImgBizImpl {
+
+    private ListenCall listenCall = new ListenCall();
+
+    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
+
+    private IComponentModelUploadService componentModelUploadService = SpringUtil.getBean(IComponentModelUploadService.class);
+
+
+    public void todo(Session session, String msgData, String callId) throws InterruptedException {
+        new Thread(new Runnable() {
+            @SneakyThrows
+            @Override
+            public void run() {
+                boolean flag = true;
+                JSONObject data = JSONUtil.parseObj(msgData);
+                Long id = data.getLong("id");
+                String action = data.getStr("action");
+                String status = data.getStr("status");
+                while (flag) {
+                    Thread.sleep(3000);
+                    ComponentCreateImgBizImpl.log.warn("查询" + session.id() + "|----------" + id);
+                    if (StrUtil.equals(status, "query")) {
+                        if (redisUtil.hasKey("componentCreateImgStatus:id:" + id)) {
+                            String ObjStatus = redisUtil.get("componentCreateImgStatus:id:" + id);
+                            if (StrUtil.equals(ObjStatus, "done") || StrUtil.equals(ObjStatus, "error")) {
+                                waitForResult(new ParamContext("msg", extracted(id, ObjStatus, action)), callId);
+                                flag = false;
+                            }
+                        } else {
+                            ComponentModelUploadEntity entity = componentModelUploadService.findById(id);
+                            Thread.sleep(2000);
+                            if (ObjectUtil.isNotNull(entity)) {
+                                if (entity.getStatus() == 1 && entity.getProgress() == 100) {
+                                    redisUtil.setEx("componentCreateImgStatus:id:" + id, "done", 5, TimeUnit.MINUTES);
+                                    waitForResult(new ParamContext("msg", extracted(id, "done", action)), callId);
+                                    flag = false;
+                                } else if (entity.getStatus() == -1) {
+                                    redisUtil.delete("modelUploadStatus:id:" + id);
+                                    waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                    flag = false;
+                                }
+                            } else {
+                                //查不到直接返回错误
+                                waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                flag = false;
+                            }
+                        }
+                    }
+                }
+            }
+        }).start();
+    }
+
+    private String extracted(Long id, String status, String action) {
+        JSONObject res = JSONUtil.createObj();
+        JSONObject resData = JSONUtil.createObj();
+        res.set("status", status);
+        res.set("action", action);
+        resData.set("id", id);
+        resData.set("status", status);
+        res.set("msg", "done");
+        res.set("data", resData);
+        res.set("code", 0);
+        return res.toString();
+    }
+
+    public String getCallId() {
+        return listenCall.getCallId();
+    }
+
+    public void waitForResult(ParamContext p, String callId) {
+        listenCall.waitForResult(p, callId);
+    }
+
+    public void listenResult(SocketBiz<ParamContext, ParamContext> method, String callId, ParamContext context) {
+        listenCall.listenResult(method, callId, context);
+    }
+
+}

+ 106 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/service/CreateImgBizImpl.java

@@ -0,0 +1,106 @@
+package com.fdkk.sxz.webApi.socket.service;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.fdkk.sxz.entity.ModelUploadEntity;
+import com.fdkk.sxz.util.RedisUtil;
+import com.fdkk.sxz.webApi.service.IModelUploadService;
+import com.fdkk.sxz.webApi.socket.bizRunable.ListenCall;
+import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
+import com.fdkk.sxz.webApi.socket.bizRunable.SocketBiz;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.yeauty.pojo.Session;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+@Slf4j
+@Component
+public class CreateImgBizImpl {
+
+    private ListenCall listenCall = new ListenCall();
+
+    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
+
+    private IModelUploadService modelUploadService = SpringUtil.getBean(IModelUploadService.class);
+
+
+    public void todo(Session session, String msgData, String callId) throws InterruptedException {
+        new Thread(new Runnable() {
+            @SneakyThrows
+            @Override
+            public void run() {
+                boolean flag = true;
+                JSONObject data = JSONUtil.parseObj(msgData);
+                Long id = data.getLong("id");
+                String action = data.getStr("action");
+                String status = data.getStr("status");
+                while (flag) {
+                    Thread.sleep(3000);
+                    CreateImgBizImpl.log.warn("查询" + session.id() + "|----------" + id);
+                    if (StrUtil.equals(status, "query")) {
+                        if (redisUtil.hasKey("createImgStatus:id:" + id)) {
+                            String ObjStatus = redisUtil.get("createImgStatus:id:" + id);
+                            if (StrUtil.equals(ObjStatus, "done") || StrUtil.equals(ObjStatus, "error")) {
+                                waitForResult(new ParamContext("msg", extracted(id, ObjStatus, action)), callId);
+                                flag = false;
+                            }
+                        } else {
+                            ModelUploadEntity entity = modelUploadService.findById(id);
+                            Thread.sleep(2000);
+                            if (ObjectUtil.isNotNull(entity)) {
+                                if (entity.getStatus() == 1 && entity.getProgress() == 100) {
+                                    redisUtil.setEx("createImgStatus:id:" + id, "done", 5, TimeUnit.MINUTES);
+                                    waitForResult(new ParamContext("msg", extracted(id, "done", action)), callId);
+                                    flag = false;
+                                } else if (entity.getStatus() == -1) {
+                                    redisUtil.delete("createImgStatus:id:" + id);
+                                    waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                    flag = false;
+                                }
+                            } else {
+                                //查不到直接返回错误
+                                waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                flag = false;
+                            }
+                        }
+                    }
+                }
+            }
+        }).start();
+    }
+
+    private String extracted(Long id, String status, String action) {
+        JSONObject res = JSONUtil.createObj();
+        JSONObject resData = JSONUtil.createObj();
+        res.set("status", status);
+        res.set("action", action);
+        resData.set("id", id);
+        resData.set("status", status);
+        res.set("msg", "done");
+        res.set("data", resData);
+        res.set("code", 0);
+        return res.toString();
+    }
+
+    public String getCallId() {
+        return listenCall.getCallId();
+    }
+
+    public void waitForResult(ParamContext p, String callId) {
+        listenCall.waitForResult(p, callId);
+    }
+
+    public void listenResult(SocketBiz<ParamContext, ParamContext> method, String callId, ParamContext context) {
+        listenCall.listenResult(method, callId, context);
+    }
+
+}

+ 106 - 0
sxz-core/src/main/java/com/fdkk/sxz/webApi/socket/service/ModelUploadBizImpl.java

@@ -0,0 +1,106 @@
+package com.fdkk.sxz.webApi.socket.service;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.fdkk.sxz.entity.ModelUploadEntity;
+import com.fdkk.sxz.util.RedisUtil;
+import com.fdkk.sxz.webApi.service.IModelUploadService;
+import com.fdkk.sxz.webApi.socket.bizRunable.ListenCall;
+import com.fdkk.sxz.webApi.socket.bizRunable.ParamContext;
+import com.fdkk.sxz.webApi.socket.bizRunable.SocketBiz;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import org.yeauty.pojo.Session;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/17
+ */
+@Slf4j
+@Component
+public class ModelUploadBizImpl {
+
+    private ListenCall listenCall = new ListenCall();
+
+    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
+
+    private IModelUploadService modelUploadService = SpringUtil.getBean(IModelUploadService.class);
+
+
+    public void todo(Session session, String msgData, String callId) throws InterruptedException {
+        new Thread(new Runnable() {
+            @SneakyThrows
+            @Override
+            public void run() {
+                boolean flag = true;
+                JSONObject data = JSONUtil.parseObj(msgData);
+                Long id = data.getLong("id");
+                String action = data.getStr("action");
+                String status = data.getStr("status");
+                while (flag) {
+                    Thread.sleep(3000);
+                    ModelUploadBizImpl.log.warn("查询" + session.id() + "|----------" + id);
+                    if (StrUtil.equals(status, "query")) {
+                        if (redisUtil.hasKey("modelUploadStatus:id:" + id)) {
+                            String ObjStatus = redisUtil.get("modelUploadStatus:id:" + id);
+                            if (StrUtil.equals(ObjStatus, "done") || StrUtil.equals(ObjStatus, "error")) {
+                                waitForResult(new ParamContext("msg", extracted(id, ObjStatus, action)), callId);
+                                flag = false;
+                            }
+                        } else {
+                            ModelUploadEntity entity = modelUploadService.findById(id);
+                            Thread.sleep(2000);
+                            if (ObjectUtil.isNotNull(entity)) {
+                                if (entity.getStatus() == 1 && entity.getProgress() == 100) {
+                                    redisUtil.setEx("modelUploadStatus:id:" + id, "done", 5, TimeUnit.MINUTES);
+                                    waitForResult(new ParamContext("msg", extracted(id, "done", action)), callId);
+                                    flag = false;
+                                } else if (entity.getStatus() == -1) {
+                                    redisUtil.delete("modelUploadStatus:id:" + id);
+                                    waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                    flag = false;
+                                }
+                            } else {
+                                //查不到直接返回错误
+                                waitForResult(new ParamContext("msg", extracted(id, "error", action)), callId);
+                                flag = false;
+                            }
+                        }
+                    }
+                }
+            }
+        }).start();
+    }
+
+    private String extracted(Long id, String status, String action) {
+        JSONObject res = JSONUtil.createObj();
+        JSONObject resData = JSONUtil.createObj();
+        res.set("status", status);
+        res.set("action", action);
+        resData.set("id", id);
+        resData.set("status", status);
+        res.set("msg", "done");
+        res.set("data", resData);
+        res.set("code", 0);
+        return res.toString();
+    }
+
+    public String getCallId() {
+        return listenCall.getCallId();
+    }
+
+    public void waitForResult(ParamContext p, String callId) {
+        listenCall.waitForResult(p, callId);
+    }
+
+    public void listenResult(SocketBiz<ParamContext, ParamContext> method, String callId, ParamContext context) {
+        listenCall.listenResult(method, callId, context);
+    }
+
+}