|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- namespace SafeCampus.Application.Services.Business.PersonInfoService;
-
- public class PersonInfoService:DbRepository<PersonInfo>, IPersonInfoService
- {
- public async Task<bool> Add(PersonInfoDto input)
- {
- var model = input.Adapt<PersonInfo>();
- var oldModel = await GetFirstAsync(x => x.PersonId == input.PersonId);
- if (oldModel != null)
- {
- throw Oops.Oh("该人员id已存在");
- }
- await InsertAsync(model);
- return true;
- }
-
- public async Task<bool> 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<PersonInfoDto> GetInfo(string id)
- {
- var model = await GetFirstAsync(x => x.PersonId == id);
- if (model == null)
- {
- return null;
- }
- return model.Adapt<PersonInfoDto>();
- }
-
- public async Task<bool> 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<bool> UpdateSet(List<string> personId, string personSetId)
- {
- var result = await Context.Updateable<PersonInfo>()
- .SetColumns(it => it.PersonSetId == personSetId)//SetColumns是可以叠加的 写2个就2个字段赋值
- .Where(it => personId.Contains(it.PersonId))
- .ExecuteCommandAsync();
- return true;
- }
-
- public async Task<SqlSugarPagedList<PersonInfoDto>> GetPageList(PersonInfoSearch search)
- {
- var query = Context.Queryable<PersonInfo>()
- .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<PersonInfo, PersonInfoDto>(search.PageNum, search.PageSize);
- return list;
- }
- }
|