| 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 | 
| } |