ExamPatriarchQuestionnaireProgressService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using Org.BouncyCastle.Tls;
  2. using YBEE.EQM.Core;
  3. namespace YBEE.EQM.Application;
  4. /// <summary>
  5. /// 家长问卷填答进度管理服务
  6. /// </summary>
  7. public class ExamPatriarchQuestionnaireProgressService : IExamPatriarchQuestionnaireProgressService, ITransient
  8. {
  9. private readonly IRepository<ExamPatriarchQuestionnaireProgress> _rep;
  10. private readonly IExportExcelService _exportExcelService;
  11. private readonly ISysDictDataService _sysDictDataService;
  12. public ExamPatriarchQuestionnaireProgressService(IRepository<ExamPatriarchQuestionnaireProgress> rep, IExportExcelService exportExcelService, ISysDictDataService sysDictDataService)
  13. {
  14. _rep = rep;
  15. _exportExcelService = exportExcelService;
  16. _sysDictDataService = sysDictDataService;
  17. }
  18. /// <summary>
  19. /// 查询学生家长问卷明细
  20. /// </summary>
  21. /// <param name="input"></param>
  22. /// <returns></returns>
  23. public async Task<PageResult<ExamStudentPatriarchQuestionnaireProgressOutput>> QueryPageList(ExamStudentPatriarchQuestionnaireProgressPageInput input)
  24. {
  25. string where = "T1.exam_plan_id = @examPlanId AND T1.sys_org_id = @sysOrgId";
  26. if (!string.IsNullOrEmpty(input.Name?.Trim()))
  27. {
  28. where = $"{where} AND T1.name LIKE '%@name%'";
  29. }
  30. if (!string.IsNullOrEmpty(input.IdNumber?.Trim()))
  31. {
  32. where = $"{where} AND T1.id_number LIKE '%@idNumber%'";
  33. }
  34. if (!string.IsNullOrEmpty(input.Mobile?.Trim()))
  35. {
  36. where = $"{where} AND T1.name LIKE '%@mobile%'";
  37. }
  38. if (input.ClassNumber.HasValue)
  39. {
  40. where = $"{where} AND T1.class_number = {input.ClassNumber.Value}";
  41. }
  42. if (input.GradeId.HasValue)
  43. {
  44. where = $"{where} AND T1.grade_id = {input.GradeId.Value}";
  45. }
  46. var p = new
  47. {
  48. CurrentSysUserInfo.SysOrgId,
  49. input.PageSize,
  50. PageOffset = (input.PageIndex - 1) * input.PageSize,
  51. input.ExamPlanId,
  52. input.Name,
  53. input.ClassNumber,
  54. input.IdNumber,
  55. input.Mobile,
  56. };
  57. var totalCount = await _rep.SqlScalarAsync<int>($@"
  58. SELECT COUNT(1) AS total_count
  59. FROM exam_student AS T1
  60. WHERE {where}", p);
  61. var items = await _rep.SqlQueriesAsync<ExamStudentPatriarchQuestionnaireProgressOutput>($@"
  62. SELECT ROW_NUMBER() OVER (ORDER BY T1.grade_id, T1.class_number, T2.id) AS `row_number`,
  63. T1.sys_org_branch_id, T5.`name` AS sys_org_branch_name,
  64. T1.id, T1.grade_id, T6.`name` AS grade_name, T1.course_comb_id,
  65. T1.school_class_id, T7.`name` AS school_class_name, T7.grade_begin_year, T1.class_number,
  66. T1.`name`, T1.certificate_type, T1.id_number,
  67. text_mask(T2.mobile, 3, 4) AS mobile, T2.submit_time, T2.is_completed
  68. FROM exam_student AS T1
  69. LEFT JOIN exam_patriarch_questionnaire_progress AS T2 ON T1.id = T2.exam_student_id
  70. LEFT JOIN sys_org AS T5 ON T1.sys_org_branch_id = T5.id
  71. LEFT JOIN base_grade AS T6 ON T1.grade_id = T6.id
  72. LEFT JOIN school_class AS T7 ON T1.school_class_id = T7.id
  73. WHERE {where}
  74. LIMIT @pageSize OFFSET @pageOffset;", p);
  75. PageResult<ExamStudentPatriarchQuestionnaireProgressOutput> ret = new()
  76. {
  77. PageIndex = input.PageIndex,
  78. PageSize = input.PageSize,
  79. TotalCount = totalCount,
  80. Items = items
  81. };
  82. return ret;
  83. }
  84. /// <summary>
  85. /// 导出未填答学生名单
  86. /// </summary>
  87. /// <param name="input"></param>
  88. /// <returns></returns>
  89. public async Task<byte[]> ExportUncompletedExcel(ExportExamPatriarchQuestionnaireProgressInput input)
  90. {
  91. var items = await _rep.SqlQueriesAsync<ExamStudentPatriarchQuestionnaireProgressOutput>($@"
  92. SELECT ROW_NUMBER() OVER (ORDER BY T1.grade_id, T1.class_number, T2.id) AS `row_number`,
  93. T1.sys_org_branch_id, T5.`name` AS sys_org_branch_name,
  94. T1.id, T1.grade_id, T6.`name` AS grade_name, T1.course_comb_id,
  95. T1.school_class_id, T7.`name` AS school_class_name, T7.grade_begin_year, T1.class_number,
  96. T1.`name`, T1.certificate_type, T1.id_number,
  97. text_mask(T2.mobile, 3, 4) AS mobile, T2.submit_time, T2.is_completed
  98. FROM exam_student AS T1
  99. LEFT JOIN exam_patriarch_questionnaire_progress AS T2 ON T1.id = T2.exam_student_id
  100. LEFT JOIN sys_org AS T5 ON T1.sys_org_branch_id = T5.id
  101. LEFT JOIN base_grade AS T6 ON T1.grade_id = T6.id
  102. LEFT JOIN school_class AS T7 ON T1.school_class_id = T7.id
  103. WHERE T1.exam_plan_id = @examPlanId AND T1.sys_org_id = @sysOrgId AND T2.is_completed IS NULL
  104. ", new { input.ExamPlanId, CurrentSysUserInfo.SysOrgId });
  105. // 获取证件类型
  106. var cts = await _sysDictDataService.GetListByDictTypeId(304);
  107. var certificateTypes = cts.ToDictionary(x => (Core.CertificateType)x.Value, y => y.Name);
  108. List<ExportExcelColDto<ExamStudentPatriarchQuestionnaireProgressOutput>> cols = new()
  109. {
  110. new(){ Name = "年级", Width = 18, GetCellValue = (r) => $"{r.GradeName}({r.GradeBeginYear}级)" },
  111. new(){ Name = "班级", Width = 10, GetCellValue = (r) => $"{r.ClassNumber}班" },
  112. new(){ Name = "校区", Width = 14, GetCellValue = (r) => r.SysOrgBranchName },
  113. new(){ Name = "学生姓名", Width = 20, GetCellValue = (r) => r.Name },
  114. new(){ Name = "证件类型", Width = 16, GetCellValue = (r) => certificateTypes[r.CertificateType] },
  115. new(){ Name = "证件号码", Width = 20, GetCellValue = (r) => r.IdNumber },
  116. };
  117. var ret = _exportExcelService.ExportExcel(new ExportExcelDto<ExamStudentPatriarchQuestionnaireProgressOutput>()
  118. {
  119. Title = $"{CurrentSysUserInfo.SysOrgName}学生家长问卷未填答名单",
  120. Columns = cols,
  121. Items = items,
  122. IncludeExportTime = false,
  123. });
  124. return ret;
  125. }
  126. /// <summary>
  127. /// 获取各班级问卷填答进度
  128. /// </summary>
  129. /// <param name="examPlanId"></param>
  130. /// <returns></returns>
  131. public async Task<List<ExamStudentPatriarchQuestionnaireProgressStatOutput>> GetProgressList(int examPlanId)
  132. {
  133. var items = await _rep.SqlQueriesAsync<ExamStudentPatriarchQuestionnaireProgressStatOutput>($@"
  134. SELECT T1.grade_id * 100 + T1.class_number AS id,
  135. T1.*, T2.`name` AS grade_name,
  136. ROUND(CASE WHEN T1.total_count = 0 THEN 0 ELSE T1.completed_count * 1.0 / T1.total_count * 100 END, 2) as completed_progress
  137. FROM
  138. (
  139. SELECT T1.grade_id, T1.grade_begin_year, T1.class_number,
  140. SUM(CASE WHEN T1.is_completed = 1 THEN T1.sub_total_count ELSE 0 END) AS completed_count,
  141. SUM(CASE WHEN T1.is_completed = 0 THEN T1.sub_total_count ELSE 0 END) AS uncompleted_count,
  142. MAX(T1.total_count) AS total_count
  143. FROM
  144. (
  145. SELECT T1.*, IFNULL(T2.is_completed, 0) AS is_completed, T2.sub_total_count
  146. FROM
  147. (
  148. SELECT T1.grade_id, T3.grade_begin_year, T1.class_number, COUNT(1) AS total_count
  149. FROM exam_student AS T1
  150. LEFT JOIN exam_patriarch_questionnaire_progress AS T2 ON T1.id = T2.exam_student_id
  151. LEFT JOIN school_class AS T3 ON T1.school_class_id = T3.id
  152. WHERE T1.exam_plan_id = @examPlanId AND T1.sys_org_id = @sysOrgId
  153. GROUP BY T1.grade_id, T3.grade_begin_year, T1.class_number
  154. ) AS T1
  155. JOIN
  156. (
  157. SELECT T1.grade_id, T1.class_number, T2.is_completed, COUNT(1) AS sub_total_count
  158. FROM exam_student AS T1
  159. LEFT JOIN exam_patriarch_questionnaire_progress AS T2 ON T1.id = T2.exam_student_id
  160. WHERE T1.exam_plan_id = @examPlanId AND T1.sys_org_id = @sysOrgId
  161. GROUP BY T1.grade_id, T1.class_number, T2.is_completed
  162. ) AS T2 ON T1.grade_id = T2.grade_id AND T1.class_number = T2.class_number
  163. ) AS T1
  164. GROUP BY T1.grade_id, T1.grade_begin_year, T1.class_number
  165. ) AS T1
  166. LEFT JOIN base_grade AS T2 ON T1.grade_id = T2.id
  167. ORDER BY T1.grade_id, T1.class_number", new { ExamPlanId = examPlanId, CurrentSysUserInfo.SysOrgId });
  168. return items;
  169. }
  170. }