namespace SafeCampus.Application.Services.Business.PersonInfoService; public class PersonInfoService:DbRepository, IPersonInfoService { public async Task Add(PersonInfoDto input) { var model = input.Adapt(); var oldModel = await GetFirstAsync(x => x.PersonId == input.PersonId); if (oldModel != null) { throw Oops.Oh("该人员id已存在"); } await InsertAsync(model); return true; } public async Task Delete(string id) { var model = await GetFirstAsync(x => x.PersonId == id); if (model == null) { throw Oops.Oh("信息不存在"); } await DeleteAsync(model); return true; } public async Task GetInfo(string id) { var model = await Context.Queryable() .Includes(x => x.DormitoryInfoItem) .Includes(x => x.PersonSetInfoItem,x=>x.MajorInfoItem,x=>x.DepartmentInfoItem) .Includes(x => x.PersonFacesList) .FirstAsync(x => x.PersonId == id); if (model == null) { return null; } return model.Adapt(); } public async Task Update(PersonInfoDto input) { var model = await GetFirstAsync(p => p.PersonId == input.PersonId); if (model == null) { throw Oops.Oh("信息不存在"); } var res = input.Adapt(model); await UpdateAsync(res); return true; } public async Task UpdateSet(List personId, string personSetId) { var result = await Context.Updateable() .SetColumns(it => it.PersonSetId == personSetId)//SetColumns是可以叠加的 写2个就2个字段赋值 .Where(it => personId.Contains(it.PersonId)) .ExecuteCommandAsync(); return true; } public async Task> GetPageList(PersonInfoSearch search) { var query = Context.Queryable() .Includes(x => x.PersonSetInfoItem, x => x.MajorInfoItem, x => x.DepartmentInfoItem) .Includes(x=>x.PersonFacesList) .Includes(x=>x.DormitoryInfoItem) .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId) .WhereIF(!string.IsNullOrEmpty(search.PersonName), x => x.Name.Contains(search.PersonName)) .WhereIF(search.DepId.HasValue, x => x.PersonSetInfoItem.MajorInfoItem.DepId==search.DepId) .WhereIF(search.MajorId.HasValue, x => x.PersonSetInfoItem.MajorId==search.MajorId) .WhereIF(!string.IsNullOrEmpty(search.Phone), x => x.Phone.Contains(search.Phone)); var list = await query.OrderByDescending(x => x.CreateTime) .ToPagedListAsyncMapster(search.PageNum, search.PageSize); return list; } public async Task GetCount(string sex) { var query = await Context.Queryable() .WhereIF(!string.IsNullOrEmpty(sex),x => x.Gender == sex) .CountAsync(); return query; } public async Task GetAge() { var query = await Context.Queryable().GroupBy(x => x.Age) .Select(x => new { Label = x.Age, Value = SqlFunc.AggregateCount(x.Age) }).ToListAsync(); return new {Label=query.Select(x=>x.Label),Value=query.Select(x=>x.Value)}; } }