From 4e92556e2406940ea096ccc0130835a91b88212c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=AE=87=E6=81=92?= <13581426+zhou030824@user.noreply.gitee.com> Date: Wed, 7 Feb 2024 15:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=93=E6=8B=8D=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/domain/CompreFaceApiResponse.java | 10 + .../domain/dto/CompreFaceApiResponseDto.java | 235 ++++++++++++++++++ .../controller/ComprefaceController.java | 4 +- .../com/zyh/system/mapper/CameraMapper.java | 2 + .../zyh/system/mapper/ComprefaceMapper.java | 2 + .../zyh/system/service/ComprefaceService.java | 2 +- .../service/impl/ComprefaceServicempl.java | 21 +- .../zyh/system/service/impl/EsServicempl.java | 60 ----- .../main/resources/mapper/SysUserMapper.xml | 3 + 9 files changed, 269 insertions(+), 70 deletions(-) create mode 100644 community-security-common/src/main/java/com/zyh/common/domain/dto/CompreFaceApiResponseDto.java delete mode 100644 community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/EsServicempl.java diff --git a/community-security-common/src/main/java/com/zyh/common/domain/CompreFaceApiResponse.java b/community-security-common/src/main/java/com/zyh/common/domain/CompreFaceApiResponse.java index c638deb..87af1a2 100644 --- a/community-security-common/src/main/java/com/zyh/common/domain/CompreFaceApiResponse.java +++ b/community-security-common/src/main/java/com/zyh/common/domain/CompreFaceApiResponse.java @@ -22,6 +22,7 @@ public class CompreFaceApiResponse { private Box box; private List subjects; private List> landmarks; + private Camera camera; public Age getAge() { return age; @@ -68,8 +69,17 @@ public class CompreFaceApiResponse { } public void setLandmarks(List> landmarks) { + this.landmarks = landmarks; } + + public Camera getCamera() { + return camera; + } + + public void setCamera(Camera camera) { + this.camera = camera; + } } public static class Age { diff --git a/community-security-common/src/main/java/com/zyh/common/domain/dto/CompreFaceApiResponseDto.java b/community-security-common/src/main/java/com/zyh/common/domain/dto/CompreFaceApiResponseDto.java new file mode 100644 index 0000000..4ccb233 --- /dev/null +++ b/community-security-common/src/main/java/com/zyh/common/domain/dto/CompreFaceApiResponseDto.java @@ -0,0 +1,235 @@ +package com.zyh.common.domain.dto; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.zyh.common.domain.Camera; + +public class CompreFaceApiResponseDto { + + private List result; + + public List getResult() { + return result; + } + + public void setResult(List result) { + this.result = result; + } + + public static class Result { + private Age age; + private Gender gender; + private Pose pose; + private Box box; + private List subjects; + private List> landmarks; + private Camera camera; + + public Age getAge() { + return age; + } + + public void setAge(Age age) { + this.age = age; + } + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + public Pose getPose() { + return pose; + } + + public void setPose(Pose pose) { + this.pose = pose; + } + + public Box getBox() { + return box; + } + + public void setBox(Box box) { + this.box = box; + } + + public List getSubjects() { + return subjects; + } + + public void setSubjects(List subjects) { + this.subjects = subjects; + } + + public List> getLandmarks() { + return landmarks; + } + + public void setLandmarks(List> landmarks) { + + this.landmarks = landmarks; + } + + public Camera getCamera() { + return camera; + } + + public void setCamera(Camera camera) { + this.camera = camera; + } + } + + public static class Age { + private Double probability; + private Integer high; + private Integer low; + + public Double getProbability() { + return probability; + } + + public void setProbability(Double probability) { + this.probability = probability; + } + + public Integer getHigh() { + return high; + } + + public void setHigh(Integer high) { + this.high = high; + } + + public Integer getLow() { + return low; + } + + public void setLow(Integer low) { + this.low = low; + } + } + + public static class Gender { + private Double probability; + private String value; + + public Double getProbability() { + return probability; + } + + public void setProbability(Double probability) { + this.probability = probability; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public static class Pose { + private Double pitch; + private Double roll; + private Double yaw; + + public Double getPitch() { + return pitch; + } + + public void setPitch(Double pitch) { + this.pitch = pitch; + } + + public Double getRoll() { + return roll; + } + + public void setRoll(Double roll) { + this.roll = roll; + } + + public Double getYaw() { + return yaw; + } + + public void setYaw(Double yaw) { + this.yaw = yaw; + } + } + + public static class Box { + private Double probability; + private Integer xMax; + private Integer yMax; + private Integer xMin; + private Integer yMin; + + public Double getProbability() { + return probability; + } + + public void setProbability(Double probability) { + this.probability = probability; + } + + public Integer getxMax() { + return xMax; + } + + public void setxMax(Integer xMax) { + this.xMax = xMax; + } + + public Integer getyMax() { + return yMax; + } + + public void setyMax(Integer yMax) { + this.yMax = yMax; + } + + public Integer getxMin() { + return xMin; + } + + public void setxMin(Integer xMin) { + this.xMin = xMin; + } + + public Integer getyMin() { + return yMin; + } + + public void setyMin(Integer yMin) { + this.yMin = yMin; + } + } + + public static class Subject { + private String subject; + private Double similarity; + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public Double getSimilarity() { + return similarity; + } + + public void setSimilarity(Double similarity) { + this.similarity = similarity; + } + } +} diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/controller/ComprefaceController.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/controller/ComprefaceController.java index 61d7635..36be4a9 100644 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/controller/ComprefaceController.java +++ b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/controller/ComprefaceController.java @@ -21,10 +21,10 @@ public class ComprefaceController { private ComprefaceService comprefaceService; @PostMapping("/compreFace") - public Result compareFaces(@RequestParam("file") MultipartFile file) throws IOException { + public Result compareFaces(@RequestParam("file") MultipartFile file,@RequestParam String cameraId) throws IOException { // 调用Compreface服务进行人脸比对 - return comprefaceService.compareWithSingleFace(file); + return comprefaceService.compareWithSingleFace(file,cameraId); } diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/CameraMapper.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/CameraMapper.java index b24d855..538534d 100644 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/CameraMapper.java +++ b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/CameraMapper.java @@ -15,4 +15,6 @@ public interface CameraMapper { Integer cameraAdd(Camera camera); Integer cameraUpdate(Camera camera); + + Camera selectCamera(@Param("cameraId") String cameraId); } diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/ComprefaceMapper.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/ComprefaceMapper.java index 0feaa5e..a4ddfae 100644 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/ComprefaceMapper.java +++ b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/mapper/ComprefaceMapper.java @@ -1,6 +1,8 @@ package com.zyh.system.mapper; +import com.zyh.common.domain.Camera; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface ComprefaceMapper { diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/ComprefaceService.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/ComprefaceService.java index 0f6d1bb..0971677 100644 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/ComprefaceService.java +++ b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/ComprefaceService.java @@ -8,5 +8,5 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; public interface ComprefaceService { - Result compareWithSingleFace(MultipartFile targetImage) throws IOException; + Result compareWithSingleFace(MultipartFile targetImage,String cameraId) throws IOException; } diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/ComprefaceServicempl.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/ComprefaceServicempl.java index 17ef97d..897a43d 100644 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/ComprefaceServicempl.java +++ b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/ComprefaceServicempl.java @@ -2,9 +2,12 @@ package com.zyh.system.service.impl; import com.fasterxml.jackson.databind.ObjectMapper; import com.zyh.common.constants.RabbitMQQueueNameConstants; +import com.zyh.common.domain.Camera; import com.zyh.common.domain.CompreFaceApiResponse; +import com.zyh.common.domain.dto.CompreFaceApiResponseDto; import com.zyh.common.result.Result; import com.zyh.common.util.ComprefaceUtils; +import com.zyh.system.mapper.CameraMapper; import com.zyh.system.mapper.ComprefaceMapper; import com.zyh.system.service.ComprefaceService; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -20,31 +23,35 @@ public class ComprefaceServicempl implements ComprefaceService { @Autowired - private ComprefaceMapper comprefaceMapper; + private CameraMapper cameraMapper; @Autowired - private EsServicempl esServicempl; + private ComprefaceMapper comprefaceMapper; + @Autowired RabbitTemplate rabbitTemplate; + @Override - public Result compareWithSingleFace(MultipartFile targetImage) throws IOException { + public Result compareWithSingleFace(MultipartFile targetImage, String cameraId) throws IOException { byte[] bytes = targetImage.getBytes(); - // 将接收到的图片路径转换为 base64 + Result result = ComprefaceUtils.recognizeFace(bytes); CompreFaceApiResponse.Result data = result.getData(); + //查询设备信息 + Camera camera = cameraMapper.selectCamera(cameraId); + data.setCamera(camera); + -// esServicempl.add(data); ObjectMapper objectMapper = new ObjectMapper(); String jsonString = objectMapper.writeValueAsString(data); - rabbitTemplate.convertAndSend(RabbitMQQueueNameConstants.SEND_SMS_QUEUE_NAME, jsonString,message -> { + rabbitTemplate.convertAndSend(RabbitMQQueueNameConstants.SEND_SMS_QUEUE_NAME, jsonString, message -> { message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-", "")); return message; }); - return Result.success(data); } diff --git a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/EsServicempl.java b/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/EsServicempl.java deleted file mode 100644 index 72368a2..0000000 --- a/community-security-modules/community-security-modules-photo/src/main/java/com/zyh/system/service/impl/EsServicempl.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.zyh.system.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.zyh.common.domain.CompreFaceApiResponse; -import com.zyh.system.service.EsService; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.common.xcontent.XContentType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.io.IOException; - -@Service -public class EsServicempl implements EsService { - @Autowired - private RestHighLevelClient restHighLevelClient; - @Autowired - private ObjectMapper objectMapper; - - - private final static String INDEX_NAME = "face"; - - - public void pushToElasticsearch(CompreFaceApiResponse.Result data) { - try { - IndexRequest indexRequest = new IndexRequest(INDEX_NAME); - - // 不设置文档 ID,由 Elasticsearch 自动生成一个唯一 ID - // indexRequest.id(data.getYourId()); - - String jsonData = objectMapper.writeValueAsString(data); - indexRequest.source(jsonData, XContentType.JSON); - - IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT); - - // 可以根据 indexResponse 获取有关索引操作的信息 - System.out.println("Elasticsearch Index Response: " + indexResponse); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - public void add(CompreFaceApiResponse.Result data) { - try { - IndexRequest indexRequest = new IndexRequest(INDEX_NAME) - .source(JSONObject.toJSONString(data), XContentType.JSON); - - restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT); - } catch (IOException e) { - e.printStackTrace(); - } - } - - -} diff --git a/community-security-modules/community-security-modules-photo/src/main/resources/mapper/SysUserMapper.xml b/community-security-modules/community-security-modules-photo/src/main/resources/mapper/SysUserMapper.xml index b6b5fc4..b762f2c 100644 --- a/community-security-modules/community-security-modules-photo/src/main/resources/mapper/SysUserMapper.xml +++ b/community-security-modules/community-security-modules-photo/src/main/resources/mapper/SysUserMapper.xml @@ -20,4 +20,7 @@ +