소스 검색

serviceBus调整

liqk 4 년 전
부모
커밋
0ad63c5f8d

+ 7 - 4
TEAMModelFunction/ServiceBusTopic.cs

@@ -6,7 +6,6 @@ using Azure.Cosmos;
 using Microsoft.Azure.WebJobs;
 using Microsoft.Azure.WebJobs.Host;
 using Microsoft.Extensions.Logging;
-using TEAMModelOS.Models.SchoolInfo;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 
@@ -33,10 +32,14 @@ namespace TEAMModelFunction
                 ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
                 exam.progress = progress.ToString();
                 await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
-            } else if (name.ToString().Equals("Survey")) { 
-            
+            } else if (name.ToString().Equals("Survey")) {
+                Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
+                survey.progress = progress.ToString();
+                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
             } else if (name.ToString().Equals("Vote")) {
-
+                Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.ToString(), new PartitionKey($"{code}"));
+                vote.progress = progress.ToString();
+                await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
             }
 
         }

+ 52 - 0
TEAMModelFunction/model/ExamClassResult.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelFunction
+{
+    //[CosmosDB(Database = "TEAMModelOS", Name = "Common")]
+    public class ExamClassResult : ID
+    {
+        public ExamClassResult() {
+            //paper = new PaperSimple();
+            studentAnswers = new List<List<List<string>>>();
+            studentScores = new List<List<double>>();
+            info = new ClassInfo();
+            studentIds = new List<string>();
+            studentAnswers = new List<List<List<string>>>();
+            studentScores = new List<List<double>>();
+        }
+        public string pk { get; set; }
+        [PartitionKey]
+        public string code { get; set; }
+        public string school { get; set; }
+        public string id { get; set; }
+        public string examId { get; set; }
+        public string subjectId { get; set; }
+        public int year { get; set; }
+        public ClassInfo info { get; set; }
+        public string progress { get; set; }
+        //public PaperSimple paper { get; set; }
+        //public List<double> point { get; set; }
+        public List<string> studentIds { get; set; }
+        public List<List<List<string>>> studentAnswers { get; set; }
+        public List<List<double>> studentScores { get; set; }
+        public string scope { get; set; }
+        public int? ttl { get; set; }
+    }
+/*    public class PaperSimple {
+        public string id { get; set; }
+        public string name { get; set; }
+        public string code { get; set; }
+        public string blob { get; set; }
+        public string scope { get; set; }
+    }*/
+    public class ClassInfo {
+        public string id { get; set; }
+        public string name { get; set; }
+        //public string code { get; set; }
+    }
+}

+ 120 - 0
TEAMModelFunction/model/ExamInfo.cs

@@ -0,0 +1,120 @@
+using DocumentFormat.OpenXml.Bibliography;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using System.Text.Json.Serialization;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelFunction
+{
+    /// <summary>
+    /// 考试基础信息
+    /// </summary>
+    //[CosmosDB(Database = "TEAMModelOS", Name = "School")]
+    public class ExamInfo : ID
+    {
+        [PartitionKey]
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string code { get; set; }
+    
+        public string pk { get; set; }
+        public int? ttl { get; set; } 
+        public ExamInfo() {
+            period = new PeriodSimple();
+            grades = new List<Grade>();
+            subjects = new List<Subject>();
+            papers = new List<PaperSimple>();
+            targetClassIds = new List<string>();
+        }
+        [JsonProperty(PropertyName = "id")]
+        public string id { get; set; }
+
+        public string name { get; set; }
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        public int stuCount { get; set; }
+/*        //实际考试人数
+        public int realCount { get; set; }
+        //平均分
+        public double piont { get; set; }*/
+        //指标
+        //public double index { get; set; }
+        public long createDate { get; set; }
+        //public string examCode { get; set; }
+        
+        /// <summary>
+        /// 施测起始时间
+        /// </summary>
+        public long startTime { get; set; }
+        /// <summary>
+        /// 施测结束时间
+        /// </summary>
+        public long endTime { get; set; }
+        /// <summary>
+        /// 施测对象
+        /// </summary>
+       // public List<string> target { get; set; }
+        /// <summary>
+        /// 发布
+        /// </summary>
+        public string publish { get; set; }
+
+        public int status { get; set; }
+        public int year { get; set; }
+        public string range { get; set; }
+        public string source { get; set; }
+        public List<string> targetClassIds { get; set; }
+        public List<PaperSimple> papers { get; set; }
+        ///考试类型 段考 stage  联考 union 平常考 normal 其他 other
+        /// </summary>
+        public string type { get; set; }
+        public PeriodSimple period { get; set; }
+        public List<Grade> grades { get; set; }
+        public List<Subject> subjects { get; set; }
+        public long sequenceNumber { get; set; }
+        //public Condition conditions { get; set; }
+        public List<string> blobUrl { get; set; }
+        public string progress { get; set; }
+        public string scope { get; set; }
+        public Custom examType { get; set; }
+        /// <summary>
+        /// 所有试卷阅卷状态
+        /// </summary>
+        //public List<int> marks { get; set; }
+    }
+    public class Custom {
+        public string id { get; set; }
+        public string name { get; set; }
+    }
+    public class PaperSimple { 
+        public string id { get; set; }
+        public string code { get; set; }
+        public string name { get; set; }
+        public string blob { get; set; }
+        public string scope { get; set; }
+        public int multipleRule { get; set; }
+        //该试卷配分情况
+        public List<double> point { get; set; }
+        public List<List<string>> answers { get; set; }
+    }
+    public class PeriodSimple
+    {
+        public string id { get; set; }
+        public string name { get; set; }
+    }
+    public class Grade
+    {
+        public string id { get; set; }
+        public string name { get; set; }
+    }
+    public class Subject
+    {
+        public string id { get; set; }
+        public string name { get; set; }
+
+
+    }
+}

+ 51 - 0
TEAMModelFunction/model/ExamResult.cs

@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelFunction
+{
+    /// <summary>
+    /// 考试成绩信息
+    /// </summary>
+    //[CosmosDB(Database = "TEAMModelOS", Name = "School")]
+    public  class ExamResult:ID
+    {
+        [PartitionKey]
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string code { get; set; }
+        // [PartitionKey(name = "ExamResult")]
+        public string pk { get; set; }
+        public int? ttl { get; set; } 
+        public ExamResult()
+        {
+            classes = new List<ClassRange>();
+            studentScores = new List<List<double>>();
+            studentIds = new List<string>();
+            point = new List<double>();
+        }
+        public string id { get; set; }
+        public string name { get; set; }
+        public string time { get; set; }
+        public string subjectId { get; set; }
+        public List<ClassRange> classes { get; set; }
+        public List<List<double>> studentScores { get; set; }
+        public List<string> studentIds { get; set; }
+        public List<double> point { get; set; }
+     
+        public string schoolId { get; set; }
+        public PaperSimple paper { get; set; }
+        public string scope { get; set; }
+        public string examId { get; set; }
+        public string school { get; set; }
+        public int year { get; set; }
+    }
+    public class ClassRange {
+
+        public string id { get; set; }
+        public string name { get; set; }
+        public List<int> range { get; set; }
+    }
+}

+ 141 - 0
TEAMModelFunction/model/Survey.cs

@@ -0,0 +1,141 @@
+using ProtoBuf;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using TEAMModelOS.Models.CommonInfo;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelFunction
+{
+    /// <summary>
+    /// 问卷调查
+    /// </summary>
+    [CosmosDB(Database = "TEAMModelOS",Name = "School")]
+    public class Survey : ID
+    {
+        public Survey() {
+            questions = new List<Questions>();
+            classes = new List<Classes>();
+        }
+        public string id { get; set; }
+        public int? ttl { get; set; }
+        public string pk { get; set; }
+        /// <summary>
+        /// 学校编码 或者醍摩豆ID
+        /// </summary>
+        [PartitionKey]
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string code { get; set; }
+        public string name { get; set; }   //测试问卷名称', // 问卷名称
+        public string description { get; set; }   //测试问卷描述', // 问卷描述
+        //public string type { get; set; }   //normal', // 问卷类型
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        public int year { get; set; }
+        public string progress { get; set; }
+        public List<Questions> questions { get; set; }
+        public List<string> targetClassIds { get; set; }
+        public int stuCount { get; set; }
+        public int status { get; set; } // 问卷状态(100:待发布 200:已发布 300:已结束)
+        /// <summary>
+        /// 发布对象
+        /// </summary>
+        //[ProtoMember(4)]
+        //public List<Target> target { get; set; }
+
+        /// <summary>
+        /// 发布模式 0 立即发布 1 定时
+        /// </summary>
+        [ProtoMember(5)]
+        public string publishModel { get; set; }
+
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        [ProtoMember(6)]
+        public long startTime { get; set; }
+
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        [ProtoMember(7)]
+        public long endTime { get; set; }
+        public long createTime { get; set; } // 问卷发布时间
+        public List<Classes> classes { get; set; }
+
+        public long sequenceNumber { get; set; }
+
+        public string url { get; set; }
+        public string scope { get; set; }
+
+    }
+    /*public class Item {
+        public string stem { get; set; }
+        /// <summary>
+        ///  Complete Single Multiple Subjective, Judge判断
+        /// </summary>
+        //public string type { get; set; }
+        public bool required { get; set; }
+        public int order { get; set; }
+        public string description { get; set; } = null;
+        public List<CodeValue> options { get; set; }
+        public List<CodeVal> result { get; set; }
+    }*/
+     public class Questions { 
+        public string qid { get; set; }
+        public string question { get; set; }
+        public List<Options> option { get; set; }
+        public string type { get; set; }
+        public QuestionResult result { get; set; }
+
+    }
+    public class Options { 
+        public string code { get; set; }
+        public string value { get; set; }
+        public Result result { get; set; }
+    }
+    public class QuestionResult
+    {
+        public double finish { get; set; }
+        public double finishRate { get; set; }
+    }
+    public class Result { 
+        public double count { get; set; }
+        public double rate { get; set; }
+    }
+    public class Classes { 
+        public string code { get; set; }
+        public string id { get; set; }
+        public string name { get; set; }
+        public string scope { get; set; }
+        public Result result { get; set; }
+        public List<StudentInfo> students { get; set; }
+        public List<AnswerRate> answers { get; set; }
+    }
+    public class AnswerRate {
+        public string qid { get; set; }
+        public double answerRate { get; set; }
+        public List<Options> option { get; set; }
+    }
+    public class StudentInfo {
+        public string id { get; set; }
+        public string name { get; set; }
+        public long finishTime { get; set; }
+        public List<AnswerInfo> answers { get; set; }
+        public ResultInfo result { get; set; }
+    }
+    public class ResultInfo
+    {
+        public double answerRate { get; set; }
+    }
+    public class AnswerInfo { 
+        public string qid { get; set; }
+        public string answer { get; set; }
+    }
+    /*public class CodeVal{
+        public string code { get; set; }
+        public int value { get; set; }
+    }*/
+}

+ 108 - 0
TEAMModelFunction/model/Vote.cs

@@ -0,0 +1,108 @@
+using ProtoBuf;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+using TEAMModelOS.SDK.DI;
+
+namespace TEAMModelFunction
+{
+    /// <summary>
+    /// 投票
+    /// </summary>
+    //[CosmosDB(Database = "TEAMModelOS", Name = "School")]
+    public class Vote : ID
+    {
+        [PartitionKey]
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string code { get; set; }
+        public string pk { get; set; }
+
+        public Vote()
+        {
+            options = new List<OptionsVote>();
+
+        }
+
+        [ProtoMember(1)]
+        public string id { get; set; }
+        /// <summary>
+        /// 投票名称
+        /// </summary>
+        [ProtoMember(3)]
+        public string name { get; set; }
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        public int year { get; set; }
+        public string progress { get; set; }
+        public List<OptionsVote> options { get; set; }
+        public bool secret { get; set; }
+        public int selectMax { get; set; }
+        public int stuCount { get; set; }
+        public string scope { get; set; }
+        public List<string> targetClassIds { get; set; }
+        /// <summary>
+        /// 发布模式 0 立即发布 1 定时
+        /// </summary>
+        [ProtoMember(5)]
+        public string publishModel { get; set; }
+
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        [ProtoMember(6)]
+        public long startTime { get; set; }
+        public long createDate { get; set; }
+
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        [ProtoMember(7)]
+        public long endTime { get; set; }
+
+
+        /// <summary>
+        /// 投票描述
+        /// </summary>
+        [ProtoMember(8)]
+        public string description { get; set; }
+
+
+/*        /// <summary>
+        /// 投票附件
+        /// </summary>
+        [ProtoMember(9)]
+        public List<ProcessRes> resource { get; set; }
+*/
+
+        /// <summary>
+        /// 状态 (100:待发布 200:已发布 300:已结束)
+        /// </summary>
+        [ProtoMember(10)]
+        public int status { get; set; }
+
+
+/*        /// <summary>
+        /// 模式
+        /// </summary>
+        [ProtoMember(11)]
+        public List<string> other { get; set; }*/
+
+/*
+        public string url { get; set; }
+
+        /// <summary>
+        /// 选项
+        /// </summary>
+        [ProtoMember(12)]
+        public List<Option> option { get; set; }*/
+
+        public int? ttl { get; set; }
+
+        public long sequenceNumber { get; set; }
+    }
+    public class OptionsVote { 
+        public string code { get; set; }
+        public string value { get; set; }
+    }
+}

+ 14 - 6
TEAMModelOS.SDK/DI/AzureServiceBus/AzureServiceBusExtensions.cs

@@ -105,17 +105,25 @@ namespace TEAMModelOS.SDK.DI
         }
 
 
-        public static async Task<long> SendLeamMessage<T>(this ServiceBusClient client, string TopicName, string id, string pk, long startTime)
+        public static async Task<long> SendLeamMessage<T>(this ServiceBusClient client, string TopicName, string id, string pk, long startTime, string progress)
         {
             //微調代碼
-            string progress = "pending";
             var timer = DateTimeOffset.FromUnixTimeMilliseconds(startTime);
-            if (timer.CompareTo(DateTimeOffset.UtcNow) < 0)
+            /*if (type.Equals("start"))
             {
-                progress = "going";
-            } else if (timer.CompareTo(DateTimeOffset.UtcNow) > 0) {
-                progress = "finish";
+                if (timer.CompareTo(DateTimeOffset.UtcNow) < 0)
+                {
+                    progress = "going";
+                }
             }
+            else if(type.Equals("end"))
+            {
+                if (timer.CompareTo(DateTimeOffset.UtcNow) < 0)
+                {
+                    progress = "finish";
+                }
+            }*/
+            
             
             //设定开始时间
             Dictionary<string, object> dict = new Dictionary<string, object>() {

+ 2 - 2
TEAMModelOS/Controllers/Exam/ExamController.cs

@@ -96,7 +96,7 @@ namespace TEAMModelOS.Controllers
                 }
                 request.stuCount = count;
                 exam = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"Exam-{code}"));
-                await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
+                await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime,"going");
                 //request.sequenceNumber = SequenceNumber;
             }
             else
@@ -112,7 +112,7 @@ namespace TEAMModelOS.Controllers
 
             //设定结束时间
             string msgEndId = _snowflakeId.NextId() + "";
-            await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.endTime);
+            await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.endTime,"finish");
             return Ok(new{ exam });
         }
         /// <summary>

+ 1 - 1
TEAMModelOS/Controllers/Task/HomeworkController.cs

@@ -160,7 +160,7 @@ namespace TEAMModelOS.Controllers.Learn
 
             //设定结束时间
             string msgEndId = _snowflakeId.NextId() + "";
-            await _serviceBus.GetServiceBusClient().SendLeamMessage<Homework>(Constants.TopicName, request.homeWork.id, request.homeWork.code, request.homeWork.endTime);
+            await _serviceBus.GetServiceBusClient().SendLeamMessage<Homework>(Constants.TopicName, request.homeWork.id, request.homeWork.code, request.homeWork.endTime,"finish");
             //_timerWorkService.TimerWork<Homework>(request.@params.homeWork.endTime, 300, new Dictionary<string, object> { { "id", request.@params.homeWork.id } });
             //清除作业
             if (request.reset)

+ 2 - 2
TEAMModelOS/Controllers/Task/SurveyController.cs

@@ -85,7 +85,7 @@ namespace TEAMModelOS.Controllers
                 {
                     survey = await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request.survey, new PartitionKey($"Survey-{code}"));
                 }*/
-                await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.survey.id, request.survey.code, request.survey.startTime);
+                await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.survey.id, request.survey.code, request.survey.startTime,"going");
 
             }
             else {
@@ -105,7 +105,7 @@ namespace TEAMModelOS.Controllers
             //Survey homeWork = await _azureCosmos.SaveOrUpdate<Survey>(request.survey);
 
             //设定结束时间
-            await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.survey.id, request.survey.code, request.survey.endTime);
+            await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.survey.id, request.survey.code, request.survey.endTime,"finish");
 
             //清除作业
             if (!request.reset)

+ 2 - 2
TEAMModelOS/Controllers/Task/VoteController.cs

@@ -108,7 +108,7 @@ namespace TEAMModelOS.Controllers.Learn
                 {
                     vote = await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request.vote, new PartitionKey($"Vote-{code}"));
                 }*/
-                await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime);
+                await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime,"going");
                 //request.vote.sequenceNumber = SequenceNumber;
 
             }
@@ -129,7 +129,7 @@ namespace TEAMModelOS.Controllers.Learn
             //设定结束时间
             //_timerWorkService.TimerWork<Vote>(request.vote.endTime, 300, new Dictionary<string, object> { { "id", request.vote.id } });
             //设定结束时间
-            await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.endTime);
+            await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.endTime,"finish");
             //清除作业
             if (!request.reset)
             {