From 7bc2f53e87f4ee8abd74b1e1171fab4192237de6 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期二, 22 十月 2024 12:17:37 +0800
Subject: [PATCH] 34

---
 /dev/null             |    0 
 app.js                |  155 ++++++++++++++++++++++++++-------------------------
 img/G190166668888.png |    0 
 3 files changed, 79 insertions(+), 76 deletions(-)

diff --git a/app.js b/app.js
index de0e73b..bc1dd9d 100644
--- a/app.js
+++ b/app.js
@@ -99,88 +99,93 @@
 
 // 定义人脸识别  用base64图片文件换患者信息
 app.post('/faceuser', async (req, res) => {
-    const action = req.body.action;
-    const deviceID = req.body.deviceID;
-    // base64图像内容,base64 编码(长宽像素值范围:80*80~200*200,注意:图片的base64 编码是不包含图片头的,如 data:image/jpg;base64,)
-    const content = req.body.content;
-    const mode=req.body
-    logHttps(mode)
-    if (action == 'doFace' && deviceID && content) {
-        // 转成oss路径
-        const ossurl = await base64toFile(content, deviceID)
-        console.log('得到oss图片路径', ossurl)
-        let searchFaceRequest = new facebody20191230.SearchFaceRequest({
-            dbName: 'Face_systemtest',
-            imageUrl: ossurl,
-            limit: 1,
-        });
+    try{
+        const action = req.body.action;
+        const deviceID = req.body.deviceID;
+        // base64图像内容,base64 编码(长宽像素值范围:80*80~200*200,注意:图片的base64 编码是不包含图片头的,如 data:image/jpg;base64,)
+        const content = req.body.content;
+        const mode=req.body
+        mode.content=''
+        logHttps(mode)
+        if (action == 'doFace' && deviceID && content) {
+            // 转成oss路径
+            const ossurl = await base64toFile(content, deviceID)
+            console.log('得到oss图片路径', ossurl)
+            let searchFaceRequest = new facebody20191230.SearchFaceRequest({
+                dbName: 'Face_systemtest',
+                imageUrl: ossurl,
+                limit: 1,
+            });
 
-        let runtime = new Util.RuntimeOptions({});
-        try {
-            // 复制代码运行请自行打印 API 的返回值
-            const data = await createClient().searchFaceWithOptions(searchFaceRequest, runtime);
-            const matchList = data.body.data?.matchList
-            let response = null
-            if (matchList?.length > 0) {
-                const faceItems = matchList[0].faceItems
-                if (faceItems?.length === 0) {
-                    console.log('没有找到患者对应的人脸')
-                    response = {
-                        retCode: "0",
-                        msg: "没有找到患者,请先检查患者code"
-                    };
-                } else if (faceItems[0].score >= 0.2) {
-                    const entityId = faceItems[0].entityId
-                    console.log(entityId, '患者id找到了')
-                    let query = `SELECT * FROM patient_info WHERE code = '${entityId}'`
-                    const [rows] = await pool.promise().query(query);
-                    if (rows.length > 0) {
-                        const user = rows[0];
+            let runtime = new Util.RuntimeOptions({});
+            try {
+                // 复制代码运行请自行打印 API 的返回值
+                const data = await createClient().searchFaceWithOptions(searchFaceRequest, runtime);
+                const matchList = data.body.data?.matchList
+                let response = null
+                if (matchList?.length > 0) {
+                    const faceItems = matchList[0].faceItems
+                    if (faceItems?.length === 0) {
+                        console.log('没有找到患者对应的人脸')
                         response = {
-                            retCode: "1",
-                            uinfo: {
-                                title: user.client_code,
-                                cardID: user.code,
-                                userNum: user.patient_no,
-                                name: user.patient_name,
-                                sex: user.patient_gender === 0 ? '男' : '女',
-                                age: getAgeFromIdCard(user.patient_identity_no),
-                                headimgurl: user.patient_avatar_icon,
-                                imgBaseData: '',
-                                remark: '患者人脸识别111'
-                            },
-                            dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
-                            msg: "success"
+                            retCode: "0",
+                            msg: "没有找到患者,请先检查患者code"
                         };
-                        // res.json(response);
+                    } else if (faceItems[0].score >= 0.2) {
+                        const entityId = faceItems[0].entityId
+                        console.log(entityId, '患者id找到了')
+                        let query = `SELECT * FROM patient_info WHERE code = '${entityId}'`
+                        const [rows] = await pool.promise().query(query);
+                        if (rows.length > 0) {
+                            const user = rows[0];
+                            response = {
+                                retCode: "1",
+                                uinfo: {
+                                    title: user.client_code,
+                                    cardID: user.code,
+                                    userNum: user.patient_no,
+                                    name: user.patient_name,
+                                    sex: user.patient_gender === 0 ? '男' : '女',
+                                    age: getAgeFromIdCard(user.patient_identity_no),
+                                    headimgurl: user.patient_avatar_icon,
+                                    imgBaseData: '',
+                                    remark: '患者人脸识别111'
+                                },
+                                dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
+                                msg: "success"
+                            };
+                            // res.json(response);
+                        } else {
+                            response = {
+                                retCode: "0",
+                                msg: "没有找到患者,请先检查患者code"
+                            };
+                            // res.json(response);
+                        }
                     } else {
                         response = {
                             retCode: "0",
                             msg: "没有找到患者,请先检查患者code"
                         };
-                        // res.json(response);
                     }
-                } else {
-                    response = {
-                        retCode: "0",
-                        msg: "没有找到患者,请先检查患者code"
-                    };
+                    res.json(response);
                 }
-                res.json(response);
-            }
-            else {
-                res.status(500).json({ retCode: "-1", msg: "没有识别到患者" });
-            }
-        } catch (error) {
-            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
-            // 错误 message
-            console.log(error)
-            res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+                else {
+                    res.status(500).json({ retCode: "-1", msg: "没有识别到患者" });
+                }
+            } catch (error) {
+                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+                // 错误 message
+                console.log(error)
+                res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
 
+            }
+        } else {
+            // 如果请求参数不符合预期,则返回错误信息
+            res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
         }
-    } else {
-        // 如果请求参数不符合预期,则返回错误信息
-        res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+    }catch(err){
+        res.status(400).json({ retCode: "-1", msg: err });
     }
 
 
@@ -284,7 +289,7 @@
     await fs.writeFile(outputPath, buffer);
     const ossUrl = await getOssUrl(outputPath)
     // 删除本地图片
-    delImg(outputPath)
+    // delImg(outputPath)
     console.log('File saved to', outputPath);
     console.log(`得到ossUrl=${ossUrl}`)
     return ossUrl
@@ -320,12 +325,10 @@
 // 访问日志记录
 const logHttps=(mode)=>{
     try{
-    console.log(mode)
-    console.log(JSON.stringify(mode))
-    let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')`
-    pool.promise().query(sqlStr)
+        let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')`
+        pool.promise().query(sqlStr)
     }catch (err) {
-        console.error('Error creating directory:', err);
+        console.error('Error creating directory2222:', err);
         throw err;
     }
 }
diff --git a/img/888888.png b/img/888888.png
deleted file mode 100644
index eb768b9..0000000
--- a/img/888888.png
+++ /dev/null
Binary files differ
diff --git a/img/G190166668888.png b/img/G190166668888.png
new file mode 100644
index 0000000..edd439e
--- /dev/null
+++ b/img/G190166668888.png
Binary files differ

--
Gitblit v1.8.0