|
@@ -21,6 +21,10 @@
|
|
失败:
|
|
失败:
|
|
<span style="color:red;">{{errorNum}}</span>/{{allNum}}
|
|
<span style="color:red;">{{errorNum}}</span>/{{allNum}}
|
|
</span>
|
|
</span>
|
|
|
|
+ <span>
|
|
|
|
+ 并发请求:
|
|
|
|
+ <span style="color:black;">{{reqNum}}</span>
|
|
|
|
+ </span>
|
|
<span v-show="completeShow" style="color: green;font-weight: bold;">全部处理完成</span>
|
|
<span v-show="completeShow" style="color: green;font-weight: bold;">全部处理完成</span>
|
|
<span v-show="!completeShow&&(successNum>0||errorNum>0)" style="color: red;font-weight: bold;">处理中...</span>
|
|
<span v-show="!completeShow&&(successNum>0||errorNum>0)" style="color: red;font-weight: bold;">处理中...</span>
|
|
</div>
|
|
</div>
|
|
@@ -68,10 +72,13 @@ function isImageFile(fileName) {
|
|
//读取文件,返回网站路径. 只扫描当前文件夹,不递归扫描
|
|
//读取文件,返回网站路径. 只扫描当前文件夹,不递归扫描
|
|
function readImageFiles(folderPath) {
|
|
function readImageFiles(folderPath) {
|
|
const files = fs.readdirSync(folderPath);
|
|
const files = fs.readdirSync(folderPath);
|
|
- return files.filter(isImageFile).map(fileName => folderPath + "/" + fileName);
|
|
|
|
|
|
+ return files
|
|
|
|
+ .filter(isImageFile)
|
|
|
|
+ .sort()
|
|
|
|
+ .map(fileName => folderPath + "/" + fileName);
|
|
}
|
|
}
|
|
|
|
|
|
-const CONCURRENCY = 2; //同时处理的照片数量; 深夜增加并发
|
|
|
|
|
|
+let CONCURRENCY = 2; //同时处理的照片数量; 深夜增加并发
|
|
|
|
|
|
export default {
|
|
export default {
|
|
data() {
|
|
data() {
|
|
@@ -81,7 +88,8 @@ export default {
|
|
successNum: 0, //成功数量
|
|
successNum: 0, //成功数量
|
|
errorNum: 0, //失败数量
|
|
errorNum: 0, //失败数量
|
|
allNum: 0, //总数
|
|
allNum: 0, //总数
|
|
- completeShow: false
|
|
|
|
|
|
+ completeShow: false,
|
|
|
|
+ reqNum: 0
|
|
};
|
|
};
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -104,29 +112,41 @@ export default {
|
|
},
|
|
},
|
|
folderPaths => {
|
|
folderPaths => {
|
|
if (folderPaths) {
|
|
if (folderPaths) {
|
|
- this.processQueue(folderPaths[0]);
|
|
|
|
|
|
+ this.photoList = readImageFiles(folderPaths[0]);
|
|
|
|
+ this.allNum = this.photoList.length;
|
|
|
|
+ this.processQueue();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
);
|
|
},
|
|
},
|
|
- processQueue(folderPath) {
|
|
|
|
- this.photoList = readImageFiles(folderPath);
|
|
|
|
- this.allNum = this.photoList.length;
|
|
|
|
-
|
|
|
|
|
|
+ processQueue() {
|
|
let taskQueue = [];
|
|
let taskQueue = [];
|
|
- for (const studentPhotoPath of this.photoList) {
|
|
|
|
- taskQueue.push(this.processStudentPhoto.bind(this, studentPhotoPath));
|
|
|
|
|
|
+ let total = 0;
|
|
|
|
+ for (
|
|
|
|
+ let i = this.successNum + this.errorNum;
|
|
|
|
+ i < this.photoList.length && total < 100;
|
|
|
|
+ i++, total++
|
|
|
|
+ ) {
|
|
|
|
+ taskQueue.push(this.processStudentPhoto.bind(this, this.photoList[i]));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ this.processQueueSingle(taskQueue);
|
|
|
|
+ },
|
|
|
|
+ processQueueSingle(taskQueue100) {
|
|
// 并发处理请求,可在控制台查看请求峰值
|
|
// 并发处理请求,可在控制台查看请求峰值
|
|
- async.parallelLimit(taskQueue, CONCURRENCY, (err, results) => {
|
|
|
|
|
|
+ CONCURRENCY = new Date().getHours() < 6 ? 8 : 5;
|
|
|
|
+ async.parallelLimit(taskQueue100, CONCURRENCY, (err, results) => {
|
|
if (err) {
|
|
if (err) {
|
|
alert(err);
|
|
alert(err);
|
|
console.log(err);
|
|
console.log(err);
|
|
} else {
|
|
} else {
|
|
console.log(results);
|
|
console.log(results);
|
|
- console.log("photoList处理完毕");
|
|
|
|
- this.completeShow = true;
|
|
|
|
|
|
+ if (this.successNum + this.errorNum < this.allNum) {
|
|
|
|
+ console.log("处理完100张图片了,3秒后继续...");
|
|
|
|
+ setTimeout(this.processQueue, 3000);
|
|
|
|
+ } else {
|
|
|
|
+ console.log("photoList处理完毕");
|
|
|
|
+ this.completeShow = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -138,6 +158,7 @@ export default {
|
|
.replace(fileSuffix, ""); //文件名就是身份证号码
|
|
.replace(fileSuffix, ""); //文件名就是身份证号码
|
|
const photoFile = fs.readFileSync(studentPhotoPath);
|
|
const photoFile = fs.readFileSync(studentPhotoPath);
|
|
const rootOrgId = localStorage.getItem("rootOrgId");
|
|
const rootOrgId = localStorage.getItem("rootOrgId");
|
|
|
|
+ this.reqNum = window.requestInProcessingTotal;
|
|
|
|
|
|
//生成新名称
|
|
//生成新名称
|
|
const upyunPhotoPath = (() => {
|
|
const upyunPhotoPath = (() => {
|
|
@@ -236,12 +257,12 @@ export default {
|
|
this.$http
|
|
this.$http
|
|
.post("/facepp/v3/faceset/addface", formData_addface)
|
|
.post("/facepp/v3/faceset/addface", formData_addface)
|
|
.then(res => {
|
|
.then(res => {
|
|
- console.log(
|
|
|
|
- `res.data.face_added: ${
|
|
|
|
- res.data.face_added
|
|
|
|
- }, res.data.face_count: ${res.data.face_count}`
|
|
|
|
- );
|
|
|
|
- if (res.data.face_count > 8000) {
|
|
|
|
|
|
+ // console.log(
|
|
|
|
+ // `res.data.face_added: ${
|
|
|
|
+ // res.data.face_added
|
|
|
|
+ // }, res.data.face_count: ${res.data.face_count}`
|
|
|
|
+ // );
|
|
|
|
+ if (res.data.face_count > 4000) {
|
|
window.DB.updateFaceSet(faceset_token, res.data.face_count).then(
|
|
window.DB.updateFaceSet(faceset_token, res.data.face_count).then(
|
|
() => {
|
|
() => {
|
|
this.faceSetToken = undefined;
|
|
this.faceSetToken = undefined;
|