diff --git a/WeChatApplet/Controllers/ServerController.cs b/WeChatApplet/Controllers/ServerController.cs index 82be656..7935846 100644 --- a/WeChatApplet/Controllers/ServerController.cs +++ b/WeChatApplet/Controllers/ServerController.cs @@ -39,11 +39,23 @@ namespace YD_WeChatApplet.Controllers /// [AllowAnonymous] [HttpGet("GetPersonalGoalInfo")] - public async Task> GetPersonalGoalInfo([FromQuery]PersonalGoalInfoReqDto req) + public async Task> GetPersonalGoalInfo([FromQuery]PersonalGoalInfoReqDto req) { return await _serverService.GetPersonalGoalInfo(req); } + /// + /// 获取用户训练记录 + /// + /// + /// + [AllowAnonymous] + [HttpGet("GetUserTrainingRecords")] + public async Task> GetUserTrainingRecords([FromQuery]UserTrainingRecordsReqDto req) + { + return await _serverService.GetUserTrainingRecords(req); + } + /// /// 获取资源类型树 /// @@ -139,5 +151,17 @@ namespace YD_WeChatApplet.Controllers { return await _serverService.GetUserPageList(paramDto); } + + /// + /// 获取智慧体育用户管理页面数据(员工数据) + /// + /// + /// + [AllowAnonymous] + [HttpGet("GetSmartSportsUserPageList")] + public async Task> GetSmartSportsUserPageList([FromQuery] SmartSportsUserParam paramDto) + { + return await _serverService.GetSmartSportsUserPageList(paramDto); + } } } \ No newline at end of file diff --git a/WeChatApplet/Services/Impl/ServerService.cs b/WeChatApplet/Services/Impl/ServerService.cs index f1e4169..d9f4b92 100644 --- a/WeChatApplet/Services/Impl/ServerService.cs +++ b/WeChatApplet/Services/Impl/ServerService.cs @@ -18,6 +18,7 @@ using System.Net; using YD_WeChatApplet.Api.SmartSportsEntitys; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Authorization; +using System.Linq; using System.Text.Json; using YD_WeChatApplet.Commons.Dto.School; using VOL.Entity.DomainModels; @@ -41,22 +42,113 @@ namespace YD_WeChatApplet.Services /// 获取打卡详情 /// /// - public async Task> GetPersonalGoalInfo(PersonalGoalInfoReqDto req) + public async Task> GetPersonalGoalInfo(PersonalGoalInfoReqDto req) { - var pgList = await ( - from pg in _userContext.PersonalGoal - join pgr in _userContext.PersonalGoalResult on pg.Id equals pgr.PersonalGoalId - where pg.UserId == req.UserId && pg.GoalDate.Month == req.Month.Month && pg.GoalDate.Year == req.Month.Year - select new PersonalGoalInfoDto() - { - GoalDuration = pg.GoalDuration, - GoalAmount = pg.GoalAmount, - GoalDate = pg.GoalDate, - Amount = pgr.Amount, - IsFinish = pg.GoalAmount > pgr.Amount - }).ToListAsync(); + var query = from pg in _userContext.PersonalGoal + join pgr in _userContext.PersonalGoalResult on pg.Id equals pgr.PersonalGoalId + where pg.UserId == req.UserId + select new PersonalGoalInfoDto() + { + GoalDuration = pg.GoalDuration, + GoalAmount = pg.GoalAmount, + GoalDate = pg.GoalDate, + Amount = pgr.Amount, + IsFinish = pg.GoalAmount > pgr.Amount + }; - return pgList; + // 如果提供了月份筛选 + if (!string.IsNullOrEmpty(req.Month) && DateTime.TryParse(req.Month, out DateTime monthDate)) + { + query = query.Where(x => x.GoalDate.Month == monthDate.Month && x.GoalDate.Year == monthDate.Year); + } + + var total = await query.CountAsync(); + var pgList = await query + .OrderByDescending(x => x.GoalDate) + .Skip((req.PageIndex - 1) * req.PageSize) + .Take(req.PageSize) + .ToListAsync(); + + return new PageDataDto + { + Total = total, + Datas = pgList + }; + } + + /// + /// 获取用户训练记录 + /// + /// + /// + public async Task> GetUserTrainingRecords(UserTrainingRecordsReqDto req) + { + // 查询个人目标结果表 + var personalQuery = from pgr in _userContext.PersonalGoalResult + where pgr.UserId == req.UserId + select new UserTrainingRecordsDto + { + Id = pgr.Id, + TrainingType = pgr.PersonalGoalType.ToString(), + TrainingMode = pgr.WorkModeTypeName, + Duration = pgr.Duration, + JumpCount = pgr.Amount, + Kcal = pgr.Amount / 10m, // 简单的卡路里计算 + TrainingTime = pgr.CreateTime, + DataSource = "个人训练" + }; + + // 查询团队任务结果表 + var teamQuery = from gtr in _userContext.GroupTaskResult + where gtr.UserId == req.UserId + select new UserTrainingRecordsDto + { + Id = gtr.Id, + TrainingType = "团队训练", + TrainingMode = gtr.WorkModeTypeName, + Duration = gtr.Duration, + JumpCount = gtr.Amount, + Kcal = gtr.Amount / 10m, // 简单的卡路里计算 + TrainingTime = gtr.CreateTime, + DataSource = "团队训练" + }; + + // 合并查询结果 + var combinedQuery = personalQuery.Union(teamQuery); + + // 应用筛选条件 + if (!string.IsNullOrEmpty(req.Type)) + { + combinedQuery = combinedQuery.Where(x => x.TrainingType.Contains(req.Type)); + } + + if (!string.IsNullOrEmpty(req.Mode)) + { + combinedQuery = combinedQuery.Where(x => x.TrainingMode.Contains(req.Mode)); + } + + if (!string.IsNullOrEmpty(req.StartTime) && DateTime.TryParse(req.StartTime, out DateTime startTime)) + { + combinedQuery = combinedQuery.Where(x => x.TrainingTime >= startTime); + } + + if (!string.IsNullOrEmpty(req.EndTime) && DateTime.TryParse(req.EndTime, out DateTime endTime)) + { + combinedQuery = combinedQuery.Where(x => x.TrainingTime <= endTime); + } + + var total = await combinedQuery.CountAsync(); + var records = await combinedQuery + .OrderByDescending(x => x.TrainingTime) + .Skip((req.PageIndex - 1) * req.PageSize) + .Take(req.PageSize) + .ToListAsync(); + + return new PageDataDto + { + Total = total, + Datas = records + }; } /// @@ -372,5 +464,56 @@ namespace YD_WeChatApplet.Services return res; } + + /// + /// 获取智慧体育用户管理页面数据(员工数据) + /// + /// + /// + public async Task> GetSmartSportsUserPageList(SmartSportsUserParam paramDto) + { + var res = new PageDataDto(); + + var query = _userContext.Users.Select(x => new SmartSportsUserDto + { + User_Id = x.User_Id, + UserName = x.UserName ?? "", + UserTrueName = x.UserTrueName ?? "", + HeadImageUrl = x.HeadImageUrl ?? "", + BirthDate = x.BirthDate ?? "", + Gender = x.Gender, + Address = x.Address ?? "", + Height = x.Height.HasValue ? x.Height.Value.ToString() : "", + Weight = x.Weight.HasValue ? x.Weight.Value.ToString() : "", + Role = "员工", // 微信小程序用户统一标记为员工 + CreateDate = x.CreateDate, + GradeId = null, // 员工数据没有年级概念 + GradeName = "" // 员工数据没有年级概念 + }); + + // 按姓名筛选 + if (!string.IsNullOrEmpty(paramDto.UserTrueName)) + { + query = query.Where(x => x.UserTrueName.Contains(paramDto.UserTrueName)); + } + + // 按性别筛选 + if (paramDto.Gender.HasValue) + { + query = query.Where(x => x.Gender == paramDto.Gender); + } + + // 注意:员工数据没有年级概念,所以忽略 GradeId 筛选 + + res.Total = await query.CountAsync(); + + var list = await query.OrderByDescending(x => x.CreateDate) + .Skip((paramDto.PageIndex - 1) * paramDto.PageSize) + .Take(paramDto.PageSize) + .ToListAsync(); + res.Datas = list; + + return res; + } } } diff --git a/WeChatApplet/Services/Interface/IServerService.cs b/WeChatApplet/Services/Interface/IServerService.cs index 58f2de8..f79de8d 100644 --- a/WeChatApplet/Services/Interface/IServerService.cs +++ b/WeChatApplet/Services/Interface/IServerService.cs @@ -15,7 +15,14 @@ namespace YD_WeChatApplet.Services /// 获取打卡详情 /// /// - Task> GetPersonalGoalInfo(PersonalGoalInfoReqDto req); + Task> GetPersonalGoalInfo(PersonalGoalInfoReqDto req); + + /// + /// 获取用户训练记录 + /// + /// + /// + Task> GetUserTrainingRecords(UserTrainingRecordsReqDto req); /// /// 获取资源类型树 @@ -73,5 +80,11 @@ namespace YD_WeChatApplet.Services /// Task> GetUserPageList(UserPageListParam paramDto); + /// + /// 获取智慧体育用户管理页面数据(员工数据) + /// + /// + /// + Task> GetSmartSportsUserPageList(SmartSportsUserParam paramDto); } } diff --git a/YD_WeChatApplet.Commons/Dto/Server/PersonalGoalInfoReqDto.cs b/YD_WeChatApplet.Commons/Dto/Server/PersonalGoalInfoReqDto.cs index 33a287b..e6c2e99 100644 --- a/YD_WeChatApplet.Commons/Dto/Server/PersonalGoalInfoReqDto.cs +++ b/YD_WeChatApplet.Commons/Dto/Server/PersonalGoalInfoReqDto.cs @@ -8,7 +8,9 @@ namespace YD_WeChatApplet.Commons { public class PersonalGoalInfoReqDto { + public int PageIndex { get; set; } = 1; + public int PageSize { get; set; } = 31; public int UserId { get; set; } - public DateTime Month { get; set; } + public string Month { get; set; } } } diff --git a/YD_WeChatApplet.Commons/Dto/Server/SmartSportsUserDto.cs b/YD_WeChatApplet.Commons/Dto/Server/SmartSportsUserDto.cs new file mode 100644 index 0000000..21f5f1f --- /dev/null +++ b/YD_WeChatApplet.Commons/Dto/Server/SmartSportsUserDto.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YD_WeChatApplet.Commons.Dto.Server +{ + /// + /// 智慧体育用户管理页面数据传输对象 + /// + public class SmartSportsUserDto + { + /// + /// 用户ID + /// + public int User_Id { get; set; } + + /// + /// 用户名 + /// + public string UserName { get; set; } + + /// + /// 用户姓名 + /// + public string UserTrueName { get; set; } + + /// + /// 头像 + /// + public string HeadImageUrl { get; set; } + + /// + /// 年级ID + /// + public int? GradeId { get; set; } + + /// + /// 年级名称 + /// + public string GradeName { get; set; } + + /// + /// 出生年月 + /// + public string BirthDate { get; set; } + + /// + /// 性别 + /// + public int? Gender { get; set; } + + /// + /// 地址 + /// + public string Address { get; set; } + + /// + /// 身高(字符串格式) + /// + public string Height { get; set; } + + /// + /// 体重(字符串格式) + /// + public string Weight { get; set; } + + /// + /// 拥有身份 + /// + public string Role { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateDate { get; set; } + } + + /// + /// 智慧体育用户管理页面查询参数 + /// + public class SmartSportsUserParam : PageDto + { + /// + /// 用户姓名 + /// + public string UserTrueName { get; set; } + + /// + /// 年级ID + /// + public int? GradeId { get; set; } + + /// + /// 性别 + /// + public int? Gender { get; set; } + } +} diff --git a/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsDto.cs b/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsDto.cs new file mode 100644 index 0000000..1a69688 --- /dev/null +++ b/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsDto.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YD_WeChatApplet.Commons +{ + public class UserTrainingRecordsDto + { + /// + /// 训练ID + /// + public int Id { get; set; } + + /// + /// 训练类型 + /// + public string TrainingType { get; set; } + + /// + /// 训练模式 + /// + public string TrainingMode { get; set; } + + /// + /// 训练时长(分钟) + /// + public int Duration { get; set; } + + /// + /// 跳绳个数 + /// + public int JumpCount { get; set; } + + /// + /// 消耗卡路里 + /// + public decimal Kcal { get; set; } + + /// + /// 训练时间 + /// + public DateTime TrainingTime { get; set; } + + /// + /// 数据来源 + /// + public string DataSource { get; set; } + } +} diff --git a/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsReqDto.cs b/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsReqDto.cs new file mode 100644 index 0000000..005cd83 --- /dev/null +++ b/YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsReqDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YD_WeChatApplet.Commons +{ + public class UserTrainingRecordsReqDto + { + public int PageIndex { get; set; } = 1; + public int PageSize { get; set; } = 10; + public int UserId { get; set; } + public string Type { get; set; } + public string Mode { get; set; } + public string StartTime { get; set; } + public string EndTime { get; set; } + } +}