|
@@ -2399,136 +2399,149 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("un-upload-abilitysub")]
|
|
|
public async Task<IActionResult> UnUploadAbilitysub(JsonElement json)
|
|
|
{
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- //金牛直属。
|
|
|
- string sql = "SELECT distinct c.id,s.schoolId as code , c.name FROM c join s in c.schools where s.areaId='f35e0031-a53f-45e5-b307-1cd39446a2cf' and array_length(c.binds)>0 ";
|
|
|
- List<IdNameCode> tmdidSchooCode = new List<IdNameCode>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(queryText: sql,
|
|
|
- requestOptions: new QueryRequestOptions { PartitionKey= new PartitionKey("Base")}))
|
|
|
- {
|
|
|
- tmdidSchooCode.Add(item);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ //金牛直属。
|
|
|
+ string sql = "SELECT distinct c.id,s.schoolId as code , c.name FROM c join s in c.schools where s.areaId='f35e0031-a53f-45e5-b307-1cd39446a2cf' and array_length(c.binds)>0 ";
|
|
|
+ List<IdNameCode> tmdidSchooCode = new List<IdNameCode>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ tmdidSchooCode.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Ability> abilities = new List<Ability>();
|
|
|
+ string abilitysql = "select value c from c ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<Ability>(queryText: abilitysql,
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Ability-standard4") }))
|
|
|
+ {
|
|
|
+ abilities.Add(item);
|
|
|
+ }
|
|
|
+ List<dynamic> dynamics = new List<dynamic>();
|
|
|
+ foreach (var idcode in tmdidSchooCode)
|
|
|
+ {
|
|
|
+ string subsql = "select value c from c ";
|
|
|
+ List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
+ List<UnUpload> unUploads = new List<UnUpload>();
|
|
|
+ (string blobPix, string sas) = _azureStorage.GetBlobContainerSAS(idcode.code, Azure.Storage.Sas.BlobContainerSasPermissions.Read);
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>(queryText: subsql,
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{idcode.code}-{idcode.id}") }))
|
|
|
+ {
|
|
|
+ abilitySubs.Add(item);
|
|
|
|
|
|
- List<Ability> abilities = new List<Ability>();
|
|
|
- string abilitysql = "select value c from c ";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<Ability>(queryText: abilitysql,
|
|
|
- requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Ability-standard4") }))
|
|
|
- {
|
|
|
- abilities.Add(item);
|
|
|
- }
|
|
|
- List<dynamic> dynamics = new List<dynamic>();
|
|
|
- foreach (var idcode in tmdidSchooCode) {
|
|
|
- string subsql = "select value c from c ";
|
|
|
- List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
- List<UnUpload> unUploads = new List<UnUpload>();
|
|
|
- (string blobPix, string sas) = _azureStorage.GetBlobContainerSAS(idcode.code, Azure.Storage.Sas.BlobContainerSasPermissions.Read);
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>(queryText: subsql,
|
|
|
- requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{idcode.code}-{idcode.id}") }))
|
|
|
- {
|
|
|
- abilitySubs.Add(item);
|
|
|
-
|
|
|
- }
|
|
|
- //移除通识
|
|
|
- abilitySubs.RemoveAll(ab => ab.id.Equals("2438e72f-4de8-4ccb-8cae-3f1dce89a769"));
|
|
|
- if (abilitySubs.Count > 3) {
|
|
|
- //一个都没上传
|
|
|
- if (!abilitySubs.SelectMany(upsl => upsl.uploads).Any())
|
|
|
- {
|
|
|
- var a= abilitySubs.Count - 3;
|
|
|
- for (int i = 0; i < a; i++) {
|
|
|
- abilitySubs.RemoveAt(i);
|
|
|
- }
|
|
|
}
|
|
|
- else {
|
|
|
- //检查
|
|
|
- var 上传了的 = abilitySubs.FindAll(x => x.uploads.Count > 0);
|
|
|
- //如果上传大于三个能力点,则清空掉多余的没有上传的
|
|
|
- if (上传了的.Count >= 3)
|
|
|
+ //移除通识
|
|
|
+ abilitySubs.RemoveAll(ab => ab.id.Equals("2438e72f-4de8-4ccb-8cae-3f1dce89a769"));
|
|
|
+ if (abilitySubs.Count > 3)
|
|
|
+ {
|
|
|
+ //一个都没上传
|
|
|
+ if (!abilitySubs.SelectMany(upsl => upsl.uploads).Any())
|
|
|
{
|
|
|
- abilitySubs.RemoveAll(x => x.uploads.Count == 0);
|
|
|
+ try {
|
|
|
+ var a = abilitySubs.Count - 3;
|
|
|
+ abilitySubs = abilitySubs.Skip(a).ToList();
|
|
|
+ } catch { return BadRequest($"{idcode.ToJsonString()},{abilitySubs.ToJsonString()}"); }
|
|
|
}
|
|
|
- //如果上传不足三个的,保证有三个能力点
|
|
|
- else {
|
|
|
- var 未上传的数量 = abilitySubs.Count - 上传了的.Count;
|
|
|
- int 需要移除的数量 = 未上传的数量 - (3 - 上传了的.Count);
|
|
|
- abilitySubs.RemoveAll(x => x.uploads.Count == 0);
|
|
|
- var 未上传的= abilitySubs.FindAll(x => x.uploads.Count == 0);
|
|
|
- for (int i = 0; i < 需要移除的数量; i++)
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //检查
|
|
|
+ var 上传了的 = abilitySubs.FindAll(x => x.uploads.Count > 0);
|
|
|
+ //如果上传大于三个能力点,则清空掉多余的没有上传的
|
|
|
+ if (上传了的.Count >= 3)
|
|
|
+ {
|
|
|
+ abilitySubs.RemoveAll(x => x.uploads.Count == 0);
|
|
|
+ }
|
|
|
+ //如果上传不足三个的,保证有三个能力点
|
|
|
+ else
|
|
|
{
|
|
|
- 未上传的.Remove(abilitySubs[i]);
|
|
|
+
|
|
|
+ var 未上传的数量 = abilitySubs.Count - 上传了的.Count;
|
|
|
+ int 需要增加的 = 3 - 上传了的.Count;
|
|
|
+ abilitySubs.RemoveAll(x => x.uploads.Count == 0);
|
|
|
+ var 未上传的 = abilitySubs.FindAll(x => x.uploads.Count == 0);
|
|
|
+ List<AbilitySub> newAb = 上传了的;
|
|
|
+ for (int i = 0; i < 需要增加的; i++)
|
|
|
+ {
|
|
|
+ newAb.Add(未上传的[i]);
|
|
|
+ }
|
|
|
+ abilitySubs = newAb;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- foreach (var item in abilitySubs) {
|
|
|
- var ability = abilities.Find(x => x.id.Equals(item.id));
|
|
|
- foreach (var x in ability.stds)
|
|
|
+ foreach (var item in abilitySubs)
|
|
|
{
|
|
|
- UnUpload unUpload = new UnUpload { abilityId= ability .id, abilityName= $"{ability.name}({ability.no})" };
|
|
|
- var upload = item.uploads.FindAll(u => u.stdid.Equals(x.id));
|
|
|
- if (upload != null)
|
|
|
+ var ability = abilities.Find(x => x.id.Equals(item.id));
|
|
|
+ foreach (var x in ability.stds)
|
|
|
{
|
|
|
- AbilityStdTask abilityStdTask = null;
|
|
|
- x.task.ForEach(t => {
|
|
|
- if (upload.Where(u => u.taskid.Equals(t.id)).Any())
|
|
|
+ UnUpload unUpload = new UnUpload { abilityId = ability.id, abilityName = $"{ability.name}({ability.no})" };
|
|
|
+ var upload = item.uploads.FindAll(u => u.stdid.Equals(x.id));
|
|
|
+ if (upload != null)
|
|
|
+ {
|
|
|
+ AbilityStdTask abilityStdTask = null;
|
|
|
+ x.task.ForEach(t => {
|
|
|
+ if (upload.Where(u => u.taskid.Equals(t.id)).Any())
|
|
|
+ {
|
|
|
+ abilityStdTask = t;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //检查是否正确上传任务的。
|
|
|
+ if (abilityStdTask == null)
|
|
|
{
|
|
|
- abilityStdTask = t;
|
|
|
+ var dict = new Dictionary<string, List<string>>();
|
|
|
+ dict.Add(x.id, new List<string>(x.task.Select(t => t.id)));
|
|
|
+ unUpload.taskUnUplaod = dict;
|
|
|
}
|
|
|
- });
|
|
|
- //检查是否正确上传任务的。
|
|
|
- if (abilityStdTask == null)
|
|
|
- {
|
|
|
- var dict = new Dictionary<string, List<string>>();
|
|
|
- dict.Add(x.id, new List<string>(x.task.Select(t => t.id)));
|
|
|
- unUpload.taskUnUplaod = dict;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SubUpload subUpload = upload.Find(ap => ap.taskid.Equals(abilityStdTask.id));
|
|
|
- if (subUpload != null)
|
|
|
+ else
|
|
|
{
|
|
|
- List<string> urlUn = new List<string>();
|
|
|
- foreach (var url in subUpload.urls)
|
|
|
+ SubUpload subUpload = upload.Find(ap => ap.taskid.Equals(abilityStdTask.id));
|
|
|
+ if (subUpload != null)
|
|
|
{
|
|
|
- string blobItem = url.url.Replace($"{blobPix}/", "");
|
|
|
- List<string> items = await _azureStorage.GetBlobContainerClient(item.school).List(blobItem);
|
|
|
- if (!items.Any())
|
|
|
+ List<string> urlUn = new List<string>();
|
|
|
+ foreach (var url in subUpload.urls)
|
|
|
{
|
|
|
- urlUn.Add(blobItem);
|
|
|
+ string blobItem = url.url.Replace($"{blobPix}/", "");
|
|
|
+ List<string> items = await _azureStorage.GetBlobContainerClient(item.school).List(blobItem);
|
|
|
+ if (!items.Any())
|
|
|
+ {
|
|
|
+ urlUn.Add(blobItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (urlUn.Any())
|
|
|
+ {
|
|
|
+ Dictionary<string, KeyValuePair<string, List<string>>> urlUnExsit = new Dictionary<string, KeyValuePair<string, List<string>>>();
|
|
|
+ urlUnExsit.Add(x.id, new KeyValuePair<string, List<string>>(abilityStdTask.id, urlUn));
|
|
|
+ unUpload.urlUnExsit = urlUnExsit;
|
|
|
}
|
|
|
}
|
|
|
- if (urlUn.Any())
|
|
|
+ else
|
|
|
{
|
|
|
- Dictionary<string, KeyValuePair<string, List<string>>> urlUnExsit = new Dictionary<string, KeyValuePair<string, List<string>>>();
|
|
|
- urlUnExsit.Add(x.id, new KeyValuePair<string, List<string>>(abilityStdTask.id, urlUn));
|
|
|
- unUpload.urlUnExsit = urlUnExsit;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var dict = new Dictionary<string, List<string>>();
|
|
|
- dict.Add(x.id, new List<string>(x.task.Select(t => t.id)));
|
|
|
- unUpload.taskUnUplaod = dict;
|
|
|
+ var dict = new Dictionary<string, List<string>>();
|
|
|
+ dict.Add(x.id, new List<string>(x.task.Select(t => t.id)));
|
|
|
+ unUpload.taskUnUplaod = dict;
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ unUpload.stdsUnUpload.Add(x.id);
|
|
|
+ }
|
|
|
+ if (unUpload.stdsUnUpload.Any() || unUpload.taskUnUplaod != null || unUpload.urlUnExsit != null)
|
|
|
+ {
|
|
|
+ unUploads.Add(unUpload);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- unUpload.stdsUnUpload.Add(x.id);
|
|
|
- }
|
|
|
- if (unUpload.stdsUnUpload.Any() || unUpload.taskUnUplaod != null || unUpload.urlUnExsit != null)
|
|
|
- {
|
|
|
- unUploads.Add(unUpload);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ if (unUploads.Any())
|
|
|
+ {
|
|
|
+ dynamics.Add(new { idcode, unUploads });
|
|
|
+ }
|
|
|
}
|
|
|
- if (unUploads.Any()) {
|
|
|
- dynamics.Add(new { idcode, unUploads });
|
|
|
- }
|
|
|
+ return Ok(new { dynamics });
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return BadRequest($"{ex.Message}{ex.StackTrace}");
|
|
|
}
|
|
|
- return Ok(new { dynamics }) ;
|
|
|
}
|
|
|
|
|
|
public class UnUpload {
|