|
@@ -1,12 +1,14 @@
|
|
|
package com.jpsoft.smart.lapi.handler;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
import com.jpsoft.smart.lapi.dto.PersonVerification;
|
|
|
import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
import com.jpsoft.smart.modules.base.service.PersonDeviceFilterLogService;
|
|
|
import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
|
|
|
import com.jpsoft.smart.modules.business.service.WorkAttendanceService;
|
|
|
import com.jpsoft.smart.modules.common.utils.LApiUtil;
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.sys.entity.SysLog;
|
|
|
import com.jpsoft.smart.modules.sys.service.SysLogService;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
@@ -15,9 +17,12 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
@@ -31,6 +36,8 @@ import java.util.HashMap;
|
|
|
@Component
|
|
|
@ChannelHandler.Sharable
|
|
|
public class PersonVerificationHandler extends SimpleChannelInboundHandler<PersonVerification> {
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private PersonDeviceLogService personDeviceLogService;
|
|
@@ -46,21 +53,27 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
|
|
|
|
|
|
@Override
|
|
|
protected void channelRead0(ChannelHandlerContext ctx, PersonVerification personVerification) throws Exception {
|
|
|
- log.warn("人员记录");
|
|
|
+ log.warn("===人员记录 begin===");
|
|
|
+ asyncWork(ctx,personVerification);
|
|
|
+ log.warn("===人员记录 end===");
|
|
|
+ }
|
|
|
|
|
|
- JSONObject jsonObject = personVerification.getJsonObject();
|
|
|
+ @Async
|
|
|
+ public void asyncWork(ChannelHandlerContext ctx,PersonVerification personVerification) {
|
|
|
+ log.warn("===人员记录异步处理 begin===");
|
|
|
|
|
|
- // log.warn(jsonObject.toString());
|
|
|
+ JSONObject jsonObject = personVerification.getJsonObject();
|
|
|
|
|
|
JSONObject faceJson = new JSONObject(jsonObject.getStr("FaceInfoList").substring(1,jsonObject.getStr("FaceInfoList").length()-1));
|
|
|
|
|
|
Long timestamp = faceJson.getLong("Timestamp");
|
|
|
+
|
|
|
if (timestamp.toString().length()<13){
|
|
|
- double timestampDouble = timestamp * Math.pow(10, 13 - timestamp.toString().length());
|
|
|
- timestamp =new Double(timestampDouble).longValue() ;
|
|
|
+ double timestampDouble = timestamp * Math.pow(10, 13 - timestamp.toString().length());
|
|
|
+ timestamp =new Double(timestampDouble).longValue() ;
|
|
|
}
|
|
|
|
|
|
- // log.warn(String.valueOf(timestamp));
|
|
|
+ //log.warn(String.valueOf(timestamp));
|
|
|
Date date = new Date(timestamp);
|
|
|
|
|
|
//设备序列号
|
|
@@ -78,7 +91,7 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
|
|
|
//匹配状态信息
|
|
|
JSONObject libMatInfoListJson = new JSONObject();
|
|
|
if (StringUtils.isNotBlank(jsonObject.getStr("LibMatInfoList").substring(1,jsonObject.getStr("LibMatInfoList").length()-1))){
|
|
|
- libMatInfoListJson = new JSONObject(jsonObject.getStr("LibMatInfoList").substring(1,jsonObject.getStr("LibMatInfoList").length()-1));
|
|
|
+ libMatInfoListJson = new JSONObject(jsonObject.getStr("LibMatInfoList").substring(1,jsonObject.getStr("LibMatInfoList").length()-1));
|
|
|
}
|
|
|
|
|
|
//匹配人员信息
|
|
@@ -96,37 +109,61 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
|
|
|
map.put("matchPersonInfo",matchPersonInfo);
|
|
|
log.warn(map.toString());
|
|
|
|
|
|
- new Thread(()->{
|
|
|
- SysLog sysLog = new SysLog();
|
|
|
- sysLog.setPointcut(deviceNo);
|
|
|
- sysLog.setUrl("/LAPI/V1.0/System/Event/Notification/PersonVerification");
|
|
|
- sysLog.setData(map.toString());
|
|
|
- sysLog.setRemark("收到人脸识别信息");
|
|
|
- SocketAddress remoteAddress = ctx.channel().remoteAddress();
|
|
|
- sysLog.setRemoteIp(remoteAddress.toString());
|
|
|
- sysLog.setCreateTime(new Date());
|
|
|
- sysLogService.insert(sysLog);
|
|
|
- }).start();
|
|
|
+ SysLog sysLog = new SysLog();
|
|
|
+ sysLog.setPointcut(deviceNo);
|
|
|
+ sysLog.setUrl("/LAPI/V1.0/System/Event/Notification/PersonVerification");
|
|
|
+ sysLog.setData(map.toString());
|
|
|
+ sysLog.setRemark("收到人脸识别信息");
|
|
|
+ SocketAddress remoteAddress = ctx.channel().remoteAddress();
|
|
|
+ sysLog.setRemoteIp(remoteAddress.toString());
|
|
|
+ sysLog.setCreateTime(new Date());
|
|
|
+ sysLogService.insert(sysLog);
|
|
|
+
|
|
|
+ //上传人脸信息
|
|
|
+ String faceImageUrl = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(faceImageJson.getStr("Data"))){
|
|
|
+ BASE64Decoder decoder = new BASE64Decoder();
|
|
|
+
|
|
|
+ byte[] imgData = decoder.decodeBuffer(faceImageJson.getStr("Data"));
|
|
|
+
|
|
|
+ for (int i = 0; i < imgData.length; ++i) {
|
|
|
+ if (imgData[i] < 0) {// 调整异常数据
|
|
|
+ imgData[i] += 256;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(imgData);
|
|
|
+
|
|
|
+
|
|
|
+ faceImageUrl = OSSUtil.upload(ossConfig, "/devicePersonLog", faceImageJson.getStr("Name"), inputStream);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存图片路径错误" + e.getMessage());
|
|
|
+ }
|
|
|
|
|
|
//记录人员记录
|
|
|
- personDeviceLogService.deviceInsertLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo,date,maskFlag);
|
|
|
+ personDeviceLogService.deviceInsertLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo,date,maskFlag,faceImageUrl);
|
|
|
|
|
|
//记录人员过滤记录
|
|
|
- personDeviceFilterLogService.deviceInsertFilterLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo,date,maskFlag);
|
|
|
+ personDeviceFilterLogService.deviceInsertFilterLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo,date,maskFlag,faceImageUrl);
|
|
|
|
|
|
//记录考勤信息
|
|
|
try {
|
|
|
- // final Integer personId = LApiUtil.getPersonCode(libMatInfoListJson, matchPersonInfo);
|
|
|
final PersonInfo personInfo = LApiUtil.getPersonCode(libMatInfoListJson, matchPersonInfo);
|
|
|
final BigDecimal fTemperature = temperature;
|
|
|
final Date recordDate = date;
|
|
|
|
|
|
if(personInfo.getId()!=null && personInfo.getId()!=0L) {
|
|
|
- new Thread(() -> workAttendanceService.punchIn(personInfo.getId(), fTemperature, recordDate)).start();
|
|
|
+ workAttendanceService.punchIn(personInfo.getId(), fTemperature, recordDate);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex){
|
|
|
log.error(ex.getMessage(),ex);
|
|
|
}
|
|
|
+
|
|
|
+ log.warn("===人员记录异步处理 end===");
|
|
|
}
|
|
|
}
|