Azure LogicApps:从字符串到浮点的转换返回零

问题描述 投票:0回答:1

我很惊讶地看到这一点,但是我看到在某些情况下,字符串值没有按预期的浮点数转换;大部分返回零。

下图显示了会发生什么。如您所见,在我的逻辑应用程序中,我有2个变量,即类型为var_MarginStrstring和类型为var_MarginValuesfloat。我按以下方式分配var_MarginVal

var_MarginVal = float(string(variables('var_MarginStr')))

enter image description here

enter image description here

[在将新的Blob插入Blob存储帐户后,在触发我的逻辑应用的工作中。 Blob的content(*。csv)传递给Azure函数,该函数返回JSON对象。然后,JSON对象将遍历每个项目,并通过存储过程发送到我的数据库。

我已经检查了Azure函数,它将内容完美地转换为JSON,并且这样的响应是:

{
  "fileName": "20200307-PLC-JKB-Margin.csv",
  "agentName": "PLC",
  "noOfRecords": 5,
  "data": [
    {
      "accountId": "JKB1234LC",
      "marginValue": "0.00"
    },
    {
      "accountId": "JKB4321LC",
      "marginValue": "1200000.00"
    },
    {
      "accountId": "JKB5678LC",
      "marginValue": "6000000.00"
    },
    {
      "accountId": "JKB8765LC",
      "marginValue": "4000000.00"
    },
    {
      "accountId": "JKB9123LC",
      "marginValue": "0.00"
    }
  ]
}

这是我的整个LogicApp:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "CSVTOJSON": {
                "inputs": {
                    "body": "@body('Get_blob_content')",
                    "function": {
                        "id": "/subscriptions/xxxx/resourceGroups/xxxx-PRD-PORTAL-01/providers/Microsoft.Web/sites/jksbmarginrequest/functions/CSVTOJSON"
                    },
                    "method": "POST",
                    "queries": {
                        "fileName": "@triggerBody()?['Name']"
                    }
                },
                "runAfter": {
                    "[Initialize]_For_Composed_AccountId": [
                        "Succeeded"
                    ]
                },
                "type": "Function"
            },
            "Condition": {
                "actions": {
                    "Apply_to_DB": {
                        "actions": {
                            "Execute_stored_procedure_(V2)": {
                                "inputs": {
                                    "body": {
                                        "pActualAccountId": "@{items('Apply_to_DB')?['accountId']}@{variables('var_ComposeAccountIdSuffix')}",
                                        "pAgentId": "@variables('var_AgentName')",
                                        "pEffectiveDate": "@{formatDateTime(utcNow(),'yyyy-MM-dd')}",
                                        "pMarginVal": "@variables('var_MarginVal')"
                                    },
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['sql']['connectionId']"
                                        }
                                    },
                                    "method": "post",
                                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/procedures/@{encodeURIComponent(encodeURIComponent('[dbo].[usp_MarginAddUpdate]'))}"
                                },
                                "runAfter": {
                                    "[Set]_Margin_Value_Float": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "ApiConnection"
                            },
                            "[Set]_Margin_Value_Float": {
                                "inputs": {
                                    "name": "var_MarginVal",
                                    "value": "@float(string(variables('var_MarginStr')))"
                                },
                                "runAfter": {
                                    "[Set]_Margin_Value_String": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "SetVariable"
                            },
                            "[Set]_Margin_Value_String": {
                                "inputs": {
                                    "name": "var_MarginStr",
                                    "value": "@items('Apply_to_DB')?['marginValue']"
                                },
                                "runAfter": {},
                                "type": "SetVariable"
                            }
                        },
                        "foreach": "@body('Parse_JSON')?['data']",
                        "runAfter": {
                            "For_each": [
                                "Succeeded"
                            ]
                        },
                        "type": "Foreach"
                    },
                    "Create_HTML_table": {
                        "inputs": {
                            "format": "HTML",
                            "from": "@body('Parse_JSON')?['data']"
                        },
                        "runAfter": {
                            "Apply_to_DB": [
                                "Succeeded"
                            ]
                        },
                        "type": "Table"
                    },
                    "Execute_a_SQL_query_(V2)": {
                        "inputs": {
                            "body": {
                                "actualParameters": {
                                    "pAgentId": "@variables('var_AgentName')"
                                },
                                "formalParameters": {
                                    "pAgentId": "VARCHAR(10)"
                                },
                                "query": "select * from [dbo].[Parser_MarginFileSettings]\nWhere AgentId =@pAgentId"
                            },
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['sql']['connectionId']"
                                }
                            },
                            "method": "post",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('default'))},@{encodeURIComponent(encodeURIComponent('default'))}/query/sql"
                        },
                        "runAfter": {
                            "[Set]_Agent_Name": [
                                "Succeeded"
                            ]
                        },
                        "type": "ApiConnection"
                    },
                    "For_each": {
                        "actions": {
                            "[Set]_Composed_Account_ID_with_Suffix": {
                                "inputs": {
                                    "name": "var_ComposeAccountIdSuffix",
                                    "value": "@items('For_each')?['Suffix_AccountId']"
                                },
                                "runAfter": {},
                                "type": "SetVariable"
                            }
                        },
                        "foreach": "@body('Execute_a_SQL_query_(V2)')?['resultsets']?['Table1']",
                        "runAfter": {
                            "Execute_a_SQL_query_(V2)": [
                                "Succeeded"
                            ]
                        },
                        "type": "Foreach"
                    },
                    "Parse_JSON": {
                        "inputs": {
                            "content": "@body('CSVTOJSON')",
                            "schema": {
                                "properties": {
                                    "agentName": {
                                        "type": "string"
                                    },
                                    "data": {
                                        "items": {
                                            "properties": {
                                                "accountId": {
                                                    "type": "string"
                                                },
                                                "marginValue": {
                                                    "type": "string"
                                                }
                                            },
                                            "required": [
                                                "accountId",
                                                "marginValue"
                                            ],
                                            "type": "object"
                                        },
                                        "type": "array"
                                    },
                                    "fileName": {
                                        "type": "string"
                                    },
                                    "noOfRecords": {
                                        "type": "integer"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "runAfter": {},
                        "type": "ParseJson"
                    },
                    "[Set]_Agent_Name": {
                        "inputs": {
                            "name": "var_AgentName",
                            "value": "@body('Parse_JSON')?['agentName']"
                        },
                        "runAfter": {
                            "Parse_JSON": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    }
                },
                "else": {
                    "actions": {
                        "Compose_Fail-over_Data": {
                            "inputs": {
                                "File_Name": "@triggerBody()?['Name']",
                                "Message": "@body('CSVTOJSON')",
                                "Status_Code": "@outputs('CSVTOJSON')['statusCode']"
                            },
                            "runAfter": {},
                            "type": "Compose"
                        },
                        "For_Error_Listing": {
                            "inputs": {
                                "format": "HTML",
                                "from": "@outputs('Compose_Fail-over_Data')"
                            },
                            "runAfter": {
                                "Compose_Fail-over_Data": [
                                    "Succeeded"
                                ]
                            },
                            "type": "Table"
                        },
                        "Send_an_email_(V2)": {
                            "inputs": {
                                "body": {
                                    "Body": "<p><u><strong>An Error Occured While Updating Margin Request File<br>\n<br>\n</strong></u><u><strong>@{outputs('Compose_Fail-over_Data')}</strong></u><u><strong></strong></u><br>\n</p>",
                                    "Subject": "Margin File Output",
                                    "To": "[email protected]"
                                },
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['office365']['connectionId']"
                                    }
                                },
                                "method": "post",
                                "path": "/v2/Mail"
                            },
                            "runAfter": {
                                "For_Error_Listing": [
                                    "Succeeded"
                                ]
                            },
                            "type": "ApiConnection"
                        }
                    }
                },
                "expression": {
                    "and": [
                        {
                            "equals": [
                                "@outputs('CSVTOJSON')['statusCode']",
                                200
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "CSVTOJSON": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Get_blob_content": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Path']))}/content",
                    "queries": {
                        "inferContentType": true
                    }
                },
                "runAfter": {},
                "runtimeConfiguration": {
                    "staticResult": {
                        "name": "Get_blob_content0",
                        "staticResultOptions": "Disabled"
                    }
                },
                "type": "ApiConnection"
            },
            "[Initialize]_Agent_Name": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var_AgentName",
                            "type": "string",
                            "value": "PLC"
                        }
                    ]
                },
                "runAfter": {
                    "Get_blob_content": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "[Initialize]_For_Composed_AccountId": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var_ComposeAccountIdSuffix",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "[Initialize]_For_Margin_Value_FLoat": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "[Initialize]_For_Margin_Value_FLoat": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var_MarginVal",
                            "type": "float",
                            "value": 0
                        }
                    ]
                },
                "runAfter": {
                    "[Initialize]_Margin_Value_String": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "[Initialize]_Margin_Value_String": {
                "inputs": {
                    "variables": [
                        {
                            "name": "var_MarginStr",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "[Initialize]_Agent_Name": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "staticResults": {
            "Get_blob_content0": {
                "outputs": {
                    "headers": {},
                    "statusCode": "OK"
                },
                "status": "Succeeded"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/triggers/batch/onupdatedfile",
                    "queries": {
                        "folderId": "JTJmcGxj",
                        "maxFileCount": 1
                    }
                },
                "metadata": {
                    "JTJmcGxj": "/plc"
                },
                "recurrence": {
                    "frequency": "Second",
                    "interval": 3
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/xxxx/resourceGroups/xxx-PRD-PORTAL-01/providers/Microsoft.Web/connections/azureblob-2",
                    "connectionName": "azureblob-2",
                    "id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/southeastasia/managedApis/azureblob"
                },
                "office365": {
                    "connectionId": "/subscriptions/xxxx/resourceGroups/xxx-PRD-PORTAL-01/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/southeastasia/managedApis/office365"
                },
                "sql": {
                    "connectionId": "/subscriptions/xxxx/resourceGroups/xxx-PRD-PORTAL-01/providers/Microsoft.Web/connections/sql-6",
                    "connectionName": "sql-6",
                    "id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/southeastasia/managedApis/sql"
                }
            }
        }
    }
}
azure azure-logic-apps data-conversion
1个回答
1
投票

默认情况下,当For For Each运行时,它会同时运行迭代。不能保证变量使用当前迭代的值。如果将For Each更改为按顺序运行,它将与变量一起使用。在“对于每个设置”中,打开“并发控制”并将“并行度”设置为1。如果希望并行运行,则另一个选择是删除循环中变量的使用。

此页上的[Microsoft循环文档https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-control-flow-loops说]

为了从每个变量的操作中获得可预测的结果循环迭代,依次运行这些循环。例如,当同时运行的循环结束,增加,减少和追加变量操作返回可预测的结果。但是,在并发运行循环中的每次迭代,这些操作可能会返回不可预测的结果。

© www.soinside.com 2019 - 2024. All rights reserved.