From 2b033223988962f6196450c07437bc8982a461af Mon Sep 17 00:00:00 2001 From: coco1986509808 <1986509808@qq.com> Date: Wed, 10 May 2023 19:35:13 +0800 Subject: [PATCH] =?UTF-8?q?5.10=E5=90=8E=E7=AB=AF=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E4=BA=BA=E5=83=8F=E5=A7=93=E5=90=8D=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/config/TimeTransform.java | 28 +++++++++++++++++ .../server/controllers/CameraController.java | 1 + .../server/controllers/FaceController.java | 30 ++++++++++++------- .../dkha/server/controllers/IndexContral.java | 6 ++-- .../server/controllers/WebSocketContral.java | 29 +++++++++++------- 5 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 face-server/src/main/java/com/dkha/server/common/config/TimeTransform.java diff --git a/face-server/src/main/java/com/dkha/server/common/config/TimeTransform.java b/face-server/src/main/java/com/dkha/server/common/config/TimeTransform.java new file mode 100644 index 0000000..3b84938 --- /dev/null +++ b/face-server/src/main/java/com/dkha/server/common/config/TimeTransform.java @@ -0,0 +1,28 @@ +package com.dkha.server.common.config; + + +public class TimeTransform { + + public TimeTransform() { + } + + public String trans(){ + //获得系统的时间,单位为毫秒,转换为秒 + long totalMillTimes=System.currentTimeMillis(); + long totalSeconds=totalMillTimes/1000; + + //求当前时间的秒 + long totalSecond=totalSeconds%60; + + //求当前时间的分 + long totalMinutes=totalSeconds/60; + long totalMinute=totalMinutes%60; + + //求当前时间的时 + long totalHours=totalSeconds/3600; + long totalHour=totalHours%24; + + String time = totalHour+":"+totalMinutes+":"+totalMinute; + return time; + } +} diff --git a/face-server/src/main/java/com/dkha/server/controllers/CameraController.java b/face-server/src/main/java/com/dkha/server/controllers/CameraController.java index 3d9b2a7..d87636d 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/CameraController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/CameraController.java @@ -113,6 +113,7 @@ public class CameraController extends CommonResult { List> results = new ArrayList<>(); for (SysRegionEntity region:regionByLevel) { List> bayonet = faceCameraServiceImpl.getBayonet(region.getPid()); + //System.out.println(bayonet); results.add(bayonet.get(0)); } return successResult(results); diff --git a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java index de520fc..cfbf2b4 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java @@ -32,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.Serializable; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.*; @@ -159,24 +160,29 @@ public class FaceController extends CommonResult { public void sendWebsocket2(List oncompareFacelist){ compareFaceLists.clear(); + long a = System.currentTimeMillis(); // compareFaceLists = oncompareFacelist; for (CompareFaceList com :oncompareFacelist){ - if(UtilValidate.isNotEmpty(com.getName())){ - //根据人脸名称去找rphoto +// if(UtilValidate.isNotEmpty(com.getName())){ + //根据人脸名称去人像库中寻找rphoto QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.eq("name",com.getName()); + queryWrapper.eq("id_portrait",com.getName()); Portrait rphoto = iPortraitService.getBaseMapper().selectOne(queryWrapper); - System.out.println("rphoto"+rphoto); +// System.out.println("rphoto"+rphoto); + //判断数据库中查找的数据是否为空 com.setRphoto(rphoto.getUrl()); - } - if(com.getXsd()>70) { - System.out.println("相似度为:" + com.getXsd() + "%,小于70"); + com.setName(rphoto.getName()); +// } compareFaceLists.add(com); - } } - System.out.println(compareFaceLists); + long b = System.currentTimeMillis(); + System.out.println("查表数据时间"+(b-a)+"ms"); +// System.out.println(compareFaceLists); WebSocketContral webSocketContral =new WebSocketContral(); webSocketContral.sendMessage(gson.toJson(compareFaceLists)); + long c =System.currentTimeMillis(); + SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd aHH:mm:ss:SSS"); + System.out.println("websocket发送完成时间点"+ dateFormatGmt.format(new Date())+ ",共耗时"+(c-b)+"ms"); } @PostMapping("/compareList") @@ -201,8 +207,12 @@ public class FaceController extends CommonResult { public List getFacelist() { return this.facelist; } + @GetMapping("test0509") + public void getUrl(@RequestParam("url") String url) { + System.out.println("获取url"+url); + } - /* @GetMapping("one") + /* @GetMapping("one") public List webSocketSet=new CopyOnWriteArraySet(); @@ -124,30 +127,36 @@ public class WebSocketContral { @OnMessage public void onMessage(String message) { + faceController1 =applicationContext.getBean(FaceController.class); // log.error("接收数据:{}",message); // if(UtilValidate.isEmpty(this.session) || this.session.isOpen()==false){return;} //System.out.println(message); if(UtilValidate.isNotEmpty(message)) { log.info("【websocket消息】收到客户端消息:{}",message); + long start = System.currentTimeMillis(); + SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd aHH:mm:ss:SSS"); + System.out.println("收到comparelist数据时间:"+dateFormatGmt.format(new Date())); +// timeTransform = applicationContext.getBean(TimeTransform.class); +// System.out.println("收到comparelist数据时间:"+ timeTransform.trans()); + ReturnVO returnVO=gson.fromJson(message,ReturnVO.class); //System.out.println(message); - faceController1 =applicationContext.getBean(FaceController.class); - if(returnVO.getMessage().equals("okpro")) { + if(returnVO.getMessage().equals("okplus")){ + // List facelist =gson.fromJson(gson.toJson(returnVO.getData()),List.class); + List oncompareFaceLists = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference>() {}); + long end =System.currentTimeMillis(); + System.out.println("接收数据耗时"+ (end - start)+ "ms"); + faceController1.sendWebsocket2(oncompareFaceLists); + + } + else if(returnVO.getMessage().equals("okpro")) { if (UtilValidate.isNotEmpty(returnVO.getData())) { // List facelist =gson.fromJson(gson.toJson(returnVO.getData()),List.class); List onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference>() {}); faceController1.sendWebsocket1(onfacelist); } } - else if(returnVO.getMessage().equals("okplus")){ - if (UtilValidate.isNotEmpty(returnVO.getData())) { - // List facelist =gson.fromJson(gson.toJson(returnVO.getData()),List.class); - List oncompareFaceLists = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference>() {}); -// FaceController faceController = new FaceController(); - faceController1.sendWebsocket2(oncompareFaceLists); - } - } } log.info("【websocket消息】收到客户端消息:{}","发送完成");