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 GetFirstAsync(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) .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 == search.PersonName) .WhereIF(!string.IsNullOrEmpty(search.Phone), x => x.Phone == search.Phone); var list = await query.OrderByDescending(x => x.CreateTime) .ToPagedListAsyncMapster(search.PageNum, search.PageSize); return list; } }