guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?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="cn.stylefeng.guns.modular.business.mapper.MentalTestRecordMapper">
 
    <select id="myTestTopic" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO">
        (SELECT omt.id          AS id,
                omt.order_no    AS orderNo,
                o.id            AS mentalTestRecordId,
                o.create_time   AS createTime,
                o.answer_no     AS answerNo,
                omt.status_flag AS statusFlag,
                omt.is_back     AS isBack,
                omt.test_flag   AS testFlag,
                tt.id           AS topicId,
                tt.status_flag  AS topicStatus,
                tt.title,
                tt.class_id,
                tt.intro,
                tt.image,
                tt.test_type,
                tt.test_amount,
                tt.consult_one,
                tt.consult_amount,
                tt.test_people_num,
                tt.test_set_num
        FROM t_mental_test_record o
            LEFT JOIN t_order_mental_test omt ON o.answer_no = omt.order_no
            LEFT JOIN t_mental_test_topic tt ON o.topic_id = tt.id
        <where>
            <if test="userId != null">
                AND o.user_id = #{userId}
            </if>
            <if test="topicId != null">
                AND o.topic_id = #{topicId}
            </if>
        </where>
        )
        UNION ALL
        (SELECT o.id           AS id,
                o.order_no     AS orderNo,
                NULL           AS mentalTestRecordId,
                o.create_time  AS createTime,
                NULL           AS answerNo,
                o.status_flag  AS statusFlag,
                o.is_back      AS isBack,
                o.test_flag    AS testFlag,
                tt.id          AS topicId,
                tt.status_flag AS topicStatus,
                tt.title,
                tt.class_id,
                tt.intro,
                tt.image,
                tt.test_type,
                tt.test_amount,
                tt.consult_one,
                tt.consult_amount,
                tt.test_people_num,
                tt.test_set_num
        FROM t_order_mental_test o
            LEFT JOIN t_mental_test_topic tt ON o.goods_id = tt.id
        <where> order_no NOT IN (SELECT answer_no FROM t_mental_test_record)
            AND o.status_flag = 1
            <if test="userId != null">
                AND o.user_id = #{userId}
            </if>
            <if test="topicId != null">
                AND o.topic_id = #{topicId}
            </if>
        </where>
        )
    </select>
    <!--<select id="myTestTopic" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestTopicDTO">
        SELECT
            o.*,
            tt.status_flag topicStatus,
            tt.title,
            tt.class_id,
            tt.intro,
            tt.image,
            tt.test_type,
            tt.test_amount,
            tt.consult_one,
            tt.consult_amount,
            tt.test_people_num,
            tt.test_set_num
        FROM
            t_mental_test_record o
            LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
        <where>
            <if test="userId != null">
                AND o.user_id = #{userId}
            </if>
            <if test="topicId != null">
                AND o.topic_id = #{topicId}
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>-->
 
    <select id="myTestRecordTopicByMentalAppointmentId" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestRecordTopicDTO">
        SELECT
            o.*,
            tt.status_flag topicStatus,
            tt.title,
            tt.class_id,
            tt.intro,
            tt.image,
            tt.test_type,
            tt.test_amount,
            tt.consult_one,
            tt.consult_amount,
            tt.test_people_num,
            tt.test_set_num
        FROM
            t_mental_test_record o
            LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
        <where>
            <if test="mentalAppointmentId != null">
                AND o.mental_appointment_id = #{mentalAppointmentId}
            </if>
            <if test="mentalAppointmentIdList != null">
                AND o.mental_appointment_id IN
                <foreach collection="mentalAppointmentIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
 
    <select id="myTestOrder" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestMyTestOrderDTO">
        SELECT
            o.*,
            tt.id topicId,
            tt.status_flag topicStatus,
            tt.title,
            tt.class_id,
            tt.intro,
            tt.image,
            tt.test_type,
            tt.test_amount,
            tt.consult_one,
            tt.consult_amount,
            tt.test_people_num,
            tt.test_set_num
        FROM
            t_order_mental_test o
            LEFT JOIN t_mental_test_topic tt ON tt.id = o.goods_id
        <where>
            AND o.status_flag = 1 AND ( ( tt.test_type = 0 AND o.test_flag = 1 ) OR tt.test_type = 1 OR o.is_back = 1 )
            <if test="userId != null">
                AND o.user_id = #{userId}
            </if>
            <if test="topicId != null">
                AND o.goods_id = #{topicId}
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
 
    <select id="getPage" resultType="cn.stylefeng.guns.modular.business.dto.MentalTestRecordPageDTO">
        SELECT
            tt.*,
            o.create_time,
            tu.nick_name,
            tu.telephone
        FROM
            t_mental_test_record o
                LEFT JOIN t_mental_test_topic tt ON tt.id = o.topic_id
                LEFT JOIN toc_customer tu ON tu.customer_id = o.user_id
        <where>
            <if test="title != null and title != ''">
                AND tt.title LIKE CONCAT('%', #{title}, '%')
            </if>
            <if test="testType != null">
                AND tt.test_type = #{testType}
            </if>
            <if test="nickName != null and nickName != ''">
                AND tu.nick_name LIKE CONCAT('%', #{nickName}, '%')
            </if>
            <if test="telephone != null and telephone != ''">
                AND tu.telephone LIKE CONCAT('%', #{telephone}, '%')
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
 
</mapper>