<?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.FsStoreOrderOfflineMapper">

    <resultMap type="FsStoreOrderOffline" id="FsStoreOrderOfflineResult">
        <result property="orderId"    column="order_id"    />
        <result property="crmId"    column="crm_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="status"    column="status"    />
        <result property="payPrice"    column="pay_price"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="createTime"    column="create_time"    />
        <result property="certificates"    column="certificates"    />
        <result property="uploadTime"    column="upload_time"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="uploadUserId"    column="upload_user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="remark"    column="remark"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="auditBy"    column="audit_by"    />
        <result property="storeName"    column="store_name"    />
        <result property="storeAddress"    column="store_address"    />
        <result property="batchNo"    column="batch_no"    />
        <result property="businessCode"    column="business_code"    />
    </resultMap>

    <sql id="selectFsStoreOrderOfflineVo">
        select order_id, crm_id, order_code, status, pay_price, pay_money, create_time, certificates, upload_time, company_user_id, upload_user_id, company_id, remark, audit_time, audit_by, store_name, store_address, batch_no, business_code from fs_store_order_offline
    </sql>

    <select id="selectFsStoreOrderOfflineList" parameterType="FsStoreOrderOffline" resultMap="FsStoreOrderOfflineResult">
        <include refid="selectFsStoreOrderOfflineVo"/>
        <where>
            <if test="crmId != null "> and crm_id = #{crmId}</if>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="payPrice != null "> and pay_price = #{payPrice}</if>
            <if test="payMoney != null "> and pay_money = #{payMoney}</if>
            <if test="certificates != null  and certificates != ''"> and certificates = #{certificates}</if>
            <if test="uploadTime != null "> and upload_time = #{uploadTime}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="uploadUserId != null "> and upload_user_id = #{uploadUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="auditTime != null "> and audit_time = #{auditTime}</if>
            <if test="auditBy != null  and auditBy != ''"> and audit_by = #{auditBy}</if>
            <if test="storeName != null  and storeName != ''"> and store_name like concat('%', #{storeName}, '%')</if>
            <if test="storeAddress != null  and storeAddress != ''"> and store_address = #{storeAddress}</if>
            <if test="batchNo != null  and batchNo != ''"> and batch_no = #{batchNo}</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
        </where>
    </select>

    <select id="selectFsStoreOrderOfflineById" parameterType="Long" resultMap="FsStoreOrderOfflineResult">
        <include refid="selectFsStoreOrderOfflineVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertFsStoreOrderOffline" parameterType="FsStoreOrderOffline" useGeneratedKeys="true" keyProperty="orderId">
        insert into fs_store_order_offline
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="crmId != null">crm_id,</if>
            <if test="orderCode != null">order_code,</if>
            <if test="status != null">status,</if>
            <if test="payPrice != null">pay_price,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="createTime != null">create_time,</if>
            <if test="certificates != null">certificates,</if>
            <if test="uploadTime != null">upload_time,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="uploadUserId != null">upload_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="remark != null">remark,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="auditBy != null">audit_by,</if>
            <if test="storeName != null">store_name,</if>
            <if test="storeAddress != null">store_address,</if>
            <if test="batchNo != null">batch_no,</if>
            <if test="businessCode != null">business_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="crmId != null">#{crmId},</if>
            <if test="orderCode != null">#{orderCode},</if>
            <if test="status != null">#{status},</if>
            <if test="payPrice != null">#{payPrice},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="certificates != null">#{certificates},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="uploadUserId != null">#{uploadUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="auditBy != null">#{auditBy},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="storeAddress != null">#{storeAddress},</if>
            <if test="batchNo != null">#{batchNo},</if>
            <if test="businessCode != null">#{businessCode},</if>
        </trim>
    </insert>

    <update id="updateFsStoreOrderOffline" parameterType="FsStoreOrderOffline">
        update fs_store_order_offline
        <trim prefix="SET" suffixOverrides=",">
            <if test="crmId != null">crm_id = #{crmId},</if>
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="payPrice != null">pay_price = #{payPrice},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="certificates != null">certificates = #{certificates},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="uploadUserId != null">upload_user_id = #{uploadUserId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="auditBy != null">audit_by = #{auditBy},</if>
            <if test="storeName != null">store_name = #{storeName},</if>
            <if test="storeAddress != null">store_address = #{storeAddress},</if>
            <if test="batchNo != null">batch_no = #{batchNo},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

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

</mapper>
