人员管理
This commit is contained in:
parent
b0a8156739
commit
3d641112fd
@ -124,7 +124,24 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
||||
}
|
||||
|
||||
var list = await query.ToPagedListAsync(input);
|
||||
return list.Adapt<PageResult<MemberOutput>>();
|
||||
var result = list.Adapt<PageResult<MemberOutput>>();
|
||||
|
||||
// 设置Age字段:优先使用数据库中的Age,如果没有则根据BirthDate计算
|
||||
foreach (var item in result.Rows)
|
||||
{
|
||||
if (item.Age.HasValue)
|
||||
{
|
||||
// 数据库中已有Age,直接使用
|
||||
continue;
|
||||
}
|
||||
// 数据库中没有Age,根据BirthDate动态计算
|
||||
if (item.BirthDate.HasValue)
|
||||
{
|
||||
item.Age = MemberOutput.CalculateAgeFromBirthDate(item.BirthDate);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -224,9 +241,12 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
||||
entity.Remark = input.Remark;
|
||||
entity.AuditRemark = "";
|
||||
|
||||
// 仅保存出生日期,年龄在输出时动态计算
|
||||
// 保存出生日期
|
||||
entity.BirthDate = input.BirthDate;
|
||||
|
||||
// 保存年龄字段:如果用户填写了年龄,直接保存;如果没有填写但有出生日期,可以在查询时动态计算
|
||||
entity.Age = input.Age;
|
||||
|
||||
if (input.PersonType == PersonType.Coach)
|
||||
{
|
||||
entity.SkillLevel = input.SkillLevel;
|
||||
|
||||
@ -108,18 +108,21 @@ public class MemberOutput : AppUserOutput
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 年龄(动态计算)
|
||||
/// 年龄
|
||||
/// 优先使用数据库存储的Age字段,如果不存在则根据BirthDate动态计算
|
||||
/// </summary>
|
||||
public int? Age
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!BirthDate.HasValue) return null;
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - BirthDate.Value.Year;
|
||||
if (BirthDate.Value.Date > today.AddYears(-age)) age--;
|
||||
return age;
|
||||
}
|
||||
public int? Age { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根据出生日期计算年龄的辅助方法
|
||||
/// </summary>
|
||||
public static int? CalculateAgeFromBirthDate(DateTime? birthDate)
|
||||
{
|
||||
if (!birthDate.HasValue) return null;
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - birthDate.Value.Year;
|
||||
if (birthDate.Value.Date > today.AddYears(-age)) age--;
|
||||
return age;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -184,6 +187,11 @@ public class CreateOrUpdateMemberInput
|
||||
/// </summary>
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 年龄
|
||||
/// </summary>
|
||||
public int? Age { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 联系电话
|
||||
/// </summary>
|
||||
|
||||
@ -209,7 +209,13 @@
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.AppUser.Dtos.MemberOutput.Age">
|
||||
<summary>
|
||||
年龄(动态计算)
|
||||
年龄
|
||||
优先使用数据库存储的Age字段,如果不存在则根据BirthDate动态计算
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:YD_Event.Application.AppUser.Dtos.MemberOutput.CalculateAgeFromBirthDate(System.Nullable{System.DateTime})">
|
||||
<summary>
|
||||
根据出生日期计算年龄的辅助方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.AppUser.Dtos.MemberOutput.SkillLevel">
|
||||
@ -267,6 +273,11 @@
|
||||
出生日期 (运动员等)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.AppUser.Dtos.CreateOrUpdateMemberInput.Age">
|
||||
<summary>
|
||||
年龄
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.AppUser.Dtos.CreateOrUpdateMemberInput.Mobile">
|
||||
<summary>
|
||||
联系电话
|
||||
|
||||
@ -60,6 +60,12 @@ public class AppUser : Entity<long>, ISoftDelete, ICreatedUserId, ICreatedTime,
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? BirthDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 年龄
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? Age { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 联系电话
|
||||
/// </summary>
|
||||
|
||||
@ -579,6 +579,11 @@
|
||||
出生日期
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Core.Entities.AppUser.Age">
|
||||
<summary>
|
||||
年龄
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Core.Entities.AppUser.Mobile">
|
||||
<summary>
|
||||
联系电话
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user