From 3e84213ddd83ec01d44646ccf6067328e71b7c17 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 21 十月 2024 16:54:57 +0800
Subject: [PATCH] 3456

---
 app.js |   66 ++++++++++++++++++++++++++++++--
 1 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/app.js b/app.js
index c9ae4b3..8bfe0f1 100644
--- a/app.js
+++ b/app.js
@@ -63,7 +63,7 @@
                         userNum: user.patient_no,
                         name: user.patient_name,
                         sex: user.patient_gender === 0 ? '男' : '女',
-                        age: user.patient_age_2,
+                        age: getAgeFromIdCard(user.patient_identity_no),
                         headimgurl: user.patient_avatar_icon,
                         imgBaseData: '',
                         remark: ''
@@ -102,7 +102,7 @@
         const ossurl = await base64toFile(content, deviceID)
         console.log('得到oss图片路径', ossurl)
         let searchFaceRequest = new facebody20191230.SearchFaceRequest({
-            dbName: 'Face_emeishan',
+            dbName: 'Face_systemtest',
             imageUrl: ossurl,
             limit: 1,
         });
@@ -136,10 +136,10 @@
                                 userNum: user.patient_no,
                                 name: user.patient_name,
                                 sex: user.patient_gender === 0 ? '男' : '女',
-                                age: user.patient_age_2,
+                                age: getAgeFromIdCard(user.patient_identity_no),
                                 headimgurl: user.patient_avatar_icon,
                                 imgBaseData: '',
-                                remark: ''
+                                remark: '患者人脸识别111'
                             },
                             dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
                             msg: "success"
@@ -296,4 +296,60 @@
     }catch(err){
         console.log('数据写入异常')
     }
-}
\ No newline at end of file
+}
+const getAge=(idCard)=>{
+       // 检查身份证号码长度是否正确
+       if (idCard.length !== 18) {
+        throw new Error('身份证号码长度必须为18位');
+    }
+
+    // 获取出生年月日
+    const birthYear = parseInt(idCard.substring(6, 10), 10);
+    const birthMonth = parseInt(idCard.substring(10, 12), 10);
+    const birthDay = parseInt(idCard.substring(12, 14), 10);
+
+    // 获取当前日期
+    const now = new Date();
+    const currentYear = now.getFullYear();
+    const currentMonth = now.getMonth() + 1; // 注意:getMonth() 返回的月份是从0开始的
+    const currentDay = now.getDate();
+
+    // 计算年龄
+    let age = currentYear - birthYear;
+
+    // 如果当前日期在生日之前,则年龄减一
+    if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
+        age--;
+    }
+
+    return age;
+}
+function getAgeFromIdCard(idCard) {
+    // 检查身份证号码长度是否正确
+    if (idCard.length !== 18) {
+        // throw new Error('身份证号码长度必须为18位');
+        return ''
+    }
+
+    // 获取出生年月日
+    const birthYear = parseInt(idCard.substring(6, 10), 10);
+    const birthMonth = parseInt(idCard.substring(10, 12), 10);
+    const birthDay = parseInt(idCard.substring(12, 14), 10);
+
+    // 获取当前日期
+    const now = new Date();
+    const currentYear = now.getFullYear();
+    const currentMonth = now.getMonth() + 1; // 注意:getMonth() 返回的月份是从0开始的
+    const currentDay = now.getDate();
+
+    // 计算年龄
+    let age = currentYear - birthYear;
+
+    // 如果当前日期在生日之前,则年龄减一
+    if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
+        age--;
+    }
+
+    return age;
+}
+

--
Gitblit v1.8.0