From 85524bbddf545f14427edbef0ededc310d84434a Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 23 十二月 2024 16:02:37 +0800
Subject: [PATCH] 加如日志

---
 app.js |  129 +++++++++++--------------------------------
 1 files changed, 33 insertions(+), 96 deletions(-)

diff --git a/app.js b/app.js
index c4ed47f..d97bce9 100644
--- a/app.js
+++ b/app.js
@@ -2,22 +2,15 @@
 const bodyParser = require('body-parser');
 const mysql = require('mysql2');
 const fs = require('fs').promises;
-const fs2=require('fs')
 const path = require('path');
-const logger = require('./logger'); // 根据实际情况调整路径
-const axios = require('axios');
+const logger = require(path.resolve(__dirname, 'logger'));
 // 转成能识别的url
 const ViapiUtil = require('@alicloud/viapi-utils');
 
 const facebody20191230 = require('@alicloud/facebody20191230');
 const OpenApi = require('@alicloud/openapi-client');
 const Util = require('@alicloud/tea-util');
-const thirdPartyApi = require('./thirdPartyApi');
-
-/**token缓存 */
-let cachedToken = null;
-/**token缓存时间 */
-let tokenExpiresAt = null;
+const thirdPartyApi = require(path.resolve(__dirname, 'thirdPartyApi'));
 
 const app = express();
 const port = 3000;
@@ -54,32 +47,18 @@
     return new facebody20191230.default(config);
 }
 app.get('/', (req, res) => {
-    const title = '岱特智能'; // 动态设置标题
-    const html = `
-      <!DOCTYPE html>
-      <html lang="zh-CN">
-      <head>
-          <meta charset="UTF-8">
-          <meta name="viewport" content="width=device-width, initial-scale=1.0">
-          <title>${title}</title>
-      </head>
-      <body>
-      <iframe
-        src="https://udify.app/chatbot/irsmISE8DBCWAhxz"
-        style="width: 100%; height: 100%; min-height: 700px"
-        frameborder="0"
-        allow="microphone">
-      </iframe>
-      </body>
-      </html>
-    `;
-    res.send(html);
+    
+    res.json({mas:'hahahahh'});
   });
-  app.get('/test', async (req, res) => {
-    const token=await thirdPartyApi.getAccessToken()
-    logger.info('返回token=='+JSON.stringify(token))
-    res.json(token);
-  });
+app.get('/test', async (req, res) => {
+try {
+const token=await thirdPartyApi.getAccessToken()
+logger.info('返回token=='+JSON.stringify(token))
+res.json(token);
+}catch(err){
+    logger.info('catch=='+JSON.stringify(err))
+}
+});
 // 定义 /webuser 路由处理器  用患者code 换信息
 app.post('/webuser', async (req, res) => {
     const mode=req.body
@@ -88,8 +67,7 @@
     const deviceID = req.body.deviceID;
     const type = req.body.type;
     const xid = req.body.xid;
-    console.log()
-    logger.info(`req body action=${action},deviceID=${deviceID},type=${type},xid=${xid}`)
+    logger.info(`成分分析仪用户请求req body action=${action},deviceID=${deviceID},type=${type},xid=${xid}`)
     if (action === 'doWebUser' && deviceID && type !== undefined) {
         try {
             const pathParams={code:xid}
@@ -131,47 +109,6 @@
         res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
     }
 });
-app.post('/webuserPatientId',async(req,res)=>{
-    const mode=req.body
-    logHttps(mode)
-    const patientId = req.query.patientId;
-    if (patientId) {
-        try {
-            const pathParams={code:xid}
-            const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null,  pathParams,{});
-            console.log('--------------获取到了患者信息')
-            // console.log(data)
-            if(data?.code===200&&data?.message==='SUCCESS'&&data?.data){
-                const user = data.data;
-                response = {
-                    recode: 2001,
-                    userinfo: {
-                        name: user.patientName,
-                        sex: user.patientGenderText,
-                        age: user.age,
-                        usernum: user.code, //这个是数据返回会携带回来UID
-                        address: user.patientAddress,
-                        remark: '患者人脸识别111'
-                    },
-                    remsg: "success"
-                };
-                console.log('返回患者信息成功')
-            }else{
-                response = {
-                    retcode: 1001,
-                    remsg: "没有找到患者,请先检查患者code"
-                };
-            }
-        } catch (err) {
-            console.error(err);
-            res.status(500).json({ retCode: "-1", msg: "Database error" });
-        }
-    } else {
-        // 如果请求参数不符合预期,则返回错误信息
-        res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
-    }
-})
-
 // 定义人脸识别  用base64图片文件换患者信息
 app.post('/faceuser', async (req, res) => {
     try{
@@ -181,11 +118,11 @@
         const content = req.body.content;
         const mode=req.body
         mode.content=''
-        logHttps(mode)
+        logger.info(`人脸识别请求deviceID=${deviceID},action=${action}`)
         if (action == 'doFace' && deviceID && content) {
             // 转成oss路径
             const ossurl = await base64toFile(content, deviceID)
-            console.log('得到oss图片路径', ossurl)
+            logger.info(`得到oss图片路径=${ossurl}`)
             let searchFaceRequest = new facebody20191230.SearchFaceRequest({
                 dbName: 'Face_systemtest',
                 imageUrl: ossurl,
@@ -201,7 +138,7 @@
                 if (matchList?.length > 0) {
                     const faceItems = matchList[0].faceItems
                     if (faceItems?.length === 0) {
-                        console.log('没有找到患者对应的人脸')
+                        logger.info(`没有找到患者对应的人脸`)
                         response = {
                             retCode: "0",
                             msg: "没有找到患者,请先检查患者code"
@@ -211,8 +148,7 @@
                         console.log(entityId, '患者id找到了')
                         const pathParams={code:entityId}
                         const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null,  pathParams,{});
-                        console.log('--------------获取到了患者信息')
-                        // console.log(data)
+                        logger.info(`患者接口请求成功`)
                         if(data?.code===200&&data?.message==='SUCCESS'&&data?.data){
                             const user = data.data;
                             response = {
@@ -227,7 +163,7 @@
                                 },
                                 remsg: "success"
                             };
-                            console.log('返回患者信息成功')
+                            logger.info(`返回患者信息成功=${user.patientName}`)
                         }else{
                             response = {
                                 retcode: 1001,
@@ -272,7 +208,7 @@
     const deviceID = req.body.deviceID;
     const mode=req.body
     mode.action='webResults'
-    logHttps(mode)
+    logger.info(`人体成分分析仪结果返回请求deviceID=${deviceID},action=${JSON.stringify(mode)}`)
     try {
       
         const datas=mode.datas
@@ -301,7 +237,7 @@
             }
             console.log(data)
             const resdata = await thirdPartyApi.fetchThirdPartyData('/patient/rtcf/result/save', 'POST', {}, data,{},{});
-            console.log('-----返回人体成分分析保存')
+            logger.info(`结果插入成功`)
             console.log(resdata)
         });
         response = {
@@ -311,6 +247,7 @@
         res.json(response)
        
     }catch(err){
+        logger.errer(`结果插入失败`)
         res.status(4000).json({ reCode: "4000", msg: "Invalid request parameters" });
     }
     
@@ -325,7 +262,7 @@
   const clientCode = req.query.clientCode;
   const mode={"action":'getpatientInfo',"patientId":patientId,}
   console.log(patientId,'-----------------',clientCode)
-  logHttps(mode)
+  logger.info(`血流量设备请求患者信息,请求参数=${patientId},clintCode=${clientCode}`)
   if(patientId&&clientCode){
     // 输出传入的patientid值
     try {
@@ -359,21 +296,21 @@
                     diagnosisDoctor:''
                 })
             })
+            logger.info(`血流量设备请求患者信息,请求成功返回患者信息=${JSON.stringify(users)}`)
             res.json(users);
         } else {
-            const response = {
-                retCode: "0",
-                msg: "没有找到患者,请先检查患者code"
-            };
+            logger.info(`血流量设备请求患者信息,请求成功返回患者信息=[]`)
             res.json([]);
         }
     } catch (err) {
         console.error(err);
+        logger.errer(`血流量设备请求患者信息,请求失败=${err}`)
         res.status(500).json({ retCode: "-1", msg: "接口出错!"+err });
     }
 
   }else{
     // 如果请求参数不符合预期,则返回错误信息
+    
     res.status(400).json({ retCode: "-1", msg: "请求参数出错" });
   }
 
@@ -391,11 +328,7 @@
         }
         const body=req.body
         console.log(body)
-        const mode={
-            action:'PostCheckExam',
-            params:body.examId
-        }
-        logHttps(mode)
+        logger.info(`血流量设备上报结果,请求信息clientCode=${clientCode}`)
         // 组合上传数据
         const data={
             id:0,
@@ -465,13 +398,16 @@
         const resdata = await thirdPartyApi.fetchThirdPartyDataNoToke('/patient/result/from/doppler/blood/flow/device/saveData', 'POST', {}, data,{},{});
         console.log(resdata)
         if(resdata.code===200&&resdata?.data=='OK'){
+            logger.info(`血流量设备上报结果,请求成功`)
             res.json({"Msg": "检查结果上传成功", "Status": "SUCCESS" });
+
         }else{
+            logger.info(`血流量设备上报结果,请求失败`)
             res.json({"Msg": "检查结果上传失败", "Status": "err" });
         } 
     }
     catch(err){
-        console.log(err)
+        logger.info(`血流量设备上报结果,请求报错`)
         res.status(400).json({ retCode: "-1", msg: "请求出错了" });
     }
   
@@ -481,6 +417,7 @@
 
 // 启动服务器
 app.listen(port, async () => {
+    logger.info(`Server running at http://localhost:${port}/`)
     console.log(`Server running at http://localhost:${port}/`);
 });
 /**

--
Gitblit v1.8.0