<?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.aucma.base.mapper.RecordOutStoreMapper">

    <resultMap type="RecordOutStore" id="RecordOutStoreResult">
        <result property="objId" column="obj_id"/>
        <result property="storeCode" column="store_code"/>
        <result property="storeArea" column="store_area"/>
        <result property="spaceCode" column="space_code"/>
        <result property="materialCode" column="material_code"/>
        <result property="materialName" column="material_name"/>
        <result property="outStoreAmount" column="out_store_amount"/>
        <result property="outStoreTime" column="out_store_time"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="barcodeCode" column="barcode_code"/>
        <result property="materialType" column="material_type"/>
        <result property="exitPattern" column="exit_pattern"/>
    </resultMap>

    <sql id="selectRecordOutStoreVo">
        select obj_id,
               store_code,
               store_area,
               space_code,
               material_code,
               material_name,
               out_store_amount,
               out_store_time,
               is_flag,
               created_by,
               created_time,
               updated_by,
               updated_time,
               barcode_code,
               material_type,
               exit_pattern
        from record_outstore
    </sql>

    <select id="selectRecordOutStoreList" parameterType="RecordOutStore" resultMap="RecordOutStoreResult">
        <include refid="selectRecordOutStoreVo"/>
        <where>
            <if test="storeCode != null  and storeCode != ''">and store_code = #{storeCode}</if>
            <if test="storeArea != null  and storeArea != ''">and store_area = #{storeArea}</if>
            <if test="spaceCode != null  and spaceCode != ''">and space_code = #{spaceCode}</if>
            <if test="materialCode != null  and materialCode != ''">and material_code = #{materialCode}</if>
            <if test="materialName != null  and materialName != ''">and material_name like concat(concat('%',
                #{materialName}), '%')
            </if>
            <if test="outStoreAmount != null ">and out_store_amount = #{outStoreAmount}</if>
            <if test="params.beginOutStoreTime != null and params.beginOutStoreTime != '' and params.endOutStoreTime != null and params.endOutStoreTime != ''">
                and out_store_time between to_date(#{params.beginOutStoreTime}, 'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endOutStoreTime}, 'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="createdTime != null ">and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
            <if test="barcodeCode != null  and barcodeCode != ''">and barcode_code = #{barcodeCode}</if>
            <if test="materialType != null  and materialType != ''">and material_type = #{materialType}</if>
            <if test="exitPattern != null ">and exit_pattern = #{exitPattern}</if>
        </where>
    </select>

    <select id="selectRecordOutStoreByObjId" parameterType="Long" resultMap="RecordOutStoreResult">
        <include refid="selectRecordOutStoreVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertRecordOutStore" parameterType="RecordOutStore">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_record_outstore.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into record_outstore
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="storeCode != null">store_code,</if>
            <if test="storeArea != null">store_area,</if>
            <if test="spaceCode != null">space_code,</if>
            <if test="materialCode != null">material_code,</if>
            <if test="materialName != null">material_name,</if>
            <if test="outStoreAmount != null">out_store_amount,</if>
            <if test="outStoreTime != null">out_store_time,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="barcodeCode != null">barcode_code,</if>
            <if test="materialType != null">material_type,</if>
            <if test="exitPattern != null">exit_pattern,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="storeCode != null">#{storeCode},</if>
            <if test="storeArea != null">#{storeArea},</if>
            <if test="spaceCode != null">#{spaceCode},</if>
            <if test="materialCode != null">#{materialCode},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="outStoreAmount != null">#{outStoreAmount},</if>
            <if test="outStoreTime != null">#{outStoreTime},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="barcodeCode != null">#{barcodeCode},</if>
            <if test="materialType != null">#{materialType},</if>
            <if test="exitPattern != null">#{exitPattern},</if>
        </trim>
    </insert>

    <update id="updateRecordOutStore" parameterType="RecordOutStore">
        update record_outstore
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeCode != null">store_code = #{storeCode},</if>
            <if test="storeArea != null">store_area = #{storeArea},</if>
            <if test="spaceCode != null">space_code = #{spaceCode},</if>
            <if test="materialCode != null">material_code = #{materialCode},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="outStoreAmount != null">out_store_amount = #{outStoreAmount},</if>
            <if test="outStoreTime != null">out_store_time = #{outStoreTime},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
            <if test="barcodeCode != null">barcode_code = #{barcodeCode},</if>
            <if test="materialType != null">material_type = #{materialType},</if>
            <if test="exitPattern != null">exit_pattern = #{exitPattern},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteRecordOutStoreByObjId" parameterType="Long">
        delete
        from record_outstore
        where obj_id = #{objId}
    </delete>

    <delete id="deleteRecordOutStoreByObjIds" parameterType="String">
        delete from record_outstore where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>