From ae8d25d96edf6593b0502c5f2596c44110c87265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=8D=9A?= Date: Fri, 18 Oct 2024 10:44:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=95=BF=E5=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shapelight-admin/pom.xml | 4 +- .../modules/face/rtsp/RtspFrameGrabber.java | 49 +++++++++++++++---- .../modules/feignClient/CxFeignClient.java | 21 ++++++++ .../httpapi/controler/HttpApiController.java | 7 ++- .../job/task/PersonSynchronousTask.java | 5 +- 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/shapelight-admin/pom.xml b/shapelight-admin/pom.xml index 935e87e..ccfade2 100644 --- a/shapelight-admin/pom.xml +++ b/shapelight-admin/pom.xml @@ -295,11 +295,11 @@ - + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java b/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java index 369267e..6da75a9 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/face/rtsp/RtspFrameGrabber.java @@ -1,6 +1,7 @@ package net.shapelight.modules.face.rtsp; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.json.JSONObject; import com.arcsoft.face.FaceEngine; import com.arcsoft.face.FaceFeature; import com.arcsoft.face.FaceInfo; @@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import lombok.extern.slf4j.Slf4j; import net.shapelight.common.config.GlobalValue; +import net.shapelight.common.utils.Constant; import net.shapelight.modules.face.dto.FaceRecognitionResDTO; import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.enums.ErrorCodeEnum; @@ -21,6 +23,7 @@ import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.impl.FaceEngineServiceImpl; import net.shapelight.modules.face.util.UserInfo; import net.shapelight.modules.face.util.UserRamGroup; +import net.shapelight.modules.feignClient.CxFeignClient; import net.shapelight.modules.ten.entity.TenPersonEntity; import net.shapelight.modules.ten.service.TenPersonService; import org.apache.commons.pool2.impl.GenericObjectPool; @@ -28,6 +31,7 @@ import org.bytedeco.javacpp.avutil; import org.bytedeco.javacv.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; import javax.imageio.ImageIO; @@ -36,9 +40,8 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Enumeration; -import java.util.List; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import static org.bytedeco.javacpp.avutil.AV_LOG_ERROR; @@ -55,6 +58,9 @@ public class RtspFrameGrabber { @Autowired private GlobalValue globalValue; + + @Autowired + private CxFeignClient feignClient; /** * 用于记录人脸识别相关状态 */ @@ -139,7 +145,7 @@ public class RtspFrameGrabber { // logger.info("处理帧............................................."); BufferedImage bi = java2DFrameConverter.getBufferedImage(frame); byte[] bytes = imageToBytes(bi, "jpg"); - // 读取图片 + /* // 读取图片 BufferedImage image = ImageIO.read(new File("C:\\Users\\zhangbo\\OneDrive\\图片\\Camera Roll\\1寸相片.jpg")); // 创建字节输出流 @@ -149,9 +155,9 @@ public class RtspFrameGrabber { ImageIO.write(image, "jpg", baos); // 转换为byte数组 - byte[] imageBytes = baos.toByteArray(); - if (imageBytes != null && imageBytes.length > 0) { - ImageInfo imageInfo = ImageFactory.getRGBData(imageBytes); + byte[] imageBytes = baos.toByteArray();*/ + if (bytes != null && bytes.length > 0) { + ImageInfo imageInfo = ImageFactory.getRGBData(bytes); List faceInfoList = faceEngineService.detectFaces(imageInfo); if (CollectionUtil.isNotEmpty(faceInfoList)) { faceInfoList.forEach(faceInfo -> { @@ -161,8 +167,33 @@ public class RtspFrameGrabber { if (featureBytes != null) { List userInfoList = UserRamGroup.getUserList(cellId); List userCompareInfoList = faceEngineService.faceRecognition(featureBytes,userInfoList,Float.parseFloat(globalValue.getRecFaceThd())); - UserCompareInfo userCompareInfo = userCompareInfoList.get(0); - personService.update(new LambdaUpdateWrapper().set(TenPersonEntity::getIsWatchSafeVideo,1).eq(TenPersonEntity::getPersonId,userCompareInfo.getFaceId())); + if(!userCompareInfoList.isEmpty()) { + UserCompareInfo userCompareInfo = userCompareInfoList.get(0); + TenPersonEntity tenPerson = personService.getOne(new LambdaQueryWrapper() + .eq(TenPersonEntity::getPersonId,userCompareInfo.getFaceId())); + Map personnelTypeMap = new HashMap<>(); + personnelTypeMap.put(Constant.PERSON_TYPE_OWNER,"2");//内部人员 + personnelTypeMap.put(Constant.PERSON_TYPE_MEMBER,"1");//承包商 + personnelTypeMap.put(Constant.PERSON_TYPE_TENANT,"3");//长期供应商 + Map params = new HashMap<>(); + params.put("pmWatchVideoRecordId",""); + params.put("orgId",tenPerson.getOrgId()); + params.put("orgName",""); + params.put("personnelName",tenPerson.getName()); + params.put("personnelId",tenPerson.getOpenId()); + params.put("personnelCardId",tenPerson.getIdCard()); + params.put("personnelType",personnelTypeMap.get(tenPerson.getPersonType())); + params.put("dictSex",tenPerson.getGender()==0?"女":"男"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + params.put("watchVideoTime",sdf.format(System.currentTimeMillis())); + JSONObject jsonObject = feignClient.savePmWatchVideoRecord(params); + if(jsonObject.getBool("success")!=null&&jsonObject.getBool("success")) { + personService.update(new LambdaUpdateWrapper() + .set(TenPersonEntity::getIsWatchSafeVideo,1) + .eq(TenPersonEntity::getPersonId,userCompareInfo.getFaceId())); + } + } + } else { log.error("图片不合格,未检测到人脸"); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/feignClient/CxFeignClient.java b/shapelight-admin/src/main/java/net/shapelight/modules/feignClient/CxFeignClient.java index d1f08d3..15a78cc 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/feignClient/CxFeignClient.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/feignClient/CxFeignClient.java @@ -14,24 +14,45 @@ import java.util.Map; @Component public interface CxFeignClient { + /* + 获取token + */ @GetMapping("/Auth/getToken") String getToken(@RequestParam String appid, @RequestParam String appsecret); + /* + 同步安全视频观看记录 + */ @PostMapping("/ExternalService/SavePmWatchVideoRecord") JSONObject savePmWatchVideoRecord(@RequestParam Map params); + /* + 同步进出场记录 + */ @PostMapping("/ExternalService/SavePmEntryExitRecord") JSONObject savePmEntryExitRecord(@RequestParam Map params); + /* + 同步访客记录 + */ @PostMapping("/ExternalService/SavePmVisitorPersonnel") JSONObject savePmVisitorPersonnel(@RequestParam Map params); + /* + 获取内部人员信息 + */ @GetMapping("/ExternalService/GetPmInternalPersonnelList") JSONObject getPmInternalPersonnelList(@RequestParam Map params); + /* + 获取承包商信息 + */ @GetMapping("/ExternalService/GetPmContractorDataList") JSONObject getPmContractorDataList(@RequestParam Map params); + /* + 获取长期供应商信息 + */ @GetMapping("/ExternalService/GetPmSupplierDataList") JSONObject getPmSupplierDataList(@RequestParam Map params); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java b/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java index e160dcf..07d6487 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/httpapi/controler/HttpApiController.java @@ -834,7 +834,12 @@ public class HttpApiController { params.put("accessControlName",memberEntity.getOpenId()); params.put("state",""); params.put("failureReason",""); - cxFeignClient.savePmEntryExitRecord(params); + cn.hutool.json.JSONObject jsonObject = cxFeignClient.savePmEntryExitRecord(params); + if(jsonObject.getBool("success")!=null && jsonObject.getBool("success")){ + log.debug("同步进出场记录成功"); + }else { + log.debug("同步进出场记录失败"+"姓名:"+memberEntity.getName()+",errorMessage"+jsonObject.getStr("message")); + } return R.ok(); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java index 5b3ae53..937e212 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java @@ -92,13 +92,16 @@ public class PersonSynchronousTask implements ITask { } else { json = cxFeignClient.getPmSupplierDataList(params); } - if (json.getBool("success")) { + if (json.getBool("success")!=null&&json.getBool("success")) { JSONObject data = json.getJSONObject("data"); JSONArray dataList = data.getJSONArray("list"); List list1 = dataList.toList(JSONObject.class); list1.forEach(person -> { save(person,item); }); + log.debug("获取人员信息成功"+type); + } else { + log.debug("获取人员信息失败"+json.getStr("message")); } log.debug("同步inxex:"+(i+1)); }