|
@@ -1,4 +1,5 @@
|
|
|
using Azure.Cosmos;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
@@ -56,12 +57,89 @@ namespace TEAMModelOS.Controllers
|
|
|
_configuration = configuration;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "scope":"school/private",
|
|
|
+ "tmdid":"1595321354",
|
|
|
+ "delete_id":"asdeeeqq-adfghnlr-pfkcmsss-ssadffgtre",
|
|
|
+ "opt":"delete",
|
|
|
+ "school":"hbcn" //如果scope=school 这 school字段必须有值
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取开课记录
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
+ // [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [HttpPost("delete-lesson-record")]
|
|
|
+ public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
|
|
|
+ {
|
|
|
+ string scope = "";
|
|
|
+ string tmdid = "";
|
|
|
+ string lessonId;
|
|
|
+ string school;
|
|
|
+ string tbname;
|
|
|
+ string code;
|
|
|
+ if (request.TryGetProperty("delete_id", out JsonElement _delete_id) && !string.IsNullOrEmpty($"{_delete_id}")
|
|
|
+ && request.TryGetProperty("tmdid", out JsonElement _dtmdid) && !string.IsNullOrEmpty($"{_dtmdid}")
|
|
|
+ && request.TryGetProperty("scope", out JsonElement _dscope) && !string.IsNullOrEmpty($"{_dscope}")
|
|
|
+ && request.TryGetProperty("opt", out JsonElement _opt) && !string.IsNullOrEmpty($"{_opt}"))
|
|
|
+ {
|
|
|
+ request.TryGetProperty("school", out JsonElement _dschool);
|
|
|
+ school = $"{_dschool}";
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if ($"{_opt}".Equals("delete"))
|
|
|
+ {
|
|
|
+ if ($"{_dscope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{school}";
|
|
|
+ tbname = "School";
|
|
|
+ }
|
|
|
+ else if ($"{_dscope}".Equals("private"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{tmdid}";
|
|
|
+ tbname = "Teacher";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest() ;
|
|
|
+ }
|
|
|
+ lessonId = $"{_delete_id}";
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ LessonRecord lessonRecord ;
|
|
|
+ var doc = JsonDocument.Parse(response.ContentStream);
|
|
|
+ lessonRecord = doc.RootElement.ToObject<LessonRecord>();
|
|
|
+ lessonRecord.status = -1;
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ var messageChange = new ServiceBusMessage(request.ToJsonString());
|
|
|
+ messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+ else { return BadRequest(); }
|
|
|
+ }
|
|
|
+ else { return BadRequest() ; }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取开课记录 (c.status<>-1 or IS_DEFINED(c.status)=false )
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-lesson-record-count")]
|
|
|
public async Task<IActionResult> GetLessonRecordCont(JsonElement request)
|
|
@@ -69,7 +147,7 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
- sql.Append("select value(count(1)) from c ");
|
|
|
+ sql.Append("select value(count(1)) from c ");
|
|
|
Dictionary<string ,object> dict = GetLessonCond(request);
|
|
|
AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
string tbname = "";
|
|
@@ -105,6 +183,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
int count=0;
|
|
|
+ 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).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
{
|
|
|
count = item;
|
|
@@ -112,7 +191,7 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { count=count });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取开课记录
|
|
|
/// </summary>
|
|
@@ -186,6 +265,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
List<LessonRecord> lessonRecords = new List<LessonRecord>();
|
|
|
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,
|
|
|
requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
|
|
@@ -223,7 +303,6 @@ namespace TEAMModelOS.Controllers
|
|
|
continuationToken = null;
|
|
|
return Ok(new { currCount=0, continuationToken = continuationToken, lessonRecords });
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private Dictionary<string, object> GetLessonCond(JsonElement request)
|