4.19 websocket处理更新

master
coco1986509808 2023-04-19 18:54:24 +08:00
parent d976d8824b
commit 604eb68005
3 changed files with 23 additions and 58 deletions

View File

@ -5,11 +5,15 @@ import com.dkha.common.http.HttpUtil;
import com.dkha.common.modules.vo.face.FaceResEntity; import com.dkha.common.modules.vo.face.FaceResEntity;
import com.dkha.common.modules.vo.CompareFaceList; import com.dkha.common.modules.vo.CompareFaceList;
import com.dkha.common.result.CommonResult; import com.dkha.common.result.CommonResult;
import com.dkha.common.modules.vo.ReturnVO;
import com.dkha.common.util.JsonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,6 +24,7 @@ import java.util.*;
@RestController @RestController
@RequestMapping("faces") @RequestMapping("faces")
@Slf4j @Slf4j
@Component
public class FaceController extends CommonResult { public class FaceController extends CommonResult {
@Resource @Resource
private MinioUtil minioUtil; private MinioUtil minioUtil;
@ -27,8 +32,9 @@ public class FaceController extends CommonResult {
private String apiServerPrefix; private String apiServerPrefix;
@Autowired @Autowired
private HttpUtil httpUtil; private HttpUtil httpUtil;
@Autowired
private Gson gson; private Gson gson =new Gson();
private int count ; private int count ;
private Map<String,FaceResEntity> faceRes = new HashMap<>(); private Map<String,FaceResEntity> faceRes = new HashMap<>();
@ -96,7 +102,15 @@ public class FaceController extends CommonResult {
System.out.println(facelist.size()); System.out.println(facelist.size());
return facelist; return facelist;
} }
@PostMapping("/test123")
public void test(@RequestBody ReturnVO returnVO){
System.out.println("进入测试接口");
System.out.println("returnvo:"+returnVO);
System.out.println(gson.toJson(returnVO));
System.out.println(gson.toJson(returnVO.getData()));
List<FaceResEntity> testfacelist = JsonUtil.string2Obj(gson.toJson(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {});
System.out.println(testfacelist);
}
//从算法端获取图片列表接口 //从算法端获取图片列表接口
@PostMapping("/getList") @PostMapping("/getList")
@ -109,29 +123,27 @@ public class FaceController extends CommonResult {
count++; count++;
facelist.add(res); facelist.add(res);
} }
System.out.println(facelist);
WebSocketContral webSocketContral =new WebSocketContral(); WebSocketContral webSocketContral =new WebSocketContral();
webSocketContral.sendMessage(gson.toJson(facelist)); webSocketContral.sendMessage(gson.toJson(facelist));
//webSocketContral.sendMessage("发送websocket信息中"); System.out.println("发送信息结束");
} }
public void sendWebsocket1(List<FaceResEntity> onfacelist){ public void sendWebsocket1(List<FaceResEntity> onfacelist){
facelist.clear(); facelist.clear();
facelist = onfacelist; facelist = onfacelist;
//System.out.println(facelist);
WebSocketContral webSocketContral =new WebSocketContral(); WebSocketContral webSocketContral =new WebSocketContral();
System.out.println("facelist"+ facelist);
System.out.println("GSON" + gson.toJson(facelist));
webSocketContral.sendMessage(gson.toJson(facelist)); webSocketContral.sendMessage(gson.toJson(facelist));
//webSocketContral.sendMessage("发送websocket信息中"); //System.out.println("发送信息结束");
} }
public void sendWebsocket2(List<CompareFaceList> oncompareFacelist){ public void sendWebsocket2(List<CompareFaceList> oncompareFacelist){
compareFaceLists.clear(); compareFaceLists.clear();
compareFaceLists = oncompareFacelist; compareFaceLists = oncompareFacelist;
WebSocketContral webSocketContral =new WebSocketContral(); WebSocketContral webSocketContral =new WebSocketContral();
webSocketContral.sendMessage(gson.toJson(oncompareFacelist)); webSocketContral.sendMessage(gson.toJson(oncompareFacelist));
//webSocketContral.sendMessage("发送websocket信息中");
System.out.println("list:"+ oncompareFacelist);
} }
@PostMapping("/compareList") @PostMapping("/compareList")

View File

@ -70,6 +70,7 @@ public class WebSocketContral {
{ {
redisUtils =applicationContext.getBean(RedisUtils.class); redisUtils =applicationContext.getBean(RedisUtils.class);
this.session=session; this.session=session;
System.out.println("session信息"+ session);
if(myMap.containsKey(session.getId())) if(myMap.containsKey(session.getId()))
{ {
try { try {
@ -123,10 +124,7 @@ public class WebSocketContral {
{ {
ReturnVO returnVO=gson.fromJson(message,ReturnVO.class); ReturnVO returnVO=gson.fromJson(message,ReturnVO.class);
System.out.println(message); System.out.println(message);
System.out.println(returnVO.getMessage());
System.out.println(returnVO.getMessage().getClass());
if(returnVO.getMessage().equals("okpro")) { if(returnVO.getMessage().equals("okpro")) {
System.out.println("进入第一个方法");
if (UtilValidate.isNotEmpty(returnVO.getData())) { if (UtilValidate.isNotEmpty(returnVO.getData())) {
// List<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class); // List<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class);
List<FaceResEntity> onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {}); List<FaceResEntity> onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {});
@ -175,7 +173,6 @@ public class WebSocketContral {
{ {
// log.info("【websocket消息】广播消息message={}",message); // log.info("【websocket消息】广播消息message={}",message);
sessionSendMsg(websocket.session,message); sessionSendMsg(websocket.session,message);
System.out.println("后台在发送websocket信息");
} }
} }

View File

@ -1,44 +0,0 @@
package com.dkha.task.service;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import com.dkha.common.enums.ErrEnum;
import com.dkha.common.enums.SocketEnum;
import com.dkha.common.modules.vo.face.FaceResEntity;
import com.dkha.common.redis.RedisKeys;
import com.dkha.common.redis.RedisUtils;
import com.dkha.common.util.UtilValidate;
import com.dkha.server.controllers.FaceController;
import com.dkha.task.comm.TimerData;
import com.dkha.task.modual.SysUserTokenEntity;
import com.dkha.task.modual.mapper.SysUserTokenDao;
import com.dkha.task.modual.vo.BayonetVO;
import com.dkha.task.modual.vo.ReturnVO;
import com.google.gson.Gson;
import lombok.Data;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
public class Datatest {
public List<FaceResEntity> getFaceList() {
FaceController faceController = new FaceController();
System.out.println(faceController.getFacelist());
return faceController.getFacelist();
}
}