Browse Source

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

XW 2 years ago
parent
commit
f71cd065b4

+ 27 - 16
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -2394,6 +2394,9 @@ namespace TEAMModelBI.Controllers.BISchool
         public async Task<IActionResult> SetScPeriod(JsonElement jsonElement)
         {
             if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
+            if (!jsonElement.TryGetProperty("periodName", out JsonElement periodName)) return BadRequest();
+
+            List<string> periodNames = $"{periodName}".ToObject<List<string>>();
             jsonElement.TryGetProperty("Language", out JsonElement Language);
 
             var cosmosClient = _azureCosmos.GetCosmosClient();
@@ -2423,34 +2426,42 @@ namespace TEAMModelBI.Controllers.BISchool
             School school = null;
 
             school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{scId}", new PartitionKey("Base"));
+            
             if (school != null)
             {
-                school.period.Add(new Period
+                foreach (var item in periodNames)
                 {
-                    id = Guid.NewGuid().ToString(),
-                    name = "默认学段",
-                    campusId = campusId,
-                    semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
+                    if (school.campuses.Count > 0)
+                        campusId = school.campuses.Select(x => x.id).FirstOrDefault().ToString();
+
+                    school.period.Add(new Period
+                    {
+                        id = Guid.NewGuid().ToString(),
+                        name = item,
+                        campusId = campusId,
+                        semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
                         new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
-                    subjects = new List<Subject>() {
+                        subjects = new List<Subject>() {
                         new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
                         new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
                         new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
                         },
-                    grades = schoolConfig.grades,
-                    analysis = new Analysis()
-                    {
-                        type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
+                        grades = schoolConfig.grades,
+                        analysis = new Analysis()
+                        {
+                            type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
                         new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[1].name },
                         new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[2].name },
                         new ExamSimple { id = Guid.NewGuid().ToString(), name =  schoolConfig.PresetExam[0].type[3].name } },
-                        income = schoolConfig.PresetExam[0].income,
-                        eugenics = schoolConfig.PresetExam[0].eugenics,
-                        touch = schoolConfig.PresetExam[0].touch
-                    }
-                });
+                            income = schoolConfig.PresetExam[0].income,
+                            eugenics = schoolConfig.PresetExam[0].eugenics,
+                            touch = schoolConfig.PresetExam[0].touch
+                        }
+                    });
+                }
 
-                school.campuses.Add(new Campus { name = school.name, id = campusId });
+                if (!school.campuses.Select(x => x.id).Contains(campusId))
+                    school.campuses.Add(new Campus { name = school.name, id = campusId });
             }
 
             school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));

+ 4 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1423,7 +1423,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                     BlobDownloadResult timelineblobDownload = await _azureStorage.GetBlobContainerClient(blobname).GetBlobClient($"/records/{_lessonId}/IES/TimeLine.json").DownloadContentAsync();
                                     TimeLineData timeLineData = timelineblobDownload.Content.ToObjectFromJson<TimeLineData>();
                                     lessonRecord.hitaClientCmpCount = timeLineData.events.Where(z => !string.IsNullOrWhiteSpace(z.WrkCmpSrcType) && z.WrkCmpSrcType.Equals("HitaClientCmp")).Count();
-                                    lessonRecord.collateTaskCount = lessonRecord.hitaClientCmpCount;
+                                    //lessonRecord.collateTaskCount = lessonRecord.hitaClientCmpCount;
                                 } catch {
                                 }
 
@@ -1441,7 +1441,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                                         lessonRecord.clientCount = lessonBase.summary.clientCount;
                                         lessonRecord.attendRate = lessonBase.summary.attendRate;
                                         lessonRecord.groupCount = lessonBase.summary.groupCount;
-                                        lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount+ lessonRecord.hitaClientCmpCount;
+                                        lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount;
+                                        lessonRecord.hitaClientCmpCount = lessonBase.summary.collateTaskCount+ lessonRecord.hitaClientCmpCount;
                                         lessonRecord.collateCount = lessonBase.summary.collateCount;
                                         lessonRecord.pushCount = lessonBase.summary.pushCount;
                                         lessonRecord.totalPoint = lessonBase.summary.totalPoint;
@@ -1488,7 +1489,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
 
                                             //}
 
-                                            int a = lessonRecord.collateTaskCount;
+                                            int a = lessonRecord.hitaClientCmpCount;
                                             int b = lessonRecord.pushCount;
                                             int c = lessonRecord.examCount;
                                             switch (true)

+ 77 - 0
TEAMModelOS.SDK/Models/Cosmos/OpenEntity/OStudent.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.OpenEntity
+{
+    public class OStudent
+    {
+        /// <summary>
+        /// 学生id
+        /// </summary>
+        public string id { get; set; }
+        /// <summary>
+        /// 学生名称
+        /// </summary>
+        public string name { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        public string picture { get; set; }
+        /// <summary>
+        /// 学校ID
+        /// </summary>
+        public string schoolId { get; set; }
+        /// <summary>
+        /// 邮箱
+        /// </summary>
+        public string mail { get; set; }
+        /// <summary>
+        /// 手机号
+        /// </summary>
+        public string mobile { get; set; }
+        /// <summary>
+        /// 国家
+        /// </summary>
+        public string country { get; set; }
+        /// <summary>
+        /// 入学年
+        /// </summary>
+        public int year { get; set; }
+        /// <summary>
+        /// 座号
+        /// </summary>
+        public string no { get; set; }
+        /// <summary>
+        /// 班级Id
+        /// </summary>
+        public string classId { get; set; }
+        /// <summary>
+        /// 分组id
+        /// </summary>
+        public string groupId { get; set; }
+        /// <summary>
+        /// 分组名称
+        /// </summary>
+        public string groupName { get; set; }
+        /// <summary>
+        /// 学段id
+        /// </summary>
+        public string periodId { get; set; }
+        /// <summary>
+        /// 性别 M( male,男) F (female 女)  N(secret 保密) 
+        /// </summary>
+        public string gender { get; set; }
+        /// <summary>
+        /// 补充留级信息
+        /// 0在校,1毕业 
+        /// </summary>
+        public int graduate { get; set; } = 0;
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        public long createTime { get; set; }
+    }
+}

+ 5 - 2
TEAMModelOS.SDK/Models/Service/StatisticsService.cs

@@ -1,5 +1,6 @@
 using Azure.Cosmos;
 using Azure.Messaging.ServiceBus;
+using DocumentFormat.OpenXml.Spreadsheet;
 using HTEXLib.COMM.Helpers;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.Configuration;
@@ -240,6 +241,7 @@ namespace TEAMModelOS.SDK
                         name = member.name,
                         picture = member.picture,
                         school = school,
+                        groupName=member.groupName,
                         update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
                     });
                 }
@@ -272,7 +274,7 @@ namespace TEAMModelOS.SDK
                     x.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
                     x.nickname = mbm?.nickname;
                     x.picture = mbm?.picture;
-
+                    x.groupName = mbm?.groupName;
                 }
             });
             return (returnTrains, yxtrain, updateTeacherTrains);
@@ -327,6 +329,7 @@ namespace TEAMModelOS.SDK
                         name = member.name,
                         picture = member.picture,
                         school = school,
+                        groupName = member.groupName,
                         update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
                     });
                 }
@@ -356,7 +359,7 @@ namespace TEAMModelOS.SDK
                     x.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
                     x.nickname = mbm?.nickname;
                     x.picture = mbm?.picture;
-                    
+                    x.groupName = mbm?.groupName;
                 }
             });
 

+ 4 - 0
TEAMModelOS/Controllers/Normal/AbilityStatisticsController.cs

@@ -283,6 +283,8 @@ namespace TEAMModelOS.Controllers
                         x.school,
                         x.id,
                         x.totalTime,
+                        x.groupName,
+                        x.picture,
                         currency = new {
                             x.currency.submitTime,
                             x.currency.exerciseAbility,
@@ -445,6 +447,8 @@ namespace TEAMModelOS.Controllers
                         x.school,
                         x.id,
                         x.totalTime,
+                        x.groupName,
+                        x.picture,
                         currency = new
                         {
                             x.currency.submitTime,

+ 17 - 0
TEAMModelOS/Controllers/OpenApi/Business/BizOverallEducationController.cs

@@ -61,6 +61,23 @@ namespace TEAMModelOS.Controllers
             var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing, id, school, jsonElement);
             return Ok(new { responseData });
         }
+
+        /// <summary>
+        /// 学生详细信息
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-student-info")]
+        [ApiToken(Auth = "1902", Name = "学生详细信息", TName = "學生詳細信息", EName = "Student Details", RWN = "R", Limit = false)]
+        public async Task<IActionResult> GetLoginStuInfo(JsonElement jsonElement) 
+        {
+            var (id, school) = HttpContext.GetApiTokenInfo();
+            //if(!jsonElement.TryGetProperty("schoolId",out JsonElement schoolId)) return Ok(new { code = RespondCode.ParamsError, msg = "参数错误:schoolId", data = "" });
+            var responseData = await OpenApiService.GetLoginStuInfo(_azureCosmos, _dingDing, _option, id, school, jsonElement);
+            return Ok(new { responseData });
+        }
+
         ///数据结构说明
         /**
          *

+ 85 - 0
TEAMModelOS/Controllers/OpenApi/OpenApiService.cs

@@ -34,6 +34,8 @@ using Microsoft.OData.Edm;
 using TEAMModelOS.Controllers.Core;
 using DocumentFormat.OpenXml.VariantTypes;
 using static TEAMModelOS.Controllers.CourseController;
+using System.IdentityModel.Tokens.Jwt;
+using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 
 namespace TEAMModelOS.Controllers
 {
@@ -1744,5 +1746,88 @@ namespace TEAMModelOS.Controllers
             string datawebHooks = webHooks.ToJsonString();
         }
 
+        /// <summary>
+        /// 学生登录信息
+        /// </summary>
+        /// <param name="_azureCosmos"></param>
+        /// <param name="_dingDing"></param>
+        /// <param name="bizId"></param>
+        /// <param name="school"></param>
+        /// <param name="json"></param>
+        /// <returns></returns>
+        public static async Task<ResponseData<dynamic>> GetLoginStuInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, Option _option, string bizId, string school, JsonElement json)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                if (!json.TryGetProperty("idToken", out JsonElement _idToken)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "idToken参数错误", data = null };
+                //if (!string.IsNullOrWhiteSpace($"{_idToken}") && JwtAuthExtension.ValidateApiToken($"{_idToken}", _option.JwtSecretKey))
+                //{
+                //    JwtSecurityToken jwt = new($"{_idToken}");
+                //}
+                OStudent student = new();
+                JwtSecurityToken jwt = new($"{_idToken}");
+                var iss = jwt.Payload.Iss;
+                var stuId = jwt.Payload.Sub;
+                var scId = jwt.Payload.Azp;
+                jwt.Payload.TryGetValue("name", out object stuName);
+                jwt.Payload.TryGetValue("picture", out object stuPicture);
+                if(!jwt.Payload.TryGetValue("scope", out object scope)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:scope", data = null };
+                if(!jwt.Payload.TryGetValue("roles", out object _roles)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:roles", data = null };
+                jwt.Payload.TryGetValue("permissions", out object permissions);
+                jwt.Payload.TryGetValue("standard", out object standard);
+                jwt.Payload.TryGetValue("area", out object area);
+                jwt.Payload.TryGetValue("website", out object website);
+
+                List<string> roles = $"{_roles}".ToObject<List<string>>();
+                if (roles.Contains("student") && $"{scope}".Equals("student")) 
+                {
+                    if (!string.IsNullOrEmpty(stuId) && !string.IsNullOrEmpty(scId))
+                    {
+                        if (school.Equals(scId))
+                        {
+                            var responseStu = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(stuId, new PartitionKey($"Base-{scId}"));
+                            if (responseStu.Status == 200)
+                            {
+                                JsonDocument jsonD = JsonDocument.Parse(responseStu.Content);
+                                student = jsonD.RootElement.ToObject<OStudent>();
+                                switch (student.gender)
+                                {
+                                    case "M":
+                                        student.gender = "男";
+                                        break;
+                                    case "F":
+                                        student.gender = "女";
+                                        break;
+                                    case "N":
+                                        student.gender = "保密";
+                                        break;
+                                }
+                            }
+                            else
+                                return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到该学生", data = new { id = stuId, schoolId = scId } };
+                        }
+                        else
+                            return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "headers和idToken中的学校ID不匹配", data = null };
+                    }
+                    else
+                        return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:Sub/scId", data = null };
+                }
+                else
+                    return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:roles/Azp", data = null };
+
+
+                return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = student };
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetLoginStuInfo()   参数:stu:{_stuId},school:{school},json:{json.ToJsonString()} \n  {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务器错误" };
+            }
+
+
+
+        }
+
     }
 }

+ 57 - 0
TEAMModelOS/Controllers/OpenApi/OpenSchool/ScStudentController.cs

@@ -0,0 +1,57 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Options;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Filter;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+
+namespace TEAMModelOS.Controllers
+{
+    [Route("school")]
+    [ApiController]
+    public class ScStudentController : ControllerBase
+    {
+        private AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly AzureStorageFactory _azureStorage;
+        public IConfiguration _configuration { get; set; }
+        private readonly CoreAPIHttpService _coreAPIHttpService;
+
+
+        public ScStudentController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _serviceBus = serviceBus;
+            _configuration = configuration;
+            _azureStorage = azureStorage;
+            _coreAPIHttpService = coreAPIHttpService;
+        }
+
+        /// <summary>
+        /// 学生详细信息
+        /// </summary>
+        /// <param name="jsonElement"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-student-info")]
+        [ApiToken(Auth = "2000", Name = "学生详细信息", TName = "學生詳細信息", EName = "Student Details", RWN = "R", Limit = false)]
+        public async Task<IActionResult> GetLoginStuInfo(JsonElement jsonElement)
+        {
+            var (id, school) = HttpContext.GetApiTokenInfo();
+
+            var responseDate = await OpenApiService.GetLoginStuInfo(_azureCosmos, _dingDing, _option, id, school, jsonElement);
+
+            return Ok(new { responseDate });
+        }
+    }
+
+}