平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 line
2.7 KiB

  1. namespace SafeCampus.Application.Services.Business.PersonSetInfoService;
  2. public class PersonSetInfoService:DbRepository<PersonSetInfo>, IPersonSetInfoService
  3. {
  4. public async Task<bool> Add(PersonSetInfoDto input)
  5. {
  6. var model = input.Adapt<PersonSetInfo>();
  7. var oldModel = await GetFirstAsync(x => x.PersonSetId == input.PersonSetId);
  8. if (oldModel != null)
  9. {
  10. throw Oops.Oh("该班级id已存在");
  11. }
  12. model.CreateTime=DateTime.Now;
  13. await InsertAsync(model);
  14. return true;
  15. }
  16. public async Task<bool> Delete(string id)
  17. {
  18. var model = await GetFirstAsync(x => x.PersonSetId == id);
  19. if (model == null)
  20. {
  21. throw Oops.Oh("信息不存在");
  22. }
  23. await DeleteAsync(model);
  24. return true;
  25. }
  26. public async Task<bool> Update(PersonSetInfoDto input)
  27. {
  28. var model = await GetFirstAsync(p => p.PersonSetId == input.PersonSetId);
  29. if (model == null)
  30. {
  31. throw Oops.Oh("信息不存在");
  32. }
  33. var res = input.Adapt(model);
  34. await UpdateAsync(res);
  35. return true;
  36. }
  37. public async Task<List<PersonSetInfoDto>> GetPageList(long? majorId, string setName)
  38. {
  39. var list =await Context.Queryable<PersonSetInfo>()
  40. .Includes(x=>x.MajorInfoItem,x=>x.DepartmentInfoItem)
  41. .Includes(x => x.ClassTeacherItem, st => st.SysUserItem)
  42. .Where(x=>x.PersonSetId!=SafeCampusConst.ZDRY)
  43. .WhereIF(majorId.HasValue,x=>x.MajorId==majorId)
  44. .WhereIF(!string.IsNullOrEmpty(setName),x=>x.PersonSetName.Contains(setName))
  45. .ToListAsync();
  46. return list.Adapt<List<PersonSetInfoDto>>();
  47. }
  48. public async Task<SqlSugarPagedList<PersonSetInfoDto>> GetList(PersonSetInfoSearch search)
  49. {
  50. var query = Context.Queryable<PersonSetInfo>()
  51. .Includes(x => x.MajorInfoItem, x => x.DepartmentInfoItem)
  52. .Includes(x => x.ClassTeacherItem, st => st.SysUserItem)
  53. .Where(x => x.PersonSetId != SafeCampusConst.ZDRY)
  54. .WhereIF(search.MajorId.HasValue, x => x.MajorId ==search.MajorId)
  55. .WhereIF(!string.IsNullOrEmpty(search.SetName), x => x.PersonSetName.Contains(search.SetName));
  56. var list = await query.OrderByDescending(x => x.CreateTime)
  57. .ToPagedListAsyncMapster<PersonSetInfo, PersonSetInfoDto>(search.PageNum, search.PageSize);
  58. return list;
  59. }
  60. public async Task<bool> CheckName(string name,string id)
  61. {
  62. var model =await GetFirstAsync(x => x.PersonSetName == name&&(string.IsNullOrEmpty(id) ||x.PersonSetId!=id));
  63. return model != null;
  64. }
  65. }