From 00fe3336b89c3c24ffe2826f45419d8e7dbb17fc Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期四, 23 五月 2024 15:46:57 +0800
Subject: [PATCH] feat:统计新需求

---
 src/main/resources/mapper/ExamPaperAnswerMapper.xml |   92 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 77 insertions(+), 15 deletions(-)

diff --git a/src/main/resources/mapper/ExamPaperAnswerMapper.xml b/src/main/resources/mapper/ExamPaperAnswerMapper.xml
index 7b059bf..75b6094 100644
--- a/src/main/resources/mapper/ExamPaperAnswerMapper.xml
+++ b/src/main/resources/mapper/ExamPaperAnswerMapper.xml
@@ -475,20 +475,82 @@
     GROUP BY user_id) d ON a.user_id = d.user_id
   </select>
 
-<insert id="insertDefault">
-  INSERT INTO t_exam_paper_answer(exam_paper_id, paper_name, paper_type, system_score, user_score, paper_score, question_correct, question_count, do_time, status,
-  create_user, create_time, invalid)
-  SELECT
-  a.id, a.name, a.paper_type, 0, 0, a.score, 0,  a.question_count, 0, 2, b.user_id, NOW(), 0
-  FROM t_exam_paper a
-  left join t_exam_paper_user b on a.id = b.exam_paper_id and b.deleted = 0
-  left join t_exam_paper_answer c on a.id = c.exam_paper_id and c.create_user = b.user_id
-  WHERE a.id = #{examPaperId}
-  and c.id is null
-  and b.user_id not in
-  <foreach collection="userIds" item="item" open="(" close=")" separator=",">
-    #{item}
-  </foreach>
-</insert>
+    <insert id="insertDefault">
+      INSERT INTO t_exam_paper_answer(exam_paper_id, paper_name, paper_type, system_score, user_score, paper_score, question_correct, question_count, do_time, status,
+      create_user, create_time, invalid)
+      SELECT
+      a.id, a.name, a.paper_type, 0, 0, a.score, 0,  a.question_count, 0, 2, b.user_id, NOW(), 0
+      FROM t_exam_paper a
+      left join t_exam_paper_user b on a.id = b.exam_paper_id and b.deleted = 0
+      left join t_exam_paper_answer c on a.id = c.exam_paper_id and c.create_user = b.user_id
+      WHERE a.id = #{examPaperId}
+      and c.id is null
+      and b.user_id not in
+      <foreach collection="userIds" item="item" open="(" close=")" separator=",">
+        #{item}
+      </foreach>
+    </insert>
+
+  <select id="dataByTemplate" resultType="java.util.Map" parameterType="com.mindskip.xzs.domain.vo.ExamPaperDataVO">
+    SELECT
+      a.id,
+      a.name,
+      COUNT(DISTINCT c.create_user) as factPeopleTotal, -- 鍙傝�冧汉鏁�
+      IFNULL(ROUND(AVG(c.user_score), 2), 0) as averageScore, -- 骞冲潎鎴愮哗
+      IFNULL(ROUND((COUNT(DISTINCT c.create_user) * 100.0 / COUNT(DISTINCT d.user_id)), 2), 0) AS referencePercentage -- 鍙傝�冪櫨鍒嗘瘮
+    FROM
+      t_department a
+        LEFT JOIN t_user_department b ON a.id = b.department_id
+        LEFT JOIN t_exam_templates_user d ON d.user_id = b.user_id AND d.templates_id = #{id}
+        LEFT JOIN t_exam_templates_user_count e ON d.templates_id = e.exam_templates_id
+        LEFT JOIN t_exam_paper_answer c ON d.user_id = c.create_user AND e.exam_paper_id = c.exam_paper_id AND (c.invalid = 0 OR c.invalid IS NULL)
+    GROUP BY
+      a.id, a.name
+  </select>
+
+  <select id="totalByTemplate" resultType="java.util.Map" parameterType="com.mindskip.xzs.domain.vo.ExamPaperDataVO">
+    SELECT
+           (SELECT (SELECT count(*) FROM t_exam_paper) + (SELECT count(*) FROM t_exam_templates)) as examTotal, -- 鎬昏�冭瘯娆℃暟
+           COUNT(DISTINCT c.create_user) as factPeopleTotal, -- 鍙傝�冧汉鏁�
+           IFNULL(ROUND(AVG(c.user_score), 2), 0) as averageScore, -- 骞冲潎鎴愮哗
+           IFNULL(ROUND((COUNT(DISTINCT c.create_user) * 100.0 / COUNT(DISTINCT d.user_id)), 2), 0) AS referencePercentage -- 鍙傝�冪櫨鍒嗘瘮
+    FROM
+      t_exam_templates a
+        LEFT JOIN t_exam_templates_user d ON d.templates_id = a.id
+        LEFT JOIN t_exam_templates_user_count e ON d.templates_id = e.exam_templates_id
+        LEFT JOIN t_exam_paper_answer c ON d.user_id = c.create_user AND e.exam_paper_id = c.exam_paper_id AND (c.invalid = 0 OR c.invalid IS NULL)
+    WHERE a.id = #{id}
+    GROUP BY
+      a.id
+  </select>
+
+  <select id="dataByPaper" resultType="java.util.Map" parameterType="com.mindskip.xzs.domain.vo.ExamPaperDataVO">
+    SELECT
+      a.id,
+      a.name,
+      COUNT(DISTINCT c.create_user) as factPeopleTotal, -- 鍙傝�冧汉鏁�
+      IFNULL(ROUND(AVG(c.user_score), 2), 0) as averageScore, -- 骞冲潎鎴愮哗
+      IFNULL(ROUND((COUNT(DISTINCT c.create_user) * 100.0 / COUNT(DISTINCT d.user_id)), 2), 0) AS referencePercentage -- 鍙傝�冪櫨鍒嗘瘮
+    FROM
+      t_department a
+        LEFT JOIN t_user_department b ON a.id = b.department_id
+        LEFT JOIN t_exam_paper_answer c ON b.user_id = c.create_user AND (c.invalid = 0 OR c.invalid IS NULL) AND c.exam_paper_id = #{id}
+        LEFT JOIN t_exam_paper_user d ON c.exam_paper_id = d.exam_paper_id and b.user_id = d.user_id
+    GROUP BY
+      a.id, a.name
+  </select>
+
+  <select id="totalByPaper" resultType="java.util.Map" parameterType="com.mindskip.xzs.domain.vo.ExamPaperDataVO">
+    SELECT
+        (SELECT (SELECT count(*) FROM t_exam_paper) + (SELECT count(*) FROM t_exam_templates)) as examTotal, -- 鎬昏�冭瘯娆℃暟
+        count(DISTINCT b.create_user) AS factPeopleTotal, -- 鍙傝�冩暟
+        IFNULL(ROUND(avg(user_score), 2), 0) as averageScore, -- 骞冲潎鍒�
+        IFNULL(ROUND((COUNT(DISTINCT b.create_user) * 100.0 / COUNT(DISTINCT c.user_id)), 2), 0) AS referencePercentage -- 鍙傝�冪櫨鍒嗘瘮
+    FROM t_exam_paper a
+           LEFT JOIN t_exam_paper_answer b ON a.id = b.exam_paper_id AND (b.invalid = 0 OR b.invalid IS NULL)
+           LEFT JOIN t_exam_paper_user c ON a.id = c.exam_paper_id
+    WHERE a.id = #{id}
+    GROUP BY a.id
+  </select>
 
 </mapper>

--
Gitblit v1.8.0