admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
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
<?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.yeshi.fanli.dao.mybatis.redpack.RedPackDetailMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.redpack.RedPackDetail">
    <id column="rpd_id" property="id" jdbcType="BIGINT"/>
    <result column="rpd_identify_code" property="identifyCode" jdbcType="VARCHAR"/>
    <result column="rpd_uid" property="uid" jdbcType="BIGINT"/>
    <result column="rpd_money" property="money" jdbcType="DECIMAL"/>
    <result column="rpd_title" property="title" jdbcType="VARCHAR"/>
    <result column="rpd_desc_info" property="descInfo" jdbcType="VARCHAR"/>
    <result column="rpd_remark" property="remark" jdbcType="VARCHAR"/>
    <result column="rpd_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="rpd_display" property="display" jdbcType="VARCHAR"/>
    <result column="rpd_type" property="type" typeHandler="com.yeshi.fanli.util.mybatishandler.redpack.RedPackDetailTypeEnumHandler"/>
  </resultMap>
  
  <resultMap id="UserMonthMoneyMap" type="com.yeshi.fanli.vo.redpack.RedPackMonthVO">
        <result column="expend" property="expend" jdbcType="DECIMAL" />
        <result column="income" property="income" jdbcType="DECIMAL" />
        <result column="dateFormate" property="dateFormate" jdbcType="VARCHAR" />
  </resultMap>
  
  <sql id="Base_Column_List">rpd_id,rpd_identify_code,rpd_uid,rpd_money,rpd_title,rpd_type,rpd_desc_info,rpd_remark,rpd_create_time,rpd_display</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_red_pack_detail where rpd_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_red_pack_detail where rpd_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.redpack.RedPackDetail" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_red_pack_detail (rpd_id,rpd_identify_code,rpd_uid,rpd_money,rpd_title,rpd_type,rpd_desc_info,rpd_remark,rpd_create_time,rpd_display) values (#{id,jdbcType=BIGINT},,#{identifyCode,jdbcType=VARCHAR}#{uid,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{title,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{descInfo,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{display,jdbcType=VARCHAR})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.redpack.RedPackDetail" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_red_pack_detail
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">rpd_id,</if>
      <if test="identifyCode != null">rpd_identify_code,</if>
      <if test="uid != null">rpd_uid,</if>
      <if test="money != null">rpd_money,</if>
      <if test="title != null">rpd_title,</if>
      <if test="type != null">rpd_type,</if>
      <if test="descInfo != null">rpd_desc_info,</if>
      <if test="remark != null">rpd_remark,</if>
      <if test="createTime != null">rpd_create_time,</if>
      <if test="display != null">rpd_display,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="identifyCode != null">#{identifyCode,jdbcType=VARCHAR},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="money != null">#{money,jdbcType=DECIMAL},</if>
      <if test="title != null">#{title,jdbcType=VARCHAR},</if>
      <if test="type != null">#{type,jdbcType=VARCHAR},</if>
      <if test="descInfo != null">#{descInfo,jdbcType=VARCHAR},</if>
      <if test="remark != null">#{remark,jdbcType=VARCHAR},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="display != null">#{display,jdbcType=VARCHAR},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.redpack.RedPackDetail">update yeshi_ec_red_pack_detail set rpd_identify_code = #{identifyCode,jdbcType=VARCHAR},rpd_uid = #{uid,jdbcType=BIGINT},rpd_money = #{money,jdbcType=DECIMAL},rpd_title = #{title,jdbcType=VARCHAR},rpd_type = #{type,jdbcType=VARCHAR},rpd_desc_info = #{descInfo,jdbcType=VARCHAR},rpd_remark = #{remark,jdbcType=VARCHAR},rpd_create_time = #{createTime,jdbcType=TIMESTAMP} where rpd_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.redpack.RedPackDetail">update yeshi_ec_red_pack_detail
    <set>
      <if test="identifyCode != null">rpd_identify_code=#{identifyCode,jdbcType=VARCHAR},</if>
      <if test="uid != null">rpd_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="money != null">rpd_money=#{money,jdbcType=DECIMAL},</if>
      <if test="title != null">rpd_title=#{title,jdbcType=VARCHAR},</if>
      <if test="type != null">rpd_type=#{type,jdbcType=VARCHAR},</if>
      <if test="descInfo != null">rpd_desc_info=#{descInfo,jdbcType=VARCHAR},</if>
      <if test="remark != null">rpd_remark=#{remark,jdbcType=VARCHAR},</if>
      <if test="createTime != null">rpd_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="display != null">rpd_display=#{display,jdbcType=VARCHAR},</if>
    </set> where rpd_id = #{id,jdbcType=BIGINT}
  </update>
  
  <select id="getByIdentifyCode" resultMap="BaseResultMap">
      SELECT * FROM `yeshi_ec_red_pack_detail` t
    WHERE t.`rpd_identify_code` = #{identifyCode}
  </select>
  
  <select id="countUseMoneyByDate" resultType="java.math.BigDecimal">
      SELECT IFNULL(SUM(t.`rpd_money`),0) FROM `yeshi_ec_red_pack_detail` t
    WHERE t.rpd_display = 1 AND t.`rpd_money` <![CDATA[<]]> 0 AND t.`rpd_uid` = #{uid} AND t.`rpd_type` <![CDATA[<>]]> 'violation'
        <if test="dateType == 1"> <!-- 今日  -->
            AND TO_DAYS(t.`rpd_create_time`) =  TO_DAYS(NOW());
        </if>
        <if test="dateType == 2"> <!-- 昨日  -->
          AND TO_DAYS(NOW()) - TO_DAYS(t.`rpd_create_time`) = 1
        </if>
           <if test="dateType == 3"> <!-- 本月  -->
          AND DATE_FORMAT(t.`rpd_create_time`, '%Y%m') =DATE_FORMAT(CURDATE(), '%Y%m')
        </if>
        <if test="dateType == 4"> <!--上月  -->
          AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(t.`rpd_create_time`, '%Y%m')) = 1
        </if>
  </select>
  
  
  <select id="countAddMoneyByDate" resultType="java.math.BigDecimal">
      SELECT IFNULL(SUM(t.`rpd_money`),0) FROM `yeshi_ec_red_pack_detail` t
    WHERE t.rpd_display = 1 AND t.`rpd_money` <![CDATA[>]]> 0  AND t.`rpd_uid` = #{uid} AND  t.`rpd_type`<![CDATA[<>]]>'refund'
        <if test="dateType == 1"> <!-- 今日  -->
            AND TO_DAYS(t.`rpd_create_time`) =  TO_DAYS(NOW());
        </if>
        <if test="dateType == 2"> <!-- 昨日  -->
          AND TO_DAYS(NOW()) - TO_DAYS(t.`rpd_create_time`) = 1
        </if>
           <if test="dateType == 3"> <!-- 本月  -->
          AND DATE_FORMAT(t.`rpd_create_time`, '%Y%m') =DATE_FORMAT(CURDATE(), '%Y%m')
        </if>
        <if test="dateType == 4"> <!--上月  -->
          AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(t.`rpd_create_time`, '%Y%m')) = 1
        </if>
  </select>
  
  <select id="selectByMaxCreateTime" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_red_pack_detail t
    WHERE t.rpd_display = 1 AND t.`rpd_uid`=#{uid} AND t.`rpd_create_time`<![CDATA[<=]]> #{date} 
    ORDER BY t.`rpd_create_time` DESC,t.rpd_id DESC
    LIMIT #{count}
  </select>
  
  <select id="selectByUidWithIndexId" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" />    FROM yeshi_ec_red_pack_detail t 
    WHERE t.rpd_display = 1 AND t.`rpd_uid`=#{uid}
        AND t.`rpd_create_time`<![CDATA[<=]]>(SELECT rpd_create_time FROM yeshi_ec_red_pack_detail WHERE rpd_id =#{id})
    ORDER BY t.`rpd_create_time` DESC,t.rpd_id DESC
    LIMIT #{count}
  </select>
  
  <select id="selectMonthMoneyByUid" resultMap="UserMonthMoneyMap">
        <foreach collection="dateFormat" index="index" item="item"
            separator="UNION ALL">
            <trim prefix="(" suffix=")">
                SELECT c.time AS dateFormate , IF(a.money IS NULL,0,a.money) AS income ,IF(b.money IS NULL,0,b.money) AS expend
                FROM (SELECT  #{item} AS `time`) c 
                LEFT JOIN (SELECT DATE_FORMAT(d.`rpd_create_time`,'%Y-%m') AS `time`,SUM(d.`rpd_money`)AS money
                               FROM `yeshi_ec_red_pack_detail` d
                               WHERE d.rpd_display = 1 AND d.`rpd_uid`=#{uid} AND  d.`rpd_money`<![CDATA[>=]]>0 AND DATE_FORMAT(d.`rpd_create_time`,'%Y-%m')=#{item} 
                               GROUP BY DATE_FORMAT(d.`rpd_create_time`,'%Y-%m')
                               ) a ON a.time=c.time
 
                LEFT JOIN(SELECT DATE_FORMAT(d.`rpd_create_time`,'%Y-%m') AS `time`,SUM(d.`rpd_money`) AS money
                              FROM `yeshi_ec_red_pack_detail` d
                            WHERE d.rpd_display = 1 AND d.`rpd_uid`=#{uid} AND d.`rpd_money` <![CDATA[<]]>0 AND DATE_FORMAT(d.`rpd_create_time`,'%Y-%m')=#{item} 
                              GROUP BY DATE_FORMAT(d.`rpd_create_time`,'%Y-%m')
                              ) b ON c.time=b.time
           </trim>
       </foreach>
  </select>
  
  <select id="selectCountByUid" resultType="java.lang.Long"  parameterType="java.lang.Long">
    SELECT count(rpd_id) FROM yeshi_ec_red_pack_detail
    WHERE rpd_display = 1 AND rpd_uid=#{uid}
  </select>
  
  <select id="selectMonthCountByUid" resultType="java.lang.Integer">
    SELECT COUNT(*) FROM 
            (SELECT * FROM yeshi_ec_red_pack_detail d 
             WHERE d.rpd_display = 1 AND d.`rpd_uid`=#{uid} AND d.`rpd_create_time` <![CDATA[<=]]> #{date} 
             GROUP BY DATE_FORMAT(d.`rpd_create_time`,'%y-%m')
             ) a
  </select>
  
  <select id="selectCountByUidAndMaxCreateTime" resultType="java.lang.Long">
    SELECT count(rpd_id) FROM yeshi_ec_red_pack_detail
    WHERE rpd_display = 1 AND rpd_uid=#{uid} and `rpd_create_time`<![CDATA[<=]]>#{date}
 </select>
 
  <select id="countReduceMoneyByDate" resultType="java.math.BigDecimal">
      SELECT IFNULL(SUM(t.`rpd_money`),0) FROM `yeshi_ec_red_pack_detail` t
    WHERE t.`rpd_uid` = #{uid} 
         AND t.`rpd_type` IN ('redExchangePass','useByShopOrder','giveOthersSucceed')
        <if test="dateType == 1"> <!-- 今日  -->
            AND TO_DAYS(t.`rpd_create_time`) =  TO_DAYS(NOW());
        </if>
        <if test="dateType == 2"> <!-- 昨日  -->
          AND TO_DAYS(NOW()) - TO_DAYS(t.`rpd_create_time`) = 1
        </if>
           <if test="dateType == 3"> <!-- 本月  -->
          AND DATE_FORMAT(t.`rpd_create_time`, '%Y%m') =DATE_FORMAT(CURDATE(), '%Y%m')
        </if>
        <if test="dateType == 4"> <!--上月  -->
          AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(t.`rpd_create_time`, '%Y%m')) = 1
        </if>
  </select>
  
  
  <select id="countWinMoneyByDate" resultType="java.math.BigDecimal">
      SELECT IFNULL(SUM(t.`rpd_money`),0) FROM `yeshi_ec_red_pack_detail` t
    WHERE t.`rpd_uid` = #{uid}
         AND t.`rpd_type` IN ('newUserReward','invite','increaseReward','seriesReward','giveOthersReceive')
        <if test="dateType == 1"> <!-- 今日  -->
            AND TO_DAYS(t.`rpd_create_time`) =  TO_DAYS(NOW());
        </if>
        <if test="dateType == 2"> <!-- 昨日  -->
          AND TO_DAYS(NOW()) - TO_DAYS(t.`rpd_create_time`) = 1
        </if>
           <if test="dateType == 3"> <!-- 本月  -->
          AND DATE_FORMAT(t.`rpd_create_time`, '%Y%m') =DATE_FORMAT(CURDATE(), '%Y%m')
        </if>
        <if test="dateType == 4"> <!--上月  -->
          AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),DATE_FORMAT(t.`rpd_create_time`, '%Y%m')) = 1
        </if>
  </select>
  
  
  <select id="query" resultMap="BaseResultMap">
    SELECT * FROM `yeshi_ec_red_pack_detail` t
     WHERE t.`rpd_uid` LIKE '${key}%'
        <if test = "uid != null">
               AND t.`rpd_uid` = #{uid}
            </if>
        <if test = "type == 1">
            AND t.`rpd_type` = 'giveOthersSucceed' 
        </if>
        <if test = "type == 2">
            AND t.`rpd_type` = 'useByShopOrder'
        </if>
        <if test = "type == 3">
            AND t.`rpd_type` = 'redExchangePass'
        </if>
        <if test = "type == 4">
            AND t.`rpd_type` = 'deduct'
        </if>
    ORDER BY t.`rpd_id` DESC
    LIMIT #{start},#{count}
  </select>
  
  <select id="count" resultType="Long">
      SELECT IFNULL(COUNT(t.rpd_id),0) FROM yeshi_ec_red_pack_detail t
    WHERE t.`rpd_uid` LIKE '${key}%'
        <if test = "uid != null">
               AND t.`rpd_uid` = #{uid}
            </if>
           <if test = "type == 1">
            AND t.`rpd_type` = 'giveOthersSucceed' 
        </if>
        <if test = "type == 2">
            AND t.`rpd_type` = 'useByShopOrder'
        </if>
        <if test = "type == 3">
            AND t.`rpd_type` = 'redExchangePass'
        </if>
        <if test = "type == 4">
            AND t.`rpd_type` = 'deduct'
        </if>
  </select>
  
  <select id="countNumByDay" resultType="Long">
      SELECT COUNT(d.`rpd_id`) FROM `yeshi_ec_red_pack_detail` d
     WHERE d.`rpd_money` > 0 AND d.`rpd_type` NOT IN ('refund','giveOthersFail','shopOrderDrawBack','redExchangeReject')
             AND TO_DAYS( d.`rpd_create_time`) = TO_DAYS(#{preDay})
  </select>
  
  
  <select id="countMoneyByDay" resultType="BigDecimal">
      SELECT SUM(d.`rpd_money`)  FROM `yeshi_ec_red_pack_detail` d
     WHERE d.`rpd_money` > 0 AND d.`rpd_type` NOT IN ('refund','giveOthersFail','shopOrderDrawBack','redExchangeReject')
             AND TO_DAYS( d.`rpd_create_time`) = TO_DAYS(#{preDay})
  </select>
  
</mapper>