zwhui 1 жил өмнө
parent
commit
e188c39fea

+ 33 - 0
midjourney-netty-websocket-web/pom.xml

@@ -83,6 +83,39 @@
         </dependency>
 
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>${start-class}</mainClass>
+                    <layout>ZIP</layout><!-- Replace with your main class -->
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                    <compilerArgument>-Xlint:unchecked</compilerArgument>
+                </configuration>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
 
+        <finalName>midjourney-netty</finalName>
+    </build>
 
 </project>

+ 7 - 2
midjourney-netty-websocket-web/src/main/java/com/yhlxj/netty/websocket/midjounrey/controller/NotifyController.java

@@ -1,7 +1,9 @@
 package com.yhlxj.netty.websocket.midjounrey.controller;
 
+import com.cyksj.common.annotation.Log;
 import com.yhlxj.netty.websocket.midjounrey.dao.model.dto.SendMsgReq;
 import com.yhlxj.netty.websocket.midjounrey.service.SocketServer;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -10,12 +12,15 @@ import org.springframework.web.bind.annotation.RestController;
  * @author chan
  * @date 2024-09-06 22:39
  */
-@RestController("/msg")
+@Slf4j
+@RestController
+@RequestMapping("/msg")
 public class NotifyController {
 
     @RequestMapping("/send")
     public String sendMsg(@RequestBody SendMsgReq sendMsgReq){
-        SocketServer.sendMessage(sendMsgReq.getMsg(),sendMsgReq.getUserToken());
+        log.info("sendMsgReq:{}", sendMsgReq);
+        SocketServer.sendMessage(sendMsgReq.getMsg(),sendMsgReq.getUserId());
         return "success";
     }
 

+ 1 - 1
midjourney-netty-websocket-web/src/main/java/com/yhlxj/netty/websocket/midjounrey/dao/model/dto/SendMsgReq.java

@@ -9,7 +9,7 @@ import lombok.Data;
 @Data
 public class SendMsgReq {
 
-    private String userToken;
+    private String userId;
 
     private String msg;
 

+ 8 - 6
midjourney-netty-websocket-web/src/main/java/com/yhlxj/netty/websocket/midjounrey/service/SocketServer.java

@@ -11,8 +11,10 @@ import com.yhlxj.netty.websocket.starter.annotations.*;
 import com.yhlxj.netty.websocket.starter.socket.Session;
 import io.netty.handler.codec.http.HttpHeaders;
 import io.netty.handler.timeout.IdleStateEvent;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
 
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -22,8 +24,10 @@ import java.util.concurrent.ConcurrentMap;
  * @author chan
  * @date 2024-09-06 22:39
  */
-@WsServerEndpoint(value = "/ws/{userToken}/{taskId}")
+@Component
+@WsServerEndpoint(value = "/ws/midjourney/{userToken}/{taskId}")
 @Slf4j
+@RequiredArgsConstructor
 public class SocketServer {
 
 	private static ConcurrentMap<String, Set<Session>> sessionPool = new ConcurrentHashMap<>();
@@ -31,8 +35,7 @@ public class SocketServer {
 
 	private static final String ADMIN = "yhlxj";
 
-	//@Autowired
-	private MidjourneyService midjourneyService;
+	private final MidjourneyService midjourneyService;
 
 	@HandshakeBefore
 	public void handshakeBefore(HttpHeaders headers,@PathParam String userid) {
@@ -105,7 +108,6 @@ public class SocketServer {
 
 			//根据子类型进行处理
 			if (WsMessageTypeEnum.getMessageType(body.getStr("type")) == WsMessageTypeEnum.CLIENT_TASK_ID) { //
-				MidjourneyService midjourneyService = SpringCtxUtils.getBean(MidjourneyService.class);
 				MidjourneyUserConversation conversation = midjourneyService.getConversationById(body.getStr("taskId"));
 				session.sendText(packMsg(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation)));
 			} else {
@@ -173,8 +175,8 @@ public class SocketServer {
 		sendMessage(packMsg(typeEnum, message), userToken);
 	}
 
-	public static void sendMessage(String message,String userToken){
-		Set<Session> sessions = sessionPool.get(userToken);
+	public static void sendMessage(String message,String userId){
+		Set<Session> sessions = sessionPool.get(userId);
 		if (CollectionUtil.isNotEmpty(sessions)) {
 			sessions.forEach((session)->{
 				session.sendText(message);

+ 3 - 3
midjourney-netty-websocket-web/src/main/resources/application.yml

@@ -20,9 +20,9 @@ spring:
       - ${activeProfile}
   datasource:
     type: com.zaxxer.hikari.HikariDataSource
-    url: jdbc:mysql://inside.liuliangbang.vip:33306/yhlxj?useAffectedRows=true
-    username: dev
-    password: Dev.12345
+    url: jdbc:mysql://sh-cdb-4tdnmrqa.sql.tencentcdb.com:63893/yhlxj_pre?useAffectedRows=true
+    username: yhlxj
+    password: yhlxj123
     platform: mysql
     continue-on-error: false
     driver-class-name: com.mysql.cj.jdbc.Driver

+ 12 - 6
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -805,7 +805,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
 
     private static String uploadPic(String url, String prefix) throws IOException {
         // 替换 URL 并下载图像字节
-        url = url.replace("cdn.mj.liuliangbang.vip", "cdn.discordapp.com");
+        url = url.replace("cdn.mj.liuliangbang.vip", "media.liuliangbang.vip");
 
         byte[] body;
         try {
@@ -1138,8 +1138,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
     private void sendProgressToClient( MidjourneyUserConversation conversation) {
         log.info("sendProgressToClient: {}", conversation);
         //WebSocket 直接发送 任务状态
-        WssSession wssSession = WSS_SESSION_MAP.get(conversation.getUserId());
-        if (wssSession != null) {
+        //WssSession wssSession = WSS_SESSION_MAP.get(conversation.getUserId());
+        //if (wssSession != null) {
             conversation.setChannelId(null);
             conversation.setInstanceId(null);
             if(JSONUtil.isJson(conversation.getProperties())){
@@ -1169,9 +1169,15 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             if(JSONUtil.isJson(conversation.getFailReason())){
                 conversation.setFailReason("生成图片失败");
             }
-
-            wssSession.sendMessage(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation));
-        }
+            String url = "https://web.liuliangbang.vip/8080/api/msg/send";
+        Map<String, Object> data = MapUtil.builder(new HashMap<String,Object>())
+                .put("taskId", conversation.getTaskId())
+                .put("msg", JSONUtil.toJsonStr(conversation))
+                .put("userId", conversation.getUserId())
+                .build();
+        HttpUtil.post(url, JSONUtil.toJsonStr(data));
+            //wssSession.sendMessage(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation));
+        //}
     }
 
     public static String replaceUserId(String messageContent, String newUserId) {

+ 1 - 1
midjourney/src/main/java/com/yhlxj/service/task/Scheduler.java

@@ -26,7 +26,7 @@ public class Scheduler {
     public void syncPicture() throws Exception {
         midjourneyService.syncPicture();
     }
-    @Scheduled(cron = "45 0/15 * * * ?")
+    //@Scheduled(cron = "45 0/15 * * * ?")
     public void syncAccount() throws Exception {
         midjourneyAccountService.syncAccountByMJPlus();
     }