Browse Source

update 省平台对接。

CrazyIter_Bin 3 years ago
parent
commit
b2cf4e63f8

+ 44 - 1
TEAMModelOS.FunctionV4/HttpTrigger/ScsYxptApis.cs

@@ -35,7 +35,50 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             _azureRedis = azureRedis;
             _thirdApisService = thirdApisService;
         }
-        
+        /// <summary>
+        /// 5.3.1.1获取项目列表
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [Function("GetProjectInfoByTrainComIDV2")]
+        public async Task<HttpResponseData> GetProjectInfoByTrainComIDV2([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
+        {
+            var response = req.CreateResponse(HttpStatusCode.OK);
+            List<ScProject> projects = new List<ScProject>();
+            string data = await new StreamReader(req.Body).ReadToEndAsync();
+            JsonElement accessConfig = data.ToObject<JsonElement>().GetProperty("accessConfig");
+            ScAccessConfig config = $"{accessConfig}".ToObject<ScAccessConfig>();
+            string areaId = null;
+            if (data.ToObject<JsonElement>().TryGetProperty("areaId", out JsonElement _areaId))
+            {
+                areaId = $"{_areaId}";
+            }
+            Code = "GetProjectInfoByTrainComID";
+            parameterMap = new Dictionary<string, object>();
+            parameterMap.Add("TrainComID", config.trainComID);
+            ScsResult result = new ScsResult { code = Code, title = "5.3.1.1获取项目列表" };
+            try
+            {
+                result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
+                if (result.result)
+                {
+                    projects = result.content.ToObject<List<ScProject>>();
+                }
+                else
+                {
+
+                }
+                await response.WriteAsJsonAsync(new { data = projects.ToJsonString() });
+                return response;
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")},IES5.ScApisService:GetProjectInfoByTrainComID\n{ex.Message}{ex.StackTrace}\n{result.ToJsonString()}\n{data}", GroupNames.成都开发測試群組);
+                await response.WriteAsJsonAsync(new { data = projects.ToJsonString() });
+                return response;
+            }
+        }
         /// <summary>
         /// 5.3.1.1获取项目列表
         /// </summary>

+ 33 - 3
TEAMModelOS.SDK/Models/Service/Third/Sc/ScYxptModel.cs

@@ -51,15 +51,45 @@ namespace TEAMModelOS.SDK.Models
         public string DiagnosisDicNum { get; set; }
         public int ID { get; set; }
     }
-    public class ScProject
-    {
+    [TableName(Name = "ScYxpt")]
+    public class ScComConfig : TableEntity
+    { /// <summary>
+      /// pk="ScComConfig"
+      /// rk=$"{trainComID}"
+      /// </summary>
+        public string passKey { get; set; }
+        public string trainComID { get; set; }
+        public string trainComName { get; set; }
+        public string privateKey { get; set; }
+        public string url { get; set; }
+    }
+
+    [TableName(Name = "ScYxpt")]
+    public class ScProject : TableEntity
+    {  /// <summary>
+       /// pk="ScProject"
+       /// rk=$"{ProjectItemID}"
+       /// </summary>
+       /// <summary>
+       /// ["pdf"]
+       /// </summary>
+        public string homeworkType { get; set; }
+        public string areaId { get; set; }
+        public string areaName{ get; set; }
+        public string path { get; set; }
+        public string passKey { get; set; }
+        public string trainComID { get; set; }
+        public string privateKey { get; set; }
+        public string url { get; set; }
+        public string standard { get; set; }
+        public string config { get; set; } = "scsyxpt";//scsyxpt
         public int ProjectID { get; set; }
         public string ProjectTitle { get; set; }
         public int ProjectItemID { get; set; }
         public string ProjectItemTitle { get; set; }
         public int TCount { get; set; }
         public int IsQuota { get; set; }
-        public bool IsDiagnosis { get; set; }
+        public int IsDiagnosis { get; set; }
         public int SchoolDiagnosisMinDimension { get; set; }
         public int SchoolDiagnosisMinCount { get; set; }
         public int TeacherDiagnosisMinDimension { get; set; }

+ 32 - 62
TEAMModelOS/Controllers/Third/Sc/ScApiController.cs

@@ -55,22 +55,7 @@ namespace TEAMModelOS.Controllers
         private readonly ThirdApisService _scsApisService;
         public readonly string type = "scsyxpt";
         private readonly HttpTrigger _httpTrigger;
-        /// <summary>
-        /// 机构安全码
-        /// </summary>
-        public string _sc_passKey;
-        /// <summary>
-        /// 机构ID
-        /// </summary>
-        public string _sc_trainComID;
-        /// <summary>
-        /// 机构 AES 密钥
-        /// </summary>
-        public string _sc_privateKey;
-        /// <summary>
-        /// 访问地址
-        /// </summary>
-        public string _sc_url;
+         private List<ScComConfig> scsyxptConfigs { get; set; }
         public IConfiguration _configuration { get; set; }
         public ScApiController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
          AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService accountHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
@@ -85,25 +70,10 @@ namespace TEAMModelOS.Controllers
             _azureRedis = azureRedis;
             _accountHttpService = accountHttpService;
             _scsApisService = scsApisService;
-            _sc_passKey = _configuration.GetValue<string>("Third:scsyxpt:passKey");
-            _sc_trainComID = _configuration.GetValue<string>("Third:scsyxpt:trainComID");
-            _sc_privateKey = _configuration.GetValue<string>("Third:scsyxpt:privateKey");
-            _sc_url = _configuration.GetValue<string>("Third:scsyxpt:url");
+           
             _httpTrigger = httpTrigger;
         }
-        /// <summary>
-        ///
-        /// </summary>
-        /// <param name="json"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("sc/fix-table-data")]
-        [AllowAnonymous]
-        public async Task<IActionResult> FixTableData(JsonElement json ) {
-
-            // _azureStorage.FindListByDict()
-            return Ok();
-        }
+         
         /// <summary>
         ///
         /// </summary>
@@ -114,14 +84,14 @@ namespace TEAMModelOS.Controllers
         [AllowAnonymous]
         public async Task<IActionResult> GetProjectList(List<Unbind> unbinds)
         {
-
-
+            scsyxptConfigs= await _azureStorage.FindListByDict<ScComConfig>(new Dictionary<string, object> { { Constant.PartitionKey, "ScComConfig" } });
+            ScComConfig scsyxptConfig= scsyxptConfigs[0];
             // 5.3.1.1获取项目列表 
-            string trainComID = _sc_trainComID;
+            string trainComID = scsyxptConfig.trainComID;
             string Code = "GetProjectInfoByTrainComID";
             Dictionary<string, object> parameterMap = new Dictionary<string, object>();
-            parameterMap.Add("TrainComID", _sc_trainComID);
-            ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            parameterMap.Add("TrainComID", scsyxptConfig.trainComID);
+            ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetProjectInfoByTrainComID.code = Code;
             GetProjectInfoByTrainComID.title = "5.3.1.1获取项目列表";
 
@@ -132,7 +102,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("ProjectID", "92");
             parameterMap.Add("ProjectItemID", "1131");
-            ScsResult GetSchoolList1 = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetSchoolList1 = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetSchoolList1.code = Code;
             GetSchoolList1.title = "5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表";
 
@@ -142,7 +112,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("ProjectID", "82");
             parameterMap.Add("ProjectItemID", "1086");
-            ScsResult GetProjectDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetProjectDiagnosis = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetProjectDiagnosis.code = Code;
             GetProjectDiagnosis.title = "5.3.1.19获取项目设置的可选能力点";
             // 补充
@@ -153,7 +123,7 @@ namespace TEAMModelOS.Controllers
             //parameterMap.Add("ProjectID", "22");
             //parameterMap.Add("ProjectItemID", "22");
             parameterMap.Add("PXID", "242849");
-            ScsResult GetDiagnosisListByProject_V2 = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetDiagnosisListByProject_V2 = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetDiagnosisListByProject_V2.code = Code;
             GetDiagnosisListByProject_V2.title = "5.3.1.3通过项目编号获取学员测评能力项V2";
 
@@ -164,7 +134,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("ProjectID", "82");
             parameterMap.Add("ProjectItemID", "1086");
-            ScsResult GetTeachersListByProject = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetTeachersListByProject = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetTeachersListByProject.code = Code;
 
 
@@ -176,7 +146,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("Pxid", "254175");
             parameterMap.Add("Tid", "422152");
-            ScsResult GetSingleTeacherByProject = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetSingleTeacherByProject = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetSingleTeacherByProject.code = Code;
             GetSingleTeacherByProject.title = "5.3.1.11获取跳转学员信息";
 
@@ -192,7 +162,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("ProjectID", "22");
             parameterMap.Add("ProjectItemID", "24");
             parameterMap.Add("PXID", "65321");
-            ScsResult GetDiagnosisListByProject = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetDiagnosisListByProject = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetDiagnosisListByProject.code = Code;
             GetDiagnosisListByProject.title = "5.3.1.3通过项目编号获取学员测评能力项";
 
@@ -205,7 +175,7 @@ namespace TEAMModelOS.Controllers
             //parameterMap.Add("ProjectID", "22");
             //parameterMap.Add("ProjectItemID", "22");
             parameterMap.Add("PXID", "244188");
-            ScsResult GetDiagnosisListByProject_V2T = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetDiagnosisListByProject_V2T = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetDiagnosisListByProject_V2T.code = Code;
             GetDiagnosisListByProject_V2T.title = "5.3.1.3通过项目编号获取学员测评能力项V2";
 
@@ -222,7 +192,7 @@ namespace TEAMModelOS.Controllers
                 parameterMap.Add("CourseHour", "50");
                 parameterMap.Add("ResearchText", "");//学习成果描述,字符长度<=300
                 parameterMap.Add("ComPassed", "1");//0、未认定  1、合格  2、优秀  3、不合格  4、其他
-                UpdateTeacherSituation = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+                UpdateTeacherSituation = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
                 UpdateTeacherSituation.code = Code;
                 UpdateTeacherSituation.title = "5.3.1.4学员培训基本情况回写";
             }
@@ -250,7 +220,7 @@ namespace TEAMModelOS.Controllers
                 pfileMapA.Add("md5", "9c3da8c5c07c2c660cd73c01f56d7fca");
                 pfileMapA.Add("fileType", "pdf");
                 pfilesA.Add(pfileMapA);
-                UpdateTeacherDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+                UpdateTeacherDiagnosis = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
                 UpdateTeacherDiagnosis.code = Code;
                 UpdateTeacherDiagnosis.title = "5.3.1.5学员能力点测评结果回写";
             }
@@ -263,7 +233,7 @@ namespace TEAMModelOS.Controllers
             Code = "GetDiagnosisDic";
             parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", trainComID);
-            ScsResult GetDiagnosisDic = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetDiagnosisDic = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetDiagnosisDic.code = Code;
             GetDiagnosisDic.title = "5.3.1.6获取能力测评体系字典值数据";
 
@@ -273,7 +243,7 @@ namespace TEAMModelOS.Controllers
             parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("DiagnosisDicID", "3");
-            ScsResult GetDiagnosisItemDic = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetDiagnosisItemDic = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetDiagnosisItemDic.code = Code;
             GetDiagnosisItemDic.title = "5.3.1.7获取能力测评评价类型字典值数据";
 
@@ -283,7 +253,7 @@ namespace TEAMModelOS.Controllers
             parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("DiagnosisItemID", "4");
-            ScsResult GetchoiceDic = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetchoiceDic = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetchoiceDic.code = Code;
             GetchoiceDic.title = "5.3.1.8获取能力测评评价类型细则字典值数据";
 
@@ -293,7 +263,7 @@ namespace TEAMModelOS.Controllers
             parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("PXID", "65321");
-            ScsResult GetTeacherInfoByPXID = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetTeacherInfoByPXID = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetTeacherInfoByPXID.code = Code;
             GetTeacherInfoByPXID.title = "5.3.1.9根据培训ID与机构ID获取老师信息";
 
@@ -305,7 +275,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("ProjectItemID", "3");
             parameterMap.Add("SchoolID", "220913");
             parameterMap.Add("Type", "0");
-            ScsResult GetSchoolPlanBySchoolID = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetSchoolPlanBySchoolID = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetSchoolPlanBySchoolID.code = Code;
             GetSchoolPlanBySchoolID.title = "5.3.1.10根据培训项目ID与学校ID获取学校方案";
 
@@ -360,7 +330,7 @@ namespace TEAMModelOS.Controllers
                     //parameterMapData.Add("ComPassed", "1");//0、未认定  1、合格  2、优秀  3、不合格  4、其他
                     //list.Add(parameterMapData);
                 }
-                UpdateTeacherListSituation = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+                UpdateTeacherListSituation = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterContent);
                 UpdateTeacherListSituation.code = Code;
                 UpdateTeacherListSituation.title = "5.3.1.12学员培训基本情况批量回写";
             }
@@ -438,7 +408,7 @@ namespace TEAMModelOS.Controllers
                 //    pfiles.Add(pfileMap);
                 //    list.Add(parameterMapData);
                 //}
-                UpdateTeacherListDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+                UpdateTeacherListDiagnosis = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterContent);
                 UpdateTeacherListDiagnosis.code = Code;
                 UpdateTeacherListDiagnosis.title = "5.3.1.13学员能力点测评结果批量回写";
             }
@@ -461,7 +431,7 @@ namespace TEAMModelOS.Controllers
                 parameterMap.Add("fileSize", "247767");
                 parameterMap.Add("md5", "9c3da8c5c07c2c660cd73c01f56d7fca");
                 parameterMap.Add("fileType", "pdf");
-                UploadSBTARPDF = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+                UploadSBTARPDF = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
                 UploadSBTARPDF.code = Code;
                 UploadSBTARPDF.title = "5.3.1.14学员校本研修PDF回写";
             }
@@ -499,7 +469,7 @@ namespace TEAMModelOS.Controllers
                     parameterMapData.Add("fileType", "pdf");
                     list.Add(parameterMapData);
                 }
-                UploadSBTARPDFList = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+                UploadSBTARPDFList = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterContent);
                 UploadSBTARPDFList.code = Code;
                 UploadSBTARPDFList.title = "5.3.1.15学员校本教研PDF批量回写";
             }
@@ -519,7 +489,7 @@ namespace TEAMModelOS.Controllers
                 parameterMap.Add("fileSize", "247767");
                 parameterMap.Add("md5", "9c3da8c5c07c2c660cd73c01f56d7fca");
                 parameterMap.Add("fileType", "mp4");
-                UploadKTSL = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+                UploadKTSL = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
                 UploadKTSL.code = Code;
                 UploadKTSL.title = "5.3.1.16学员课堂实录回写";
             }
@@ -557,7 +527,7 @@ namespace TEAMModelOS.Controllers
                     parameterMapData.Add("fileType", "mp4");
                     list.Add(parameterMapData);
                 }
-                UploadKTSLList = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+                UploadKTSLList = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterContent);
                 UploadKTSLList.code = Code;
                 UploadKTSLList.title = "5.3.1.17学员课堂实录批量回写";
 
@@ -570,7 +540,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("TrainComID", trainComID);
             parameterMap.Add("ProjectID", "22");
             parameterMap.Add("ProjectItemID", "24");
-            ScsResult GetSchoolList = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetSchoolList = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetSchoolList.code = Code;
             GetSchoolList.title = "5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表";
 
@@ -586,7 +556,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("ProjectID", "22");
             parameterMap.Add("ProjectItemID", "21");
             parameterMap.Add("SchoolID", "200001");
-            ScsResult GetSchoolDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetSchoolDiagnosis = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetSchoolDiagnosis.code = Code;
             GetSchoolDiagnosis.title = "5.3.1.20获取学校设置的可选能力点";
 
@@ -598,7 +568,7 @@ namespace TEAMModelOS.Controllers
             parameterMap.Add("ProjectItemID", "24");
             parameterMap.Add("curPage", "1");
             parameterMap.Add("pageSize", "10");
-            ScsResult GetTeachersPageListByProject = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+            ScsResult GetTeachersPageListByProject = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetTeachersPageListByProject.code = Code;
             GetTeachersPageListByProject.title = "5.3.1.21分页获取学员名单";
 
@@ -653,7 +623,7 @@ namespace TEAMModelOS.Controllers
                 parameterMapData.Add("files", files);
                 list.Add(parameterMapData);
             }
-            ScsResult UploadSBTARPDFListV2 = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+            ScsResult UploadSBTARPDFListV2 = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterContent);
             UploadSBTARPDFListV2.code = Code;
             UploadSBTARPDFListV2.title = "5.3.1.22学员校本教研PDF(每人可以返回多条)批量回写";
 

+ 2 - 517
TEAMModelOS/Controllers/Third/Sc/ScController.cs

@@ -57,22 +57,7 @@ namespace TEAMModelOS.Controllers
         public readonly string type = "scsyxpt";
         private readonly HttpTrigger _httpTrigger;
        private readonly IWebHostEnvironment _environment;
-        /// <summary>
-        /// 机构安全码
-        /// </summary>
-        public string _sc_passKey;
-        /// <summary>
-        /// 机构ID
-        /// </summary>
-        public string _sc_trainComID;
-        /// <summary>
-        /// 机构 AES 密钥
-        /// </summary>
-        public string _sc_privateKey;
-        /// <summary>
-        /// 访问地址
-        /// </summary>
-        public string _sc_url;
+       
         public IConfiguration _configuration { get; set; }
         public ScController(IWebHostEnvironment environment,AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
           AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
@@ -87,10 +72,6 @@ namespace TEAMModelOS.Controllers
             _azureRedis = azureRedis;
             _coreAPIHttpService = coreAPIHttpService;
             _scsApisService = scsApisService;
-            _sc_passKey = _configuration.GetValue<string>("Third:scsyxpt:passKey");
-            _sc_trainComID = _configuration.GetValue<string>("Third:scsyxpt:trainComID");
-            _sc_privateKey = _configuration.GetValue<string>("Third:scsyxpt:privateKey");
-            _sc_url = _configuration.GetValue<string>("Third:scsyxpt:url");
             _httpTrigger = httpTrigger;
             _environment = environment;
         }
@@ -117,490 +98,7 @@ namespace TEAMModelOS.Controllers
             }
         }
 
-
-        /// <summary>
-        /// 检查醍摩豆id存在多个学校的情况
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("sc/delete-school-teacher")]
-        [AllowAnonymous]
-        public async Task<IActionResult> DeleteSchoolTeacher(JsonElement request) {
-            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);
-            return Ok(request);
-        }
-        /// <summary>
-        /// 处理
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("sc/get-scs-teacher")]
-        [AllowAnonymous]
-        public async Task<IActionResult> getScsTeacher(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 ScTeachers = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
-            var ScSchools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "areaId", $"{areaId}" } });
-
-            Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", $"{accessConfig}" }, { "areaId", $"{areaId}"} };
-            (int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetTeachersListByProject");
-            var teachers = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
-            //未保存在数据库的。
-            var a = teachers.Select(x => $"{x.TID}").ToList();
-            var s = ScTeachers.Select(y => $"{ y.TID}").ToList();
-            var asin = a.Except(s).ToList();
-            var updates= teachers.FindAll(x => asin.Contains($"{x.TID}"));
-            var updateTeachers = ScTeachers.FindAll(x => updates.Select(y => $"{ y.PXID}").Contains($"{x.RowKey}"));
-            if (updateTeachers.IsNotEmpty()) {
-                //省平台更新的
-                updateTeachers.ForEach(x => {
-                    var tt = teachers.Find(z => x.RowKey.Equals($"{z.PXID}"));
-                    if (tt != null) {
-                        x.status = 1;
-                        x.TID =tt.TID;
-                        x.TeacherName=tt.TeacherName;
-                        x.SchoolID= tt.SchoolID;
-                        x.SchoolName=tt.SchoolName;
-                        x.ProjectID= tt.ProjectID;
-                        x.ProjectItemID= tt.ProjectItemID;
-                        x.ProjectItemTitle= tt.ProjectItemTitle;
-                        x.ProjectTitle= tt.ProjectTitle;
-                        x.CityID= tt.CityID;
-                        x.DistrictID = tt.DistrictID;
-                        x.CityName= tt.CityName;
-                        x.DisName = tt.DisName;
-                        x.Account= tt.Account;
-                        x.TeacherXK = tt.TeacherXK;
-                        x.TeacherXD= tt.TeacherXD;
-                        x.Mobile = x.Mobile;
-                        x.Email= tt.Email;
-                        x.tmdid = null;
-                        var school = ScSchools.Find(s => s.schoolid == x.SchoolID);
-                        x.schoolCode = school?.schoolCode;
-                    }
-                });
-                updateTeachers = await _azureStorage.UpdateAll(updateTeachers);
-            }
-            var unbindtmdid = ScTeachers.FindAll(x => string.IsNullOrEmpty(x.tmdid));
-            var tids = unbindtmdid.Select(x => $"{x.TID}").ToHashSet();
-            if (tids.Count() > 0)
-            {
-                List<DbBind> binds = new List<DbBind>();
-                string sql = $"SELECT c.id,b.userid,b.data FROM c join b in c.binds  where b.userid in ({string.Join(",", tids.Select(x => $"'{x}'"))})";
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<DbBind>
-                    (queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                {
-                    binds.Add(item);
-                }
-                if (binds.IsNotEmpty())
-                {
-                    List<ScTeacher> update = new List<ScTeacher>();
-                    binds.ForEach(x => {
-                        var exs = unbindtmdid.FindAll(z => $"{z.TID}".Equals(x.userid));
-                        if (exs.IsNotEmpty())
-                        {
-                            exs.ForEach(y => {
-                                y.tmdid = x.id;
-                            });
-                            update.AddRange(exs);
-                        }
-                    });
-                    var group = update.GroupBy(x => x.RowKey).Select(z => new { z.Key, list = z.ToList() });
-                    List<ScTeacher> scTeachers = new();
-                    group.ToList().ForEach(x => {
-                        if (x.list.Count() == 1)
-                        {
-                            scTeachers.Add(x.list[0]);
-                        }
-                        else if (x.list.Count > 1)
-                        {
-                            scTeachers.Add(x.list[0]);
-                        }
-                    });
-                    scTeachers = await _azureStorage.SaveOrUpdateAll(scTeachers);
-                }
-            }
-            unbindtmdid = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
-            return Ok(unbindtmdid.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }));
-        }
-
-        /// <summary>
-        /// 检查醍摩豆id存在多个学校的情况
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("sc/get-project-school-teacher")]
-        [AllowAnonymous]
-        public async Task<IActionResult> GetProjectSchoolTeacher(JsonElement request) {
-            if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
-            if (!request.TryGetProperty("ignoreSchools", out JsonElement ignoreSchools)) 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<IdNameCode> ignore = ignoreSchools.ToObject<List<IdNameCode>>();
-            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");
-            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 });
-            }
-            // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
-            (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
-            if (status == 200)
-            {
-                schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
-                if (ignore.IsNotEmpty())
-                {
-                    matchSchools = schools.FindAll(x => ignore.Select(y=>y.name).Contains(x.schoolname));
-                    if (matchSchools.IsNotEmpty())
-                    {
-                        if (matchSchools.Count != ignore.Count)
-                        {
-                            var matched = matchSchools.Select(x => x.schoolname);
-                            var unmatch = ignore.Select(y => y.name).Except(matched);
-                            List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
-                            if (scschoolUnmatch.IsNotEmpty()) {
-                                return Ok(new { matched, unmatch, scschoolUnmatch });
-                            }
-                        }
-                        else {
-                            matchSchools.ForEach(x => {
-                               var exschool= ignore.Find(y => y.name.Equals(x.schoolname));
-                                if (exschool != null) {
-                                    x.schoolCode = exschool.id;
-                                    x.areaId = $"{areaId}";
-                                    x.city = $"{city}";
-                                    x.dist = $"{dist}";
-                                }
-                            });
-                        }
-                    }
-                    else {
-                        return Ok(new { unmatch=ignore, schools }) ;
-                    }
-                }
-                //数据校验
-               tbschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() {  { "PartitionKey", "ScSchool" } });
-                if (tbschools.IsNotEmpty())
-                {
-                  
-                    var a = tbschools.Select(y => $"{y.RowKey}").ToList();
-                    saveschools = schools.Where(x=>!a.Exists(z=>z.Equals($"{x.schoolid}"))).ToList();
-                    List<SchoolData> schoolDatas = new List<SchoolData>();
-                    saveschools.ForEach(x =>
-                    {
-                        x.RowKey = $"{x.schoolid}";
-                        x.PartitionKey = "ScSchool";
-                        x.areaId = $"{areaId}";
-                        x.city = $"{city}";
-                        x.dist = $"{dist}";
-                        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);
-                    saveschools.ForEach(x => {
-
-                        var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
-                        if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
-                        {
-                           
-                            x.schoolCode = schoolData.id;
-                            x.areaId = $"{areaId}";
-                            x.city = $"{city}";
-                            x.dist = $"{dist}";
-                        }
-                    });
-                    saveschools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
-                    saveschools.RemoveAll(x => tbschools.FindAll(z=>!string.IsNullOrEmpty(z.schoolCode)).Exists(y=>y.schoolCode.Equals(x.schoolCode)));
-                    saveschools = await _azureStorage.SaveAll(saveschools);
-                }
-                else {
-                    List<SchoolData> schoolDatas = new List<SchoolData>();
-                    schools.ForEach(x =>
-                    {
-                        x.RowKey = $"{x.schoolid}";
-                        x.PartitionKey = "ScSchool";
-                        x.areaId = $"{areaId}";
-                        x.city = $"{city}";
-                        x.dist = $"{dist}";
-                        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);
-                    schools.ForEach(x => {
-                        var schoolData =  schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
-                        if (schoolData != null && !string.IsNullOrEmpty(schoolData.id)) {
-                            x.schoolCode = schoolData.id;
-                            x.areaId = $"{areaId}";
-                            x.city = $"{city}";
-                            x.dist = $"{dist}";
-                          
-                        }
-                    });
-
-                   schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
-                   saveschools = await _azureStorage.SaveOrUpdateAll(schools);
-                }
-            }
-           
-            List<string> unsave = new List<string>();
-            if (saveschools.IsNotEmpty()) {
-               var ex    = schools.Select(x => $"{x.schoolid}").Except(saveschools.Select(y=>y.RowKey));
-                if (ex.Count() > 0) {
-                    unsave.AddRange(ex);
-                }
-            }
-            if (tbschools.IsNotEmpty())
-            {
-                var ex = schools.Select(x => $"{x.schoolid}").Except(tbschools.Select(y => y.RowKey));
-                if (ex.Count() > 0)
-                {
-                    unsave.AddRange(ex);
-                }
-            }
-
-            var areaschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", $"ScSchool" } ,{ "areaId",$"{areaId}" } });
-
-            List<School> cosbdschools = 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") }))
-            {
-                cosbdschools.Add(item);
-            }
-
-            var tbs = areaschools.FindAll(x => areaschools.Select(z => z.schoolCode).Except(cosbdschools.Select(x => x.id)).Contains(x.schoolCode));
-            List<CSchool> cSchools = new List<CSchool>();
-            foreach (var sch in tbs) {
-                cSchools.Add(new CSchool
-                {
-                    id = sch.schoolCode,
-                    name = sch.schoolname,
-                   // admin = "1530606136",
-                    period = new List<string>() { sch.schooltypename },
-                    size = 100,
-                });
-            
-            }
-           
-            var client = _azureCosmos.GetCosmosClient();
-            List<School> schoolsfailed = new List<School>();
-            List<School> schoolsScucess = new List<School>();
-            List<string> failedmsg= new List<string>();
-            foreach (var sc in cSchools)
-            {
-                List<Period> periods = new List<Period>();
-                string campusId = Guid.NewGuid().ToString();
-                sc.period.ForEach(x => {
-                    periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x, campusId = campusId });
-                });
-                School school = new School
-                {
-                    id = sc.id,
-                    name = sc.name,
-                    size = sc.size,
-                    code = "Base",
-                    campuses = new List<Campus> { new Campus { name = sc.name, id = campusId } },
-                    region = "中国",
-                    province = "四川省",
-                    city = $"{city}",
-                    timeZone = new SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
-                    type = 1,
-                    pk = "School",
-                    ttl = -1,
-                    schoolCode = sc.id,
-                    dist=$"{dist}",
-                    period = periods,
-                    areaId =$"{areaId}",
-                    standard=$"{standard}"
-                };
-                try
-                {
-                    //await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(school, new PartitionKey(school.code));
-                    schoolsScucess.Add(school);
-                }
-                catch (CosmosException ex)
-                {
-                    failedmsg.Add($"{school.ToJsonString()}\n \n{ex.Status}{ex.Message }\n {ex.StackTrace}");
-                    schoolsfailed.Add(school);
-                }
-                catch (Exception ex) {
-                    failedmsg.Add($"{school.ToJsonString()}\n{ex.Message }\n {ex.StackTrace}");
-                    schoolsfailed.Add(school);
-                }
-            }
-            //省平台获取到的学生。
-            List<ScTeacher> teachers = new();
-            // Table获取的学生
-            List<ScTeacher> areaTeacher = new();
-            List<ScTeacher> repeat = new();
-            // 5.3.1.2获取学员名单
-            (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetTeachersListByProject");
-            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 });
-                if (teachers.IsNotEmpty()) {
-                    teachers.ForEach(x => {
-
-                        ScSchool scSchool= all.Find(y => y.schoolid == x.SchoolID);
-                        if (scSchool != null) {
-                            x.schoolCode = scSchool.schoolCode;
-                        }
-                        x.RowKey = $"{x.PXID}";
-                        x.PartitionKey = "ScTeacher";
-                        x.areaId = $"{areaId}";
-                    });
-
-                    areaTeacher = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
-                    if (areaTeacher.IsNotEmpty())
-                    {
-                        List<ScTeacher> unbindtmdid = new List<ScTeacher>();
-                        //未保存在数据库的。
-                        var saveTeachers= teachers.FindAll(x => !areaTeacher.Select(y => y.RowKey).Contains($"{x.PXID}"));
-                        if (saveTeachers.IsNotEmpty()) {
-                            saveTeachers = await _azureStorage.SaveAll(saveTeachers);
-                            unbindtmdid.AddRange(saveTeachers);
-                        }
-                       
-                        var unbind= areaTeacher.FindAll(x => string.IsNullOrEmpty(x.tmdid));
-                        if (unbind.IsNotEmpty()) {
-                            unbindtmdid.AddRange(unbind);
-                        }
-
-                        //处理没有醍摩豆id
-                        var tids= unbindtmdid.Select(x => $"{x.TID}").ToHashSet();
-                        if (tids.Count() > 0) {
-                            List<DbBind> binds = new List<DbBind>();
-                            string sql = $"SELECT c.id,b.userid,b.data FROM c join b in c.binds  where b.userid in ({string.Join(",", tids.Select(x => $"'{x}'"))})";
-                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<DbBind>
-                                (queryText: sql , requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                            {
-                                binds.Add(item);
-                            }
-                            if (binds.IsNotEmpty()) {
-                                List<ScTeacher> update = new List<ScTeacher>();
-                                binds.ForEach(x => {
-                                   var exs= unbindtmdid.FindAll(z => $"{z.TID}".Equals(x.userid));
-                                    if (exs.IsNotEmpty()) {
-                                        exs.ForEach(y => {
-                                            y.tmdid = x.id;
-                                        });
-                                        update.AddRange(exs);
-                                    }
-                                });
-                                var group= update.GroupBy(x => x.RowKey).Select(z=>new { z.Key ,list= z.ToList()});
-                                List<ScTeacher> scTeachers = new();
-                                group.ToList().ForEach(x => {
-                                    if (x.list.Count() == 1)
-                                    {
-                                        scTeachers.Add(x.list[0]);
-                                    }
-                                    else if(x.list.Count>1) {
-                                        scTeachers.Add(x.list[0]);
-                                        repeat.AddRange(x.list);
-                                    }
-                                });
-                                scTeachers = await _azureStorage.SaveOrUpdateAll(scTeachers);
-                            }
-                        }
-                    }
-                    else
-                    {
-                        //处理没有醍摩豆id
-                        var tids = teachers.Select(x => $"{x.TID}").ToHashSet();
-                        if (tids.Count() > 0)
-                        {
-                            List<DbBind> binds = new List<DbBind>();
-                            string sql = $"SELECT c.id,b.userid,b.data FROM c join b in c.binds  where b.userid in ({string.Join(",", tids.Select(x => $"'{x}'"))})";
-                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<DbBind>
-                                (queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                            {
-                                binds.Add(item);
-                            }
-                            if (binds.IsNotEmpty())
-                            {
-                                
-                                binds.ForEach(x => {
-                                    var exs = teachers.FindAll(z => $"{z.TID}".Equals(x.userid));
-                                    if (exs.IsNotEmpty())
-                                    {
-                                        exs.ForEach(y => {
-                                            y.tmdid = x.id;
-                                        });
-                                    }
-                                });
-                            }
-                        }
-                        var group = teachers.GroupBy(x => x.RowKey).Select(z => new { z.Key, list = z.ToList() });
-                        List<ScTeacher> scTeachers = new();
-                        group.ToList().ForEach(x => {
-                            if (x.list.Count() == 1)
-                            {
-                                scTeachers.Add(x.list[0]);
-                            }
-                            else if (x.list.Count > 1)
-                            {
-                                scTeachers.Add(x.list[0]);
-                                repeat.AddRange(x.list);
-                            }
-                        });
-                        scTeachers = await _azureStorage.SaveOrUpdateAll(scTeachers);
-                  }
-                }
-            }
-            return Ok(new {
-                projects, msg=$"Table中已经有:{tbschools.Count}个学校,省平台获取到:" +
-                $"{schools?.Count}个学校,本次保存有:{saveschools?.Count},没有被保存的学校:" +
-                $"{unsave?.Count},创建失败的学校有:{schoolsfailed.Count()}," +
-                $"创建成功的的学校有:{schoolsScucess.Count()}",
-                schoolsfailed,
-                failedmsg,
-                schoolsScucess,
-                tbsch= tbschools.Select(x=>new { x.schoolname,x.schoolCode}),
-                repeat
-            });
-        }
+ 
         public class  DbBind{
             public string id { get; set; }
             public string userid { get; set; }
@@ -952,16 +450,6 @@ namespace TEAMModelOS.Controllers
             var HostName = HttpContext.GetHostName();
             //var rurl = new StringBuilder($"https://{_option.HostName}/sso");
             var rurl = new StringBuilder($"https://{HostName}/sso");
-            
-           
-            //if (path.Equals("sc"))
-            //{
-            //    path = $"scpjx";
-            //}
-            //else
-            //{
-            //    path = $"sc{path}";
-            //}
             try {
               
                 string parmas = $"Pxid={scsso.Pxid}&Webid={scsso.Webid}&tid={scsso.tid}&time={scsso.time}";
@@ -987,7 +475,6 @@ namespace TEAMModelOS.Controllers
                     string enurl = $"status=5&param={HttpUtility.UrlEncode(new { scsso.Pxid, scsso.tid}.ToJsonString(), Encoding.UTF8)}";
                     return Redirect(rurl.Append($"?{enurl}").ToString());
                 }
-               
                 string setsql = $"select  value(c) from c where contains(c.accessConfig,'{ scTeachers[0].ProjectID}') and contains(c.accessConfig,'{ scTeachers[0].ProjectItemID}')  and contains(c.accessConfig,'scsyxpt') ";
                 AreaSetting setting = null;
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<AreaSetting>(queryText: setsql,
@@ -1003,8 +490,6 @@ namespace TEAMModelOS.Controllers
                 string accessConfig = setting.accessConfig;
                 Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "pxid", scsso.Pxid }, { "tid", scsso.tid }, { "areaId", $"{setting.id}" } };
                 string SchoolName = "", SchoolID = "", ProjectID = "", ProjectItemID = "", TeacherName = "" , Account="";
-
-                
                 if (scTeachers.IsNotEmpty())
                 {
                     ScTeacher scTeacher = scTeachers[0];

+ 100 - 34
TEAMModelOS/Controllers/Third/Sc/ScDataInitController.cs

@@ -57,24 +57,9 @@ namespace TEAMModelOS.Controllers.Third
         public readonly string type = "scsyxpt";
         private readonly HttpTrigger _httpTrigger;
         private readonly IWebHostEnvironment _environment;
-        /// <summary>
-        /// 机构安全码
-        /// </summary>
-        public string _sc_passKey;
-        /// <summary>
-        /// 机构ID
-        /// </summary>
-        public string _sc_trainComID;
-        /// <summary>
-        /// 机构 AES 密钥
-        /// </summary>
-        public string _sc_privateKey;
-        /// <summary>
-        /// 访问地址
-        /// </summary>
-        public string _sc_url;
+        private readonly ThirdApisService _thirdApisService;
         public IConfiguration _configuration { get; set; }
-        public ScDataInitController(IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
+        public ScDataInitController(ThirdApisService thirdApisService,IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
           AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
@@ -87,15 +72,106 @@ namespace TEAMModelOS.Controllers.Third
             _azureRedis = azureRedis;
             _coreAPIHttpService = coreAPIHttpService;
             _scsApisService = scsApisService;
-            _sc_passKey = _configuration.GetValue<string>("Third:scsyxpt:passKey");
-            _sc_trainComID = _configuration.GetValue<string>("Third:scsyxpt:trainComID");
-            _sc_privateKey = _configuration.GetValue<string>("Third:scsyxpt:privateKey");
-            _sc_url = _configuration.GetValue<string>("Third:scsyxpt:url");
             _httpTrigger = httpTrigger;
             _environment = environment;
+            _thirdApisService = thirdApisService;
         }
+
         /// <summary>
-        /// 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
+        /// 0. 获取省平台相关的项目
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-scs-porject")]
+        [AllowAnonymous]
+        public async Task<IActionResult> GetScsPorject(JsonElement request) {
+            List<ScComConfig> scComConfigs = await _azureStorage.FindListByDict<ScComConfig>(new Dictionary<string, object> { { Constant.PartitionKey, "ScComConfig" } });
+            string Code = "GetProjectInfoByTrainComID";
+            List<ScProject> projectsSave = new List<ScProject>();
+            foreach (var config in scComConfigs) {
+                Dictionary<string, object> parameterMap = new Dictionary<string, object>();
+                parameterMap.Add("TrainComID", config.trainComID);
+                ScsResult result = new ScsResult { code = Code, title = "5.3.1.1获取项目列表" };
+                result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
+                List<ScProject> projects = result.content.ToObject<List<ScProject>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+                List<ScProject> scProjects = await _azureStorage.FindListByDict<ScProject>(new Dictionary<string, object> { { Constant.PartitionKey, "ScProject" }, { "trainComID", $"{config.trainComID}" } });
+              
+                foreach (var project in projects)
+                {
+                    if (scProjects.IsNotEmpty())
+                    {
+                        ScProject scProject= scProjects.Find(x => x.ProjectItemID == project.ProjectItemID);
+                        if (scProject != null)
+                        {
+                            scProject.PartitionKey = "ScProject";
+                            scProject.trainComID = config.trainComID;
+                            scProject.passKey = config.passKey;
+                            scProject.privateKey = config.privateKey;
+                            scProject.RowKey = $"{project.ProjectItemID}";
+                            scProject.config = "scsyxpt";
+                            scProject.ProjectID = project.ProjectID;
+                            scProject.ProjectItemID = project.ProjectItemID;
+                            scProject.ProjectItemTitle = project.ProjectItemTitle;
+                            scProject.ProjectTitle = project.ProjectTitle;
+                            scProject.TCount = project.TCount;
+                            scProject.IsDiagnosis = project.IsDiagnosis;
+                            scProject.IsQuota = project.IsQuota;
+                            scProject.SchoolDiagnosisMinCount = project.SchoolDiagnosisMinCount;
+                            scProject.SchoolDiagnosisMinDimension = project.SchoolDiagnosisMinDimension;
+                            scProject.TeacherDiagnosisMinDimension = project.TeacherDiagnosisMinDimension;
+                            projectsSave.Add(scProject);
+                        }
+                        else {
+                            projectsSave.Add(new ScProject
+                            {
+                                PartitionKey = "ScProject",
+                                trainComID = config.trainComID,
+                                passKey = config.passKey,
+                                privateKey = config.privateKey,
+                                RowKey = $"{project.ProjectItemID}",
+                                config = "scsyxpt",
+                                ProjectID = project.ProjectID,
+                                ProjectItemID = project.ProjectItemID,
+                                ProjectItemTitle = project.ProjectItemTitle,
+                                ProjectTitle = project.ProjectTitle,
+                                TCount = project.TCount,
+                                IsDiagnosis = project.IsDiagnosis,
+                                IsQuota = project.IsQuota,
+                                SchoolDiagnosisMinCount = project.SchoolDiagnosisMinCount,
+                                SchoolDiagnosisMinDimension = project.SchoolDiagnosisMinDimension,
+                                TeacherDiagnosisMinDimension = project.TeacherDiagnosisMinDimension,
+                            });
+                        }
+                    }
+                    else {
+                        projectsSave.Add(new ScProject { 
+                            PartitionKey= "ScProject",
+                            trainComID=config.trainComID,
+                            passKey=config.passKey,
+                            privateKey=config.privateKey, 
+                            RowKey=$"{project.ProjectItemID}",
+                            config= "scsyxpt",
+                            ProjectID=project.ProjectID,
+                            ProjectItemID=project.ProjectItemID,
+                            ProjectItemTitle=project.ProjectItemTitle,
+                            ProjectTitle=project.ProjectTitle,
+                            TCount=project.TCount,
+                            IsDiagnosis=project.IsDiagnosis,
+                            IsQuota=project.IsQuota,
+                            SchoolDiagnosisMinCount=project.SchoolDiagnosisMinCount,
+                            SchoolDiagnosisMinDimension=project.SchoolDiagnosisMinDimension,
+                            TeacherDiagnosisMinDimension=project.TeacherDiagnosisMinDimension,
+                        });
+                    }
+                }
+            }
+            await _azureStorage.SaveOrUpdateAll(projectsSave);
+            return Ok(new { projectsSave });
+        }
+        
+        /// <summary>
+        /// 3. 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -245,7 +321,6 @@ namespace TEAMModelOS.Controllers.Third
                     scTeachers = await _azureStorage.SaveOrUpdateAll(scTeachers);
                 }
             }
-
             //反向更新教师绑定的省平台的SchoolID(int)和schoolCode(string)
             ScTeachers = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
             var scSchools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "areaId", $"{areaId}" } });
@@ -262,7 +337,7 @@ namespace TEAMModelOS.Controllers.Third
             return Ok(updateTch.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }));
         }
         /// <summary>
-        /// 检查学校是否有同名的
+        ///1. 检查学校是否有同名的
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -275,11 +350,8 @@ namespace TEAMModelOS.Controllers.Third
             if (!request.TryGetProperty("ignoreSchools", out JsonElement ignoreSchools)) return BadRequest();
             if (!request.TryGetProperty("city", out JsonElement city)) return BadRequest();
             if (!request.TryGetProperty("dist", out JsonElement dist)) return BadRequest();
-            List<ScProject> projects = null;
-            List<ScSchool> saveschools = null;
             List<ScSchool> schools = null;
             List<ScSchool> matchSchools = null;
-            List<ScSchool> tbschools = null;
             int status = -1; string json = null;
             Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", $"{accessConfig}" }, { "areaId", $"{areaId}" } };
             List<IdNameCode> ignore = ignoreSchools.ToObject<List<IdNameCode>>();
@@ -326,7 +398,7 @@ namespace TEAMModelOS.Controllers.Third
             return Ok(new { schools = schools.Select(x => new { x.schoolname, x.schoolCode, x.schoolid, x.ProjectID, x.ProjectItemID }) });
             }
         /// <summary>
-        /// 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
+        /// 2. 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -344,9 +416,6 @@ namespace TEAMModelOS.Controllers.Third
                 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获取项目列表
@@ -522,9 +591,7 @@ namespace TEAMModelOS.Controllers.Third
                     period = new List<string>() { sch.schooltypename },
                     size = 100,
                 });
-
             }
-
             var client = _azureCosmos.GetCosmosClient();
             List<School> schoolsfailed = new List<School>();
             List<School> schoolsScucess = new List<School>();
@@ -585,7 +652,6 @@ namespace TEAMModelOS.Controllers.Third
                 tbsch = tbschools.Select(x => new { x.schoolname, x.schoolCode }),
                 
             });
-
         }
     }
 }