平安校园
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

74 строки
2.5 KiB

  1. namespace SafeCampus.Application.Services.Business.PersonInfoService;
  2. public class PersonInfoService:DbRepository<PersonInfo>, IPersonInfoService
  3. {
  4. public async Task<bool> Add(PersonInfoDto input)
  5. {
  6. var model = input.Adapt<PersonInfo>();
  7. var oldModel = await GetFirstAsync(x => x.PersonId == input.PersonId);
  8. if (oldModel != null)
  9. {
  10. throw Oops.Oh("该人员id已存在");
  11. }
  12. await InsertAsync(model);
  13. return true;
  14. }
  15. public async Task<bool> Delete(string id)
  16. {
  17. var model = await GetFirstAsync(x => x.PersonId == id);
  18. if (model == null)
  19. {
  20. throw Oops.Oh("信息不存在");
  21. }
  22. await DeleteAsync(model);
  23. return true;
  24. }
  25. public async Task<PersonInfoDto> GetInfo(string id)
  26. {
  27. var model = await GetFirstAsync(x => x.PersonId == id);
  28. if (model == null)
  29. {
  30. return null;
  31. }
  32. return model.Adapt<PersonInfoDto>();
  33. }
  34. public async Task<bool> Update(PersonInfoDto input)
  35. {
  36. var model = await GetFirstAsync(p => p.PersonId == input.PersonId);
  37. if (model == null)
  38. {
  39. throw Oops.Oh("信息不存在");
  40. }
  41. var res = input.Adapt(model);
  42. await UpdateAsync(res);
  43. return true;
  44. }
  45. public async Task<bool> UpdateSet(List<string> personId, string personSetId)
  46. {
  47. var result = await Context.Updateable<PersonInfo>()
  48. .SetColumns(it => it.PersonSetId == personSetId)//SetColumns是可以叠加的 写2个就2个字段赋值
  49. .Where(it => personId.Contains(it.PersonId))
  50. .ExecuteCommandAsync();
  51. return true;
  52. }
  53. public async Task<SqlSugarPagedList<PersonInfoDto>> GetPageList(PersonInfoSearch search)
  54. {
  55. var query = Context.Queryable<PersonInfo>()
  56. .Includes(x => x.PersonSetInfoItem)
  57. .Includes(x=>x.PersonFacesList)
  58. .Includes(x=>x.DormitoryInfoItem)
  59. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  60. .WhereIF(!string.IsNullOrEmpty(search.PersonName), x => x.Name == search.PersonName)
  61. .WhereIF(!string.IsNullOrEmpty(search.Phone), x => x.Phone == search.Phone);
  62. var list = await query.OrderByDescending(x => x.CreateTime)
  63. .ToPagedListAsyncMapster<PersonInfo, PersonInfoDto>(search.PageNum, search.PageSize);
  64. return list;
  65. }
  66. }