Browse Source

处理数据恢复问题。

CrazyIter_Bin 3 years ago
parent
commit
e0561ec1a7

+ 0 - 1
TEAMModelOS.SDK/Models/Cosmos/Teacher/Research/TeacherTrain.cs

@@ -124,7 +124,6 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public HashSet<string> update { get; set; } = new HashSet<string>();
         public string push { get; set; } 
-       
     }
     public class TeacherTrainChange {
         /// <summary>

+ 3 - 3
TEAMModelOS.SDK/Models/Service/StatisticsService.cs

@@ -261,7 +261,7 @@ namespace TEAMModelOS.SDK
                 if (mbm != null)
                 {
                     x.groupName = mbm?.groupName;
-                    x.name = mbm?.name;
+                    x.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
                     x.nickname = mbm?.nickname;
                     x.picture = mbm?.picture;
                     
@@ -277,7 +277,7 @@ namespace TEAMModelOS.SDK
             {
                 teachers.Add(StatisticsTeacher(train, setting, area, client, studies));  //yield return await  StatisticsTeacher(  train,   setting,   area,   client);
             }
-            int pagesize = 50;
+            int pagesize = 100;
             if (teachers.Count <= pagesize)
             {
                 await Task.WhenAll(teachers);
@@ -306,7 +306,7 @@ namespace TEAMModelOS.SDK
                 {
                     teachers.Add(DoProperty(train.update, property, setting, area, client, train, studies));
                 }
-                int pagesize = 50;
+                int pagesize = 100;
                 if (teachers.Count <= pagesize)
                 {
                     await Task.WhenAll(teachers);

+ 27 - 21
TEAMModelOS/Controllers/Normal/AbilityStatisticsController.cs

@@ -124,6 +124,13 @@ namespace TEAMModelOS.Controllers
                 TeacherTrain teacherTrain = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherTrain>(userid, new PartitionKey($"TeacherTrain-{school}"));
                 teacherTrain.nickname= name;
                 teacherTrain.name = name;
+                
+                var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+                List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "schoolCode", school }, { "tmdid", $"{teacherTrain.id}" } });
+                if (teachers.Any())
+                {
+                    teacherTrain.name = teachers[0].TeacherName;
+                }
                 teacherTrain.picture = picture;
                 teacherTrain.summary = $"{_summary}";
                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(teacherTrain, userid, new PartitionKey($"TeacherTrain-{school}"));
@@ -256,12 +263,7 @@ namespace TEAMModelOS.Controllers
                 var teacherAilities = teacherTrains.SelectMany(x => x.currency.teacherAilities);
                 setting.accessConfig = null;
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-                List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", setting.id } });
                 teacherTrains.ForEach(x => {
-                    var tch=  teachers.Find(z => z.tmdid.Equals(x.id));
-                    if (tch != null) {
-                        x.name = tch.TeacherName;
-                    }
                     x.currency.videoTime = (int)x.currency.videoTime;
                     x.currency.teacherAilities.ForEach(y => {
                         y.videoTime = (int)y.videoTime;
@@ -403,12 +405,8 @@ namespace TEAMModelOS.Controllers
                 (List<TeacherTrain> teacherTrains, List<RGroupList> yxtrain) = await StatisticsService.StatisticsSchool(_coreAPIHttpService, school, setting, area, client, _dingDing, update);
 
                 var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-                List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", setting.id }, { "schoolCode", school } });
                 teacherTrains.ForEach(x => {
-                    var tch= teachers.Find(z => z.tmdid.Equals(x.id));
-                    if (tch != null) {
-                        x.name = tch.TeacherName;
-                    }
+                    
                     x.currency.videoTime = (int)x.currency.videoTime;
                     x.currency.teacherAilities.ForEach(y => {
                         y.videoTime = (int)y.videoTime;
@@ -513,16 +511,16 @@ namespace TEAMModelOS.Controllers
                 {
                     teacherTrain = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherTrain>(tmdid, new PartitionKey($"TeacherTrain-{school}"));
                     var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-                    List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", setting.id } , { "schoolCode", school }, { "tmdid", $"{_tmdid}" }});
-                    if (teachers.Any())
+                    teacherTrain.nickname = name;
+                    teacherTrain.name = name;
+                    if (!string.IsNullOrWhiteSpace(setting.accessConfig))
                     {
-                        teacherTrain.name = teachers[0].TeacherName;
-                    }
-                    else {
-                        teacherTrain.name = name;
+                        List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", setting.id }, { "schoolCode", school }, { "tmdid", $"{_tmdid}" } });
+                        if (teachers.Any())
+                        {
+                            teacherTrain.name = teachers[0].TeacherName;
+                        }
                     }
-                    teacherTrain.name = name;
-                    teacherTrain.nickname = name;
                     teacherTrain.picture = picture;
                     if (update != null && update.Count > 0)
                     {
@@ -540,6 +538,16 @@ namespace TEAMModelOS.Controllers
                 }
                 catch (CosmosException)
                 {
+                    string tname = name;
+                    if (!string.IsNullOrWhiteSpace(setting.accessConfig)) {
+                        var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+                        List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", setting.id }, { "schoolCode", school }, { "tmdid", $"{_tmdid}" } });
+                        if (teachers.Any())
+                        {
+                            tname = teachers[0].TeacherName;
+                        }
+                    }
+                   
                     teacherTrain = await StatisticsService.StatisticsTeacher(new TeacherTrain
                     {
                         pk = "TeacherTrain",
@@ -548,7 +556,7 @@ namespace TEAMModelOS.Controllers
                         tmdid = tmdid,
                         nickname= name,
                         school = school,
-                        name = name,
+                        name = tname,
                         picture = picture,
                         update = new HashSet<string> {  StatisticsService.TeacherAbility,
                         StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
@@ -566,9 +574,7 @@ namespace TEAMModelOS.Controllers
             catch (Exception ex)
             {
                 return BadRequest(new { ex.Message, ex.StackTrace });
-
             }
         }
-
     }
 }

+ 2 - 1
TEAMModelOS/Controllers/Third/OAuth2Controller.cs

@@ -96,7 +96,8 @@ namespace TEAMModelOS.Controllers
 
         [HttpGet("{path}/oauth2")]
         [AllowAnonymous]
-        public async Task<IActionResult> Oauth2([FromQuery] OAuth oauth2, string path) { 
+        public async Task<IActionResult> Oauth2([FromQuery] OAuth oauth2, string path) {
+            //https://ssoserviceurl/oauth2/authorize?client_id=APPKEY&openid=OPENID=&service=SERVICE
             return Ok(new { oauth2, path });
         }
     }

+ 104 - 0
TEAMModelOS/Controllers/Third/Xkw/XkwOAuth2Controller.cs

@@ -0,0 +1,104 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using System.Text.Json;
+using TEAMModelOS.SDK.Models;
+using Microsoft.AspNetCore.Http;
+using TEAMModelOS.SDK.Extension;
+using Azure.Cosmos;
+using System.Text;
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
+using Microsoft.Extensions.Options;
+using Azure.Messaging.ServiceBus;
+using Microsoft.Extensions.Configuration;
+using HTEXLib.COMM.Helpers;
+using TEAMModelOS.SDK;
+using System.IdentityModel.Tokens.Jwt;
+using TEAMModelOS.Services;
+using TEAMModelOS.SDK.Models.Service;
+using System.IO;
+using System.Dynamic;
+using Microsoft.AspNetCore.Authorization;
+using Azure.Storage.Blobs.Models;
+using static TEAMModelOS.SDK.Models.Teacher;
+using System.Web;
+using static TEAMModelOS.Controllers.FixDataController;
+using static TEAMModelOS.SDK.SchoolService;
+using Microsoft.AspNetCore.Hosting;
+namespace TEAMModelOS.Controllers
+{
+    // <summary>
+    ///  标准OAuth2
+    /// </summary>
+    ///  
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //
+    //[Route("")]
+    //[Route("api/[controller]")]
+    [ApiController]
+    public class XkwOAuth2Controller : ControllerBase
+    {
+        private readonly SnowflakeId _snowflakeId;
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly AzureRedisFactory _azureRedis;
+        private readonly CoreAPIHttpService _coreAPIHttpService;
+        private readonly ThirdApisService _scsApisService;
+        private readonly HttpTrigger _httpTrigger;
+        private readonly IWebHostEnvironment _environment;
+        /// <summary>
+        /// 机构安全码
+        /// </summary>
+        public string _sc_passKey;
+        /// <summary>
+        /// 机构ID
+        /// </summary>
+        public string _sc_trainComID;
+        /// <summary>
+        /// 机构 AES 密钥
+        /// </summary>
+        public string _sc_privateKey;
+        /// <summary>
+        /// 访问地址
+        /// </summary>
+        public string _sc_url;
+        public IConfiguration _configuration { get; set; }
+        public XkwOAuth2Controller(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;
+            _snowflakeId = snowflakeId;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _azureStorage = azureStorage;
+            _serviceBus = serviceBus;
+            _configuration = configuration;
+            _azureRedis = azureRedis;
+            _coreAPIHttpService = coreAPIHttpService;
+            _scsApisService = scsApisService;
+            _httpTrigger = httpTrigger;
+            _environment = environment;
+        }
+
+        /// <summary>
+        ///  标准OAuth2  方式的回调地址。
+        /// </summary>D:\VisualStudioProjects\TEAMModelOS\TEAMModelOS.SDK\Models\Service\Third\ScYxptModel.cs
+        /// <param name="request"></param>
+        /// <returns></returns>
+
+        [HttpGet("{path}/oauth2")]
+        [AllowAnonymous]
+        public async Task<IActionResult> Oauth2([FromQuery] OAuth oauth2, string path) {
+            //https://ssoserviceurl/oauth2/authorize?client_id=APPKEY&openid=OPENID=&service=SERVICE
+            return Ok(new { oauth2, path });
+        }
+    }
+}

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

@@ -702,7 +702,162 @@ namespace TEAMModelOS.Controllers
             return Ok(new { data });
         }
 
+        [HttpPost("test-scteacher-dn")]
+        public async Task<IActionResult> TestScteacherDn(JsonElement json) {
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            string sqls = "select distinct value(c.id )from c where c.code='Base' and  IS_DEFINED(c.finalScore)=true  ";
+            //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos
+            //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos/yxpt%2Fjinniu%2Fscbind%2F1647432004.json
+            List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "870a5a6b-1ab3-461a-bdeb-baec19780ddb" } });
+            List<string> ids = new List<string>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
+                .GetItemQueryIterator<string>(sqls, requestOptions: new QueryRequestOptions {PartitionKey= new PartitionKey("Base") }))
+            {
+                ids.Add(item);
+            }
+            long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+            List<string> erorr = new List<string>();
+            List<ScTeacher> teachersUp = new List<ScTeacher>();
+            foreach (var id in ids) {
+                try {
+                    BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("teammodelos").GetBlobClient($"/yxpt/jinniu/scbind/{id}.json").DownloadContentAsync();
+                    ScBindData scBindData = baseblobDownload.Content.ToObjectFromJson<ScBindData>();
+                    var tcd=  teachers.Find(x => x.RowKey.Equals(scBindData.pxid));
+                    if (tcd != null)
+                    {
+                        Teacher teacher = new Teacher
+                        {
+                            pk="Base",
+                            code = "Base",
+                            id = id,
+                            name = scBindData.username,
+                            size = 2,
+                            defaultSchool = tcd.schoolCode,
+                            schools = new List<TeacherSchool> {
+                                new TeacherSchool 
+                                {
+                                    schoolId = tcd.schoolCode, status = "join", time = now, name = scBindData.sn, areaId = tcd.areaId
+                                }
+                            },
+                            binds = new List<ThirdBind> { 
+                                new ThirdBind 
+                                { 
+                                    type= "scsyxpt",userid=scBindData.userid,username= scBindData.username,account=scBindData.account,data=new List<string>{ scBindData.ToJsonString()}
+                                }
+                            }
+                        };
+                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Teacher).UpsertItemAsync(teacher,new PartitionKey("Base"));
+                        tcd.tmdid = id;
+                        teachersUp.Add(tcd);
+                    }
+                    
+                } catch (Exception ) {
+                    erorr.Add(id);
+                }
+            }
+            await table.SaveOrUpdateAll(teachersUp);
+            return Ok();
+        }
+        [HttpPost("test-scteacher")]
+        public async Task<IActionResult> TestScteacher(JsonElement json) {
+            var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
+            List<TeacherFile> teacherFiles = new List<TeacherFile>();
+            string sqls = "select distinct c.id,c.code from c where c.pk='TeacherFile' and  IS_DEFINED(c.fileRecords)=false ";
+            List<IdNameCode> ids = new List<IdNameCode>();
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(sqls, requestOptions: new QueryRequestOptions {  }))
+            {
+                item.code= item.code.Replace("TeacherFile-", "");
+                ids.Add(item);
+            }
+            var grp = ids.GroupBy(g => g.code).Select(x => new { key = x.Key, list = x.ToList() });
+          
+            foreach (var gp in grp) {
+                foreach (var tch in gp.list) {
+                    if (!string.IsNullOrWhiteSpace(tch.id)) {
+                       var id  =  ids.Find(x => x.id.Equals(tch.id))?.id;
+                        if (id != null) {
+                            TeacherFile teacherFile = new TeacherFile { id = id,pk= "TeacherFile",code= $"TeacherFile-{gp.key}",ttl=-1 };
+                            List<AbilitySub> abilitySubs = new List<AbilitySub>();
+                            string sql = "select value(c) from c ";
+                            try {
+                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>
+                             (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{gp.key}-{id}") }))
+                                {
+                                    abilitySubs.Add(item);
+                                }
+                           
+                            Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
+                            var taskids=  abilitySubs.SelectMany(x => x.taskRcds).Select(x => x.id).ToHashSet();
+                            if (taskids.Any()) {
+
+                                List<AbilityTask> abilityTasks = new List<AbilityTask>();
+                                string taskSql = $"select distinct value(c) from c  join b in c.children where c.code='AbilityTask-standard10' and b.id in ({string.Join(",", taskids.Select(m=>$"'{m}'"))})";
+                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
+                                   (taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
+                                {
+                                    abilityTasks.Add(item);
+                                }
+                                abilityTasks.ForEach(x => {
+                                    x.children.ForEach(y => {
+                                       var di= taskids.ToList().Find(z => z.Equals(y.id));
+                                        if (!string.IsNullOrWhiteSpace(id)) {
+                                            y.rnodes.ForEach(r => {
+                                                if (valuePairs.ContainsKey(r.hash))
+                                                {
+                                                    valuePairs.TryGetValue(r.hash, out var value);
+                                                    value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = r.id });
+                                                }
+                                                else {
+                                                    valuePairs.Add(r.hash, new RecordFileAbility
+                                                    {
+                                                        fileRecord =
+                                                        new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
+                                                        fileAbilities = new List<FileAbility> { new FileAbility { url=r.link,abilityId=x.abilityId,taskId=x.id,nodeId=r.id } }
+                                                    });
+                                                }
+                                            });
+                                        }
+                                    });
+                                });
+                                }
+                                foreach (var item in valuePairs)
+                                {
+                                    teacherFile.fileRecords.Add(new FileRecord
+                                    {
+                                        hash = item.Value.fileRecord.hash,
+                                        size = item.Value.fileRecord.size,
+                                        duration = item.Value.fileRecord.duration,
+                                        view = (int)item.Value.fileRecord.view,
+                                        type = item.Value.fileRecord.type,
+                                        done = true,
+                                        files = item.Value.fileAbilities
+                                    });
+                                    
+                                 
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                                return BadRequest(new { ex = ex.Message, ms = ex.StackTrace });
+
+                            }
+                            teacherFiles.Add(teacherFile);
+                             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacherFile, new PartitionKey(teacherFile.code));
+                        }
+                    }
+                }
+            }
+            
+            return Ok(teacherFiles);
+        }
 
+
+        public class RecordFileAbility
+        {
+
+           public FileRecord fileRecord { get; set; }
+            public List<FileAbility> fileAbilities { get; set; }
+        }
         [HttpPost("test-blob-folder")]
         public async Task<IActionResult> TestBlobFolder(JsonElement json)
         {
@@ -731,5 +886,4 @@ namespace TEAMModelOS.Controllers
             return Ok(new { lessonIds , ids , notdata, notblob });
         }
     }
-
 }

+ 15 - 1
TEAMModelOS/appsettings.Development.json

@@ -87,7 +87,7 @@
       "trainComID": "3069", //机构ID
       "privateKey": "52C1C240E4BE086DD15DB10814E243E6", //机构 AES 密钥
       "url": "https://scts.scedu.com.cn/webservice/EduService.asmx/RequestService"
-    }
+    },
 
     ///英鼎教育-金牛区
     //"scsyxpt": {
@@ -96,5 +96,19 @@
     //  "privateKey": "CA00580BB7BFA3817334CFA38257AC9A", //机构 AES 密钥
     //  "url": "https://scts.scedu.com.cn/webservice/EduService.asmx/RequestService"
     //}
+
+    ///学科网测试站
+    "xkw": {
+      "appKey": "key808", //学科网分配的appkey
+      "appSecret": "ed4545f513444725bd811e909d3ac79f", //学科网分配的appSecret
+      "service": "http://t.zxxk.com/user/uc", // 学科网的服务,如http://www.zxxk.com/、http://zujuan.xkw.com/等,注意域名后面的斜杠不能少,更多服务可联系客服获取
+      "oauthServerUrl": "https://t.zxxk.com" //学科网Oauth认证平台地址
+    }
+    //"xkw": {
+    //  "appKey": "key808", //学科网分配的appkey
+    //  "appSecret": "ed4545f513444725bd811e909d3ac79f", //学科网分配的appSecret
+    //  "service": "http://t.zxxk.com/user/uc", // 学科网的服务,如http://www.zxxk.com/、http://zujuan.xkw.com/等,注意域名后面的斜杠不能少,更多服务可联系客服获取
+    //  "oauthServerUrl": "https://t.zxxk.com" //学科网Oauth认证平台地址
+    //}
   }
 }