|
@@ -12,6 +12,7 @@ using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
+using System.Text.Json.Nodes;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.Filter;
|
|
|
using TEAMModelOS.Models;
|
|
@@ -274,15 +275,13 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok(new { count=count });
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 获取开课记录
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- // [AuthToken(Roles = "teacher,admin")]
|
|
|
+ // [AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-lesson-record")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> GetLessonRecord(JsonElement request)
|
|
@@ -319,7 +318,7 @@ namespace TEAMModelOS.Controllers
|
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
string tbname = "";
|
|
|
string code = "";
|
|
|
- if (_scope.GetString().Equals("school") )
|
|
|
+ if (_scope.GetString().Equals("school"))
|
|
|
{
|
|
|
if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
|
|
|
if (!string.IsNullOrEmpty($"{_school}"))
|
|
@@ -340,7 +339,8 @@ namespace TEAMModelOS.Controllers
|
|
|
code = $"LessonRecord-{_tmdid}";
|
|
|
tbname = "Teacher";
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
@@ -349,7 +349,8 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
List<LessonRecord> lessonRecords = new List<LessonRecord>();
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and ");
|
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
|
|
|
.GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
|
|
@@ -366,7 +367,109 @@ namespace TEAMModelOS.Controllers
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- var tmdids= lessonRecords.Select(x => x.tmdid).ToHashSet();
|
|
|
+ var tmdids = lessonRecords.Select(x => x.tmdid).ToHashSet();
|
|
|
+ if (tmdids != null && tmdids.Count > 0)
|
|
|
+ {
|
|
|
+ List<IdNameCode> codes = new List<IdNameCode>();
|
|
|
+ string sqltmd = $"select c.id,c.name,c.picture from c where c.id in ({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<IdNameCode>(queryText: sqltmd, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ codes.Add(item);
|
|
|
+ }
|
|
|
+ if (codes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ lessonRecords.ForEach(x => {
|
|
|
+ var tmd = codes.Find(z => z.id.Equals(x.tmdid));
|
|
|
+ if (tmd != null)
|
|
|
+ {
|
|
|
+ x.tmdname = tmd.name;
|
|
|
+ x.tmdpicture = tmd.picture;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { currCount = lessonRecords.Count, continuationToken, lessonRecords });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ continuationToken = null;
|
|
|
+ return Ok(new { currCount = 0, continuationToken = continuationToken, lessonRecords });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取开课记录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ // [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [HttpPost("get-other-lesson-record")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ public async Task<IActionResult> GetOtherLessonRecord(JsonElement request)
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
+ string tbname = "";
|
|
|
+ string code = "";
|
|
|
+ if (_scope.GetString().Equals("school") )
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
|
|
|
+ if (!string.IsNullOrEmpty($"{_school}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{_school}";
|
|
|
+ tbname = "School";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ($"{_scope}".Equals("private"))
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
|
|
|
+ if (!string.IsNullOrEmpty($"{_tmdid}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{_tmdid}";
|
|
|
+ tbname = "Teacher";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ request.TryGetProperty("periodId", out JsonElement _periodId);
|
|
|
+ //优质课程
|
|
|
+ var excellent = new JsonObject
|
|
|
+ {
|
|
|
+ ["excellent"] = true,
|
|
|
+ ["periodId"] = $"{_periodId}",
|
|
|
+ }.ToJsonString().ToObject<JsonElement>();
|
|
|
+ //专家好客
|
|
|
+ var doubleGreen = new JsonObject
|
|
|
+ {
|
|
|
+ ["doubleGreen"] = true,
|
|
|
+ ["periodId"] = $"{_periodId}",
|
|
|
+ }.ToJsonString().ToObject<JsonElement>();
|
|
|
+ //今日课程
|
|
|
+ var today = new JsonObject
|
|
|
+ {
|
|
|
+ ["today"] = true,
|
|
|
+ ["periodId"] = $"{_periodId}",
|
|
|
+ }.ToJsonString().ToObject<JsonElement>();
|
|
|
+ List<LessonRecord> excellentRcd =await GetOtherLessonCond(excellent, code, tbname);
|
|
|
+ List<LessonRecord> doubleGreenRcd = await GetOtherLessonCond(doubleGreen, code, tbname);
|
|
|
+ List<LessonRecord> todayRcd = await GetOtherLessonCond(today, code, tbname);
|
|
|
+ try {
|
|
|
+ var tmdids_excellent = excellentRcd.Select(x => x.tmdid);
|
|
|
+ var tmdids_doubleGreen = excellentRcd.Select(x => x.tmdid);
|
|
|
+ var tmdids_today = excellentRcd.Select(x => x.tmdid);
|
|
|
+ List<string> tmdids=new List<string>();
|
|
|
+ tmdids.AddRange(tmdids_excellent);
|
|
|
+ tmdids.AddRange(tmdids_doubleGreen);
|
|
|
+ tmdids.AddRange(tmdids_today);
|
|
|
if (tmdids != null && tmdids.Count > 0) {
|
|
|
List< IdNameCode > codes= new List<IdNameCode> ();
|
|
|
string sqltmd = $"select c.id,c.name,c.picture from c where c.id in ({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
|
|
@@ -374,22 +477,60 @@ namespace TEAMModelOS.Controllers
|
|
|
codes.Add(item);
|
|
|
}
|
|
|
if (codes.IsNotEmpty()) {
|
|
|
- lessonRecords.ForEach(x => {
|
|
|
+ excellentRcd.ForEach(x => {
|
|
|
var tmd= codes.Find(z => z.id.Equals(x.tmdid));
|
|
|
if (tmd != null) {
|
|
|
x.tmdname = tmd.name;
|
|
|
x.tmdpicture= tmd.picture;
|
|
|
}
|
|
|
});
|
|
|
+ doubleGreenRcd.ForEach(x => {
|
|
|
+ var tmd = codes.Find(z => z.id.Equals(x.tmdid));
|
|
|
+ if (tmd != null)
|
|
|
+ {
|
|
|
+ x.tmdname = tmd.name;
|
|
|
+ x.tmdpicture = tmd.picture;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ todayRcd.ForEach(x => {
|
|
|
+ var tmd = codes.Find(z => z.id.Equals(x.tmdid));
|
|
|
+ if (tmd != null)
|
|
|
+ {
|
|
|
+ x.tmdname = tmd.name;
|
|
|
+ x.tmdpicture = tmd.picture;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
- return Ok(new { currCount=lessonRecords.Count, continuationToken, lessonRecords });
|
|
|
+ return Ok(new { excellentRcd , doubleGreenRcd, todayRcd });
|
|
|
} catch (Exception ex) {
|
|
|
- continuationToken = null;
|
|
|
- return Ok(new { currCount=0, continuationToken = continuationToken, lessonRecords });
|
|
|
+ return Ok(new { excellentRcd, doubleGreenRcd, todayRcd });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private async Task<List<LessonRecord>> GetOtherLessonCond(JsonElement request,string code ,string tbname ) {
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.Append("select value(c) from c ");
|
|
|
+ Dictionary<string, object> dict = GetLessonCond(request);
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
+ List<LessonRecord> lessonRecords = new List<LessonRecord>();
|
|
|
+ cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>-1 or IS_DEFINED(c.status) = false ) and ");
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
|
|
|
+ .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ lessonRecords.Add(obj.ToObject<LessonRecord>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lessonRecords;
|
|
|
+ }
|
|
|
+
|
|
|
private Dictionary<string, object> GetLessonCond(JsonElement request)
|
|
|
{
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
@@ -431,12 +572,14 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
dict.Add(">=.discuss", 1);
|
|
|
}
|
|
|
-
|
|
|
+ if (request.TryGetProperty("excellent", out JsonElement excellent) && excellent.GetBoolean())
|
|
|
+ {
|
|
|
+ dict.Add(">=.excellent", 1);
|
|
|
+ }
|
|
|
if (request.TryGetProperty("name", out JsonElement name) && !string.IsNullOrWhiteSpace($"{name}"))
|
|
|
{
|
|
|
dict.Add("$.name", name);
|
|
|
}
|
|
|
-
|
|
|
if (request.TryGetProperty("today", out JsonElement today) && today.GetBoolean())
|
|
|
{
|
|
|
DateTime dateTimeA= Convert.ToDateTime(DateTimeOffset.UtcNow.ToString("D"));
|