puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?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.dsh.course.mapper.TCoursePackagePaymentMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dsh.course.entity.TCoursePackagePayment">
        <id column="id" property="id"/>
        <result column="appUserId" property="appUserId"/>
        <result column="studentId" property="studentId"/>
        <result column="coursePackageId" property="coursePackageId"/>
        <result column="payType" property="payType"/>
        <result column="classHours" property="classHours"/>
        <result column="cashPayment" property="cashPayment"/>
        <result column="playPaiCoin" property="playPaiCoin"/>
        <result column="totalClassHours" property="totalClassHours"/>
        <result column="laveClassHours" property="laveClassHours"/>
        <result column="absencesNumber" property="absencesNumber"/>
        <result column="payUserType" property="payUserType"/>
        <result column="payStatus" property="payStatus"/>
        <result column="orderNumber" property="orderNumber"/>
        <result column="payUserId" property="payUserId"/>
        <result column="status" property="status"/>
        <result column="withdrawalTime" property="withdrawalTime"/>
        <result column="certificate" property="certificate"/>
        <result column="state" property="state"/>
        <result column="insertTime" property="insertTime"/>
    </resultMap>
    <update id="updateUseTime">
        update t_course_package_payment
        set useTime = #{date}
        where id = #{id}
    </update>
    <update id="updateHoursById">
        update t_course_package_payment set classHours =classHours+#{i},laveClassHours =laveClassHours+#{i} where id =#{id}
    </update>
    <update id="updateHoursById1">
        update t_course_package_payment set totalClassHours = totalClassHours+#{i},classHours =classHours+#{i},laveClassHours =laveClassHours+#{i} where id =#{id}
    </update>
 
    <select id="queryCountNumber" resultType="int">
        SELECT
        count( 1 ) AS num
        FROM (
          SELECT studentId FROM t_course_package_payment WHERE payStatus = 2 AND state = 1 and coursePackageId = #{coursePackageId} GROUP BY studentId
        ) AS aa
    </select>
 
    <select id="getCoursePackagePaymentByCode" resultType="com.dsh.course.entity.TCoursePackagePayment">
        select * from t_course_package_payment where 1=1
        <if test="code != null">
            and `code` = #{code}
        </if>
    </select>
 
    <select id="billingDataRequestVo" resultType="com.dsh.course.model.BillingRequest">
        SELECT DATE_FORMAT(insertTime, '%m-%d %H:%i')as `time`,IFNULL(playPaiCoin, cashPayment) AS amount
        from t_course_package_payment
        where payStatus = 2 and state = 1 and payType in (1,2)
        <if test="null != monthStart and '' != monthStart and null != monthEnd and '' != monthEnd">
            and DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') between #{monthStart} and #{monthEnd}
        </if>
        <if test="null != appUserId and '' != appUserId ">
            and appUserId = #{appUserId}
        </if>
    </select>
 
 
    <select id="queryRegistrationRecord" resultType="map">
        select
        CAST(id AS CHAR(20)) as id,
        appUserId,
        studentId,
        DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i') as insertTime,
        totalClassHours,
        laveClassHours,
        absencesNumber,
        `status`
        from t_course_package_order_student where state = 1
        <if test="null != coursePackageId">
            and coursePackageId = #{coursePackageId}
        </if>
        <if test="null != userIds">
            and appUserId in
            <foreach collection="userIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != studentIds">
            and studentId in
            <foreach collection="studentIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        order by
        CASE
        WHEN laveClassHours &lt; 3 THEN 0
        ELSE 1
        END, insertTime DESC
 
    </select>
 
    <select id="queryRegistrationRecord1" resultType="map">
        select
        CAST(id AS CHAR(20)) as id,
        appUserId,
        studentIds,
        DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i') as insertTime,
        `status`
        from t_course_package_order where state = 1
        <if test="null != coursePackageId">
            and coursePackageId = #{coursePackageId}
        </if>
        <if test="null != userIds">
            and appUserId in
            <foreach collection="userIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != studentIds">
            and studentId in
            <foreach collection="studentIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        order by
        insertTime DESC
    </select>
 
 
 
    <select id="queryWalkInStudentList" resultType="map">
        select
        CAST(id AS CHAR(20)) as id,
        appUserId,
        studentId
        from t_course_package_payment where payStatus = 2 and state = 1
        <if test="null != coursePackageId">
            and coursePackageId = #{coursePackageId}
        </if>
        <if test="null != coursePackagePaymentId">
            and id not in
            <foreach collection="coursePackagePaymentId" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != userIds">
            and appUserId in
            <foreach collection="userIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="null != studentIds">
            and studentId in
            <foreach collection="studentIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        order by insertTime desc
    </select>
    <select id="getStudentIds" resultType="java.lang.Integer">
        SELECT studentId
        FROM t_course_package_payment
        WHERE appUserId = #{appId} AND id != #{id} and coursePackageId=#{classId}
 
 
    </select>
    <select id="getStudentTotal" resultType="map">
        select
        appUserId,
        studentId,
        coursePackageId,
        count(1) as number
        from (
            select
            appUserId,
            studentId,
            coursePackageId
            from t_course_package_scheduling
            where `status` != 4
            <if test="null != appUserIds">
                and appUserId in
                <foreach collection="appUserIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(classDate, '%Y-%m-%d') between #{start} and #{end}
            </if>
            order by classDate
        ) as a
        group by a.appUserId, a.studentId, a.coursePackageId
    </select>
    <select id="pacQueryDto" resultType="map">
        select
        id,
        name,
        province,
        city,
        storeId,
        count(1) as number
        from (
            select
            b.id,
            b.`name`,
            b.province,
            b.city,
            b.storeId
            from t_course_package_scheduling a
            left join t_course_package b on (a.coursePackageId = b.id)
            where a.`status` != 4 and b.status != 4 and b.auditStatus = 2 and b.state = 1
            <if test="null != storeIds and storeIds.size() > 0">
                and b.storeId in
                <foreach collection="storeIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(a.classDate, '%Y-%m-%d') between #{start} and #{end}
            </if>
            <if test="null != name and '' != name">
                and b.name like CONCAT('%', #{name}, '%')
            </if>
            order by classDate
        ) as aa group by aa.id, aa.name, aa.province, aa.city, aa.storeId
    </select>
 
    <select id="listOne" resultType="com.dsh.course.entity.TCoursePackagePayment">
        select a.*,b.coursePackageTypeId as type from t_course_package_order_student a
        left join t_course_package b on (a.coursePackageId = b.id)
        where a.appUserId in
        <foreach collection="ids" separator="," open="(" item="id" close=")">#{id}</foreach>
    </select>
    <select id="queryStore" resultType="java.lang.Integer">
        SELECT
            tc.storeId
        FROM
            t_payment_competition pc
                LEFT JOIN t_competition  tc on pc.competitionId = tc.id
        WHERE pc.code=#{code}
    </select>
    <select id="queryRegistrationRecord3" resultType="java.util.Map">
        SELECT        CAST(id AS CHAR(20)) as id,
                      appUserId, studentId,
                      DATE_FORMAT(classDate, '%Y-%m-%d %H:%i') as insertTime,
                      DATE_FORMAT(DATE(MIN(classDate)), '%Y-%m-%d') AS totalClassHours,
                      DATE_FORMAT( DATE(MAX(endDate)), '%Y-%m-%d') AS laveClassHours,
            '' as absencesNumber,
            7 as status,
            3 as type
        FROM t_course_package_scheduling where type = 3
        GROUP BY coursePackageId, studentId;
 
 
    </select>
 
    <update id="updateBytime">
        update  t_course_package_payment
            set laveClassHours = #{coursePackagePayment.laveClassHours},absencesNumber=#{coursePackagePayment.absencesNumber}
        where id = #{coursePackagePayment.id}
    </update>
</mapper>