|
@@ -29,6 +29,7 @@ using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
using System.Security.Claims;
|
|
using System.Security.Claims;
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
|
+using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Both
|
|
namespace TEAMModelOS.Controllers.Both
|
|
{
|
|
{
|
|
@@ -41,13 +42,14 @@ namespace TEAMModelOS.Controllers.Both
|
|
{
|
|
{
|
|
private AzureCosmosFactory _azureCosmos;
|
|
private AzureCosmosFactory _azureCosmos;
|
|
private readonly DingDing _dingDing;
|
|
private readonly DingDing _dingDing;
|
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
private readonly Option _option;
|
|
private readonly Option _option;
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
private static List<string> weekDays = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
|
|
private static List<string> weekDays = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
|
|
public IConfiguration _configuration { get; set; }
|
|
public IConfiguration _configuration { get; set; }
|
|
- public CourseBaseController(AzureRedisFactory azureRedis, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
|
|
|
|
|
|
+ public CourseBaseController(AzureRedisFactory azureRedis, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
|
|
{
|
|
{
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
@@ -55,7 +57,7 @@ namespace TEAMModelOS.Controllers.Both
|
|
_serviceBus = serviceBus;
|
|
_serviceBus = serviceBus;
|
|
_configuration = configuration;
|
|
_configuration = configuration;
|
|
_azureStorage = azureStorage;
|
|
_azureStorage = azureStorage;
|
|
- _azureRedis = azureRedis;
|
|
|
|
|
|
+ _azureRedis = azureRedis; _coreAPIHttpService = coreAPIHttpService;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 更新保存课程
|
|
/// 更新保存课程
|
|
@@ -1676,76 +1678,95 @@ namespace TEAMModelOS.Controllers.Both
|
|
public async Task<IActionResult> Student(JsonElement request) {
|
|
public async Task<IActionResult> Student(JsonElement request) {
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- (string student, _, _, string school) = HttpContext.GetAuthTokenInfo();
|
|
|
|
|
|
+ (string userid, _, _, string school) = HttpContext.GetAuthTokenInfo();
|
|
if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
|
|
if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
|
|
string code = $"CourseTask-{school}";
|
|
string code = $"CourseTask-{school}";
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
- switch (true)
|
|
|
|
|
|
+ object scope = null;
|
|
|
|
+ HttpContext?.Items.TryGetValue("Scope", out scope);
|
|
|
|
+ int memberType = 2;
|
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeStudent))
|
|
{
|
|
{
|
|
- //任教学校课程和个人课程
|
|
|
|
- case bool when $"{grant_type}".Equals("teach", StringComparison.OrdinalIgnoreCase):
|
|
|
|
- string sql = $"SELECT distinct value c FROM c join b in c.schedules where c.pk='CourseTask' and b.teacherId in() ";
|
|
|
|
- List<KeyValuePair<string, CourseTask>> schoolTeacherTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
- List<KeyValuePair<string, CourseTask>> schoolAssistantTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
|
|
+ memberType = 2;
|
|
|
|
+ // Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>(userid, new PartitionKey($"Base-{school}"));
|
|
|
|
+ }
|
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTmdUser))
|
|
|
|
+ {
|
|
|
|
+ memberType = 1;
|
|
|
|
+ }
|
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTeacher))
|
|
|
|
+ {
|
|
|
|
+ memberType = 1;
|
|
|
|
+ }
|
|
|
|
+ List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, userid, memberType, school, new List<string> { "class", "teach" });
|
|
|
|
+ if (groups.IsNotEmpty()) {
|
|
|
|
+ switch (true)
|
|
|
|
+ {
|
|
|
|
+ //学生应参与的课程
|
|
|
|
+ case bool when $"{grant_type}".Equals("attend", StringComparison.OrdinalIgnoreCase):
|
|
|
|
+ string sql = $"SELECT distinct value c FROM c join b in c.schedules where c.pk='CourseTask' and b.groupId in() ";
|
|
|
|
+ List<KeyValuePair<string, CourseTask>> schoolTeacherTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
+ List<KeyValuePair<string, CourseTask>> schoolAssistantTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
|
|
- List<KeyValuePair<string, CourseTask>> privateTeacherTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
- List<KeyValuePair<string, CourseTask>> privateAssistantTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
- List<CourseDto> schoolCourses = new List<CourseDto>();
|
|
|
|
- List<CourseDto> teahcerCourses = new List<CourseDto>();
|
|
|
|
- if (!string.IsNullOrWhiteSpace(school))
|
|
|
|
- {
|
|
|
|
- School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
|
- JsonElement _year = default, _semesterId = default, _periodId = default;
|
|
|
|
- if (!request.TryGetProperty("periodId", out _periodId)) return BadRequest();
|
|
|
|
- if (!request.TryGetProperty("year", out _year))
|
|
|
|
- {
|
|
|
|
- return BadRequest();
|
|
|
|
- }
|
|
|
|
- if (!request.TryGetProperty("semesterId", out _semesterId))
|
|
|
|
- {
|
|
|
|
- return BadRequest();
|
|
|
|
- }
|
|
|
|
- var period = schoolBase.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
|
- //string date = SchoolService.GetOpensByStudyYearAndSemester(period.semesters, int.Parse($"{_year}"), $"{_semesterId}");
|
|
|
|
- sql = $"{sql} and c.year={_year} and c.semesterId='{_semesterId}'";
|
|
|
|
- HashSet<string> courseIds = new HashSet<string>();
|
|
|
|
- var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseTask>(sql, $"CourseTask-{school}");
|
|
|
|
- if (resultSchool.list.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- if (courseIds.Any())
|
|
|
|
|
|
+ List<KeyValuePair<string, CourseTask>> privateTeacherTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
+ List<KeyValuePair<string, CourseTask>> privateAssistantTask = new List<KeyValuePair<string, CourseTask>>();
|
|
|
|
+ List<CourseDto> schoolCourses = new List<CourseDto>();
|
|
|
|
+ List<CourseDto> teahcerCourses = new List<CourseDto>();
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(school))
|
|
{
|
|
{
|
|
- string sqlCourse = $"select value c from c where c.id in ({string.Join(",", courseIds.Select(b => $"'{b}'"))})";
|
|
|
|
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(sqlCourse, $"CourseBase-{school}");
|
|
|
|
- if (result.list.IsNotEmpty())
|
|
|
|
|
|
+ School schoolBase = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
|
+ JsonElement _year = default, _semesterId = default, _periodId = default;
|
|
|
|
+ if (!request.TryGetProperty("periodId", out _periodId)) return BadRequest();
|
|
|
|
+ if (!request.TryGetProperty("year", out _year))
|
|
{
|
|
{
|
|
- foreach (var item in result.list)
|
|
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ if (!request.TryGetProperty("semesterId", out _semesterId))
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ var period = schoolBase.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
|
+ //string date = SchoolService.GetOpensByStudyYearAndSemester(period.semesters, int.Parse($"{_year}"), $"{_semesterId}");
|
|
|
|
+ sql = $"{sql} and c.year={_year} and c.semesterId='{_semesterId}'";
|
|
|
|
+ HashSet<string> courseIds = new HashSet<string>();
|
|
|
|
+ var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseTask>(sql, $"CourseTask-{school}");
|
|
|
|
+ if (resultSchool.list.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (courseIds.Any())
|
|
|
|
+ {
|
|
|
|
+ string sqlCourse = $"select value c from c where c.id in ({string.Join(",", courseIds.Select(b => $"'{b}'"))})";
|
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(sqlCourse, $"CourseBase-{school}");
|
|
|
|
+ if (result.list.IsNotEmpty())
|
|
{
|
|
{
|
|
- List<CourseTaskDto> courseTaskDtos = new List<CourseTaskDto>();
|
|
|
|
- var teacher = schoolTeacherTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="teacher" });
|
|
|
|
- if (teacher.Any())
|
|
|
|
|
|
+ foreach (var item in result.list)
|
|
{
|
|
{
|
|
- courseTaskDtos.AddRange(teacher.ToList());
|
|
|
|
- }
|
|
|
|
- var assistant = schoolAssistantTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="assistant" });
|
|
|
|
- if (assistant.Any())
|
|
|
|
- {
|
|
|
|
- courseTaskDtos.AddRange(assistant.ToList());
|
|
|
|
|
|
+ List<CourseTaskDto> courseTaskDtos = new List<CourseTaskDto>();
|
|
|
|
+ var teacher = schoolTeacherTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="teacher" });
|
|
|
|
+ if (teacher.Any())
|
|
|
|
+ {
|
|
|
|
+ courseTaskDtos.AddRange(teacher.ToList());
|
|
|
|
+ }
|
|
|
|
+ var assistant = schoolAssistantTask.Where(x => x.Key.Equals(item.id)).Select(z => new CourseTaskDto { courseTask=z.Value, type="assistant" });
|
|
|
|
+ if (assistant.Any())
|
|
|
|
+ {
|
|
|
|
+ courseTaskDtos.AddRange(assistant.ToList());
|
|
|
|
+ }
|
|
|
|
+ schoolCourses.Add(new CourseDto { courseBase=item, courseTasks=courseTaskDtos });
|
|
}
|
|
}
|
|
- schoolCourses.Add(new CourseDto { courseBase=item, courseTasks=courseTaskDtos });
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseTask>(sql, $"CourseTask");
|
|
|
|
- if (resultTeacher.list.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- HashSet<string> courseIds = new HashSet<string>();
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return Ok(new { teahcerCourses, schoolCourses });
|
|
|
|
|
|
+ var resultTeacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseTask>(sql, $"CourseTask");
|
|
|
|
+ if (resultTeacher.list.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ HashSet<string> courseIds = new HashSet<string>();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { teahcerCourses, schoolCourses });
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|