<?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.cim.idm.dao.WareHouseDao">

    <update id="edit">
        update BS_ERPLOCATION set USE_LOCATION = #{dto.useLocation}, IS_OVEN = #{dto.isOven}
        where ERPFACTORYNAME = #{dto.erpFactoryName} and ERPLOCATIONNAME = #{dto.erpLocationName}
    </update>

    <select id="page" resultType="com.cim.idm.model.po.storage.StorageSpec">
        select SITENAME, STORAGENAME, DESCRIPTION, STORAGEUSETYPE
        from STORAGESPEC
        <where>
            <if test="dto.storageName != null and dto.storageName != ''">
                AND STORAGENAME LIKE '%'||#{dto.storageName}||'%'
            </if>
            <if test="dto.description != null and dto.description != ''">
                AND DESCRIPTION LIKE '%'||#{dto.description}||'%'
            </if>
            <if test="dto.storageUseType != null and dto.storageUseType != ''">
                AND STORAGEUSETYPE = #{dto.storageUseType}
            </if>
        </where>
    </select>

    <select id="get" resultType="com.cim.idm.model.po.storage.StorageSpec">
        select SITENAME, STORAGENAME, DESCRIPTION
        from STORAGESPEC
        where SITENAME = #{siteName}
        and STORAGENAME = #{storageName}
    </select>

    <insert id="add">
        insert into STORAGESPEC(SITENAME, STORAGENAME, DESCRIPTION, STORAGEUSETYPE)
        values (#{storageSpec.siteName}, #{storageSpec.storageName}, #{storageSpec.description}, #{storageSpec.storageUseType})
    </insert>

    <update id="editStorage">
        update STORAGESPEC set DESCRIPTION = #{edit.description} ,STORAGEUSETYPE = #{edit.storageUseType}
        where SITENAME = #{edit.siteName}
        and STORAGENAME = #{edit.storageName}
    </update>

    <delete id="delStorage">
        delete from STORAGESPEC
        where SITENAME = #{del.siteName}
        and STORAGENAME = #{del.storageName}
    </delete>

    <select id="search" resultType="com.cim.idm.model.po.storage.StorageSpec">
        select SITENAME, STORAGENAME, DESCRIPTION
        from STORAGESPEC
        where 1 = 1 AND
        <foreach item="type" index="index" collection="prefix" open="(" separator="or" close=")">
            STORAGENAME LIKE #{type}||'%'
        </foreach>
        <if test="storageName != null and storageName != ''">
            AND STORAGENAME LIKE #{storageName}||'%'
        </if>
    </select>
</mapper>