|
@@ -63,7 +63,7 @@ namespace TEAMModelAPI.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-group-list")]
|
|
|
- [ApiToken(Auth = "109", Name = "学校教师列表", RW = "R", Limit = false)]
|
|
|
+ [ApiToken(Auth = "109", Name = "学校名单列表", RW = "R", Limit = false)]
|
|
|
public async Task<IActionResult> GetGroupList(JsonElement json)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -179,7 +179,7 @@ namespace TEAMModelAPI.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("import-class-members")]
|
|
|
- [ApiToken(Auth = "112", Name = "导入行政班学生", RW = "W", Limit = false)]
|
|
|
+ [ApiToken(Auth = "111", Name = "导入行政班学生", RW = "W", Limit = false)]
|
|
|
public async Task<IActionResult> ImportClassMembers(JsonElement json)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
@@ -192,10 +192,10 @@ namespace TEAMModelAPI.Controllers
|
|
|
if (period != null)
|
|
|
{
|
|
|
List<Student> webStudents = _students.ToObject<List<Student>>();
|
|
|
- List<Student> preStudents = await StudentService.GeStudentData(_azureCosmos, school, webStudents);
|
|
|
+ List<Student> preStudents = await StudentService.GeStudentData(_azureCosmos, school, webStudents?.Select(x=>x.id));
|
|
|
var retUpsert = await StudentService.upsertStudents(_azureCosmos, _dingDing, _option, school, json.GetProperty("students").EnumerateArray());
|
|
|
await StudentService.CheckStudent(_serviceBus, _configuration, _azureCosmos, school, webStudents, preStudents);
|
|
|
- return this.Ok(new { code = $"Base-{school}", students = retUpsert.studs, retUpsert.classDuplNos, retUpsert.errorIds });
|
|
|
+ return this.Ok(new { code = $"{school}", students = retUpsert.studs, retUpsert.classDuplNos, retUpsert.errorIds });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -205,6 +205,128 @@ namespace TEAMModelAPI.Controllers
|
|
|
else {
|
|
|
return Ok(new { error = 1, msg = "学生列表格式错误" });
|
|
|
}
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///更新學生資料,批量密碼重置,基本資訊更新(姓名、教室ID、性別、學年及座號)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("update-class-members")]
|
|
|
+ [ApiToken(Auth = "112", Name = "更新行政班学生", RW = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> UpdateClassMembers(JsonElement json)
|
|
|
+ {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ if (!json.TryGetProperty("periodId", out JsonElement _periodId)) { return Ok(new { error = 2, msg = "学段信息错误!" }); }
|
|
|
+ if (json.TryGetProperty("students", out JsonElement _students)) { return Ok(new { error = 1, msg = "学生列表格式错误!" }); }
|
|
|
+ if (_students.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ Period period = data.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
+ if (period != null)
|
|
|
+ {
|
|
|
+ //更新學生資料,批量密碼重置,基本資訊更新(姓名、教室ID、性別、學年及座號)
|
|
|
+ List<Student> webStudents = json.GetProperty("students").ToObject<List<Student>>();
|
|
|
+ List<Student> preStudents = await StudentService.GeStudentData(_azureCosmos, school, webStudents?.Select(x => x.id));
|
|
|
+ var retUpdate = await StudentService.updateStudents(_azureCosmos, _dingDing, _option, school, json.GetProperty("students").EnumerateArray());
|
|
|
+ await StudentService.CheckStudent(_serviceBus, _configuration, _azureCosmos, school, webStudents, preStudents);
|
|
|
+ return this.Ok(new { code = school, students = retUpdate.studs, retUpdate.classDuplNos, retUpdate.nonexistentIds, retUpdate.errorNos, retUpdate.errorClassId });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 2, msg = "学段信息错误!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 1, msg = "学生列表格式错误" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ////將學生基本資料內的classId、no、groupId及groupName寫入null
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("remove-class-members")]
|
|
|
+ [ApiToken(Auth = "113", Name = "移除行政班学生", RW = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> RemoveClassMembers(JsonElement json)
|
|
|
+ {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ if (!json.TryGetProperty("periodId", out JsonElement _periodId)) { return Ok(new { error = 2, msg = "学段信息错误!" }); }
|
|
|
+ if (json.TryGetProperty("students", out JsonElement _students)) { return Ok(new { error = 1, msg = "学生列表格式错误!" }); }
|
|
|
+ if (_students.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ Period period = data.period.Find(x => x.id.Equals($"{_periodId}"));
|
|
|
+ if (period != null)
|
|
|
+ {
|
|
|
+ //將學生基本資料內的classId、no、groupId及groupName寫入null
|
|
|
+ List<string> stus = json.GetProperty("students").ToObject<List<string>>();
|
|
|
+ List<Student> webStudents = new List<Student>();
|
|
|
+ foreach (string idstu in stus)
|
|
|
+ {
|
|
|
+ webStudents.Add(new Student { id = idstu, code = $"Base-{school}" });
|
|
|
+ }
|
|
|
+ List<Student> preStudents = await StudentService.GeStudentData(_azureCosmos, school, webStudents?.Select(x => x.id));
|
|
|
+ (List<string> studs, List<string> nonexistentIds, List<string> errorIds) retRemove = await StudentService.removeStudentClassInfo( _azureCosmos, _dingDing, _option,school, json.GetProperty("students").EnumerateArray());
|
|
|
+ await StudentService.CheckStudent(_serviceBus, _configuration, _azureCosmos, school, webStudents, preStudents);
|
|
|
+ return Ok(new { code = $"{school}", ids = retRemove.studs, retRemove.nonexistentIds, retRemove.errorIds });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 2, msg = "学段信息错误!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 1, msg = "学生列表格式错误" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 创建或更新教学班
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("upsert-teach-group")]
|
|
|
+ [ApiToken(Auth = "114", Name = "创建或更新教学班", RW = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> UpsertTeachGroup(JsonElement json) {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ if (!json.TryGetProperty("groupList", out JsonElement _groupList)) { return Ok(new { error=1,msg="名单对象不存在"}); }
|
|
|
+ var list= _groupList.ToObject<GroupListDto>();
|
|
|
+ if (list != null && list.Valid().isVaild) {
|
|
|
+ if (string.IsNullOrWhiteSpace(list.id))
|
|
|
+ {
|
|
|
+ GroupList 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,
|
|
|
+ from=3
|
|
|
+ };
|
|
|
+ groupList = await GroupListService.CheckListNo(groupList, _azureCosmos, _dingDing, _option);
|
|
|
+
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ var groupList = jsonDocument.RootElement.ToObject<GroupList>();
|
|
|
+ groupList.name=string.IsNullOrWhiteSpace(list.name)?groupList.name: list.name;
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return Ok();
|
|
|
}
|
|
|
|
|
@@ -215,14 +337,146 @@ namespace TEAMModelAPI.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("import-teach-members")]
|
|
|
- [ApiToken(Auth = "111", Name = "导入教学班学生", RW = "W", Limit = false)]
|
|
|
+ [ApiToken(Auth = "115", Name = "导入教学班学生", RW = "W", Limit = false)]
|
|
|
public async Task<IActionResult> ImportTeachMembers(JsonElement json)
|
|
|
{
|
|
|
- json.TryGetProperty("periodId", out JsonElement _periodId);
|
|
|
- json.TryGetProperty("students", out JsonElement _students);
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
- return Ok();
|
|
|
+ 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 = _members.ToObject<List<Member>>();
|
|
|
+ ValidResult valid = members.Valid();
|
|
|
+ if (valid.isVaild)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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())
|
|
|
+ {
|
|
|
+ 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 = $"名单类型不是教学班或者不是当前学校的名单!{list.type},{list.school}" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 2, msg = "名单错误!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = valid, msg = "名单列表格式错误!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 1, msg = "名单列表格式错误" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 导入教学班学生
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("remove-teach-members")]
|
|
|
+ [ApiToken(Auth = "116", Name = "移除教学班学生", RW = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> RemoveTeachMembers(JsonElement json) {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ json.TryGetProperty("stuids", out JsonElement _stuids);
|
|
|
+ json.TryGetProperty("tmdids", out JsonElement _tmdids);
|
|
|
+ if (json.TryGetProperty("groupId", out JsonElement _groupId)) { return Ok(new { error = 1, msg = "名单错误!" }); }
|
|
|
+ List<string> stuids = null;
|
|
|
+ if (_stuids.ValueKind.Equals(JsonValueKind.Array)) {
|
|
|
+ stuids = _stuids.ToObject<List<string>>();
|
|
|
+ }
|
|
|
+ List<string> tmdids = null;
|
|
|
+ if (_tmdids.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ tmdids = _tmdids.ToObject<List<string>>();
|
|
|
+ }
|
|
|
+ if (tmdids.Any() || stuids.Any())
|
|
|
+ {
|
|
|
+ // School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_groupId}", new PartitionKey($"GroupList-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument document= JsonDocument.Parse(response.Content);
|
|
|
+ var list= document.RootElement.Deserialize<GroupList>();
|
|
|
+ List<string> remove_tmdids = new List<string>();
|
|
|
+ if (tmdids.Any()) {
|
|
|
+ tmdids.ForEach(x => {
|
|
|
+ int len= list.members.RemoveAll(z => z.id.Equals(x) && z.type == 1);
|
|
|
+ if (len > 0) {
|
|
|
+ remove_tmdids.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<string> remove_stuids = new List<string>();
|
|
|
+ if (stuids.Any())
|
|
|
+ {
|
|
|
+ stuids.ForEach(x => {
|
|
|
+ int len = list.members.RemoveAll(z => z.id.Equals(x) && z.type == 2);
|
|
|
+ if (len > 0)
|
|
|
+ {
|
|
|
+ remove_stuids.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _configuration, _serviceBus);
|
|
|
+ return Ok(new { remove_stuids, remove_tmdids, list });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { error = 2, msg = "名单错误!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 2, msg = "移除的名单人员为空!" });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|