Explorar el Código

調整azure storager table sdk 與相關代碼調整

JAELYS hace 3 años
padre
commit
605e988ffe
Se han modificado 31 ficheros con 614 adiciones y 520 borrados
  1. 2 0
      .gitignore
  2. 2 1
      TEAMModelBI/Controllers/BIHome/HomeStatisController.cs
  3. 2 1
      TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs
  4. 13 10
      TEAMModelBI/Controllers/BITest/TestController.cs
  5. 22 20
      TEAMModelBI/Controllers/DingDingStruc/DDStructController.cs
  6. 83 68
      TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs
  7. 23 21
      TEAMModelBI/Controllers/LoginController.cs
  8. 6 4
      TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs
  9. 11 6
      TEAMModelOS.FunctionV4/CosmosDB/TriggerCorrect.cs
  10. 13 15
      TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs
  11. 12 12
      TEAMModelOS.FunctionV4/CosmosDB/TriggerExamLite.cs
  12. 16 16
      TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs
  13. 10 9
      TEAMModelOS.FunctionV4/CosmosDB/TriggerStudy.cs
  14. 11 9
      TEAMModelOS.FunctionV4/CosmosDB/TriggerSurvey.cs
  15. 11 10
      TEAMModelOS.FunctionV4/CosmosDB/TriggerVote.cs
  16. 4 3
      TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs
  17. 50 73
      TEAMModelOS.SDK/DI/AzureStorage/AzureStorageTableExtensions.cs
  18. 9 11
      TEAMModelOS.SDK/Helper/Security/Md5Hash/Md5Hash.cs
  19. 4 3
      TEAMModelOS.SDK/Models/Service/SchoolService.cs
  20. 48 35
      TEAMModelOS.SDK/Models/Service/Third/ThirdService.cs
  21. 5 3
      TEAMModelOS/Controllers/Common/ExamController.cs
  22. 3 3
      TEAMModelOS/Controllers/Normal/AbilityController.cs
  23. 2 1
      TEAMModelOS/Controllers/School/SchoolTeacherController.cs
  24. 4 4
      TEAMModelOS/Controllers/System/CoreController.cs
  25. 4 2
      TEAMModelOS/Controllers/System/OpenApiController.cs
  26. 4 3
      TEAMModelOS/Controllers/Third/DingDingController.cs
  27. 27 18
      TEAMModelOS/Controllers/Third/Sc/ScApiController.cs
  28. 113 84
      TEAMModelOS/Controllers/Third/Sc/ScController.cs
  29. 94 71
      TEAMModelOS/Controllers/Third/Sc/ScDataInitController.cs
  30. 4 3
      TEAMModelOS/Controllers/XTest/FixDataController.cs
  31. 2 1
      TEAMModelOS/Controllers/XTest/TestController.cs

+ 2 - 0
.gitignore

@@ -259,3 +259,5 @@ _Pvt_Extensions
 /TEAMModelBI/wwwroot/static
 *.log.*
 
+/TEAMModelOS/Properties/ServiceDependencies/ies5-rc - Web Deploy/profile.arm.json
+/TEAMModelOS/Properties/ServiceDependencies/ies5-test - Web Deploy/profile.arm.json

+ 2 - 1
TEAMModelBI/Controllers/BIHome/HomeStatisController.cs

@@ -806,7 +806,8 @@ namespace TEAMModelBI.Controllers.BIHome
             try
             {
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
-                List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+                List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
 
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 List<PowerStics> powerStics = new List<PowerStics>(); 

+ 2 - 1
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -61,7 +61,8 @@ namespace TEAMModelBI.Controllers.BISchool
         public async Task<IActionResult> GetAuthorityBIList()
         {
             Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
-            List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+            List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
 
             return Ok(new { authorityBIList });
         }

+ 13 - 10
TEAMModelBI/Controllers/BITest/TestController.cs

@@ -159,9 +159,10 @@ namespace TEAMModelBI.Controllers.BITest
             if (!string.IsNullOrEmpty($"{platform}"))
                 strlist.Add($"platform {QueryComparisons.Equal} {platform}");
 
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("OptLog");
             string sql = string.Join(" and ", strlist);
+            var temp = table.QueryWhereString<OptLog>(sql);
 
-            var temp = _azureStorage.QueryWhereString<OptLog>(sql);
             return Ok(new { state = 200, temp });
         }
 
@@ -192,7 +193,8 @@ namespace TEAMModelBI.Controllers.BITest
                 if (!string.IsNullOrEmpty($"{platform}"))
                     tableSql.Append(!string.IsNullOrEmpty(tableSql.ToString()) ? $" {TableOperators.And} platform {QueryComparisons.Equal} '{platform}' " : $" platform {QueryComparisons.Equal} '{platform}' ");
 
-                operateLogs = await _azureStorage.QueryWhereString<OptLog>(tableSql.ToString());
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("OptLog");
+                operateLogs = await table.QueryWhereString<OptLog>(tableSql.ToString());
                 return Ok(new { state = 200, operateLogs });
             }
             catch (Exception ex)
@@ -226,7 +228,7 @@ namespace TEAMModelBI.Controllers.BITest
 
             //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
             string access_token = response.AccessToken;
-            List<string> datalist = new List<string>();
+            
             IDingTalkClient quitStaffClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/querydimission");
             OapiSmartworkHrmEmployeeQuerydimissionRequest reqDimission = new OapiSmartworkHrmEmployeeQuerydimissionRequest() { Offset = 0L, Size = 50L };
             OapiSmartworkHrmEmployeeQuerydimissionResponse rspDimission = quitStaffClient.Execute(reqDimission, access_token);
@@ -237,8 +239,8 @@ namespace TEAMModelBI.Controllers.BITest
             }
             else if (rspDimission.Result != null)
             {
-                datalist = rspDimission.Result.DataList;
-                return Ok(new { state = 200, datalist = datalist });
+                var datalist = rspDimission.Result.DataList;
+                return Ok(new { state = 200, datalist });
             }
             else
             {
@@ -304,9 +306,10 @@ namespace TEAMModelBI.Controllers.BITest
         [HttpPost("set-rolesorperm")]
         public async Task<IActionResult> SetRolesOrPermissions() 
         {
-            List<DingDingUserInfo> ddUserId = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", "continent" } });
-            List<string> read = new List<string>() { "abilitystandard-read", "batcharea-read", "batchschool-read", "orgusers-read" };
-            List<DingDingUserInfo> tempUserInfo = new List<DingDingUserInfo>();
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+            List<DingDingUserInfo> ddUserId = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", "continent" } });
+            List<string> read = new() { "abilitystandard-read", "batcharea-read", "batchschool-read", "orgusers-read" };
+            List<DingDingUserInfo> tempUserInfo = new();
             foreach (var user in ddUserId) 
             {
                 if (string.IsNullOrEmpty(user.roles)) 
@@ -318,7 +321,7 @@ namespace TEAMModelBI.Controllers.BITest
                 {
                     user.permissions = string.Join(",", read);
                 }
-                List<string> tempRead = new List<string>(user.permissions.Split(","));
+                List<string> tempRead = new(user.permissions.Split(","));
 
                 foreach (var temp in read) 
                 {
@@ -331,7 +334,7 @@ namespace TEAMModelBI.Controllers.BITest
                 tempUserInfo.Add(user);
             }
 
-            var response = await _azureStorage.SaveOrUpdateAll<DingDingUserInfo>(tempUserInfo);
+            var response = await table.SaveOrUpdateAll<DingDingUserInfo>(tempUserInfo);
 
             return Ok(new { state = 200, response });
         }

+ 22 - 20
TEAMModelBI/Controllers/DingDingStruc/DDStructController.cs

@@ -249,43 +249,44 @@ namespace TEAMModelBI.Controllers.DingDingStruc
 
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
-                Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
-                List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);
+                Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+                List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
 
                 //获取access_token
-                DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
-                OapiGettokenRequest request = new OapiGettokenRequest();
+                DefaultDingTalkClient client = new("https://oapi.dingtalk.com/gettoken");
+                OapiGettokenRequest request = new();
                 request.Appkey = appKey;
                 request.Appsecret = appSecret;
                 request.SetHttpMethod("Get");
                 OapiGettokenResponse response = client.Execute(request);
-                if (response.IsError)
-                {
-                    return BadRequest();
-                }
+                if (response.IsError) return BadRequest();               
 
                 //access_token的有效期为7200秒(2小时),有效期内重复获取会返回相同结果并自动续期,过期后获取会返回新的access_token
                 string access_token = response.AccessToken;
 
                 IDingTalkClient userListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
-                OapiV2UserListRequest reqUserList1 = new OapiV2UserListRequest();
-                reqUserList1.DeptId = long.Parse($"{tempDeptId}");
-                reqUserList1.Cursor = 0L;
-                reqUserList1.Size = 50L;
-                reqUserList1.ContainAccessLimit = false;
-                reqUserList1.OrderField = "custom";
-                reqUserList1.Language = "zh_CN";
+                OapiV2UserListRequest reqUserList1 = new()
+                {
+                    DeptId = long.Parse($"{tempDeptId}"),
+                    Cursor = 0L,
+                    Size = 50L,
+                    ContainAccessLimit = false,
+                    OrderField = "custom",
+                    Language = "zh_CN"
+                };
                 reqUserList1.SetHttpMethod("GET");
                 OapiV2UserListResponse rspV2UserList1 = userListClient.Execute(reqUserList1, access_token);
-                List<DDUserInfoAndTMD> dDAndTmdInfos = new List<DDUserInfoAndTMD>();
+                List<DDUserInfoAndTMD> dDAndTmdInfos = new();
 
-                List<DingDingUserInfo> ddUserInfos = new List<DingDingUserInfo>();
+                List<DingDingUserInfo> ddUserInfos = new();
 
+                var tabledd = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");                
                 if (rspV2UserList1.Result.List != null)
                 {
                     foreach (var itemUser in rspV2UserList1.Result.List)
                     {
-                        List<DingDingUserInfo> temp = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" } });
+                        List<DingDingUserInfo> temp = await tabledd.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" } });
                         foreach (var item in temp)
                         {
                             ddUserInfos.Add(item);
@@ -357,7 +358,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 {
                     //获取下级部门列表
                     IDingTalkClient v2DeptListClient2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
-                    OapiV2DepartmentListsubRequest reqDeptList2 = new OapiV2DepartmentListsubRequest() { DeptId = long.Parse($"{tempDeptId}"), Language = "zh_CN" };
+                    OapiV2DepartmentListsubRequest reqDeptList2 = new() { DeptId = long.Parse($"{tempDeptId}"), Language = "zh_CN" };
                     OapiV2DepartmentListsubResponse rspDeptLis2 = v2DeptListClient2.Execute(reqDeptList2, access_token);
 
                     if (rspDeptLis2.Result != null)
@@ -489,7 +490,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 IDingTalkClient userInfoClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
 
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
-                List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+                List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
 
                 if (!string.IsNullOrEmpty($"{userIds}"))
                 {

+ 83 - 68
TEAMModelBI/Controllers/DingDingStruc/TableDingDingInfoController.cs

@@ -68,6 +68,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
                 HttpClient httpClient = _http.CreateClient();
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
                 string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
 
                 //获取access_token
@@ -88,7 +89,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 OapiV2DepartmentListsubRequest reqDeptList1 = new OapiV2DepartmentListsubRequest() { DeptId = 1L, Language = "zh_CN" };
                 OapiV2DepartmentListsubResponse rspDeptList1 = deptListClient.Execute(reqDeptList1, access_token);
 
-                List<DingDingUserInfo> ddUserInfos = new List<DingDingUserInfo>();
+                List<DingDingUserInfo> ddUserInfos = new();
 
                 if (rspDeptList1.Result != null)
                 {
@@ -163,7 +164,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
 
                 var tempddUserInfos = ddUserInfos.GroupBy(c => c.RowKey).Select(c => c.First()).ToList();//去重
                 //List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(dingDingUserInfos);  //只是保存至Table
-                List<DingDingUserInfo> TempdingDingUserInfos = await _azureStorage.SaveOrUpdateAll(tempddUserInfos);  //保存和修改至Table
+                List<DingDingUserInfo> TempdingDingUserInfos = await table.SaveOrUpdateAll(tempddUserInfos);  //保存和修改至Table
                 return Ok(new { state = 200, UserInfo = TempdingDingUserInfos });
             }
             catch (Exception ex)
@@ -183,14 +184,15 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         {
             try
             {
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
                 string divide = _configuration["CustomParam:SiteScope"];
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", $"{divide}" } };
-                List<DingDingUserInfo> ddUserInfoList = await _azureStorage.FindListByDict<DingDingUserInfo>(dic);
+                List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
 
-                List<ddUserInfo> ddUserInfos = new();
+                List<DDUserInfo> ddUserInfos = new();
                 foreach (var item in ddUserInfoList)
                 {
-                    ddUserInfo ddUserInfo = new ddUserInfo()
+                    DDUserInfo ddUserInfo = new()
                     {
                         partitionKey = item.PartitionKey,
                         rowKey = item.RowKey,
@@ -237,6 +239,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         {
             try
             {
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
                 string divide = _configuration["CustomParam:SiteScope"];
@@ -270,7 +274,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                         ddUserInfos.Add(ddUserInfo);
                     }
 
-                    List<DingDingUserInfo> tempddUserInfos = await _azureStorage.SaveAll(ddUserInfos);
+                    List<DingDingUserInfo> tempddUserInfos = await table.SaveAll(ddUserInfos);
 
                     //保存操作记录
                     await _azureStorage.SaveLog("tabledd-add", $"{_tmdName}【{_tmdId}】添加待入职员工至table数据表中", _dingDing, httpContext: HttpContext);
@@ -308,6 +312,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         {
             try
             {
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+
                 string appKey = _configuration["DingDingAuth:appKey"];
                 string appSecret = _configuration["DingDingAuth:appSecret"];
                 string divide = _configuration["CustomParam:SiteScope"];
@@ -316,7 +322,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
 
                 //获取access_token
                 IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
-                OapiGettokenRequest request = new OapiGettokenRequest() { Appkey = appKey, Appsecret = appSecret };
+                OapiGettokenRequest request = new() { Appkey = appKey, Appsecret = appSecret };
                 request.SetHttpMethod("Get");
                 OapiGettokenResponse response = client.Execute(request);
                 if (response.IsError)
@@ -332,10 +338,10 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 OapiSmartworkHrmEmployeeQuerydimissionResponse rspDimission = quitStaffClient.Execute(reqDimission, access_token);
                 if (rspDimission.Result != null)
                 {
-                    List<DingDingUserInfo> ddUserInfos = new List<DingDingUserInfo>();
+                    List<DingDingUserInfo> ddUserInfos = new();
                     foreach (var itemId in rspDimission.Result.DataList)
                     {
-                        await _azureStorage.DeleteSingle<DingDingUserInfo>(divide, $"{itemId}");
+                        await table.DeleteSingle<DingDingUserInfo>(divide, $"{itemId}");
                     }
 
                     //保存操作记录
@@ -373,12 +379,13 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (!jsonElement.TryGetProperty("permissions", out JsonElement _permissions)) return BadRequest();
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
 
-                StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】醍摩豆账号");
-                List<DingDingUserInfo> ddUserInfo = new List<DingDingUserInfo>();
-                var tempUser = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                StringBuilder stringBuilder = new($"{_tmdName}【{_tmdId}】醍摩豆账号");
+                List<DingDingUserInfo> ddUserInfo = new();
+                var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
                 List<string> listper = _permissions.ToObject<List<string>>();
                 List<string> roles = new();//角色列表
-                List<string> permissions = new List<string>();//权限列表
+                List<string> permissions = new ();//权限列表
 
                 foreach (var item in tempUser)
                 {
@@ -400,7 +407,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     permissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>();
                 }
 
-                ddUserInfo = await _azureStorage.UpdateAll<DingDingUserInfo>(ddUserInfo);
+                ddUserInfo = await table.UpdateAll<DingDingUserInfo>(ddUserInfo);
 
                 //保存操作记录
                 await _azureStorage.SaveLog("tabledd-update", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
@@ -430,7 +437,8 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 string divide = _configuration["CustomParam:SiteScope"];
 
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", $"{divide}" } };
-                List<DingDingUserInfo> tempUserInfos = await _azureStorage.FindListByDict<DingDingUserInfo>(dic);
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                List<DingDingUserInfo> tempUserInfos = await table.FindListByDict<DingDingUserInfo>(dic);
 
                 List<DingDingUserInfo> userInfo = new();
                 tempUserInfos.ForEach(x => {
@@ -507,10 +515,10 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 //    }
                 //}
 
-                List<ddUserInfo> ddUserInfos = new();
+                List<DDUserInfo> ddUserInfos = new();
                 foreach (var item in userInfo)
                 {
-                    ddUserInfo tempUserInfo = new ddUserInfo()
+                    DDUserInfo tempUserInfo = new DDUserInfo()
                     {
                         partitionKey = item.PartitionKey,
                         rowKey = item.RowKey,
@@ -563,9 +571,11 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+
                 List<DingDingUserInfo> tempddUsers = null;
-                List<DingDingUserInfo> ddUsers = new List<DingDingUserInfo>();
-                StringBuilder tableSql = new StringBuilder();
+                List<DingDingUserInfo> ddUsers = new();
+                StringBuilder tableSql = new();
 
                 if (!string.IsNullOrEmpty($"{rowKey}"))
                     tableSql.Append($"RowKey {QueryComparisons.Equal}  '{rowKey}'");
@@ -598,7 +608,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     else return Ok(new { state = 1, message = "该手机号未找到醍摩豆账户" });
                 }
 
-                tempddUsers = await _azureStorage.QueryWhereString<DingDingUserInfo>(tableSql.ToString());
+                tempddUsers = await table.QueryWhereString<DingDingUserInfo>(tableSql.ToString());
 
                 if (tempddUsers.Count > 0)
                 {
@@ -617,7 +627,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     }
                 }
                 else return Ok(new { state = 2, message = "钉钉ID错误请检查钉钉ID" });
-                if (ddUsers.Count > 0) ddUsers = await _azureStorage.SaveOrUpdateAll(ddUsers);
+                if (ddUsers.Count > 0) ddUsers = await table.SaveOrUpdateAll(ddUsers);
 
                 //保存操作记录
                 await _azureStorage.SaveLog("tabledd-update", $"{_tmdName}【{_tmdId}】操作:绑定钉钉账户[{rowKey}]和醍摩豆账户[{tmdId}]", _dingDing, httpContext: HttpContext);
@@ -648,13 +658,15 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 if (!jsonElement.TryGetProperty("isAdmin", out JsonElement isAdmin)) return BadRequest();
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
-
-                var tempUser = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{rowKey}" } });
-                List<ddUserInfo> ddUserInfos = new();
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{rowKey}" } });
+                
+                List<DDUserInfo> ddUserInfos = new();
                 List<string> roles = new();//角色列表
                 List<string> permissions = new List<string>();//权限列表
 
-                StringBuilder msg = new StringBuilder($"{_tmdName}【{_tmdId}】");
+                StringBuilder msg = new($"{_tmdName}【{_tmdId}】");
+
                 if (bool.Parse($"{isAdmin}") == true)
                 {
                     foreach (var user in tempUser)
@@ -663,14 +675,14 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                         {
                             user.roles = "admin,assist";
                         }
-                        List<string> tempRoles = new List<string>(user.roles.Split(","));
+                        List<string> tempRoles = new(user.roles.Split(","));
                         if (!tempRoles.Contains("admin"))
                         {
                             tempRoles.Add("admin");
                         }
                         user.roles = string.Join(",", tempRoles);
-
-                        DingDingUserInfo respUser = await _azureStorage.SaveOrUpdate<DingDingUserInfo>(user);
+                       
+                        DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
 
                         if (respUser != null)
                         {
@@ -682,14 +694,14 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                 {
                     foreach (var user in tempUser)
                     {
-                        List<string> tempRoles = new List<string>(user.roles.Split(","));                        
+                        List<string> tempRoles = new(user.roles.Split(","));                        
                         if (tempRoles.Contains("admin")) 
                         {
                             tempRoles.Remove("admin");
                         }
                         user.roles = string.Join(",", tempRoles);
-
-                        DingDingUserInfo respUser = await _azureStorage.SaveOrUpdate<DingDingUserInfo>(user);
+                        
+                        DingDingUserInfo respUser = await table.SaveOrUpdate<DingDingUserInfo>(user);
 
                         if (respUser != null)
                         {
@@ -725,14 +737,14 @@ namespace TEAMModelBI.Controllers.DingDingStruc
         /// <param name="access_token"></param>
         /// <returns></returns>
         public async Task<List<DingDingUserInfo>> GetDingDingUserInfo(string partitionKey, long deptId, long parentId, string name, string access_token)
-        {
-            List<DingDingUserInfo> ddUserInfos = new List<DingDingUserInfo>();
+        {            
+            List<DingDingUserInfo> ddUserInfos = new();
 
             //获取部门人员信息
             IDingTalkClient userListClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
 
             //获取部门用户
-            OapiV2UserListRequest reqUserList = new OapiV2UserListRequest()
+            OapiV2UserListRequest reqUserList = new()
             {
                 DeptId = deptId,
                 Cursor = 0L,
@@ -750,13 +762,14 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                     var tempInfo = ddUserInfos.Find(x => x.RowKey.Equals(itemUser.Unionid));
                     if (string.IsNullOrEmpty($"{tempInfo}"))
                     {
-                        var tableUsers = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" }, { "unionId", $"{itemUser.Unionid}" } });
-                        if (tableUsers.Count > 0)
+                        var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                        var users = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "RowKey", $"{itemUser.Userid}" }, { "unionId", $"{itemUser.Unionid}" } });
+                        if (users.Count > 0)
                         {
-                            foreach (var tableUser in tableUsers)
+                            foreach (var user in users)
                             {
-                                DingDingUserInfo ddUserInfo = new DingDingUserInfo();
-                                ddUserInfo.PartitionKey = tableUser.PartitionKey;
+                                DingDingUserInfo ddUserInfo = new();
+                                ddUserInfo.PartitionKey = user.PartitionKey;
                                 ddUserInfo.RowKey = itemUser.Userid;
                                 ddUserInfo.unionId = itemUser.Unionid;
                                 ddUserInfo.name = itemUser.Name;
@@ -770,40 +783,42 @@ namespace TEAMModelBI.Controllers.DingDingStruc
                                 ddUserInfo.avatar = itemUser.Avatar;
                                 ddUserInfo.isAdmin = itemUser.Admin;
                                 ddUserInfo.PartitionKey = partitionKey;
-                                ddUserInfo.tmdId = tableUser.tmdId;
-                                ddUserInfo.tmdName = tableUser.tmdName;
-                                ddUserInfo.tmdMobile = tableUser.tmdMobile;
-                                ddUserInfo.mail = tableUser.mail;
-                                ddUserInfo.picture = tableUser.picture;
-                                ddUserInfo.roles = tableUser.roles;
-                                ddUserInfo.permissions = tableUser.permissions;
+                                ddUserInfo.tmdId = user.tmdId;
+                                ddUserInfo.tmdName = user.tmdName;
+                                ddUserInfo.tmdMobile = user.tmdMobile;
+                                ddUserInfo.mail = user.mail;
+                                ddUserInfo.picture = user.picture;
+                                ddUserInfo.roles = user.roles;
+                                ddUserInfo.permissions = user.permissions;
 
                                 ddUserInfos.Add(ddUserInfo);
                             }
                         }
                         else
                         {
-                            DingDingUserInfo ddUserInfo = new DingDingUserInfo();
-                            ddUserInfo.RowKey = itemUser.Userid;
-                            ddUserInfo.unionId = itemUser.Unionid;
-                            ddUserInfo.name = itemUser.Name;
-                            ddUserInfo.title = itemUser.Title;
-                            ddUserInfo.mobile = itemUser.Mobile;
-                            ddUserInfo.jobNumber = itemUser.JobNumber;
-                            ddUserInfo.pid = parentId;
-                            ddUserInfo.deptId = deptId;
-                            ddUserInfo.deptName = name;
-                            ddUserInfo.depts = string.Join(",", itemUser.DeptIdList.ToArray());
-                            ddUserInfo.avatar = itemUser.Avatar;
-                            ddUserInfo.isAdmin = itemUser.Admin;
-                            ddUserInfo.PartitionKey = partitionKey;
-                            ddUserInfo.tmdId = "";
-                            ddUserInfo.tmdName = "";
-                            ddUserInfo.tmdMobile = "";
-                            ddUserInfo.mail = "";
-                            ddUserInfo.picture = "";
-                            ddUserInfo.roles = "assist";
-                            ddUserInfo.permissions = "abilitystandard-read,batcharea-read,batchschool-read,orgusers-read";
+                            DingDingUserInfo ddUserInfo = new()
+                            {
+                                RowKey = itemUser.Userid,
+                                unionId = itemUser.Unionid,
+                                name = itemUser.Name,
+                                title = itemUser.Title,
+                                mobile = itemUser.Mobile,
+                                jobNumber = itemUser.JobNumber,
+                                pid = parentId,
+                                deptId = deptId,
+                                deptName = name,
+                                depts = string.Join(",", itemUser.DeptIdList.ToArray()),
+                                avatar = itemUser.Avatar,
+                                isAdmin = itemUser.Admin,
+                                PartitionKey = partitionKey,
+                                tmdId = "",
+                                tmdName = "",
+                                tmdMobile = "",
+                                mail = "",
+                                picture = "",
+                                roles = "assist",
+                                permissions = "abilitystandard-read,batcharea-read,batchschool-read,orgusers-read"
+                            };
 
                             ddUserInfos.Add(ddUserInfo);
                         }
@@ -814,7 +829,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
             return ddUserInfos;
         }
 
-        public record ddUserInfo
+        public record DDUserInfo
         {
             public string partitionKey { get; set; }
             public string rowKey { get; set; }

+ 23 - 21
TEAMModelBI/Controllers/LoginController.cs

@@ -158,7 +158,7 @@ namespace TEAMModelBI.Controllers
                 }
                 if (teacher == null)
                 {
-                    return Ok(new { state = 1, dingDingBind = dingDingBind });
+                    return Ok(new { state = 1, dingDingBind });
                 }
                 else
                 {
@@ -174,7 +174,8 @@ namespace TEAMModelBI.Controllers
                         }, location, _configuration);
 
                     Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };//设置只访问BI的权限
-                    List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);  //获取权限列表
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+                    List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);  //获取权限列表
 
                     if (implicit_token!=null)
                     {
@@ -296,7 +297,8 @@ namespace TEAMModelBI.Controllers
                     }, location, _configuration);
 
                 Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };//设置只访问BI的权限
-                List<Authority> authorityBIList = await _azureStorage.FindListByDict<Authority>(dic);  //获取权限列表
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+                List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);  //获取权限列表
 
                 List<string> roles = new List<string>();//角色列表
                 List<string> permissions = new List<string>();//权限列表
@@ -419,18 +421,15 @@ namespace TEAMModelBI.Controllers
 
                 //获取access_token
                 IDingTalkClient tokenClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
-                OapiGettokenRequest tokenRequest = new OapiGettokenRequest() { Appkey = appKey, Appsecret = appSecret };
+                OapiGettokenRequest tokenRequest = new() { Appkey = appKey, Appsecret = appSecret };
                 tokenRequest.SetHttpMethod("Get");
                 OapiGettokenResponse tokenRespone = tokenClient.Execute(tokenRequest);
-                if (tokenRespone.IsError)
-                {
-                    return BadRequest();
-                }
+                if (tokenRespone.IsError) return BadRequest();              
 
                 string access_token = tokenRespone.AccessToken;
                 //获取临时授权码 获取授权用户的个人信息
-                DefaultDingTalkClient clientinfo = new DefaultDingTalkClient("https://oapi.dingtalk.com/sns/getuserinfo_bycode");
-                OapiSnsGetuserinfoBycodeRequest req = new OapiSnsGetuserinfoBycodeRequest() { TmpAuthCode = $"{LoginTempCode}" };  //通过扫描二维码,跳转到指定的Url后,向Url中追加Code临时授权码
+                DefaultDingTalkClient clientinfo = new("https://oapi.dingtalk.com/sns/getuserinfo_bycode");
+                OapiSnsGetuserinfoBycodeRequest req = new() { TmpAuthCode = $"{LoginTempCode}" };  //通过扫描二维码,跳转到指定的Url后,向Url中追加Code临时授权码
                 OapiSnsGetuserinfoBycodeResponse response = clientinfo.Execute(req, appKey, appSecret);
 
                 if (response.Errcode.Equals(40078)) 
@@ -440,7 +439,7 @@ namespace TEAMModelBI.Controllers
 
                 string unionid = response.UserInfo.Unionid;
                 IDingTalkClient client2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/getbyunionid"); //userid地址
-                OapiUserGetbyunionidRequest byunionidRequest = new OapiUserGetbyunionidRequest() { Unionid = unionid };
+                OapiUserGetbyunionidRequest byunionidRequest = new() { Unionid = unionid };
                 OapiUserGetbyunionidResponse byunionidResponse = client2.Execute(byunionidRequest, access_token);
                 if (byunionidResponse.IsError|| byunionidResponse.Errcode == 60121)
                 {
@@ -449,7 +448,7 @@ namespace TEAMModelBI.Controllers
                 // 根据userId获取用户信息
                 string userid = byunionidResponse.Result.Userid;
                 IDingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
-                OapiV2UserGetRequest v2GetRequest = new OapiV2UserGetRequest()
+                OapiV2UserGetRequest v2GetRequest = new()
                 {
                     Userid = userid,
                     Language = "zh_CN"
@@ -462,7 +461,8 @@ namespace TEAMModelBI.Controllers
                     return Ok(new { state = 0, message = "扫码登录失败" });
                 }
 
-                List<DingDingUserInfo> ddusers = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{v2GetResponse.Result.Userid}" }, { "unionId", $"{v2GetResponse.Result.Unionid}" } });
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                List<DingDingUserInfo> ddusers = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{v2GetResponse.Result.Userid}" }, { "unionId", $"{v2GetResponse.Result.Unionid}" } });
 
                 if (ddusers.Count > 0)
                 {
@@ -503,7 +503,7 @@ namespace TEAMModelBI.Controllers
                 }
                 else
                 {
-                    DingDingUserInfo dingDingUserInfo = new DingDingUserInfo()
+                    DingDingUserInfo dingDingUserInfo = new ()
                     {
                         PartitionKey = divide,
                         RowKey = v2GetResponse.Result.Userid,
@@ -525,8 +525,8 @@ namespace TEAMModelBI.Controllers
                         picture = "",
                         roles = "",
                         permissions = "",
-                    };
-                    await _azureStorage.Save<DingDingUserInfo>(dingDingUserInfo);
+                    };                    
+                    await table.Save<DingDingUserInfo>(dingDingUserInfo);
 
                     return Ok(new { state = 400, ddUserId = dingDingUserInfo });
                 }
@@ -559,12 +559,13 @@ namespace TEAMModelBI.Controllers
 
                 if (responseMessage.StatusCode == HttpStatusCode.OK)
                 {
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
                     var temp = await responseMessage.Content.ReadAsStringAsync();
                     if (temp.Length > 0)
                     {
                         List<DingDingUserInfo> ddUserInfos = new();
                         List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
-                        var tempUser = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
+                        var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
                         foreach (var item in itemjson)
                         {
                             foreach (var itemUser in tempUser)
@@ -584,7 +585,7 @@ namespace TEAMModelBI.Controllers
                             }
                         }
 
-                        var dingDingUserInfos = await _azureStorage.UpdateAll<DingDingUserInfo>(ddUserInfos);
+                        var dingDingUserInfos = await table.UpdateAll(ddUserInfos);
 
 
                         return Ok(new { state = 200, ddUsers = dingDingUserInfos });
@@ -614,10 +615,11 @@ namespace TEAMModelBI.Controllers
                 if (!jsonElement.TryGetProperty("mobile", out JsonElement moile)) return BadRequest();
                 if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
                 if (!jsonElement.TryGetProperty("rowKey", out JsonElement userId)) return BadRequest();
-                var tempUser = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
 
                 List<string> roles = new();//角色列表
-                List<string> permissions = new List<string>();//权限列表
+                List<string> permissions = new();//权限列表
                 List<DingDingUserInfo> ddUserInfos = new();
                 var id_token = "";
 
@@ -659,7 +661,7 @@ namespace TEAMModelBI.Controllers
                                     ddUserInfos.Add(itemUser);
                                 }
 
-                                ddUserInfos = await _azureStorage.UpdateAll<DingDingUserInfo>(ddUserInfos);
+                                ddUserInfos = await table.UpdateAll<DingDingUserInfo>(ddUserInfos);
 
                                 //保存操作记录
                                 await _azureStorage.SaveLog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext);

+ 6 - 4
TEAMModelBI/Controllers/OperateRecord/OperateLogController.cs

@@ -60,7 +60,8 @@ namespace TEAMModelBI.Controllers.OperateRecord
                 if (!string.IsNullOrEmpty($"{platform}"))
                     tableSql.Append(!string.IsNullOrEmpty(tableSql.ToString()) ? $" and platform eq '{platform}' " : $" platform eq '{platform}' ");
 
-                operateLogs = await _azureStorage.QueryWhereString<OptLog>(tableSql.ToString());
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("OptLog");
+                operateLogs = await table.QueryWhereString<OptLog>(tableSql.ToString());
                 return Ok(new { state = 200, operateLogs });
             }
             catch (Exception ex)
@@ -100,7 +101,8 @@ namespace TEAMModelBI.Controllers.OperateRecord
                     tableStrWhere.Append($"time ge {startDate}L and time le {endDate}L ");
                     operateStr.Append($"删除的时间戳,开始——结束时间戳:{startDate}-{endDate}");
                 }
-                var temp = await _azureStorage.DeleteStringWhere<OptLog>(rowKey: tableStrWhere.ToString());
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("OptLog");
+                var temp = await table.DeleteStringWhere<OptLog>(rowKey: tableStrWhere.ToString());
 
                 //保存操作记录
                 await _azureStorage.SaveLog("operatelog-del", operateStr?.ToString(), _dingDing, httpContext: HttpContext);
@@ -137,8 +139,8 @@ namespace TEAMModelBI.Controllers.OperateRecord
                     storageSql = $"tmdId eq '{tmdId}' and platform eq '{platform}'";
                 else storageSql = $"tmdId eq '{tmdId}'";
 
-                List<OptLog> optLogs = new List<OptLog>();
-                optLogs = await _azureStorage.QueryWhereString<OptLog>(storageSql);
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("OptLog");
+                var optLogs = await table.QueryWhereString<OptLog>(storageSql);
 
                 return Ok(new { state = 200, optLogs });
             }

+ 11 - 6
TEAMModelOS.FunctionV4/CosmosDB/TriggerCorrect.cs

@@ -42,14 +42,17 @@ namespace TEAMModelOS.FunctionV4
             {
                 return;
             }
-            await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}阅卷配置【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在执行", GroupNames.成都开发測試群組);
+            //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}阅卷配置【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在执行", GroupNames.成都开发測試群組);
+
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+
             try {
                 Correct correct = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Correct>(tdata.id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
 
                 if (correct != null)
                 {
                     string PartitionKey = string.Format("{0}{1}{2}", correct.code, "-", correct.progress);
-                    List<ChangeRecord> correctRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    List<ChangeRecord> correctRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (correct.progress)
                     {
                         case "pending":
@@ -60,7 +63,7 @@ namespace TEAMModelOS.FunctionV4
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCorrect, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), correctRecords[0].sequenceNumber);
                                 correctRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(correctRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(correctRecords[0]);
                             }
                             else
                             {
@@ -72,7 +75,8 @@ namespace TEAMModelOS.FunctionV4
                                     sequenceNumber = start,
                                     msgId = messageCorrect.MessageId
                                 };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
@@ -342,7 +346,7 @@ namespace TEAMModelOS.FunctionV4
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageCorrectEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), correctRecords[0].sequenceNumber);
                                 correctRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(correctRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(correctRecords[0]);
                             }
                             else
                             {
@@ -354,7 +358,8 @@ namespace TEAMModelOS.FunctionV4
                                     sequenceNumber = end,
                                     msgId = messageCorrectEnd.MessageId
                                 };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "finish":

+ 13 - 15
TEAMModelOS.FunctionV4/CosmosDB/TriggerExam.cs

@@ -23,8 +23,8 @@ namespace TEAMModelOS.FunctionV4
             CosmosClient client, JsonElement input, TriggerData data)
         {
 
-            List<ExamClassResult> examClassResults = new List<ExamClassResult>();
-            List<ExamSubject> examSubjects = new List<ExamSubject>();
+            List<ExamClassResult> examClassResults = new();
+            List<ExamSubject> examSubjects = new();
             try
             {
                 if ((data.status != null && data.status.Value == 404))
@@ -65,9 +65,9 @@ namespace TEAMModelOS.FunctionV4
                             }
                         }
                     }
-
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                     string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
-                    List<ChangeRecord> records = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
+                    List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
                     //处理科目信息
                     List<string> sub = new List<string>();
                     foreach (ExamSubject subject in info.subjects)
@@ -87,7 +87,7 @@ namespace TEAMModelOS.FunctionV4
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
                                 records[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(records[0]);
                                 //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
                             }
                             else
@@ -100,8 +100,8 @@ namespace TEAMModelOS.FunctionV4
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = message.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                               
+                                await table.Save<ChangeRecord>(changeRecord);
                                 //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
                             }
                             break;
@@ -328,8 +328,6 @@ namespace TEAMModelOS.FunctionV4
                                         await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
                                     }
                                 }
-
-
                             }
                             catch (Exception e)
                             {
@@ -345,7 +343,7 @@ namespace TEAMModelOS.FunctionV4
                                     long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
                                     await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
                                     records[0].sequenceNumber = end;
-                                    await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
+                                    await table.SaveOrUpdate<ChangeRecord>(records[0]);
                                     //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
                                 }
                                 else
@@ -358,8 +356,8 @@ namespace TEAMModelOS.FunctionV4
                                         PartitionKey = PartitionKey,
                                         sequenceNumber = end,
                                         msgId = messageEnd.MessageId
-                                    };
-                                    await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                    };                                   
+                                    await table.Save<ChangeRecord>(changeRecord);
                                     //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
                                 }
                             }
@@ -377,7 +375,7 @@ namespace TEAMModelOS.FunctionV4
                                     newStatus = 1;
                                 }
                                 //处理活动中间件
-                                List<StuActivity> stus = new List<StuActivity>();
+                                List<StuActivity> stus = new();
                                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<StuActivity>(
                                                    queryText: $"select c.id from c where c.id  = '{info.id}'"))
                                 {
@@ -439,8 +437,8 @@ namespace TEAMModelOS.FunctionV4
         public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info, List<ExamClassResult> examClassResults)
         {
             //计算单次考试简易统计信息
-            Settlement settlement = new Settlement();
-            List<ExamResult> examResults = new List<ExamResult>();
+            Settlement settlement = new();
+            List<ExamResult> examResults = new();
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
                                queryText: $"select value(c) from c where c.examId  = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
             {

+ 12 - 12
TEAMModelOS.FunctionV4/CosmosDB/TriggerExamLite.cs

@@ -47,11 +47,11 @@ namespace TEAMModelOS.FunctionV4
                 }
                // await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修评测活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 ExamLite lite = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>(tdata.id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                 if (lite != null)
                 {
                     string PartitionKey = string.Format("{0}{1}{2}", lite.code, "-", lite.progress);
-                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    List<ChangeRecord> changeRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (lite.progress)
                     {
                         case "pending":
@@ -62,23 +62,23 @@ namespace TEAMModelOS.FunctionV4
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 changeRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
-                            List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
+                            List<(string pId, List<string> gid)> ps = new();
                             if (lite.groupLists.Count > 0)
                             {
                                 var group = lite.groupLists;
@@ -91,7 +91,7 @@ namespace TEAMModelOS.FunctionV4
                                 }
                             }
                             (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, lite.tchLists, lite.school, ps);
-                            List<StuActivity> tchActivities = new List<StuActivity>();
+                            List<StuActivity> tchActivities = new();
                             (string standard, List<string> tmdids, string school, List<string> update, int statistics)  list =    (null,null, null, new List<string> { StatisticsService.TeacherExamLite }, 0)  ;
                             if (tchList.IsNotEmpty())
                             {
@@ -138,19 +138,19 @@ namespace TEAMModelOS.FunctionV4
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 changeRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageWorkEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "finish":

+ 16 - 16
TEAMModelOS.FunctionV4/CosmosDB/TriggerHomework.cs

@@ -48,34 +48,34 @@ namespace TEAMModelOS.FunctionV4
                 }
                 //await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 Homework work = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>(tdata.id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                 if (work != null)
                 {
-                    string PartitionKey = string.Format("{0}{1}{2}", work.code, "-", work.progress);
-                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    string PartitionKey = string.Format("{0}{1}{2}", work.code, "-", work.progress);                   
+                    List<ChangeRecord> changeRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (work.progress)
                     {
                         case "pending":
-                            var messageWork = new ServiceBusMessage(new { id = tdata.id, progress = "going", code = tdata.code }.ToJsonString());
+                            var messageWork = new ServiceBusMessage(new { tdata.id, progress = "going", tdata.code }.ToJsonString());
                             messageWork.ApplicationProperties.Add("name", "Homework");
                             if (changeRecords.Count > 0)
                             {
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 changeRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
@@ -95,9 +95,9 @@ namespace TEAMModelOS.FunctionV4
                             (List<RMember> tmdids, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, classes, work.school, ps);
                             var addStudentsCls = tmdids.FindAll(x => x.type == 2);
                             var addTmdidsCls = tmdids.FindAll(x => x.type == 1);
-                            List<StuActivity> stuActivities = new List<StuActivity>();
-                            List<StuActivity> tmdActivities = new List<StuActivity>();
-                            List<StuActivity> tchActivities = new List<StuActivity>();
+                            List<StuActivity> stuActivities = new();
+                            List<StuActivity> tmdActivities = new();
+                            List<StuActivity> tchActivities = new();
                             if (addTmdidsCls.IsNotEmpty())
                             {
                                 addTmdidsCls.ForEach(x =>
@@ -182,7 +182,7 @@ namespace TEAMModelOS.FunctionV4
                                 }
                                 tchList.ForEach(x =>
                                 {
-                                    HashSet<string> classIds = new HashSet<string>();
+                                    HashSet<string> classIds = new();
                                     classInfos.ForEach(z => {
                                         z.members.ForEach(y => {
                                             if (y.id.Equals(x) && y.type == 1)
@@ -223,19 +223,19 @@ namespace TEAMModelOS.FunctionV4
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 changeRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageWorkEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             //if (bustasks.IsNotEmpty())
                             //{

+ 10 - 9
TEAMModelOS.FunctionV4/CosmosDB/TriggerStudy.cs

@@ -52,7 +52,8 @@ namespace TEAMModelOS.FunctionV4
                 if (study != null)
                 {
                     string PartitionKey = string.Format("{0}{1}{2}", study.code, "-", study.progress);
-                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
+                    List<ChangeRecord> changeRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (study.progress)
                     {
                         case "pending":
@@ -63,19 +64,19 @@ namespace TEAMModelOS.FunctionV4
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 changeRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWork, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
@@ -145,19 +146,19 @@ namespace TEAMModelOS.FunctionV4
                                     long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                     await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                     changeRecords[0].sequenceNumber = end;
-                                    await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                    await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                                 }
                                 else
                                 {
                                     long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageWorkEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
-                                    ChangeRecord changeRecord = new ChangeRecord
+                                    ChangeRecord changeRecord = new()
                                     {
                                         RowKey = tdata.id,
                                         PartitionKey = PartitionKey,
                                         sequenceNumber = end,
                                         msgId = messageWorkEnd.MessageId
-                                    };
-                                    await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                    };                                   
+                                    await table.Save<ChangeRecord>(changeRecord);
                                 }
 
                             }

+ 11 - 9
TEAMModelOS.FunctionV4/CosmosDB/TriggerSurvey.cs

@@ -58,31 +58,32 @@ namespace TEAMModelOS.FunctionV4
 
                 if (survey != null)
                 {
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                     string PartitionKey = string.Format("{0}{1}{2}", survey.code, "-", survey.progress);
-                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    List<ChangeRecord> changeRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (survey.progress)
                     {
                         case "pending":
-                            var messageSurvey = new ServiceBusMessage(new { id = tdata.id, progress = "going", code = tdata.code }.ToJsonString());
+                            var messageSurvey = new ServiceBusMessage(new { tdata.id, progress = "going", tdata.code }.ToJsonString());
                             messageSurvey.ApplicationProperties.Add("name", "Survey");
                             if (changeRecords.Count > 0)
                             {
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 changeRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageSurvey, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageSurvey.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
@@ -250,7 +251,7 @@ namespace TEAMModelOS.FunctionV4
                             #endregion
 #if DEBUG
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}问卷调查{tdata.id}写入完成!", GroupNames.成都开发測試群組);
-#endif
+#endif                           
                             var messageSurveyEnd = new ServiceBusMessage(new { id = tdata.id, progress = "finish", code = tdata.code }.ToJsonString());
                             messageSurveyEnd.ApplicationProperties.Add("name", "Survey");
                             if (changeRecords.Count > 0)
@@ -258,7 +259,7 @@ namespace TEAMModelOS.FunctionV4
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageSurveyEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), changeRecords[0].sequenceNumber);
                                 changeRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(changeRecords[0]);
                             }
                             else
                             {
@@ -270,7 +271,8 @@ namespace TEAMModelOS.FunctionV4
                                     sequenceNumber = end,
                                     msgId = messageSurveyEnd.MessageId
                                 };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
 #if DEBUG
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}问卷调查{tdata.id}将于:{tdata.endTime}完成并结算!", GroupNames.成都开发測試群組);

+ 11 - 10
TEAMModelOS.FunctionV4/CosmosDB/TriggerVote.cs

@@ -37,6 +37,7 @@ namespace TEAMModelOS.FunctionV4
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{tdata.id}");
                     return;
                 }
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
                 var adid = tdata.id;
                 var adcode = "";
                 string blobcntr = null;
@@ -56,7 +57,7 @@ namespace TEAMModelOS.FunctionV4
                 if (vote != null)
                 {
                     string PartitionKey = string.Format("{0}{1}{2}", vote.code, "-", vote.progress);
-                    List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
+                    List<ChangeRecord> voteRecords = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", tdata.id }, { "PartitionKey", PartitionKey } });
                     switch (vote.progress)
                     {
                         case "pending":
@@ -67,7 +68,7 @@ namespace TEAMModelOS.FunctionV4
                                 long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVote, DateTimeOffset.FromUnixTimeMilliseconds(tdata.startTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber);
                                 voteRecords[0].sequenceNumber = start;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
                             }
                             else
                             {
@@ -78,8 +79,8 @@ namespace TEAMModelOS.FunctionV4
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageVote.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
                             break;
                         case "going":
@@ -264,19 +265,19 @@ namespace TEAMModelOS.FunctionV4
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
                                 await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), voteRecords[0].sequenceNumber);
                                 voteRecords[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
+                                await table.SaveOrUpdate<ChangeRecord>(voteRecords[0]);
                             }
                             else
                             {
                                 long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageVoteEnd, DateTimeOffset.FromUnixTimeMilliseconds(tdata.endTime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                ChangeRecord changeRecord = new()
                                 {
                                     RowKey = tdata.id,
                                     PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageVoteEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                };                                
+                                await table.Save<ChangeRecord>(changeRecord);
                             }
 #if DEBUG
                             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动{tdata.id}将于:{tdata.endTime}完成并结算!", GroupNames.成都开发測試群組);
@@ -298,8 +299,8 @@ namespace TEAMModelOS.FunctionV4
                                     countcds.Add(new { code = count.Element.ToString(), count = (int)count.Score });
                                 }
                             }
-                            List<Task<string>> tasks = new List<Task<string>>();
-                            List<VoteRecord> recordsBlob = new List<VoteRecord>();
+                            List<Task<string>> tasks = new();
+                            List<VoteRecord> recordsBlob = new();
                             foreach (var rcd in records)
                             {
                                 var value = rcd.Value.ToString().ToObject<VoteRecord>();

+ 4 - 3
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -279,7 +279,8 @@ namespace TEAMModelOS.SDK.DI
         /// <returns></returns>
         public static async Task SaveLog(this AzureStorageFactory azureStorage, string type, string msg,DingDing dingDing, string scope = null, string bizId = null, Option option = null, HttpContext httpContext = null)
         {
-            OptLog log = new OptLog() { RowKey = Guid.NewGuid().ToString() };
+            var table = azureStorage.GetCloudTableClient().GetTableReference("OptLog");
+            OptLog log = new() { RowKey = Guid.NewGuid().ToString() };
             try
             {
                 object id = null, school = null, name = null, website = null ;
@@ -305,10 +306,10 @@ namespace TEAMModelOS.SDK.DI
                     log.jsonfile = $"/0-public/optlog/{log.RowKey}-{log.PartitionKey}.json";
                     await azureStorage.UploadFileByContainer("0-public", log.ToJsonString(), "optlog", $"{log.RowKey}-{log.PartitionKey}.json");
                     log.msg = null;
-                    await azureStorage.SaveOrUpdate<OptLog>(log);
+                    await table.SaveOrUpdate<OptLog>(log);
                 }
                 else {
-                    await azureStorage.SaveOrUpdate<OptLog>(log);
+                    await table.SaveOrUpdate<OptLog>(log);
                 }
             }
             catch (Exception ex)

+ 50 - 73
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageTableExtensions.cs

@@ -227,48 +227,40 @@ namespace TEAMModelOS.SDK.DI
         }
         #endregion
 
-        public static async Task<T> Save<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
-        {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
-            TableOperation operation = TableOperation.Insert(entity);
-            TableResult result = await TableName.ExecuteAsync(operation);
-            return (T)result.Result;
+        public static async Task<T> Save<T>(this CloudTable table, TableEntity entity) where T : TableEntity, new()
+        {                  
+            TableResult result = await table.ExecuteAsync(TableOperation.Insert(entity));
+            return result.Result as T;
         }
-        public static async Task<T> SaveOrUpdate<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> SaveOrUpdate<T>(this CloudTable table, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
-            TableOperation operation = TableOperation.InsertOrReplace(entity);
-            TableResult result = await TableName.ExecuteAsync(operation);
-            return (T)result.Result;
+            TableResult result = await table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
+            return result.Result as T;
         }
 
-        public static async Task<T> Update<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
-        {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
-            TableOperation operation = TableOperation.Replace(entity);
-            TableResult result = await TableName.ExecuteAsync(operation);
-            return (T)result.Result;
+        public static async Task<T> Update<T>(this CloudTable table, TableEntity entity) where T : TableEntity, new()
+        {                       
+            TableResult result = await table.ExecuteAsync(TableOperation.Replace(entity));
+            return result.Result as T;
         }
 
-        public static async Task<T> Delete<T>(this AzureStorageFactory azureStorage, TableEntity entity) where T : TableEntity, new()
+        public static async Task<T> Delete<T>(this CloudTable table, TableEntity entity) where T : TableEntity, new()
         {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
-            TableOperation operation = TableOperation.Delete(entity);
-            TableResult result = await TableName.ExecuteAsync(operation);
-            return (T)result.Result;
+            TableResult result = await table.ExecuteAsync(TableOperation.Delete(entity));
+            return result.Result as T;
         }
 
-        public static async Task<List<T>> DeleteAll<T>(this AzureStorageFactory azureStorage,  List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> DeleteAll<T>(this CloudTable table,  List<T> entitys) where T : TableEntity, new()
         {
             if (!entitys.IsNotEmpty())
             {
                 return null;
             }
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+            
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
-                Dictionary<string, List<T>> dictInfo = new Dictionary<string, List<T>>
+                Dictionary<string, List<T>> dictInfo = new()
                 {
                     { group.Key, group.ToList() }
                 };
@@ -287,25 +279,22 @@ namespace TEAMModelOS.SDK.DI
                     for (int i = 0; i < pages; i++)
                     {
                         List<T> lists = values.Skip((i) * pageSize).Take(pageSize).ToList();
-                        TableBatchOperation batchOperation = new TableBatchOperation();
+                        TableBatchOperation batchOperation = new();
                         for (int j = 0; j < lists.Count; j++)
                         {
                             batchOperation.Delete(lists[j]);
                         }
-                        result = await TableName.ExecuteBatchAsync(batchOperation);
+                        result = await table.ExecuteBatchAsync(batchOperation);
                     }
                 }
             }
             return entitys;
         }
 
-        public static async Task<List<T>> SaveOrUpdateAll<T>(this AzureStorageFactory azureStorage, List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> SaveOrUpdateAll<T>(this CloudTable table, List<T> entitys) where T : TableEntity, new()
         {
-            if (!entitys.IsNotEmpty())
-            {
-                return null;
-            }
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+            if (!entitys.IsNotEmpty()) return null;           
+            
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -333,19 +322,16 @@ namespace TEAMModelOS.SDK.DI
                         {
                             batchOperation.InsertOrReplace(lists[j]);
                         }
-                        result = await TableName.ExecuteBatchAsync(batchOperation);
+                        result = await table.ExecuteBatchAsync(batchOperation);
                     }
                 }
             }
             return entitys;
         }
-        public static async Task<List<T>> UpdateAll<T>(this AzureStorageFactory azureStorageFactory, List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> UpdateAll<T>(this CloudTable table, List<T> entitys) where T : TableEntity, new()
         {
-            if (!entitys.IsNotEmpty())
-            {
-                return null;
-            }
-            CloudTable TableName = await azureStorageFactory.InitializeTable<T>();
+            if (!entitys.IsNotEmpty()) return null;            
+            
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -373,19 +359,16 @@ namespace TEAMModelOS.SDK.DI
                         {
                             batchOperation.Replace(lists[j]);
                         }
-                        result = await TableName.ExecuteBatchAsync(batchOperation);
+                        result = await table.ExecuteBatchAsync(batchOperation);
                     }
                 }
             }
             return entitys;
         }
-        public static async Task<List<T>> SaveAll<T>(this AzureStorageFactory azureStorage, List<T> entitys) where T : TableEntity, new()
+        public static async Task<List<T>> SaveAll<T>(this CloudTable table, List<T> entitys) where T : TableEntity, new()
         {
-            if (!entitys.IsNotEmpty())
-            {
-                return null;
-            }
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+            if (!entitys.IsNotEmpty()) return null;            
+           
             IList<Dictionary<string, List<T>>> listInfo = new List<Dictionary<string, List<T>>>();
             foreach (IGrouping<string, T> group in entitys.GroupBy(c => c.PartitionKey))
             {
@@ -413,18 +396,17 @@ namespace TEAMModelOS.SDK.DI
                         {
                             batchOperation.Insert(lists[j]);
                         }
-                        result = await TableName.ExecuteBatchAsync(batchOperation);
+                        result = await table.ExecuteBatchAsync(batchOperation);
                     }
                 }
             }
             return entitys;
         }
 
-        public static async Task<List<T>> FindListByDict<T>(this AzureStorageFactory azureStorage, Dictionary<string, object> dict) where T : TableEntity, new()
-        {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+        public static async Task<List<T>> FindListByDict<T>(this CloudTable table, Dictionary<string, object> dict) where T : TableEntity, new()
+        {            
             var exQuery = new TableQuery<T>();
-            StringBuilder builder = new StringBuilder();
+            StringBuilder builder = new();
             if (null != dict && dict.Count > 0)
             {
                 var keys = dict.Keys;
@@ -459,7 +441,7 @@ namespace TEAMModelOS.SDK.DI
                 }
 
                 exQuery.Where(builder.ToString());
-                return await QueryList<T>(exQuery, TableName);
+                return await QueryList<T>(exQuery, table);
             }
             else
             {
@@ -522,12 +504,11 @@ namespace TEAMModelOS.SDK.DI
         /// <param name="azureStorage"></param>
         /// <param name="strWhere">查询条件| 例:$"RowKey {QueryComparisons.GreaterThanOrEqual} '{123456}' {TableOperators.And} RowKey {QueryComparisons.LessThanOrEqual} '{123456}'" </param>
         /// <returns></returns>
-        public static async Task<List<T>> QueryWhereString<T>(this AzureStorageFactory azureStorage, string strWhere = null) where T : TableEntity, new()
-        {
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+        public static async Task<List<T>> QueryWhereString<T>(this CloudTable table, string strWhere = null) where T : TableEntity, new()
+        {            
             var exQuery = new TableQuery<T>();
             exQuery.Where(strWhere);
-            return await QueryList<T>(exQuery, TableName);
+            return await QueryList<T>(exQuery, table);
         }
 
         /// <summary>
@@ -538,17 +519,15 @@ namespace TEAMModelOS.SDK.DI
         /// <param name="partitionKey"></param>
         /// <param name="rowKey"></param>
         /// <returns></returns>
-        public static async Task<TableResult> DeleteSingle<T>(this AzureStorageFactory azureStorage, string partitionKey, string rowKey) where T : ITableEntity, new()
+        public static async Task<TableResult> DeleteSingle<T>(this CloudTable table, string partitionKey, string rowKey) where T : ITableEntity, new()
         {
-            // query all rows
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+            // query all rows            
             var queryOperation = TableOperation.Retrieve<T>(partitionKey, rowKey);
 
-            var tableResult = await TableName.ExecuteAsync(queryOperation);
+            var tableResult = await table.ExecuteAsync(queryOperation);
             if (tableResult.Result is T item)
-            {
-                var deleteOperation = TableOperation.Delete(item);
-                var dels = await TableName.ExecuteAsync(deleteOperation);
+            {                
+                var dels = await table.ExecuteAsync(TableOperation.Delete(item));
                 return dels;
             }
             else return null;
@@ -561,18 +540,17 @@ namespace TEAMModelOS.SDK.DI
         /// <param name="azureStorage"></param>
         /// <param name="rowKey"></param>
         /// <returns></returns>
-        public static async Task<List<string>> DeleteStringWhere<T>(this AzureStorageFactory azureStorage, string rowKey) where T : ITableEntity, new()
+        public static async Task<List<string>> DeleteStringWhere<T>(this CloudTable table, string rowKey) where T : ITableEntity, new()
         {
-            // query all rows
-            CloudTable TableName = await azureStorage.InitializeTable<T>();
+            // query all rows           
 
             var exQuery = new TableQuery<T>();
             exQuery.Where(rowKey);
             TableContinuationToken continuationToken = null;
-            List<T> entitys = new List<T>();
+            List<T> entitys = new();
             do
             {
-                var result = await TableName.ExecuteQuerySegmentedAsync(exQuery, continuationToken);                
+                var result = await table.ExecuteQuerySegmentedAsync(exQuery, continuationToken);                
                 if (result.Results.Count > 0)
                 {
                     entitys.AddRange(result.ToList());
@@ -582,13 +560,12 @@ namespace TEAMModelOS.SDK.DI
 
             List<string> ster = new List<string>();
             foreach (var item in entitys)
-            {
-                var queryOperation = TableOperation.Retrieve<T>(item.PartitionKey, item.RowKey);
-                var tableResult = await TableName.ExecuteAsync(queryOperation);
+            {                
+                var tableResult = await table.ExecuteAsync(TableOperation.Retrieve<T>(item.PartitionKey, item.RowKey));
                 if (tableResult.Result is T items)
                 {
                     var deleteOperation = TableOperation.Delete(items);
-                    await TableName.ExecuteAsync(deleteOperation);
+                    await table.ExecuteAsync(deleteOperation);
                     ster.Add(items.RowKey);
                 }
             }

+ 9 - 11
TEAMModelOS.SDK/Helper/Security/Md5Hash/Md5Hash.cs

@@ -16,17 +16,15 @@ namespace TEAMModelOS.SDK
         /// <returns></returns>
         public static string Encrypt(string input, bool half)
         {
-            using (var md5 = MD5.Create())
+            using var md5 = MD5.Create();
+            var result = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
+            var strResult = BitConverter.ToString(result);
+            strResult = strResult.Replace("-", "");
+            if (half)//16位MD5加密(取32位加密的9~25字符)
             {
-                var result = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
-                var strResult = BitConverter.ToString(result);
-                strResult = strResult.Replace("-", "");
-                if (half)//16位MD5加密(取32位加密的9~25字符)
-                {
-                    strResult = strResult?.Substring(8, 16);
-                }
-                return strResult;
+                strResult = strResult?.Substring(8, 16);
             }
+            return strResult;
         }
         #endregion
 
@@ -37,7 +35,7 @@ namespace TEAMModelOS.SDK
         /// <returns></returns>
         public static string Encrypt(string strPwd)
         {
-            MD5 md5 = new MD5CryptoServiceProvider();
+            using var md5 = MD5.Create();
             byte[] data = System.Text.Encoding.Default.GetBytes(strPwd);
             byte[] result = md5.ComputeHash(data);
             string ret = "";
@@ -47,7 +45,7 @@ namespace TEAMModelOS.SDK
         }
         public static string GetMd5Str_16X(string ConvertString) //16位小写
         {
-            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
+            using var md5 = MD5.Create();
             string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
             t2 = t2.Replace("-", "");
             t2 = t2.ToLower();

+ 4 - 3
TEAMModelOS.SDK/Models/Service/SchoolService.cs

@@ -28,6 +28,7 @@ namespace TEAMModelOS.SDK
             List<ScSchool> matchSchools = null;
             List<ScSchool> schools = null;
             List<ScSchool> saveschools = null;
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
             // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
             (  int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
             if (status == 200)
@@ -68,7 +69,7 @@ namespace TEAMModelOS.SDK
                     }
                 }
                 //数据校验
-                tbschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
+                tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
                 if (tbschools.IsNotEmpty())
                 {
 
@@ -105,7 +106,7 @@ namespace TEAMModelOS.SDK
                     });
                     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);
+                    saveschools = await table.SaveAll(saveschools);
                 }
                 else
                 {
@@ -143,7 +144,7 @@ namespace TEAMModelOS.SDK
                     });
 
                     schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
-                    saveschools = await _azureStorage.SaveOrUpdateAll(schools);
+                    saveschools = await table.SaveOrUpdateAll(schools);
                 }
             }
             return null;

+ 48 - 35
TEAMModelOS.SDK/Models/Service/Third/ThirdService.cs

@@ -16,10 +16,11 @@ namespace TEAMModelOS.SDK.Models
     public static class ThirdService
     {
         //自动加入学校,加入培训名单,并根据学科进行分组
-        public static async Task<ScTeacher> GetScTeacher(ScBindData scBind, Teacher teacher, AzureStorageFactory _azureStorage, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, IConfiguration _configuration,DingDing _dingDing)
+        public static async Task<ScTeacher> GetScTeacher(ScBindData scBind, Teacher teacher, AzureStorageFactory _azureStorage, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, IConfiguration _configuration, DingDing _dingDing)
         {
-            List<ScSchool> schools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object> { { "PartitionKey", "ScSchool" }, { "RowKey", scBind.sid } });
-            List<ScTeacher> scTeachers = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "TID", scBind.userid }, { "RowKey", $"{scBind.pxid}" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            List<ScSchool> schools = await table.FindListByDict<ScSchool>(new Dictionary<string, object> { { "PartitionKey", "ScSchool" }, { "RowKey", scBind.sid } });
+            List<ScTeacher> scTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "TID", scBind.userid }, { "RowKey", $"{scBind.pxid}" } });
             if (schools.IsNotEmpty())
             {
                 ScSchool scSchool = schools[0];
@@ -27,9 +28,9 @@ namespace TEAMModelOS.SDK.Models
                 {
                     try
                     {
-                       
+
                         School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(scSchool.schoolCode, new PartitionKey("Base"));
-                        
+
                         if (school != null)
                         {
                             if (scTeachers.IsNotEmpty())
@@ -39,7 +40,7 @@ namespace TEAMModelOS.SDK.Models
                                     scTeachers[0].tmdid = teacher.id;
                                     scTeachers[0].schoolCode = scSchool.schoolCode;
                                     scTeachers[0].areaId = school.areaId;
-                                    await _azureStorage.SaveOrUpdate<ScTeacher>(scTeachers[0]);
+                                    await table.SaveOrUpdate<ScTeacher>(scTeachers[0]);
                                 }
                             }
                             var sc = teacher.schools.Find(x => x.schoolId.Equals(scSchool.schoolCode));
@@ -67,7 +68,7 @@ namespace TEAMModelOS.SDK.Models
                                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync(schoolTeacher);
                                         }
                                     }
-                                    catch (CosmosException ex)
+                                    catch (CosmosException)
                                     {
                                         SchoolTeacher schoolTeacher = new SchoolTeacher
                                         {
@@ -134,7 +135,7 @@ namespace TEAMModelOS.SDK.Models
 
                                 var meber = yxtrain.SelectMany(x => x.members).Where(y => y.id.Equals(teacher.id));
                                 //不在研修名单
-                                if (meber == null || meber.Count() <= 0)
+                                if (meber == null || !meber.Any())
                                 {
                                     yxtrain[0].members.Add(new Member { id = teacher.id, type = 1, groupId = groupId, groupName = groupName });
                                     await GroupListService.UpsertList(yxtrain[0], _azureCosmos, _configuration, _serviceBus);
@@ -160,7 +161,7 @@ namespace TEAMModelOS.SDK.Models
                                 {
                                     groupId = Guid.NewGuid().ToString();
                                 }
-                                GroupList groupList = new GroupList()
+                                GroupList groupList = new()
                                 {
                                     id = Guid.NewGuid().ToString(),
                                     code = $"GroupList-{scSchool.schoolCode}",
@@ -187,7 +188,8 @@ namespace TEAMModelOS.SDK.Models
             }
             return null;
         }
-        public static async Task<(string accessConfig, Area area, AreaSetting setting)> GetAccessConfig(CosmosClient client,string standard) {
+        public static async Task<(string accessConfig, Area area, AreaSetting setting)> GetAccessConfig(CosmosClient client, string standard)
+        {
             Area area = null;
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").
                    GetItemQueryIterator<Area>($"select value(c) from c where c.standard='{standard}'", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Area") }))
@@ -207,48 +209,58 @@ namespace TEAMModelOS.SDK.Models
                     setting = null;
                 }
             }
-            if (setting == null||  string.IsNullOrEmpty(setting.accessConfig))
+            if (setting == null || string.IsNullOrEmpty(setting.accessConfig))
             {
-                return (null,null,null);
+                return (null, null, null);
             }
-            else {
-                return (setting.accessConfig,area,setting);
+            else
+            {
+                return (setting.accessConfig, area, setting);
             }
         }
-        public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard,DingDing dingDing,  AreaSetting setting, HttpTrigger httpTrigger,  Teacher teacher, TEAMModelOS.Models.Option _option, AzureStorageFactory _azureStorage) {
-            List<string> abilityNos = new List<string>() ;
-            var config= setting.accessConfig.ToObject<JsonElement>();
-            config.TryGetProperty("config", out JsonElement _config);
+        public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard, DingDing dingDing, AreaSetting setting, HttpTrigger httpTrigger, Teacher teacher, TEAMModelOS.Models.Option _option, AzureStorageFactory _azureStorage)
+        {
+            List<string> abilityNos = new();
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+
+            setting.accessConfig.ToObject<JsonElement>().TryGetProperty("config", out JsonElement _config);
+
             if ($"{_config}".Equals("scsyxpt"))
             {
-                var binds =  teacher.binds.FindAll(x => x.type.Equals("scsyxpt"));
-                var datas =  binds.SelectMany(x => x.data).Where(y=>y.Contains("scsyxpt"));
-                HashSet<string> pxids = new HashSet<string> ();
-                if (datas != null) {
-                    datas.ToList().ForEach(x => {
-                        var data =    x.ToObject<ScBindData>();
-                        if (!string.IsNullOrEmpty(data?.pxid)) {
+                var binds = teacher.binds.FindAll(x => x.type.Equals("scsyxpt"));
+                var datas = binds.SelectMany(x => x.data).Where(y => y.Contains("scsyxpt"));
+                HashSet<string> pxids = new();
+                if (datas != null)
+                {
+                    datas.ToList().ForEach(x =>
+                    {
+                        var data = x.ToObject<ScBindData>();
+                        if (!string.IsNullOrEmpty(data?.pxid))
+                        {
                             pxids.Add(data.pxid);
                         }
                     });
                 }
-                foreach (var pxid in pxids) {
-                    List<ScTeacher> teachers = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "PXID", pxid } });
-                    Dictionary<string, object> dict = new Dictionary<string, object>();
+                foreach (var pxid in pxids)
+                {
+                    List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "PXID", pxid } });
+                    Dictionary<string, object> dict = new();
                     if (teachers.IsNotEmpty())
                     {
-                        dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pxid", pxid }, { "areaId", setting.id } ,{ "schoolCode", teachers[0].schoolCode} };
+                        dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pxid", pxid }, { "areaId", setting.id }, { "schoolCode", teachers[0].schoolCode } };
                     }
-                    else {
+                    else
+                    {
                         dict = new Dictionary<string, object>() { { "accessConfig", setting.accessConfig }, { "pxid", pxid }, { "areaId", setting.id } };
                     }
-                   
-                   
+
+
                     (int status, string json) = await httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetDiagnosisListByProject_V2");
                     if (status == 200)
                     {
                         List<string> nos = json.ToObject<List<string>>();
-                        if (nos.IsNotEmpty()) {
+                        if (nos.IsNotEmpty())
+                        {
                             abilityNos.AddRange(nos);
                         }
                     }
@@ -256,7 +268,8 @@ namespace TEAMModelOS.SDK.Models
             }
             //获取能力点
             List<Ability> abilities = null;
-            if (abilityNos.IsNotEmpty()) {
+            if (abilityNos.IsNotEmpty())
+            {
                 abilities = new List<Ability>();
                 StringBuilder sql = new StringBuilder($"select value(c) from c where c.no in ({string.Join(",", abilityNos.Select(x => $"'{x}'"))})");
                 await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
@@ -267,6 +280,6 @@ namespace TEAMModelOS.SDK.Models
             }
             return abilities;
         }
-       
+
     }
 }

+ 5 - 3
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -429,7 +429,8 @@ namespace TEAMModelOS.Controllers
             {
                 if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
-                List<SchoolYear> years = await _azureStorage.FindListByDict<SchoolYear>(new Dictionary<string, object>() { { "RowKey", code }, { "PartitionKey", "Exam" } });
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolYear");
+                List<SchoolYear> years = await table.FindListByDict<SchoolYear>(new Dictionary<string, object>() { { "RowKey", code }, { "PartitionKey", "Exam" } });
                 int year = 0;
                 if (years.Count > 0)
                 {
@@ -453,7 +454,7 @@ namespace TEAMModelOS.Controllers
                         }
                         year = ct == 0 ? DateTimeOffset.UtcNow.Year : DateTimeOffset.FromUnixTimeMilliseconds(ct).Year;
                         years[0].year = year;
-                        await _azureStorage.SaveOrUpdate<SchoolYear>(years[0]);
+                        await table.SaveOrUpdate<SchoolYear>(years[0]);
                     }
                 }
                 else
@@ -480,7 +481,8 @@ namespace TEAMModelOS.Controllers
                         PartitionKey = "Exam",
                         year = year
                     };
-                    await _azureStorage.Save<SchoolYear>(sy);
+                   
+                    await table.Save<SchoolYear>(sy);
                 }
                 var query = $"select c.id,c.name,c.code,c.period,c.startTime,c.endTime,c.stuCount,c.type,c.progress,c.examType,c.createTime,c.source, c.subjects, c.grades,c.owner, c.scope,c.classes,c.sRate,c.lostStu,c.sStatus ,c.school from c where (c.status<>404 or IS_DEFINED(c.status) = false )";
                 if (requert.TryGetProperty("classIds", out JsonElement classIds))

+ 3 - 3
TEAMModelOS/Controllers/Normal/AbilityController.cs

@@ -210,10 +210,10 @@ namespace TEAMModelOS.Controllers
                     request.TryGetProperty("code", out JsonElement _code);
                     if (!string.IsNullOrWhiteSpace($"{_code}"))
                     {
-                       
-                        List<ScSchool> schools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "schoolCode", $"{_code}" } });
+                        var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+                        List<ScSchool> schools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "schoolCode", $"{_code}" } });
                         if (schools.IsNotEmpty()) {
-                            Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig },{ "schoolCode",$"{schools[0].schoolid}"}, { "areaId", setting.id } };
+                            Dictionary<string, object> dict = new() { { "accessConfig", accessConfig },{ "schoolCode",$"{schools[0].schoolid}"}, { "areaId", setting.id } };
                             (int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolDiagnosis");
                             if (status == 200)
                             {

+ 2 - 1
TEAMModelOS/Controllers/School/SchoolTeacherController.cs

@@ -153,7 +153,8 @@ namespace TEAMModelOS.Controllers
             {
                 { "PartitionKey",  "authority"}
             };
-            List<Authority> authoritylist = await _azureStorage.FindListByDict<Authority>(dict);
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
+            List<Authority> authoritylist = await table.FindListByDict<Authority>(dict);
             return Ok(new { authoritylist });
         }
 

+ 4 - 4
TEAMModelOS/Controllers/System/CoreController.cs

@@ -157,7 +157,7 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> ImageQuang(List<ImageQuangRequest> request)
         {
             if (request.Count < 1) return BadRequest();
-            Regex rex = new Regex(@"data:(?<key1>image.+?);base64,(?<key2>.+)");
+            Regex rex = new(@"data:(?<key1>image.+?);base64,(?<key2>.+)");
 
             List<object> respons = new List<object>();
             var quantizer = new PngQuantizer();
@@ -191,7 +191,7 @@ namespace TEAMModelOS.Controllers
                         quantized.Save(nbase64ms, ImageFormat.Png); //保存為PNG格式
                         byte[] data = nbase64ms.ToArray();
                         string base64 = $"data:image/png;base64,{Convert.ToBase64String(data)}"; //創建新的img src base64
-                        respons.Add(new { base64 = base64, blob = img });
+                        respons.Add(new { base64, blob = img });
 
                         // TODO 下面註解,無法解決保存時,真正改變Format32bppArgb為Format8bppIndexed,需要再研究
                         //ImageCodecInfo imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(info => info.MimeType == "image/png");
@@ -201,12 +201,12 @@ namespace TEAMModelOS.Controllers
                     }
                     else
                     {
-                        respons.Add(new { base64 = item.base64, blob = "" }); //異常的圖片,原Base64返回
+                        respons.Add(new { item.base64, blob = "" }); //異常的圖片,原Base64返回
                     }
                 }
                 else
                 {
-                    respons.Add(new { base64 = item.base64, blob = "" }); //不符合的圖片,原Base64返回
+                    respons.Add(new { item.base64, blob = "" }); //不符合的圖片,原Base64返回
                 }
             }
             return Ok(respons);

+ 4 - 2
TEAMModelOS/Controllers/System/OpenApiController.cs

@@ -82,7 +82,8 @@ namespace TEAMModelOS.Controllers
       //  [AuthToken(Roles = "admin")]
         [HttpPost("get-api")]
         public async Task<IActionResult> GetApi(JsonElement json) {
-            List<OpenApi> apis = await _azureStorage.FindListByDict<OpenApi>(new Dictionary<string, object>() { { "PartitionKey", "IES5-API" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("OpenApi");
+            List<OpenApi> apis = await table.FindListByDict<OpenApi>(new Dictionary<string, object>() { { "PartitionKey", "IES5-API" } });
             return Ok(new { apis });
         }
         /*
@@ -99,7 +100,8 @@ namespace TEAMModelOS.Controllers
         [HttpPost("get-webhook")]
         public async Task<IActionResult> GetWebhook(JsonElement json)
         {
-            List<Webhook> webhooks = await _azureStorage.FindListByDict<Webhook>(new Dictionary<string, object>() { { "PartitionKey", "IES5-WEBHOOK" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("OpenApi");
+            List<Webhook> webhooks = await table.FindListByDict<Webhook>(new Dictionary<string, object>() { { "PartitionKey", "IES5-WEBHOOK" } });
             return Ok(new { webhooks });
         }
         /*

+ 4 - 3
TEAMModelOS/Controllers/Third/DingDingController.cs

@@ -141,7 +141,8 @@ namespace TEAMModelOS.Controllers.Third
 
                 if (byunionidResponse.IsError  || byunionidResponse.Errcode == 60121)
                 {
-                    ddusers = await _azureStorage.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{Unionid}" }, { "PartitionKey", "DDUserInfo-IES5" } });
+                    var table = _azureStorage.GetCloudTableClient().GetTableReference("DDUserInfo");
+                    ddusers = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{Unionid}" }, { "PartitionKey", "DDUserInfo-IES5" } });
                     //是企业外部用户 
                     return Ok(new { state = 0, message = byunionidResponse.Errmsg });
                 }
@@ -166,8 +167,8 @@ namespace TEAMModelOS.Controllers.Third
                     Title = v2GetResponse?.Result?.Title;
                 }
             }
-            catch (Exception ex) { 
-            
+            catch (Exception ex ){
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-dingding-login异常{ex.Message}", GroupNames.成都开发測試群組);
             }
 
             return Ok();

+ 27 - 18
TEAMModelOS/Controllers/Third/Sc/ScApiController.cs

@@ -84,7 +84,8 @@ namespace TEAMModelOS.Controllers
         [AllowAnonymous]
         public async Task<IActionResult> GetProjectList(List<Unbind> unbinds)
         {
-            scsyxptConfigs= await _azureStorage.FindListByDict<ScComConfig>(new Dictionary<string, object> { { Constant.PartitionKey, "ScComConfig" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            scsyxptConfigs = await table.FindListByDict<ScComConfig>(new Dictionary<string, object> { { Constant.PartitionKey, "ScComConfig" } });
             ScComConfig scsyxptConfig= scsyxptConfigs[0];
             // 5.3.1.1获取项目列表 
             string trainComID = scsyxptConfig.trainComID;
@@ -98,31 +99,37 @@ namespace TEAMModelOS.Controllers
 
             // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
             Code = "GetSchoolList";
-            parameterMap = new Dictionary<string, object>();
-            parameterMap.Add("TrainComID", trainComID);
-            parameterMap.Add("ProjectID", "92");
-            parameterMap.Add("ProjectItemID", "1131");
+            parameterMap = new Dictionary<string, object>
+            {
+                { "TrainComID", trainComID },
+                { "ProjectID", "92" },
+                { "ProjectItemID", "1131" }
+            };
             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返回学校列表";
 
             // 5.3.1.19获取项目设置的可选能力点,
             Code = "GetProjectDiagnosis";
-            parameterMap = new Dictionary<string, object>();
-            parameterMap.Add("TrainComID", trainComID);
-            parameterMap.Add("ProjectID", "82");
-            parameterMap.Add("ProjectItemID", "1086");
+            parameterMap = new Dictionary<string, object>
+            {
+                { "TrainComID", trainComID },
+                { "ProjectID", "82" },
+                { "ProjectItemID", "1086" }
+            };
             ScsResult GetProjectDiagnosis = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetProjectDiagnosis.code = Code;
             GetProjectDiagnosis.title = "5.3.1.19获取项目设置的可选能力点";
             // 补充
             //  5.3.1.3通过项目编号获取学员测评能力项,需要确认每个教师是是否一样。
             Code = "GetDiagnosisListByProject_V2";
-            parameterMap = new Dictionary<string, object>();
-            parameterMap.Add("TrainComID", trainComID);
-            //parameterMap.Add("ProjectID", "22");
-            //parameterMap.Add("ProjectItemID", "22");
-            parameterMap.Add("PXID", "242849");
+            parameterMap = new Dictionary<string, object>
+            {
+                { "TrainComID", trainComID },
+                //parameterMap.Add("ProjectID", "22");
+                //parameterMap.Add("ProjectItemID", "22");
+                { "PXID", "242849" }
+            };
             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";
@@ -130,10 +137,12 @@ namespace TEAMModelOS.Controllers
 
             // 5.3.1.2获取学员名单,。
             Code = "GetTeachersListByProject";
-            parameterMap = new Dictionary<string, object>();
-            parameterMap.Add("TrainComID", trainComID);
-            parameterMap.Add("ProjectID", "82");
-            parameterMap.Add("ProjectItemID", "1086");
+            parameterMap = new Dictionary<string, object>
+            {
+                { "TrainComID", trainComID },
+                { "ProjectID", "82" },
+                { "ProjectItemID", "1086" }
+            };
             ScsResult GetTeachersListByProject = await _scsApisService.Post(scsyxptConfig.url, Code, scsyxptConfig.passKey, scsyxptConfig.privateKey, parameterMap);
             GetTeachersListByProject.code = Code;
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 113 - 84
TEAMModelOS/Controllers/Third/Sc/ScController.cs


+ 94 - 71
TEAMModelOS/Controllers/Third/Sc/ScDataInitController.cs

@@ -59,7 +59,7 @@ namespace TEAMModelOS.Controllers.Third
         private readonly IWebHostEnvironment _environment;
         private readonly ThirdApisService _thirdApisService;
         public IConfiguration _configuration { get; set; }
-        public ScDataInitController(ThirdApisService thirdApisService,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;
@@ -85,23 +85,26 @@ namespace TEAMModelOS.Controllers.Third
         [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" } });
+        public async Task<IActionResult> GetScsPorject(JsonElement request)
+        {
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            List<ScComConfig> scComConfigs = await table.FindListByDict<ScComConfig>(new Dictionary<string, object> { { Constant.PartitionKey, "ScComConfig" } });
             string Code = "GetProjectInfoByTrainComID";
             List<ScProject> projectsSave = new List<ScProject>();
-            foreach (var config in scComConfigs) {
+            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}" } });
-              
+                List<ScProject> scProjects = await table.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);
+                        ScProject scProject = scProjects.Find(x => x.ProjectItemID == project.ProjectItemID);
                         if (scProject != null)
                         {
                             scProject.PartitionKey = "ScProject";
@@ -122,7 +125,8 @@ namespace TEAMModelOS.Controllers.Third
                             scProject.TeacherDiagnosisMinDimension = project.TeacherDiagnosisMinDimension;
                             projectsSave.Add(scProject);
                         }
-                        else {
+                        else
+                        {
                             projectsSave.Add(new ScProject
                             {
                                 PartitionKey = "ScProject",
@@ -144,32 +148,34 @@ namespace TEAMModelOS.Controllers.Third
                             });
                         }
                     }
-                    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);
+            await table.SaveOrUpdateAll(projectsSave);
             return Ok(new { projectsSave });
         }
-        
+
         /// <summary>
         /// 3. 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
         /// </summary>
@@ -186,8 +192,9 @@ namespace TEAMModelOS.Controllers.Third
             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}" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            var ScTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
+            var ScSchools = await table.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 });
@@ -230,11 +237,12 @@ namespace TEAMModelOS.Controllers.Third
                         x.schoolCode = school?.schoolCode;
                     }
                 });
-                addTeachers = await _azureStorage.SaveOrUpdateAll(addTeachers);
+                addTeachers = await table.SaveOrUpdateAll(addTeachers);
             }
-            else {
+            else
+            {
                 //省平台更新的
-                foreach(var x in adds)
+                foreach (var x in adds)
                 {
                     x.RowKey = $"{x.PXID}";
                     x.status = 1;
@@ -243,9 +251,10 @@ namespace TEAMModelOS.Controllers.Third
                     var school = ScSchools.Find(s => s.schoolid == x.SchoolID);
                     x.schoolCode = school?.schoolCode;
                 }
-                addTeachers = await _azureStorage.SaveOrUpdateAll(adds);
+                addTeachers = await table.SaveOrUpdateAll(adds);
             }
-            if (ScTeachers.Count == teachers.Count) {
+            if (ScTeachers.Count == teachers.Count)
+            {
                 foreach (var x in ScTeachers)
                 {
                     var tt = teachers.Find(z => x.RowKey.Equals($"{z.PXID}"));
@@ -275,7 +284,7 @@ namespace TEAMModelOS.Controllers.Third
                         x.schoolCode = school?.schoolCode;
                     }
                 }
-                addTeachers = await _azureStorage.SaveOrUpdateAll(ScTeachers);
+                addTeachers = await table.SaveOrUpdateAll(ScTeachers);
             }
             #endregion 省平台获取到最新的教师,并添加到Table中。
             //反向去补全四川省平台 Table中没有绑定tmdid的账号
@@ -292,12 +301,14 @@ namespace TEAMModelOS.Controllers.Third
                 }
                 if (binds.IsNotEmpty())
                 {
-                    List<ScTeacher> update = new List<ScTeacher>();
-                    binds.ForEach(x => {
+                    List<ScTeacher> update = new();
+                    binds.ForEach(x =>
+                    {
                         var exs = unbindtmdid.FindAll(z => $"{z.TID}".Equals(x.userid));
                         if (exs.IsNotEmpty())
                         {
-                            exs.ForEach(y => {
+                            exs.ForEach(y =>
+                            {
                                 y.tmdid = x.id;
                             });
                             update.AddRange(exs);
@@ -305,7 +316,8 @@ namespace TEAMModelOS.Controllers.Third
                     });
                     var group = update.GroupBy(x => x.RowKey).Select(z => new { z.Key, list = z.ToList() });
                     List<ScTeacher> scTeachers = new();
-                    group.ToList().ForEach(x => {
+                    group.ToList().ForEach(x =>
+                    {
                         if (x.list.Count() == 1)
                         {
                             scTeachers.Add(x.list[0]);
@@ -315,21 +327,22 @@ namespace TEAMModelOS.Controllers.Third
                             scTeachers.Add(x.list[0]);
                         }
                     });
-                    scTeachers = await _azureStorage.SaveOrUpdateAll(scTeachers);
+                    scTeachers = await table.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}" } });
+            ScTeachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
+            var scSchools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "areaId", $"{areaId}" } });
             List<ScTeacher> updateTch = new List<ScTeacher>();
-            ScTeachers.FindAll(y=>string.IsNullOrWhiteSpace(y.schoolCode)).ForEach(x =>
+            ScTeachers.FindAll(y => string.IsNullOrWhiteSpace(y.schoolCode)).ForEach(x =>
+              {
+                  var scSchool = scSchools.Find(s => s.schoolid == x.SchoolID);
+                  x.schoolCode = scSchool?.schoolCode;
+                  updateTch.Add(x);
+              });
+            if (updateTch.IsNotEmpty())
             {
-               var scSchool= scSchools.Find(s => s.schoolid == x.SchoolID);
-                x.schoolCode = scSchool?.schoolCode;
-                updateTch.Add(x);
-            });
-            if (updateTch.IsNotEmpty()) {
-                await _azureStorage.SaveOrUpdateAll(updateTch);
+                await table.SaveOrUpdateAll(updateTch);
             }
             return Ok(new { update = updateTch.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }), ScTeachers });
         }
@@ -341,9 +354,10 @@ namespace TEAMModelOS.Controllers.Third
         [ProducesDefaultResponseType]
         [HttpPost("get-sc-school")]
         [AllowAnonymous]
-        public async Task<IActionResult> GetScSchool(JsonElement request) {
+        public async Task<IActionResult> GetScSchool(JsonElement request)
+        {
             if (!request.TryGetProperty("accessConfig", out JsonElement accessConfig)) return BadRequest();
-            if(!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
+            if (!request.TryGetProperty("areaId", out JsonElement areaId)) 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();
@@ -393,7 +407,7 @@ namespace TEAMModelOS.Controllers.Third
                 }
             }
             return Ok(new { schools = schools.Select(x => new { x.schoolname, x.schoolCode, x.schoolid, x.ProjectID, x.ProjectItemID }) });
-            }
+        }
         /// <summary>
         /// 2. 处理 省平台最新的教师以及 反向更新没有绑定醍摩豆id 的账号。
         /// </summary>
@@ -402,15 +416,17 @@ namespace TEAMModelOS.Controllers.Third
         [ProducesDefaultResponseType]
         [HttpPost("get-project-school")]
         [AllowAnonymous]
-        public async Task<IActionResult> GetProjectSchool(JsonElement request) {
+        public async Task<IActionResult> GetProjectSchool(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")})) {
+            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}" } };
@@ -426,9 +442,12 @@ namespace TEAMModelOS.Controllers.Third
             {
                 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");
-            if (status == 200) {
+            (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");           
+            if (status == 200)
+            {               
                 schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
                 if (ignore.IsNotEmpty())
                 {
@@ -447,7 +466,8 @@ namespace TEAMModelOS.Controllers.Third
                         }
                         else
                         {
-                            matchSchools.ForEach(x => {
+                            matchSchools.ForEach(x =>
+                            {
                                 var exschool = ignore.Find(y => y.name.Equals(x.schoolname));
                                 if (exschool != null)
                                 {
@@ -455,25 +475,25 @@ namespace TEAMModelOS.Controllers.Third
                                     x.areaId = $"{areaId}";
                                     x.city = $"{city}";
                                     x.dist = $"{dist}";
-                                   
+
                                 }
                             });
                         }
                     }
                     else
                     {
-                        return Ok(new { unmatch = ignore, schools= schools.Select(x=>new {x.schoolname,x.schoolCode,x.schoolid,x.ProjectID,x.ProjectItemID}) });
+                        return Ok(new { unmatch = ignore, schools = schools.Select(x => new { x.schoolname, x.schoolCode, x.schoolid, x.ProjectID, x.ProjectItemID }) });
                     }
                 }
 
                 //数据校验
-                tbschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" },{ "areaId" ,$"{areaId}"} });
+                tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" }, { "areaId", $"{areaId}" } });
                 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>();
+                    List<SchoolData> schoolDatas = new();
                     saveschools.ForEach(x =>
                     {
                         x.RowKey = $"{x.schoolid}";
@@ -494,8 +514,9 @@ namespace TEAMModelOS.Controllers.Third
                             }
                         }
                     });
-                    schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
-                    saveschools.ForEach(x => {
+                    schoolDatas = await GenerateSchoolCode(schoolDatas, _dingDing, _environment);
+                    saveschools.ForEach(x =>
+                    {
 
                         var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
                         if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
@@ -509,7 +530,7 @@ namespace TEAMModelOS.Controllers.Third
                     });
                     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);
+                    saveschools = await table.SaveAll(saveschools);
                 }
                 else
                 {
@@ -535,7 +556,8 @@ namespace TEAMModelOS.Controllers.Third
                         }
                     });
                     schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
-                    schools.ForEach(x => {
+                    schools.ForEach(x =>
+                    {
                         var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
                         if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
                         {
@@ -547,7 +569,7 @@ namespace TEAMModelOS.Controllers.Third
                         }
                     });
                     schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
-                    saveschools = await _azureStorage.SaveOrUpdateAll(schools);
+                    saveschools = await table.SaveOrUpdateAll(schools);
                 }
             }
             List<string> unsave = new List<string>();
@@ -568,7 +590,7 @@ namespace TEAMModelOS.Controllers.Third
                 }
             }
 
-            var areaschools = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", $"ScSchool" }, { "areaId", $"{areaId}" } });
+            var areaschools = await table.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") }))
@@ -597,7 +619,8 @@ namespace TEAMModelOS.Controllers.Third
             {
                 List<Period> periods = new List<Period>();
                 string campusId = Guid.NewGuid().ToString();
-                sc.period.ForEach(x => {
+                sc.period.ForEach(x =>
+                {
                     periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x, campusId = campusId });
                 });
                 School school = new School
@@ -647,7 +670,7 @@ namespace TEAMModelOS.Controllers.Third
                 failedmsg,
                 schoolsScucess,
                 tbsch = tbschools.Select(x => new { x.schoolname, x.schoolCode }),
-                
+
             });
         }
     }

+ 4 - 3
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -1495,8 +1495,9 @@ namespace TEAMModelOS.Controllers
             //    Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "schoolCode", $"{z.schoolid}" }, { "areaId", "99a4a33b-e21b-44ac-80a1-b31dc40496e0" } };
             //    (int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolDiagnosis");
             //};
-            List<ScTeacher> teachers=  await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" } });
-            List<ScTeacherDiagnosis> diagnoses = await _azureStorage.FindListByDict<ScTeacherDiagnosis>(new Dictionary<string, object> { { "PartitionKey", "ScTeacherDiagnosis" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            List<ScTeacher> teachers=  await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" } });
+            List<ScTeacherDiagnosis> diagnoses = await table.FindListByDict<ScTeacherDiagnosis>(new Dictionary<string, object> { { "PartitionKey", "ScTeacherDiagnosis" } });
             List<string> rowkeys=  diagnoses.Where(z => !string.IsNullOrEmpty(z.schoolCode)).Select(x => x.RowKey).ToList();
             teachers.RemoveAll(x => rowkeys.Contains(x.RowKey));
             await _dingDing.SendBotMsg($"Diagnosis :{ rowkeys.Count }",GroupNames.成都开发測試群組);
@@ -1513,7 +1514,7 @@ namespace TEAMModelOS.Controllers
                     await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetDiagnosisListByProject_V2");
                 }
             }
-            return Ok(new { Count=rowkeys.Count });
+            return Ok(new { rowkeys.Count });
         }
 
         /// <summary>

+ 2 - 1
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -618,7 +618,8 @@ namespace TEAMModelOS.Controllers
         {
            
             var areaId =request.GetProperty("areaId");
-            List<ScTeacher> teachers = await _azureStorage.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
             return Ok(teachers.Select(x =>new  {x.areaId,x.PXID,x.TID,x.TeacherName,x.tmdid,x.SchoolName,x.DisName }));
         }