chenyc
2025-07-31 1a75bdddcea613825535fd03c9ac318c3ca8dc3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
const express = require('express');
const bodyParser = require('body-parser');
const mysql = require('mysql2');
const fs = require('fs').promises;
const path = require('path');
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(path.resolve(__dirname, 'thirdPartyApi'));
 
const app = express();
app.use(bodyParser.json())
const port = 3000;
 
// 设置 JSON 请求体的最大大小为 5MB
app.use(express.json({ limit: '5mb' }));
 
// 设置 URL 编码请求体的最大大小为 5MB
app.use(express.urlencoded({ extended: true, limit: '5mb' }));
 
// 使用 body-parser 中间件解析 JSON 请求体
app.use(bodyParser.json());
 
// 创建 MySQL 连接池
const pool = mysql.createPool({
    host: 'rds.leon056.com',
    port: 26422, // 确保端口号正确
    user: 'root',
    password: 'PalGain2007', // 请替换为您的数据库密码
    database: 'hemodialysis_sys'  // 请替换为您的数据库名称
});
 
const createClient = () => {
    // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
    // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378664.html。
    let config = new OpenApi.Config({
        // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
        accessKeyId: 'LTAI5tPBxZiqgd9h6gcL9Qzc',
        // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
        accessKeySecret: 'IE6nsjJMTul2ZHkeQ27bg4wmWIngTu',
    });
    // Endpoint 请参考 https://api.aliyun.com/product/facebody
    config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
    return new facebody20191230.default(config);
}
app.get('/', (req, res) => {
    
    res.json({mas:'hdadsadas'});
  });
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
    logHttps(mode)
    const action = req.body.action;
    const deviceID = req.body.deviceID;
    const type = req.body.type;
    const xid = req.body.xid;
    logger.info(`成分分析仪用户请求req body action=${action},deviceID=${deviceID},type=${type},xid=${xid}`)
    if (action === 'doWebUser' && deviceID && type !== undefined) {
        try {
            const pathParams={code:xid}
            const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null,  pathParams,{});
            logger.info(`get patInfo data=${JSON.stringify(data)}`)
            console.log('get patInfo ----',data.data)
            // 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"
                };
                logger.info('Successfully returned patient information')
                console.log('Successfully returned patient information')
            }else{
                response = {
                    retcode: 1001,
                    remsg: "没有找到患者,请先检查患者code"
                };
            }
            res.json(response);
 
        } catch (err) {
            console.error(err);
            logger.error(err)
            res.status(500).json({ retCode: "-1", msg: err });
        }
    } else {
        // 如果请求参数不符合预期,则返回错误信息
        res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
    }
});
// 定义人脸识别  用base64图片文件换患者信息
app.post('/faceuser', async (req, res) => {
    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=''
        logger.info(`人脸识别请求deviceID=${deviceID},action=${action}`)
        if (action == 'doFace' && deviceID && content) {
            // 转成oss路径
            const ossurl = await base64toFile(content, deviceID)
            logger.info(`得到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) {
                        logger.info(`没有找到患者对应的人脸`)
                        response = {
                            retCode: "0",
                            msg: "没有找到患者,请先检查患者code"
                        };
                    } else if (faceItems[0].score >= 0.2) {
                        const entityId = faceItems[0].entityId
                        console.log(entityId, '患者id找到了')
                        const pathParams={code:entityId}
                        const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null,  pathParams,{});
                        logger.info(`患者接口请求成功`)
                        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"
                            };
                            logger.info(`返回患者信息成功=${user.patientName}`)
                        }else{
                            response = {
                                retcode: 1001,
                                remsg: "没有找到患者,请先检查患者code"
                            };
                        }
                        
                    } else {
                        response = {
                            retcode: 1001,
                            remsg: "没有找到患者,请先检查患者code"
                        };
                    }
                    res.json(response);
                }
                else {
                    res.status(500).json({ retCode: "-1", msg: "没有识别到患者" });
                }
            } catch (error) {
                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
                // 错误 message
                console.log(error)
                res.status(400).json({ retCode: "-1", msg: error });
 
            }
        } else {
            // 如果请求参数不符合预期,则返回错误信息
            res.status(400).json({ retCode: "-1", msg: "Invalid request parameters 333"  });
        }
    }catch(err){
        res.status(400).json({ retCode: "-1", msg: err });
    }
 
 
 
 
})
// 定义设备数据回传接口
// 定义数据回传接口
app.post('/webResults',async (req, res) =>{
    const action = req.body.action;
    const deviceID = req.body.deviceID;
    const mode=req.body
    mode.action='webResults'
    logger.info(`人体成分分析仪结果返回请求deviceID=${deviceID},action=${JSON.stringify(mode)}`)
    try {
      
        const datas=mode.datas
        datas.forEach(async element => {
            // 组合数据
            let data={}
            // 没有BF
            if(element.fatFree){
                data={
                    id:0,
                    code:element.recordNo,
                    patientCode:element.userID,
                    commTime:element.measureTime,
                    rtcfJsonBf:JSON.stringify(element)
                }
            }
            // 没有BMI
            if(element.bmi){
                data={
                    id:0,
                    code:element.recordNo,
                    patientCode:element.userID,
                    commTime:element.measureTime,
                    rtcfJsonBmi:JSON.stringify(element)
                }
            }
            console.log(data)
            const resdata = await thirdPartyApi.fetchThirdPartyData('/patient/rtcf/result/save', 'POST', {}, data,{},{});
            logger.info(`结果插入成功`)
            console.log(resdata)
        });
        response = {
            recode: "2000",
            remsg: "成功2222"
        };
        res.json(response)
       
    }catch(err){
        logger.errer(`结果插入失败`)
        res.status(4000).json({ reCode: "4000", msg: "Invalid request parameters" });
    }
    
})
// 定义北京悦琦创通科技有限公司VBP-10系列HTTP通信协议
/**
 * patientId={patientId} 
 */
app.get('/getpatientInfo',async(req,res)=>{
    // 使用req.query访问查询字符串参数
  const patientId = req.query.patientId;
  const clientCode = req.query.clientCode;
  const mode={"action":'getpatientInfo',"patientId":patientId,}
  console.log(patientId,'-----------------',clientCode)
  logger.info(`血流量设备请求患者信息,请求参数=${patientId},clintCode=${clientCode}`)
  if(patientId&&clientCode){
    // 输出传入的patientid值
    try {
        //查询参数
        const pathParams={
            clientCode:clientCode,
            patQueryCode:patientId
        }
        const data = await thirdPartyApi.fetchThirdPartyDataNoToke('/patient/info/listPatsPublic', 'POST', {}, null,  pathParams,{});
        console.log(data.data.list)
        const rows= data.data.list
        if (rows.length > 0) {
            let users=[]
            rows.forEach(user=>{
                users.push({
                    patientId: user.code,
                    fullName: user.patientName,
                    gender: user.patientGender,
                    age: user.age,
                    birthday:'',
                    phoneNum:user.patientMobile,
                    address: user.patientAvatarIcon,
                    idType: user.patientIdentityType,
                    idNum: user.patientIdentityNo,
                    height:'',
                    weight:'',
                    requestDoctor:'',
                    requestDept :"",
                    examDoctor:'',
                    examDept:"",
                    diagnosisDoctor:''
                })
            })
            logger.info(`血流量设备请求患者信息,请求成功返回患者信息=${JSON.stringify(users)}`)
            res.json(users);
        } else {
            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: "请求参数出错" });
  }
 
})
/**
 * PostCheckExam  病人信息及检测结果以JSON的形式回传至服务器
 */
app.post('/PostCheckExam',async (req,res)=>{
    try {
        const clientCode = req.query.clientCode;
        console.log('-------------------',clientCode)
        if(!clientCode){
            res.json({"Msg": "请求参数没有clientCode", "Status": "err" });
            return
        }
        const body=req.body
        console.log(body)
        logger.info(`血流量设备上报结果,请求信息clientCode=${clientCode}`)
        // 组合上传数据
        const data={
            id:0,
            code:'',
            patient_code :body.patientId,
            client_code:clientCode,
            exam_id:body.examId,
            SBPLB:body.SBPLB,
            MBPLB:body.MBPLB,
            DBPLB:body.DBPLB,
            PPLB:body.PPLB,
            SBPRB:body.SBPRB,
            MBPRB:body.MBPRB,
            DBPRB:body.DBPRB,
            PPRB:body.PPRB,
            SBPLA:body.SBPLA,
            MBPLA:body.MBPLA,
            DBPLA:body.DBPLA,
            SBPRA:body.SBPRA,
            MBPRA:body.MBPRA,
            DBPRA:body.DBPRA,
            ABIL:body.ABIL,
            ABIR:body.ABIR,
            BAIL:body.BAIL,
            BAIR:body.BAIR,
            PWVL:body.PWVL,
            PWVR:body.PWVR,
            TBIL:body.TBIL,
            TBIR:body.TBIR,
            SBPLAPTA:body.SBPLAPTA,
            DBPLAPTA:body.DBPLAPTA,
            MBPLAPTA:body.MBPLAPTA,
            PPLAPTA:body.PPLAPTA,
            SBPRAPTA:body.SBPRAPTA,
            DBPRAPTA:body.DBPRAPTA,
            MBPRAPTA:body.MBPRAPTA,
            PPRAPTA:body.PPRAPTA,
            SBPLAFA:body.SBPLAFA,
            DBPLAFA:body.DBPLAFA,
            MBPLAFA:body.MBPLAFA,
            PPLAFA:body.PPLAFA,
            SBPRAFA:body.SBPRAFA,
            DBPRAFA:body.DBPRAFA,
            MBPRAFA:body.MBPRAFA,
            PPRAFA:body.PPRAFA,
            index_LB:body.indexLB,
            index_RB:body.indexRB,
            index_LAPTA:body.indexLAPTA,
            index_RAPTA:body.indexRAPTA,
            index_LAFA:body.indexLAFA,
            index_RAFA:body.indexRAFA,
            image:body.image,
            request_doctor:body.requestDoctor,
            request_department:body.requestDepartment,
            request_date:getDateString(body.requestDate),
            exam_department:body.examDepartment,
            diagnostician_doctor:body.diagnosticianDoctor,
            check_date:getDateString(body.checkDate),
            check_result:body.checkResult,
            diagnosis:body.diagnosis,
            exam_type_id:body.examTypeId,
            exam_type_name:body.examTypeName,
            operator_doctor:body.operatorDoctor,
            abi_advice:body.abiAdvice,
            pwv_result:body.pwvResult
        }
        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){
        logger.info(`血流量设备上报结果,请求报错`)
        res.status(400).json({ retCode: "-1", msg: "请求出错了11" });
    }
  
 
    
})
// 大连新的InBody 人体成分分析仪患者注册
app.post('/inbodyapi/getuserinfo',async (req, res) => {
    logger.info(`人体成分分析仪患者注册请求body=${JSON.stringify(req.body)}`)
     // 从请求体中获取用户信息
     // 这里假设请求体包含 USER_ID 和 ORDER_DATE 字段
    const { USER_ID, ORDER_DATE } = req.body;
     // 检查请求参数是否有效
     if (!USER_ID) {
        return res.status(400).json({
            IsResult: false,
            INBODY_USER_INFO: [],
            ErrorMsg: 'USER_ID or ORDER_DATE is missing'
        });
    }
     const pathParams = { clientCode:'CLIENT9195181802236kHJF',patientHemoCode:USER_ID}
     const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/queryInAndOuts', 'POST', {}, pathParams,  {},{});
        // console.log('查询InAndOuts数据',data)
        if(data.code===200&&data?.message==='SUCCESS'&&data?.data){
            const list= data.data.list;
            if(list.length>0){
 
                console.log(list[0])
                const mode=list[0]
                const user={
                    USER_ID: mode.patientHemoCode,
                    USER_NAME: mode.patientName,
                    USER_GENDER: mode.patientGender===0? 'M':'F',
                    USER_BIRTHDAY: '',
                    USER_AGE: mode.age,
                    USER_HEIGHT: mode.patientHeight,
                    ORDER_DATE:mode.code
                }
                res.json({
                    IsResult: true,
                    INBODY_USER_INFO: [user],
                    ErrorMsg: ''
                });
 
                logger.info(`请求患者成功:${mode.patientName}`)
            }
            else{
                res.json({
                    IsResult: false,
                    INBODY_USER_INFO: [],
                    ErrorMsg: 'User not found'
                });
                logger.info(`请求患者失败:没有找到用户`)
            }
        }else{
            res.json({
                IsResult: false,
                INBODY_USER_INFO: [],
                ErrorMsg: 'User not found'
            });
            logger.info(`请求患者失败:没有找到用户`)
        }
})
app.post('/inbodyapi/setinbodydata',async (req, res) => {
    logger.info(`人体成分分析仪结果请求body=${JSON.stringify(req.body)}`)
    const element = req.body;
    try {
        const data={
            id:0,
            code:'',
            // code:element.DATETIMES,
            patientCode:element.ORDER_DATE,
            commTime:formatted(),
            uploadTime:formatTimestamp(element.DATETIMES),
            rtcfJsonBmi:JSON.stringify(element),
        }
        const resdata = await thirdPartyApi.fetchThirdPartyData('/patient/rtcf/result/save', 'POST', {}, data,{},{});
        if(resdata.code===200&&resdata?.message==='SUCCESS'){
            logger.info(`结果插入成功`+JSON.stringify(resdata))
            res.json({
                IsResult: true,
                ErrorMsg: 'User not found'
            });
        }else{
            logger.info(`结果插入失败`+JSON.stringify(resdata))
        }
    } catch (error) {
        return res.status(400).json({
            IsResult: false,
            ErrorMsg: error
        });
    }
})
 
 
// 启动服务器
app.listen(port, async () => {
    logger.info(`Server running at http://localhost:${port}/`)
    console.log(`Server running at http://localhost:${port}/`);
});
/**
 * 
 * @param {*} file base64图片格式转本地
 */
// base64z转文件后验证
const base64toFile = async (dataurl, imgName) => {
    // 将 Base64 数据转换为 Buffer
    const buffer = Buffer.from(dataurl, 'base64');
    // 定义输出文件路径
    // 定义输出文件路径
    const outputDir = path.join(__dirname, 'img');
    const outputPath = path.join(outputDir, `${imgName}.png`);
    await ensureDirectoryExists(outputDir);
    await fs.writeFile(outputPath, buffer);
    const ossUrl = await getOssUrl(outputPath)
    // 删除本地图片
    delImg(outputPath)
    console.log('File saved to', outputPath);
    console.log(`得到ossUrl=${ossUrl}`)
    return ossUrl
 
}
//验证后删除文件图片
const delImg = (path) => {
    fs.unlink(path, (err) => {
        if (err) {
            console.log('删除失败')
        } else {
            console.log('删除成功')
        }
    })
}
 
// 确保输出目录存在
const ensureDirectoryExists = async (directory) => {
    try {
        await fs.mkdir(directory, { recursive: true });
    } catch (err) {
        console.error('Error creating directory:', err);
    }
}
// 将文件上传到阿里的oss
const getOssUrl = async (path) => {
    let ossUrl = await ViapiUtil.default.upload('LTAI5tPBxZiqgd9h6gcL9Qzc', 'IE6nsjJMTul2ZHkeQ27bg4wmWIngTu', path);
    console.log(ossUrl)
    return ossUrl
}
 
// 访问日志记录
const logHttps=(mode)=>{
    try{
        let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')`
        console.log(sqlStr)
        pool.promise().query(sqlStr)
    }catch (err) {
        console.error('访问日志记录错误:', err);
    }
}
 
/**
 * 根据身份证算年龄
 */
 
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;
}
 
/**
 * 时间戳转string  输出: "2024-01-08 00:00:00" (假设时区为东八区)
 * @param {*} date 
 */
function getDateString(date){
    try{
        if(date){
            let timestamp = 1734624000000;
            let d = new Date(timestamp);
            return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
        }else{
            return ''
        }
    }
    catch(err){
        console.log(err)
        return ''
    }
    
   
}
function getCurrentDateFormatted() {
    const date = new Date();
 
    const year = date.getFullYear(); // 获取年份,如 2025
 
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份(0-11),需要 +1,然后补零
 
    const day = String(date.getDate()).padStart(2, '0'); // 获取日期,并补零
 
    return `${year}${month}${day}`;
}
function formatTimestamp(timestampStr) {
    const str = String(timestampStr);
    
    // 使用正则表达式匹配 YYYYMMDDHHMMSS 并分组
    const match = str.match(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/);
    
    if (!match) {
        throw new Error("Invalid timestamp format");
    }
    
    // 重组为 YYYY-MM-DD HH:mm:ss
    return `${match[1]}-${match[2]}-${match[3]} ${match[4]}:${match[5]}:${match[6]}`;
}
 
 
function formatted() {
    const date = new Date();
    return date.getFullYear() + '-' +
    String(date.getMonth() + 1).padStart(2, '0') + '-' +
    String(date.getDate()).padStart(2, '0') + ' ' +
    String(date.getHours()).padStart(2, '0') + ':' +
    String(date.getMinutes()).padStart(2, '0') + ':' +
    String(date.getSeconds()).padStart(2, '0');
}