TradeRecordMapper.xml 8.49 KB
Newer Older
1 2 3 4 5 6 7 8
<?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="cn.wisenergy.mapper.TradeRecordMapper">
    <resultMap id="tradeMap" type="cn.wisenergy.model.app.TradeRecord">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="trade_type" property="tradeType"/>
        <result column="trade_no" property="tradeNo"/>
9
        <result column="status" property="status"/>
10
        <result column="task_id" property="taskId"/>
licc's avatar
licc committed
11 12
        <result column="money" property="money"/>
        <result column="card_number" property="cardNumber"/>
13 14 15 16 17 18 19 20 21 22 23 24 25 26
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        trade_record
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
licc's avatar
licc committed
27
        user_id,trade_type,trade_no,status,task_id,money,card_number,create_time,update_time
28 29 30
    </sql>

    <sql id="vals">
licc's avatar
licc committed
31
        #{userId},#{tradeType},#{tradeNo},#{status},#{taskId},#{money},#{cardNumber},now(),now()
32 33 34 35 36 37
    </sql>

    <sql id="updateCondition">
        <if test="userId != null">user_id = #{userId},</if>
        <if test="tradeType != null">trade_type =#{tradeType},</if>
        <if test="tradeNo != null">trade_no =#{tradeNo},</if>
38
        <if test="status != null">status =#{status},</if>
39
        <if test="taskId != null">task_id =#{taskId},</if>
licc's avatar
licc committed
40 41
        <if test="money != null">money =#{money},</if>
        <if test="cardNumber != null">card_number =#{cardNumber},</if>
42 43 44 45 46 47 48 49
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userId != null">and user_id = #{userId}</if>
        <if test="tradeType != null">and trade_type =#{tradeType}</if>
        <if test="tradeNo != null">and trade_no =#{tradeNo}</if>
50
        <if test="status != null">and status =#{status}</if>
51
        <if test="taskId != null">and task_id =#{taskId}</if>
licc's avatar
licc committed
52 53
        <if test="money != null">and money =#{money}</if>
        <if test="cardNumber != null">and card_number =#{cardNumber}</if>
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
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>
    <insert id="add" parameterType="cn.wisenergy.model.app.TradeRecord" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <update id="edit" parameterType="cn.wisenergy.model.app.TradeRecord">
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
        <where>
            id = #{id}
        </where>
    </update>

    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

83 84 85 86 87 88 89 90 91 92
    <select id="getByUserId" resultType="cn.wisenergy.model.app.TradeRecord">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>

93
    <select id="getSixMonthIncome" resultType="cn.wisenergy.model.vo.AccumulatedIncomeVo">
licc's avatar
licc committed
94 95 96
        select a.user_id as userId,a.money as income,date_format(a.create_time,'%Y-%m') as yearMonth
        FROM  trade_record as a right join (SELECT user_id ,trade_type,
        date_format(create_time,'%Y-%m'),max(create_time) as time
97 98
        FROM
        <include refid="table"/>
licc's avatar
licc committed
99
        WHERE date_format(create_time,'%Y-%m') &lt;= date_format(now(),'%Y-%m')
licc's avatar
licc committed
100
        and date_format(create_time,'%Y-%m') >= date_format(now() - interval 5 month,'%Y-%m')
101
        and (status=1 or status=0)
licc's avatar
licc committed
102
        and user_id=#{userId}
licc's avatar
licc committed
103 104 105 106 107 108
        and trade_type in(2,4,5,7,8)
        group by user_id ,trade_type,date_format(create_time,'%Y-%m')) as b on
        a.user_id= b.user_id
        and a.trade_type=b.trade_type
        and a.create_time =b.time
        ORDER BY b.time desc
109 110 111 112 113 114 115
    </select>

    <select id="getWithdrawalRecord" resultType="cn.wisenergy.model.vo.WithdrawalRecordVo">
        select user_id as userId, status as status, money as money, update_time as moneyTime
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
116
            (status=2 or status=3)
117
            <if test="userId">
licc's avatar
licc committed
118
                and user_id=#{userId}
119 120 121 122 123 124
            </if>
            <if test="yearMonth != null">
                AND(
                YEAR(update_time) = YEAR(#{yearMonth})
                AND MONTH(update_time) = MONTH(#{yearMonth}))
            </if>
125 126 127
        </where>
    </select>

licc's avatar
licc committed
128
    <select id="queryMonthAward" resultType="java.lang.Double">
licc's avatar
licc committed
129
        select sum(money)
licc's avatar
licc committed
130 131 132
        from
        <include refid="table"/>
        <where>
133 134
            (trade_type=4 or trade_type=7)
            and status=0
licc's avatar
licc committed
135 136 137
            <if test="userId">
                and user_id=#{userId}
            </if>
licc's avatar
licc committed
138 139
            <if test="yearMonth != null">
                AND(
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
                YEAR(create_time) = YEAR(#{yearMonth})
                AND MONTH(create_time) = MONTH(#{yearMonth}))
            </if>
        </where>
    </select>

    <select id="queryMonthGrow" resultType="java.lang.Double">
        select sum(money)
        from
        <include refid="table"/>
        <where>
            (trade_type=4 or trade_type=7)
            and status=0
            <if test="yearMonth != null">
                AND(
                YEAR(create_time) = YEAR(#{yearMonth})
                AND MONTH(create_time) = MONTH(#{yearMonth}))
            </if>
        </where>
    </select>

    <select id="queryAllAward" resultType="java.lang.Double">
        select sum(money)
        from
        <include refid="table"/>
        <where>
            (trade_type=4 or trade_type=7)
            and status=0
            <if test="yearMonth != null">
                and create_time &lt; #{yearMonth}
            </if>
        </where>
    </select>

    <select id="queryByUserLevel" resultType="java.lang.Double">
        select sum(t.money)
        from trade_record t,user_info u
        <where>
            (t.trade_type=4 or t.trade_type=7)
            and t.status=0
            and t.user_id=u.user_id
            <if test="yearMonth != null">
                and t.create_time &lt; #{yearMonth}
                AND(
                YEAR(t.create_time) = YEAR(#{yearMonth})
                AND MONTH(t.create_time) = MONTH(#{yearMonth}))
            </if>
            <if test="userLevel != null">
                and u.user_level=#{userLevel}
licc's avatar
licc committed
189 190 191 192
            </if>
        </where>
    </select>

licc's avatar
licc committed
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
    <select id="count" resultType="java.lang.Integer">
        select count(1)
        from
        <include refid="table"/>
        <where>
            <if test="userId != null and userId != ''">
                user_id = #{userId}
            </if>
        </where>
    </select>

    <select id="getList" resultType="cn.wisenergy.model.app.TradeRecord">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <if test="userId != null and userId != ''">
                user_id = #{userId}
            </if>
        </where>
        order by create_time desc
        limit #{startNum},#{endNum}
    </select>

licc's avatar
licc committed
218 219 220 221 222 223 224 225
    <select id="getVersion" resultType="cn.wisenergy.model.app.TradeRecord">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        where trade_type=9
    </select>

licc's avatar
licc committed
226 227 228 229 230 231 232 233 234
    <select id="getByUserIdAndType" resultType="cn.wisenergy.model.app.TradeRecord">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
            and trade_type=#{tradeType}
            AND(
licc's avatar
licc committed
235 236
            YEAR(create_time) = YEAR(#{yearMonth})
            AND MONTH(create_time) = MONTH(#{yearMonth}))
licc's avatar
licc committed
237 238 239 240 241 242 243 244 245 246 247
        </where>
        order by create_time desc
        limit 1
    </select>

    <select id="getRebateList" resultType="cn.wisenergy.model.app.TradeRecord">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
licc's avatar
licc committed
248
            status=1
licc's avatar
licc committed
249
            and user_id=#{userId}
licc's avatar
licc committed
250
            and trade_type=2
licc's avatar
licc committed
251
            AND(
licc's avatar
licc committed
252 253
            YEAR(create_time) = YEAR(#{yearMonth})
            AND MONTH(create_time) = MONTH(#{yearMonth}))
licc's avatar
licc committed
254 255 256
        </where>
    </select>

257
</mapper>