121 lines
5.2 KiB
Java
121 lines
5.2 KiB
Java
|
package com.guwan.backend.face;/*
|
||
|
package com.guwan.face;
|
||
|
|
||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
|
import com.guwan.config.GlobalValue;
|
||
|
import com.guwan.face.entity.UserCompareInfo;
|
||
|
import com.guwan.face.service.FaceEngineService;
|
||
|
import com.guwan.face.util.Base64Util;
|
||
|
import com.guwan.face.util.UserInfo;
|
||
|
import com.guwan.face.util.UserRamGroup;
|
||
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
||
|
import net.shapelight.modules.ten.entity.TenCellEntity;
|
||
|
import net.shapelight.modules.ten.entity.TenPersonEntity;
|
||
|
import net.shapelight.modules.ten.service.TenCellService;
|
||
|
import net.shapelight.modules.ten.service.TenPersonService;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.boot.ApplicationArguments;
|
||
|
import org.springframework.boot.ApplicationRunner;
|
||
|
import org.springframework.core.annotation.Order;
|
||
|
import org.springframework.stereotype.Component;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
@Component
|
||
|
@Order(1)
|
||
|
@Slf4j
|
||
|
public class FaceEngineAutoRun implements ApplicationRunner {
|
||
|
@Autowired
|
||
|
private FaceEngineService faceEngineService;
|
||
|
@Autowired
|
||
|
private TenPersonService tenPersonService;
|
||
|
@Autowired
|
||
|
private TenCellService tenCellService;
|
||
|
@Autowired
|
||
|
private GlobalValue globalValue;
|
||
|
|
||
|
@Override
|
||
|
public void run(ApplicationArguments args) throws Exception {
|
||
|
// 任务初始化
|
||
|
log.debug("服务启动。。。。。初始化人脸库");
|
||
|
// Map<String, String> fileMap = Maps.newHashMap();
|
||
|
// fileMap.put("zhao1", "赵丽颖");
|
||
|
// fileMap.put("yang1", "杨紫");
|
||
|
// fileMap.put("baixue", "白雪");
|
||
|
// fileMap.put("chenchuang", "陈创");
|
||
|
// for (String f : fileMap.keySet()) {
|
||
|
// ClassPathResource resource = new ClassPathResource("static/images/" + f + ".jpg");
|
||
|
// InputStream inputStream = resource.getInputStream();
|
||
|
// ImageInfo rgbData = ImageFactory.getRGBData(inputStream);
|
||
|
// List<FaceInfo> faceInfoList = faceEngineService.detectFaces(rgbData);
|
||
|
// if (CollectionUtil.isNotEmpty(faceInfoList)) {
|
||
|
// byte[] feature = faceEngineService.extractFaceFeature(rgbData, faceInfoList.get(0), ExtractType.REGISTER);
|
||
|
// UserRamCache.UserInfo userInfo = new UserCompareInfo();
|
||
|
// userInfo.setFaceId(f);
|
||
|
// userInfo.setName(fileMap.get(f));
|
||
|
// userInfo.setFaceFeature(feature);
|
||
|
// //这边注册到内存缓存中,也可以根据业务,注册到数据库中
|
||
|
// UserRamCache.addUser(userInfo);
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// 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);
|
||
|
UserRamGroup.addOrgId(cellEntity.getOrgId(),cellId);
|
||
|
int count = tenPersonService.findCount(cellId);
|
||
|
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, cellId);
|
||
|
for(TenPersonEntity personEntity: listPage){
|
||
|
if(personEntity.getFeature()!=null && personEntity.getFeature().length()>0){
|
||
|
UserInfo userInfo = new UserCompareInfo();
|
||
|
userInfo.setFaceId(personEntity.getPersonId()+"");
|
||
|
userInfo.setName(personEntity.getName());
|
||
|
userInfo.setFaceFeature(Base64Util.base64ToBytes(personEntity.getFeature()));
|
||
|
//这边注册到内存缓存中
|
||
|
UserRamGroup.addUser(userInfo,cellId);
|
||
|
faceCount++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
log.debug(cellEntity.getName()+":初始化人脸库完成,共 "+faceCount+" 人");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
*/
|