|
@@ -56,6 +56,54 @@ namespace TEAMModelAPI.Controllers
|
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
|
_serviceBus = serviceBus;
|
|
|
}
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-course-list")]
|
|
|
+ [ApiToken(Auth = "1301", Name = "获取课程列表信息", RW = "R", Limit = false)]
|
|
|
+ public async Task<IActionResult> GetCourseList(JsonElement json)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
+ json.TryGetProperty("subjectId", out JsonElement subjectId);
|
|
|
+ StringBuilder sql = new StringBuilder($"SELECT c.id,c.name,c.subject,c.period,c.scope,c.no,c.school FROM c where 1=1 ");
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{periodId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.period.id='{periodId}'");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{subjectId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.subject.id='{subjectId}'");
|
|
|
+ }
|
|
|
+ List<dynamic> courses = new List<dynamic>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
|
|
|
+ GetItemQueryIterator<dynamic>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ return Ok(new { courses });
|
|
|
+ }
|
|
|
+
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-course-info")]
|
|
|
+ [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "R", Limit = false)]
|
|
|
+ public async Task<IActionResult> GetCourseInfo(JsonElement json)
|
|
|
+ {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ json.TryGetProperty("courseId", out JsonElement courseId);
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School")
|
|
|
+ .ReadItemStreamAsync($"{courseId}", new PartitionKey($"Course-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument document = JsonDocument.Parse(response.Content);
|
|
|
+ Course course = document.RootElement.Deserialize<Course>();
|
|
|
+ return Ok(new { course.name, course.id, course.subject, course.period, course.scope, course.school, course.no, course.desc, course.schedule });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 1, msg = "课程不存在!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取指定学段作息
|
|
|
/// </summary>
|
|
@@ -63,7 +111,7 @@ namespace TEAMModelAPI.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-period-timetable")]
|
|
|
- [ApiToken(Auth = "1301", Name = "试卷和评测的条件信息", RW = "R", Limit = false)]
|
|
|
+ [ApiToken(Auth = "1303", Name = "试卷和评测的条件信息", RW = "R", Limit = false)]
|
|
|
public async Task<IActionResult> GetPaperExamCondition(JsonElement json)
|
|
|
{
|
|
|
json.TryGetProperty("periodId", out JsonElement _periodId);
|
|
@@ -83,57 +131,27 @@ namespace TEAMModelAPI.Controllers
|
|
|
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
|
- [HttpPost("upsert-course-info")]
|
|
|
- [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "W", Limit = false)]
|
|
|
+ [HttpPost("upsert-course-infos")]
|
|
|
+ [ApiToken(Auth = "1304", Name = "课程详细信息", RW = "W", Limit = false)]
|
|
|
public async Task<IActionResult> UpsertCourseInfo(JsonElement json)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- if (!json.TryGetProperty("course", out JsonElement _course)) { return Ok(new { error = 1, msg = "课程对象不存在" }); }
|
|
|
- var courseDto = _course.ToObject<CourseDto>();
|
|
|
- Course course = null;
|
|
|
- if (courseDto != null && courseDto.Valid().isVaild) {
|
|
|
+ if (!json.TryGetProperty("courses", out JsonElement _courses)) { return Ok(new { error = 1, msg = "课程对象不存在" }); }
|
|
|
+ List<CourseDto> courseDtos = _courses.ToObject<List<CourseDto>>();
|
|
|
+ List<Dictionary<string, string>> errorData = new List<Dictionary<string, string>>();
|
|
|
+ List<Course> courses = new List<Course>() ;
|
|
|
+ if (courseDtos != null && courseDtos.Valid().isVaild) {
|
|
|
School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
- var period = data.period.Find(x => x.id.Equals($"{courseDto.periodId}"));
|
|
|
- if (period != null)
|
|
|
- {
|
|
|
- var subject = period.subjects.Find(x => x.id.Equals($"{courseDto.subjectId}"));
|
|
|
- if (subject != null)
|
|
|
+ foreach (var courseDto in courseDtos) {
|
|
|
+ var period = data.period.Find(x => x.id.Equals($"{courseDto.periodId}"));
|
|
|
+ if (period != null)
|
|
|
{
|
|
|
- if (string.IsNullOrWhiteSpace(courseDto?.id))
|
|
|
- {
|
|
|
- course = new Course
|
|
|
- {
|
|
|
- pk = "Course",
|
|
|
- id = Guid.NewGuid().ToString(),
|
|
|
- code = $"Course-{school}",
|
|
|
- name = courseDto.name,
|
|
|
- subject = new SubjectSimple { id = subject.id, name = subject.name },
|
|
|
- period = new PeriodSimple { id = period.id, name = period.name },
|
|
|
- school = school,
|
|
|
- desc = courseDto.desc,
|
|
|
- scope = "school",
|
|
|
- no = courseDto.no,
|
|
|
- };
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
- }
|
|
|
- else
|
|
|
+ var subject = period.subjects.Find(x => x.id.Equals($"{courseDto.subjectId}"));
|
|
|
+ if (subject != null)
|
|
|
{
|
|
|
- Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{course.id}", new PartitionKey($"Course-{school}"));
|
|
|
- if (response.Status == 200)
|
|
|
+ Course course = null;
|
|
|
+ if (string.IsNullOrWhiteSpace(courseDto?.id))
|
|
|
{
|
|
|
- JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
- course = jsonDocument.RootElement.ToObject<Course>();
|
|
|
- course.pk = "Course";
|
|
|
- course.name = string.IsNullOrWhiteSpace(courseDto.name) ? course.name : courseDto.name;
|
|
|
- course.subject = new SubjectSimple { id = subject.id, name = subject.name };
|
|
|
- course.period = new PeriodSimple { id = period.id, name = period.name };
|
|
|
- course.school = school;
|
|
|
- course.desc = string.IsNullOrWhiteSpace(courseDto.desc) ? course.desc : courseDto.desc;
|
|
|
- course.scope = "school";
|
|
|
- course.no = string.IsNullOrWhiteSpace(courseDto.no) ? course.no : courseDto.no;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(course,course.id, new PartitionKey(course.code));
|
|
|
- }
|
|
|
- else {
|
|
|
course = new Course
|
|
|
{
|
|
|
pk = "Course",
|
|
@@ -149,22 +167,60 @@ namespace TEAMModelAPI.Controllers
|
|
|
};
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{course.id}", new PartitionKey($"Course-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
+ course = jsonDocument.RootElement.ToObject<Course>();
|
|
|
+ course.pk = "Course";
|
|
|
+ course.name = string.IsNullOrWhiteSpace(courseDto.name) ? course.name : courseDto.name;
|
|
|
+ course.subject = new SubjectSimple { id = subject.id, name = subject.name };
|
|
|
+ course.period = new PeriodSimple { id = period.id, name = period.name };
|
|
|
+ course.school = school;
|
|
|
+ course.desc = string.IsNullOrWhiteSpace(courseDto.desc) ? course.desc : courseDto.desc;
|
|
|
+ course.scope = "school";
|
|
|
+ course.no = string.IsNullOrWhiteSpace(courseDto.no) ? course.no : courseDto.no;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(course, course.id, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ course = new Course
|
|
|
+ {
|
|
|
+ pk = "Course",
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = $"Course-{school}",
|
|
|
+ name = courseDto.name,
|
|
|
+ subject = new SubjectSimple { id = subject.id, name = subject.name },
|
|
|
+ period = new PeriodSimple { id = period.id, name = period.name },
|
|
|
+ school = school,
|
|
|
+ desc = courseDto.desc,
|
|
|
+ scope = "school",
|
|
|
+ no = courseDto.no,
|
|
|
+ };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (course != null) { courses.Add(course); }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorData.Add(new Dictionary<string, string> { { "course", courseDto.name }, { "subjectId", courseDto.subjectId } });
|
|
|
}
|
|
|
- return Ok(new { period.subjects, period.timetable, course = course });
|
|
|
}
|
|
|
- else {
|
|
|
- return Ok(new { error =4, msg = "科目不存在!" });
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorData.Add(new Dictionary<string, string> { { "course", courseDto.name }, { "periodId", courseDto.periodId } });
|
|
|
+ //return Ok(new { error = 2, msg = "学段不存在!" });
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok(new { error = 2, msg = "学段不存在!" });
|
|
|
- }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { error = 3, msg = courseDto.Valid() });
|
|
|
+ return Ok(new { error = 3, msg = courseDtos.Valid() });
|
|
|
}
|
|
|
+ return Ok(new { courses = courses ,errorData});
|
|
|
}
|
|
|
|
|
|
public class ImportCourse {
|
|
@@ -185,7 +241,7 @@ namespace TEAMModelAPI.Controllers
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert-course-schedule")]
|
|
|
- [ApiToken(Auth = "1303", Name = "更新课程的排课信息", RW = "W", Limit = false)]
|
|
|
+ [ApiToken(Auth = "1305", Name = "更新课程的排课信息", RW = "W", Limit = false)]
|
|
|
public async Task<IActionResult> UpsertCourseSchedule(JsonElement json)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
@@ -569,55 +625,5 @@ namespace TEAMModelAPI.Controllers
|
|
|
updateCourse= update_course
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-course-list")]
|
|
|
- [ApiToken(Auth = "1303", Name = "获取课程列表信息", RW = "R", Limit = false)]
|
|
|
- public async Task<IActionResult> GetCourseList(JsonElement json)
|
|
|
- {
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
- json.TryGetProperty("subjectId", out JsonElement subjectId);
|
|
|
- StringBuilder sql = new StringBuilder($"SELECT c.id,c.name,c.subject,c.period,c.scope,c.no,c.school FROM c where 1=1 ");
|
|
|
- if (!string.IsNullOrWhiteSpace($"{periodId}"))
|
|
|
- {
|
|
|
- sql.Append($" and c.period.id='{periodId}'");
|
|
|
- }
|
|
|
- if (!string.IsNullOrWhiteSpace($"{subjectId}"))
|
|
|
- {
|
|
|
- sql.Append($" and c.subject.id='{subjectId}'");
|
|
|
- }
|
|
|
- List<dynamic> courses = new List<dynamic>();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
|
|
|
- GetItemQueryIterator<dynamic>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
|
|
|
- {
|
|
|
- courses.Add(item);
|
|
|
- }
|
|
|
- return Ok(new { courses });
|
|
|
- }
|
|
|
-
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [HttpPost("get-course-info")]
|
|
|
- [ApiToken(Auth = "1304", Name = "课程详细信息", RW = "R", Limit = false)]
|
|
|
- public async Task<IActionResult> GetCourseInfo(JsonElement json)
|
|
|
- {
|
|
|
- var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- json.TryGetProperty("courseId", out JsonElement courseId);
|
|
|
- Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School")
|
|
|
- .ReadItemStreamAsync($"{courseId}", new PartitionKey($"Course-{school}"));
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- JsonDocument document = JsonDocument.Parse(response.Content);
|
|
|
- Course course = document.RootElement.Deserialize<Course>();
|
|
|
- return Ok(new { course.name, course.id, course.subject, course.period, course.scope, course.school, course.no, course.desc, course.schedule });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok(new { error = 1, msg = "课程不存在!" });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|