v10:特征库分组,根据小区id

This commit is contained in:
gaoben 2024-08-14 09:32:48 +08:00
parent 88273e1a3d
commit 75cc8af2cb
17 changed files with 380 additions and 171 deletions

View File

@ -1,11 +1,17 @@
package net.shapelight.modules.face; package net.shapelight.modules.face;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.shapelight.common.config.GlobalValue;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.Base64Util; import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.ten.entity.TenCellEntity;
import net.shapelight.modules.ten.entity.TenPersonEntity; import net.shapelight.modules.ten.entity.TenPersonEntity;
import net.shapelight.modules.ten.service.TenCellService;
import net.shapelight.modules.ten.service.TenPersonService; import net.shapelight.modules.ten.service.TenPersonService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
@ -26,6 +32,10 @@ public class FaceEngineAutoRun implements ApplicationRunner {
private FaceEngineService faceEngineService; private FaceEngineService faceEngineService;
@Autowired @Autowired
private TenPersonService tenPersonService; private TenPersonService tenPersonService;
@Autowired
private TenCellService tenCellService;
@Autowired
private GlobalValue globalValue;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
@ -52,7 +62,37 @@ public class FaceEngineAutoRun implements ApplicationRunner {
// } // }
// } // }
int count = tenPersonService.findCount(); // int count = tenPersonService.findCount();
// int pageSize = 1000;
// int page = count/pageSize;
// if(count%1000!=0){
// page = page+1;
// }
// int faceCount = 0;
// for (int i = 0; i < page; i++) {
// int start = i*1000;
// List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000);
// for(TenPersonEntity personEntity: listPage){
// if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){
// UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(personEntity.getPersonId()+"");
// userInfo.setName(personEntity.getName());
// userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
// //这边注册到内存缓存中
// UserRamCache.addUser(userInfo);
// faceCount++;
// }
// }
// }
List<TenCellEntity> cellList = tenCellService.list(new QueryWrapper<TenCellEntity>()
.eq("tenant_id",globalValue.getTenantId())
.eq("delete_flag",0));
for(TenCellEntity cellEntity: cellList){
String cellId = cellEntity.getCellId()+"";
UserRamGroup.addCell(cellId);
int count = tenPersonService.findCount(cellId);
int pageSize = 1000; int pageSize = 1000;
int page = count/pageSize; int page = count/pageSize;
if(count%1000!=0){ if(count%1000!=0){
@ -61,19 +101,20 @@ public class FaceEngineAutoRun implements ApplicationRunner {
int faceCount = 0; int faceCount = 0;
for (int i = 0; i < page; i++) { for (int i = 0; i < page; i++) {
int start = i*1000; int start = i*1000;
List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000); List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000, cellId);
for(TenPersonEntity personEntity: listPage){ for(TenPersonEntity personEntity: listPage){
if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){ if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){
UserRamCache.UserInfo userInfo = new UserCompareInfo(); UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(personEntity.getPersonId()+""); userInfo.setFaceId(personEntity.getPersonId()+"");
userInfo.setName(personEntity.getName()); userInfo.setName(personEntity.getName());
userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
//这边注册到内存缓存中 //这边注册到内存缓存中
UserRamCache.addUser(userInfo); UserRamGroup.addUser(userInfo,cellId);
faceCount++; faceCount++;
} }
} }
} }
log.debug("初始化人脸库完成,共 "+faceCount+""); log.debug(cellEntity.getName()+":初始化人脸库完成,共 "+faceCount+"");
}
} }
} }

View File

@ -2,9 +2,10 @@ package net.shapelight.modules.face.entity;
import lombok.Data; import lombok.Data;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
@Data @Data
public class UserCompareInfo extends UserRamCache.UserInfo { public class UserCompareInfo extends UserInfo {
private Float similar; private Float similar;
} }

View File

@ -6,6 +6,7 @@ import com.arcsoft.face.enums.ExtractType;
import com.arcsoft.face.toolkit.ImageInfo; import com.arcsoft.face.toolkit.ImageInfo;
import net.shapelight.modules.face.entity.ProcessInfo; import net.shapelight.modules.face.entity.ProcessInfo;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import java.util.List; import java.util.List;
@ -19,12 +20,10 @@ public interface FaceEngineService {
byte[] extractFaceFeature(ImageInfo imageInfo, FaceInfo faceInfo, ExtractType extractType); byte[] extractFaceFeature(ImageInfo imageInfo, FaceInfo faceInfo, ExtractType extractType);
List<UserCompareInfo> faceRecognition(byte[] faceFeature, List<UserRamCache.UserInfo> userInfoList, float passRate) ; List<UserCompareInfo> faceRecognition(byte[] faceFeature, List<UserInfo> userInfoList, float passRate) ;
List<ProcessInfo> process(ImageInfo imageInfo, List<FaceInfo> faceInfoList); List<ProcessInfo> process(ImageInfo imageInfo, List<FaceInfo> faceInfoList);
} }

View File

@ -14,6 +14,7 @@ import net.shapelight.modules.face.enums.ErrorCodeEnum;
import net.shapelight.modules.face.factory.FaceEngineFactory; import net.shapelight.modules.face.factory.FaceEngineFactory;
import net.shapelight.modules.face.rpc.BusinessException; import net.shapelight.modules.face.rpc.BusinessException;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
@ -220,15 +221,15 @@ public class FaceEngineServiceImpl implements FaceEngineService {
} }
@Override @Override
public List<UserCompareInfo> faceRecognition(byte[] faceFeature, List<UserRamCache.UserInfo> userInfoList, float passRate) { public List<UserCompareInfo> faceRecognition(byte[] faceFeature, List<UserInfo> userInfoList, float passRate) {
List<UserCompareInfo> resultUserInfoList = Lists.newLinkedList();//识别到的人脸列表 List<UserCompareInfo> resultUserInfoList = Lists.newLinkedList();//识别到的人脸列表
FaceFeature targetFaceFeature = new FaceFeature(); FaceFeature targetFaceFeature = new FaceFeature();
targetFaceFeature.setFeatureData(faceFeature); targetFaceFeature.setFeatureData(faceFeature);
List<List<UserRamCache.UserInfo>> faceUserInfoPartList = Lists.partition(userInfoList, 1000);//分成1000一组多线程处理 List<List<UserInfo>> faceUserInfoPartList = Lists.partition(userInfoList, 1000);//分成1000一组多线程处理
CompletionService<List<UserCompareInfo>> completionService = new ExecutorCompletionService(compareExecutorService); CompletionService<List<UserCompareInfo>> completionService = new ExecutorCompletionService(compareExecutorService);
for (List<UserRamCache.UserInfo> part : faceUserInfoPartList) { for (List<UserInfo> part : faceUserInfoPartList) {
completionService.submit(new CompareFaceTask(part, targetFaceFeature, passRate)); completionService.submit(new CompareFaceTask(part, targetFaceFeature, passRate));
} }
for (int i = 0; i < faceUserInfoPartList.size(); i++) { for (int i = 0; i < faceUserInfoPartList.size(); i++) {
@ -248,6 +249,7 @@ public class FaceEngineServiceImpl implements FaceEngineService {
} }
@Override @Override
public List<ProcessInfo> process(ImageInfo imageInfo, List<FaceInfo> faceInfoList) { public List<ProcessInfo> process(ImageInfo imageInfo, List<FaceInfo> faceInfoList) {
FaceEngine faceEngine = null; FaceEngine faceEngine = null;
@ -303,12 +305,12 @@ public class FaceEngineServiceImpl implements FaceEngineService {
private class CompareFaceTask implements Callable<List<UserCompareInfo>> { private class CompareFaceTask implements Callable<List<UserCompareInfo>> {
private List<UserRamCache.UserInfo> userInfoList; private List<UserInfo> userInfoList;
private FaceFeature targetFaceFeature; private FaceFeature targetFaceFeature;
private float passRate; private float passRate;
public CompareFaceTask(List<UserRamCache.UserInfo> userInfoList, FaceFeature targetFaceFeature, float passRate) { public CompareFaceTask(List<UserInfo> userInfoList, FaceFeature targetFaceFeature, float passRate) {
this.userInfoList = userInfoList; this.userInfoList = userInfoList;
this.targetFaceFeature = targetFaceFeature; this.targetFaceFeature = targetFaceFeature;
this.passRate = passRate; this.passRate = passRate;
@ -320,7 +322,7 @@ public class FaceEngineServiceImpl implements FaceEngineService {
List<UserCompareInfo> resultUserInfoList = Lists.newLinkedList();//识别到的人脸列表 List<UserCompareInfo> resultUserInfoList = Lists.newLinkedList();//识别到的人脸列表
try { try {
faceEngine = faceEngineComparePool.borrowObject(); faceEngine = faceEngineComparePool.borrowObject();
for (UserRamCache.UserInfo userInfo : userInfoList) { for (UserInfo userInfo : userInfoList) {
FaceFeature sourceFaceFeature = new FaceFeature(); FaceFeature sourceFaceFeature = new FaceFeature();
sourceFaceFeature.setFeatureData(userInfo.getFaceFeature()); sourceFaceFeature.setFeatureData(userInfo.getFaceFeature());
FaceSimilar faceSimilar = new FaceSimilar(); FaceSimilar faceSimilar = new FaceSimilar();

View File

@ -0,0 +1,11 @@
package net.shapelight.modules.face.util;
import lombok.Data;
@Data
public class UserInfo {
private String faceId;
private String name;
private byte[] faceFeature;
}

View File

@ -10,51 +10,51 @@ import java.util.concurrent.CopyOnWriteArraySet;
public class UserRamCache { public class UserRamCache {
private static final ConcurrentHashMap<String, UserInfo> USER_INFO_MAP = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, UserInfo> USER_INFO_MAP = new ConcurrentHashMap<>();
private static final Set<Listener> REGISTER = new CopyOnWriteArraySet<>(); private final Set<Listener> REGISTER = new CopyOnWriteArraySet<>();
public static void addUser(UserInfo userInfo) { public void addUser(UserInfo userInfo) {
USER_INFO_MAP.put(userInfo.getFaceId(), userInfo); USER_INFO_MAP.put(userInfo.getFaceId(), userInfo);
for (Listener listener : REGISTER) { for (Listener listener : REGISTER) {
listener.onAdd(userInfo); listener.onAdd(userInfo);
} }
} }
public static void removeUser(String faceId) { public void removeUser(String faceId) {
UserInfo userInfo = USER_INFO_MAP.remove(faceId); UserInfo userInfo = USER_INFO_MAP.remove(faceId);
for (Listener listener : REGISTER) { for (Listener listener : REGISTER) {
listener.onRemove(userInfo); listener.onRemove(userInfo);
} }
} }
public static List<UserInfo> getUserList() { public List<UserInfo> getUserList() {
List<UserInfo> userInfoList = Lists.newLinkedList(); List<UserInfo> userInfoList = Lists.newLinkedList();
userInfoList.addAll(USER_INFO_MAP.values()); userInfoList.addAll(USER_INFO_MAP.values());
return userInfoList; return userInfoList;
} }
public static void clear(){ public void clear(){
USER_INFO_MAP.clear(); USER_INFO_MAP.clear();
REGISTER.clear(); REGISTER.clear();
} }
public static void addListener(Listener listener) { public void addListener(Listener listener) {
REGISTER.add(listener); REGISTER.add(listener);
} }
public static void removeListener(Listener listener) { public void removeListener(Listener listener) {
REGISTER.remove(listener); REGISTER.remove(listener);
} }
@Data // @Data
public static class UserInfo { // public class UserInfo {
//
private String faceId; // private String faceId;
private String name; // private String name;
private byte[] faceFeature; // private byte[] faceFeature;
//
} // }
public interface Listener { public interface Listener {
default void onAdd(UserInfo userInfo) { default void onAdd(UserInfo userInfo) {

View File

@ -0,0 +1,34 @@
package net.shapelight.modules.face.util;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class UserRamGroup {
private static final ConcurrentHashMap<String, UserRamCache> USER_RAM_GROUP_MAP = new ConcurrentHashMap<>();
public static void addCell(String cellId){
UserRamCache cell = new UserRamCache();
USER_RAM_GROUP_MAP.put(cellId,cell);
}
public static void removeCell(String cellId){
USER_RAM_GROUP_MAP.remove(cellId);
}
public static void addUser(UserInfo userInfo, String cellId) {
USER_RAM_GROUP_MAP.get(cellId).addUser(userInfo);
}
public static void removeUser(String faceId, String cellId) {
USER_RAM_GROUP_MAP.get(cellId).removeUser(faceId);
}
public static List<UserInfo> getUserList(String cellId) {
return USER_RAM_GROUP_MAP.get(cellId).getUserList();
}
public static void clear(){
USER_RAM_GROUP_MAP.clear();
}
}

View File

@ -18,6 +18,7 @@ import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.rpc.Response; import net.shapelight.modules.face.rpc.Response;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.Base64Util; import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -71,47 +72,47 @@ public class FaceController {
/* /*
人脸添加 人脸添加
*/ */
@RequestMapping(value = "/faceAdd", method = RequestMethod.POST) // @RequestMapping(value = "/faceAdd", method = RequestMethod.POST)
@ResponseBody // @ResponseBody
public Response faceAdd(@RequestBody FaceAddReqDTO faceAddReqDTO) { // public Response faceAdd(@RequestBody FaceAddReqDTO faceAddReqDTO) {
String image = faceAddReqDTO.getImage(); // String image = faceAddReqDTO.getImage();
//
byte[] bytes = Base64Util.base64ToBytes(image); // byte[] bytes = Base64Util.base64ToBytes(image);
ImageInfo rgbData = ImageFactory.getRGBData(bytes); // ImageInfo rgbData = ImageFactory.getRGBData(bytes);
List<FaceInfo> faceInfoList = faceEngineService.detectFaces(rgbData); // List<FaceInfo> faceInfoList = faceEngineService.detectFaces(rgbData);
if (CollectionUtil.isNotEmpty(faceInfoList)) { // if (CollectionUtil.isNotEmpty(faceInfoList)) {
for (FaceInfo faceInfo : faceInfoList) { // for (FaceInfo faceInfo : faceInfoList) {
FaceRecognitionResDTO faceRecognitionResDTO = new FaceRecognitionResDTO(); // FaceRecognitionResDTO faceRecognitionResDTO = new FaceRecognitionResDTO();
faceRecognitionResDTO.setRect(faceInfo.getRect()); // faceRecognitionResDTO.setRect(faceInfo.getRect());
byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo,ExtractType.REGISTER); // byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo,ExtractType.REGISTER);
if (feature != null) { // if (feature != null) {
UserRamCache.UserInfo userInfo = new UserCompareInfo(); // UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(faceAddReqDTO.getName()); // userInfo.setFaceId(faceAddReqDTO.getName());
userInfo.setName(faceAddReqDTO.getName()); // userInfo.setName(faceAddReqDTO.getName());
userInfo.setFaceFeature(feature); // userInfo.setFaceFeature(feature);
//这边注册到内存缓存中也可以根据业务注册到数据库中 // //这边注册到内存缓存中也可以根据业务注册到数据库中
UserRamCache.addUser(userInfo); // UserRamCache.addUser(userInfo);
} // }
} // }
} // }
return Response.newSuccessResponse(""); // return Response.newSuccessResponse("");
} // }
@RequestMapping(value = "/getFaceList", method = RequestMethod.POST) // @RequestMapping(value = "/getFaceList", method = RequestMethod.POST)
@ResponseBody // @ResponseBody
public Response<List<GetFaceListResDTO>> getFaceList() { // public Response<List<GetFaceListResDTO>> getFaceList() {
List<UserRamCache.UserInfo> userList = UserRamCache.getUserList(); // List<UserInfo> userList = UserRamCache.getUserList();
List<GetFaceListResDTO> resDTOS = new LinkedList<>(); // List<GetFaceListResDTO> resDTOS = new LinkedList<>();
for (UserRamCache.UserInfo userInfo : userList) { // for (UserInfo userInfo : userList) {
GetFaceListResDTO face = new GetFaceListResDTO(); // GetFaceListResDTO face = new GetFaceListResDTO();
face.setId(userInfo.getFaceId()); // face.setId(userInfo.getFaceId());
face.setName(userInfo.getName()); // face.setName(userInfo.getName());
face.setUrl("/images/" + face.getId() + ".jpg"); // face.setUrl("/images/" + face.getId() + ".jpg");
resDTOS.add(face); // resDTOS.add(face);
} // }
return Response.newSuccessResponse(resDTOS); // return Response.newSuccessResponse(resDTOS);
} // }
// @RequestMapping(value = "/recognition", method = RequestMethod.POST) // @RequestMapping(value = "/recognition", method = RequestMethod.POST)
@ -156,35 +157,35 @@ public class FaceController {
/* /*
人脸识别 人脸识别
*/ */
@RequestMapping(value = "/faceRecognition", method = RequestMethod.POST) // @RequestMapping(value = "/faceRecognition", method = RequestMethod.POST)
@ResponseBody // @ResponseBody
public Response<List<FaceRecognitionResDTO>> faceRecognition(@RequestBody FaceRecognitionReqDTO faceRecognitionReqDTO) { // public Response<List<FaceRecognitionResDTO>> faceRecognition(@RequestBody FaceRecognitionReqDTO faceRecognitionReqDTO) {
String image = faceRecognitionReqDTO.getImage(); // String image = faceRecognitionReqDTO.getImage();
//
List<FaceRecognitionResDTO> faceRecognitionResDTOList = Lists.newLinkedList(); // List<FaceRecognitionResDTO> faceRecognitionResDTOList = Lists.newLinkedList();
byte[] bytes = Base64Util.base64ToBytes(image); // byte[] bytes = Base64Util.base64ToBytes(image);
ImageInfo rgbData = ImageFactory.getRGBData(bytes); // ImageInfo rgbData = ImageFactory.getRGBData(bytes);
List<FaceInfo> faceInfoList = faceEngineService.detectFaces(rgbData); // List<FaceInfo> faceInfoList = faceEngineService.detectFaces(rgbData);
if (CollectionUtil.isNotEmpty(faceInfoList)) { // if (CollectionUtil.isNotEmpty(faceInfoList)) {
for (FaceInfo faceInfo : faceInfoList) { // for (FaceInfo faceInfo : faceInfoList) {
FaceRecognitionResDTO faceRecognitionResDTO = new FaceRecognitionResDTO(); // FaceRecognitionResDTO faceRecognitionResDTO = new FaceRecognitionResDTO();
faceRecognitionResDTO.setRect(faceInfo.getRect()); // faceRecognitionResDTO.setRect(faceInfo.getRect());
byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo,ExtractType.RECOGNIZE); // byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo,ExtractType.RECOGNIZE);
if (feature != null) { // if (feature != null) {
List<UserCompareInfo> userCompareInfos = faceEngineService.faceRecognition(feature, UserRamCache.getUserList(), 0.8f); // List<UserCompareInfo> userCompareInfos = faceEngineService.faceRecognition(feature, UserRamCache.getUserList(), 0.8f);
if (CollectionUtil.isNotEmpty(userCompareInfos)) { // if (CollectionUtil.isNotEmpty(userCompareInfos)) {
faceRecognitionResDTO.setName(userCompareInfos.get(0).getName()); // faceRecognitionResDTO.setName(userCompareInfos.get(0).getName());
faceRecognitionResDTO.setSimilar(userCompareInfos.get(0).getSimilar()); // faceRecognitionResDTO.setSimilar(userCompareInfos.get(0).getSimilar());
} // }
} // }
faceRecognitionResDTOList.add(faceRecognitionResDTO); // faceRecognitionResDTOList.add(faceRecognitionResDTO);
} // }
//
} // }
//
//
return Response.newSuccessResponse(faceRecognitionResDTOList); // return Response.newSuccessResponse(faceRecognitionResDTOList);
} // }
@RequestMapping(value = "/detectFaces", method = RequestMethod.POST) @RequestMapping(value = "/detectFaces", method = RequestMethod.POST)
@ResponseBody @ResponseBody

View File

@ -26,7 +26,10 @@ import net.shapelight.modules.app.service.AppUserService;
import net.shapelight.modules.face.dto.FaceRecognitionResDTO; import net.shapelight.modules.face.dto.FaceRecognitionResDTO;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.httpapi.service.AuthService; import net.shapelight.modules.httpapi.service.AuthService;
import net.shapelight.modules.httpapi.service.RecordSaveSyncService; import net.shapelight.modules.httpapi.service.RecordSaveSyncService;
import net.shapelight.modules.nettyapi.config.CmdConstant; import net.shapelight.modules.nettyapi.config.CmdConstant;
@ -1474,6 +1477,7 @@ public class HttpApiController {
return res; return res;
} }
log.debug("设备端识别人员开始---------------------------------------------"+sn); log.debug("设备端识别人员开始---------------------------------------------"+sn);
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
// if (faceFile.isEmpty() || faceFile.getSize() == 0) { // if (faceFile.isEmpty() || faceFile.getSize() == 0) {
// return R.error("文件不能为空"); // return R.error("文件不能为空");
// } // }
@ -1496,7 +1500,8 @@ public class HttpApiController {
// faceRecognitionResDTO.setRect(faceInfo.getRect()); // faceRecognitionResDTO.setRect(faceInfo.getRect());
byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo, ExtractType.RECOGNIZE); byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfo, ExtractType.RECOGNIZE);
if (feature != null) { if (feature != null) {
List<UserCompareInfo> userCompareInfos = faceEngineService.faceRecognition(feature, UserRamCache.getUserList(), 0.8f); // List<UserCompareInfo> userCompareInfos = faceEngineService.faceRecognition(feature, UserRamCache.getUserList(), 0.8f);
List<UserCompareInfo> userCompareInfos = faceEngineService.faceRecognition(feature, UserRamGroup.getUserList(deviceEntity.getCellId()+""), 0.8f);
if (CollectionUtil.isNotEmpty(userCompareInfos)) { if (CollectionUtil.isNotEmpty(userCompareInfos)) {
faceRecognitionResDTO = new FaceRecognitionResDTO(); faceRecognitionResDTO = new FaceRecognitionResDTO();
faceRecognitionResDTO.setPersonId(userCompareInfos.get(0).getFaceId()); faceRecognitionResDTO.setPersonId(userCompareInfos.get(0).getFaceId());
@ -1523,7 +1528,7 @@ public class HttpApiController {
//身份证比对成功访客 //身份证比对成功访客
//----------------------------------------以下业务----------------------------------------------------- //----------------------------------------以下业务-----------------------------------------------------
log.debug("身份证人脸识别成功保存识别记录:"+sn); log.debug("身份证人脸识别成功保存识别记录:"+sn);
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); // TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
TenRecordEntity record = new TenRecordEntity(); TenRecordEntity record = new TenRecordEntity();
record.setDeviceSn(sn); record.setDeviceSn(sn);
@ -1605,7 +1610,7 @@ public class HttpApiController {
//----------------------------------------以下业务----------------------------------------------------- //----------------------------------------以下业务-----------------------------------------------------
log.debug("人脸识别成功:"+sn); log.debug("人脸识别成功:"+sn);
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); // TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
boolean passFlag = false; boolean passFlag = false;
if(tenPersonEntity.getPersonType() == Constant.PERSON_TYPE_GUEST){ if(tenPersonEntity.getPersonType() == Constant.PERSON_TYPE_GUEST){
//访客直接判断有效期 //访客直接判断有效期
@ -1706,7 +1711,7 @@ public class HttpApiController {
} }
}else{ }else{
if(icCard !=null && icCard.length()>0){ if(icCard !=null && icCard.length()>0){
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); // TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
TenPersonEntity tenPersonEntity = tenPersonService.findByIcCardTop(icCard,deviceEntity.getTenantId()+""); TenPersonEntity tenPersonEntity = tenPersonService.findByIcCardTop(icCard,deviceEntity.getTenantId()+"");
if(tenPersonEntity!=null){ if(tenPersonEntity!=null){
@ -1941,13 +1946,21 @@ public class HttpApiController {
tenPersonService.updateByIdCard(personEntity); tenPersonService.updateByIdCard(personEntity);
} }
//特征保存到内存 //特征保存到内存
UserRamCache.removeUser(personEntity.getPersonId()+""); // UserRamCache.removeUser(personEntity.getPersonId()+"");
log.debug("内存删除人员:"+personEntity.getPersonId()+" 姓名:"+personEntity.getName()); // log.debug("内存删除人员:"+personEntity.getPersonId()+" 姓名:"+personEntity.getName());
UserRamCache.UserInfo userInfo = new UserCompareInfo(); // UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(personEntity.getPersonId()+"");
// userInfo.setName(personEntity.getName());
// userInfo.setFaceFeature(Base64.getDecoder().decode(personEntity.getFeature()));
// UserRamCache.addUser(userInfo);
UserRamGroup.removeUser(personEntity.getPersonId()+"",deviceEntity.getCellId()+"");
UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(personEntity.getPersonId()+""); userInfo.setFaceId(personEntity.getPersonId()+"");
userInfo.setName(personEntity.getName()); userInfo.setName(personEntity.getName());
userInfo.setFaceFeature(Base64.getDecoder().decode(personEntity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
UserRamCache.addUser(userInfo); //这边注册到内存缓存中
UserRamGroup.addUser(userInfo,deviceEntity.getCellId()+"");
log.debug("内存增加人员:"+personEntity.getPersonId()+" 姓名:"+personEntity.getName()); log.debug("内存增加人员:"+personEntity.getPersonId()+" 姓名:"+personEntity.getName());
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
JSONObject personRes = new JSONObject(); JSONObject personRes = new JSONObject();

View File

@ -1,5 +1,6 @@
package net.shapelight.modules.job.task; package net.shapelight.modules.job.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.minio.MinioClient; import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.shapelight.common.config.GlobalValue; import net.shapelight.common.config.GlobalValue;
@ -8,8 +9,11 @@ import net.shapelight.common.utils.RedisUtils;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.Base64Util; import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.sys.service.SysUserService; import net.shapelight.modules.sys.service.SysUserService;
import net.shapelight.modules.ten.entity.TenCellEntity;
import net.shapelight.modules.ten.entity.TenPersonEntity; import net.shapelight.modules.ten.entity.TenPersonEntity;
import net.shapelight.modules.ten.entity.TenRecordEntity; import net.shapelight.modules.ten.entity.TenRecordEntity;
import net.shapelight.modules.ten.service.TenCellService; import net.shapelight.modules.ten.service.TenCellService;
@ -28,15 +32,52 @@ public class FaceRestartTask implements ITask {
private FaceEngineService faceEngineService; private FaceEngineService faceEngineService;
@Autowired @Autowired
private TenPersonService tenPersonService; private TenPersonService tenPersonService;
@Autowired
private TenCellService tenCellService;
@Autowired
private GlobalValue globalValue;
@Override @Override
public void run(String params){ public void run(String params){
log.debug("faceEngin restart ............................................."); log.debug("faceEngin restart .............................................");
//clear all face //clear all face
UserRamCache.clear(); // UserRamCache.clear();
//
// int count = tenPersonService.findCount();
// int pageSize = 1000;
// int page = count/pageSize;
// if(count%1000!=0){
// page = page+1;
// }
// int faceCount = 0;
// for (int i = 0; i < page; i++) {
// int start = i*1000;
// List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000);
// for(TenPersonEntity personEntity: listPage){
// if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){
// UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(personEntity.getPersonId()+"");
// userInfo.setName(personEntity.getName());
// userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
// //这边注册到内存缓存中
// UserRamCache.addUser(userInfo);
// faceCount++;
// }
// }
// }
// log.debug("初始化人脸库完成,共 "+faceCount+"");
int count = tenPersonService.findCount();
//清除分组
UserRamGroup.clear();
List<TenCellEntity> cellList = tenCellService.list(new QueryWrapper<TenCellEntity>()
.eq("tenant_id",globalValue.getTenantId())
.eq("delete_flag",0));
for(TenCellEntity cellEntity: cellList){
String cellId = cellEntity.getCellId()+"";
UserRamGroup.addCell(cellId);
int count = tenPersonService.findCount(cellId);
int pageSize = 1000; int pageSize = 1000;
int page = count/pageSize; int page = count/pageSize;
if(count%1000!=0){ if(count%1000!=0){
@ -45,20 +86,21 @@ public class FaceRestartTask implements ITask {
int faceCount = 0; int faceCount = 0;
for (int i = 0; i < page; i++) { for (int i = 0; i < page; i++) {
int start = i*1000; int start = i*1000;
List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000); List<TenPersonEntity> listPage = tenPersonService.listPage(start,1000, cellId);
for(TenPersonEntity personEntity: listPage){ for(TenPersonEntity personEntity: listPage){
if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){ if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){
UserRamCache.UserInfo userInfo = new UserCompareInfo(); UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(personEntity.getPersonId()+""); userInfo.setFaceId(personEntity.getPersonId()+"");
userInfo.setName(personEntity.getName()); userInfo.setName(personEntity.getName());
userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
//这边注册到内存缓存中 //这边注册到内存缓存中
UserRamCache.addUser(userInfo); UserRamGroup.addUser(userInfo,cellId);
faceCount++; faceCount++;
} }
} }
} }
log.debug("初始化人脸库完成,共 "+faceCount+""); log.debug(cellEntity.getName()+":初始化人脸库完成,共 "+faceCount+"");
}
log.debug("faceEngin restart end............................................."); log.debug("faceEngin restart end.............................................");
} }
} }

View File

@ -8,6 +8,7 @@ import net.shapelight.common.utils.Constant;
import net.shapelight.common.utils.DateUtils; import net.shapelight.common.utils.DateUtils;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.nettyapi.service.ServerApiService;
import net.shapelight.modules.sys.entity.SysDbBakEntity; import net.shapelight.modules.sys.entity.SysDbBakEntity;
import net.shapelight.modules.sys.service.SysDbBakService; import net.shapelight.modules.sys.service.SysDbBakService;
@ -52,7 +53,8 @@ public class PersonProcessTask implements ITask {
//修改人员表 //修改人员表
tenPersonService.updateStatusById(guest); tenPersonService.updateStatusById(guest);
//特征保存到内存 //特征保存到内存
UserRamCache.removeUser(guest.getPersonId()+""); UserRamGroup.removeUser(guest.getPersonId()+"",guest.getCellId()+"");
// UserRamCache.removeUser(guest.getPersonId()+"");
log.debug("内存删除人员:"+guest.getPersonId()+" 姓名:"+guest.getName()); log.debug("内存删除人员:"+guest.getPersonId()+" 姓名:"+guest.getName());
//修改同步表 //修改同步表
// List<TenPersonSyncEntity> syncEntityList = tenPersonSyncService.findByPersonId(guest.getPersonId(),guest.getTenantId()); // List<TenPersonSyncEntity> syncEntityList = tenPersonSyncService.findByPersonId(guest.getPersonId(),guest.getTenantId());

View File

@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
import net.shapelight.common.annotation.SysLog; import net.shapelight.common.annotation.SysLog;
import net.shapelight.common.utils.Constant; import net.shapelight.common.utils.Constant;
import net.shapelight.common.utils.SnowflakeIdWorker; import net.shapelight.common.utils.SnowflakeIdWorker;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.sys.controller.AbstractController;
import net.shapelight.modules.sys.entity.SysUserEntity; import net.shapelight.modules.sys.entity.SysUserEntity;
import net.shapelight.modules.sys.service.SysUserRoleService; import net.shapelight.modules.sys.service.SysUserRoleService;
@ -108,6 +109,8 @@ public class TenCellController extends AbstractController {
tenCell.setCreateTime(new Date()); tenCell.setCreateTime(new Date());
tenCellService.save(tenCell); tenCellService.save(tenCell);
UserRamGroup.addCell(id+"");
return R.ok(); return R.ok();
} }
@ -144,6 +147,8 @@ public class TenCellController extends AbstractController {
tenCellService.removeByIds(Arrays.asList(ids)); tenCellService.removeByIds(Arrays.asList(ids));
//删除小区绑定的设备 //删除小区绑定的设备
tenDeviceService.evictRemoveByCellIds(ids); tenDeviceService.evictRemoveByCellIds(ids);
UserRamGroup.addCell(ids[0]+"");
return R.ok(); return R.ok();
} }

View File

@ -26,7 +26,10 @@ import net.shapelight.modules.app.entity.AppUserEntity;
import net.shapelight.modules.app.service.AppUserService; import net.shapelight.modules.app.service.AppUserService;
import net.shapelight.modules.excel.model.PersonModel; import net.shapelight.modules.excel.model.PersonModel;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.nettyapi.service.ServerApiService;
import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.sys.controller.AbstractController;
import net.shapelight.modules.sys.entity.SysUserEntity; import net.shapelight.modules.sys.entity.SysUserEntity;
@ -168,6 +171,12 @@ public class TenPersonController extends AbstractController {
} }
params.put("personType", Constant.PERSON_TYPE_GUEST); params.put("personType", Constant.PERSON_TYPE_GUEST);
PageUtils page = tenPersonService.queryPage(params); PageUtils page = tenPersonService.queryPage(params);
// Date now = new Date();
// for (TenPersonEntity guest : (List<TenPersonEntity>)page.getList()) {
// if(guest.getLiveEnd().getTime()<now.getTime()){
// guest.setStatus(Constant.PESON_SUATUS_GUEST_DATE_OUT);
// }
// }
return R.ok().put("data", page); return R.ok().put("data", page);
} }
@ -539,17 +548,27 @@ public class TenPersonController extends AbstractController {
tenPerson.setLastUpdateBy(getUser().getUsername()); tenPerson.setLastUpdateBy(getUser().getUsername());
tenPerson.setLastUpdateTime(new Date()); tenPerson.setLastUpdateTime(new Date());
tenPersonService.updateStatusById(tenPerson); tenPersonService.updateStatusById(tenPerson);
TenPersonEntity entity = tenPersonService.getByIdWithDelete(tenPerson.getPersonId());
//特征保存到内存 //特征保存到内存
UserRamCache.removeUser(tenPerson.getPersonId()+""); // UserRamCache.removeUser(tenPerson.getPersonId()+"");
UserRamGroup.removeUser(tenPerson.getPersonId()+"",entity.getCellId()+"");
log.debug("内存删除人员:"+tenPerson.getPersonId()+" 姓名:"+tenPerson.getName()); log.debug("内存删除人员:"+tenPerson.getPersonId()+" 姓名:"+tenPerson.getName());
if(tenPerson.getStatus().intValue() == 0){ if(tenPerson.getStatus().intValue() == 0){
TenPersonEntity entity = tenPersonService.getByIdWithDelete(tenPerson.getPersonId());
UserRamCache.UserInfo userInfo = new UserCompareInfo(); // UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(entity.getPersonId()+"");
// userInfo.setName(entity.getName());
// userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature()));
// UserRamCache.addUser(userInfo);
// log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName());
UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(entity.getPersonId()+""); userInfo.setFaceId(entity.getPersonId()+"");
userInfo.setName(entity.getName()); userInfo.setName(entity.getName());
userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(entity.getFeature()));
UserRamCache.addUser(userInfo); //这边注册到内存缓存中
log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName()); UserRamGroup.addUser(userInfo,entity.getCellId()+"");
} }
//一下推送 //一下推送

View File

@ -119,9 +119,9 @@ public interface TenPersonDao {
List<TenPersonEntity> findByIdCardAndDept(@Param("idCard")String idCard, @Param("deptId")Long deptId); List<TenPersonEntity> findByIdCardAndDept(@Param("idCard")String idCard, @Param("deptId")Long deptId);
List<TenPersonEntity> listPage(@Param("start")int start, @Param("count")int count); List<TenPersonEntity> listPage(@Param("start")int start, @Param("count")int count, @Param("cellId")String cellId);
int findCount(); int findCount(@Param("cellId")String cellId);
int findByIdCardCount(@Param("idCard")String idCard, @Param("tenantId")String tenantId); int findByIdCardCount(@Param("idCard")String idCard, @Param("tenantId")String tenantId);

View File

@ -145,9 +145,9 @@ public interface TenPersonService {
List<TenPersonEntity> findByIdCardAndDept(String idCard, List<TenPersonEntity> findByIdCardAndDept(String idCard,
Long deptId); Long deptId);
List<TenPersonEntity> listPage(int start, int count); List<TenPersonEntity> listPage(int start, int count, String cellId);
int findCount(); int findCount(String cellId);
TenLabelEntity findLabelByName(String name, String tenantId); TenLabelEntity findLabelByName(String name, String tenantId);

View File

@ -27,7 +27,9 @@ import net.shapelight.modules.face.dto.FaceRecognitionResDTO;
import net.shapelight.modules.face.entity.UserCompareInfo; import net.shapelight.modules.face.entity.UserCompareInfo;
import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.service.FaceEngineService;
import net.shapelight.modules.face.util.Base64Util; import net.shapelight.modules.face.util.Base64Util;
import net.shapelight.modules.face.util.UserInfo;
import net.shapelight.modules.face.util.UserRamCache; import net.shapelight.modules.face.util.UserRamCache;
import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.nettyapi.service.ServerApiService;
import net.shapelight.modules.ten.entity.*; import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.ten.service.*; import net.shapelight.modules.ten.service.*;
@ -454,13 +456,22 @@ public class TenPersonServiceImpl implements TenPersonService {
// } // }
int flag = tenPersonDao.insert(entity); int flag = tenPersonDao.insert(entity);
//特征保存到内存 //特征保存到内存
UserRamCache.UserInfo userInfo = new UserCompareInfo(); // UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(entity.getPersonId()+"");
// userInfo.setName(entity.getName());
// userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature()));
// UserRamCache.addUser(userInfo);
UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(entity.getPersonId()+""); userInfo.setFaceId(entity.getPersonId()+"");
userInfo.setName(entity.getName()); userInfo.setName(entity.getName());
userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(entity.getFeature()));
UserRamCache.addUser(userInfo); //这边注册到内存缓存中
UserRamGroup.addUser(userInfo,entity.getCellId()+"");
log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName()); log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName());
////访客添加失效redisKey ////访客添加失效redisKey
// if(entity.getPersonType() == Constant.PERSON_TYPE_GUEST){ // if(entity.getPersonType() == Constant.PERSON_TYPE_GUEST){
// //
@ -893,7 +904,8 @@ public class TenPersonServiceImpl implements TenPersonService {
//删除人员 //删除人员
tenPersonDao.logicDeleteById(personId, cellId); tenPersonDao.logicDeleteById(personId, cellId);
//基础人脸库 //基础人脸库
UserRamCache.removeUser(personId+""); // UserRamCache.removeUser(personId+"");
UserRamGroup.removeUser(personId+"",cellId+"");
log.debug("内存移除人员:"+personId); log.debug("内存移除人员:"+personId);
//记录所有人员id //记录所有人员id
@ -1479,13 +1491,23 @@ public class TenPersonServiceImpl implements TenPersonService {
//特征保存到内存 //特征保存到内存
if(entity.getFeature()!=null && entity.getFeature().length()>0){ if(entity.getFeature()!=null && entity.getFeature().length()>0){
UserRamCache.removeUser(entity.getPersonId()+""); // UserRamCache.removeUser(entity.getPersonId()+"");
// log.debug("内存删除人员:"+entity.getPersonId()+" 姓名:"+entity.getName());
// UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(entity.getPersonId()+"");
// userInfo.setName(entity.getName());
// userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature()));
// UserRamCache.addUser(userInfo);
UserRamGroup.removeUser(entity.getPersonId()+"",entity.getCellId()+"");
log.debug("内存删除人员:"+entity.getPersonId()+" 姓名:"+entity.getName()); log.debug("内存删除人员:"+entity.getPersonId()+" 姓名:"+entity.getName());
UserRamCache.UserInfo userInfo = new UserCompareInfo(); UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(entity.getPersonId()+""); userInfo.setFaceId(entity.getPersonId()+"");
userInfo.setName(entity.getName()); userInfo.setName(entity.getName());
userInfo.setFaceFeature(Base64.getDecoder().decode(entity.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(entity.getFeature()));
UserRamCache.addUser(userInfo); //这边注册到内存缓存中
UserRamGroup.addUser(userInfo,entity.getCellId()+"");
log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName()); log.debug("内存增加人员:"+entity.getPersonId()+" 姓名:"+entity.getName());
//配置同步数据 //配置同步数据
List<TenPersonSyncEntity> syncEntitys = tenPersonSyncService.findByPersonId(entity.getPersonId(), entity.getTenantId()); List<TenPersonSyncEntity> syncEntitys = tenPersonSyncService.findByPersonId(entity.getPersonId(), entity.getTenantId());
@ -2159,11 +2181,20 @@ public class TenPersonServiceImpl implements TenPersonService {
tenPersonDao.insert(tenPerson); tenPersonDao.insert(tenPerson);
//特征保存到内存 //特征保存到内存
if(tenPerson.getFeature()!=null && tenPerson.getFeature().length()>0){ if(tenPerson.getFeature()!=null && tenPerson.getFeature().length()>0){
UserRamCache.UserInfo userInfo = new UserCompareInfo(); // UserRamCache.UserInfo userInfo = new UserCompareInfo();
// userInfo.setFaceId(tenPerson.getPersonId()+"");
// userInfo.setName(tenPerson.getName());
// userInfo.setFaceFeature(Base64.getDecoder().decode(tenPerson.getFeature()));
// UserRamCache.addUser(userInfo);
// log.debug("内存增加人员:"+tenPerson.getPersonId()+" 姓名:"+tenPerson.getName());
UserInfo userInfo = new UserCompareInfo();
userInfo.setFaceId(tenPerson.getPersonId()+""); userInfo.setFaceId(tenPerson.getPersonId()+"");
userInfo.setName(tenPerson.getName()); userInfo.setName(tenPerson.getName());
userInfo.setFaceFeature(Base64.getDecoder().decode(tenPerson.getFeature())); userInfo.setFaceFeature(Base64Util.base64ToBytes(tenPerson.getFeature()));
UserRamCache.addUser(userInfo); //这边注册到内存缓存中
UserRamGroup.addUser(userInfo,tenPerson.getCellId()+"");
log.debug("内存增加人员:"+tenPerson.getPersonId()+" 姓名:"+tenPerson.getName()); log.debug("内存增加人员:"+tenPerson.getPersonId()+" 姓名:"+tenPerson.getName());
} }
@ -2487,13 +2518,13 @@ public class TenPersonServiceImpl implements TenPersonService {
} }
@Override @Override
public List<TenPersonEntity> listPage(int start, int count) { public List<TenPersonEntity> listPage(int start, int count, String cellId) {
return tenPersonDao.listPage(start, count); return tenPersonDao.listPage(start, count, cellId);
} }
@Override @Override
public int findCount() { public int findCount(String cellId) {
return tenPersonDao.findCount(); return tenPersonDao.findCount(cellId);
} }
@Override @Override

View File

@ -1353,11 +1353,19 @@
</select> </select>
<select id="listPage" resultType="net.shapelight.modules.ten.entity.TenPersonEntity"> <select id="listPage" resultType="net.shapelight.modules.ten.entity.TenPersonEntity">
select * from ten_person where delete_flag = 0 and status = 0 limit #{start},#{count} select * from ten_person where delete_flag = 0
and status = 0
<if test="cellId != null and cellId!=''">
and cell_id = #{cellId}
</if>
limit #{start},#{count}
</select> </select>
<select id="findCount" resultType="int"> <select id="findCount" resultType="int">
select count(*) from ten_person where delete_flag = 0 and status = 0 select count(*) from ten_person where delete_flag = 0 and status = 0
<if test="cellId != null and cellId!=''">
and cell_id = #{cellId}
</if>
</select> </select>
<select id="findByIdCardList" resultType="net.shapelight.modules.ten.entity.TenPersonEntity"> <select id="findByIdCardList" resultType="net.shapelight.modules.ten.entity.TenPersonEntity">