浏览代码

声部查询问题修改

liweifan 3 年之前
父节点
当前提交
528a16dc83

+ 59 - 57
cooleshow-user/user-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -131,63 +131,65 @@
     <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
         select t.* from subject t
         join (
-        <trim prefixOverrides="union all">
-            <if test="type == null or type =='MUSIC'">
-                union all
-                (
-                    select
-                        a.music_subject_ as subject_id_
-                    from music_sheet a
-                    join music_sheet_purchase_record a1 on a.id_ = a1.music_sheet_id_
-                    where a1.student_id_ = #{userId} and a1.order_status_ = 'PAID'
-                    GROUP BY a.music_subject_
-                )
-            </if>
-            <if test="type == null or type =='VIDEO'">
-                union all
-                (
-                    select
-                        a.lesson_subject_ as subject_id_
-                    from video_lesson_group a
-                    join video_lesson_purchase_record a1 on a.id_ = a1.video_lesson_group_id_
-                    where a1.student_id_ = #{userId}
-                    GROUP BY a.lesson_subject_
-                )
-            </if>
-            <if test="type == null or type =='PINAO_ROOM'">
-                union all
-                (
-                    select
-                        a.subject_id_ as subject_id_
-                    from course_group a
-                    join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
-                    where a.type_ = 'PIANO_ROOM_CLASS' and a1.user_id_ = #{userId}
-                    GROUP BY a.subject_id_
-                )
-            </if>
-            <if test="type == null or type =='PRACTICE'">
-                union all
-                (
-                    select
-                        a.subject_id_ as subject_id_
-                    from course_group a
-                    join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
-                    where a.type_ = 'PRACTICE' and a1.user_id_ = #{userId}
-                    GROUP BY a.subject_id_
-                )
-            </if>
-            <if test="type == null or type =='LIVE'">
-                union all
-                (
-                    select
-                        a.subject_id_ as subject_id_
-                    from course_group a
-                    join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
-                    where a.type_ = 'LIVE' and a1.user_id_ = #{userId}
-                    GROUP BY a.subject_id_
-                )
-            </if>
-        </trim>
+            select a.subject_id_ from (
+                <trim prefixOverrides="union all">
+                    <if test="type == null or type =='MUSIC'">
+                        union all
+                        (
+                            select
+                                a.music_subject_ as subject_id_
+                            from music_sheet a
+                            join music_sheet_purchase_record a1 on a.id_ = a1.music_sheet_id_
+                            where a1.student_id_ = #{userId} and a1.order_status_ = 'PAID'
+                            GROUP BY a.music_subject_
+                        )
+                    </if>
+                    <if test="type == null or type =='VIDEO'">
+                        union all
+                        (
+                            select
+                                a.lesson_subject_ as subject_id_
+                            from video_lesson_group a
+                            join video_lesson_purchase_record a1 on a.id_ = a1.video_lesson_group_id_
+                            where a1.student_id_ = #{userId}
+                            GROUP BY a.lesson_subject_
+                        )
+                    </if>
+                    <if test="type == null or type =='PINAO_ROOM'">
+                        union all
+                        (
+                            select
+                                a.subject_id_ as subject_id_
+                            from course_group a
+                            join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
+                            where a.type_ = 'PIANO_ROOM_CLASS' and a1.user_id_ = #{userId}
+                            GROUP BY a.subject_id_
+                        )
+                    </if>
+                    <if test="type == null or type =='PRACTICE'">
+                        union all
+                        (
+                            select
+                                a.subject_id_ as subject_id_
+                            from course_group a
+                            join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
+                            where a.type_ = 'PRACTICE' and a1.user_id_ = #{userId}
+                            GROUP BY a.subject_id_
+                        )
+                    </if>
+                    <if test="type == null or type =='LIVE'">
+                        union all
+                        (
+                            select
+                                a.subject_id_ as subject_id_
+                            from course_group a
+                            join course_schedule_student_payment a1 on a.id_ = a1.course_group_id_
+                            where a.type_ = 'LIVE' and a1.user_id_ = #{userId}
+                            GROUP BY a.subject_id_
+                        )
+                    </if>
+                </trim>
+            ) a group by a.subject_id_
         ) a on t.id_ = a.subject_id_
         where t.parent_subject_id_ != 0
         and not exists(

+ 25 - 23
cooleshow-user/user-biz/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -31,38 +31,40 @@
     <select id="subjectSelect" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
         select t.* from subject t
         join (
-        <trim prefixOverrides="union all">
-            <if test="type == null or type =='MUSIC'">
-                union all
-                (select a.music_subject_ as subject_id_ from music_sheet a
+            select a.subject_id_ from (
+            <trim prefixOverrides="union all">
+                <if test="type == null or type =='MUSIC'">
+                    union all
+                    (select a.music_subject_ as subject_id_ from music_sheet a
                     where a.del_flag_ = 0 and a.state_ = 1
                     GROUP BY a.music_subject_)
-            </if>
-            <if test="type == null or type =='VIDEO'">
-                union all
-                (select a.lesson_subject_ as subject_id_ from video_lesson_group a
+                </if>
+                <if test="type == null or type =='VIDEO'">
+                    union all
+                    (select a.lesson_subject_ as subject_id_ from video_lesson_group a
                     where a.audit_status_ = 'PASS' and a.shelves_flag_ = 1
                     GROUP BY a.lesson_subject_)
-            </if>
-            <if test="type == null or type =='PINAO_ROOM'">
-                union all
-                (select a.subject_id_ as subject_id_ from course_group a
+                </if>
+                <if test="type == null or type =='PINAO_ROOM'">
+                    union all
+                    (select a.subject_id_ as subject_id_ from course_group a
                     where a.type_ = 'PIANO_ROOM_CLASS' and a.status_ in ('ING','COMPLETE','APPLY')
                     GROUP BY a.subject_id_)
-            </if>
-            <if test="type == null or type =='PRACTICE'">
-                union all
-                (select a.subject_id_ as subject_id_ from course_group a
+                </if>
+                <if test="type == null or type =='PRACTICE'">
+                    union all
+                    (select a.subject_id_ as subject_id_ from course_group a
                     where a.type_ = 'PRACTICE' and a.status_ in ('ING','COMPLETE','APPLY')
                     GROUP BY a.subject_id_)
-            </if>
-            <if test="type == null or type =='LIVE'">
-                union all
-                (select a.subject_id_ as subject_id_ from course_group a
-                    where a.type_ = 'LIVE' and a.status_ in ('ING','COMPLETE','APPLY')
+                </if>
+                <if test="type == null or type =='LIVE'">
+                    union all
+                    (select a.subject_id_ as subject_id_ from course_group a
+                    where a.type_ = 'LIVE' and a.status_ in ('APPLY')
                     GROUP BY a.subject_id_)
-            </if>
-        </trim>
+                </if>
+            </trim>
+            ) a group by a.subject_id_
         ) a on t.id_ = a.subject_id_
         where t.parent_subject_id_ != 0
     </select>

+ 24 - 22
cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -178,28 +178,30 @@
     <select id="querySubjectItem" resultType="com.yonge.cooleshow.biz.dal.entity.Subject">
         select t.* from subject t
         join (
-            <trim prefixOverrides="union all">
-                <if test="type == null or type =='MUSIC'">
-                    union all
-                    (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY music_subject_)
-                </if>
-                <if test="type == null or type =='VIDEO'">
-                    union all
-                    (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY lesson_subject_)
-                </if>
-                <if test="type == null or type =='PINAO_ROOM'">
-                    union all
-                    (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ = #{userId} GROUP BY subject_id_)
-                </if>
-                <if test="type == null or type =='PRACTICE'">
-                    union all
-                    (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ = #{userId} GROUP BY subject_id_)
-                </if>
-                <if test="type == null or type =='LIVE'">
-                    union all
-                    (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId} GROUP BY subject_id_)
-                </if>
-            </trim>
+            select a.subject_id_ from (
+                <trim prefixOverrides="union all">
+                    <if test="type == null or type =='MUSIC'">union all
+                        (select music_subject_ as subject_id_ from music_sheet where user_id_ = #{userId} GROUP BY
+                        music_subject_)
+                    </if>
+                    <if test="type == null or type =='VIDEO'">
+                        union all
+                        (select lesson_subject_ as subject_id_ from video_lesson_group where teacher_id_ = #{userId} GROUP BY lesson_subject_)
+                    </if>
+                    <if test="type == null or type =='PINAO_ROOM'">
+                        union all
+                        (select subject_id_ as subject_id_ from course_group where type_ = 'PIANO_ROOM_CLASS' and teacher_id_ = #{userId} GROUP BY subject_id_)
+                    </if>
+                    <if test="type == null or type =='PRACTICE'">
+                        union all
+                        (select subject_id_ as subject_id_ from course_group where type_ = 'PRACTICE' and teacher_id_ = #{userId} GROUP BY subject_id_)
+                    </if>
+                    <if test="type == null or type =='LIVE'">
+                        union all
+                        (select subject_id_ as subject_id_ from course_group where type_ = 'LIVE' and teacher_id_ = #{userId} GROUP BY subject_id_)
+                    </if>
+                </trim>
+            ) a group by a.subject_id_
         ) a on t.id_ = a.subject_id_
         where t.parent_subject_id_ != 0
         and not exists(