From 5b76d629eef02be2f8c7c8ccde13d02aee25e63b Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 18 九月 2024 16:17:54 +0800
Subject: [PATCH] 大屏优化

---
 ycl-server/src/main/resources/mapper/zgyw/CheckScoreMapper.xml |  123 +++++++++++++++++++++++++---------------
 1 files changed, 76 insertions(+), 47 deletions(-)

diff --git a/ycl-server/src/main/resources/mapper/zgyw/CheckScoreMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/CheckScoreMapper.xml
index df07d02..45b4d2f 100644
--- a/ycl-server/src/main/resources/mapper/zgyw/CheckScoreMapper.xml
+++ b/ycl-server/src/main/resources/mapper/zgyw/CheckScoreMapper.xml
@@ -18,9 +18,18 @@
     </resultMap>
 
     <sql id="selectCheckScoreVo">
-        select id, score, tcs.dept_id, template_id, examine_tag, examine_category,
-        tcs.create_time,tcs.update_time,tcs.update_user, publish
-        from t_check_score tcs left join sys_dept d on tcs.dept_id = d.dept_id
+        select id,
+               score,
+               tcs.dept_id,
+               template_id,
+               examine_tag,
+               examine_category,
+               tcs.create_time,
+               tcs.update_time,
+               tcs.update_user,
+               publish
+        from t_check_score tcs
+                 left join sys_dept d on tcs.dept_id = d.dept_id
     </sql>
 
     <select id="selectCheckScoreList" resultMap="CheckScoreResult">
@@ -87,7 +96,9 @@
     </update>
 
     <delete id="deleteCheckScoreById" parameterType="Long">
-        delete from t_check_score where id = #{id}
+        delete
+        from t_check_score
+        where id = #{id}
     </delete>
 
     <delete id="deleteCheckScoreByIds" parameterType="String">
@@ -107,48 +118,55 @@
     <select id="selectScoreIndex" resultType="java.util.Map">
         select t.* from ${tableName} t
         left join sys_dept d on t.dept_id = d.dept_id
-        where t.dept_id = #{deptId}
-        <if test="examineTag != null">
-            and examine_tag = #{examineTag}
-        </if>
-        <if test="date != null">
-            and date_format(t.create_time,'%Y-%m') = #{date}
-        </if>
-        <if test="quarter != null and quarter.size > 0">
-            and date_format(t.create_time, '%Y-%m') between #{quarter[0]} and #{quarter[1]}
-        </if>
-        ${params.dataScope}
+        <where>
+            t.dept_id = #{deptId}
+            <if test="examineTag != null">
+                and examine_tag = #{examineTag}
+            </if>
+            <if test="date != null">
+                and date_format(t.create_time,'%Y-%m') = #{date}
+            </if>
+            <if test="quarter != null and quarter.size > 0">
+                and date_format(t.create_time, '%Y-%m') between #{quarter[0]} and #{quarter[1]}
+            </if>
+            <if test="params.publish != null  and params.publish != ''">
+                and publish = #{params.publish}
+            </if>
+            ${params.dataScope}
+        </where>
     </select>
 
     <insert id="saveBatch">
-        insert into t_check_score (score,dept_id,template_id,examine_tag,examine_category,create_time) values
+        insert into t_check_score (score,dept_id,template_id,index_id,examine_tag,examine_category,create_time) values
         <foreach collection="scoreList" separator="," item="score">
-            (#{score.score},#{score.deptId},#{score.templateId},#{score.examineTag},#{score.examineCategory},#{score.createTime})
+            (#{score.score},#{score.deptId},#{score.templateId},#{score.indexId},#{score.examineTag},#{score.examineCategory},#{score.createTime})
         </foreach>
     </insert>
 
     <select id="selectCheckScoreMap" resultType="com.ycl.platform.domain.entity.CheckScore">
-        SELECT
-        id,
+        SELECT * FROM
+        (SELECT
+        tcs.id,
         tcs.dept_id,
-        examine_category,
-        ROUND(AVG(score) OVER(PARTITION BY tcs.dept_id, examine_category), 2) AS score,
+        tcs.examine_category,
         tcs.publish,
-        tcs.create_time AS createTime
+        tcs.create_time,
+        ROW_NUMBER() OVER(PARTITION BY tcs.dept_id, tcs.examine_category ORDER BY tcs.create_time DESC) AS rn,
+        AVG(tcs.score) OVER(PARTITION BY tcs.dept_id, tcs.examine_category) AS score
         FROM
         t_check_score tcs
         LEFT JOIN sys_dept d ON tcs.dept_id = d.dept_id
         <where>
             examine_tag = #{examineTag}
-            AND DATE_FORMAT(tcs.create_time, '%Y-%m') BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m') AND DATE_FORMAT(#{endDate}, '%Y-%m')
-            <if test="params.publish != null  and params.publish != ''">and publish = #{params.publish}</if>
+            AND DATE(tcs.create_time) BETWEEN DATE(#{startDate}) AND DATE(#{endDate})
+            <if test="params.publish != null  and params.publish != ''">AND tcs.publish = #{params.publish}</if>
             ${params.dataScope}
         </where>
---         GROUP BY tcs.dept_id, tcs.examine_category, tcs.examine_tag
+        ) t where rn =1
     </select>
 
     <select id="getLast" resultType="com.ycl.platform.domain.entity.CheckScore">
-        select * from t_check_score tcs  LEFT JOIN sys_dept d ON tcs.dept_id = d.dept_id
+        select * from t_check_score tcs LEFT JOIN sys_dept d ON tcs.dept_id = d.dept_id
         <where>
             tcs.examine_tag = #{examineTag}
             <if test="params.publish != null  and params.publish != ''">and tcs.publish = #{params.publish}</if>
@@ -158,35 +176,46 @@
     </select>
     <select id="home" resultType="java.util.Map">
         <![CDATA[
-        SELECT
-            DATE_FORMAT(cs.create_time, '%Y-%m-%d %h:%i:%s') AS createTime,
-            d.area,
-            CASE WHEN cs.examine_tag = '0' THEN '鐪佸巺' WHEN cs.examine_tag = '1' THEN '甯傚眬' WHEN cs.examine_tag = '2' THEN '' END AS examineTag,
-            ct.template_name AS templateName,
-            cs.score
-        FROM
-            t_check_score cs
-                LEFT JOIN t_check_template ct ON cs.template_id = ct.id
-                LEFT JOIN sys_dept d ON cs.dept_id = d.dept_id
+        SELECT DATE_FORMAT(cs.create_time, '%Y-%m-%d %h:%i:%s') AS createTime,
+               d.area,
+               CASE
+                   WHEN cs.examine_tag = '0' THEN '鐪佸巺'
+                   WHEN cs.examine_tag = '1' THEN '甯傚眬'
+                   WHEN cs.examine_tag = '2' THEN '' END        AS examineTag,
+               ct.template_name                                 AS templateName,
+               cs.score
+        FROM t_check_score cs
+                 LEFT JOIN t_check_template ct ON cs.template_id = ct.id
+                 LEFT JOIN sys_dept d ON cs.dept_id = d.dept_id
         WHERE cs.score < ct.alarm_score
         ORDER BY cs.create_time DESC
         ]]>
     </select>
 
     <select id="calculate" resultType="java.util.Map">
-        SELECT
-        area AS deptName,
-        ROUND(AVG(score)) AS score
-        FROM
-        t_check_score tcs
-        LEFT JOIN sys_dept d ON tcs.dept_id = d.dept_id
-        WHERE
-        examine_tag = 1
-        AND examine_category = #{category}
-        AND DATE_FORMAT(tcs.create_time, '%Y-%m') BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m') AND DATE_FORMAT(#{endDate},
-        '%Y-%m')
+        SELECT area              AS deptName,
+               ROUND(AVG(score)) AS score
+        FROM t_check_score tcs
+                 LEFT JOIN sys_dept d ON tcs.dept_id = d.dept_id
+        WHERE examine_tag = 1
+          AND examine_category = #{category}
+          AND DATE_FORMAT(tcs.create_time, '%Y-%m') BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m') AND DATE_FORMAT(
+                #{endDate},
+                '%Y-%m')
         GROUP BY tcs.dept_id
         ORDER BY score DESC, tcs.dept_id
     </select>
 
+    <select id="dashboard" resultType="com.ycl.platform.domain.entity.CheckScore">
+        select s.*,d.area as deptName from t_check_score s
+        left join sys_dept d on s.dept_id = d.dept_id
+        <where>
+            <if test="dataScope == 1">
+                AND s.examine_tag = 1
+            </if>
+        </where>
+        ORDER BY
+        s.create_time DESC
+        LIMIT 7
+    </select>
 </mapper>

--
Gitblit v1.8.0