ExamOrgService.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 被监测机构管理服务
  5. /// </summary>
  6. public class ExamOrgService : IExamOrgService, ITransient
  7. {
  8. private readonly IRepository<ExamOrg> _rep;
  9. public ExamOrgService(IRepository<ExamOrg> rep)
  10. {
  11. _rep = rep;
  12. }
  13. /// <summary>
  14. /// 添加机构
  15. /// </summary>
  16. /// <param name="input"></param>
  17. /// <returns></returns>
  18. public async Task AddList(AddExamOrgListInput input)
  19. {
  20. var existsOrgIdList = await _rep.Where(t => t.ExamPlanId == input.ExamPlanId).Select(t => t.SysOrgId).ToListAsync();
  21. var addOrgIdList = from t in input.SysOrgIdList where !(from rid in existsOrgIdList select rid).Contains(t) select t;
  22. var roles = addOrgIdList.Select(u => new ExamOrg
  23. {
  24. ExamPlanId = input.ExamPlanId,
  25. SysOrgId = u,
  26. }).ToList();
  27. await _rep.InsertAsync(roles);
  28. }
  29. /// <summary>
  30. /// 移出机构
  31. /// </summary>
  32. /// <param name="input"></param>
  33. /// <returns></returns>
  34. public async Task Remove(DelExamOrgInput input)
  35. {
  36. var roleUsers = await _rep.Where(t => input.IdList.Contains(t.Id)).ToListAsync();
  37. await _rep.DeleteAsync(roleUsers);
  38. }
  39. /// <summary>
  40. /// 根据监测计划ID获取监测机构列表
  41. /// </summary>
  42. /// <param name="examPlanId"></param>
  43. /// <returns></returns>
  44. public async Task<List<ExamOrgOutput>> GetListByExamPlanId(int examPlanId)
  45. {
  46. var items = await _rep.DetachedEntities.Where(t => t.ExamPlanId == examPlanId).ProjectToType<ExamOrgOutput>().ToListAsync();
  47. var odrs = await _rep.Change<ExamOrgDataReport>().Where(t => t.ExamOrg.ExamPlanId == examPlanId).ToListAsync();
  48. foreach (var item in items)
  49. {
  50. item.DataReports = odrs.Where(t => t.ExamOrgId == item.Id).ToDictionary(t => (short)t.Type, u => u.Status);
  51. }
  52. return items;
  53. }
  54. /// <summary>
  55. /// 分页查询监测机构列表
  56. /// </summary>
  57. /// <param name="input"></param>
  58. /// <returns></returns>
  59. public async Task<PageResult<ExamOrgOutput>> QueryPageList(ExamOrgPageInput input)
  60. {
  61. var orgName = !string.IsNullOrEmpty(input.OrgName?.Trim());
  62. var ret = await _rep.DetachedEntities.Where(t => t.ExamPlanId == input.ExamPlanId)
  63. .Where((orgName, u => EF.Functions.Like(u.SysOrg.FullName, $"%{input.OrgName.Trim()}%")))
  64. .ProjectToType<ExamOrgOutput>()
  65. .ToADPagedListAsync(input.PageIndex, input.PageSize);
  66. var odrs = await _rep.Change<ExamOrgDataReport>().Where(t => t.ExamOrg.ExamPlanId == input.ExamPlanId).ProjectToType<ExamOrgDataReportOutput>().ToListAsync();
  67. foreach (var item in ret.Items)
  68. {
  69. item.DataReportList = odrs.Where(t => t.ExamOrgId == item.Id).ToList();
  70. item.DataReports = item.DataReportList.ToDictionary(t => (short)t.Type, u => u.Status);
  71. }
  72. return ret;
  73. }
  74. /// <summary>
  75. /// 分页查询未加入的机构
  76. /// </summary>
  77. /// <param name="input"></param>
  78. /// <returns></returns>
  79. public async Task<PageResult<SysOrgLiteOutput>> QueryNotInSysOrgPageList(ExamOrgNotInPageInput input)
  80. {
  81. var code = !string.IsNullOrEmpty(input.Code?.Trim());
  82. var name = !string.IsNullOrEmpty(input.Name?.Trim());
  83. var examPlan = await _rep.Change<ExamPlan>().DetachedEntities.FirstOrDefaultAsync(t => t.Id == input.ExamPlanId);
  84. var inOrgIds = await _rep.DetachedEntities.Where(t => t.ExamPlanId == input.ExamPlanId).Select(t => t.SysOrgId).ToListAsync();
  85. var ret = await _rep.Change<SysOrg>().DetachedEntities
  86. .Where((code, u => EF.Functions.Like(u.Code, $"%{input.Code.Trim()}%")))
  87. .Where((name, u => EF.Functions.Like(u.FullName, $"%{input.Name.Trim()}%")))
  88. .Where(input.UrbanRuralType.HasValue, t => t.UrbanRuralType == input.UrbanRuralType)
  89. .Where(input.Status.HasValue, t => t.Status == input.Status)
  90. .Where(t => t.OrgType == OrgType.SCHOOL && t.EducationStage == examPlan.EducationStage && t.UrbanRuralType != UrbanRuralType.NONE && !inOrgIds.Contains(t.Id))
  91. .ProjectToType<SysOrgLiteOutput>()
  92. .ToADPagedListAsync(input.PageIndex, input.PageSize);
  93. return ret;
  94. }
  95. /// <summary>
  96. /// 分页查询机构监测计划列表
  97. /// </summary>
  98. /// <param name="input"></param>
  99. /// <returns></returns>
  100. public async Task<PageResult<ExamPlanOutput>> QueryExamPlanPageList(ExamPlanPageInput input)
  101. {
  102. var name = !string.IsNullOrEmpty(input.Name?.Trim());
  103. var searchBeginTime = !string.IsNullOrEmpty(input.SearchBeginTime?.Trim());
  104. var searchEndTime = !string.IsNullOrEmpty(input.SearchEndTime?.Trim());
  105. var ret = await _rep.DetachedEntities.Where(t => t.SysOrgId == CurrentSysUserInfo.SysOrgId && (t.ExamPlan.Status == ExamStatus.ACTIVE || t.ExamPlan.Status == ExamStatus.STOPPED))
  106. .Where((name, u => EF.Functions.Like(u.ExamPlan.Name, $"%{input.Name.Trim()}%") || EF.Functions.Like(u.ExamPlan.FullName, $"%{input.Name.Trim()}%") || EF.Functions.Like(u.ExamPlan.ShortName, $"%{input.Name.Trim()}%")))
  107. .Where(input.EducationStage.HasValue, t => t.ExamPlan.EducationStage == input.EducationStage)
  108. //.Where(input.ExamPeriodType.HasValue, t => t.ExamPlan.ExamPeriodType == input.ExamPeriodType)
  109. //.Where(input.ExamType.HasValue, t => t.ExamPlan.ExamType == input.ExamType)
  110. .Where(input.SemesterId.HasValue, t => t.ExamPlan.SemesterId == input.SemesterId)
  111. .Where(t => (t.ExamPlan.Status == ExamStatus.ACTIVE || t.ExamPlan.Status == ExamStatus.STOPPED) && (!input.Status.HasValue || input.Status.HasValue && t.ExamPlan.Status == input.Status))
  112. .Where((searchBeginTime, u => u.ExamPlan.CreateTime >= DateTime.Parse(input.SearchBeginTime)))
  113. .Where((searchEndTime, u => u.ExamPlan.CreateTime <= DateTime.Parse(input.SearchEndTime)))
  114. .OrderByDescending(t => t.ExamPlanId)
  115. .Select(t => t.ExamPlan).ProjectToType<ExamPlanOutput>().ToADPagedListAsync(input.PageIndex, input.PageSize);
  116. return ret;
  117. }
  118. }