|
@@ -289,25 +289,53 @@ namespace TEAMModelAPI.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert-teach-groups")]
|
|
|
[ApiToken(Auth = "1206", Name = "创建或更新教学班", RW = "W", Limit = false)]
|
|
|
- public async Task<IActionResult> UpsertTeachGroups(JsonElement json) {
|
|
|
+ public async Task<IActionResult> UpsertTeachGroups(GroupListDtoImpt json) {
|
|
|
var (_, school) = HttpContext.GetApiTokenInfo();
|
|
|
- if (!json.TryGetProperty("groupLists", out JsonElement _groupLists) || !_groupLists.ValueKind.Equals(JsonValueKind.Array)) { return Ok(new { error=1,msg="名单对象不存在"}); }
|
|
|
- var groupListsDto = _groupLists.ToObject<List<GroupListDto>>();
|
|
|
+ var groupListsDto = json.groupLists;
|
|
|
List<GroupList> groupLists = new List<GroupList>(); ;
|
|
|
List<Dictionary<string, string>> errorData = new List<Dictionary<string, string>>();
|
|
|
- if (groupListsDto != null && groupListsDto.Valid().isVaild)
|
|
|
- {
|
|
|
- School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
- foreach (var list in groupListsDto) {
|
|
|
- Period period = data.period.Find(x => x.id.Equals($"{list.periodId}"));
|
|
|
- if (period != null)
|
|
|
+ School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ foreach (var list in groupListsDto) {
|
|
|
+ Period period = data.period.Find(x => x.id.Equals($"{list.periodId}"));
|
|
|
+ if (period != null)
|
|
|
+ {
|
|
|
+ GroupList groupList = null;
|
|
|
+ if (string.IsNullOrWhiteSpace(list.id))
|
|
|
{
|
|
|
- GroupList groupList = null;
|
|
|
- if (string.IsNullOrWhiteSpace(list.id))
|
|
|
+ groupList = new GroupList()
|
|
|
+ {
|
|
|
+ pk = "GroupList",
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = $"GroupList-{school}",
|
|
|
+ name = list.name,
|
|
|
+ periodId = list.periodId,
|
|
|
+ scope = "school",
|
|
|
+ school = school,
|
|
|
+ type = "teach",
|
|
|
+ year = list.year,
|
|
|
+ froms = 3
|
|
|
+ };
|
|
|
+ groupList = await GroupListService.CheckListNo(groupList, _azureCosmos, _dingDing, _option);
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(groupList, new PartitionKey(groupList.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{list.id}", new PartitionKey($"GroupList-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
+ groupList = jsonDocument.RootElement.ToObject<GroupList>();
|
|
|
+ groupList.name = string.IsNullOrWhiteSpace(list.name) ? groupList.name : list.name;
|
|
|
+ groupList.periodId = string.IsNullOrWhiteSpace(list.periodId) ? groupList.periodId : list.periodId;
|
|
|
+ groupList.school = school;
|
|
|
+ groupList.scope = "school";
|
|
|
+ groupList.froms = 3;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(groupList, groupList.id, new PartitionKey(groupList.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
groupList = new GroupList()
|
|
|
{
|
|
|
- pk = "GroupList",
|
|
|
id = Guid.NewGuid().ToString(),
|
|
|
code = $"GroupList-{school}",
|
|
|
name = list.name,
|
|
@@ -321,56 +349,26 @@ namespace TEAMModelAPI.Controllers
|
|
|
groupList = await GroupListService.CheckListNo(groupList, _azureCosmos, _dingDing, _option);
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(groupList, new PartitionKey(groupList.code));
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{list.id}", new PartitionKey($"GroupList-{school}"));
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
- groupList = jsonDocument.RootElement.ToObject<GroupList>();
|
|
|
- groupList.name = string.IsNullOrWhiteSpace(list.name) ? groupList.name : list.name;
|
|
|
- groupList.periodId = string.IsNullOrWhiteSpace(list.periodId) ? groupList.periodId : list.periodId;
|
|
|
- groupList.school = school;
|
|
|
- groupList.scope = "school";
|
|
|
- groupList.froms = 3;
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(groupList, groupList.id, new PartitionKey(groupList.code));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- groupList = new GroupList()
|
|
|
- {
|
|
|
- id = Guid.NewGuid().ToString(),
|
|
|
- code = $"GroupList-{school}",
|
|
|
- name = list.name,
|
|
|
- periodId = list.periodId,
|
|
|
- scope = "school",
|
|
|
- school = school,
|
|
|
- type = "teach",
|
|
|
- year = list.year,
|
|
|
- froms = 3
|
|
|
- };
|
|
|
- groupList = await GroupListService.CheckListNo(groupList, _azureCosmos, _dingDing, _option);
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(groupList, new PartitionKey(groupList.code));
|
|
|
- }
|
|
|
- }
|
|
|
- if (groupList != null) {
|
|
|
- groupLists.Add(groupList);
|
|
|
- }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- errorData.Add(new Dictionary<string, string> { { "group",list.name}, { "periodId",list.periodId} });
|
|
|
- // return Ok(new { error = 2, msg ="学段不存在!" });
|
|
|
+ if (groupList != null) {
|
|
|
+ groupLists.Add(groupList);
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorData.Add(new Dictionary<string, string> { { "group",list.name}, { "periodId",list.periodId} });
|
|
|
+ // return Ok(new { error = 2, msg ="学段不存在!" });
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok(new { error = 3, msg = groupListsDto.Valid() });
|
|
|
- }
|
|
|
+
|
|
|
return Ok(new { groupLists, errorData });
|
|
|
}
|
|
|
|
|
|
+ public class MemberImpt {
|
|
|
+ public List<Member> members { get; set; } = new List<Member>();
|
|
|
+ public string groupId { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 导入教学班学生
|
|
|
/// </summary>
|
|
@@ -379,81 +377,64 @@ namespace TEAMModelAPI.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("import-teach-members")]
|
|
|
[ApiToken(Auth = "1207", Name = "导入教学班学生", RW = "W", Limit = false)]
|
|
|
- public async Task<IActionResult> ImportTeachMembers(JsonElement json)
|
|
|
+ public async Task<IActionResult> ImportTeachMembers(MemberImpt json)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- if (!json.TryGetProperty("groupId", out JsonElement _groupId)) { return Ok(new { error = 2, msg = "名单错误!" }); }
|
|
|
- if(!json.TryGetProperty("members", out JsonElement _members)) return Ok(new { error = 1, msg = "名单列表格式错误" });
|
|
|
- if (_members.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ //School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ List<Member> members = json.members;
|
|
|
+ var tmds = members.Where(x => x.type == 1);
|
|
|
+ var stus = members.Where(x => x.type == 2);
|
|
|
+ List<Student> students = await StudentService.GeStudentData(_azureCosmos, school, stus?.Select(x => x.id));
|
|
|
+ List<TmdInfo> infos = null;
|
|
|
+ string tmdstr = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var content = new StringContent(tmds.Select(x => x.id).ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ tmdstr = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ infos = tmdstr.ToObject<List<TmdInfo>>();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- //School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
- List<Member> members = _members.ToObject<List<Member>>();
|
|
|
- ValidResult valid = members.Valid();
|
|
|
- if (valid.isVaild)
|
|
|
+ await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.Get("Default").location}用户转换失败:{_coreAPIHttpService.options.Get("Default").url}{tmdstr}\n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ //return Ok(new { error =3, msg = "醍摩豆ID验证错误!" });
|
|
|
+ }
|
|
|
+ var unexist_student = stus.Select(x => x.id).Except(students.Select(y => y.id));
|
|
|
+ var unexist_tmdids = tmds.Select(x => x.id).Except(infos.Select(y => y.id));
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{json.groupId}", new PartitionKey($"GroupList-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
+ var list = jsonDocument.RootElement.ToObject<GroupList>();
|
|
|
+ if (list.type.Equals("teach") && list.school.Equals(school))
|
|
|
{
|
|
|
- var tmds = members.Where(x => x.type == 1);
|
|
|
- var stus = members.Where(x => x.type == 2);
|
|
|
- List<Student> students = await StudentService.GeStudentData(_azureCosmos, school, stus?.Select(x => x.id));
|
|
|
- List<TmdInfo> infos = null;
|
|
|
- string tmdstr = "";
|
|
|
- try
|
|
|
- {
|
|
|
- var content = new StringContent(tmds.Select(x => x.id).ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
- tmdstr = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
- infos = tmdstr.ToObject<List<TmdInfo>>();
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.Get("Default").location}用户转换失败:{_coreAPIHttpService.options.Get("Default").url}{tmdstr}\n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
- //return Ok(new { error =3, msg = "醍摩豆ID验证错误!" });
|
|
|
- }
|
|
|
- var unexist_student = stus.Select(x => x.id).Except(students.Select(y => y.id));
|
|
|
- var unexist_tmdids = tmds.Select(x => x.id).Except(infos.Select(y => y.id));
|
|
|
- Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_groupId}", new PartitionKey($"GroupList-{school}"));
|
|
|
- if (response.Status == 200)
|
|
|
+ if (infos.Any())
|
|
|
{
|
|
|
- JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
- var list = jsonDocument.RootElement.ToObject<GroupList>();
|
|
|
- if (list.type.Equals("teach") && list.school.Equals(school))
|
|
|
- {
|
|
|
- if (infos.Any())
|
|
|
- {
|
|
|
- infos.ToList().ForEach(x => {
|
|
|
- if (!list.members.Where(z => z.type == 1).Select(x => x.id).Contains(x.id))
|
|
|
- {
|
|
|
- GroupListService.JoinList(list, x.id , 1 , school);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- if (stus.Any())
|
|
|
+ infos.ToList().ForEach(x => {
|
|
|
+ if (!list.members.Where(z => z.type == 1).Select(x => x.id).Contains(x.id))
|
|
|
{
|
|
|
- stus.ToList().ForEach(x => {
|
|
|
- if (!list.members.Where(z => z.type == 2).Select(x => x.id).Contains(x.id)) {
|
|
|
- GroupListService.JoinList(list, x.id ,2 , school);
|
|
|
- }
|
|
|
- });
|
|
|
+ GroupListService.JoinList(list, x.id , 1 , school);
|
|
|
}
|
|
|
- list = await GroupListService.CheckListNo(list, _azureCosmos, _dingDing, _option);
|
|
|
- list = await GroupListService.UpsertList(list, _azureCosmos, _configuration, _serviceBus);
|
|
|
- return Ok(new { unexist_student, unexist_tmdids, import_list=list });
|
|
|
- }
|
|
|
- else {
|
|
|
- return Ok(new { error = 3, msg = $"名单类型不是教学班或者不是当前学校的名单!{list.type},{list.school}" });
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
- else
|
|
|
+ if (stus.Any())
|
|
|
{
|
|
|
- return Ok(new { error = 2, msg = "名单错误!" });
|
|
|
+ stus.ToList().ForEach(x => {
|
|
|
+ if (!list.members.Where(z => z.type == 2).Select(x => x.id).Contains(x.id)) {
|
|
|
+ GroupListService.JoinList(list, x.id ,2 , school);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ list = await GroupListService.CheckListNo(list, _azureCosmos, _dingDing, _option);
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _configuration, _serviceBus);
|
|
|
+ return Ok(new { unexist_student, unexist_tmdids, import_list=list });
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok(new { error = 3, msg = valid });
|
|
|
+ else {
|
|
|
+ return Ok(new { error = 3, msg = $"名单类型不是教学班或者不是当前学校的名单!{list.type},{list.school}" });
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return Ok(new { error = 1, msg = "名单列表格式错误" });
|
|
|
+ return Ok(new { error = 2, msg = "名单错误!" });
|
|
|
}
|
|
|
}
|
|
|
|