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

    <resultMap type="FsStoreAfterSales" id="FsStoreAfterSalesResult">
        <result property="id"    column="id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="refundAmount"    column="refund_amount"    />
        <result property="serviceType"    column="service_type"    />
        <result property="reasons"    column="reasons"    />
        <result property="explains"    column="explains"    />
        <result property="explainImg"    column="explain_img"    />
        <result property="shipperCode"    column="shipper_code"    />
        <result property="deliverySn"    column="delivery_sn"    />
        <result property="deliveryName"    column="delivery_name"    />
        <result property="status"    column="status"    />
        <result property="salesStatus"    column="sales_status"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="userId"    column="user_id"    />
        <result property="consignee"    column="consignee"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="address"    column="address"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="isPackage"    column="is_package"    />
        <result property="packageJson"    column="package_json"    />
    </resultMap>

    <sql id="selectFsStoreAfterSalesVo">
        select id, order_code, refund_amount, service_type, reasons, explains, explain_img, shipper_code, delivery_sn, delivery_name, status, sales_status ,order_status, create_time, is_del, user_id, consignee, phone_number, address,company_id,company_user_id,is_package,package_json from fs_store_after_sales
    </sql>

    <select id="selectFsStoreAfterSalesList" parameterType="FsStoreAfterSales" resultMap="FsStoreAfterSalesResult">
        <include refid="selectFsStoreAfterSalesVo"/>
        <where>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="refundAmount != null "> and refund_amount = #{refundAmount}</if>
            <if test="serviceType != null "> and service_type = #{serviceType}</if>
            <if test="reasons != null  and reasons != ''"> and reasons = #{reasons}</if>
            <if test="explains != null  and explains != ''"> and explains = #{explains}</if>
            <if test="explainImg != null  and explainImg != ''"> and explain_img = #{explainImg}</if>
            <if test="shipperCode != null  and shipperCode != ''"> and shipper_code = #{shipperCode}</if>
            <if test="deliverySn != null  and deliverySn != ''"> and delivery_sn = #{deliverySn}</if>
            <if test="deliveryName != null  and deliveryName != ''"> and delivery_name like concat('%', #{deliveryName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="salesStatus != null "> and sales_status = #{salesStatus}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="consignee != null  and consignee != ''"> and consignee = #{consignee}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
        </where>
        order by id desc
    </select>

    <select id="selectFsStoreAfterSalesById" parameterType="Long" resultMap="FsStoreAfterSalesResult">
        <include refid="selectFsStoreAfterSalesVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsStoreAfterSales" parameterType="FsStoreAfterSales" useGeneratedKeys="true" keyProperty="id">
        insert into fs_store_after_sales
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderCode != null">order_code,</if>
            <if test="refundAmount != null">refund_amount,</if>
            <if test="serviceType != null">service_type,</if>
            <if test="reasons != null">reasons,</if>
            <if test="explains != null">explains,</if>
            <if test="explainImg != null">explain_img,</if>
            <if test="shipperCode != null">shipper_code,</if>
            <if test="deliverySn != null">delivery_sn,</if>
            <if test="deliveryName != null">delivery_name,</if>
            <if test="status != null">status,</if>
            <if test="salesStatus != null">sales_status,</if>
            <if test="orderStatus != null">order_status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="userId != null">user_id,</if>
            <if test="consignee != null">consignee,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="address != null">address,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="isPackage != null">is_package,</if>
            <if test="packageJson != null">package_json,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderCode != null">#{orderCode},</if>
            <if test="refundAmount != null">#{refundAmount},</if>
            <if test="serviceType != null">#{serviceType},</if>
            <if test="reasons != null">#{reasons},</if>
            <if test="explains != null">#{explains},</if>
            <if test="explainImg != null">#{explainImg},</if>
            <if test="shipperCode != null">#{shipperCode},</if>
            <if test="deliverySn != null">#{deliverySn},</if>
            <if test="deliveryName != null">#{deliveryName},</if>
            <if test="status != null">#{status},</if>
            <if test="salesStatus != null">#{salesStatus},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="userId != null">#{userId},</if>
            <if test="consignee != null">#{consignee},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="address != null">#{address},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="isPackage != null">#{isPackage},</if>
            <if test="packageJson != null">#{packageJson},</if>
         </trim>
    </insert>

    <update id="updateFsStoreAfterSales" parameterType="FsStoreAfterSales">
        update fs_store_after_sales
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null">order_code = #{orderCode},</if>
            <if test="refundAmount != null">refund_amount = #{refundAmount},</if>
            <if test="serviceType != null">service_type = #{serviceType},</if>
            <if test="reasons != null">reasons = #{reasons},</if>
            <if test="explains != null">explains = #{explains},</if>
            <if test="explainImg != null">explain_img = #{explainImg},</if>
            <if test="shipperCode != null">shipper_code = #{shipperCode},</if>
            <if test="deliverySn != null">delivery_sn = #{deliverySn},</if>
            <if test="deliveryName != null">delivery_name = #{deliveryName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="salesStatus != null">sales_status = #{salesStatus},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="consignee != null">consignee = #{consignee},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="address != null">address = #{address},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="isPackage != null">is_package = #{isPackage},</if>
            <if test="packageJson != null">package_json = #{packageJson},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsStoreAfterSalesById" parameterType="Long">
        delete from fs_store_after_sales where id = #{id}
    </delete>

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

</mapper>
