|
@@ -51,9 +51,9 @@
|
|
|
data() {
|
|
|
return {
|
|
|
photoQuantityLimit:10000,//单次上传限制
|
|
|
- photoList:[],//总的照片
|
|
|
- photoLine:[],//正在处理的照片
|
|
|
- concurrency:5,//同时处理的照片数量
|
|
|
+ photoList:[],//总的照片队列
|
|
|
+ photoLine:[],//正在处理的照片队列
|
|
|
+ concurrency:8,//同时处理的照片数量
|
|
|
returnMsgList:[],//返回信息
|
|
|
successNum:0, //成功数量
|
|
|
errorNum:0, //失败数量
|
|
@@ -77,7 +77,7 @@
|
|
|
this.init();
|
|
|
var photos = document.getElementById('photos');
|
|
|
for(var i = 0;i<photos.files.length;i++){
|
|
|
- this.photoList.push(photos.files[i]);
|
|
|
+ this.photoList.push(photos.files[i]);
|
|
|
}
|
|
|
this.allNum = this.photoList.length;
|
|
|
if(this.allNum > this.photoQuantityLimit){
|
|
@@ -91,9 +91,6 @@
|
|
|
this.processStudentPhoto(this.photoLine[i]);
|
|
|
}
|
|
|
var _this = this;
|
|
|
- /*var secondInterval = setInterval(function(){
|
|
|
- _this.seconds = _this.seconds+1;
|
|
|
- },1000);*/
|
|
|
var uploadTime = setInterval(function(){
|
|
|
//检查photoLine中是否有已经完成的
|
|
|
for (let i = 0; i < _this.photoLine.length; i++) {
|
|
@@ -108,99 +105,81 @@
|
|
|
//检查看是否全部完成了
|
|
|
console.log('photoList处理完毕');
|
|
|
clearInterval(uploadTime);
|
|
|
- //clearInterval(secondInterval);
|
|
|
}
|
|
|
- },1000);
|
|
|
+ },500);
|
|
|
},
|
|
|
- isImageFile(file) {
|
|
|
- let lowercaseName = file.toLowerCase();
|
|
|
- if (lowercaseName.endsWith('.jpg') || lowercaseName.endsWith('.jpeg') || lowercaseName.endsWith('.png')) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
processStudentPhoto(photo) {
|
|
|
- let arr = photo.name.split('.');
|
|
|
- let fileName = arr[0];//文件名就是身份证号码
|
|
|
- let fileSuffix = arr[1];//文件后缀
|
|
|
+ let photoNameArr = photo.name.split('.');
|
|
|
+ let fileName = photoNameArr[0];//文件名就是身份证号码
|
|
|
+ let fileSuffix = photoNameArr[1];//文件后缀
|
|
|
let md5Hash = CryptoJS.MD5(Base64.encode(photo.name)).toString();
|
|
|
- let photoMD5 = md5Hash+'.'+fileSuffix;
|
|
|
let rootOrgId = localStorage.getItem('rootOrgId');
|
|
|
//根据身份证号码查询学生信息
|
|
|
- this.$http.get('/api/ecs_core/studentFaceInfo/identityNumber?orgId='+rootOrgId+'&identityNumber='+fileName, {
|
|
|
- }).then((response) => {
|
|
|
- var studentFaceInfoJSON = response.body;
|
|
|
- if (studentFaceInfoJSON.student && studentFaceInfoJSON.student.id) {
|
|
|
- let md5 = studentFaceInfoJSON.photoMD5;
|
|
|
- let studentId = studentFaceInfoJSON.student.id;
|
|
|
- //分析人脸
|
|
|
+ this.$http.get('/api/ecs_core/studentFaceInfo/identityNumber?orgId='+rootOrgId+'&identityNumber='+fileName, {})
|
|
|
+ .then((response) => {
|
|
|
+ var studentFaceInfo = response.body;
|
|
|
+ if (studentFaceInfo.student && studentFaceInfo.student.id) {
|
|
|
this.detectFace(photo).then((res)=>{
|
|
|
- if(res.body.faces.length<1){
|
|
|
- this.finishOneBack(false,fileName,'没有检测到人脸',photo);
|
|
|
- }else{
|
|
|
+ if(res.body.faces.length>=1){
|
|
|
let face_token = res.body.faces[0].face_token;
|
|
|
this.getFaceSetToken().then((res)=>{
|
|
|
- //var face_set_token = res.bodyText;
|
|
|
- var face_set_token = 'ee564a7abbde7f1287f668ddd945ccfa';
|
|
|
- let photoMD5 = md5Hash+'.'+fileSuffix;
|
|
|
- var savePhotoInfo = {
|
|
|
- 'studentFaceInfoId':studentFaceInfoJSON.id,
|
|
|
+ //var face_set_token = res.bodyText;
|
|
|
+ var face_set_token = 'ee564a7abbde7f1287f668ddd945ccfa';
|
|
|
+ this.addFaceToSet(face_set_token, face_token).then((res)=>{
|
|
|
+ this.saveStudentFaceInfo({
|
|
|
+ 'studentFaceInfoId':studentFaceInfo.id,
|
|
|
+ 'studentId':studentFaceInfo.student.id,
|
|
|
'face_set_token':face_set_token,
|
|
|
'face_token':face_token,
|
|
|
- 'studentId':studentId,
|
|
|
- 'userName':localStorage.getItem('userName'),
|
|
|
'fileName':fileName,
|
|
|
'file':photo,
|
|
|
- 'identityNumber':fileName,
|
|
|
'fileSuffix':fileSuffix,
|
|
|
- 'photoMD5':photoMD5
|
|
|
- };
|
|
|
- this.addFaceToSet(face_set_token, face_token).then((res)=>{
|
|
|
- this.saveImageToUpyun(savePhotoInfo);
|
|
|
- },(err)=>{
|
|
|
- this.finishOneBack(false,fileName,'addFaceToSet失败',photo);
|
|
|
+ 'photoNewName':md5Hash+'.'+fileSuffix
|
|
|
});
|
|
|
- },(error)=>{
|
|
|
- this.finishOneBack(false,fileName,'getFaceSetToken失败',photo);
|
|
|
- }
|
|
|
- );
|
|
|
+ },(err)=>{
|
|
|
+ this.finishOne(false,fileName,'addFaceToSet失败',photo);
|
|
|
+ });
|
|
|
+ },(err)=>{
|
|
|
+ this.finishOne(false,fileName,'获取FaceSetToken失败',photo);
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ this.finishOne(false,fileName,'face++没有检测到人脸',photo);
|
|
|
}
|
|
|
},(err)=>{
|
|
|
- this.finishOneBack(false,fileName,'调用face++检测人脸失败',photo);
|
|
|
+ this.finishOne(false,fileName,'调用face++检测人脸失败',photo);
|
|
|
});
|
|
|
}else{
|
|
|
- this.finishOneBack(false,fileName,'查询身份证不存在',photo);
|
|
|
+ this.finishOne(false,fileName,'查询身份证不存在',photo);
|
|
|
}
|
|
|
},(error)=>{
|
|
|
- this.finishOneBack(false,fileName,'根据身份证号码查询失败',photo);
|
|
|
+ this.finishOne(false,fileName,'根据身份证号码查询失败',photo);
|
|
|
});
|
|
|
},
|
|
|
- saveImageToUpyun(savePhotoInfo){
|
|
|
- this._saveImageToUpyun(savePhotoInfo).then((res)=>{
|
|
|
+ //保存照片信息
|
|
|
+ saveStudentFaceInfo(photoInfo){
|
|
|
+ this.saveImageToUpyun(photoInfo).then((res)=>{
|
|
|
//调用core后台接口,对数据进行保存
|
|
|
- let photoMD5 = savePhotoInfo.md5Hash+'.'+savePhotoInfo.fileSuffix;
|
|
|
- if(!savePhotoInfo.studentFaceInfoId){
|
|
|
- this.saveStudentFaceInfoByPost(savePhotoInfo);
|
|
|
+ if(!photoInfo.studentFaceInfoId){
|
|
|
+ this.saveStudentFaceInfoByPost(photoInfo);
|
|
|
}else{
|
|
|
- this.saveStudentFaceInfoByPut(savePhotoInfo);
|
|
|
+ this.saveStudentFaceInfoByPut(photoInfo);
|
|
|
}
|
|
|
},(err)=>{
|
|
|
- this.finishOneBack(false,savePhotoInfo.fileName,'saveImageToUpyun失败',savePhotoInfo.file);
|
|
|
+ this.finishOne(false,photoInfo.fileName,'saveImageToUpyun失败',photoInfo.file);
|
|
|
});
|
|
|
},
|
|
|
- _saveImageToUpyun(savePhotoInfo){
|
|
|
- var url = process.env.VUE_APP_UPYUN_BUCKETURL+'/student_base_photo/'
|
|
|
- +savePhotoInfo.identityNumber+'/'
|
|
|
- +savePhotoInfo.photoMD5;
|
|
|
+ //保存文件至又拍云
|
|
|
+ saveImageToUpyun(photoInfo){
|
|
|
+ var url = process.env.VUE_APP_UPYUN_BUCKETURL+'/student_base_photo/'+photoInfo.fileName+'/'+photoInfo.photoNewName;
|
|
|
var authorization = 'Basic '+Base64.encode(process.env.VUE_APP_UPYUN_OPERATOR+':'+process.env.VUE_APP_UPYUN_PASSWORD);
|
|
|
var headers = {headers:{'Authorization':authorization,'Content-Type': 'image/jpeg'}};
|
|
|
- return this.$http.put(url,savePhotoInfo.file,headers);
|
|
|
+ return this.$http.put(url,photoInfo.file,headers);
|
|
|
},
|
|
|
+ //获取faceSetToken
|
|
|
getFaceSetToken(){
|
|
|
return this.$http.get('/api/ecs_core/faceSet/enableFaceSet');
|
|
|
},
|
|
|
+ //faceToken加入faceSetToken
|
|
|
addFaceToSet(faceset_token,face_token){
|
|
|
let formData_addface = new FormData();
|
|
|
formData_addface.append('api_key', process.env.VUE_APP_FACEPP_API_KEY);
|
|
@@ -209,6 +188,7 @@
|
|
|
formData_addface.append('face_tokens', face_token);
|
|
|
return this.$http.post('/facepp/v3/faceset/addface', formData_addface);
|
|
|
},
|
|
|
+ //face++分析人脸
|
|
|
detectFace(file){
|
|
|
let fileBlob = new Blob([file]);
|
|
|
let formData_face_token = new FormData();
|
|
@@ -217,41 +197,42 @@
|
|
|
formData_face_token.append('image_file', fileBlob);
|
|
|
return this.$http.post('/facepp/v3/detect', formData_face_token);
|
|
|
},
|
|
|
- saveStudentFaceInfoByPost(savePhotoInfo){
|
|
|
+ saveStudentFaceInfoByPost(photoInfo){
|
|
|
this.$http.post('/api/ecs_core/studentFaceInfo', {
|
|
|
- 'faceSetToken': savePhotoInfo.face_set_token,
|
|
|
- 'faceToken': savePhotoInfo.face_token,
|
|
|
- 'photoMD5': savePhotoInfo.photoMD5,
|
|
|
+ 'faceSetToken': photoInfo.face_set_token,
|
|
|
+ 'faceToken': photoInfo.face_token,
|
|
|
+ 'photoMD5': photoInfo.photoNewName,
|
|
|
'student': {
|
|
|
- 'id': savePhotoInfo.studentId
|
|
|
+ 'id': photoInfo.studentId
|
|
|
},
|
|
|
- 'createUser':savePhotoInfo.userName,
|
|
|
- 'updateUser':savePhotoInfo.userName,
|
|
|
+ 'createUser':localStorage.getItem('userName'),
|
|
|
+ 'updateUser':localStorage.getItem('userName'),
|
|
|
'createType':'IMPORT_TOOL'
|
|
|
}).then((res)=>{
|
|
|
- this.finishOneBack(true,savePhotoInfo.fileName,'处理成功',savePhotoInfo.file);
|
|
|
+ this.finishOne(true,photoInfo.fileName,'处理成功',photoInfo.file);
|
|
|
},(err)=>{
|
|
|
- this.finishOneBack(false,savePhotoInfo.fileName,'saveStudentFaceInfoByPost失败',savePhotoInfo.file);
|
|
|
+ this.finishOne(false,photoInfo.fileName,'saveStudentFaceInfoByPost失败',photoInfo.file);
|
|
|
});
|
|
|
},
|
|
|
- saveStudentFaceInfoByPut(savePhotoInfo){
|
|
|
+ saveStudentFaceInfoByPut(photoInfo){
|
|
|
this.$http.put('/api/ecs_core/studentFaceInfo', {
|
|
|
- 'faceSetToken': savePhotoInfo.face_set_token,
|
|
|
- 'faceToken': savePhotoInfo.face_token,
|
|
|
- 'photoMD5': savePhotoInfo.photoMD5,
|
|
|
+ 'faceSetToken': photoInfo.face_set_token,
|
|
|
+ 'faceToken': photoInfo.face_token,
|
|
|
+ 'photoMD5': photoInfo.photoNewName,
|
|
|
'student': {
|
|
|
- 'id': savePhotoInfo.studentId
|
|
|
+ 'id': photoInfo.studentId
|
|
|
},
|
|
|
- 'createUser':savePhotoInfo.userName,
|
|
|
- 'updateUser':savePhotoInfo.userName,
|
|
|
+ 'createUser':localStorage.getItem('userName'),
|
|
|
+ 'updateUser':localStorage.getItem('userName'),
|
|
|
'createType':'IMPORT_TOOL'
|
|
|
}).then((res)=>{
|
|
|
- this.finishOneBack(true,savePhotoInfo.fileName,'处理成功',savePhotoInfo.file);
|
|
|
+ this.finishOne(true,photoInfo.fileName,'处理成功',photoInfo.file);
|
|
|
},(err)=>{
|
|
|
- this.finishOneBack(false,savePhotoInfo.fileName,'saveStudentFaceInfoByPut失败',savePhotoInfo.file);
|
|
|
+ this.finishOne(false,photoInfo.fileName,'saveStudentFaceInfoByPut失败',photoInfo.file);
|
|
|
});
|
|
|
},
|
|
|
- finishOneBack(isSuccess,fileName,msg,file){
|
|
|
+ //成功或失败处理
|
|
|
+ finishOne(isSuccess,fileName,msg,file){
|
|
|
file.finished = true;
|
|
|
this.returnMsgList.push({'success':isSuccess,'fileName':fileName,'msg':msg});
|
|
|
if(isSuccess){
|