<?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.zhyc.module.dairyProducts.mapper.NpRawMilkInspeMapper">

    <resultMap type="NpRawMilkInspe" id="NpRawMilkInspeResult">
        <result property="id"    column="id"    />
        <result property="datetime"    column="datetime"    />
        <result property="source"    column="source"    />
        <result property="freeze"    column="freeze"    />
        <result property="density"    column="density"    />
        <result property="fat"    column="fat"    />
        <result property="protein"    column="protein"    />
        <result property="nonFat"    column="non_fat"    />
        <result property="dryMatter"    column="dry_matter"    />
        <result property="impurityDegree"    column="impurity"    />
        <result property="lactose"    column="lactose"    />
        <result property="ashContent"    column="ash_content"    />
        <result property="acidity"    column="acidity"    />
        <result property="ph"    column="ph"    />
        <result property="bacterialColony"    column="bacterial_colony"    />
        <result property="lactoferrin"    column="lactoferrin"    />
        <result property="ig"    column="ig"    />
        <result property="somaticCell"    column="somatic_cell"    />
        <result property="usea"    column="usea"    />
        <result property="fatRatio"    column="fat_ratio"    />
        <result property="comment"    column="comment"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectNpRawMilkInspeVo">
        select id, datetime, source, freeze, density, fat, protein, non_fat, dry_matter,
               impurity, lactose, ash_content, acidity, ph, bacterial_colony, lactoferrin,
               ig, somatic_cell, usea, fat_ratio, comment, create_by, create_time
        from np_raw_milk_inspe
    </sql>

    <select id="selectNpRawMilkInspeList" parameterType="NpRawMilkInspe" resultMap="NpRawMilkInspeResult">
        <include refid="selectNpRawMilkInspeVo"/>
        <where>
            <if test="params.beginTime != null and params.beginTime != ''">
                and datetime &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and datetime &lt;= #{params.endTime}
            </if>
            <if test="source != null  and source != ''"> and source like concat('%', #{source}, '%')</if>
        </where>
    </select>

    <select id="selectNpRawMilkInspeById" parameterType="Long" resultMap="NpRawMilkInspeResult">
        <include refid="selectNpRawMilkInspeVo"/>
        where id = #{id}
    </select>

    <insert id="insertNpRawMilkInspe" parameterType="NpRawMilkInspe" useGeneratedKeys="true" keyProperty="id">
        insert into np_raw_milk_inspe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="datetime != null">datetime,</if>
            <if test="source != null">source,</if>
            <if test="freeze != null">freeze,</if>
            <if test="density != null">density,</if>
            <if test="fat != null">fat,</if>
            <if test="protein != null">protein,</if>
            <if test="nonFat != null">non_fat,</if>
            <if test="dryMatter != null">dry_matter,</if>
            <if test="impurityDegree != null">impurity,</if>
            <if test="lactose != null">lactose,</if>
            <if test="ashContent != null">ash_content,</if>
            <if test="acidity != null">acidity,</if>
            <if test="ph != null">ph,</if>
            <if test="bacterialColony != null">bacterial_colony,</if>
            <if test="lactoferrin != null">lactoferrin,</if>
            <if test="ig != null">ig,</if>
            <if test="somaticCell != null">somatic_cell,</if>
            <if test="usea != null">usea,</if>
            <if test="fatRatio != null">fat_ratio,</if>
            <if test="comment != null">comment,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="datetime != null">#{datetime},</if>
            <if test="source != null">#{source},</if>
            <if test="freeze != null">#{freeze},</if>
            <if test="density != null">#{density},</if>
            <if test="fat != null">#{fat},</if>
            <if test="protein != null">#{protein},</if>
            <if test="nonFat != null">#{nonFat},</if>
            <if test="dryMatter != null">#{dryMatter},</if>
            <if test="impurityDegree != null">#{impurityDegree},</if>
            <if test="lactose != null">#{lactose},</if>
            <if test="ashContent != null">#{ashContent},</if>
            <if test="acidity != null">#{acidity},</if>
            <if test="ph != null">#{ph},</if>
            <if test="bacterialColony != null">#{bacterialColony},</if>
            <if test="lactoferrin != null">#{lactoferrin},</if>
            <if test="ig != null">#{ig},</if>
            <if test="somaticCell != null">#{somaticCell},</if>
            <if test="usea != null">#{usea},</if>
            <if test="fatRatio != null">#{fatRatio},</if>
            <if test="comment != null">#{comment},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateNpRawMilkInspe" parameterType="NpRawMilkInspe">
        update np_raw_milk_inspe
        <trim prefix="SET" suffixOverrides=",">
            <if test="datetime != null">datetime = #{datetime},</if>
            <if test="source != null">source = #{source},</if>
            <if test="freeze != null">freeze = #{freeze},</if>
            <if test="density != null">density = #{density},</if>
            <if test="fat != null">fat = #{fat},</if>
            <if test="protein != null">protein = #{protein},</if>
            <if test="nonFat != null">non_fat = #{nonFat},</if>
            <if test="dryMatter != null">dry_matter = #{dryMatter},</if>
            <if test="impurityDegree != null">impurity = #{impurityDegree},</if>
            <if test="lactose != null">lactose = #{lactose},</if>
            <if test="ashContent != null">ash_content = #{ashContent},</if>
            <if test="acidity != null">acidity = #{acidity},</if>
            <if test="ph != null">ph = #{ph},</if>
            <if test="bacterialColony != null">bacterial_colony = #{bacterialColony},</if>
            <if test="lactoferrin != null">lactoferrin = #{lactoferrin},</if>
            <if test="ig != null">ig = #{ig},</if>
            <if test="somaticCell != null">somatic_cell = #{somaticCell},</if>
            <if test="usea != null">usea = #{usea},</if>
            <if test="fatRatio != null">fat_ratio = #{fatRatio},</if>
            <if test="comment != null">comment = #{comment},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNpRawMilkInspeById" parameterType="Long">
        delete from np_raw_milk_inspe where id = #{id}
    </delete>

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