<?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.fs.store.mapper.FsIntegralOrderMapper">

    <resultMap type="FsIntegralOrder" id="FsIntegralOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="userAddress"    column="user_address"    />
        <result property="itemJson"    column="item_json"    />
        <result property="integral"    column="integral"    />
        <result property="status"    column="status"    />
        <result property="deliveryCode"    column="delivery_code"    />
        <result property="deliveryName"    column="delivery_name"    />
        <result property="deliverySn"    column="delivery_sn"    />
        <result property="deliveryTime"    column="delivery_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="barCode"    column="bar_code"    />
    </resultMap>

    <sql id="selectFsIntegralOrderVo">
        select order_id, order_code, user_id,bar_code, user_name, user_phone, user_address, item_json, integral, status, delivery_code, delivery_name, delivery_sn, delivery_time, create_time, remark from fs_integral_order
    </sql>

    <select id="selectFsIntegralOrderList" parameterType="FsIntegralOrder" resultMap="FsIntegralOrderResult">
        <include refid="selectFsIntegralOrderVo"/>
        <where>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="integral != null  and integral != ''"> and integral = #{integral}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="deliverySn != null  and deliverySn != ''"> and delivery_sn like concat('%', #{deliverySn}, '%')</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectFsIntegralOrderByOrderId" parameterType="Long" resultMap="FsIntegralOrderResult">
        <include refid="selectFsIntegralOrderVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertFsIntegralOrder" parameterType="FsIntegralOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into fs_integral_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderCode != null">order_code,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="userAddress != null">user_address,</if>
            <if test="itemJson != null">item_json,</if>
            <if test="integral != null">integral,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="deliveryCode != null">delivery_code,</if>
            <if test="deliveryName != null">delivery_name,</if>
            <if test="deliverySn != null">delivery_sn,</if>
            <if test="deliveryTime != null">delivery_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
            <if test="barCode != null">bar_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="userAddress != null">#{userAddress},</if>
            <if test="itemJson != null">#{itemJson},</if>
            <if test="integral != null">#{integral},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="deliveryCode != null">#{deliveryCode},</if>
            <if test="deliveryName != null">#{deliveryName},</if>
            <if test="deliverySn != null">#{deliverySn},</if>
            <if test="deliveryTime != null">#{deliveryTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="barCode != null">#{barCode},</if>
         </trim>
    </insert>

    <update id="updateFsIntegralOrder" parameterType="FsIntegralOrder">
        update fs_integral_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="userAddress != null">user_address = #{userAddress},</if>
            <if test="itemJson != null">item_json = #{itemJson},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="deliveryCode != null">delivery_code = #{deliveryCode},</if>
            <if test="deliveryName != null">delivery_name = #{deliveryName},</if>
            <if test="deliverySn != null">delivery_sn = #{deliverySn},</if>
            <if test="deliveryTime != null">delivery_time = #{deliveryTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="barCode != null">bar_code = #{barCode},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteFsIntegralOrderByOrderId" parameterType="Long">
        delete from fs_integral_order where order_id = #{orderId}
    </delete>

    <delete id="deleteFsIntegralOrderByOrderIds" parameterType="String">
        delete from fs_integral_order where order_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
</mapper>
