CrazyIter_Bin 2 سال پیش
والد
کامیت
6bcaab0aa1
2فایلهای تغییر یافته به همراه98 افزوده شده و 38 حذف شده
  1. 90 30
      TEAMModelOS/Controllers/Third/Sc/ScDataInitController.cs
  2. 8 8
      TEAMModelOS/appsettings.Development.json

+ 90 - 30
TEAMModelOS/Controllers/Third/Sc/ScDataInitController.cs

@@ -57,14 +57,14 @@ namespace TEAMModelOS.Controllers.Third
         private readonly AzureServiceBusFactory _serviceBus;
         private readonly AzureRedisFactory _azureRedis;
         private readonly CoreAPIHttpService _coreAPIHttpService;
- 
+
         public readonly string type = "scsyxpt";
         private readonly HttpTrigger _httpTrigger;
         private readonly IWebHostEnvironment _environment;
         private readonly IHttpClientFactory _httpClient;
         public IConfiguration _configuration { get; set; }
-        public ScDataInitController(IHttpClientFactory httpClient,  IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
-          AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService,   HttpTrigger httpTrigger)
+        public ScDataInitController(IHttpClientFactory httpClient, IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
+          AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
@@ -75,7 +75,7 @@ namespace TEAMModelOS.Controllers.Third
             _configuration = configuration;
             _azureRedis = azureRedis;
             _coreAPIHttpService = coreAPIHttpService;
- 
+
             _httpTrigger = httpTrigger;
             _environment = environment;
             _httpClient = httpClient;
@@ -100,7 +100,7 @@ namespace TEAMModelOS.Controllers.Third
                 Dictionary<string, object> parameterMap = new Dictionary<string, object>();
                 parameterMap.Add("TrainComID", config.trainComID);
                 ScsResult result = new ScsResult { bizcode = Code, title = "5.3.1.1获取项目列表" };
-                result = await ThirdApisService.Post(_httpClient.CreateClient(),config.url, Code, config.passKey, config.privateKey, parameterMap);
+                result = await ThirdApisService.Post(_httpClient.CreateClient(), config.url, Code, config.passKey, config.privateKey, parameterMap);
                 List<ScProject> projects = result.content.ToObject<List<ScProject>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
                 List<ScProject> scProjects = await table.FindListByDict<ScProject>(new Dictionary<string, object> { { Constant.PartitionKey, "ScProject" }, { "trainComID", $"{config.trainComID}" } });
 
@@ -188,7 +188,8 @@ namespace TEAMModelOS.Controllers.Third
         [ProducesDefaultResponseType]
         [HttpPost("get-unbind-teacher")]
         [AllowAnonymous]
-        public async Task<IActionResult> getUnBindTeacher(JsonElement request) {
+        public async Task<IActionResult> getUnBindTeacher(JsonElement request)
+        {
             if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
             if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
             if (!request.TryGetProperty("dist", out JsonElement dist)) return BadRequest();
@@ -208,14 +209,15 @@ namespace TEAMModelOS.Controllers.Third
         [ProducesDefaultResponseType]
         [HttpPost("get-scs-teacher-add")]
         [AllowAnonymous]
-        public async Task<IActionResult> getScsTeacherAdd(JsonElement request) {
+        public async Task<IActionResult> getScsTeacherAdd(JsonElement request)
+        {
             if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
             if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
             if (!request.TryGetProperty("dist", out JsonElement dist)) return BadRequest();
             if (!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
             if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
             var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-           // var ScTeachers1249 = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", 1249 } });
+            // var ScTeachers1249 = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", 1249 } });
             //数据校验
             //var jsondata = ScTeachers1249.Select(x => new { x.schoolCode, x.tmdid, x.PXID, x.TID, x.TeacherName, x.SchoolName, x.SchoolID, x.Account, x.areaId }).ToJsonString();
             //当前区已有的教师
@@ -233,11 +235,11 @@ namespace TEAMModelOS.Controllers.Third
             string json_teachers = teachers.ToJsonString();
             //拿到当前期的所有且是再当前区内的学校的培训id
             var a = teachers.Select(x => $"{x.PXID}").ToList();
-            var s = ScTeachers.Select(z=>z.RowKey).ToList();
+            var s = ScTeachers.Select(z => z.RowKey).ToList();
             //新增的pxid
             var addPxid = a.Except(s).ToList();
             //原来已经有的pdxid可能需要更新的,如果需要更新,则需要判断两次的TID是否相同,不相同则需要换绑tmdid,则需要把tmdid置空
-            var updatePxid = a.Where(x=>s.Contains(x)).ToList();
+            var updatePxid = a.Where(x => s.Contains(x)).ToList();
             if (addPxid.Any())
             {
                 List<ScTeacher> newTeachers = new List<ScTeacher>();
@@ -262,22 +264,26 @@ namespace TEAMModelOS.Controllers.Third
                 });
                 await table.SaveOrUpdateAll(newTeachers);
             }
-            if (updatePxid.Any()) {
+            if (updatePxid.Any())
+            {
                 List<ScTeacher> updateTeachers = new List<ScTeacher>();
                 var allScteacher = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
-                updatePxid.ForEach(update => {
+                updatePxid.ForEach(update =>
+                {
                     //数据库的教师
                     var updateTeacherDB = ScTeachers.Find(x => $"{x.RowKey}".Equals(update));
                     //省平台的教师
                     var schoolInfo = ScSchools.Find(x => x.schoolid == updateTeacherDB.SchoolID);
                     var scTeacher = allScteacher.Find(x => $"{x.PXID}".Equals(update));
-                    if (updateTeacherDB != null && scTeacher!=null) {
+                    if (updateTeacherDB != null && scTeacher != null)
+                    {
                         if (updateTeacherDB.TID == scTeacher.TID)
                         {
                             //保持tmdid不变
                             updateTeacherDB.TID = scTeacher.TID;
                         }
-                        else {
+                        else
+                        {
                             updateTeacherDB.tmdid = null;
                         }
                         updateTeacherDB.PXID = scTeacher.PXID;
@@ -304,7 +310,7 @@ namespace TEAMModelOS.Controllers.Third
                         updateTeacherDB.schoolCode = schoolInfo?.schoolCode;
                         updateTeachers.Add(updateTeacherDB);
                     }
-                   
+
                 });
                 await table.SaveOrUpdateAll(updateTeachers);
             }
@@ -339,8 +345,8 @@ namespace TEAMModelOS.Controllers.Third
             teachers.RemoveAll(x => !ScSchools.Select(z => z.schoolid).Contains(x.SchoolID));
             string json_teachers = teachers.ToJsonString();
             var a = teachers.Select(x => $"{x.TID}").ToList();
-            string json_a=a.ToJsonString();
-            var s = ScTeachers.Where(z=>!string.IsNullOrWhiteSpace(z.tmdid)).Select(y => $"{ y.TID}").ToList();
+            string json_a = a.ToJsonString();
+            var s = ScTeachers.Where(z => !string.IsNullOrWhiteSpace(z.tmdid)).Select(y => $"{y.TID}").ToList();
             //未保存在数据库的。
             var asin = a.Except(s).ToList();
             string json_asin = asin.ToJsonString();
@@ -372,7 +378,7 @@ namespace TEAMModelOS.Controllers.Third
             #region 省平台获取到最新的教师,并添加到Table中。
             var adds = teachers.FindAll(x => asin.Contains($"{x.TID}"));
 
-            var addTeachers = ScTeachers.FindAll(x => adds.Select(y => $"{ y.PXID}").Contains($"{x.RowKey}"));
+            var addTeachers = ScTeachers.FindAll(x => adds.Select(y => $"{y.PXID}").Contains($"{x.RowKey}"));
             if (addTeachers.IsNotEmpty())
             {
                 //省平台教师替换的。
@@ -408,10 +414,11 @@ namespace TEAMModelOS.Controllers.Third
                             x.schoolCode = school?.schoolCode;
                         }
                     }
-                    else { 
+                    else
+                    {
 
                     }
-                    
+
                 });
                 addTeachers = await table.SaveOrUpdateAll(addTeachers);
             }
@@ -519,7 +526,7 @@ namespace TEAMModelOS.Controllers.Third
               });
             if (updateTch.IsNotEmpty())
             {
-               // await table.SaveOrUpdateAll(updateTch);
+                // await table.SaveOrUpdateAll(updateTch);
             }
             return Ok(new { addTeachers, update = updateTch.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }), ScTeachers });
         }
@@ -617,7 +624,7 @@ namespace TEAMModelOS.Controllers.Third
             //5.3.1.1获取项目列表
             //(status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetProjectInfoByTrainComID");
             //新的方式  5.3.1.1获取项目列表
-            (status, json) = await ScsStudyApisService.GetProjectInfoByTrainComID(_httpClient.CreateClient(), _dingDing, _azureStorage, $"{areaId}", $"{accessConfig}"); 
+            (status, json) = await ScsStudyApisService.GetProjectInfoByTrainComID(_httpClient.CreateClient(), _dingDing, _azureStorage, $"{areaId}", $"{accessConfig}");
             List<ScProject> projects = null;
             List<ScSchool> saveschools = null;
             List<ScSchool> schools = null;
@@ -633,8 +640,9 @@ namespace TEAMModelOS.Controllers.Third
             //(status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
             (status, json) = await ScsStudyApisService.GetSchoolList(_httpClient.CreateClient(), _dingDing, _azureStorage, $"{areaId}", $"{accessConfig}");
             if (status == 200)
-            {               
+            {
                 schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+                //return Ok(new { unmatch = ignore.Select(c => new { c.id ,c.name}), schools = schools.Select(x => new { x.schoolname, x.schoolCode, x.schoolid }) });
                 if (ignore.IsNotEmpty())
                 {
                     matchSchools = schools.FindAll(x => ignore.Select(y => y.name).Contains(x.schoolname));
@@ -810,18 +818,22 @@ namespace TEAMModelOS.Controllers.Third
                 string campusId = Guid.NewGuid().ToString();
                 sc.period.ForEach(x =>
                 {
-                    periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x, campusId = campusId,
+                    periods.Add(new Period
+                    {
+                        id = Guid.NewGuid().ToString(),
+                        name = x,
+                        campusId = campusId,
                         semesterCount = 2,
                         gradeCount = 1,
-                        grades=new List<string> { "一年级"},
-                        subjectCount=1,
-                        subjects=new List<Subject> { new Subject {name="预设学科" ,id= Guid.NewGuid().ToString()} },
+                        grades = new List<string> { "一年级" },
+                        subjectCount = 1,
+                        subjects = new List<Subject> { new Subject { name = "预设学科", id = Guid.NewGuid().ToString() } },
                         semesters = new List<Semester>
                         {
                             new Semester { name = "上学期", start = 1, month = 9, day = 1, id = Guid.NewGuid().ToString() },
                             new Semester { name = "下学期", start = 0, month = 3, day = 1, id = Guid.NewGuid().ToString() }
                         },
-                    }) ;
+                    });
                 });
                 School school = new School
                 {
@@ -852,12 +864,12 @@ namespace TEAMModelOS.Controllers.Third
                 }
                 catch (CosmosException ex)
                 {
-                    failedmsg.Add($"{school.ToJsonString()}\n \n{ex.Status}{ex.Message }\n ");
+                    failedmsg.Add($"{school.ToJsonString()}\n \n{ex.Status}{ex.Message}\n ");
                     schoolsfailed.Add(school);
                 }
                 catch (Exception ex)
                 {
-                    failedmsg.Add($"{school.ToJsonString()}\n{ex.Message }\n ");
+                    failedmsg.Add($"{school.ToJsonString()}\n{ex.Message}\n ");
                     schoolsfailed.Add(school);
                 }
             }
@@ -875,5 +887,53 @@ namespace TEAMModelOS.Controllers.Third
 
             });
         }
+
+        /// <summary>
+        /// 2. 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("init-project-school")]
+        [AllowAnonymous]
+        public async Task<IActionResult> InitProjectSchool(JsonElement request)
+        {
+            if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
+            if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
+            if (!request.TryGetProperty("dist", out JsonElement dist)) return BadRequest();
+            if (!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            if (!request.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
+            List<School> ignore = new List<School>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: $"select value(c) from c where c.areaId='{areaId}'",
+                requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
+            {
+                ignore.Add(item);
+            }
+            Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", $"{accessConfig}" }, { "areaId", $"{areaId}" } };
+            int status = -1; string json = null;
+            //5.3.1.1获取项目列表
+            //(status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetProjectInfoByTrainComID");
+            //新的方式  5.3.1.1获取项目列表
+            (status, json) = await ScsStudyApisService.GetProjectInfoByTrainComID(_httpClient.CreateClient(), _dingDing, _azureStorage, $"{areaId}", $"{accessConfig}");
+            List<ScProject> projects = null;
+            List<ScSchool> saveschools = null;
+            List<ScSchool> schools = null;
+            List<ScSchool> matchSchools = null;
+            List<ScSchool> tbschools = null;
+            if (status == 200)
+            {
+                projects = json.ToObject<List<ScProject>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+            }
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+
+            // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
+            //(status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
+            (status, json) = await ScsStudyApisService.GetSchoolList(_httpClient.CreateClient(), _dingDing, _azureStorage, $"{areaId}", $"{accessConfig}");
+            if (status == 200)
+            {
+                schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+            }
+            return Ok();
+        }
     }
 }

+ 8 - 8
TEAMModelOS/appsettings.Development.json

@@ -22,22 +22,22 @@
   },
   "Azure": {
     "Storage": {
-      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodeltest;AccountKey=O2W2vadCqexDxWO+px+QK7y1sHwsYj8f/WwKLdOdG5RwHgW/Dupz9dDUb4c1gi6ojzQaRpFUeAAmOu4N9E+37A==;EndpointSuffix=core.chinacloudapi.cn"
+      "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelos;AccountKey=Dl04mfZ9hE9cdPVO1UtqTUQYN/kz/dD/p1nGvSq4tUu/4WhiKcNRVdY9tbe8620nPXo/RaXxs+1F9sVrWRo0bg==;EndpointSuffix=core.chinacloudapi.cn"
     },
     "Cosmos": {
-      "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
+      "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
     },
     "Redis": {
-      "ConnectionString": "52.130.252.100:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"
+      "ConnectionString": "CoreRedisCN.redis.cache.chinacloudapi.cn:6380,password=LyJWP1ORJdv+poXWofAF97lhCEQPg1wXWqvtzXGXQuE=,ssl=True,abortConnect=False"
     },
     "ServiceBus": {
-      "ConnectionString": "Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=",
-      "ActiveTask": "dep-active-task",
-      "ItemCondQueue": "dep-itemcond",
-      "GenPdfQueue": "dep-genpdf"
+      "ConnectionString": "Endpoint=sb://coreiotservicebuscnpro.servicebus.chinacloudapi.cn/;SharedAccessKeyName=TEAMModelOS;SharedAccessKey=llRPBMDJG9w1Nnifj+pGhV0g4H2REcq0PjvX2qqpcOg=",
+      "ActiveTask": "active-task",
+      "ItemCondQueue": "itemcond",
+      "GenPdfQueue": "genpdf"
     },
     "SignalR": {
-      "ConnectionString": "Endpoint=https://channel.service.signalr.net;AccessKey=KrblW06tuA4a/GyqRPDU0ynFFmAWxbAvyJihHclSXbQ=;Version=1.0;"
+      "ConnectionString": "Endpoint=https://channel.signalr.azure.cn;AccessKey=AtcB7JYFNUbUXb1rGxa3PVksQ2X5YSv3JOHZR9J88tw=;Version=1.0;"
     }
   },
   "HaBookAuth": {