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

    <resultMap type="FsWarehouses" id="FsWarehousesResult">
        <result property="id"    column="id"    />
        <result property="warehouseName"    column="warehouse_name"    />
        <result property="warehouseCode"    column="warehouse_code"    />
        <result property="warehouseAddress"    column="warehouse_address"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contactPhone"    column="contact_phone"    />
        <result property="isActive"    column="is_active"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectFsWarehousesVo">
        select id, warehouse_name, warehouse_code, warehouse_address, contact_person, contact_phone, is_active, created_at, updated_at, remark from fs_warehouses
    </sql>

    <select id="selectFsWarehousesList" parameterType="FsWarehouses" resultMap="FsWarehousesResult">
        <include refid="selectFsWarehousesVo"/>
        <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="warehouseAddress != null  and warehouseAddress != ''"> and warehouse_address = #{warehouseAddress}</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person = #{contactPerson}</if>
            <if test="contactPhone != null  and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
            <if test="isActive != null "> and is_active = #{isActive}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>

    <select id="selectFsWarehousesById" parameterType="Long" resultMap="FsWarehousesResult">
        <include refid="selectFsWarehousesVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsWarehouses" parameterType="FsWarehouses" useGeneratedKeys="true" keyProperty="id">
        insert into fs_warehouses
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warehouseName != null and warehouseName != ''">warehouse_name,</if>
            <if test="warehouseCode != null">warehouse_code,</if>
            <if test="warehouseAddress != null">warehouse_address,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="contactPhone != null">contact_phone,</if>
            <if test="isActive != null">is_active,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warehouseName != null and warehouseName != ''">#{warehouseName},</if>
            <if test="warehouseCode != null">#{warehouseCode},</if>
            <if test="warehouseAddress != null">#{warehouseAddress},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="contactPhone != null">#{contactPhone},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFsWarehouses" parameterType="FsWarehouses">
        update fs_warehouses
        <trim prefix="SET" suffixOverrides=",">
            <if test="warehouseName != null and warehouseName != ''">warehouse_name = #{warehouseName},</if>
            <if test="warehouseCode != null">warehouse_code = #{warehouseCode},</if>
            <if test="warehouseAddress != null">warehouse_address = #{warehouseAddress},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="contactPhone != null">contact_phone = #{contactPhone},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsWarehousesById" parameterType="Long">
        delete from fs_warehouses where id = #{id}
    </delete>

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

</mapper>
