chengjie 2 月之前
父節點
當前提交
30db353adf
共有 1 個文件被更改,包括 91 次插入8 次删除
  1. 91 8
      src/api/miaoguo/literacyController.js

+ 91 - 8
src/api/miaoguo/literacyController.js

@@ -121,8 +121,6 @@ export async function GetMiaoguoAISearch(ctx) {
121 121
                     }
122 122
                 }
123 123
             }
124
-            //console.log("4:"+moment().format("mm:ss"));
125
-            result={"errcode": 10000, result: result}
126 124
         }
127 125
         else{
128 126
             console.log("New Word");
@@ -195,14 +193,22 @@ export async function GetMiaoguoAISearch(ctx) {
195 193
                 obj.JSONString=JSON.stringify(result);
196 194
                 let sql3="INSERT INTO `MiaoguoLiteracy` SET ?;";
197 195
                 await commonModel.RunSql(obj,sql3);
198
-                result={"errcode": 10000, result: result};
196
+
199 197
             }
200 198
             //如果是英文单词
201 199
             else if ((stringUtils.IsEnglish(param.Word)) || param.SearchType=="eng"){
202 200
                 
203
-                let result2=await getAiDataEng(param.Word);
201
+                result=await getAiDataEng(param.Word);
202
+
203
+                let obj={};
204
+                obj.Word=param.Word;
205
+                obj.SearchType='eng';
206
+                obj.Author="";
207
+                obj.ShiciUrl="";
208
+                obj.JSONString=JSON.stringify(result);
209
+                let sql3="INSERT INTO `MiaoguoLiteracy` SET ?;";
210
+                await commonModel.RunSql(obj,sql3);
204 211
 
205
-                result={"errcode": 10000, result: result2};
206 212
             }
207 213
             //整句中是否有中文
208 214
             else if ((stringUtils.IsChineseSentence(param.Word)) && param.SearchType!="eng") {
@@ -255,14 +261,91 @@ export async function GetMiaoguoAISearch(ctx) {
255 261
                     obj.JSONString=json;
256 262
                     let sql3="INSERT INTO `MiaoguoLiteracy` SET ?;";
257 263
                     await commonModel.RunSql(obj,sql3);
264
+                    
265
+                }
266
+            }
267
+        }
268
+
269
+        //判断是否有公式
270
+        if (stringUtils.IsChineseSentence(param.Word) && param.Word.length>=2 && param.SearchType!="zici") {
258 271
 
259
-                    globalCache.set(cacheKey, result, config.BufferMemoryTimeHigh);
260
-                    console.log("缓存");
261
-                    result={"errcode": 10000, result: result};
272
+            if (param.SearchType=="latex"){
273
+                let sql="SELECT * FROM kylx365_db.LatexTable where Name = '"+param.Word+"';";
274
+                let latexList = await commonModel.RunSql(null,sql);
275
+                if (latexList && latexList.length>0){
276
+                    let obj={};
277
+                    obj.LATEX={};
278
+                    obj.LATEX.LatexName=latexList[0].Name;
279
+                    obj.LATEX.LatexContent=latexList[0].LaTeX;
280
+                    obj.LATEX.Subject=latexList[0].Subject;
281
+                    obj.LATEX.Grade=latexList[0].Grade;
282
+                    obj.LATEX.Category=latexList[0].Category;
283
+                    obj.LATEX.FontSize=latexList[0].FontSize;
284
+                    result=obj;
285
+                }
286
+            }
287
+            else {
288
+                let sql="SELECT * FROM kylx365_db.LatexTable where Subject='"+param.Word+"' or Name like '%"+param.Word+"%' order by Subject,Grade,Category,Name,id desc;";
289
+                let latexList = await commonModel.RunSql(null,sql);
290
+
291
+                if (result.List && latexList && latexList.length > 0) {
292
+                    let b=false;
293
+                    for (let i = 0; i < result.List.length; i++) {
294
+                        if (result.List[i].Type=="latex") {
295
+                            b = true;
296
+                        }
297
+                    }
298
+                    if (!b) {
299
+                        for (let i = 0; i < latexList.length; i++) {
300
+                            let obj = {};
301
+                            obj.Type = "latex";
302
+                            obj.Key = latexList[i].Name;
303
+                            obj.Remark = latexList[i].Grade + " "  + latexList[i].Category;
304
+                            obj.Content = latexList[i].Subject;
305
+                            obj.TypeName = "公式";
306
+                            result.List.push(obj);
307
+                        }
308
+                    }
309
+                }
310
+                else if (!result.List && result.CHN && latexList && latexList.length > 0){
311
+                    let list=[];
312
+                    if (result.CHN){
313
+                        let obj = {};
314
+                        obj.Type = "zici";
315
+                        obj.Key = result.CHN.HanZi;
316
+                        obj.Remark = "";
317
+                        obj.TypeName = "字词";
318
+                        list.push(obj);
319
+                    }
320
+                    if (result.ENG){
321
+                        let obj = {};
322
+                        obj.Type = "eng";
323
+                        obj.Key = result.ENG.Word;
324
+                        obj.Remark = "";
325
+                        obj.TypeName = "翻译";
326
+                        list.push(obj);
327
+                    }
328
+                    for (let i = 0; i < latexList.length; i++) {
329
+                        let obj = {};
330
+                        obj.Type = "latex";
331
+                        obj.Key = latexList[i].Name;
332
+                        obj.Remark = latexList[i].Grade + " "  + latexList[i].Category;
333
+                        obj.Content = latexList[i].Subject;
334
+                        obj.TypeName = "公式";
335
+                        list.push(obj);
336
+                    }
337
+                    result={};
338
+                    result.HanZi=param.Word;
339
+                    result.List=list;
262 340
                 }
263 341
             }
264 342
         }
343
+
344
+        globalCache.set(cacheKey, result, config.BufferMemoryTimeHigh);
345
+        console.log("缓存");
265 346
     }
347
+
348
+    result={"errcode": 10000, result: result};
266 349
     ctx.body = result;
267 350
 }
268 351