CrazyIter_Bin 3 years ago
parent
commit
002f9ec9fb

+ 4 - 0
TEAMModelOS.SDK/Models/Cosmos/School/SchoolTeacher.cs

@@ -15,6 +15,10 @@ namespace TEAMModelOS.SDK.Models
         public List<string> permissions { get; set; } = new List<string>();
         public List<string> permissions { get; set; } = new List<string>();
         public string status { get; set; }
         public string status { get; set; }
         public long createTime { get; set; }
         public long createTime { get; set; }
+        /// <summary>
+        /// ½ÌʦµÄ¿ÆÄ¿Êý×é
+        /// </summary>
+        public List<string> subjectIds { get; set; }=new List<string>();
         //public string groupId { get; set; }
         //public string groupId { get; set; }
         //public string groupName { get; set; }
         //public string groupName { get; set; }
     }
     }

+ 23 - 1
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -110,7 +110,7 @@ namespace TEAMModelOS.Controllers
                 Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(userid, new PartitionKey("Base"));
                 Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(userid, new PartitionKey("Base"));
                 switch (true)
                 switch (true)
                 {
                 {
-                    //修改默认学校
+                        //修改默认学校
                     case bool when $"{_opt}".Equals("UpdateDefaultSchool", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)):
                     case bool when $"{_opt}".Equals("UpdateDefaultSchool", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)):
                         if (teacher.schools.Select(x => x.schoolId).Contains($"{_defaultSchool}") && !string.IsNullOrEmpty($"{_defaultSchool}"))
                         if (teacher.schools.Select(x => x.schoolId).Contains($"{_defaultSchool}") && !string.IsNullOrEmpty($"{_defaultSchool}"))
                         {
                         {
@@ -122,6 +122,28 @@ namespace TEAMModelOS.Controllers
                         {
                         {
                             return BadRequest(new { status = -1, msg = "您未加入该学校!" });
                             return BadRequest(new { status = -1, msg = "您未加入该学校!" });
                         }
                         }
+                        //设置教师的科目信息
+                    case bool when $"{_opt}".Equals("SetTeacherSubject", StringComparison.OrdinalIgnoreCase) && request.TryGetProperty("targerTecher", out JsonElement _targetTecher) 
+                        && request.TryGetProperty("subjectIds", out JsonElement _subjectIds):
+                        if (_subjectIds.ValueKind.Equals(JsonValueKind.Array))
+                        {
+                            try
+                            {
+                                SchoolTeacher schoolTeacher = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{_targetTecher}", new PartitionKey($"Teacher-{school}"));
+                                schoolTeacher.subjectIds = _subjectIds.ToObject<List<string>>();
+                                await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, $"{_targetTecher}", new PartitionKey($"Teacher-{school}"));
+                                return Ok(new { status = 1 , schoolTeacher });
+                            }
+                            catch (Exception ex)
+                            {
+                                await _dingDing.SendBotMsg($"IES5,{_option.Location},Teacher/init/set-teacher-info:SetTeacherSubject()\n{ex.Message}{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                                return Ok(new { error = -1, msg = "设置失败" });
+                            }
+                        }
+                        else {
+                            return Ok(new { error = -1, msg = "设置失败" });
+                        }
+                        ///移交管理员
                     case bool when $"{_opt}".Equals("TransferAdminRole", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("targerTecher", out JsonElement _targetTecher)):
                     case bool when $"{_opt}".Equals("TransferAdminRole", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("targerTecher", out JsonElement _targetTecher)):
                         if (!string.IsNullOrEmpty(school) && !string.IsNullOrEmpty($"{_targetTecher}"))
                         if (!string.IsNullOrEmpty(school) && !string.IsNullOrEmpty($"{_targetTecher}"))
                         {
                         {

+ 31 - 10
TEAMModelOS/Controllers/Third/ScController.cs

@@ -107,7 +107,10 @@ namespace TEAMModelOS.Controllers.Third
         [HttpPost("sc/get-project-school-teacher")]
         [HttpPost("sc/get-project-school-teacher")]
         [AllowAnonymous]
         [AllowAnonymous]
         public async Task<IActionResult> GetProjectSchoolTeacher(JsonElement request) {
         public async Task<IActionResult> GetProjectSchoolTeacher(JsonElement request) {
-          // await _azureStorage.DeleteAll<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
+            List<ScSchool > delScSchool = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" },{ "areaId", "99a4a33b-e21b-44ac-80a1-b31dc40496e0" } });
+            await _azureStorage.DeleteAll(delScSchool);
+            List <ScTeacher> delScTeacher = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "99a4a33b-e21b-44ac-80a1-b31dc40496e0" } });
+            await _azureStorage.DeleteAll(delScTeacher);
             if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
             if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
             if (!request.TryGetProperty("ignoreSchools", out JsonElement ignoreSchools)) return BadRequest();
             if (!request.TryGetProperty("ignoreSchools", out JsonElement ignoreSchools)) return BadRequest();
             if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
             if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
@@ -142,7 +145,10 @@ namespace TEAMModelOS.Controllers.Third
                         {
                         {
                             var matched = matchSchools.Select(x => x.schoolname);
                             var matched = matchSchools.Select(x => x.schoolname);
                             var unmatch = ignore.Select(y => y.name).Except(matched);
                             var unmatch = ignore.Select(y => y.name).Except(matched);
-                            return Ok(new { matched, unmatch });
+                            List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
+                            if (scschoolUnmatch.IsNotEmpty()) {
+                                return Ok(new { matched, unmatch, scschoolUnmatch });
+                            }
                         }
                         }
                         else {
                         else {
                             matchSchools.ForEach(x => {
                             matchSchools.ForEach(x => {
@@ -161,7 +167,7 @@ namespace TEAMModelOS.Controllers.Third
                     }
                     }
                 }
                 }
                 //数据校验
                 //数据校验
-               tbschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() {  { "PartitionKey", $"ScSchool" } });
+               tbschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() {  { "PartitionKey", "ScSchool" } });
                 if (tbschools.IsNotEmpty())
                 if (tbschools.IsNotEmpty())
                 {
                 {
                   
                   
@@ -181,6 +187,7 @@ namespace TEAMModelOS.Controllers.Third
                         }
                         }
                     });
                     });
 
 
+
                     schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
                     schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
                     saveschools.ForEach(x => {
                     saveschools.ForEach(x => {
 
 
@@ -206,15 +213,22 @@ namespace TEAMModelOS.Controllers.Third
                         x.areaId = $"{areaId}";
                         x.areaId = $"{areaId}";
                         x.city = $"{city}";
                         x.city = $"{city}";
                         x.dist = $"{dist}";
                         x.dist = $"{dist}";
-                        if (string.IsNullOrEmpty(x.schoolCode))
-                        {
-                            schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
+                        var a = ignore.Find(z => z.name.Equals(x.schoolname));
+                        if (a != null) {
+                            x.schoolCode = a.id;
+                        }
+                        else {
+                            if (string.IsNullOrEmpty(x.schoolCode))
+                            {
+                                schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
+                            }
                         }
                         }
-                        
                     });
                     });
+                     
+                    
+
                     schoolDatas   = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
                     schoolDatas   = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
                     schools.ForEach(x => {
                     schools.ForEach(x => {
-                       
                         var schoolData =  schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
                         var schoolData =  schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
                         if (schoolData != null && !string.IsNullOrEmpty(schoolData.id)) {
                         if (schoolData != null && !string.IsNullOrEmpty(schoolData.id)) {
                             x.schoolCode = schoolData.id;
                             x.schoolCode = schoolData.id;
@@ -225,7 +239,7 @@ namespace TEAMModelOS.Controllers.Third
                     });
                     });
 
 
                    schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
                    schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
-                   saveschools = await _azureStorage.SaveAll(schools);
+                   saveschools = await _azureStorage.SaveOrUpdateAll(schools);
                 }
                 }
             }
             }
            
            
@@ -300,7 +314,7 @@ namespace TEAMModelOS.Controllers.Third
                 };
                 };
                 try
                 try
                 {
                 {
-                    await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(school, new PartitionKey(school.code));
+                    //await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(school, new PartitionKey(school.code));
                     schoolsScucess.Add(school);
                     schoolsScucess.Add(school);
                 }
                 }
                 catch (CosmosException ex)
                 catch (CosmosException ex)
@@ -321,13 +335,20 @@ namespace TEAMModelOS.Controllers.Third
             (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetTeachersListByProject");
             (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetTeachersListByProject");
             if (status == 200)
             if (status == 200)
             {
             {
+                var all = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", $"ScSchool" }, { "areaId", $"{areaId}" } });
                 teachers = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
                 teachers = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
                 if (teachers.IsNotEmpty()) {
                 if (teachers.IsNotEmpty()) {
                     teachers.ForEach(x => {
                     teachers.ForEach(x => {
+
+                        ScSchool scSchool= all.Find(y => y.schoolid == x.SchoolID);
+                        if (scSchool != null) {
+                            x.schoolCode = scSchool.schoolCode;
+                        }
                         x.RowKey = $"{x.PXID}";
                         x.RowKey = $"{x.PXID}";
                         x.PartitionKey = "ScTeacher";
                         x.PartitionKey = "ScTeacher";
                         x.areaId = $"{areaId}";
                         x.areaId = $"{areaId}";
                     });
                     });
+
                     areaTeacher = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
                     areaTeacher = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
                     if (areaTeacher.IsNotEmpty())
                     if (areaTeacher.IsNotEmpty())
                     {
                     {