admin
2020-04-13 dd5b15229cb15459fa7c31ccea77dac28cbfafbd
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
<?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.tlj.UserTaoLiJinDetailMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail">
    <id column="utd_id" property="id" jdbcType="BIGINT"/>
    <result column="utd_uid" property="uid" jdbcType="BIGINT"/>
    <result column="utd_money" property="money" jdbcType="DECIMAL"/>
    <result column="utd_title" property="title" jdbcType="VARCHAR"/>
    <result column="utd_type" property="type" typeHandler="com.yeshi.fanli.util.mybatishandler.tlj.TaoLiJinDetailTypeEnumHandler"/>
    <result column="utd_desc_info" property="descInfo" jdbcType="VARCHAR"/>
    <result column="utd_remark" property="remark" jdbcType="INTEGER"/>
    <result column="utd_create_time" property="createTime" jdbcType="TIMESTAMP"/>
  </resultMap>
  
  <resultMap id="UserMonthMoneyMap" type="com.yeshi.fanli.vo.tlj.TaoLiJinMonthVO">
        <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">utd_id,utd_uid,utd_money,utd_title,utd_type,utd_desc_info,utd_remark,utd_create_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_user_taolijin_detail where utd_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_taolijin_detail where utd_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_taolijin_detail (utd_id,utd_uid,utd_money,utd_title,utd_type,utd_desc_info,utd_remark,utd_create_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{title,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{descInfo,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_taolijin_detail
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">utd_id,</if>
      <if test="uid != null">utd_uid,</if>
      <if test="money != null">utd_money,</if>
      <if test="title != null">utd_title,</if>
      <if test="type != null">utd_type,</if>
      <if test="descInfo != null">utd_desc_info,</if>
      <if test="remark != null">utd_remark,</if>
      <if test="createTime != null">utd_create_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</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>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail">update yeshi_ec_user_taolijin_detail set utd_uid = #{uid,jdbcType=BIGINT},utd_money = #{money,jdbcType=DECIMAL},utd_title = #{title,jdbcType=VARCHAR},utd_type = #{type,jdbcType=VARCHAR},utd_desc_info = #{descInfo,jdbcType=VARCHAR},utd_remark = #{remark,jdbcType=VARCHAR},utd_create_time = #{createTime,jdbcType=TIMESTAMP} where utd_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail">update yeshi_ec_user_taolijin_detail
    <set>
      <if test="uid != null">utd_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="money != null">utd_money=#{money,jdbcType=DECIMAL},</if>
      <if test="title != null">utd_title=#{title,jdbcType=VARCHAR},</if>
      <if test="type != null">utd_type=#{type,jdbcType=VARCHAR},</if>
      <if test="descInfo != null">utd_desc_info=#{descInfo,jdbcType=VARCHAR},</if>
      <if test="remark != null">utd_remark=#{remark,jdbcType=VARCHAR},</if>
      <if test="createTime != null">utd_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
    </set> where utd_id = #{id,jdbcType=BIGINT}
  </update>
  
   
  <select id="countDetail" resultType="Long">
      SELECT IFNULL(count(t.utd_id),0) FROM `yeshi_ec_user_taolijin_detail` t
    WHERE t.`utd_uid` = #{uid}
  </select>
  
  <select id="countUseMoneyByDate" resultType="java.math.BigDecimal">
      SELECT IFNULL(SUM(t.`utd_money`),0) FROM `yeshi_ec_user_taolijin_detail` t
    WHERE t.`utd_uid` = #{uid} AND (t.`utd_type` = 'reduce' OR  t.`utd_type` = 'refund')
        <if test="dateType == 1"> <!-- 今日  -->
            AND TO_DAYS(t.`utd_create_time`) =  TO_DAYS(NOW());
        </if>
        <if test="dateType == 2"> <!-- 昨日  -->
          AND TO_DAYS(NOW()) - TO_DAYS(t.`utd_create_time`) = 1
        </if>
           <if test="dateType == 3"> <!-- 本月  -->
          AND DATE_FORMAT(t.`utd_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.`utd_create_time`, '%Y%m')) = 1
        </if>
  </select>
  
  <select id="selectByMaxCreateTime" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" /> FROM yeshi_ec_user_taolijin_detail t
    WHERE t.`utd_uid`=#{uid} AND t.`utd_create_time`<![CDATA[<=]]> #{date}
    ORDER BY t.`utd_create_time` DESC,t.utd_id DESC
    LIMIT #{count}
  </select>
  
  <select id="selectByUidWithIndexId" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" />    FROM yeshi_ec_user_taolijin_detail t 
    WHERE t.`utd_uid`=#{uid}
        AND t.`utd_create_time`<![CDATA[<=]]>(SELECT utd_create_time FROM yeshi_ec_user_taolijin_detail WHERE utd_id =#{id})
    ORDER BY t.`utd_create_time` DESC,t.utd_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.`utd_create_time`,'%Y-%m') AS `time`,SUM(d.`utd_money`)AS money
                               FROM `yeshi_ec_user_taolijin_detail` d
                               WHERE d.`utd_uid`=#{uid} AND  d.`utd_money`<![CDATA[>=]]>0 AND DATE_FORMAT(d.`utd_create_time`,'%Y-%m')=#{item} 
                               GROUP BY DATE_FORMAT(d.`utd_create_time`,'%Y-%m')
                               ) a ON a.time=c.time
 
                LEFT JOIN(SELECT DATE_FORMAT(d.`utd_create_time`,'%Y-%m') AS `time`,SUM(d.`utd_money`) AS money
                              FROM `yeshi_ec_user_taolijin_detail` d
                            WHERE d.`utd_uid`=#{uid} AND d.`utd_money` <![CDATA[<]]>0 AND DATE_FORMAT(d.`utd_create_time`,'%Y-%m')=#{item} 
                              GROUP BY DATE_FORMAT(d.`utd_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(utd_id) FROM yeshi_ec_user_taolijin_detail
    WHERE utd_uid=#{uid}
  </select>
  
  <select id="selectMonthCountByUid" resultType="java.lang.Integer">
    SELECT COUNT(*) FROM 
            (SELECT * FROM yeshi_ec_user_taolijin_detail d 
             WHERE d.`utd_uid`=#{uid} AND d.`utd_create_time` <![CDATA[<=]]> #{date} 
             GROUP BY DATE_FORMAT(d.`utd_create_time`,'%y-%m')
             ) a
  </select>
  
  <select id="selectCountByUidAndMaxCreateTime" resultType="java.lang.Long">
    SELECT count(utd_id) FROM yeshi_ec_user_taolijin_detail
    WHERE utd_uid=#{uid} and `utd_create_time`<![CDATA[<=]]>#{date}
 </select>
 
 <select id="countNumByDay" resultType="Long">
    SELECT COUNT(d.`utd_id`) FROM `yeshi_ec_user_taolijin_detail` d
    WHERE d.`utd_type` = 'add' AND TO_DAYS(d.`utd_create_time`) = TO_DAYS(#{preDay})
 </select>
 
 <select id="countMoneyByDay" resultType="BigDecimal">
    SELECT SUM(d.`utd_money`) FROM `yeshi_ec_user_taolijin_detail` d
    WHERE d.`utd_type` = 'add' AND TO_DAYS(d.`utd_create_time`) = TO_DAYS(#{preDay})
 </select>
 
 
  
</mapper>