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

    <resultMap type="RecordInStore" id="RecordInStoreResult">
            <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="materialType"    column="material_type"    />
            <result property="materialCode"    column="material_code"    />
            <result property="inStoreAmount"    column="in_store_amount"    />
            <result property="inStoreTime"    column="in_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="materialName"    column="material_name"    />
            <result property="entryPattern"    column="entry_pattern"    />
    </resultMap>

    <sql id="selectRecordInStoreVo">
        select obj_id, store_code, store_area, space_code, material_type, material_code, in_store_amount, in_store_time, is_flag, created_by, created_time, updated_by, updated_time, barcode_code, material_name, entry_pattern from record_instore
    </sql>

    <select id="selectRecordInStoreList" parameterType="RecordInStore" resultMap="RecordInStoreResult">
        <include refid="selectRecordInStoreVo"/>
        <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="materialType != null  and materialType != ''"> and material_type = #{materialType}</if>
                        <if test="materialCode != null  and materialCode != ''"> and material_code = #{materialCode}</if>
                        <if test="inStoreAmount != null "> and in_store_amount = #{inStoreAmount}</if>
                        <if test="params.beginInStoreTime != null and params.beginInStoreTime != '' and params.endInStoreTime != null and params.endInStoreTime != ''">
                        and in_store_time between to_date(#{params.beginInStoreTime}, 'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endInStoreTime}, '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="materialName != null  and materialName != ''"> and material_name like concat(concat('%', #{materialName}), '%')</if>
                        <if test="entryPattern != null "> and entry_pattern = #{entryPattern}</if>
        </where>
    </select>

    <select id="selectRecordInStoreByObjId" parameterType="Long" resultMap="RecordInStoreResult">
            <include refid="selectRecordInStoreVo"/>
            where obj_id = #{objId}
    </select>

    <insert id="insertRecordInStore" parameterType="RecordInStore">
            <selectKey keyProperty="objId" resultType="long" order="BEFORE">
                SELECT seq_record_instore.NEXTVAL as objId FROM DUAL
            </selectKey>
        insert into record_instore
        <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="materialType != null">material_type,</if>
                <if test="materialCode != null">material_code,</if>
                <if test="inStoreAmount != null">in_store_amount,</if>
                <if test="inStoreTime != null">in_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="materialName != null">material_name,</if>
                <if test="entryPattern != null">entry_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="materialType != null">#{materialType},</if>
                <if test="materialCode != null">#{materialCode},</if>
                <if test="inStoreAmount != null">#{inStoreAmount},</if>
                <if test="inStoreTime != null">#{inStoreTime},</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="materialName != null">#{materialName},</if>
                <if test="entryPattern != null">#{entryPattern},</if>
        </trim>
    </insert>

    <update id="updateRecordInStore" parameterType="RecordInStore">
        update record_instore
        <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="materialType != null">material_type = #{materialType},</if>
                    <if test="materialCode != null">material_code = #{materialCode},</if>
                    <if test="inStoreAmount != null">in_store_amount = #{inStoreAmount},</if>
                    <if test="inStoreTime != null">in_store_time = #{inStoreTime},</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="materialName != null">material_name = #{materialName},</if>
                    <if test="entryPattern != null">entry_pattern = #{entryPattern},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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