CrazyIter_Bin 11 hónapja
szülő
commit
24db3ef605

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 2030 - 4
TEAMModelOS.Function/IESServiceBusTrigger.cs


+ 83 - 5
TEAMModelOS.Function/IESTimerTrigger.cs

@@ -1,23 +1,101 @@
 using System;
+using DinkToPdf.Contracts;
 using Microsoft.Azure.Functions.Worker;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Extension;
 
 namespace TEAMModelOS.Function
 {
     public class IESTimerTrigger
     {
         private readonly ILogger _logger;
-
-        public IESTimerTrigger(ILoggerFactory loggerFactory)
+        /// <summary>
+        /// 文档。https://docs.microsoft.com/zh-cn/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp
+        /// Timer 在线测试  https://ncrontab.swimburger.net/
+        /// </summary>
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureRedisFactory _azureRedis;
+        //private readonly IConverter _converter;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly IHttpClientFactory _httpClient;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
+        //private IPSearcher _ipSearcher;
+        private readonly IConfiguration _configuration;
+        public IESTimerTrigger(ILoggerFactory loggerFactory, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClient, SnowflakeId snowflakeId,   AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
         {
             _logger = loggerFactory.CreateLogger<IESTimerTrigger>();
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _azureStorage = azureStorage;
+            _azureRedis = azureRedis;
+          //  _converter = converter;
+            _snowflakeId=snowflakeId;
+            _httpClient = httpClient;
+            //  _ipSearcher = ipSearcher;
+            _coreAPIHttpService = coreAPIHttpService;
+            _configuration= configuration;
         }
 
-        [Function("IESTimerTrigger")]
-        public void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
+
+
+        /// <summary>
+        /// //0 1 * * * * 一天中每小时的第 1 分钟
+        ///0 */10 * * * *  每五分钟一次
+        /// </summary>
+        /// <param name="myTimer"></param>
+        /// <returns></returns>
+        [Function("DailyReport")]
+        public async Task DailyReport([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
         {
             _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
-            
+            try
+            {
+                await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.location},定时任务{DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss")}", GroupNames.成都开发測試群組);
+                string local = Environment.GetEnvironmentVariable("Option:Location");
+                // if (local.Contains("Test")||local.Contains("Dep"))
+                {
+
+                    int am = 9;
+                    int pm = 9;
+                    //int am = DateTimeOffset.Now.Hour;
+                    //int pm = DateTimeOffset.Now.Hour;
+                    var url = Environment.GetEnvironmentVariable("HaBookAuth:CoreAPI");
+                    var clientID = Environment.GetEnvironmentVariable("HaBookAuth:CoreService:clientID");
+                    var clientSecret = Environment.GetEnvironmentVariable("HaBookAuth:CoreService:clientSecret");
+                    string location = "";
+                    if (local.Contains("China"))
+                    {
+                        location = "China";
+                    }
+                    else if (local.Contains("Global"))
+                    {
+                        location = "Global";
+                    }
+                    var client = _httpClient.CreateClient();
+                    var token = CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location).Result;
+                    if (client.DefaultRequestHeaders.Contains("Authorization"))
+                    {
+                        client.DefaultRequestHeaders.Remove("Authorization");
+                        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
+                    }
+                    else
+                    {
+                        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
+                    }
+                    var data = await TEAMModelOS.SDK.Models.Service.SystemService.AccumulateDaily(_configuration, _azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing, client, _snowflakeId, url, am, pm);
+                    //await _dingDing.SendBotMsg($"返回数据{data.ToJsonString()}", GroupNames.成都开发測試群組);
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{DailyReport}\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+
             if (myTimer.ScheduleStatus is not null)
             {
                 _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");

+ 113 - 0
TEAMModelOS.Function/Properties/ServiceDependencies/ies5func - Web Deploy/profile.arm.json

@@ -0,0 +1,113 @@
+{
+  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
+  "contentVersion": "1.0.0.0",
+  "metadata": {
+    "_dependencyType": "compute.appService.windows"
+  },
+  "parameters": {
+    "resourceGroupName": {
+      "type": "string",
+      "defaultValue": "TEAMModelChengdu",
+      "metadata": {
+        "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
+      }
+    },
+    "resourceGroupLocation": {
+      "type": "string",
+      "defaultValue": "",
+      "metadata": {
+        "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
+      }
+    },
+    "resourceName": {
+      "type": "string",
+      "defaultValue": "ies5func",
+      "metadata": {
+        "description": "Name of the main resource to be created by this template."
+      }
+    },
+    "resourceLocation": {
+      "type": "string",
+      "defaultValue": "[parameters('resourceGroupLocation')]",
+      "metadata": {
+        "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
+      }
+    }
+  },
+  "variables": {
+    "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+    "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]"
+  },
+  "resources": [
+    {
+      "type": "Microsoft.Resources/resourceGroups",
+      "name": "[parameters('resourceGroupName')]",
+      "location": "[parameters('resourceGroupLocation')]",
+      "apiVersion": "2019-10-01"
+    },
+    {
+      "type": "Microsoft.Resources/deployments",
+      "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+      "resourceGroup": "[parameters('resourceGroupName')]",
+      "apiVersion": "2019-10-01",
+      "dependsOn": [
+        "[parameters('resourceGroupName')]"
+      ],
+      "properties": {
+        "mode": "Incremental",
+        "template": {
+          "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+          "contentVersion": "1.0.0.0",
+          "resources": [
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[parameters('resourceName')]",
+              "type": "Microsoft.Web/sites",
+              "apiVersion": "2015-08-01",
+              "tags": {
+                "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
+              },
+              "dependsOn": [
+                "[variables('appServicePlan_ResourceId')]"
+              ],
+              "kind": "app",
+              "properties": {
+                "name": "[parameters('resourceName')]",
+                "kind": "app",
+                "httpsOnly": true,
+                "reserved": false,
+                "serverFarmId": "[variables('appServicePlan_ResourceId')]",
+                "siteConfig": {
+                  "metadata": [
+                    {
+                      "name": "CURRENT_STACK",
+                      "value": "dotnetcore"
+                    }
+                  ]
+                }
+              },
+              "identity": {
+                "type": "SystemAssigned"
+              }
+            },
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[variables('appServicePlan_name')]",
+              "type": "Microsoft.Web/serverFarms",
+              "apiVersion": "2015-08-01",
+              "sku": {
+                "name": "S1",
+                "tier": "Standard",
+                "family": "S",
+                "size": "S1"
+              },
+              "properties": {
+                "name": "[variables('appServicePlan_name')]"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ]
+}

+ 174 - 0
TEAMModelOS.Function/Properties/ServiceDependencies/ies5func - Zip Deploy/profile.arm.json

@@ -0,0 +1,174 @@
+{
+  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
+  "contentVersion": "1.0.0.0",
+  "metadata": {
+    "_dependencyType": "compute.function.windows.appService"
+  },
+  "parameters": {
+    "resourceGroupName": {
+      "type": "string",
+      "defaultValue": "TEAMModelChengdu",
+      "metadata": {
+        "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
+      }
+    },
+    "resourceGroupLocation": {
+      "type": "string",
+      "defaultValue": "",
+      "metadata": {
+        "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support."
+      }
+    },
+    "resourceName": {
+      "type": "string",
+      "defaultValue": "ies5func",
+      "metadata": {
+        "description": "Name of the main resource to be created by this template."
+      }
+    },
+    "resourceLocation": {
+      "type": "string",
+      "defaultValue": "[parameters('resourceGroupLocation')]",
+      "metadata": {
+        "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
+      }
+    }
+  },
+  "resources": [
+    {
+      "type": "Microsoft.Resources/resourceGroups",
+      "name": "[parameters('resourceGroupName')]",
+      "location": "[parameters('resourceGroupLocation')]",
+      "apiVersion": "2019-10-01"
+    },
+    {
+      "type": "Microsoft.Resources/deployments",
+      "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+      "resourceGroup": "[parameters('resourceGroupName')]",
+      "apiVersion": "2019-10-01",
+      "dependsOn": [
+        "[parameters('resourceGroupName')]"
+      ],
+      "properties": {
+        "mode": "Incremental",
+        "expressionEvaluationOptions": {
+          "scope": "inner"
+        },
+        "parameters": {
+          "resourceGroupName": {
+            "value": "[parameters('resourceGroupName')]"
+          },
+          "resourceGroupLocation": {
+            "value": "[parameters('resourceGroupLocation')]"
+          },
+          "resourceName": {
+            "value": "[parameters('resourceName')]"
+          },
+          "resourceLocation": {
+            "value": "[parameters('resourceLocation')]"
+          }
+        },
+        "template": {
+          "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
+          "contentVersion": "1.0.0.0",
+          "parameters": {
+            "resourceGroupName": {
+              "type": "string"
+            },
+            "resourceGroupLocation": {
+              "type": "string"
+            },
+            "resourceName": {
+              "type": "string"
+            },
+            "resourceLocation": {
+              "type": "string"
+            }
+          },
+          "variables": {
+            "storage_name": "[toLower(concat('storage', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId))))]",
+            "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]",
+            "storage_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Storage/storageAccounts/', variables('storage_name'))]",
+            "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]",
+            "function_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/sites/', parameters('resourceName'))]"
+          },
+          "resources": [
+            {
+              "location": "[parameters('resourceLocation')]",
+              "name": "[parameters('resourceName')]",
+              "type": "Microsoft.Web/sites",
+              "apiVersion": "2015-08-01",
+              "tags": {
+                "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty"
+              },
+              "dependsOn": [
+                "[variables('appServicePlan_ResourceId')]",
+                "[variables('storage_ResourceId')]"
+              ],
+              "kind": "functionapp",
+              "properties": {
+                "name": "[parameters('resourceName')]",
+                "kind": "functionapp",
+                "httpsOnly": true,
+                "reserved": false,
+                "serverFarmId": "[variables('appServicePlan_ResourceId')]",
+                "siteConfig": {
+                  "alwaysOn": true
+                }
+              },
+              "identity": {
+                "type": "SystemAssigned"
+              },
+              "resources": [
+                {
+                  "name": "appsettings",
+                  "type": "config",
+                  "apiVersion": "2015-08-01",
+                  "dependsOn": [
+                    "[variables('function_ResourceId')]"
+                  ],
+                  "properties": {
+                    "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storage_name'), ';AccountKey=', listKeys(variables('storage_ResourceId'), '2017-10-01').keys[0].value, ';EndpointSuffix=', 'core.windows.net')]",
+                    "FUNCTIONS_EXTENSION_VERSION": "~3",
+                    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
+                  }
+                }
+              ]
+            },
+            {
+              "location": "[parameters('resourceGroupLocation')]",
+              "name": "[variables('storage_name')]",
+              "type": "Microsoft.Storage/storageAccounts",
+              "apiVersion": "2017-10-01",
+              "tags": {
+                "[concat('hidden-related:', concat('/providers/Microsoft.Web/sites/', parameters('resourceName')))]": "empty"
+              },
+              "properties": {
+                "supportsHttpsTrafficOnly": true
+              },
+              "sku": {
+                "name": "Standard_LRS"
+              },
+              "kind": "Storage"
+            },
+            {
+              "location": "[parameters('resourceGroupLocation')]",
+              "name": "[variables('appServicePlan_name')]",
+              "type": "Microsoft.Web/serverFarms",
+              "apiVersion": "2015-08-01",
+              "sku": {
+                "name": "S1",
+                "tier": "Standard",
+                "family": "S",
+                "size": "S1"
+              },
+              "properties": {
+                "name": "[variables('appServicePlan_name')]"
+              }
+            }
+          ]
+        }
+      }
+    }
+  ]
+}

+ 0 - 14
TEAMModelOS.Function/Properties/serviceDependencies.teammodelosfunction-test - Zip Deploy.json

@@ -1,14 +0,0 @@
-{
-  "dependencies": {
-    "appInsights1": {
-      "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/microsoft.insights/components/teammodelosfunctiontest",
-      "type": "appInsights.azure",
-      "connectionId": "APPLICATIONINSIGHTS_CONNECTION_STRING"
-    },
-    "storage1": {
-      "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Storage/storageAccounts/teammodellog",
-      "type": "storage.azure",
-      "connectionId": "AzureWebJobsStorage"
-    }
-  }
-}

+ 0 - 1
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -44,7 +44,6 @@ using Microsoft.Azure.Amqp.Framing;
 using System.Security.Policy;
 using TEAMModelOS.SDK.Models.Service.BI;
 using TEAMModelOS.SDK.Models.Dtos;
-using System.ServiceModel.Channels;
 using static TEAMModelOS.FunctionV4.Program;
 
 namespace TEAMModelOS.FunctionV4.ServiceBus

+ 0 - 1
TEAMModelOS.SDK/TEAMModelOS.SDK.csproj

@@ -1,5 +1,4 @@
 <Project Sdk="Microsoft.NET.Sdk">
-
 	<PropertyGroup>
 		<TargetFramework>net8.0</TargetFramework>
 		<Version>5.2406.19</Version>

+ 0 - 6
TEAMModelOS.sln

@@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.32014.148
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS.SDK", "TEAMModelOS.SDK\TEAMModelOS.SDK.csproj", "{E804B5FA-8D72-4ED4-AF9E-8AA48C17CE76}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS.FunctionV4", "TEAMModelOS.FunctionV4\TEAMModelOS.FunctionV4.csproj", "{2A159D6A-55DB-4B0F-9129-3EB9EE28A1CC}"
-EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS", "TEAMModelOS\TEAMModelOS.csproj", "{985D4ABD-281A-428C-81AD-60FCA0045DAD}"
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelBI", "TEAMModelBI\TEAMModelBI.csproj", "{54DC5894-D5BA-40AB-9226-FB801E04BA24}"
@@ -31,10 +29,6 @@ Global
 		{E804B5FA-8D72-4ED4-AF9E-8AA48C17CE76}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E804B5FA-8D72-4ED4-AF9E-8AA48C17CE76}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E804B5FA-8D72-4ED4-AF9E-8AA48C17CE76}.Release|Any CPU.Build.0 = Release|Any CPU
-		{2A159D6A-55DB-4B0F-9129-3EB9EE28A1CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{2A159D6A-55DB-4B0F-9129-3EB9EE28A1CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{2A159D6A-55DB-4B0F-9129-3EB9EE28A1CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{2A159D6A-55DB-4B0F-9129-3EB9EE28A1CC}.Release|Any CPU.Build.0 = Release|Any CPU
 		{985D4ABD-281A-428C-81AD-60FCA0045DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{985D4ABD-281A-428C-81AD-60FCA0045DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{985D4ABD-281A-428C-81AD-60FCA0045DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU