<?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.sgzb.base.mapper.MaTypeHisPriceMapper">

    <resultMap type="com.bonus.sgzb.base.domain.MaTypeHisPrice" id="MaTypeHisPriceResult">
        <id     property="typeId"      column="type_id"      />
        <result property="leasePrice"    column="lease_price"    />
        <result property="time"     column="time"     />
        <result property="status"   column="status"   />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectMaTypeHisPrice">
        select type_id, lease_price, time, status, company_id
        from ma_type_his_price
    </sql>

    <select id="getTypeHisPrice" resultType="com.bonus.sgzb.base.domain.MaTypeHisPrice">

        select type_id, lease_price, time, status, company_id
        from ma_type_his_price
        <where>
            <if test="typeId != null and typeId != ''">
                AND type_id = #{typeId}
            </if>
            <if test="leasePrice != null and leasePrice != ''">
                AND lease_price = #{leasePrice}
            </if>
            <if test="time != null and time != ''">
                AND time = #{time}
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="companyId != null and companyId != ''">
                and company_id = #{companyId}
            </if>

        </where>
    </select>

    <insert id="typeHisPriceAdd" parameterType="com.bonus.sgzb.base.domain.MaTypeHisPrice">
        insert into ma_type_his_price (
        <if test="leasePrice != null and leasePrice != '' ">ma_code,</if>
        <if test="time != null and time != '' ">time,</if>
        <if test="status != null and status != '' ">status,</if>
        <if test="companyId != null and companyId != ''">company_id</if>
        )values(
        <if test="leasePrice != null and leasePrice != ''">#{leasePrice},</if>
        <if test="time != null and time != ''">#{time},</if>
        <if test="status != null and status != ''">#{status},</if>
        <if test="companyId != null and companyId != ''">#{companyId},</if>
        )
    </insert>

    <update id="updateTypeHisPrice" parameterType="com.bonus.sgzb.base.domain.MaTypeHisPrice">
        update ma_type_his_price
        <set>
            <if test="leasePrice != null and leasePrice != ''">ma_code = #{leasePrice},</if>
            <if test="time != null and time != ''">time = #{time},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>

        </set>
        where type_id = #{typeId}
    </update>
    <delete id="remove" parameterType="Long">
        delete from ma_type_his_price where type_id in
        <foreach item="typeId" collection="array" open="(" separator="," close=")">
            #{typeId}
        </foreach>
    </delete>
</mapper>