我可以看到三个主要选项,其中两个我会在这里考虑。主要原因是,由于成本原因,我没有使用 Inline Javascript 操作,因为它需要一个集成帐户,这将比以下任一选项产生更多的成本。
先决条件
触发应该是每天重复一次。它仍然需要运行,只是它是否做任何事情。没有办法摆脱它。
用当前日期初始化String 类型的变量。我已经包含了一个公式,它采用 UTC 并将其转换为您的本地时区,您只需要相应地更改它。
convertTimeZone(utcNow(), 'UTC', 'AUS Eastern Standard Time')
选项 1 - Azure 函数
到目前为止,Azure 函数是最简单的方法。创建一个 .NET 函数应用程序(或任何您熟悉的语言,但您将无法使用下面的代码),然后使用以下代码创建一个函数,名为 GetBusinessDayOfMonthForDate ...
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
DateTime dateToProcess = DateTime.Parse(req.Query["Date"]);
int businessDayCount = 0;
var tempDate = dateToProcess;
while (tempDate.Month == dateToProcess.Month)
{
businessDayCount += (tempDate.DayOfWeek.ToString().Substring(0, 1) != "S") ? 1 : 0;
tempDate = tempDate.AddDays(-1);
}
return new OkObjectResult(businessDayCount.ToString());
}
现在在上一个操作之后直接从逻辑应用调用它...
选项 2 - 标准操作
这种方法的基本前提与 Azure Function 相同,但自然要冗长得多。
这是该方法的 JSON 定义,它包括您在自己的环境中测试它所需的一切。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Condition": {
"actions": {},
"else": {
"actions": {
"Terminate": {
"inputs": {
"runStatus": "Cancelled"
},
"runAfter": {},
"type": "Terminate"
}
}
},
"expression": {
"and": [
{
"equals": [
"@variables('Business Days Up to Today')",
3
]
}
]
},
"runAfter": {
"Until_Day_Index_=_-5": [
"Succeeded"
]
},
"type": "If"
},
"Initialize_Business_Days_Up_to_Today": {
"inputs": {
"variables": [
{
"name": "Business Days Up to Today",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Initialize_Temp_Date": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Current_Date": {
"inputs": {
"variables": [
{
"name": "Current Date",
"type": "string",
"value": "@{convertTimeZone(utcNow(), 'UTC', 'AUS Eastern Standard Time')}"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Day_Index": {
"inputs": {
"variables": [
{
"name": "Day Index",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Initialize_Business_Days_Up_to_Today": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Temp_Date": {
"inputs": {
"variables": [
{
"name": "Temp Date",
"type": "string",
"value": "@variables('Current Date')"
}
]
},
"runAfter": {
"Initialize_Current_Date": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Until_Day_Index_=_-5": {
"actions": {
"Decrement_Current_Date": {
"inputs": {
"name": "Temp Date",
"value": "@{addDays(variables('Current Date'), variables('Day Index'))}"
},
"runAfter": {},
"type": "SetVariable"
},
"Decrement_Day_Index": {
"inputs": {
"name": "Day Index",
"value": 1
},
"runAfter": {
"Increment_variable": [
"Succeeded"
]
},
"type": "DecrementVariable"
},
"Increment_variable": {
"inputs": {
"name": "Business Days Up to Today",
"value": "@if(and(greaterOrEquals(dayOfWeek(variables('Temp Date')), 1), lessOrEquals(dayOfWeek(variables('Temp Date')), 6)), 1, 0)"
},
"runAfter": {
"Decrement_Current_Date": [
"Succeeded"
]
},
"type": "IncrementVariable"
}
},
"expression": "@equals(variables('Day Index'), -5)",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_Day_Index": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Day",
"interval": 1,
"timeZone": "AUS Eastern Standard Time"
},
"recurrence": {
"frequency": "Day",
"interval": 1,
"timeZone": "AUS Eastern Standard Time"
},
"type": "Recurrence"
}
}
},
"parameters": {}
}
在所有这些的基础上,输入一个条件来检查当前工作日变量是否等于 3,如果是,则运行您的逻辑。
这包含在上面的 JSON 定义中。
其中一种方法是我正在做的,所以我希望能回答你的问题。