<?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.bonus.material.ma.mapper.TypeNumHisMapper">
    <resultMap type="com.bonus.material.ma.domain.TypeNumHis" id="TypeNumHisResult">
        <result property="typeId"    column="type_id"    />
        <result property="storageNum"    column="storage_num"    />
        <result property="saveTime"    column="save_time"    />
        <result property="status"    column="status"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTypeNumHisVo">
        select type_id, storage_num, save_time, status, company_id, create_time, update_time from ma_type_num_his
    </sql>

    <select id="selectTypeNumHisList" parameterType="com.bonus.material.ma.domain.TypeNumHis" resultMap="TypeNumHisResult">
        <include refid="selectTypeNumHisVo"/>
        <where>  
            <if test="storageNum != null "> and storage_num = #{storageNum}</if>
            <if test="saveTime != null "> and save_time = #{saveTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectTypeNumHisByTypeId" parameterType="Long" resultMap="TypeNumHisResult">
        <include refid="selectTypeNumHisVo"/>
        where type_id = #{typeId}
    </select>
        
    <insert id="insertTypeNumHis" parameterType="com.bonus.material.ma.domain.TypeNumHis" useGeneratedKeys="true" keyProperty="typeId">
        insert into ma_type_num_his
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storageNum != null">storage_num,</if>
            <if test="saveTime != null">save_time,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storageNum != null">#{storageNum},</if>
            <if test="saveTime != null">#{saveTime},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTypeNumHis" parameterType="com.bonus.material.ma.domain.TypeNumHis">
        update ma_type_num_his
        <trim prefix="SET" suffixOverrides=",">
            <if test="storageNum != null">storage_num = #{storageNum},</if>
            <if test="saveTime != null">save_time = #{saveTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where type_id = #{typeId}
    </update>

    <delete id="deleteTypeNumHisByTypeId" parameterType="Long">
        delete from ma_type_num_his where type_id = #{typeId}
    </delete>

    <delete id="deleteTypeNumHisByTypeIds" parameterType="String">
        delete from ma_type_num_his where type_id in 
        <foreach item="typeId" collection="array" open="(" separator="," close=")">
            #{typeId}
        </foreach>
    </delete>
</mapper>