schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
import * as fs from "fs";
import * as path from "path";
import BaseService from "../baseService";
import { aliYunDownload, aliOSSDelete, aliOSSCopy } from "../../public/aliyunOssHelper";
import moment = require("moment");
import { TMSIdCard } from "../../entity/express/tms/tmsIdCard";
import { ResultInfo } from "../../public/commonInterface";
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
import { TMSWayBillReceive } from "../../entity/express/tms/tmsWayBillReceive";
 
/**
 * 身份证处理
 */
export default class IdCardService extends BaseService {
  //#region idCardUpload 身份证识别
  public async idCardUpload() {
    try {
      // front
      let WebAddress = this.body.positiveServerUrl + "?x-oss-process=style/600";
 
      var positiveServerUrl = this.body.positiveServerUrl.replace(
        "https://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com",
        ""
      );
      positiveServerUrl = this.body.positiveServerUrl.replace(
        "http://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com",
        ""
      );
      var filename = path.basename(positiveServerUrl);
      var _path = path.dirname(positiveServerUrl).replace(/\//g, path.sep);
      let root = path.resolve();
      _path = root + _path;
      await this.downFile(filename, WebAddress, _path);
 
      let idCardList = [];
      var _item: any = {};
      _item.card_Side = "front";
      _item.url = _path + path.sep + filename;
      idCardList.push(_item);
 
      // back
      WebAddress = this.body.negativeServerUrl + "?x-oss-process=style/600";
 
      var negativeServerUrl = this.body.negativeServerUrl.replace(
        "https://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com",
        ""
      );
      negativeServerUrl = this.body.negativeServerUrl.replace(
        "http://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com",
        ""
      );
      filename = path.basename(negativeServerUrl);
      _path = path.dirname(negativeServerUrl).replace(/\//g, path.sep);
      _path = root + _path;
      await this.downFile(filename, WebAddress, _path);
      _item = {};
      _item.card_Side = "back";
      _item.url = _path + path.sep + filename;
      idCardList.push(_item);
 
      var idCardInfo = {
        front: "",
        back: ""
      };
 
      for (var item of idCardList) {
        idCardInfo[item.card_Side] = await this.parseInfo(item.url, item.card_Side);
      }
      this.info.data = idCardInfo;
      this.info.result = true;
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    return this.info;
  }
  //#endregion
 
  //#region parseInfo 获取身份信息
  public async parseInfo(imgPath: string, idCardSide: string) {
    let APP_ID = "16447203";
    let API_KEY = "2Veev1gGjt7e9EW1kwrazcBp";
    let SECRET_KEY = "4k6DG2omFdWHSIFUVxk9EX9QYng6ZZCj";
    //imgPath = @"d:\YrtDev3\mCRM\WMS_Transport_SaaS\WinIdCard\bin\Debug\Upload\Card\22020419710520152X_1.jpg";
    try {
      var AipOcrClient = require("baidu-aip-sdk").ocr;
      let client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY);
      // client.Timeout = 5 * 60 * 10000; // 修改超时时间
 
      var fs = require("fs");
      var image = fs.readFileSync(imgPath).toString("base64");
 
      // 调用身份证识别
      let result = await client.idcard(image, idCardSide);
 
      return result;
    } catch (ex) {
      let result = { image_status: `识别出错:${ex.message}` };
      return result;
    }
  }
  //#endregion
 
  //#region downFile
  public async downFile(fileName: string, url: string, localPath: string) {
    localPath = localPath.replace(/\//g, path.sep).replace(path.sep + path.sep, path.sep);
    var fullPath = localPath + path.sep + fileName;
    fullPath = fullPath.replace(path.sep + path.sep, path.sep);
    this.ctx.helper.mkdir(localPath);
 
    if (url.indexOf("auod-bucket-01.oss-ap-southeast-2.aliyuncs.com") >= 0) {
      //System.Net.WebClient wc = new System.Net.WebClient();
      //wc.DownloadFile(url, fullPath);
      //wc.Dispose();
      await aliYunDownload(this.ctx, url, fullPath);
    } else {
      await aliYunDownload(this.ctx, url, fullPath);
    }
  }
  //#endregion
 
  //#region SingleAnalysis
  /// <summary>
  /// GetToken
  /// </summary>
  /// <param name="this.body"></param>
  /// <returns></returns>
  public async singleAnalysis(item: TMSIdCard, info: ResultInfo) {
    let positiveServerUrl = item.positiveServerUrl;
    let negativeServerUrl = item.negativeServerUrl;
    let idCardCode = item.idCardCode;
    if (!positiveServerUrl || !negativeServerUrl) {
      item.idCardCode = idCardCode;
      item.provingState = "已验证";
      item.periodState = "无效";
      item.remark = "身份证图片不存在";
      item.modifyDate = new Date();
      this.ctx.logger.info(idCardCode + "身份证图片不存在");
      await this.dbWrite.save(item);
 
      return;
    }
 
    let urlServer = "https://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com";
    if (positiveServerUrl.indexOf("http") < 0) {
      positiveServerUrl = urlServer + positiveServerUrl;
    }
    if (negativeServerUrl.indexOf("http") < 0) {
      negativeServerUrl = urlServer + negativeServerUrl;
    }
 
    try {
      info.result = await this.parseIdCard(item, positiveServerUrl, negativeServerUrl);
      if (info.result) {
        info.msg = "执行完成";
        this.ctx.logger.info(item.idCardCode + " 执行完成");
      } else {
        info.msg = "执行失败";
        this.ctx.logger.info(item.idCardCode + " 分析失败," + item.remark);
      }
      await this.dbWrite.save(item);
    } catch (exc) {
      info.result = false;
      info.msg = "执行完成";
      item.provingState = "已验证";
      item.periodState = "无效";
      if (exc.message.indexOf("重复键值为") >= 0) {
        item.remark = "身份证号已经存在";
      } else {
        item.remark = exc.message;
      }
      item.idCardCode = idCardCode;
      await this.dbWrite.save(item);
      this.ctx.logger.info(item.idCardCode + " 分析失败:" + exc.message);
    }
 
    return info;
  }
  //#endregion
 
  //#region ParseIdCard 分析身份证
  /// <summary>
  /// 分析身份证
  /// </summary>
  /// <param name="positiveServerUrl"></param>
  /// <param name="negativeServerUrl"></param>
  /// <param name="idCardCode"></param>
  /// <returns></returns>
  private async parseIdCard(idCardInfo: TMSIdCard, positiveServerUrl: string, negativeServerUrl: string) {
    let positiveServerPath = "";
    let negativeServerPath = "";
 
    let root = path.resolve();
    let rootPath = root + path.sep + "idCard" + path.sep;
    try {
      //下载图片
      if (positiveServerUrl.indexOf("http") >= 0) {
        //#region
        let urlServer = "https://auod-bucket-01.oss-ap-southeast-2.aliyuncs.com/FileServer/pic";
        let item = positiveServerUrl.replace(urlServer, "");
        urlServer = "https://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com";
        item = item.replace(urlServer, "");
        item = item.replace("?x-oss-process=style/600", "");
 
        let filename = path.basename(item);
        let _path = rootPath + path.dirname(item);
        positiveServerPath = _path + path.sep + filename;
        try {
          await this.downFile(filename, positiveServerUrl, _path);
        } catch (exx) {}
        // 下载反面
        urlServer = "https://auod-bucket-01.oss-ap-southeast-2.aliyuncs.com/FileServer/pic";
        item = negativeServerUrl.replace(urlServer, "");
        urlServer = "https://auod-bucket-wms.oss-ap-southeast-2.aliyuncs.com";
        item = item.replace(urlServer, "");
        item = item.replace("?x-oss-process=style/600", "");
 
        filename = path.basename(item);
        _path = rootPath + path.dirname(item);
        negativeServerPath = _path + path.sep + filename;
        try {
          await this.downFile(filename, negativeServerUrl, _path);
        } catch (exx) {}
        //#endregion
 
        //#region 身份证识别
        // 正面图片
        if (!fs.existsSync(positiveServerPath)) {
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.remark = "正面照片不存在";
          return false;
        }
 
        let fi = fs.statSync(positiveServerPath);
        if (fi.size <= 0) {
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.remark = "正面照片不存在";
 
          try {
            this.ctx.helper.deldir(positiveServerPath);
          } catch (e) {}
          return false;
        }
 
        // 反面图片
        if (!fs.existsSync(negativeServerPath)) {
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.remark = "正面照片不存在";
          return false;
        }
 
        fi = fs.statSync(negativeServerPath);
        if (fi.size <= 0) {
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.remark = "反面照片不存在";
          return false;
        }
 
        let positiveInfo = await this.parseInfo(positiveServerPath, "front");
        let negativeInfo = await this.parseInfo(negativeServerPath, "back");
        let image_status1 = positiveInfo.image_status;
        let image_status2 = negativeInfo.image_status;
        if (image_status1 == "normal" && image_status2 == "normal") {
          let fullName = positiveInfo["words_result"]["姓名"].words;
          let _idCardCode = positiveInfo["words_result"]["公民身份号码"].words;
          let validityPeriod: string = negativeInfo["words_result"]["失效日期"].words;
          let periodState = "无效";
          let remark = "";
          let insert = (start, orginStr, insertStr) => {
            return orginStr.slice(0, start) + insertStr + orginStr.slice(start);
          };
          if (validityPeriod && validityPeriod.length == 8) {
            validityPeriod = insert(4, validityPeriod, "-");
            validityPeriod = insert(7, validityPeriod, "-");
            let validDate = moment(validityPeriod);
            if (validDate > moment(new Date())) {
              periodState = "有效";
              remark = "百度分析成功";
              if (idCardInfo.idCardCode != _idCardCode) {
                remark = "百度纠正身份证";
              }
              if (idCardInfo.fullName != fullName) {
                remark = "百度纠正姓名";
              }
            } else {
              remark = "已过期";
            }
          } else if (validityPeriod == "长期") {
            periodState = "有效";
            remark = "百度分析成功";
            if (idCardInfo.idCardCode != _idCardCode) {
              remark = "百度纠正身份证";
            }
            if (idCardInfo.fullName != fullName) {
              remark = "百度纠正姓名";
            }
          } else {
            remark = "非正确日期";
          }
          idCardInfo.fullName = fullName;
          idCardInfo.idCardCode = _idCardCode;
          idCardInfo.validityPeriod = validityPeriod;
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = periodState;
          idCardInfo.remark = remark;
        } else if (image_status1 != "normal") {
          let remark = "";
          switch (image_status1) {
            case "reversed_side":
              remark = "身份证正反面颠倒";
              break;
            case "non_idcard":
              remark = "上传的图片中不包含身份证";
              break;
            case "blurred":
              remark = "身份证模糊";
              break;
            case "other_type_card":
              remark = "其他类型证照";
              break;
            case "over_exposure":
              remark = "身份证关键字段反光或过曝";
              break;
            case "over_dark":
              remark = "身份证欠曝(亮度过低)";
              break;
            case "unknown":
              remark = "未知图片";
              break;
          }
          idCardInfo.remark = "反面" + remark;
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.validityPeriod = null;
        } else if (image_status2 != "normal") {
          let remark = "";
          switch (image_status2) {
            case "reversed_side":
              remark = "身份证正反面颠倒";
              break;
            case "non_idcard":
              remark = "上传的图片中不包含身份证";
              break;
            case "blurred":
              remark = "身份证模糊";
              break;
            case "other_type_card":
              remark = "其他类型证照";
              break;
            case "over_exposure":
              remark = "身份证关键字段反光或过曝";
              break;
            case "over_dark":
              remark = "身份证欠曝(亮度过低)";
              break;
            case "unknown":
              remark = "未知图片";
              break;
          }
          idCardInfo.remark = "反面" + remark;
          idCardInfo.provingState = "已验证";
          idCardInfo.periodState = "无效";
          idCardInfo.validityPeriod = null;
        }
 
        try {
          this.ctx.helper.deldir(positiveServerPath);
          this.ctx.helper.deldir(negativeServerPath);
        } catch (Exception) {}
 
        //#endregion
 
        return true;
      } else {
        idCardInfo.provingState = "已验证";
        idCardInfo.periodState = "无效";
        idCardInfo.remark = "图片不存在";
        return false;
      }
    } catch (ex) {
      idCardInfo.provingState = "已验证";
      idCardInfo.periodState = "无效";
      if (ex.message.indexOf("重复键值为") >= 0) {
        idCardInfo.remark = "分析出来的身份证号已经存在";
      } else {
        idCardInfo.remark = ex.message;
      }
      this.ctx.logger.info(positiveServerPath + "分析失败:" + ex.message);
      return false;
    }
  }
  //#endregion
 
  //#region Start 开始分析身份证
  /// <summary>
  /// 开始分析身份证
  /// </summary>
  /// <param name="this.body"></param>
  /// <returns></returns>
  public async start(pageIndex: number) {
    try {
      // 并行数
      // provingState = 验证状态
      //let where = "uploadTime IS NULL AND isnull(provingState, '待验证')='待验证' And idCard_Id%" + threadCount + "=" + pageIndex;
      let where = "uploadTime IS NULL AND isnull(provingState, '待验证')='待验证'";
      //where = "idCardCode in('140106198610201223', '320586199301012420')";
      let cardList = await this.dbRead
        .createQueryBuilder(TMSIdCard, "t")
        .where(where)
        .getMany();
      let startDate = moment(new Date());
      let index = 0;
      for (let item of cardList) {
        index++;
        this.ctx.logger.info("分组ID:" + pageIndex + ",开始执行:" + index);
        try {
          await this.singleAnalysis(item, this.info);
        } catch (exc) {
          await this.dbWrite.update(TMSIdCard, item.idCard_Id, {
            provingState: "已验证",
            periodState: "无效"
          });
          this.ctx.logger.info("分组ID:" + pageIndex + "," + item.idCardCode + " 分析失败:" + exc.message);
        }
      }
      let endDate = moment(new Date());
      let span = endDate.diff(startDate, "seconds");
 
      this.ctx.logger.info("分组ID:" + pageIndex + ",执行总时长:" + span);
      //删除目录
      let root = path.resolve();
      let rootPath = root + path.sep + "idCard" + path.sep;
      this.ctx.helper.deldir(rootPath);
      // 重新创建
      this.ctx.helper.mkdir(rootPath);
    } catch (ex) {
      this.ctx.logger.info("分析错误:" + ex.message);
    }
 
    return this.info;
  }
  //#endregion
 
  //#region addIdCard 上传身份证
  public async addIdCard() {
    let { ctx } = this;
    ctx.logger.info("上传身份证:" + JSON.stringify(this.body));
    let userInfo = await this.userInfo;
 
    // try {
    //   let db = app.mongodb;
    //   let collection = db.collection("addIdCard");
    //   //将数据保存至MongoDB
    //   await collection.insert(this.body);
    //   this.ctx.logger.info("上传身份证保存至MongoDB:成功");
    // } catch (ex) {
    //   this.ctx.logger.info("上传身份证保存至MongoDB错误:" + ex.message);
    // }
 
    try {
      //#region 数据验证
      if (this.body.endDate != "长期") {
        let endDate = moment(this.body.endDate);
        let now = moment(new Date());
        if (endDate <= now) {
          this.info.result = false;
          this.info.msg = "身份证已过期不允许上传";
          return this.info;
        }
      }
 
      if (!this.body.wayBillCode) {
        this.info.result = false;
        this.info.msg = "运单号不能为空";
        return this.info;
      }
      //#endregion
 
      //#region 上传到阿里云存储
      // 上传正面图片
      let orginPath = this.body.positiveServerUrl;
      let targetPath = "/Upload/Card/" + this.body.cardId + "_1" + path.extname(this.body.positiveServerUrl);
      this.info = await aliOSSCopy(ctx, orginPath, targetPath);
      if (!this.info.result) {
        return this.info;
      }
      this.body.positiveServerUrl = targetPath;
 
      // 上传反面图片
      let orginPath2 = this.body.negativeServerUrl;
      targetPath = "/Upload/Card/" + this.body.cardId + "_2" + path.extname(this.body.negativeServerUrl);
      this.info = await aliOSSCopy(ctx, orginPath2, targetPath);
      if (!this.info.result) {
        return this.info;
      }
      this.body.negativeServerUrl = targetPath;
      //#endregion
 
      //#region 运单处理
      let mobile = null;
      let wayBillCodes: Array<string> = this.body.wayBillCode.split(/,|;|、|;|,/gi).filter(item => item);
      for (let wayBillCode of wayBillCodes) {
        let _wayBillCode = wayBillCode.trim().toUpperCase();
        if (!_wayBillCode) {
          continue;
        }
 
        let _wayBill = await this.dbRead.findOne(TMSWayBill, {
          where: [
            {
              wayBillCode: _wayBillCode
            },
            {
              customerOrderNo: _wayBillCode
            }
          ]
        });
        if (_wayBill != null) {
          mobile = _wayBill.consigneeMobile;
        }
        // 在揽收查询中新建,将状态改为未揽收
        let receiveInfo = await this.dbRead.findOne(TMSWayBillReceive, {
          wayBillCode: _wayBillCode
        });
        if (!receiveInfo) {
          receiveInfo = new TMSWayBillReceive();
          receiveInfo.collectStatus = "未揽收";
          receiveInfo.consignor_Id = 0;
          receiveInfo.consignorCode = null;
          receiveInfo.consignorName = null;
          receiveInfo.createID = 0;
          receiveInfo.creator = this.body.creator ? this.body.creator : "client";
          receiveInfo.wayBillCode = _wayBillCode;
          receiveInfo.userTrueName = this.body.creator;
          receiveInfo.user_Id = 0;
          receiveInfo.consigneeIdcard = this.body.cardId;
          receiveInfo.consigneeName = this.body.userName;
          receiveInfo.consigneeDate = new Date();
          receiveInfo.userProduct_Id = 1007;
          receiveInfo.platUser_Id = 1;
          await this.dbWrite.insert(TMSWayBillReceive, receiveInfo);
        } else {
          receiveInfo.consigneeIdcard = this.body.cardId;
          receiveInfo.consigneeName = this.body.userName;
          receiveInfo.consigneeDate = new Date();
          receiveInfo.remark = this.body.creator + "修改";
          await this.dbWrite.update(TMSWayBillReceive, receiveInfo.wayBillReceive_Id, {
            consigneeIdcard: this.body.cardId,
            consigneeName: this.body.userName
          });
        }
      }
      //#endregion
 
      //#region 身份证处理
      let _IdCard = await this.dbRead.findOne(TMSIdCard, {
        idCardCode: this.body.cardId
      });
      if (!_IdCard) {
        _IdCard = new TMSIdCard();
        _IdCard.idCardType = "身份证";
        _IdCard.fullName = this.body.userName;
        _IdCard.idCardCode = this.body.cardId;
        _IdCard.validityPeriod = this.body.endDate;
        _IdCard.uploadTime = new Date();
        _IdCard.positiveServerUrl = this.body.positiveServerUrl;
        _IdCard.negativeServerUrl = this.body.negativeServerUrl;
        _IdCard.createID = 0;
        _IdCard.creator = this.body.creator;
        _IdCard.createDate = new Date();
        _IdCard.platUser_Id = 1;
        _IdCard.platUserCode = null;
        _IdCard.platUserName = null;
        _IdCard.platCorpName = null;
        _IdCard.userProduct_Id = 1007;
        _IdCard.userProductCode = null;
        _IdCard.userProductAlias = null;
        _IdCard.consignor_Id = 0;
        _IdCard.consignorCode = null;
        _IdCard.consignorName = null;
        _IdCard.mobile = mobile;
        _IdCard.periodState = "有效";
        _IdCard.provingState = "已验证";
        _IdCard.remark = "前端上传";
 
        if (userInfo.userType === "consignor") {
          _IdCard.consignorCode = userInfo.consignorCode;
          _IdCard.consignorName = userInfo.consignorName;
          _IdCard.consignor_Id = userInfo.consignor_Id;
        }
 
        await this.dbWrite.save(_IdCard);
      } else {
        _IdCard.fullName = this.body.userName;
        _IdCard.idCardCode = this.body.cardId;
        _IdCard.positiveServerUrl = this.body.positiveServerUrl;
        _IdCard.negativeServerUrl = this.body.negativeServerUrl;
        _IdCard.periodState = "有效";
        _IdCard.provingState = "已验证";
        _IdCard.validityPeriod = this.body.endDate;
        _IdCard.uploadTime = new Date();
        _IdCard.userProduct_Id = 1007;
        _IdCard.remark = "前端上传";
        _IdCard.creator = this.body.creator;
 
        if (!_IdCard.mobile) {
          _IdCard.mobile = mobile;
        } else if (_IdCard.mobile != mobile) {
          if (!_IdCard.mobile2) {
            _IdCard.mobile2 = mobile;
          } else if (!_IdCard.mobile2 != mobile) {
            if (!_IdCard.mobile3) {
              _IdCard.mobile3 = mobile;
            }
          }
        }
        await this.dbWrite.save(_IdCard);
      }
      //#endregion
 
      //#region 轨迹处理
      if (_IdCard && _IdCard.idCard_Id > 0) {
        for (let wayBillCode of wayBillCodes) {
          let _wayBillCode = wayBillCode.trim().toUpperCase();
          if (!_wayBillCode) {
            continue;
          }
 
          let _wayBill = await this.dbRead.findOne(TMSWayBill, {
            where: [
              {
                wayBillCode: _wayBillCode
              },
              {
                customerOrderNo: _wayBillCode
              }
            ]
          });
 
          if (_wayBill != null) {
            //添加运单追踪记录
            await ctx.service.tms.wayBillHelper.setStatusHistory(
              _wayBill,
              "身份证上传",
              "身份证上传",
              "身份信息已收录",
              "上传匹配"
            );
 
            await this.dbWrite.update(TMSWayBill, _wayBill.wayBill_Id, {
              consigneeIdcard: this.body.cardId,
              consigneeName: this.body.userName
            });
          } else {
            let wb = new TMSWayBill();
            wb.wayBill_Id = 0;
            wb.wayBillCode = _wayBillCode;
            wb.orderStatus = null;
            //添加运单追踪记录
            await ctx.service.tms.wayBillHelper.setStatusHistory(
              wb,
              "身份证上传",
              "身份证上传",
              "身份信息已收录",
              "上传匹配"
            );
          }
        }
      }
      //#endregion
 
      // 删除临时文件
      await aliOSSDelete(ctx, orginPath);
      // 删除临时文件
      await aliOSSDelete(ctx, orginPath2);
 
      this.info.result = true;
      this.info.msg = "身份证上传成功";
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
    return this.info;
  }
  //#endregion
}