namespace SafeCampus.Application.Services.Business.PersonSetInfoService; public class PersonSetInfoService:DbRepository, IPersonSetInfoService { public async Task Add(PersonSetInfoDto input) { var model = input.Adapt(); var oldModel = await GetFirstAsync(x => x.PersonSetId == input.PersonSetId); if (oldModel != null) { throw Oops.Oh("该班级id已存在"); } model.CreateTime=DateTime.Now; await InsertAsync(model); return true; } public async Task Delete(string id) { var model = await GetFirstAsync(x => x.PersonSetId == id); if (model == null) { throw Oops.Oh("信息不存在"); } await DeleteAsync(model); return true; } public async Task Update(PersonSetInfoDto input) { var model = await GetFirstAsync(p => p.PersonSetId == input.PersonSetId); if (model == null) { throw Oops.Oh("信息不存在"); } var res = input.Adapt(model); await UpdateAsync(res); return true; } public async Task> GetPageList(long? majorId, string setName) { var list =await Context.Queryable() .Includes(x=>x.MajorInfoItem,x=>x.DepartmentInfoItem) .Includes(x => x.ClassTeacherItem, st => st.SysUserItem) .Where(x=>x.PersonSetId!=SafeCampusConst.ZDRY) .WhereIF(majorId.HasValue,x=>x.MajorId==majorId) .WhereIF(!string.IsNullOrEmpty(setName),x=>x.PersonSetName.Contains(setName)) .ToListAsync(); return list.Adapt>(); } public async Task> GetList(PersonSetInfoSearch search) { var query = Context.Queryable() .Includes(x => x.MajorInfoItem, x => x.DepartmentInfoItem) .Includes(x => x.ClassTeacherItem, st => st.SysUserItem) .Where(x => x.PersonSetId != SafeCampusConst.ZDRY) .WhereIF(search.MajorId.HasValue, x => x.MajorId ==search.MajorId) .WhereIF(!string.IsNullOrEmpty(search.SetName), x => x.PersonSetName.Contains(search.SetName)); var list = await query.OrderByDescending(x => x.CreateTime) .ToPagedListAsyncMapster(search.PageNum, search.PageSize); return list; } public async Task CheckName(string name,string id) { var model =await GetFirstAsync(x => x.PersonSetName == name&&(string.IsNullOrEmpty(id) ||x.PersonSetId!=id)); return model != null; } }