<?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.jxy.order.mapper.ConsumeMapper">

    <select id="checkOrderIfExistByUserId" resultType="java.lang.Integer">
        select count(*) from `consume` where user_id=#{userId} and state = 2
    </select>
    <select id="getConsumeByUserId" resultType="com.jxy.order.entity.Consume">
        select
            id,
            user_id userId,
            content,
            need_funding amount,
             `state`,
             create_time createTime
        from
            consume
        <where>
            user_id =#{userId}
            <if test="state != null"> and `state` = #{state}</if>
        </where>
        order by create_time
    </select>

    <insert id="insertConsume" useGeneratedKeys="true" keyProperty="id">
        insert into consume(user_id,content,need_funding,`state`,create_time) values (
            #{dto.userId},#{dto.content},#{dto.amountReceivable},#{dto.status},sysdate()
        )
    </insert>

    <update id="updateConsumeState">
        update
            consume
        set
            `state` = #{dto.status}
        where id = #{dto.id}
    </update>


</mapper>
