|
|
@@ -14,9 +14,8 @@ import com.inspur.common.utils.SecurityUtils;
|
|
|
import com.inspur.common.utils.StringUtils;
|
|
|
import com.inspur.common.utils.file.FileUploadUtils;
|
|
|
import com.inspur.common.utils.file.FileUtils;
|
|
|
-import com.inspur.face.domain.PartyFaceRecognition;
|
|
|
-import com.inspur.face.domain.PartyMemberFace;
|
|
|
-import com.inspur.face.domain.SubjectBean;
|
|
|
+import com.inspur.face.common.FaceConstant;
|
|
|
+import com.inspur.face.domain.*;
|
|
|
import com.inspur.face.mapper.PartyFaceRecognitionMapper;
|
|
|
import com.inspur.face.service.CompreFaceService;
|
|
|
import com.inspur.framework.config.ServerConfig;
|
|
|
@@ -31,10 +30,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static com.inspur.common.utils.PageUtils.startPage;
|
|
|
|
|
|
@@ -57,35 +54,25 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
@Autowired
|
|
|
private ISysUserTableRelService sysUserTableRelService;
|
|
|
|
|
|
- private static final String FACE_RECOGNITION_TABLE_NAME = "party_face_recognition";
|
|
|
|
|
|
private final static String MEMBER_TABLE_NAME = "party_member_manage";
|
|
|
|
|
|
- /**
|
|
|
- * 添加subject URL
|
|
|
- */
|
|
|
- public static final String URL_ADD_SUBJECT = "http://117.73.13.40:8000/api/v1/recognition/subjects";
|
|
|
-
|
|
|
- /**
|
|
|
- * 上传人脸照片 URL
|
|
|
- */
|
|
|
- public static final String URL_UPLOAD_FACE = "http://117.73.13.40:8000/api/v1/recognition/faces?subject=";
|
|
|
-
|
|
|
- /**
|
|
|
- * 人脸识别 URL
|
|
|
- */
|
|
|
- // public static final String URL_FACE_RECOGNITION = "http://117.73.13.40:8000/api/v1/recognition/recognize?face_plugins=landmarks&face_plugins=gender&face_plugins=age&face_plugins=pose";
|
|
|
- public static final String URL_FACE_RECOGNITION = "http://117.73.13.40:8000/api/v1/recognition/recognize";
|
|
|
-
|
|
|
- private final static String API_KEY = "fccde51d-9b32-4468-97b1-cf454b473e55";
|
|
|
-
|
|
|
- private static final String FILE_TEMP_PATH = "/home/inspur/party-admin/temp/";
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public AjaxResult photoSignRecord(Long meetingId) {
|
|
|
+ PartyFaceRecognition queryParam = new PartyFaceRecognition();
|
|
|
+ queryParam.setMeetingId(meetingId);
|
|
|
+ queryParam.setOpType(3);
|
|
|
+ List<PartyFaceRecognition> partyFaceRecognitionList = partyFaceRecognitionMapper.selectPartyFaceRecognitionList(queryParam);
|
|
|
+ if (CollectionUtils.isEmpty(partyFaceRecognitionList)) {
|
|
|
+ return AjaxResult.error("未找到会议签到记录");
|
|
|
+ }
|
|
|
+ return AjaxResult.success(partyFaceRecognitionList.get(0));
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<PartyFaceRecognition> selectPartyFaceRecognitionList(PartyFaceRecognition partyFaceRecognition) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
startPage();
|
|
|
return partyFaceRecognitionMapper.selectPartyFaceRecognitionList(partyFaceRecognition);
|
|
|
}
|
|
|
@@ -99,7 +86,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setOpType(1);
|
|
|
partyFaceRecognition.setOpStatus(0);
|
|
|
partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
// 调用算法服务
|
|
|
String rspCode = "";
|
|
|
@@ -107,9 +94,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
Integer opStatus = 1;
|
|
|
try {
|
|
|
// 发送请求添加subject
|
|
|
- HttpResponse response = HttpRequest.post(URL_ADD_SUBJECT)
|
|
|
+ HttpResponse response = HttpRequest.post(FaceConstant.URL_ADD_SUBJECT)
|
|
|
.body("{\"subject\":\"" + subject.getSubject() + "\"}")
|
|
|
- .header("x-api-key", API_KEY)
|
|
|
+ .header("x-api-key", FaceConstant.API_KEY)
|
|
|
.execute();
|
|
|
// 解析返回结果
|
|
|
rspCode = String.valueOf(response.getStatus());
|
|
|
@@ -132,8 +119,6 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
return AjaxResult.success(partyFaceRecognition);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public AjaxResult uploadFace(String subject, MultipartFile file) {
|
|
|
// 保存数据库
|
|
|
@@ -149,7 +134,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setOpType(2);
|
|
|
partyFaceRecognition.setOpStatus(0);
|
|
|
partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
// 调用算法服务
|
|
|
String rspCode = "";
|
|
|
@@ -158,9 +143,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
try {
|
|
|
File imageFile = new File(filePath);
|
|
|
// 发送请求添加subject
|
|
|
- HttpResponse response = HttpRequest.post(URL_UPLOAD_FACE + subject)
|
|
|
+ HttpResponse response = HttpRequest.post(FaceConstant.URL_UPLOAD_FACE + subject)
|
|
|
.form("file",imageFile)
|
|
|
- .header("x-api-key", API_KEY)
|
|
|
+ .header("x-api-key", FaceConstant.API_KEY)
|
|
|
.execute();
|
|
|
// 解析返回结果
|
|
|
rspCode = String.valueOf(response.getStatus());
|
|
|
@@ -184,7 +169,43 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AjaxResult recognizeFace(MultipartFile file) {
|
|
|
+ public AjaxResult recognizeFace(Long meetingId,MultipartFile file) {
|
|
|
+
|
|
|
+ PartyFaceRecognition recognitionResult = recognizeFace2AI(meetingId,file);
|
|
|
+ if (recognitionResult.getOpStatus() != 1 || StringUtils.isEmpty(recognitionResult.getRspCode())
|
|
|
+ || !String.valueOf(HttpStatus.HTTP_OK).equalsIgnoreCase(recognitionResult.getRspCode())) {
|
|
|
+ return AjaxResult.error("调用AI算法人脸识别失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ RecognizeFaceRsp recognizeFaceRsp = JSONObject.parseObject(recognitionResult.getRspMsg(), RecognizeFaceRsp.class);
|
|
|
+ List<RecognizeFaceRspResult> resultList = recognizeFaceRsp.getResult();
|
|
|
+ if (CollectionUtils.isEmpty(resultList)) {
|
|
|
+ log.info("recognizeFace result is empty,meetingId:{}",meetingId);
|
|
|
+ return AjaxResult.success("recognizeFace success,but result is empty");
|
|
|
+ }
|
|
|
+ // 找出所有的id_人名集合
|
|
|
+ Map<String,BigDecimal> memberMap = new HashMap<>();
|
|
|
+ for (RecognizeFaceRspResult result : resultList) {
|
|
|
+ if (CollectionUtils.isEmpty(result.getSubjects())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ RecognizeFaceRspResultSubject subject = result.getSubjects().get(0);
|
|
|
+ String mapKey = subject.getSubject();
|
|
|
+ BigDecimal mapValue = subject.getSimilarity();
|
|
|
+ if (!memberMap.containsKey(mapKey)) {
|
|
|
+ memberMap.put(mapKey,mapValue);
|
|
|
+ }else {
|
|
|
+ BigDecimal oldValue = memberMap.get(mapKey);
|
|
|
+ if (oldValue.compareTo(mapValue) < 0) {
|
|
|
+ memberMap.put(mapKey,mapValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success(memberMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private PartyFaceRecognition recognizeFace2AI(Long meetingId, MultipartFile file) {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
Map<String,String> fileMap = uploadFile(file);
|
|
|
JSONObject reqParam = new JSONObject();
|
|
|
@@ -195,8 +216,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setReqParam(reqParam.toJSONString());
|
|
|
partyFaceRecognition.setOpType(3);
|
|
|
partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setMeetingId(meetingId);
|
|
|
partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
// 调用算法服务
|
|
|
String rspCode = "";
|
|
|
@@ -205,9 +227,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
try {
|
|
|
File imageFile = new File(filePath);
|
|
|
// 发送请求添加subject
|
|
|
- HttpResponse response = HttpRequest.post(URL_FACE_RECOGNITION)
|
|
|
+ HttpResponse response = HttpRequest.post(FaceConstant.URL_FACE_RECOGNITION)
|
|
|
.form("file",imageFile)
|
|
|
- .header("x-api-key", API_KEY)
|
|
|
+ .header("x-api-key", FaceConstant.API_KEY)
|
|
|
.execute();
|
|
|
// 解析返回结果
|
|
|
rspCode = String.valueOf(response.getStatus());
|
|
|
@@ -227,7 +249,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
}
|
|
|
- return AjaxResult.success(partyFaceRecognition);
|
|
|
+ return partyFaceRecognition;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -291,7 +313,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setOpStatus(0);
|
|
|
partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
partyFaceRecognition.setMemberId(partyMemberFace.getMemberId());
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
}else {
|
|
|
partyFaceRecognition = subjectList.get(0);
|
|
|
@@ -303,9 +325,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
File imageFile = downloadFile(partyMemberFace.getPicPath());
|
|
|
try {
|
|
|
// 发送请求添加subject
|
|
|
- HttpResponse response = HttpRequest.post(URL_UPLOAD_FACE + subject)
|
|
|
+ HttpResponse response = HttpRequest.post(FaceConstant.URL_UPLOAD_FACE + subject)
|
|
|
.form("file",imageFile)
|
|
|
- .header("x-api-key", API_KEY)
|
|
|
+ .header("x-api-key", FaceConstant.API_KEY)
|
|
|
.execute();
|
|
|
// 解析返回结果
|
|
|
rspCode = String.valueOf(response.getStatus());
|
|
|
@@ -342,7 +364,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
partyFaceRecognition.setOpType(1);
|
|
|
partyFaceRecognition.setOpStatus(0);
|
|
|
partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
- partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FaceConstant.FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
partyFaceRecognition.setMemberId(partyMemberFace.getMemberId());
|
|
|
partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
// 调用算法服务
|
|
|
@@ -351,9 +373,9 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
Integer opStatus = 1;
|
|
|
try {
|
|
|
// 发送请求添加subject
|
|
|
- HttpResponse response = HttpRequest.post(URL_ADD_SUBJECT)
|
|
|
+ HttpResponse response = HttpRequest.post(FaceConstant.URL_ADD_SUBJECT)
|
|
|
.body("{\"subject\":\"" + subject + "\"}")
|
|
|
- .header("x-api-key", API_KEY)
|
|
|
+ .header("x-api-key", FaceConstant.API_KEY)
|
|
|
.execute();
|
|
|
// 解析返回结果
|
|
|
rspCode = String.valueOf(response.getStatus());
|
|
|
@@ -413,7 +435,7 @@ public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
}
|
|
|
|
|
|
private static File downloadFile(String imageUrl) {
|
|
|
- String filePath = FILE_TEMP_PATH + UUID.randomUUID().toString() + ".png";
|
|
|
+ String filePath = FaceConstant.FILE_TEMP_PATH + UUID.randomUUID().toString() + ".png";
|
|
|
// 下载文件
|
|
|
HttpUtil.downloadFile(imageUrl, filePath);
|
|
|
log.info("download file success,file path : {}:" ,filePath);
|