无关风月
2024-06-17 34e183fbfed4688f25b375d4966b937f52228827
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.study.mapper.TStudyMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.study.domain.TStudy">
        <id column="id" property="id"/>
        <result column="week" property="week"/>
        <result column="day" property="day"/>
        <result column="listen" property="listen"/>
        <result column="type" property="type"/>
        <result column="integral" property="integral"/>
        <result column="sort" property="sort"/>
        <result column="title" property="title"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        week,
        day,
        listen,
        type,
        integral,
        sort,
        title
    </sql>
 
    <select id="weekList" resultType="com.ruoyi.study.dto.StudyWeekDTO">
        SELECT COALESCE(SUM(sa.integral), 0) + COALESCE(SUM(si.integral), 0) + COALESCE(SUM(st.integral), 0) +
               COALESCE(SUM(sk.integral), 0) + COALESCE(SUM(sp.integral), 0) + COALESCE(SUM(sl.integral), 0) +
               COALESCE(SUM(g.integral), 0) AS totalIntegral,
               s.week,
               s.title,
               s.quarter,
               s.id
        FROM t_study s
                 LEFT JOIN t_study_answer sa ON s.id = sa.studyId
                 LEFT JOIN t_study_induction si ON s.id = si.studyId
                 LEFT JOIN t_study_listen st ON s.id = st.studyId
                 LEFT JOIN t_study_look sk ON s.id = sk.studyId
                 LEFT JOIN t_study_pair sp ON s.id = sp.studyId
                 LEFT JOIN t_story_listen sl ON s.id = sl.studyId
                 LEFT JOIN t_game g ON s.id = g.studyId
        <where>
            s.disabled = 0
              and sa.disabled = 0
              and si.disabled = 0
              and st.disabled = 0
              and sk.disabled = 0
              and sp.disabled = 0
              and sl.disabled = 0
              and g.disabled = 0
            <if test="quarter != null and quarter != ''">
                and s.quarter = #{quarter}
            </if>
            <if test="type != null and quarter != ''">
                and s.type = #{type}
            </if>
        </where>
        GROUP BY s.week, s.title, s.quarter, s.id;
    </select>
</mapper>