平安校园
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
3.2 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 Context.Queryable<PersonInfo>()
  28. .Includes(x => x.DormitoryInfoItem)
  29. .Includes(x => x.PersonSetInfoItem)
  30. .Includes(x => x.PersonFacesList)
  31. .FirstAsync(x => x.PersonId == id);
  32. if (model == null)
  33. {
  34. return null;
  35. }
  36. return model.Adapt<PersonInfoDto>();
  37. }
  38. public async Task<bool> Update(PersonInfoDto input)
  39. {
  40. var model = await GetFirstAsync(p => p.PersonId == input.PersonId);
  41. if (model == null)
  42. {
  43. throw Oops.Oh("信息不存在");
  44. }
  45. var res = input.Adapt(model);
  46. await UpdateAsync(res);
  47. return true;
  48. }
  49. public async Task<bool> UpdateSet(List<string> personId, string personSetId)
  50. {
  51. var result = await Context.Updateable<PersonInfo>()
  52. .SetColumns(it => it.PersonSetId == personSetId)//SetColumns是可以叠加的 写2个就2个字段赋值
  53. .Where(it => personId.Contains(it.PersonId))
  54. .ExecuteCommandAsync();
  55. return true;
  56. }
  57. public async Task<SqlSugarPagedList<PersonInfoDto>> GetPageList(PersonInfoSearch search)
  58. {
  59. var query = Context.Queryable<PersonInfo>()
  60. .Includes(x => x.PersonSetInfoItem)
  61. .Includes(x=>x.PersonFacesList)
  62. .Includes(x=>x.DormitoryInfoItem)
  63. .WhereIF(!string.IsNullOrEmpty(search.PersonSetId), x => x.PersonSetId == search.PersonSetId)
  64. .WhereIF(!string.IsNullOrEmpty(search.PersonName), x => x.Name.Contains(search.PersonName))
  65. .WhereIF(!string.IsNullOrEmpty(search.Phone), x => x.Phone.Contains(search.Phone));
  66. var list = await query.OrderByDescending(x => x.CreateTime)
  67. .ToPagedListAsyncMapster<PersonInfo, PersonInfoDto>(search.PageNum, search.PageSize);
  68. return list;
  69. }
  70. public async Task<int> GetCount(string sex)
  71. {
  72. var query = await Context.Queryable<PersonInfo>()
  73. .WhereIF(!string.IsNullOrEmpty(sex),x => x.Gender == sex)
  74. .CountAsync();
  75. return query;
  76. }
  77. public async Task<dynamic> GetAge()
  78. {
  79. var query = await Context.Queryable<PersonInfo>().GroupBy(x => x.Age)
  80. .Select(x => new { Label = x.Age, Value = SqlFunc.AggregateCount(x.Age) }).ToListAsync();
  81. return new {Label=query.Select(x=>x.Label),Value=query.Select(x=>x.Value)};
  82. }
  83. }