|
@@ -61,10 +61,10 @@ namespace TEAMModelOS.Controllers
|
|
try
|
|
try
|
|
{
|
|
{
|
|
Course course = new Course();
|
|
Course course = new Course();
|
|
- if (!requert.TryGetProperty("course", out JsonElement room)) return BadRequest();
|
|
|
|
|
|
+ if (!requert.TryGetProperty("course", out JsonElement _course)) return BadRequest();
|
|
if (!requert.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
if (!requert.TryGetProperty("option", out JsonElement option)) return BadRequest();
|
|
if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
- course = room.ToObject<Course>();
|
|
|
|
|
|
+ course = _course.ToObject<Course>();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
course.pk = typeof(Course).Name;
|
|
course.pk = typeof(Course).Name;
|
|
string code = course.code;
|
|
string code = course.code;
|
|
@@ -741,36 +741,6 @@ namespace TEAMModelOS.Controllers
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
if (scope.ToString().Equals("school"))
|
|
if (scope.ToString().Equals("school"))
|
|
{
|
|
{
|
|
- /*List<CourseManagement> managements = new List<CourseManagement>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.courses where A0.course.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{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())
|
|
|
|
- {
|
|
|
|
- managements.Add(obj.ToObject<CourseManagement>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < managements.Count; i++)
|
|
|
|
- {
|
|
|
|
- bool flag = false;
|
|
|
|
- for (int j = 0; j < managements[i].courses.Count; j++)
|
|
|
|
- {
|
|
|
|
- if (!managements[i].courses[j].course.id.Equals(id.ToString()))
|
|
|
|
- {
|
|
|
|
- flag = true;
|
|
|
|
- managements[i].courses.Remove(managements[i].courses[j]);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (flag)
|
|
|
|
- {
|
|
|
|
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(managements[i], managements[i].id, new PartitionKey($"{managements[i].code}"));
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -802,28 +772,9 @@ namespace TEAMModelOS.Controllers
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();*/
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();*/
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
if (request == null) return BadRequest();
|
|
if (request == null) return BadRequest();
|
|
- /* StringBuilder sql = new StringBuilder();
|
|
|
|
- sql.Append("select value(c) from c ");*/
|
|
|
|
- /*Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
|
- //处理id
|
|
|
|
- if (request.ids.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- dict.Add("id", request.ids.ToArray());
|
|
|
|
- }*/
|
|
|
|
|
|
+
|
|
string school_code = request.code;
|
|
string school_code = request.code;
|
|
- /*AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
|
|
|
|
- List<Course> courses = new List<Course>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school_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())
|
|
|
|
- {
|
|
|
|
- courses.Add(obj.ToObject<Course>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
|
|
+
|
|
if (request.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
if (request.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
List<Response> res = await client.GetContainer("TEAMModelOS", "School").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
|
|
List<Response> res = await client.GetContainer("TEAMModelOS", "School").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
|
|
@@ -833,54 +784,6 @@ namespace TEAMModelOS.Controllers
|
|
List<Response> res = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
|
|
List<Response> res = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemsStreamAsync(request.ids, $"Course-{school_code}");
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO JJ调整批量删除
|
|
|
|
- //await _azureCosmos.DeleteAll(courses);
|
|
|
|
- //List<IdPk> idPk = await _azureCosmos.DeleteAll<Course>(request);
|
|
|
|
- //await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Class-{code}"));
|
|
|
|
- //[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
|
|
|
|
- /*StringBuilder sqlM = new StringBuilder();
|
|
|
|
- sqlM.Append("select value(c) from c ");
|
|
|
|
- Dictionary<string, object> dict_management = new Dictionary<string, object>();
|
|
|
|
- //处理ID
|
|
|
|
- if (request.ids.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- dict_management.Add("courses[*].course.id", request.ids.ToArray());
|
|
|
|
- }
|
|
|
|
- List<CourseManagement> managements = new List<CourseManagement>();
|
|
|
|
- AzureCosmosQuery cosmosDbQuery_1 = SQLHelper.GetSQL(dict_management, sqlM);
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery_1.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CourseManagement-{school_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())
|
|
|
|
- {
|
|
|
|
- managements.Add(obj.ToObject<CourseManagement>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < managements.Count; i++)
|
|
|
|
- {
|
|
|
|
- bool flag = false;
|
|
|
|
- for (int k = 0; k < request.ids.Count; k++)
|
|
|
|
- {
|
|
|
|
- for (int j = 0; j < managements[i].courses.Count; j++)
|
|
|
|
- {
|
|
|
|
- if (managements[i].courses[j].course.id.Equals(request.ids[k].ToString()))
|
|
|
|
- {
|
|
|
|
- managements[i].courses.Remove(managements[i].courses[j]);
|
|
|
|
- flag = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (flag)
|
|
|
|
- {
|
|
|
|
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(managements[i], managements[i].id, new PartitionKey($"{managements[i].code}"));
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
- ////[Jeff] CourseManagement表廢除 刪除預定:以下CourseManagement更新程序
|
|
|
|
- //IdPk idPk= await _azureCosmos.DeleteAsync<Course>(request);
|
|
|
|
return Ok(new { ids = request.ids });
|
|
return Ok(new { ids = request.ids });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -888,12 +791,6 @@ namespace TEAMModelOS.Controllers
|
|
await _dingDing.SendBotMsg($"CN,{_option.Location},course/delete()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"CN,{_option.Location},course/delete()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
- //return builder.Data(idPk).build();
|
|
|
|
- //return Ok(new { idPk });
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -919,20 +816,12 @@ namespace TEAMModelOS.Controllers
|
|
var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
if (response.Status == 200)
|
|
if (response.Status == 200)
|
|
{
|
|
{
|
|
- /* using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
|
- CourseManagement courseManagement = json.ToObject<CourseManagement>();
|
|
|
|
- courseManagement.courses = requert.courses;*/
|
|
|
|
- //return Ok(new { error = ResponseCode.DATA_EXIST, V = "课程编码已经存在!" });
|
|
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(requert, requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(requert, requert.id, new PartitionKey($"CourseManagement-{code}"));
|
|
-
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(requert, new PartitionKey($"CourseManagement-{code}"));
|
|
course = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(requert, new PartitionKey($"CourseManagement-{code}"));
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
return Ok(new { course });
|
|
return Ok(new { course });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -982,43 +871,7 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- /* List<object> courses = new List<object>();
|
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.ToString(), new PartitionKey($"CourseManagement-{code}"));
|
|
|
|
- if (response.Status == 200)
|
|
|
|
- {
|
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
|
- foreach (var obj in json.RootElement.GetProperty("courseSimples").EnumerateArray())
|
|
|
|
- {
|
|
|
|
- courses.Add(obj.ToObject<object>());
|
|
|
|
- }
|
|
|
|
- *//*if (json.RootElement.TryGetProperty("courseSimples", out JsonElement value))
|
|
|
|
- {
|
|
|
|
- courses = (List<object>)value.ToObject<object>();
|
|
|
|
- }*//*
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- return Ok(new { error = ResponseCode.UNDEFINED, V = "数据未找到!" });
|
|
|
|
- }*/
|
|
|
|
return Ok(new { courses });
|
|
return Ok(new { courses });
|
|
- /* var query = $"select c.code,c.id,c.name,c.period,c.subject,c.teachers from c";
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school_code.GetString()}") }))
|
|
|
|
- {
|
|
|
|
- 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())
|
|
|
|
- {
|
|
|
|
- courses.Add(obj.ToObject<object>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
- //return Ok(new { courses, courses.Count });
|
|
|
|
-
|
|
|
|
- /* List<Course> data = new List<Course>();
|
|
|
|
- if (StringHelper.getKeyCount(request) > 0) {
|
|
|
|
- data = await _azureCosmos.FindByDict<Course>(request);
|
|
|
|
- }
|
|
|
|
- return builder.Data(data).Extend(new Dictionary<string, object> { { "count", data.Count } }).build();*/
|
|
|
|
}
|
|
}
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
//[AuthToken(Roles = "Teacher")]
|
|
//[AuthToken(Roles = "Teacher")]
|
|
@@ -1140,20 +993,7 @@ namespace TEAMModelOS.Controllers
|
|
Teachers teachers = teacherInfo.ToObject<Teachers>();
|
|
Teachers teachers = teacherInfo.ToObject<Teachers>();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
List<CourseManagement> courseManagements = new List<CourseManagement>();
|
|
List<CourseManagement> courseManagements = new List<CourseManagement>();
|
|
- /*var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
|
|
- if (sresponse.Status == 200)
|
|
|
|
- {
|
|
|
|
- using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
|
|
|
|
- CourseManagement course = json.ToObject<CourseManagement>();
|
|
|
|
- for (int i =0; i < course.courses.Count;i++) {
|
|
|
|
- if (course.courses[i].course.id.Equals(courseId.ToString())) {
|
|
|
|
- course.courses[i].course.notice = notice.ToString();
|
|
|
|
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(course, course.id, new PartitionKey($"{course.code}"));
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }*/
|
|
|
|
|
|
+
|
|
StringBuilder sql = new StringBuilder();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.Append("select value(c) from c");
|
|
sql.Append("select value(c) from c");
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
@@ -1187,54 +1027,9 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
return Ok(new { id });
|
|
return Ok(new { id });
|
|
}
|
|
}
|
|
- internal class valitime
|
|
|
|
- {
|
|
|
|
- public string code { get; set; }
|
|
|
|
- public string courseId { get; set; }
|
|
|
|
- public string classroomCode { get; set; }
|
|
|
|
- public string time { get; set; }
|
|
|
|
- public string day { get; set; }
|
|
|
|
- public string notice { get; set; }
|
|
|
|
- public CourseTime courseTime { get; set; }
|
|
|
|
- /// <summary>
|
|
|
|
- /// 学生分组
|
|
|
|
- /// </summary>
|
|
|
|
- public List<GroupStudent> groups { get; set; }
|
|
|
|
- /// <summary>
|
|
|
|
- /// 助教
|
|
|
|
- /// </summary>
|
|
|
|
- public List<Assistant> assistant { get; set; }
|
|
|
|
- /// <summary>
|
|
|
|
- /// 学期代码
|
|
|
|
- /// </summary>
|
|
|
|
- public string semesterCode { get; set; }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // TODO 前端没在用
|
|
|
|
|
|
+
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 教师更新副属信息,助教,分组等。
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- //[ProducesDefaultResponseType]
|
|
|
|
- ////[AuthToken(Roles = "Teacher")]
|
|
|
|
- //[HttpPost("upsert-plan")]
|
|
|
|
- //public async Task<BaseResponse> UpsertPlan(CoursePlan request) {
|
|
|
|
- // ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
- // CoursePlan datas = await _azureCosmos.FindByIdPk<CoursePlan>(request.id,request.code);
|
|
|
|
- // if (datas!=null) {
|
|
|
|
- // request.semesterCode = datas.semesterCode;
|
|
|
|
- // request.classes.ForEach(x => {
|
|
|
|
- // datas.classes.ForEach(m => {
|
|
|
|
- // if (m.classroomCode == x.classroomCode) {
|
|
|
|
- // x.courseTimes = m.courseTimes;
|
|
|
|
- // } });
|
|
|
|
- // });
|
|
|
|
- // await _azureCosmos.Update(request);
|
|
|
|
- // }
|
|
|
|
- // return builder.Data(request).build();
|
|
|
|
- //}
|
|
|
|
|
|
+
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
//[AuthToken(Roles = "Teacher")]
|
|
//[AuthToken(Roles = "Teacher")]
|
|
@@ -1517,42 +1312,7 @@ namespace TEAMModelOS.Controllers
|
|
//courses = courses.Distinct().ToList();
|
|
//courses = courses.Distinct().ToList();
|
|
return Ok(new { courses});
|
|
return Ok(new { courses});
|
|
}
|
|
}
|
|
-
|
|
|
|
- // TODO 前端没在用
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 删除课程安排
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- //[ProducesDefaultResponseType]
|
|
|
|
- ////[AuthToken(Roles = "Teacher")]
|
|
|
|
- //[HttpPost("delete-time")]
|
|
|
|
- //public async Task<BaseResponse> DeletePlan(JsonElement request)
|
|
|
|
- //{
|
|
|
|
- // ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
- // if (request.TryGetProperty("id",out JsonElement id) && request.TryGetProperty("code",out JsonElement code) && request.TryGetProperty("classroomCode",out JsonElement classroomCode)
|
|
|
|
- // && request.TryGetProperty("time",out JsonElement time) && request.TryGetProperty("day",out JsonElement day)) {
|
|
|
|
- // CoursePlan coursePlan = await _azureCosmos.FindByIdPk<CoursePlan>(id.ToString(), code.ToString());
|
|
|
|
- // List<CourseTime> courseTimes = new List<CourseTime>();
|
|
|
|
- // coursePlan.classes.ForEach(x=> {
|
|
|
|
- // if (x.classroomCode == classroomCode.ToString()) {
|
|
|
|
- // x.courseTimes.ForEach(y => {
|
|
|
|
- // if (y.time == time.ToString() && y.day == day.ToString())
|
|
|
|
- // {
|
|
|
|
- // courseTimes.Add(y);
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- // coursePlan.classes.ForEach(x => { if (x.classroomCode == classroomCode.ToString()) {
|
|
|
|
- // courseTimes.ForEach(y => { x.courseTimes.Remove(y); });
|
|
|
|
- // } });
|
|
|
|
- // await _azureCosmos.Update(coursePlan);
|
|
|
|
- // return builder.Data(coursePlan).build();
|
|
|
|
- // }
|
|
|
|
- // return builder.Data(null).build();
|
|
|
|
- //}
|
|
|
|
|
|
+
|
|
|
|
|
|
public class Student
|
|
public class Student
|
|
{
|
|
{
|