Bläddra i källkod

作业活动代码提交

CrazyIter_Bin 3 år sedan
förälder
incheckning
b68691f9cf

+ 39 - 0
TEAMModelFunction/MonitorServicesBus.cs

@@ -48,6 +48,10 @@ namespace TEAMModelFunction
                 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)
+            {
+
             }
             catch (Exception ex)
             {
@@ -68,6 +72,10 @@ namespace TEAMModelFunction
                 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)
+            {
+
             }
             catch (Exception ex)
             {
@@ -88,6 +96,10 @@ namespace TEAMModelFunction
                 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)
+            {
+
             }
             catch (Exception ex)
             {
@@ -109,12 +121,39 @@ namespace TEAMModelFunction
                 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)
+            {
+
             }
             catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,SurveyBus()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
             }
         }
+        [FunctionName("Homework")]
+        public async Task Homework([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  ) { 
+                
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Homework()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
+            }
+
+        }
         [FunctionName("Blob")]
         public async Task Blob([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "blob", Connection = "Azure:ServiceBus:ConnectionString")] string msg) {
             try

+ 140 - 32
TEAMModelFunction/TriggerWork.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
+using Azure.Messaging.ServiceBus;
 using HTEXLib.COMM.Helpers;
 using Microsoft.Azure.Documents;
 using System;
@@ -6,8 +7,10 @@ using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Service;
 
 namespace TEAMModelFunction
 {
@@ -35,51 +38,156 @@ namespace TEAMModelFunction
                     adcode = $"Activity-{tdata.creatorId}";
                     blobcntr = tdata.creatorId;
                 }
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 Homework work = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                //List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", vote.progress } });
+                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", work.progress } });
                 if (work != null)
                 {
-                    (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
-                    List<StuActivity> tchActivities = new List<StuActivity>();
-
-                    if (tchList.IsNotEmpty())
+                    switch (work.progress)
                     {
-                        tchList.ForEach(x =>
-                        {
-                            tchActivities.Add(new StuActivity
+                        case "pending":
+                            var messageWork = new ServiceBusMessage(new { id = input.Id, progress = "going", code = tdata.code }.ToJsonString());
+                            messageWork.ApplicationProperties.Add("name", "Homework");
+                            if (changeRecords.Count > 0)
                             {
-                                pk = "Activity",
-                                id = work.id,
-                                code = $"Activity-{x.id}",
-                                type = "Homework",
-                                name = work.name,
-                                startTime = work.startTime,
-                                endTime = work.endTime,
-                                scode = work.code,
-                                scope = work.scope,
-                                school = work.school,
-                                creatorId = work.creatorId,
-                                subjects = new List<string> { "" },
-                                blob = null,
-                                owner = work.owner,
-                                createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                taskStatus = -1,
-                                classIds = work.tchLists
-                            });
-                        });
-                    }
-                    await TriggerStuActivity.SaveStuActivity(client, _dingDing, null, null, tchActivities);
+                                await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                                changeRecords[0].sequenceNumber = start;
+                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                            }
+                            else
+                            {
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.stime));
+                                ChangeRecord changeRecord = new ChangeRecord
+                                {
+                                    RowKey = input.Id,
+                                    PartitionKey = "pending",
+                                    sequenceNumber = start,
+                                    msgId = messageWork.MessageId
+                                };
+                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                            }
+                            break;
+                        case "going":
+                            List<string> classes = ExamService.getClasses(work.classes, work.stuLists);
+                            (List<TmdInfo> tmdids, List<StuInfo> students, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, work.school);
+                            List<StuActivity> stuActivities = new List<StuActivity>();
+                            List<StuActivity> tmdActivities = new List<StuActivity>();
+                            List<StuActivity> tchActivities = new List<StuActivity>();
+                            if (tmdids.IsNotEmpty())
+                            {
+                                tmdids.ForEach(x =>
+                                {
+                                    tmdActivities.Add(new StuActivity
+                                    {
+                                        pk = "Activity",
+                                        id = work.id,
+                                        code = $"Activity-{x.id}",
+                                        type = "work",
+                                        name = work.name,
+                                        startTime = work.startTime,
+                                        endTime = work.endTime,
+                                        scode = work.code,
+                                        scope = work.scope,
+                                        school = work.school,
+                                        creatorId = work.creatorId,
+                                        subjects = new List<string> { "" },
+                                        blob = work.blob,
+                                        owner = work.owner,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        taskStatus = -1,
+                                        classIds = classes
+                                    });
+                                });
+                            }
+                            if (students.IsNotEmpty())
+                            {
+                                students.ForEach(x =>
+                                {
+                                    stuActivities.Add(new StuActivity
+                                    {
+                                        pk = "Activity",
+                                        id = work.id,
+                                        code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
+                                        type = "work",
+                                        name = work.name,
+                                        startTime = work.startTime,
+                                        endTime = work.endTime,
+                                        scode = work.code,
+                                        scope = work.scope,
+                                        school = work.school,
+                                        creatorId = work.creatorId,
+                                        subjects = new List<string> { "" },
+                                        blob = work.blob,
+                                        owner = work.owner,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        taskStatus = -1,
+                                        classIds = classes
+                                    });
+                                });
+                            }
+
+                            (List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, work.tchLists, work.school);
+                            if (tchList.IsNotEmpty())
+                            {
+                                tchList.ForEach(x =>
+                                {
+                                    tchActivities.Add(new StuActivity
+                                    {
+                                        pk = "Activity",
+                                        id = work.id,
+                                        code = $"Activity-{x.id}",
+                                        type = "work",
+                                        name = work.name,
+                                        startTime = work.startTime,
+                                        endTime = work.endTime,
+                                        scode = work.code,
+                                        scope = work.scope,
+                                        school = work.school,
+                                        creatorId = work.creatorId,
+                                        subjects = new List<string> { "" },
+                                        blob = work.blob,
+                                        owner = work.owner,
+                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                        taskStatus = -1,
+                                        classIds = work.tchLists
+                                    });
+                                });
+                            }
+                            await TriggerStuActivity.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, tchActivities);
 
+                            var messageWorkEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = tdata.code }.ToJsonString());
+                            messageWorkEnd.ApplicationProperties.Add("name", "Homework");
+                            if (changeRecords.Count > 0)
+                            {
+                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                                await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
+                                changeRecords[0].sequenceNumber = end;
+                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                            }
+                            else
+                            {
+                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.etime));
+                                ChangeRecord changeRecord = new ChangeRecord
+                                {
+                                    RowKey = input.Id,
+                                    PartitionKey = "going",
+                                    sequenceNumber = end,
+                                    msgId = messageWorkEnd.MessageId
+                                };
+                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                            }
+                            break;
+                        case "finish":
+                            break;
+                    }
 
                 }
-
             }
             catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修作业活动异常{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
             }
-
         }
     }
 }

+ 12 - 24
TEAMModelOS.SDK/Models/Cosmos/Common/Homework.cs

@@ -98,8 +98,19 @@ namespace TEAMModelOS.SDK.Models
         public int? status { get; set; } = 0;
         public long? size { get; set; } = 0;
         public string areaId { get; set; }
+        public bool allowSupply { get; set; }
+        public List<string> extLimit { get; set; } = new List<string>();
+        public List<Attachment> attachments { get; set; } = new List<Attachment>();
         public List<Submits> teachers { get; set; } = new List<Submits>();
+        public string recordUrl { get; set; }
     }
+    public class Attachment { 
+        public string name { get; set; }
+        public string url { get; set; }
+        public long size { get; set; }
+    }
+ 
+
     public class Submits {
         public string id { get; set; }
         //public string name { get; set; }
@@ -108,28 +119,5 @@ namespace TEAMModelOS.SDK.Models
         public long hwTime { get; set; }
     }
 
-    /*
-     let homework = {
-        id: 'xxxx',// ID由前端创建。因为要保存先保存BLOB
-        name: '作业名称',
-        code: '1595321354',
-        creatorId:'1595321354',
-        school:'hbcn',
-        scope:'private',
-        classes: [],
-        stuLists: [],
-        targets: [],
-        endTime: 1629561599999,
-        startTime: 1629561599999,
-        description: '作业描述',
-        progress: 'finish',//状态
-        allowSupply: false,//是否允许补交作业
-        typeLimit: [],//空数组代表无格式限制,有则是限制的上传格式后缀集合,比如['docx','doc']
-        attachments: [{
-        name: '附件名称.pdf',
-        url: 'xxxxxx',
-        size: 2048
-        }],//附件信息
-     }
-     */
+    
 }

+ 10 - 19
TEAMModelOS.SDK/Models/Cosmos/Student/HomeworkRecord.cs

@@ -16,28 +16,19 @@ namespace TEAMModelOS.SDK.Models
     {
         
         public HomeworkRecord() {
-            content = new List<HomeWorkContent>();
+            content = new List<Content>();
             stuCmt = new List<StudentComment>();
-            classroom = new ClassroomItem();
+          
            // nativeroom = new ClassroomItem();
-            tchCmt = new HomeWorkComment();
+            tchCmt = new HomeworkComment();
         }        
 
-        /// <summary>
-        /// 上课班级
-        /// </summary>
-        public ClassroomItem classroom { get; set; }
-
-        ///// <summary>
-        ///// 原生班级
-        ///// </summary>
-        //[ProtoMember(6)]
-        //public ClassroomItem nativeroom{ get; set; }
+       
 
         /// <summary>
         /// 提交时间
         /// </summary>
-        public long submitTime { get; set; }
+        public long time { get; set; }
 
         /// <summary>
         /// 分数
@@ -47,7 +38,7 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 作业内容
         /// </summary>
-        public List<HomeWorkContent> content { get; set; }
+        public List<Content> content { get; set; }
 
 
         /// <summary>
@@ -59,7 +50,7 @@ namespace TEAMModelOS.SDK.Models
         /// <summary>
         /// 教师评语
         /// </summary>
-        public HomeWorkComment tchCmt { get; set; }
+        public HomeworkComment tchCmt { get; set; }
     }
     public class ClassroomItem {
         public string name { get; set; }
@@ -70,12 +61,12 @@ namespace TEAMModelOS.SDK.Models
     /// <summary>
     /// 作业内容
     /// </summary>
-    public class HomeWorkContent {
+    public class Content {
 
         /// <summary>
         /// 作答记录
         /// </summary>
-        public string answers { get; set; }
+        public List<List<string>> answers { get; set; } = new List<List<string>>();
 
         /// <summary>
         ///  其他模式url 及name
@@ -139,7 +130,7 @@ namespace TEAMModelOS.SDK.Models
     /// <summary>
     /// 作业评论
     /// </summary>
-    public class HomeWorkComment {
+    public class HomeworkComment {
        
 
         /// <summary>

+ 1 - 1
TEAMModelOS.SDK/Models/Service/StuListService.cs

@@ -174,7 +174,7 @@ namespace TEAMModelFunction
                 }
             }
             catch(Exception ex ) {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n{ex.Message}{ex.StackTrace}{stuListChange.ToJsonString()}{type}", GroupNames.醍摩豆服務運維群組);
             }
         }
 

+ 2 - 2
TEAMModelOS/ClientApp/package.json

@@ -34,7 +34,7 @@
 		"firebase": "^7.19.0",
 		"firestore": "^1.1.6",
 		"html2canvas": "^1.0.0-rc.7",
-		"html2pdf.js": "^0.9.3",
+		"html2pdf.js": "^0.10.1",
 		"i18next": "^20.3.1",
 		"imports-loader": "^0.8.0",
 		"increase-memory-limit": "^1.0.7",
@@ -89,7 +89,7 @@
 		"vuex-oidc": "^3.3.0",
 		"vuex-router-sync": "^5.0.0",
 		"wangeditor": "4.5.2",
-		"xlsx": "^0.15.1"
+		"xlsx": "^0.17.1"
 	},
 	"devDependencies": {
 		"@babel/core": "^7.5.5",

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 731 - 374
TEAMModelOS/Controllers/Common/HomeworkController.cs


+ 7 - 3
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -326,20 +326,24 @@ namespace TEAMModelOS.Controllers
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-               
+
                 survey = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
                 if (survey != null)
                 {
 
-                    return Ok(new { survey , status = 200 });
+                    return Ok(new { survey, status = 200 });
                 }
                 else
                 {
                     return Ok(new { survey, status = 404 });
                 }
             }
-            catch (Exception ex)
+            catch (CosmosException ex)
             {
+
+                return Ok(new { survey, status = 404 });
+            }
+            catch (Exception ex) {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id\n{ex.Message}{ex.StackTrace}\n{id}\n{code}  ", GroupNames.醍摩豆服務運維群組);
                 return Ok(new { survey, status = 404 });
             }

+ 26 - 10
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -65,25 +65,41 @@ namespace TEAMModelOS.Controllers
         [HttpPost("fix-school")]
         public async Task<IActionResult> FixSchool(JsonElement data)
         {
+            List<string> arr = new List<string> { "xnygxx",
+            "xcsyxx",
+            "lxxcfx",
+            "gxjrxx",
+            "cdgxsx",
+            "yzxx",
+            "njtsjy",
+            "lrtsxx",
+            "rhsyzx",
+            "wjylxx",
+            "yfps",
+            "kjyxx",
+            "dsgjxx",
+            "ydzt",
+            "hqrh",
+            "czmdzz",
+            "hsbhmz",
+            "cdtmd",
+            "hbcn",
+            "habook"};
             var client = _azureCosmos.GetCosmosClient();
           
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: "SELECT  value(c) FROM c", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
             {
-                if (!string.IsNullOrEmpty(item.standard))
+                if (arr.Contains(item.id))
                 {
-                    if (item.standard.Equals("02944f32-f534-3397-ea56-e6f1fc6c3714"))
-                    {
-                        item.areaId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
-                        item.standard = "standard2";
-                        await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
-                    }
-                }
-                else {
                     item.areaId = "02944f32-f534-3397-ea56-e6f1fc6c3714";
                     item.standard = "standard2";
                     await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
                 }
-                
+                else if (item.standard.Equals("standard2")) {
+                    item.areaId = null;
+                    item.standard = null;
+                    await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
+                }
             }
             return Ok();
         }