admin
2018-12-24 16da7b547decb88029b267fa7c68bd7c3396e734
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
<?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.money.UserMoneyDetailMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.money.UserMoneyDetail">
        <id column="umd_id" property="id" jdbcType="BIGINT" />
        <result column="umd_money" property="money" jdbcType="DECIMAL" />
        <result column="umd_type" property="type"
            typeHandler="com.yeshi.fanli.util.mybatishandler.UserMoneyDetailTypeEnumHandler" />
        <result column="umd_title" property="title" jdbcType="VARCHAR" />
        <result column="umd_sub_title" property="subTitle" jdbcType="VARCHAR" />
        <result column="umd_desc_info" property="descInfo" jdbcType="VARCHAR" />
        <result column="umd_source_identify_id" property="sourceIdentifyId"
            jdbcType="BIGINT" />
        <result column="umd_identify_code" property="identifyCode"
            jdbcType="VARCHAR" />
        <result column="umd_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="umd_createtime" property="createTime" jdbcType="TIMESTAMP" />
        <result column="umd_updatetime" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="userInfo" column="umd_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="umd_uid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
 
 
    <resultMap id="UserMonthMoneyMap" type="com.yeshi.fanli.vo.money.UserMonthMoneyVO">
        <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">umd_id,umd_uid,umd_money,umd_type,umd_title,umd_sub_title,umd_desc_info,umd_source_identify_id,umd_identify_code,umd_beizhu,umd_createtime,umd_updatetime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_money_detail where umd_id = #{id,jdbcType=BIGINT}
    </select>
 
 
    <select id="selectByUidWithIndexId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_user_money_detail d WHERE d.`umd_createtime`
        <![CDATA[
            <=
        ]]>
        (SELECT
        d.`umd_createtime` FROM yeshi_ec_user_money_detail d WHERE
        d.`umd_id`=#{id}) and d.umd_uid=#{uid} order by d.`umd_createtime`
        desc,d.umd_id desc limit #{count}
    </select>
 
    <select id="selectCountByUid" resultType="java.lang.Long"
        parameterType="java.lang.Long">
        SELECT count(umd_id) FROM yeshi_ec_user_money_detail
        where umd_uid=#{uid}
    </select>
 
 
 
    <select id="selectByMaxCreateTime" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_user_money_detail d WHERE d.umd_uid=#{uid} and
        d.`umd_createtime`
        <![CDATA[
            <=
        ]]>
        #{date}
        order by d.`umd_createtime` desc,d.umd_id desc limit #{count}
    </select>
 
    <select id="selectCountByUidAndMaxCreateTime" resultType="java.lang.Long">
        SELECT count(umd_id) FROM yeshi_ec_user_money_detail
        where
        umd_uid=#{uid} and d.`umd_createtime`
        <![CDATA[
            <=
        ]]>
        #{date}
    </select>
 
 
    <select id="selectMonthCountByUid" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM (SELECT * FROM yeshi_ec_user_money_detail d WHERE
        d.`umd_uid`=#{uid} and d.`umd_createtime` <![CDATA[<=]]>
        #{date} group by DATE_FORMAT(d.`umd_createtime`,'%y-%m')) a
    </select>
 
    <select id="selectMonthMoneyByUid" resultMap="UserMonthMoneyMap">
        <foreach collection="dateFormat" index="index" item="item"  separator="UNION ALL"  >
            <trim prefix="(" suffix=")" >
                SELECT
                a.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 DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m') AS
                `time`,SUM(d.`umd_money`) AS money
                FROM
                `yeshi_ec_user_money_detail`
                d
                WHERE d.`umd_uid`=#{uid} AND
                d.`umd_money`>=0 AND DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m')=#{item} GROUP BY DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m')
                ) a
                LEFT JOIN
                (
                SELECT DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m') AS
                `time`,SUM(d.`umd_money`) AS money
                FROM
                `yeshi_ec_user_money_detail`
                d WHERE d.`umd_uid`=#{uid} AND
                d.`umd_money` <![CDATA[<0]]>
                AND DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m')=#{item} GROUP BY
                DATE_FORMAT(
                d.`umd_createtime`,'%Y-%m')
                ) b ON a.time=b.time
            </trim>
        </foreach>
    </select>
 
 
 
 
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_user_money_detail where umd_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_user_money_detail
        (umd_id,umd_uid,umd_money,umd_type,umd_title,umd_sub_title,umd_desc_info,umd_source_identify_id,umd_identify_code,umd_beizhu,umd_createtime,umd_updatetime)
        values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{type,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{subTitle,jdbcType=VARCHAR},#{descInfo,jdbcType=VARCHAR},#{sourceIdentifyId,jdbcType=BIGINT},#{identifyCode,jdbcType=VARCHAR},#{beiZhu,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_user_money_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">umd_id,</if>
            <if test="userInfo != null">umd_uid,</if>
            <if test="money != null">umd_money,</if>
            <if test="type != null">umd_type,</if>
            <if test="title != null">umd_title,</if>
            <if test="subTitle != null">umd_sub_title,</if>
            <if test="descInfo != null">umd_desc_info,</if>
            <if test="sourceIdentifyId != null">umd_source_identify_id,</if>
            <if test="identifyCode != null">umd_identify_code,</if>
            <if test="beiZhu != null">umd_beizhu,</if>
            <if test="createTime != null">umd_createtime,</if>
            <if test="updateTime != null">umd_updatetime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="type != null">#{type,jdbcType=VARCHAR},</if>
            <if test="title != null">#{title,jdbcType=VARCHAR},</if>
            <if test="subTitle != null">#{subTitle,jdbcType=VARCHAR},</if>
            <if test="descInfo != null">#{descInfo,jdbcType=VARCHAR},</if>
            <if test="sourceIdentifyId != null">#{sourceIdentifyId,jdbcType=BIGINT},</if>
            <if test="identifyCode != null">#{identifyCode,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail">update
        yeshi_ec_user_money_detail set umd_uid =
        #{userInfo.id,jdbcType=BIGINT},umd_money =
        #{money,jdbcType=DECIMAL},umd_type =
        #{type,jdbcType=VARCHAR},umd_title =
        #{title,jdbcType=VARCHAR},umd_sub_title =
        #{subTitle,jdbcType=VARCHAR},umd_desc_info =
        #{descInfo,jdbcType=VARCHAR},umd_source_identify_id =
        #{sourceIdentifyId,jdbcType=BIGINT},umd_identify_code =
        #{identifyCode,jdbcType=VARCHAR},umd_beizhu =
        #{beiZhu,jdbcType=VARCHAR},umd_createtime =
        #{createTime,jdbcType=TIMESTAMP},umd_updatetime =
        #{updateTime,jdbcType=TIMESTAMP} where umd_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.money.UserMoneyDetail">
        update yeshi_ec_user_money_detail
        <set>
            <if test="userInfo != null">umd_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="money != null">umd_money=#{money,jdbcType=DECIMAL},</if>
            <if test="type != null">umd_type=#{type,jdbcType=VARCHAR},</if>
            <if test="title != null">umd_title=#{title,jdbcType=VARCHAR},</if>
            <if test="subTitle != null">umd_sub_title=#{subTitle,jdbcType=VARCHAR},</if>
            <if test="descInfo != null">umd_desc_info=#{descInfo,jdbcType=VARCHAR},</if>
            <if test="sourceIdentifyId != null">umd_source_identify_id=#{sourceIdentifyId,jdbcType=BIGINT},
            </if>
            <if test="identifyCode != null">umd_identify_code=#{identifyCode,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">umd_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="createTime != null">umd_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">umd_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where umd_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>