簡體   English   中英

Mule 3.8.4 中的 for 循環 | 數據編織 1.0

[英]for loops in Mule 3.8.4 | Dataweave 1.0

我需要對傳入的有效負載字符串與緩存中的現有產品名稱列表進行字符串比較,因為不會有完全匹配,首先我需要從傳入的有效負載字符串中刪除最后 3 個字符並與所有字符進行比較現有的字符串/產品名稱。 如果我找到匹配項,則進行其他轉換。 否則從傳入的有效負載字符串中再刪除一個字符並再次比較。 我需要重復此操作,直到傳入有效負載的字符串大小為 =3(如果字符串大小小於 3,則無需比較)

總結:我需要從右到左刪除字符並進行字符串比較

輸入有效載荷如下:

{
  "productPartNo": "MPN-400110",
  "supplier": "70058",
  "productCode": "02",
}

需要將字符串“productPartNo”與下面現有產品列表中的“partNumber”字段進行比較

{
  "Product": [
    {
      "productNumber": "420475",
      "created": "2012-10-28",
      "partNumber": "C1F2PNEX71K9",
      "codeNo": "7712",
      "manufacturer": ""
    },
    {
      "productNumber": "478376",
      "created": "2017-12-12",
      "partNumber": "N77-C77-RMK=",
      "codeNo": "1589",
      "manufacturer": "50884"
    },
    {
      "productNumber": "478381",
      "created": "2017-12-12",
      "partNumber": "CON-U-C1F2PXNE",
      "codeNo": "1586",
      "manufacturer": "50884"
    },
    {
      "productNumber": "478384",
      "created": "2017-12-12",
      "partNumber": "PMPN4070",
      "codeNo": "1585",
      "manufacturer": "50884"
    }
 ]
}

在這種情況下,我的輸入字符串 "productPartNo": "MPN-400110" 應該與所有 PartNumber 進行比較。 從最后刪除字符后,字符串 'MPN' 將與“partNumber”匹配/包含:“PMPN4070”,因此我應該得到與 partNumber-PMPN4070 關聯的“codeNo”:“1585”作為我的輸出字段。

我如何在 %dw 1.0 中實現這個邏輯

這需要一點思考,而且它很晚,沒有多少腦力了,早上我可能會修改,但鑒於您的樣本數據,這是一個好的開始。 如果您有任何進一步的說明,請告訴我。

只需復制並粘貼到Transform Message處理器中,然后打開預覽即可。

%dw 1.0
%output application/dw

%var products = {
  "Product": [
    {
      "productNumber": "420475",
      "created": "2012-10-28",
      "partNumber": "C1F2PNEX71K9",
      "codeNo": "7712",
      "manufacturer": ""
    },
    {
      "productNumber": "478376",
      "created": "2017-12-12",
      "partNumber": "N77-C77-RMK=",
      "codeNo": "1589",
      "manufacturer": "50884"
    },
    {
      "productNumber": "478381",
      "created": "2017-12-12",
      "partNumber": "CON-U-C1F2PXNE",
      "codeNo": "1586",
      "manufacturer": "50884"
    },
    {
      "productNumber": "478384",
      "created": "2017-12-12",
      "partNumber": "PMPN4070",
      "codeNo": "1585",
      "manufacturer": "50884"
    }
 ]
}


%var inputPayload = {
  "productPartNo": "MPN-400110",
  "supplier": "70058",
  "productCode": "02"
}
---
// Get a list with all the substrings to search with--this give you the following array
// ["MPN-400","MPN-40","MPN-4","MPN-","MPN"]
(4 to (sizeOf inputPayload.productPartNo ) - 2 map inputPayload.productPartNo[0 to -$]
map (
    // Filter the list of products on the substring, 
    // this should either give you a matches or the empty list
    // Finally, take the first match.  I am not sure if this what you want.
    (products.Product filter (e) -> (e.partNumber contains $))[0]
) 
filter ($ != null))[0].codeNo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM