PRIORITY P0 ‧ GoFreight ↔ LDS BACKEND ‧ TRADE PARTNER SYNC

P0GF ↔ LDS Trade Partner Master Mapping — Spec / Flow / Design

由 GoFreight 發動:當 LDS 缺少對應 Trade Partner(company / importer / shipper)時,以 GF 資料為基礎在 LDS 自動建檔,並帶入 Customs Entry。全程寫 log,並有獨立稽核頁。本文件含對應規格、流程圖、欄位對應、缺漏候補欄位、日誌規格與頁面設計。

目錄

A. 目的與整合方向

GoFreight 使用者在建立 Customs Entry 時需要選用 Trade Partner(IOR / consignee / shipper 等)。若該 TP 在 LDS 報關後端尚未存在,系統需由 GF 發動、以 GF 既有資料為基礎,在 LDS 建立對應 Contact(必要時送 CBP 5106 建立 importer),再帶回 Customs Entry。

方向(單向、GF 主動):GoFreight 為 source of truth → 推送 / 建立 → LDS。本期不處理 LDS→GF 回寫主檔(僅回寫 LDS Code / 狀態供關聯)。主要對象:company、importer、shipper

觸發情境

  1. GF user 在 Customs Entry 指定某 TP。
  2. 系統先在 LDS 查找相同 TP(見 C 匹配策略)。
  3. 找不到 → 發動在 LDS 建立 Contact(+ 視需要 5106 importer)。
  4. 建立成功 → 帶入 Customs Entry(Importer_Id / Consignee_Id / Seller_Id)。
  5. 每一步都寫 log,並於獨立稽核頁可查。

B. 兩端實體模型

GoFreight(來源)

api.gofreight.com bundle 觀察:TP 以 reference 表示,公開結構精簡。

  • TP 物件:trade_partner { ref, name, uri }(只有三欄)
  • 角色以 booking 上的 *_ref 表示:customer_refactual_shipper_refconsignee_refcustoms_broker_refbill_to_refnotify_ref
  • 文件上傳:POST /documents/trade-partner/{ref}
  • importer_ref稅號/IRS、地址、電話 email、角色 flag(公開 bundle 內 NOT FOUND)
關鍵限制:公開 bundle 的 TP 僅 ref / name / uri。建立 LDS importer 所需的 IRS、地址等需另一個 GF TP 詳細 endpoint(不在此 bundle)。見 F「候補欄位」。

LDS(目標)

TP = 單一 Contact 物件,角色用 flag;importer 另以 5106 建到 CBP。

  • 類別:Contact : EntityDirectory / IContactManager
  • 身分鍵:IdCode(req,自動)、ExternalId(可存 GF ref)、IRSNumberCBPNumberSocialSecurityNumber+DateOfBirthDUNS
  • 角色 flag:RolesIsImporter / RolesIsShipper / RolesIsSeller / RolesIsManufacturer … RolesIsConsignee — consignee 由文件 FK 表示)
  • 地址:mailing(Adress1..3, AdressType, City, State, ZIP, Country);business 在 Contact.Ext
  • 5106:Contact.ExtImporterType + CBPF5106_*,送 ActionQUE.ImporterConsigneeCreate
注意:LDS 無 Shipment.Shipper 欄位 — shipper 角色於文件層用 Seller(+ Consolidator);Contact.RolesIsShipper flag 仍可標記。

C. TP 對應策略(匹配鍵)

依需求:importer 由 IRS No. 對應;其他 TP 由 ID 對應。落地到 LDS 的查找順序:

順序對象匹配鍵LDS 方法說明
1ImporterIRS No.(或 CBP No / SSN+DOB)GetByNumber(irs) / GetByCandidate先用標準 Customs 格式查;IsIRSNumber()/IsCBPNumber() 先分類
2其他 TP(shipper/consignee/customer…)GF TP ref(ID)GetByExternalId(gf_ref)(建議把 GF ref 存 LDS Contact.ExternalIdID 對應:GF ref ↔ LDS ExternalId
3任意LDS CodeGetByCode(code)已知 LDS code 時
4fallbackName + Address(fuzzy)GetByCandidate(candidate) / GetByName(name,Contains)避免重複建檔;需人工確認
對應持久化:建議在 GF 端維護一張 TP 對應表(GF ref ↔ LDS Code / Id / IRSNumber),並把 GF ref 同步寫入 LDS Contact.ExternalId,雙向可追。importer 以 IRS 為主鍵、其餘以 GF ref 為主鍵。

D. Flow Chart — GF 發動:查無 → 建檔 → 帶入 Entry(全程 log)

GoFreight LDS backend Audit Log ① user 建 Customs Entry指定 TP(IOR/cnee/shipper) ② 取 TP 識別IRS(importer)/ GF ref 查找請求 ③ LDS 查找 ContactGetByNumber / ExternalId / Candidate 找到? 已存在 → 取 LDS Id/Code直接使用 ④ GF 發動建檔(LDS)New → set 欄位 → Save 是 importer? 需 5106 ⑤ 送 5106ImporterConsigneeCreate ⑥ 帶入 Customs EntryImporter_Id / Consignee_Id / Seller_Id 否(非 importer)/ 完成後 每步寫 log time / user action(lookup/create/ 5106/link/file) tp name / code / type IRS / GF ref / LDS Id status / 結果 → 獨立稽核頁
紅色虛線=每個動作都寫入統一稽核 log(包含先前規劃的 customs filing 發動)。⑤ 5106 為非同步(PutToQUEOneWay),以 ABITransmission 關聯回填狀態。

E. Field Mapping(GF → LDS Contact)

M 必填(LDS Save)C 5106 必要O 選填
GF 來源LDS Contact 屬性必填CBP 5106說明 / 對應規則
trade_partner.refContact.ExternalId建議ID 對應主鍵(GF ref ↔ LDS ExternalId)
trade_partner.nameContact.NameMName≤35 字;超長拆 SecondName
(自動)Contact.CodeM未給則 GenerateCode() 自動產生
角色(依 booking *_ref)RolesIsImporter / RolesIsShipper / RolesIsSeller …Ocustomer/actual_shipper/… → 對應 flag
IRS / EIN ✱缺Contact.IRSNumberCImporter No. (EI)importer 對應主鍵;格式 NN-NNNNNNNXX
SSN + DOB ✱缺SocialSecurityNumber + DateOfBirthCImporter No. (SSN)個人 importer 替代
CBP No ✱缺Contact.CBPNumberOCBP Assigned僅更新用;無 SSN 可申請
地址(街/市/州/郵/國)✱缺Adress1 / City / State / ZIP / CountryCMailing Address5106 必要
地址類型 ✱缺AdressType(+Explanation)CAddress Type5106 必要(Has Possible Values)
實體營業地址 ✱缺Ext.BusinessAddress1 / BusinessAddressType …OPhysical Address有填則 BusinessAddressType 必填
Importer 類型 ✱缺Ext.ImporterTypeCImporter Type5106 必要(1 碼)
電話/Email ✱缺Phone / EmailO
DUNS ✱缺Contact.DUNSODUNS
MID(製造商)✱缺ManufacturerSupplierCodeOshipper/manufacturer 用

帶入 Customs Entry 的關聯

角色LDS 文件屬性說明
Importer of RecordCustomsEntry.Importer_Id必填;ABI 取號順序 IRS→CBP→SSN
ConsigneeShipment.Consignee_Id
Shipper / SellerShipment.Seller_Id(+ Consolidator)LDS 無 Shipment.Shipper,用 Seller
Buyer / ShipToShipment.Buyer_Id / ShipTo_Id

✱缺 = 在 GF 公開 bundle 的 TP 物件中找不到,需 GF 提供 TP 詳細 endpoint 才能取得(見 F)。

F. 候補欄位 — GF TP API 缺漏(建立 LDS importer 必要)

核心結論:GF 公開 bundle 的 Trade Partner 僅 ref / name / uri。要在 LDS 建立可用的 importer(5106)與完整 Contact,GF 需補以下欄位(建議於 TP 詳細 endpoint 提供)。下表為候補清單,標注 LDS 對應與必要性。
#GF 需補欄位(建議名)對應 LDS建 importer 必要性備註
1irs_no / einContact.IRSNumber必要importer 主鍵;NN-NNNNNNNXX,後兩碼不可 O/I/Z
2importer_no_type(EI/SSN/CBP)Ext.ImporterType + 號碼欄位必要決定用哪個號碼
3ssn + date_of_birthSocialSecurityNumber + DateOfBirth替代個人 importer
4cbp_noContact.CBPNumber更新用無 SSN 可申請 CBP-assigned
5mailing_address {line1,line2,city,state,zip,country}Adress1..3, City, State, ZIP, Country必要5106 mailing
6address_typeAdressType (+Explanation)必要5106 必填(代碼)
7physical_address {…} + physical_address_typeExt.BusinessAddress* / BusinessAddressType條件有實體地址則類型必填
8legal_name / dbaFullLegalName / SecondName建議name ≤35,法定名另存
9phone / email / faxPhone / Email / Fax聯絡
10dunsContact.DUNS
11mid_code(製造商)ManufacturerSupplierCodeshipper/manufacturer
12program_codes[]Ext.CBPF5106_ProgramCode1..45106 program(代碼)
13owner_officer {name,title}Ext.CBPF5106_Person1/Title負責人/officer
14roles[](importer/shipper/consignee/…)RolesIs* flags建議明確標記角色,免靠 booking 推斷
建議:GF 新增一個 TP 詳細查詢 endpoint(如 GET /trade-partners/{ref})回傳上述欄位;至少 #1、#2、#5、#6、#8、#14 應補齊,才能無人工介入完成 LDS importer 自動建檔。未補齊前,系統需在建檔精靈中提示人工補欄位並記錄缺漏。另:ImporterType / AdressType / Country / ProgramCode 的代碼值清單來自 CBP CATAIR,需建對照表。

G. Logging 規格(統一稽核日誌)

所有操作都寫入統一稽核日誌——包含 TP 查找、TP 建檔、5106 送件、帶入 entry,以及先前規劃的 customs filing 發動(calc/validate/QUE/收到 CBP 回覆)。

Log 紀錄結構(建議 schema)

TpSyncAuditLog { log_id // 流水號 timestamp // 動作時間(UTC + 顯示時區) user // GF 操作者(email / id) action // TP_LOOKUP | TP_CREATE_LDS | IMPORTER_5106 | // LINK_TO_ENTRY | CUSTOMS_FILE_QUE | CBP_RESPONSE | ... tp_name // TP 名稱 tp_code // LDS Contact.Code(建立後) tp_type / role // importer / shipper / consignee / customer ... gf_ref // GF trade_partner.ref(ID 對應) irs_no // importer 對應鍵(遮罩顯示) lds_contact_id // LDS Contact.Id entry_no // 關聯 Customs Entry(如適用) abi_transmission // 5106 / filing 的 ABITransmission id(非同步關聯) status // SUCCESS | PENDING | FAILED detail / message // 結果說明 / 錯誤碼 source_link // "Contact={id}" / "CustomsEntry={id}" }

記錄規則

H. 獨立稽核頁設計

提供一頁獨立頁面:紀錄 GF 自動在 LDS 新建了哪些 company / TP,歷程含時間、使用者、TP name、code、type(及狀態、IRS/GF ref、關聯 entry)。可篩選、可看明細。

LDS TP Auto-Create — Audit Log(獨立頁)
🔍 搜尋 TP / IRS / ref Type: All ▾ Action: TP_CREATE_LDS ▾ Date: 30d ▾ Export CSV
TimeUserTP NameLDS CodeTypeIRS / GF refStatus
06-19 10:21brad.fanPACIFIC TRADING LLCPACTRAD01Importer95-•••• / TP-1Created+5106
06-19 10:24brad.fanSHANGHAI APPAREL MFGSHGAPP02Shipper/MFR— / TP-204Created
06-19 10:25brad.fanJ SMITH (TX)Consignee— / TP-810Pending(欄位缺)
點任一列 → 明細抽屜:完整歷程、欄位值、ABITransmission、關聯 Customs Entry、錯誤/缺漏欄位。
互動版頁面:TP_Sync_Audit_Log.html(可點擊篩選 / 明細抽屜 / 缺漏欄位提示)。

I. Acceptance Criteria 與風險

Acceptance Criteria

  1. 建 Customs Entry 指定 TP 時,系統自動於 LDS 查找:importer 用 IRS(GetByNumber),其他用 GF ref(ExternalId);找到則直接用。
  2. 查無時,GF 發動以 GF 資料 New→Save 建 LDS Contact;importer 另送 ImporterConsigneeCreate(5106)。
  3. 建檔成功後,GF ref 寫入 LDS ExternalId,並把 Contact.Id 帶入 CustomsEntry.Importer_Id / Shipment.Consignee_Id/Seller_Id
  4. 若 GF 缺必要欄位(IRS/地址/ImporterType…),系統阻擋自動 5106,提示人工補欄位,並記 PENDING + 缺漏清單。
  5. 每一步寫稽核 log(含 customs filing 發動);非同步動作以 ABITransmission 關聯回填狀態。
  6. 獨立稽核頁可依 time/user/type/action/狀態篩選,顯示 TP name/code/type、IRS/GF ref、狀態,並可匯出。
  7. 重複建檔防呆:建立前必跑 GetByCandidate 比對,疑似重複需人工確認。

風險

風險對策
GF TP 缺 IRS/地址等(公開 bundle 無)請 GF 提供 TP 詳細 endpoint(F 候補欄位);未補前人工補欄並記錄
重複建檔GetByCandidate + ExternalId 去重;對應表單一來源
5106 非同步失敗PENDING 狀態 + 重試 + 反序列化 EntryValidationFault 顯示原因
代碼值(ImporterType/AddressType…)建 CBP CATAIR 對照表,隨規格更新
敏感資料(IRS/SSN)遮罩顯示、加密儲存、存取稽核