用户活跃度统计接口
This commit is contained in:
parent
1b94273c24
commit
893fe217a5
@ -39,11 +39,23 @@ namespace YD_WeChatApplet.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpGet("GetPersonalGoalInfo")]
|
[HttpGet("GetPersonalGoalInfo")]
|
||||||
public async Task<List<PersonalGoalInfoDto>> GetPersonalGoalInfo([FromQuery]PersonalGoalInfoReqDto req)
|
public async Task<PageDataDto<PersonalGoalInfoDto>> GetPersonalGoalInfo([FromQuery]PersonalGoalInfoReqDto req)
|
||||||
{
|
{
|
||||||
return await _serverService.GetPersonalGoalInfo(req);
|
return await _serverService.GetPersonalGoalInfo(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户训练记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="req"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("GetUserTrainingRecords")]
|
||||||
|
public async Task<PageDataDto<UserTrainingRecordsDto>> GetUserTrainingRecords([FromQuery]UserTrainingRecordsReqDto req)
|
||||||
|
{
|
||||||
|
return await _serverService.GetUserTrainingRecords(req);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源类型树
|
/// 获取资源类型树
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -139,5 +151,17 @@ namespace YD_WeChatApplet.Controllers
|
|||||||
{
|
{
|
||||||
return await _serverService.GetUserPageList(paramDto);
|
return await _serverService.GetUserPageList(paramDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取智慧体育用户管理页面数据(员工数据)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paramDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("GetSmartSportsUserPageList")]
|
||||||
|
public async Task<PageDataDto<SmartSportsUserDto>> GetSmartSportsUserPageList([FromQuery] SmartSportsUserParam paramDto)
|
||||||
|
{
|
||||||
|
return await _serverService.GetSmartSportsUserPageList(paramDto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ using System.Net;
|
|||||||
using YD_WeChatApplet.Api.SmartSportsEntitys;
|
using YD_WeChatApplet.Api.SmartSportsEntitys;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using YD_WeChatApplet.Commons.Dto.School;
|
using YD_WeChatApplet.Commons.Dto.School;
|
||||||
using VOL.Entity.DomainModels;
|
using VOL.Entity.DomainModels;
|
||||||
@ -41,22 +42,113 @@ namespace YD_WeChatApplet.Services
|
|||||||
/// 获取打卡详情
|
/// 获取打卡详情
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<PersonalGoalInfoDto>> GetPersonalGoalInfo(PersonalGoalInfoReqDto req)
|
public async Task<PageDataDto<PersonalGoalInfoDto>> GetPersonalGoalInfo(PersonalGoalInfoReqDto req)
|
||||||
{
|
{
|
||||||
var pgList = await (
|
var query = from pg in _userContext.PersonalGoal
|
||||||
from pg in _userContext.PersonalGoal
|
join pgr in _userContext.PersonalGoalResult on pg.Id equals pgr.PersonalGoalId
|
||||||
join pgr in _userContext.PersonalGoalResult on pg.Id equals pgr.PersonalGoalId
|
where pg.UserId == req.UserId
|
||||||
where pg.UserId == req.UserId && pg.GoalDate.Month == req.Month.Month && pg.GoalDate.Year == req.Month.Year
|
select new PersonalGoalInfoDto()
|
||||||
select new PersonalGoalInfoDto()
|
{
|
||||||
{
|
GoalDuration = pg.GoalDuration,
|
||||||
GoalDuration = pg.GoalDuration,
|
GoalAmount = pg.GoalAmount,
|
||||||
GoalAmount = pg.GoalAmount,
|
GoalDate = pg.GoalDate,
|
||||||
GoalDate = pg.GoalDate,
|
Amount = pgr.Amount,
|
||||||
Amount = pgr.Amount,
|
IsFinish = pg.GoalAmount > pgr.Amount
|
||||||
IsFinish = pg.GoalAmount > pgr.Amount
|
};
|
||||||
}).ToListAsync();
|
|
||||||
|
|
||||||
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<PersonalGoalInfoDto>
|
||||||
|
{
|
||||||
|
Total = total,
|
||||||
|
Datas = pgList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户训练记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="req"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<PageDataDto<UserTrainingRecordsDto>> 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<UserTrainingRecordsDto>
|
||||||
|
{
|
||||||
|
Total = total,
|
||||||
|
Datas = records
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -372,5 +464,56 @@ namespace YD_WeChatApplet.Services
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取智慧体育用户管理页面数据(员工数据)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paramDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<PageDataDto<SmartSportsUserDto>> GetSmartSportsUserPageList(SmartSportsUserParam paramDto)
|
||||||
|
{
|
||||||
|
var res = new PageDataDto<SmartSportsUserDto>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,14 @@ namespace YD_WeChatApplet.Services
|
|||||||
/// 获取打卡详情
|
/// 获取打卡详情
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<List<PersonalGoalInfoDto>> GetPersonalGoalInfo(PersonalGoalInfoReqDto req);
|
Task<PageDataDto<PersonalGoalInfoDto>> GetPersonalGoalInfo(PersonalGoalInfoReqDto req);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户训练记录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="req"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PageDataDto<UserTrainingRecordsDto>> GetUserTrainingRecords(UserTrainingRecordsReqDto req);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源类型树
|
/// 获取资源类型树
|
||||||
@ -73,5 +80,11 @@ namespace YD_WeChatApplet.Services
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PageDataDto<UserPageListDto>> GetUserPageList(UserPageListParam paramDto);
|
Task<PageDataDto<UserPageListDto>> GetUserPageList(UserPageListParam paramDto);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取智慧体育用户管理页面数据(员工数据)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paramDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PageDataDto<SmartSportsUserDto>> GetSmartSportsUserPageList(SmartSportsUserParam paramDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@ namespace YD_WeChatApplet.Commons
|
|||||||
{
|
{
|
||||||
public class PersonalGoalInfoReqDto
|
public class PersonalGoalInfoReqDto
|
||||||
{
|
{
|
||||||
|
public int PageIndex { get; set; } = 1;
|
||||||
|
public int PageSize { get; set; } = 31;
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
public DateTime Month { get; set; }
|
public string Month { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
100
YD_WeChatApplet.Commons/Dto/Server/SmartSportsUserDto.cs
Normal file
100
YD_WeChatApplet.Commons/Dto/Server/SmartSportsUserDto.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 智慧体育用户管理页面数据传输对象
|
||||||
|
/// </summary>
|
||||||
|
public class SmartSportsUserDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户ID
|
||||||
|
/// </summary>
|
||||||
|
public int User_Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户名
|
||||||
|
/// </summary>
|
||||||
|
public string UserName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户姓名
|
||||||
|
/// </summary>
|
||||||
|
public string UserTrueName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 头像
|
||||||
|
/// </summary>
|
||||||
|
public string HeadImageUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年级ID
|
||||||
|
/// </summary>
|
||||||
|
public int? GradeId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年级名称
|
||||||
|
/// </summary>
|
||||||
|
public string GradeName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 出生年月
|
||||||
|
/// </summary>
|
||||||
|
public string BirthDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 性别
|
||||||
|
/// </summary>
|
||||||
|
public int? Gender { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 地址
|
||||||
|
/// </summary>
|
||||||
|
public string Address { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 身高(字符串格式)
|
||||||
|
/// </summary>
|
||||||
|
public string Height { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 体重(字符串格式)
|
||||||
|
/// </summary>
|
||||||
|
public string Weight { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 拥有身份
|
||||||
|
/// </summary>
|
||||||
|
public string Role { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? CreateDate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 智慧体育用户管理页面查询参数
|
||||||
|
/// </summary>
|
||||||
|
public class SmartSportsUserParam : PageDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户姓名
|
||||||
|
/// </summary>
|
||||||
|
public string UserTrueName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年级ID
|
||||||
|
/// </summary>
|
||||||
|
public int? GradeId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 性别
|
||||||
|
/// </summary>
|
||||||
|
public int? Gender { get; set; }
|
||||||
|
}
|
||||||
|
}
|
51
YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsDto.cs
Normal file
51
YD_WeChatApplet.Commons/Dto/Server/UserTrainingRecordsDto.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 训练ID
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 训练类型
|
||||||
|
/// </summary>
|
||||||
|
public string TrainingType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 训练模式
|
||||||
|
/// </summary>
|
||||||
|
public string TrainingMode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 训练时长(分钟)
|
||||||
|
/// </summary>
|
||||||
|
public int Duration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳绳个数
|
||||||
|
/// </summary>
|
||||||
|
public int JumpCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消耗卡路里
|
||||||
|
/// </summary>
|
||||||
|
public decimal Kcal { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 训练时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime TrainingTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据来源
|
||||||
|
/// </summary>
|
||||||
|
public string DataSource { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user