<?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.oms.mapper.OmsStoreMapper">

    <resultMap type="OmsStore" id="OmsStoreResult">
        <result property="storeId"    column="store_id"    />
        <result property="storeType"    column="store_type"    />
        <result property="storeName"    column="store_name"    />
        <result property="storeCode"    column="store_code"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="limitTime"    column="limit_time"    />
        <result property="remark"    column="remark"    />
        <result property="channelType"    column="channel_type"    />
        <result property="cityIds"    column="city_ids"    />
        <result property="address"    column="address"    />
        <result property="linkUsername"    column="link_username"    />
        <result property="linkPhone"    column="link_phone"    />
        <result property="warehouseId"    column="warehouse_id"    />

    </resultMap>

    <sql id="selectOmsStoreVo">
        select store_id, store_type, store_name, store_code, status, create_time, update_time, limit_time, remark, channel_type, city_ids, address, link_username, link_phone,warehouse_id from oms_store
    </sql>

    <select id="selectOmsStoreList" parameterType="OmsStore" resultMap="OmsStoreResult">
        <include refid="selectOmsStoreVo"/>
        <where>
            <if test="storeType != null "> and store_type = #{storeType}</if>
            <if test="storeName != null  and storeName != ''"> and store_name like concat('%', #{storeName}, '%')</if>
            <if test="storeCode != null  and storeCode != ''"> and store_code = #{storeCode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</if>
            <if test="channelType != null "> and channel_type = #{channelType}</if>
            <if test="cityIds != null  and cityIds != ''"> and city_ids = #{cityIds}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="linkUsername != null  and linkUsername != ''"> and link_username like concat('%', #{linkUsername}, '%')</if>
            <if test="linkPhone != null  and linkPhone != ''"> and link_phone = #{linkPhone}</if>
            <if test="linkPhone != null  and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>

        </where>
    </select>

    <select id="selectOmsStoreById" parameterType="Long" resultMap="OmsStoreResult">
        <include refid="selectOmsStoreVo"/>
        where store_id = #{storeId}
    </select>

    <insert id="insertOmsStore" parameterType="OmsStore" useGeneratedKeys="true" keyProperty="storeId">
        insert into oms_store
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeType != null">store_type,</if>
            <if test="storeName != null">store_name,</if>
            <if test="storeCode != null">store_code,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="limitTime != null">limit_time,</if>
            <if test="remark != null">remark,</if>
            <if test="channelType != null">channel_type,</if>
            <if test="cityIds != null">city_ids,</if>
            <if test="address != null">address,</if>
            <if test="linkUsername != null">link_username,</if>
            <if test="linkPhone != null">link_phone,</if>
            <if test="warehouseId != null">warehouse_id,</if>

         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storeType != null">#{storeType},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="storeCode != null">#{storeCode},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="channelType != null">#{channelType},</if>
            <if test="cityIds != null">#{cityIds},</if>
            <if test="address != null">#{address},</if>
            <if test="linkUsername != null">#{linkUsername},</if>
            <if test="linkPhone != null">#{linkPhone},</if>
            <if test="warehouseId != null">#{warehouseId},</if>

         </trim>
    </insert>

    <update id="updateOmsStore" parameterType="OmsStore">
        update oms_store
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeType != null">store_type = #{storeType},</if>
            <if test="storeName != null">store_name = #{storeName},</if>
            <if test="storeCode != null">store_code = #{storeCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="channelType != null">channel_type = #{channelType},</if>
            <if test="cityIds != null">city_ids = #{cityIds},</if>
            <if test="address != null">address = #{address},</if>
            <if test="linkUsername != null">link_username = #{linkUsername},</if>
            <if test="linkPhone != null">link_phone = #{linkPhone},</if>
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>

        </trim>
        where store_id = #{storeId}
    </update>

    <delete id="deleteOmsStoreById" parameterType="Long">
        delete from oms_store where store_id = #{storeId}
    </delete>

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

</mapper>
