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

    <resultMap type="OmsWarehouse" id="OmsWarehouseResult">
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="warehouseName"    column="warehouse_name"    />
        <result property="warehouseCode"    column="warehouse_code"    />
        <result property="warehouseType"    column="warehouse_type"    />
        <result property="linkUsername"    column="link_username"    />
        <result property="linkPhone"    column="link_phone"    />
        <result property="cityIds"    column="city_ids"    />
        <result property="address"    column="address"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
        <result property="rate"    column="rate"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectOmsWarehouseVo">
        select warehouse_id, warehouse_name, warehouse_code, warehouse_type, link_username, link_phone, city_ids, address, remark, status,rate, create_user_id, create_time, update_time from oms_warehouse
    </sql>

    <select id="selectOmsWarehouseList" parameterType="OmsWarehouse" resultMap="OmsWarehouseResult">
        <include refid="selectOmsWarehouseVo"/>
        <where>
            <if test="warehouseName != null  and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
            <if test="warehouseCode != null  and warehouseCode != ''"> and warehouse_code = #{warehouseCode}</if>
            <if test="warehouseType != null "> and warehouse_type = #{warehouseType}</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="cityIds != null  and cityIds != ''"> and city_ids = #{cityIds}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="rate != null "> and rate = #{rate}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
        </where>
    </select>

    <select id="selectOmsWarehouseName" parameterType="OmsWarehouse" resultMap="OmsWarehouseResult">
        <include refid="selectOmsWarehouseVo"/>
        where status = 1
    </select>


    <select id="selectOmsWarehouseById" parameterType="Long" resultMap="OmsWarehouseResult">
        <include refid="selectOmsWarehouseVo"/>
        where warehouse_id = #{warehouseId}
    </select>

    <insert id="insertOmsWarehouse" parameterType="OmsWarehouse" useGeneratedKeys="true" keyProperty="warehouseId">
        insert into oms_warehouse
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warehouseName != null">warehouse_name,</if>
            <if test="warehouseCode != null">warehouse_code,</if>
            <if test="warehouseType != null">warehouse_type,</if>
            <if test="linkUsername != null">link_username,</if>
            <if test="linkPhone != null">link_phone,</if>
            <if test="cityIds != null">city_ids,</if>
            <if test="address != null">address,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
            <if test="rate != null">rate,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warehouseName != null">#{warehouseName},</if>
            <if test="warehouseCode != null">#{warehouseCode},</if>
            <if test="warehouseType != null">#{warehouseType},</if>
            <if test="linkUsername != null">#{linkUsername},</if>
            <if test="linkPhone != null">#{linkPhone},</if>
            <if test="cityIds != null">#{cityIds},</if>
            <if test="address != null">#{address},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
            <if test="rate != null">#{rate},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateOmsWarehouse" parameterType="OmsWarehouse">
        update oms_warehouse
        <trim prefix="SET" suffixOverrides=",">
            <if test="warehouseName != null">warehouse_name = #{warehouseName},</if>
            <if test="warehouseCode != null">warehouse_code = #{warehouseCode},</if>
            <if test="warehouseType != null">warehouse_type = #{warehouseType},</if>
            <if test="linkUsername != null">link_username = #{linkUsername},</if>
            <if test="linkPhone != null">link_phone = #{linkPhone},</if>
            <if test="cityIds != null">city_ids = #{cityIds},</if>
            <if test="address != null">address = #{address},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="rate != null">rate = #{rate},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where warehouse_id = #{warehouseId}
    </update>

    <delete id="deleteOmsWarehouseById" parameterType="Long">
        delete from oms_warehouse where warehouse_id = #{warehouseId}
    </delete>

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

</mapper>
