Browse Source

feat: 优化ai填值

vian 3 months atrás
parent
commit
c2e18ab785
1 changed files with 8 additions and 3 deletions
  1. 8 3
      web/maintain/price_info_lib/js/priceEmpty.js

+ 8 - 3
web/maintain/price_info_lib/js/priceEmpty.js

@@ -359,15 +359,17 @@ const EMPTY_BOOK = (() => {
       if (!changedCells.length) {
         return;
       }
-      const chunks = _.chunk(changedCells, 20);
+      const chunks = _.chunk(changedCells, 1); // 改成只能一条一条匹配,否则会很慢。经常把ai服务弄挂
       let percent = 0;
       $.bootstrapLoading.progressStart('AI填值', false);
       $("#progress_modal_body").text('正在进行AI填值,请稍后...');
       await setTimeoutSync(500);
+      const matchResCache = {};
 
       // 分块进行ai匹配
       const step = 100 / (chunks.length || 1);
-      for (const chunk of chunks) {
+      for (let i = 0; i < chunks.length; i++) {
+        const chunk = chunks[i];
         const listA = [];
         const listB = [];
         const summaryData = [];
@@ -383,7 +385,9 @@ const EMPTY_BOOK = (() => {
         const test = listB.map(item => item.length);
         console.log(test);
 
-        const matchRes = await ajaxPost('/priceInfoSummary/aiMatch', { listA, listB }, 1000 * 60 * 5);
+        const matchRes = matchResCache[listA[0]] ? matchResCache[listA[0]] : await ajaxPost('/priceInfoSummary/aiMatch', { listA, listB }, 1000 * 60 * 5);
+        matchResCache[listA[0]] = matchRes;
+
         // 填匹配值到表格,不实时保存,因为需要人工核查
         workBookObj.sheet.suspendEvent();
         workBookObj.sheet.suspendPaint();
@@ -424,6 +428,7 @@ const EMPTY_BOOK = (() => {
         workBookObj.sheet.resumeEvent();
         workBookObj.sheet.resumePaint();
         percent += step;
+        $('#progress_modal_body').text(`正在进行AI填值,请稍后${i + 1}/${chunks.length}...`);
         $("#progress_modal_bar").css('width', `${percent}%`);
         await setTimeoutSync(500);
       }