44323
2023-11-14 ddbb38c54db9c3670e5ff53f4bf713525de1099d
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
<?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 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_payment where payStatus = 2 and 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="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 * from(
                         SELECT studentId, totalClassHours, name as courseName, laveClassHours,cashPayment as cashPayment,hasHours,appUserId,insertTime
                         ,coursePackageId
                         FROM (
                                  SELECT studentId, totalClassHours, name, laveClassHours,cashPayment, (totalClassHours - laveClassHours) AS hasHours,py.appUserId,py.insertTime
                                    ,coursePackageId
                                  FROM t_course_package_payment py
                                           LEFT JOIN t_course_package cp ON py.coursePackageId = cp.id
                                  UNION ALL
                                  SELECT studentId, SUM(totalClassHours) AS totalClassHours,'总计' as name, SUM(laveClassHours) AS laveClassHours, SUM(cashPayment) AS cashPayment,
                                         (SUM(totalClassHours) - SUM(laveClassHours)) AS hasHours,py.appUserId,py.insertTime,py.coursePackageId
                                  FROM t_course_package_payment py
                                           LEFT JOIN t_course_package cp ON py.coursePackageId = cp.id
                                  GROUP BY studentId
                                  ORDER BY studentId, length(name) desc ,totalClassHours
                              ) subquery
                     ) a
        <where>
            <if test="null != start and '' != start and null != end and '' != end">
                  a.insertTime between #{start} and #{end}
            </if>
            <if test="coursePackageIds != null and coursePackageIds.size()>0">
                AND a.coursePackageId IN
                <foreach collection="coursePackageIds" separator="," item="id" open="(" close=")">
                    #{id}
                </foreach>
            </if>
        </where>
 
    </select>
    <select id="pacQueryDto" resultType="map">
 
        SELECT
            coursePackageId,
            SUM( cashPayment ) AS cashPayment,
            SUM( totalClassHours ) AS totalClassHours,
            SUM( totalClassHours - laveClassHours ) AS hasHours,
            ROUND( SUM(( totalClassHours - laveClassHours ) * ( cashPayment / totalClassHours )), 2 ) AS lavePay,
            cp.`name` ,
            cp.province,
            cp.city,
            cp.storeId,cp.cityCode,cp.provinceCode,py.insertTime
        FROM
            t_course_package_payment py
                LEFT JOIN t_course_package cp ON py.coursePackageId = cp.id
        <where>
            <if test="storeIds != null and storeIds.size()>0">
                AND cp.id IN
                <foreach collection="storeIds" separator="," item="id" open="(" close=")">
                    #{id}
                </foreach>
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                py.insertTime between #{start} and #{end}
            </if>
            <if test="null != cityCode and '' != cityCode">
               and cityCode =#{cityCode}
            </if>
 
            <if test="null != provinceCode and '' != provinceCode">
                and provinceCode =#{provinceCode}
            </if>
 
            <if test="null != name and '' != name">
                and name like CONCAT('%', #{name}, '%')
            </if>
 
 
        </where>
        GROUP BY
            coursePackageId
 
 
 
 
    </select>
 
    <select id="listOne" resultType="com.dsh.course.entity.TCoursePackagePayment">
        select * from t_course_package_payment where 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>
 
    <update id="updateBytime">
        update  t_course_package_payment
            set laveClassHours = #{coursePackagePayment.laveClassHours},absencesNumber=#{coursePackagePayment.absencesNumber}
        where id = #{coursePackagePayment.id}
    </update>
</mapper>