<?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.example.mapper.OrdersMapper">

    <sql id="Base_Column_List">
        id,bit_pay,origin_pay,user_id,address_id,time_pre,time_order,order_state,order_remark,trans_code,order_type_id
    </sql>

    <select id="selectAll" resultType="com.example.entity.Orders">
        select
        <include refid="Base_Column_List" />
        from orders
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="bitPay != null"> and bit_pay = #{bitPay}</if>
            <if test="originPay != null"> and origin_pay = #{originPay}</if>
            <if test="userId != null"> and user_id = #{userId}</if>
            <if test="addressId != null"> and address_id = #{addressId}</if>
            <if test="timePre != null"> and time_pre like concat('%', #{timePre}, '%')</if>
            <if test="timeOrder != null"> and time_order like concat('%', #{timeOrder}, '%')</if>
            <if test="orderState != null"> and order_state like concat('%', #{orderState}, '%')</if>
            <if test="orderRemark != null"> and order_remark like concat('%', #{orderRemark}, '%')</if>
            <if test="transCode != null"> and trans_code like concat('%', #{transCode}, '%')</if>
            <if test="orderTypeId != null"> and order_type_id = #{orderTypeId}</if>
        </where>
        order by id desc
    </select>

    <select id="selectById" resultType="com.example.entity.Orders">
        select
        <include refid="Base_Column_List" />
        from orders
        where id = #{id}
    </select>

    <delete id="deleteById">
        delete from orders
        where  id = #{id}
    </delete>

    <insert id="insert" parameterType="com.example.entity.Orders" useGeneratedKeys="true">
        insert into orders
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="bitPay != null">bit_pay,</if>
            <if test="originPay != null">origin_pay,</if>
            <if test="userId != null">user_id,</if>
            <if test="addressId != null">address_id,</if>
            <if test="timePre != null">time_pre,</if>
            <if test="timeOrder != null">time_order,</if>
            <if test="orderState != null">order_state,</if>
            <if test="orderRemark != null">order_remark,</if>
            <if test="transCode != null">trans_code,</if>
            <if test="orderTypeId != null">order_type_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="bitPay != null">#{bitPay},</if>
            <if test="originPay != null">#{originPay},</if>
            <if test="userId != null">#{userId},</if>
            <if test="addressId != null">#{addressId},</if>
            <if test="timePre != null">#{timePre},</if>
            <if test="timeOrder != null">#{timeOrder},</if>
            <if test="orderState != null">#{orderState},</if>
            <if test="orderRemark != null">#{orderRemark},</if>
            <if test="transCode != null">#{transCode},</if>
            <if test="orderTypeId != null">#{orderTypeId},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.Orders">
        update orders
        <set>
            <if test="bitPay != null">
                bit_pay = #{bitPay},
            </if>
            <if test="originPay != null">
                origin_pay = #{originPay},
            </if>
            <if test="userId != null">
                user_id = #{userId},
            </if>
            <if test="addressId != null">
                address_id = #{addressId},
            </if>
            <if test="timePre != null">
                time_pre = #{timePre},
            </if>
            <if test="timeOrder != null">
                time_order = #{timeOrder},
            </if>
            <if test="orderState != null">
                order_state = #{orderState},
            </if>
            <if test="orderRemark != null">
                order_remark = #{orderRemark},
            </if>
            <if test="transCode != null">
                trans_code = #{transCode},
            </if>
            <if test="orderTypeId != null">
                order_type_id = #{orderTypeId},
            </if>
        </set>
        where id = #{id} 
    </update>

</mapper>