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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?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.CounsellingOrderReservationMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.stylefeng.guns.modular.business.entity.CounsellingOrderReservation">
        <id column="id" property="id" />
        <result column="counselling_info_id" property="counsellingInfoId" />
        <result column="user_id" property="userId" />
        <result column="consultant_user_id" property="consultantUserId" />
        <result column="companion_user_id" property="companionUserId" />
        <result column="counselling_order_id" property="counsellingOrderId" />
        <result column="reservation_begin_time" property="reservationBeginTime" />
        <result column="reservation_end_time" property="reservationEndTime" />
        <result column="stauts" property="stauts" />
        <result column="create_time" property="createTime" />
        <result column="service_begin_time" property="serviceBeginTime" />
        <result column="service_end_time" property="serviceEndTime" />
        <result column="service_approve_time" property="serviceApproveTime" />
        <result column="servie_complete_time" property="servieCompleteTime" />
        <result column="consume_course_hour" property="consumeCourseHour" />
        <result column="reservation_type" property="reservationType"/>
        <result column="counsellingInfoName" property="counsellingInfoName"/>
        <result column="userName" property="userName"/>
        <result column="workNum" property="workNum"/>
        <result column="phone" property="phone"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, counselling_info_id, user_id, consultant_user_id, companion_user_id, counselling_order_id, reservation_begin_time, reservation_end_time, stauts, create_time, service_begin_time, service_end_time, service_approve_time, servie_complete_time, consume_course_hour
    </sql>
 
    <select id="findPage" resultMap="BaseResultMap">
        SELECT tcor.*,tco.phone,tc.nick_name userName,tcus.nick_name counsellingInfoName,
        (
        SELECT count(1) FROM t_counselling_reservation_work WHERE is_delete = 0 and counselling_order_reservation_id = tcor.id
        ) workNum
        FROM t_counselling_order_reservation tcor
        INNER JOIN toc_customer tc on tc.customer_id = tcor.user_id
        INNER JOIN t_counselling_info tci on tci.id = tcor.counselling_info_id
        INNER JOIN toc_customer tcus on tcus.customer_id = tci.user_id
        INNER JOIN t_counselling_user tco on tco.counselling_info_id = tcor.counselling_info_id and tco.user_id = tcor.user_id
        <where>
            tcor.stauts !=5
            <if test="params.stauts != null">
                AND tcor.stauts = #{params.stauts}
            </if>
            <if test="params.userName != null and params.userName != ''">
                AND tc.nick_name LIKE CONCAT('%',#{params.userName},'%')
            </if>
            <if test="params.counsellingInfoName != null and params.counsellingInfoName != ''">
                AND tcus.nick_name LIKE CONCAT('%',#{params.counsellingInfoName},'%')
            </if>
            <if test="params.phone != null and params.phone != ''">
                AND tco.phone  LIKE CONCAT('%',#{params.phone},'%')
            </if>
            <if test="params.searchBeginTime != null and params.searchBeginTime != ''">
                AND tcor.reservation_begin_time >= #{params.searchBeginTime}
            </if>
            <if test="params.searchEndTime != null and params.searchEndTime != ''">
                AND tcor.reservation_end_time &lt;= #{params.searchEndTime}
            </if>
            <if test="params.reservationType != null">
                AND tcor.reservation_type = #{params.reservationType}
            </if>
            <if test="params.counsellingInfoId != null">
                AND tcor.counselling_info_id = #{params.counsellingInfoId}
            </if>
            <if test="params.counsellingOrderId != null">
                AND tcor.counselling_order_id = #{params.counsellingOrderId}
            </if>
            <if test="params.customerId != null">
                AND tcor.user_id = #{params.customerId}
            </if>
        </where>
        ORDER BY tcor.reservation_begin_time DESC
    </select>
 
 
    <select id="findWorkPage" resultMap="BaseResultMap">
        SELECT tcor.*,tco.phone,tc.nick_name userName,tcus.nick_name counsellingInfoName FROM t_counselling_order_reservation tcor
        INNER JOIN toc_customer tc on tc.customer_id = tcor.user_id
        INNER JOIN t_counselling_info tci on tci.id = tcor.counselling_info_id
        INNER JOIN toc_customer tcus on tcus.customer_id = tci.user_id
        INNER JOIN t_counselling_user tco on tco.counselling_info_id = tcor.counselling_info_id and tco.user_id = tcor.user_id
        <where>
            <if test="params.stauts != null">
                AND tcor.stauts = #{params.stauts}
            </if>
            <if test="params.userName != null and params.userName != ''">
                AND tc.nick_name LIKE CONCAT('%',#{params.userName},'%')
            </if>
            <if test="params.counsellingInfoName != null and params.counsellingInfoName != ''">
                AND tcus.nick_name LIKE CONCAT('%',#{params.counsellingInfoName},'%')
            </if>
            <if test="params.phone != null and params.phone != ''">
                AND tco.phone  LIKE CONCAT('%',#{params.phone},'%')
            </if>
            <if test="params.searchBeginTime != null and params.searchBeginTime != ''">
                AND tcor.reservation_begin_time >= #{params.searchBeginTime}
            </if>
            <if test="params.searchEndTime != null and params.searchEndTime != ''">
                AND tcor.reservation_end_time &lt;= #{params.searchEndTime}
            </if>
            <if test="params.reservationType != null">
                AND tcor.reservation_type = #{params.reservationType}
            </if>
            <if test="params.counsellingInfoId != null">
                AND tcor.counselling_info_id = #{params.counsellingInfoId}
            </if>
            <if test="params.counsellingOrderId != null">
                AND tcor.counselling_order_id = #{params.counsellingOrderId}
            </if>
            <if test="params.customerId != null">
                AND (tcor.consultant_user_id = #{params.customerId} or tcor.companion_user_id = #{params.customerId}
                    or tci.user_id = #{params.customerId} )
            </if>
            <if test="params.searchType != null and params.searchType == 1">
                AND tcor.stauts IN (2,3,4)
            </if>
        </where>
        ORDER BY tcor.reservation_begin_time DESC
 
    </select>
    <select id="findOrderReservationByUserIdPage"
            resultType="cn.stylefeng.guns.modular.business.entity.CounsellingOrderReservation">
        SELECT tcor.*,tco.phone,tc.nick_name userName,tcus.nick_name counsellingInfoName FROM t_counselling_order_reservation tcor
        INNER JOIN toc_customer tc on tc.customer_id = tcor.user_id
        INNER JOIN t_counselling_info tci on tci.id = tcor.counselling_info_id
        INNER JOIN toc_customer tcus on tcus.customer_id = tci.user_id
        INNER JOIN t_counselling_user tco on tco.counselling_info_id = tcor.counselling_info_id and tco.user_id = tcor.user_id
        <where>
            <if test="params.stauts != null">
                AND tcor.stauts = #{params.stauts}
            </if>
            <if test="params.customerId != null and params.customerId != ''">
                AND tc.customer_id = #{params.customerId}
            </if>
            <if test="params.counsellingInfoName != null and params.counsellingInfoName != ''">
                AND tcus.nick_name LIKE CONCAT('%',#{params.counsellingInfoName},'%')
            </if>
 
        </where>
        ORDER BY tcor.reservation_begin_time DESC
 
    </select>
    <select id="getCounsellingNumTotalByUserId"
            resultType="cn.stylefeng.guns.modular.business.dto.UserCounsellingTotalDTO"
            parameterType="cn.stylefeng.guns.modular.business.dto.request.UserCounsellingOrderReservationRequestDTO">
        SELECT IFNUll(SUM(tco.class_hours),0) totalNum,IFNULL(SUM(tco.residue_class_hours),0) residueClassHoursNum  FROM t_counselling_user tco
        INNER JOIN t_counselling_info tci ON tci.id = tco.counselling_info_id
        INNER JOIN toc_customer tc ON tc.customer_id = tci.user_id
        <where>
            <if test="counsellingInfoName != null and counsellingInfoName != ''">
                AND tc.nick_name LIKE CONCAT('%',#{counsellingInfoName},'%')
            </if>
            <if test="customerId != null and customerId != ''">
                AND tco.user_id = #{customerId}
            </if>
        </where>
 
 
    </select>
    <select id="findReservationPage"
            resultType="cn.stylefeng.guns.modular.business.entity.CounsellingOrderReservation">
        SELECT tcor.*,tco.phone,tc.nick_name userName,tcus.nick_name counsellingInfoName,
        (
        SELECT count(1) FROM t_counselling_reservation_work WHERE is_delete = 0 and counselling_order_reservation_id = tcor.id
        ) workNum
        FROM t_counselling_order_reservation tcor
        INNER JOIN t_counselling_order  tcord ON tcord.id = tcor.counselling_order_id AND tcord.status_flag NOT IN (9,10) 
        INNER JOIN toc_customer tc on tc.customer_id = tcor.user_id
        INNER JOIN t_counselling_info tci on tci.id = tcor.counselling_info_id
        INNER JOIN toc_customer tcus on tcus.customer_id = tci.user_id
        INNER JOIN t_counselling_user tco on tco.counselling_info_id = tcor.counselling_info_id and tco.user_id = tcor.user_id
        <where>
            AND ((tcor.reservation_type = 1 AND tcor.stauts != 5) OR (tcor.reservation_type = 2))
            <if test="params.stauts != null">
                AND tcor.stauts = #{params.stauts}
            </if>
            <if test="params.userName != null and params.userName != ''">
                AND tc.nick_name LIKE CONCAT('%',#{params.userName},'%')
            </if>
            <if test="params.counsellingInfoName != null and params.counsellingInfoName != ''">
                AND tcus.nick_name LIKE CONCAT('%',#{params.counsellingInfoName},'%')
            </if>
            <if test="params.phone != null and params.phone != ''">
                AND tco.phone  LIKE CONCAT('%',#{params.phone},'%')
            </if>
            <if test="params.searchBeginTime != null and params.searchBeginTime != ''">
                AND tcor.reservation_begin_time >= #{params.searchBeginTime}
            </if>
            <if test="params.searchEndTime != null and params.searchEndTime != ''">
                AND tcor.reservation_end_time &lt;= #{params.searchEndTime}
            </if>
            <if test="params.reservationType != null">
                AND tcor.reservation_type = #{params.reservationType}
            </if>
            <if test="params.counsellingInfoId != null">
                AND tcor.counselling_info_id = #{params.counsellingInfoId}
            </if>
            <if test="params.counsellingOrderId != null">
                AND tcor.counselling_order_id = #{params.counsellingOrderId}
            </if>
            <if test="params.customerId != null">
                AND tcor.user_id = #{params.customerId}
            </if>
        </where>
        ORDER BY tcor.create_time DESC
 
    </select>
 
</mapper>