From 85524bbddf545f14427edbef0ededc310d84434a Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 23 十二月 2024 16:02:37 +0800
Subject: [PATCH] 加如日志
---
/dev/null | 0
app.js | 129 ++++++-------------------
package.json | 1
thirdPartyApi.js | 69 ++-----------
logger.js | 29 +++--
logs/app.log | 65 +++++++++++++
6 files changed, 127 insertions(+), 166 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}/`);
});
/**
diff --git a/logger.js b/logger.js
index 1a29655..dd7164c 100644
--- a/logger.js
+++ b/logger.js
@@ -1,20 +1,21 @@
+// logger.js
+
+const fs = require('fs');
const pino = require('pino');
-const pretty = require('pino-pretty');
+const { destination } = require('pino');
+const path = require('path');
+
+// 创建日志文件路径
+const logDir = path.join(__dirname, 'logs');
+if (!fs.existsSync(logDir)) {
+ fs.mkdirSync(logDir);
+}
+const logFilePath = path.join(logDir, 'app.log');
// 创建日志记录器
const logger = pino({
- level: 'info',
- transport: {
- target: 'pino-pretty', // 可选:美化输出
- options: {
- translateTime: 'SYS:dd-mm-yyyy HH:MM:ss',
- ignore: 'pid,hostname'
- }
- }
-});
+ level: 'info'
+}, destination(logFilePath));
-// 或者简单地创建一个基础日志记录器
-// const logger = pino();
-
-// 将 logger 导出以便其他模块使用
+// 导出日志记录器以便其他模块使用
module.exports = logger;
\ No newline at end of file
diff --git a/logs/app.log b/logs/app.log
new file mode 100644
index 0000000..798be94
--- /dev/null
+++ b/logs/app.log
@@ -0,0 +1,65 @@
+{"level":30,"time":1734939674147,"pid":24288,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734939674148,"pid":24288,"hostname":"dachengzhi","msg":"如果 token 已经过期或不存在,则重新获取"}
+{"level":30,"time":1734939674313,"pid":24288,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940577465,"pid":25508,"hostname":"dachengzhi","msg":"血流量设备上报结果,请求报错"}
+{"level":30,"time":1734940589397,"pid":23232,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940590124,"pid":15820,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940591132,"pid":23428,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940592115,"pid":25476,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940595609,"pid":25476,"hostname":"dachengzhi","msg":"人脸识别请求deviceID=G190166668888,action=doFace"}
+{"level":30,"time":1734940596222,"pid":25476,"hostname":"dachengzhi","msg":"得到oss图片路径=http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAI5tPBxZiqgd9h6gcL9Qzc/22baafc832cb806d4f587c93a62f7034G190166668888.png"}
+{"level":30,"time":1734940598021,"pid":25476,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940598021,"pid":25476,"hostname":"dachengzhi","msg":"如果 token 已经过期或不存在,则重新获取"}
+{"level":30,"time":1734940598332,"pid":25476,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940598492,"pid":25476,"hostname":"dachengzhi","msg":"患者接口请求成功"}
+{"level":30,"time":1734940598492,"pid":25476,"hostname":"dachengzhi","msg":"返回患者信息成功=张三丰"}
+{"level":30,"time":1734940619027,"pid":25476,"hostname":"dachengzhi","msg":"血流量设备上报结果,请求信息clientCode=CLIENT9326174148672wykR"}
+{"level":30,"time":1734940619028,"pid":25476,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/result/from/doppler/blood/flow/device/saveData,data={\"id\":0,\"code\":\"\",\"patient_code\":\"PAT2204031316230148\",\"client_code\":\"CLIENT9326174148672wykR\",\"exam_id\":\"\",\"SBPLB\":471,\"MBPLB\":-1,\"DBPLB\":-1,\"PPLB\":-1,\"SBPRB\":136,\"MBPRB\":-1,\"DBPRB\":-1,\"PPRB\":-1,\"SBPLA\":187,\"MBPLA\":-1,\"DBPLA\":-1,\"SBPRA\":151,\"MBPRA\":-1,\"DBPRA\":-1,\"ABIL\":1.2721088,\"ABIR\":1.2857143,\"BAIL\":0.7777778,\"BAIR\":0.7195767,\"PWVL\":-1,\"PWVR\":-1,\"TBIL\":-1,\"TBIR\":-1,\"SBPLAPTA\":97,\"DBPLAPTA\":-1,\"MBPLAPTA\":-1,\"PPLAPTA\":-1,\"SBPRAPTA\":189,\"DBPRAPTA\":-1,\"MBPRAPTA\":-1,\"PPRAPTA\":-1,\"SBPLAFA\":187,\"DBPLAFA\":-1,\"MBPLAFA\":-1,\"PPLAFA\":-1,\"SBPRAFA\":151,\"DBPRAFA\":-1,\"MBPRAFA\":-1,\"PPRAFA\":-1,\"index_LB\":1,\"index_RB\":0.92517006,\"index_LAPTA\":0.65986395,\"index_RAPTA\":1.2857143,\"index_LAFA\":1.2721088,\"index_RAFA\":1.0272108,\"image\":\"\",\"request_doctor\":\"李医生\",\"request_department\":\"申请科室\",\"request_date\":1734624000000,\"exam_department\":\"检查科室\",\"diagnostician_doctor\":\"谢医生\",\"check_date\":1734624000000,\"check_result\":\"左侧上肢血压偏高;右侧上肢血压未见异常;双侧上肢血压无明显差异;\\n左侧下肢胫后ABI低于正常值;右侧下肢胫后ABI在正常范围;\\n双侧下肢足背ABI在正常范围。\",\"diagnosis\":\"双侧下肢静态ABI未见异常。\\n\",\"exam_type_id\":\"001\",\"exam_type_name\":\"外周动脉阻塞检查\",\"operator_doctor\":\"1111111\",\"abi_advice\":\"本次检查结果未见异常。\",\"pwv_result\":\"\"}"}
+{"level":30,"time":1734940620212,"pid":25476,"hostname":"dachengzhi","msg":"血流量设备上报结果,请求失败"}
+{"level":30,"time":1734940662978,"pid":25476,"hostname":"dachengzhi","msg":"血流量设备上报结果,请求信息clientCode=CLIENT9326174148672wykR"}
+{"level":30,"time":1734940662978,"pid":25476,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/result/from/doppler/blood/flow/device/saveData,data={\"id\":0,\"code\":\"\",\"patient_code\":\"PAT2204031316230148\",\"client_code\":\"CLIENT9326174148672wykR\",\"exam_id\":\"33333333444\",\"SBPLB\":471,\"MBPLB\":-1,\"DBPLB\":-1,\"PPLB\":-1,\"SBPRB\":136,\"MBPRB\":-1,\"DBPRB\":-1,\"PPRB\":-1,\"SBPLA\":187,\"MBPLA\":-1,\"DBPLA\":-1,\"SBPRA\":151,\"MBPRA\":-1,\"DBPRA\":-1,\"ABIL\":1.2721088,\"ABIR\":1.2857143,\"BAIL\":0.7777778,\"BAIR\":0.7195767,\"PWVL\":-1,\"PWVR\":-1,\"TBIL\":-1,\"TBIR\":-1,\"SBPLAPTA\":97,\"DBPLAPTA\":-1,\"MBPLAPTA\":-1,\"PPLAPTA\":-1,\"SBPRAPTA\":189,\"DBPRAPTA\":-1,\"MBPRAPTA\":-1,\"PPRAPTA\":-1,\"SBPLAFA\":187,\"DBPLAFA\":-1,\"MBPLAFA\":-1,\"PPLAFA\":-1,\"SBPRAFA\":151,\"DBPRAFA\":-1,\"MBPRAFA\":-1,\"PPRAFA\":-1,\"index_LB\":1,\"index_RB\":0.92517006,\"index_LAPTA\":0.65986395,\"index_RAPTA\":1.2857143,\"index_LAFA\":1.2721088,\"index_RAFA\":1.0272108,\"image\":\"\",\"request_doctor\":\"李医生\",\"request_department\":\"申请科室\",\"request_date\":1734624000000,\"exam_department\":\"检查科室\",\"diagnostician_doctor\":\"谢医生\",\"check_date\":1734624000000,\"check_result\":\"左侧上肢血压偏高;右侧上肢血压未见异常;双侧上肢血压无明显差异;\\n左侧下肢胫后ABI低于正常值;右侧下肢胫后ABI在正常范围;\\n双侧下肢足背ABI在正常范围。\",\"diagnosis\":\"双侧下肢静态ABI未见异常。\\n\",\"exam_type_id\":\"001\",\"exam_type_name\":\"外周动脉阻塞检查\",\"operator_doctor\":\"1111111\",\"abi_advice\":\"本次检查结果未见异常。\",\"pwv_result\":\"\"}"}
+{"level":30,"time":1734940663308,"pid":25476,"hostname":"dachengzhi","msg":"血流量设备上报结果,请求成功"}
+{"level":30,"time":1734940688086,"pid":25476,"hostname":"dachengzhi","msg":"req body action=doWebUser,deviceID=888888,type=0,xid=PAT2204031316230148"}
+{"level":30,"time":1734940688086,"pid":25476,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940688086,"pid":25476,"hostname":"dachengzhi","msg":"有缓存token,直接输出"}
+{"level":30,"time":1734940688086,"pid":25476,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940688215,"pid":25476,"hostname":"dachengzhi","msg":"get patInfo data={\"code\":500,\"message\":\"报错信息:null,接口 [/patient/info/detail2] 内部错误,请联系管理员\"}"}
+{"level":30,"time":1734940714401,"pid":7592,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940726361,"pid":7428,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940729798,"pid":7428,"hostname":"dachengzhi","msg":"req body action=doWebUser,deviceID=888888,type=0,xid=PAT2204031316230148"}
+{"level":30,"time":1734940729798,"pid":7428,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940729798,"pid":7428,"hostname":"dachengzhi","msg":"如果 token 已经过期或不存在,则重新获取"}
+{"level":30,"time":1734940729946,"pid":7428,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940730049,"pid":7428,"hostname":"dachengzhi","msg":"get patInfo data={\"code\":500,\"message\":\"报错信息:null,接口 [/patient/info/detail2] 内部错误,请联系管理员\"}"}
+{"level":30,"time":1734940799515,"pid":8268,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940806565,"pid":21196,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940815064,"pid":24920,"hostname":"dachengzhi","msg":"Server running at http://localhost:3000/"}
+{"level":30,"time":1734940818112,"pid":24920,"hostname":"dachengzhi","msg":"成分分析仪用户请求req body action=doWebUser,deviceID=888888,type=0,xid=PAT2204031316230148"}
+{"level":30,"time":1734940818112,"pid":24920,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940818112,"pid":24920,"hostname":"dachengzhi","msg":"如果 token 已经过期或不存在,则重新获取"}
+{"level":30,"time":1734940818239,"pid":24920,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940818392,"pid":24920,"hostname":"dachengzhi","msg":"get patInfo data={\"code\":500,\"message\":\"报错信息:null,接口 [/patient/info/detail2] 内部错误,请联系管理员\"}"}
+{"level":30,"time":1734940826006,"pid":24920,"hostname":"dachengzhi","msg":"人脸识别请求deviceID=G190166668888,action=doFace"}
+{"level":30,"time":1734940826482,"pid":24920,"hostname":"dachengzhi","msg":"得到oss图片路径=http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAI5tPBxZiqgd9h6gcL9Qzc/dce4c3638259fdb9a96031479f8b61fcG190166668888.png"}
+{"level":30,"time":1734940827044,"pid":24920,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940827044,"pid":24920,"hostname":"dachengzhi","msg":"有缓存token,直接输出"}
+{"level":30,"time":1734940827044,"pid":24920,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940827150,"pid":24920,"hostname":"dachengzhi","msg":"患者接口请求成功"}
+{"level":30,"time":1734940827150,"pid":24920,"hostname":"dachengzhi","msg":"返回患者信息成功=张三丰"}
+{"level":30,"time":1734940834902,"pid":24920,"hostname":"dachengzhi","msg":"成分分析仪用户请求req body action=doWebUser,deviceID=888888,type=0,xid=PAT9155145531597KDeY"}
+{"level":30,"time":1734940834902,"pid":24920,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940834902,"pid":24920,"hostname":"dachengzhi","msg":"有缓存token,直接输出"}
+{"level":30,"time":1734940834902,"pid":24920,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940835006,"pid":24920,"hostname":"dachengzhi","msg":"get patInfo data={\"code\":200,\"data\":{\"accessPartName\":\"\",\"accessTypeName\":\"\",\"age\":54,\"birthday\":\"1970-02-23\",\"clientCode\":\"211221102200228702\",\"code\":\"PAT9155145531597KDeY\",\"createTime\":\"2024-06-03 14:55:32\",\"createUser\":135,\"deletedTime\":null,\"firstMedMethod\":0,\"hIS慢病备案信息\":null,\"hisCode\":\"\",\"historyCount\":14,\"id\":10842,\"isDeleted\":0,\"isTodayAsMyBirthday\":false,\"medHistoryStatByMonth\":\"66\",\"operateTime\":null,\"operateType\":null,\"patientAddress\":\"上海市联通国际大厦\",\"patientAddressJson\":\"prov=上海\\tcity=上海市\\tdistrict=静安区\\ttown=天目西路街道\\troad=天目西路\\troadno=547号\\tpoi=联通国际大厦\\tpoi_list=联通国际大厦\\tdetail=poi:联通国际大厦\",\"patientAge2\":null,\"patientAvatarIcon\":\"https://dhimg.leon056.com/hemodialysis/face/PAT9155145531597KDeY/face-036e60bb332492d33a6cc262a23c5c19.jpeg-202410211656137475.jpeg\",\"patientBaoxiaoState\":\"220107170900572164\",\"patientBaoxiaoStateName\":\"职工医保\",\"patientBedNo\":\"\",\"patientBirthday\":null,\"patientBloodType\":\"211229100000078230\",\"patientBloodTypeName\":\"A\",\"patientCardNo\":\"\",\"patientCareer\":\"DICT09555620288\",\"patientCareerName\":\"农业,牧渔,水利生产人员\",\"patientCompany\":\"公司地址\",\"patientCrb\":\"211229102600352851\",\"patientCreditValue\":2000,\"patientDegree\":\"DICT09505677102\",\"patientDegreeName\":\"初中\",\"patientDiagnose\":\"\",\"patientDiseaseRecordInGov\":\"\",\"patientDoctor\":\"USER9192092438345eqKo\",\"patientDoctorName\":\"测试宋医生\",\"patientExtendJson\":\"{\\\"历史疾病\\\":\\\"\\\",\\\"既往替代治疗史详情\\\":\\\"\\\",\\\"是否存在既往史\\\":0,\\\"是否存在既往肾脏替代治疗史\\\":0,\\\"诊疗计划\\\":\\\"我是一条诊断计划\\\"}\",\"patientFirstTimeMedTime\":\"2019-06-01 00:00:00\",\"patientFrom\":0,\"patientGender\":0,\"patientGenderText\":\"男\",\"patientHeight\":177,\"patientHemoCode\":\"6444\",\"patientIdentityNo\":\"410926197002232633\",\"patientIdentityType\":0,\"patientInitalMedCount\":0,\"patientInitalWeight\":73,\"patientIsAlcohol\":0,\"patientIsAlive\":1,\"patientIsEyeObstacle\":0,\"patientIsPositive\":1,\"patientIsReligion\":0,\"patientIsSmoking\":0,\"patientJoinInsureArea\":\"\",\"patientMobile\":\"\",\"patientName\":\"张三丰\",\"patientNamePy\":\"zsf\",\"patientNation\":\"220117133600234202\",\"patientNationName\":\"汉族\",\"patientNickName\":\"\",\"patientNo\":\"6444\",\"patientNurse\":\"USER9192092501353cesh\",\"patientNurseName\":\"测试宋护士\",\"patientOpenId\":\"\",\"patientParentCameFrom\":\"上海市\",\"patientPassword\":\"\",\"patientQrcodeUrl\":\"\",\"patientReceiveTime\":\"2023-05-01 00:00:00\",\"patientRelativeDesc\":\"\",\"patientRelativeName\":\"\",\"patientRh\":\"211229100000268785\",\"patientRhName\":\"阴性\",\"patientSignUrl\":\"\",\"patientTelNo\":\"13317872609\",\"patientTelNoRelative\":\"13915172890\",\"patientType\":\"16116564652\",\"patientTypeName\":\"血透患者\",\"patientUnionId\":\"\",\"patientWard\":\"DICT09495311066\",\"patientWardName\":\"\",\"patientWeddingState\":\"211229101700537224\",\"patientWeddingStateName\":\"已婚\",\"patientYibaoAlarmDate\":\"\",\"patientYibaoBarcode\":\"\",\"patientYibaoCode\":\"\",\"patientYibaoEndDate\":null,\"patientYoudaoPeriod\":\"211229102400610348\",\"patientYoudaoPeriodName\":\"无\",\"remark\":\"\",\"updateTime\":\"2024-10-21 16:56:18\",\"updateUser\":1118,\"医保区划信息\":null,\"医保提醒日期\":\"\",\"患者扩展属性信息\":{\"历史疾病\":\"\",\"既往替代治疗史详情\":\"\",\"是否存在既往史\":0,\"是否存在既往肾脏替代治疗史\":0,\"诊疗计划\":\"我是一条诊断计划\",\"首次透析时采用的方式\":\"\",\"首次透析时采用的通路类型\":\"\"},\"最近的人脸照片\":\"https://dhimg.leon056.com/hemodialysis/face/PAT9155145531597KDeY/face-036e60bb332492d33a6cc262a23c5c19.jpeg-202410211656137475.jpeg\"},\"message\":\"SUCCESS\"}"}
+{"level":30,"time":1734940835011,"pid":24920,"hostname":"dachengzhi","msg":"Successfully returned patient information"}
+{"level":30,"time":1734940840342,"pid":24920,"hostname":"dachengzhi","msg":"成分分析仪用户请求req body action=doWebUser,deviceID=888888,type=0,xid=PAT9155145531597KDeY"}
+{"level":30,"time":1734940840342,"pid":24920,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940840342,"pid":24920,"hostname":"dachengzhi","msg":"有缓存token,直接输出"}
+{"level":30,"time":1734940840343,"pid":24920,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/info/detail2,data=null"}
+{"level":30,"time":1734940840450,"pid":24920,"hostname":"dachengzhi","msg":"get patInfo data={\"code\":200,\"data\":{\"accessPartName\":\"\",\"accessTypeName\":\"\",\"age\":54,\"birthday\":\"1970-02-23\",\"clientCode\":\"211221102200228702\",\"code\":\"PAT9155145531597KDeY\",\"createTime\":\"2024-06-03 14:55:32\",\"createUser\":135,\"deletedTime\":null,\"firstMedMethod\":0,\"hIS慢病备案信息\":null,\"hisCode\":\"\",\"historyCount\":14,\"id\":10842,\"isDeleted\":0,\"isTodayAsMyBirthday\":false,\"medHistoryStatByMonth\":\"66\",\"operateTime\":null,\"operateType\":null,\"patientAddress\":\"上海市联通国际大厦\",\"patientAddressJson\":\"prov=上海\\tcity=上海市\\tdistrict=静安区\\ttown=天目西路街道\\troad=天目西路\\troadno=547号\\tpoi=联通国际大厦\\tpoi_list=联通国际大厦\\tdetail=poi:联通国际大厦\",\"patientAge2\":null,\"patientAvatarIcon\":\"https://dhimg.leon056.com/hemodialysis/face/PAT9155145531597KDeY/face-036e60bb332492d33a6cc262a23c5c19.jpeg-202410211656137475.jpeg\",\"patientBaoxiaoState\":\"220107170900572164\",\"patientBaoxiaoStateName\":\"职工医保\",\"patientBedNo\":\"\",\"patientBirthday\":null,\"patientBloodType\":\"211229100000078230\",\"patientBloodTypeName\":\"A\",\"patientCardNo\":\"\",\"patientCareer\":\"DICT09555620288\",\"patientCareerName\":\"农业,牧渔,水利生产人员\",\"patientCompany\":\"公司地址\",\"patientCrb\":\"211229102600352851\",\"patientCreditValue\":2000,\"patientDegree\":\"DICT09505677102\",\"patientDegreeName\":\"初中\",\"patientDiagnose\":\"\",\"patientDiseaseRecordInGov\":\"\",\"patientDoctor\":\"USER9192092438345eqKo\",\"patientDoctorName\":\"测试宋医生\",\"patientExtendJson\":\"{\\\"历史疾病\\\":\\\"\\\",\\\"既往替代治疗史详情\\\":\\\"\\\",\\\"是否存在既往史\\\":0,\\\"是否存在既往肾脏替代治疗史\\\":0,\\\"诊疗计划\\\":\\\"我是一条诊断计划\\\"}\",\"patientFirstTimeMedTime\":\"2019-06-01 00:00:00\",\"patientFrom\":0,\"patientGender\":0,\"patientGenderText\":\"男\",\"patientHeight\":177,\"patientHemoCode\":\"6444\",\"patientIdentityNo\":\"410926197002232633\",\"patientIdentityType\":0,\"patientInitalMedCount\":0,\"patientInitalWeight\":73,\"patientIsAlcohol\":0,\"patientIsAlive\":1,\"patientIsEyeObstacle\":0,\"patientIsPositive\":1,\"patientIsReligion\":0,\"patientIsSmoking\":0,\"patientJoinInsureArea\":\"\",\"patientMobile\":\"\",\"patientName\":\"张三丰\",\"patientNamePy\":\"zsf\",\"patientNation\":\"220117133600234202\",\"patientNationName\":\"汉族\",\"patientNickName\":\"\",\"patientNo\":\"6444\",\"patientNurse\":\"USER9192092501353cesh\",\"patientNurseName\":\"测试宋护士\",\"patientOpenId\":\"\",\"patientParentCameFrom\":\"上海市\",\"patientPassword\":\"\",\"patientQrcodeUrl\":\"\",\"patientReceiveTime\":\"2023-05-01 00:00:00\",\"patientRelativeDesc\":\"\",\"patientRelativeName\":\"\",\"patientRh\":\"211229100000268785\",\"patientRhName\":\"阴性\",\"patientSignUrl\":\"\",\"patientTelNo\":\"13317872609\",\"patientTelNoRelative\":\"13915172890\",\"patientType\":\"16116564652\",\"patientTypeName\":\"血透患者\",\"patientUnionId\":\"\",\"patientWard\":\"DICT09495311066\",\"patientWardName\":\"\",\"patientWeddingState\":\"211229101700537224\",\"patientWeddingStateName\":\"已婚\",\"patientYibaoAlarmDate\":\"\",\"patientYibaoBarcode\":\"\",\"patientYibaoCode\":\"\",\"patientYibaoEndDate\":null,\"patientYoudaoPeriod\":\"211229102400610348\",\"patientYoudaoPeriodName\":\"无\",\"remark\":\"\",\"updateTime\":\"2024-10-21 16:56:18\",\"updateUser\":1118,\"医保区划信息\":null,\"医保提醒日期\":\"\",\"患者扩展属性信息\":{\"历史疾病\":\"\",\"既往替代治疗史详情\":\"\",\"是否存在既往史\":0,\"是否存在既往肾脏替代治疗史\":0,\"诊疗计划\":\"我是一条诊断计划\",\"首次透析时采用的方式\":\"\",\"首次透析时采用的通路类型\":\"\"},\"最近的人脸照片\":\"https://dhimg.leon056.com/hemodialysis/face/PAT9155145531597KDeY/face-036e60bb332492d33a6cc262a23c5c19.jpeg-202410211656137475.jpeg\"},\"message\":\"SUCCESS\"}"}
+{"level":30,"time":1734940840455,"pid":24920,"hostname":"dachengzhi","msg":"Successfully returned patient information"}
+{"level":30,"time":1734940868810,"pid":24920,"hostname":"dachengzhi","msg":"人体成分分析仪结果返回请求deviceID=undefined,action={\"deviceModel\":\"SH-X10\",\"unitName\":\"上禾科技\",\"datas\":[{\"address\":\"\",\"userID\":\"PAT9288163627318uEtm\",\"loginType\":\"0\",\"measureTime\":\"2024-11-04 15:04:31\",\"bmi_s\":\"1\",\"bmi\":\"19.8\",\"height\":\"168.5\",\"birthday\":\"\",\"weight\":\"56.1\",\"age\":\"58\",\"weight_n\":\"52.6 - 71.0\",\"name\":\"雷雨\",\"weight_s\":\"1\",\"sex\":\"1\",\"recordNo\":\"20241104150431\",\"bmi_n\":\"18.5-24.9\"}],\"unitNo\":\"000000\",\"macAddr\":\"68:8f:c9:06:41:2d\",\"deviceNo\":\"G241016090739070\",\"action\":\"webResults\"}"}
+{"level":30,"time":1734940868811,"pid":24920,"hostname":"dachengzhi","msg":"获取缓存或新的 Token"}
+{"level":30,"time":1734940868811,"pid":24920,"hostname":"dachengzhi","msg":"有缓存token,直接输出"}
+{"level":30,"time":1734940868811,"pid":24920,"hostname":"dachengzhi","msg":"打包token 请求头urlhttp://testbs.ihemodialysis.com//patient/rtcf/result/save,data={\"id\":0,\"code\":\"20241104150431\",\"patientCode\":\"PAT9288163627318uEtm\",\"commTime\":\"2024-11-04 15:04:31\",\"rtcfJsonBmi\":\"{\\\"address\\\":\\\"\\\",\\\"userID\\\":\\\"PAT9288163627318uEtm\\\",\\\"loginType\\\":\\\"0\\\",\\\"measureTime\\\":\\\"2024-11-04 15:04:31\\\",\\\"bmi_s\\\":\\\"1\\\",\\\"bmi\\\":\\\"19.8\\\",\\\"height\\\":\\\"168.5\\\",\\\"birthday\\\":\\\"\\\",\\\"weight\\\":\\\"56.1\\\",\\\"age\\\":\\\"58\\\",\\\"weight_n\\\":\\\"52.6 - 71.0\\\",\\\"name\\\":\\\"雷雨\\\",\\\"weight_s\\\":\\\"1\\\",\\\"sex\\\":\\\"1\\\",\\\"recordNo\\\":\\\"20241104150431\\\",\\\"bmi_n\\\":\\\"18.5-24.9\\\"}\"}"}
+{"level":30,"time":1734940869025,"pid":24920,"hostname":"dachengzhi","msg":"结果插入成功"}
diff --git a/package.json b/package.json
index f83758e..590d7cb 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"pkg": "^5.8.1"
},
"devDependencies": {
+ "@vercel/ncc": "^0.38.3",
"nodemon": "^3.1.7"
},
"pkg": {
diff --git a/test.js b/test.js
deleted file mode 100644
index e69de29..0000000
--- a/test.js
+++ /dev/null
diff --git a/thirdPartyApi.js b/thirdPartyApi.js
index b508184..3a90e57 100644
--- a/thirdPartyApi.js
+++ b/thirdPartyApi.js
@@ -1,11 +1,13 @@
// thirdPartyApi.js
const axios = require('axios');
-
-const logger = require('./logger'); // 根据实际情况调整路径
-// BASIC_API = 'https://hemobs.icoldchain.cn/'
+const path = require('path');
+const FormData = require('form-data');
+// const logger = require(path.resolve(__dirname, 'logger'));
+BASIC_API = 'https://hemobs.icoldchain.cn/'
const BASIC_API = 'http://testbs.ihemodialysis.com/'
let cachedToken = null;
let tokenExpiresAt = null;
+
// 获取 Token 的函数
async function getAccessToken() {
@@ -30,13 +32,15 @@
// 获取缓存或新的 Token
async function getCachedOrNewToken() {
- logger.log('Check if the token exists')
+ logger.info('获取缓存或新的 Token')
if (cachedToken && tokenExpiresAt > Date.now()) {
+ logger.info('有缓存token,直接输出')
return cachedToken;
}
// 如果 token 已经过期或不存在,则重新获取
- logger.log('If the token has expired or does not exist, retrieve it again')
+ logger.info('如果 token 已经过期或不存在,则重新获取')
+ console.log('如果 token 已经过期或不存在,则重新获取')
const { data, expires_in } = await getAccessToken();
cachedToken = data;
tokenExpiresAt = Date.now() + (expires_in - 60) * 1000; // 提前 60 秒刷新 token
@@ -56,6 +60,7 @@
async function fetchThirdPartyDataNoToke(url, method = 'GET', headers = {}, data = null, queryParams = {}, pathParams = {}) {
try {
const fullUrl = buildUrl(url, pathParams);
+ logger.info(`打包token 请求头url${fullUrl},data=${JSON.stringify(data)}`)
const response = await axios({
url: fullUrl,
method,
@@ -68,7 +73,7 @@
return response.data;
} catch (error) {
- console.error('Error fetching third-party data:', error.message);
+
throw error;
}
}
@@ -77,10 +82,8 @@
async function fetchThirdPartyData(url, method = 'GET', headers = {}, data = null, queryParams = {}, pathParams = {}) {
try {
const token = await getCachedOrNewToken();
- logger.info(`get token====${token}`)
- console.log('得到了token------------------------',token)
const fullUrl = buildUrl(url, pathParams);
-
+ logger.info(`打包token 请求头url${fullUrl},data=${JSON.stringify(data)}`)
const response = await axios({
url: fullUrl,
method,
@@ -94,8 +97,7 @@
return response.data;
} catch (error) {
- logger.error('Error fetching third-party data:', error.message)
- console.error('Error fetching third-party data:', error.message);
+ logger.error(`请求失败!'${error.message} `)
throw error;
}
}
@@ -105,48 +107,3 @@
fetchThirdPartyData,
getAccessToken
};
-
-// 插入数据
-const installData=async (mode)=>{
- console.log(mode)
- try{
- let selectSql=`SELECT * FROM patient_rtcf_result WHERE code='${mode.recordNo}'`
- const [rows] = await pool.promise().query(selectSql);
- if(rows.length>0){
- let updateSql=''
- if(mode.fatFree){
- updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bf ='${JSON.stringify(mode)}'`
- }else if (mode.bmi){
- updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bmi ='${JSON.stringify(mode)}'`
- }
- if(updateSql){
- console.log(`-------------------------更新${updateSql}---------`)
- console.log(updateSql)
- await pool.promise().query(updateSql)
- }
- }else{
- console.log('34')
- // 临时的人体成分分析
- let bf=''
- // 临时的身高体重
- let bmi=''
- if(mode.fatFree){
- bf=JSON.stringify(mode)
- }
- if(mode.bmi){
- bmi=JSON.stringify(mode)
- }
- console.log(`bf=${bf},bmi=====${bmi}`)
- let sqlStr=`INSERT INTO patient_rtcf_result (id, code, patient_code,`+
- `comm_time,rtcf_json_bmi,`+
- `rtcf_json_bf,`+
- `create_time)`+
- `VALUES (0, '${mode.recordNo}', '${mode.userID}', '${mode.measureTime}','${bmi}','${bf}','${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}')`
- console.log(sqlStr)
- await pool.promise().query(sqlStr)
- }
-
- }catch(err){
- console.log('数据写入异常22')
- }
-}
\ No newline at end of file
--
Gitblit v1.8.0