From 1e9fe3fb091aea7535c987b357cc84bcdcdb38dc Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Fri, 13 Jun 2025 13:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WeChatApplet/Controllers/UserController.cs | 4 +- WeChatApplet/Services/Impl/TeacherService.cs | 90 ++++++++++++-------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/WeChatApplet/Controllers/UserController.cs b/WeChatApplet/Controllers/UserController.cs index 30e9d0b..683c936 100644 --- a/WeChatApplet/Controllers/UserController.cs +++ b/WeChatApplet/Controllers/UserController.cs @@ -91,10 +91,10 @@ namespace YD_WeChatApplet.Controllers /// [HttpPost("RemoveUniqueIdentity")] [AllowAnonymous] - public async Task RemoveUniqueIdentity(string userId) + public async Task RemoveUniqueIdentity(string userId) { await _userService.RemoveUniqueIdentity(userId); - return Ok("Ƴɹ"); + return true; } /// diff --git a/WeChatApplet/Services/Impl/TeacherService.cs b/WeChatApplet/Services/Impl/TeacherService.cs index b19a1b4..8b6bce5 100644 --- a/WeChatApplet/Services/Impl/TeacherService.cs +++ b/WeChatApplet/Services/Impl/TeacherService.cs @@ -326,58 +326,76 @@ namespace YD_WeChatApplet.Services { var res = new PageDataDto(); - if (string.IsNullOrWhiteSpace(dto.StudentNo)) + IQueryable query; + + // 如果传了学生学号,按学号查 + if (!string.IsNullOrWhiteSpace(dto.StudentNo)) { - var phoneNo = UserLoginContext.Current.PhoneNo; - - var teacherId = await _sportsContext.Teacher.Where(x => x.TeacherPhoneNo == phoneNo).Select(x => x.Id).FirstOrDefaultAsync(); - var query = from td in _sportsContext.Ai_ClassRoomRecord - where td.TeacherId == teacherId - select new ClassRoomRecordPageDto() - { - Id = td.Id, - ClassId = td.ClassId, - Name = td.Name, - StartingEndingTime = $"{(td.StartTime.HasValue ? td.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : string.Empty)}{(td.EndTime.HasValue ? " - " + td.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : string.Empty)}" - }; - - res.Total = await query.CountAsync(); - - var list = await query - .OrderByDescending(c => c.Id) - .Skip((dto.PageIndex - 1) * dto.PageSize) - .Take(dto.PageSize) - .ToListAsync(); - - res.Datas = list; + query = from s in _sportsContext.Ai_ClassroomStudentRecord + join c in _sportsContext.Ai_ClassRoomRecord on s.ClassRoomRecordId equals c.Id + where s.StudentNo == dto.StudentNo + select new ClassRoomRecordPageDto + { + Id = c.Id, + ClassId = c.ClassId, + Name = c.Name, + StartingEndingTime = (c.StartTime.HasValue ? c.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : "") + + (c.EndTime.HasValue ? " - " + c.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : "") + }; } else { - var query = from s in _sportsContext.Ai_ClassroomStudentRecord + var roleId = UserLoginContext.Current.RoleId; + + if (roleId == 3 || roleId == 5) // 学生 + { + var studentNo = UserLoginContext.Current.UserNo; + + query = from s in _sportsContext.Ai_ClassroomStudentRecord join c in _sportsContext.Ai_ClassRoomRecord on s.ClassRoomRecordId equals c.Id - where s.StudentNo == dto.StudentNo - select new ClassRoomRecordPageDto() + where s.StudentNo == studentNo + select new ClassRoomRecordPageDto { Id = c.Id, ClassId = c.ClassId, Name = c.Name, - StartingEndingTime = $"{(c.StartTime.HasValue ? c.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : string.Empty)}{(c.EndTime.HasValue ? " - " + c.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : string.Empty)}" + StartingEndingTime = (c.StartTime.HasValue ? c.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : "") + + (c.EndTime.HasValue ? " - " + c.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : "") }; + } + else // 教师 + { + var phoneNo = UserLoginContext.Current.PhoneNo; + var teacherId = await _sportsContext.Teacher + .Where(x => x.TeacherPhoneNo == phoneNo) + .Select(x => x.Id) + .FirstOrDefaultAsync(); - res.Total = await query.CountAsync(); - - var list = await query - .OrderByDescending(c => c.Id) - .Skip((dto.PageIndex - 1) * dto.PageSize) - .Take(dto.PageSize) - .ToListAsync(); - - res.Datas = list; + query = _sportsContext.Ai_ClassRoomRecord + .Where(x => x.TeacherId == teacherId) + .Select(c => new ClassRoomRecordPageDto + { + Id = c.Id, + ClassId = c.ClassId, + Name = c.Name, + StartingEndingTime = (c.StartTime.HasValue ? c.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : "") + + (c.EndTime.HasValue ? " - " + c.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : "") + }); + } } + res.Total = await query.CountAsync(); + res.Datas = await query + .OrderByDescending(x => x.Id) + .Skip((dto.PageIndex - 1) * dto.PageSize) + .Take(dto.PageSize) + .AsNoTracking() + .ToListAsync(); + return res; } + /// /// 课堂详情 ///