Browse Source

排程的Function执行代码。

CrazyIter_Bin 1 year ago
parent
commit
36b149a6f7

+ 264 - 0
TEAMModelOS.FunctionSchedule/.gitignore

@@ -0,0 +1,264 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# Azure Functions localsettings file
+local.settings.json
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# DNX
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# TODO: Comment the next line if you want to checkin your web deploy settings
+# but database connection strings (with potential passwords) will be unencrypted
+#*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/packages/*
+# except build/, which is used as an MSBuild target.
+!**/packages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+node_modules/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+*.mdf
+*.ldf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# CodeRush
+.cr/
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc

+ 346 - 0
TEAMModelOS.FunctionSchedule/ActiveTaskTopic.cs

@@ -0,0 +1,346 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using Azure.Cosmos;
+using Azure.Messaging.ServiceBus;
+using Microsoft.Extensions.Logging;
+using StackExchange.Redis;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using System.Linq;
+using TEAMModelOS.SDK.Models.Service;
+using TEAMModelOS.SDK.Models.Cosmos.BI;
+using TEAMModelOS.Models;
+using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Configuration;
+using HTEXLib.COMM.Helpers;
+using Microsoft.Azure.Functions.Worker;
+using TEAMModelOS.SDK.Services;
+using Azure.Storage.Blobs.Models;
+using System.IO;
+using Azure;
+using static TEAMModelOS.SDK.Models.Service.LessonService;
+using DinkToPdf.Contracts;
+using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
+using static TEAMModelOS.SDK.StatisticsService;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Wordprocessing;
+using System.Xml.Linq;
+using Azure.Storage.Sas;
+using DocumentFormat.OpenXml.Drawing;
+using System.Net.Http;
+using System.Web;
+using System.Net;
+using System.Net.Http.Json;
+using System.Threading;
+using System.Collections.Concurrent;
+using Microsoft.Azure.Amqp.Framing;
+using System.Security.Policy;
+using TEAMModelOS.SDK.Models.Service.BI;
+
+namespace TEAMModelOS.FunctionV4.ServiceBus
+{
+    public class ActiveTaskTopic
+    {
+
+        private readonly int psize = 20;
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureRedisFactory _azureRedis;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly Option _option;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
+        private readonly IConfiguration _configuration;
+        private readonly IConverter _converter;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly HttpTrigger _httpTrigger;
+        public ActiveTaskTopic(HttpTrigger httpTrigger, SnowflakeId snowflakeId, IConverter converter, CoreAPIHttpService coreAPIHttpService,
+            AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis,
+            AzureServiceBusFactory serviceBus, IOptionsSnapshot<Option> option,
+             IConfiguration configuration)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _azureStorage = azureStorage;
+            _azureRedis = azureRedis;
+            _serviceBus = serviceBus;
+            _option = option?.Value;
+            _configuration = configuration;
+            _coreAPIHttpService = coreAPIHttpService;
+            _converter = converter;
+            _snowflakeId = snowflakeId;
+            _httpTrigger = httpTrigger;
+        }
+        [Function("Exam")]
+        public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var json = JsonDocument.Parse(msg);
+                json.RootElement.TryGetProperty("id", out JsonElement id);
+                json.RootElement.TryGetProperty("progress", out JsonElement progress);
+                json.RootElement.TryGetProperty("code", out JsonElement code);
+                //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
+                exam.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamBus()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("Vote")]
+        public async Task VoteFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "vote", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                Vote vote = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Vote>(id.ToString(), new PartitionKey($"{code}"));
+                vote.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,VoteBus()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("Correct")]
+        public async Task CorrectFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "correct", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                Correct correct = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Correct>(id.ToString(), new PartitionKey($"{code}"));
+                correct.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(correct, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Correct()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("Survey")]
+        public async Task SurveyFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "survey", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                //Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
+                var client = _azureCosmos.GetCosmosClient();
+                Survey survey = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
+                survey.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+        }
+        [Function("Homework")]
+        public async Task HomeworkFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "homework", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                Homework homework = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Homework>(id.ToString(), new PartitionKey($"{code}"));
+                homework.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(homework, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("Study")]
+        public async Task StudyFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "study", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            string activityId = string.Empty;
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                Study study = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Study>(id.ToString(), new PartitionKey($"{code}"));
+                study.progress = progress.ToString();
+                activityId = id.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(study, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("Art")]
+        public async Task ArtFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "art", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            string activityId = string.Empty;
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                ArtEvaluation art = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ArtEvaluation>(id.ToString(), new PartitionKey($"{code}"));
+                art.progress = progress.ToString();
+                activityId = id.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(art, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Art()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Art()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+        [Function("ExamLite")]
+        public async Task ExamLiteFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "examlite", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg);
+                jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
+                jsonMsg.RootElement.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);
+                var client = _azureCosmos.GetCosmosClient();
+                ExamLite lite = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamLite>(id.ToString(), new PartitionKey($"{code}"));
+                lite.progress = progress.ToString();
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(lite, id.ToString(), new PartitionKey($"{code}"));
+            }
+            catch (CosmosException e)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ExamLite()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+       [Function("LessonRecordExpire")]
+        public async Task LessonRecordExpireFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-expire", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
+        {
+            try
+            {
+                var jsonMsg = JsonDocument.Parse(msg).RootElement;
+                jsonMsg.TryGetProperty("id", out JsonElement id);
+                jsonMsg.TryGetProperty("progress", out JsonElement progress);
+                jsonMsg.TryGetProperty("code", out JsonElement _code);
+                jsonMsg.TryGetProperty("tmdid", out JsonElement tmdid);
+                jsonMsg.TryGetProperty("tmdname", out JsonElement tmdname);
+                jsonMsg.TryGetProperty("name", out JsonElement name);
+                jsonMsg.TryGetProperty("startTime", out JsonElement startTime);
+                jsonMsg.TryGetProperty("expire", out JsonElement expire);
+                jsonMsg.TryGetProperty("scope", out JsonElement scope);
+                jsonMsg.TryGetProperty("school", out JsonElement _school);
+                jsonMsg.TryGetProperty("tag", out JsonElement _tag);
+                var client = _azureCosmos.GetCosmosClient();
+                //处理到期删除
+                if (_tag.ValueKind.Equals(JsonValueKind.String) && $"{_tag}".Equals("delete"))
+                {
+                    string lessonId = $"{id}";
+                    string tbname;
+                    string school = $"{_school}";
+                    string code = "";
+                    if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
+                    {
+                        code = $"LessonRecord-{school}";
+                        tbname = "School";
+                    }
+                    else if ($"{scope}".Equals("private"))
+                    {
+                        code = $"LessonRecord";
+                        tbname = "Teacher";
+                    }
+                    else
+                    {
+                        return;
+                    }
+                    Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
+                    if (response.Status == 200)
+                    {
+                        LessonRecord lessonRecord;
+                        var doc = JsonDocument.Parse(response.ContentStream);
+                        lessonRecord = doc.RootElement.ToObject<LessonRecord>();
+                        lessonRecord.status = 404;
+                        await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
+                        var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
+                        var messageChange = new ServiceBusMessage(new { delete_id = lessonId, tmdid = tmdid, scope = scope, opt = "delete", school = school }.ToJsonString());
+                        messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
+                        await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
+                        await _dingDing.SendBotMsg($"课例:【{lessonRecord.name}】\n课例ID:【{lessonRecord.id}】\n因时间到期,即将被自动删除,到期时间:" +
+                        $"{lessonRecord.expire}\n{lessonRecord.ToJsonString()}", GroupNames.成都开发測試群組);
+                    }
+                }
+                string biz = "expire";
+                Teacher targetTeacher = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{tmdid}", new PartitionKey($"Base"));
+                string expireTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse($"{expire}")).ToString("yyyy-MM-dd HH:mm:ss");
+                _coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "expire-private_lessonRecord", Constant.NotifyType_IES5_Course,
+                new Dictionary<string, object> { { "tmdname", tmdname }, { "tmdid", tmdid }, { "lessonId", id }, { "expireTime", expireTime }, { "lessonName", name } }, $"{Environment.GetEnvironmentVariable("Option:Location")}", _configuration, _dingDing, "");
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,LessonRecordExpire()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
+  }
+}

+ 78 - 0
TEAMModelOS.FunctionSchedule/Program.cs

@@ -0,0 +1,78 @@
+using DinkToPdf;
+using DinkToPdf.Contracts;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Hosting;
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Text.Json;
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+using TEAMModelOS.FunctionV4;
+using TEAMModelOS.FunctionV4.ServiceBus;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.DI.Multiple;
+
+namespace TEAMModelOS.FunctionV4
+{
+    public static class Program
+    {
+        public static async Task Main(string[] args)
+        {
+#if DEBUG
+
+            
+            Debugger.Launch();
+#endif
+
+             
+            var host = new HostBuilder()
+           .ConfigureAppConfiguration((context, configure) =>
+           {
+               //configure.AddCommandLine(args);
+              // configure.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables();
+           })
+           .ConfigureServices((context, services) =>
+           {
+           
+               //services.Configure<Option>(options => context. Configuration.GetSection("Option").Bind(options));
+               services.AddHttpClient();
+               services.AddHttpClient<DingDing>();
+               services.AddHttpClient<HttpTrigger>();
+               //services.AddCoreAPIHttpService(context.Configuration);
+               services.AddHttpClient<CoreAPIHttpService>().ConfigureHttpMessageHandlerBuilder(builder =>
+               {
+                   builder.PrimaryHandler = new HttpClientHandler
+                   {
+                       ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
+                   };
+               });
+               List<(string name, string connectionString)> cosmosDBConnects = new();
+               cosmosDBConnects.Add(("Default", context.Configuration.GetSection("Azure:Cosmos:ConnectionString").Get<string>()));
+               cosmosDBConnects.Add(("CoreServiceV1", context.Configuration.GetSection("CoreServiceV1:Cosmos:ConnectionString").Get<string>())); //CoreService V1 read only
+               cosmosDBConnects.Add(("CoreServiceV2CnRead", context.Configuration.GetSection("CoreServiceV2:CosmosCnRead:ConnectionString").Get<string>())); //CoreService V2 CN read only
+               services.AddMultipleAzureCosmos(cosmosDBConnects);
+               services.AddAzureServiceBus(context.Configuration.GetSection("Azure:ServiceBus:ConnectionString").Get<string>());
+               services.AddAzureRedis(context.Configuration.GetSection("Azure:Redis:ConnectionString").Get<string>());
+               services.AddSnowflakeId(Convert.ToInt64(context.Configuration.GetSection("Option:LocationNum").Get<Int32>()), 1);
+               List<(string name, string connectionString)> storageConnects = new();
+               storageConnects.Add(("Default", context.Configuration.GetSection("Azure:Storage:ConnectionString").Get<string>()));      
+              
+               services.AddMultipleAzureStorage(storageConnects);
+           })
+           .Build();
+            await host.RunAsync();
+        }
+    }
+}

+ 7 - 0
TEAMModelOS.FunctionSchedule/Properties/serviceDependencies.json

@@ -0,0 +1,7 @@
+{
+  "dependencies": {
+    "appInsights1": {
+      "type": "appInsights"
+    }
+  }
+}

+ 7 - 0
TEAMModelOS.FunctionSchedule/Properties/serviceDependencies.local.json

@@ -0,0 +1,7 @@
+{
+  "dependencies": {
+    "appInsights1": {
+      "type": "appInsights.sdk"
+    }
+  }
+}

+ 3 - 0
TEAMModelOS.FunctionSchedule/Properties/serviceDependencies.teammodelosfunction-schedule - Zip Deploy.json

@@ -0,0 +1,3 @@
+{
+  "dependencies": {}
+}

+ 59 - 0
TEAMModelOS.FunctionSchedule/TEAMModelOS.FunctionSchedule.csproj

@@ -0,0 +1,59 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+	  <TargetFramework>net6.0</TargetFramework>
+	  <AzureFunctionsVersion>v4</AzureFunctionsVersion>
+	  <OutputType>Exe</OutputType>
+	  <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
+	  <SignAssembly>true</SignAssembly>
+	  <Version>5.2311.22</Version>
+	  <AssemblyVersion>5.2311.22.1</AssemblyVersion>
+	  <FileVersion>5.2311.22.1</FileVersion>
+	  <PackageId>TEAMModelOS.FunctionSchedule</PackageId>
+	  <Authors>teammodel</Authors>
+	  <Company>醍摩豆(成都)信息技术有限公司</Company>
+	  <Product>IES5</Product>
+	  <Description>事件触发中心 </Description>
+	  <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
+	  <PackageProjectUrl>https://www.teammodel.cn/</PackageProjectUrl>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+	  <DefineConstants>DEBUG;TRACE</DefineConstants>
+  </PropertyGroup>
+
+	<ItemGroup>
+		<!--<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />-->
+		<!--<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />-->
+		<!--<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" />-->
+		<!--<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.0" />-->
+		<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
+
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.1" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.7.0" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.0.0-preview2" />
+		<!--<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="3.0.9" />-->
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="5.0.1" />
+		<PackageReference Include="SPS.SBCompressor" Version="0.6.5" />
+		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
+		<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
+	</ItemGroup>
+	<ItemGroup>
+		<ProjectReference Include="..\TEAMModelOS.SDK\TEAMModelOS.SDK.csproj" />
+	</ItemGroup>
+	<ItemGroup>
+		<None Update="host.json">
+			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
+		</None>
+		<None Update="local.settings.json">
+			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
+			<CopyToPublishDirectory>Never</CopyToPublishDirectory>
+		</None>
+	</ItemGroup>
+	<ProjectExtensions>
+		<VisualStudio>
+			<UserProperties local_1settings_1json__JsonSchema="" />
+		</VisualStudio>
+	</ProjectExtensions>
+</Project>

+ 19 - 0
TEAMModelOS.FunctionSchedule/host.json

@@ -0,0 +1,19 @@
+{
+  "version": "2.0",
+  "cosmosDB": {
+    "connectionMode": "Direct",
+    "protocol": "Tcp"
+  },
+  "logging": {
+    "console": {
+      "isEnabled": "true"
+    },
+    "applicationInsights": {
+      "samplingExcludedTypes": "Request",
+      "samplingSettings": {
+        "isEnabled": true,
+        "ExcludedTypes": "Request"
+      }
+    }
+  }
+}

+ 7 - 1
TEAMModelOS.sln

@@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS", "TEAMModelOS\
 EndProject
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelBI", "TEAMModelBI\TEAMModelBI.csproj", "{54DC5894-D5BA-40AB-9226-FB801E04BA24}"
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelBI", "TEAMModelBI\TEAMModelBI.csproj", "{54DC5894-D5BA-40AB-9226-FB801E04BA24}"
 EndProject
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TEAMModelOS.TEST", "TEAMModelOS.TEST\TEAMModelOS.TEST.csproj", "{335938F6-8418-497A-AB41-CDD006FB8FD6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TEAMModelOS.TEST", "TEAMModelOS.TEST\TEAMModelOS.TEST.csproj", "{335938F6-8418-497A-AB41-CDD006FB8FD6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TEAMModelOS.FunctionSchedule", "TEAMModelOS.FunctionSchedule\TEAMModelOS.FunctionSchedule.csproj", "{0C96C724-D76D-4471-97E3-927B175ED7DB}"
 EndProject
 EndProject
 Global
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Release|Any CPU.Build.0 = Release|Any CPU
 		{335938F6-8418-497A-AB41-CDD006FB8FD6}.Release|Any CPU.Build.0 = Release|Any CPU
+		{0C96C724-D76D-4471-97E3-927B175ED7DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{0C96C724-D76D-4471-97E3-927B175ED7DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{0C96C724-D76D-4471-97E3-927B175ED7DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{0C96C724-D76D-4471-97E3-927B175ED7DB}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 		HideSolutionNode = FALSE