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

    <resultMap type="NpYogurtInsp" id="NpYogurtInspResult">
        <result property="id"    column="id"    />
        <result property="source"    column="source"    />
        <result property="datetime"    column="datetime"    />
        <result property="fat"    column="fat"    />
        <result property="protein"    column="protein"    />
        <result property="nonFat"    column="non_fat"    />
        <result property="acidity"    column="acidity"    />
        <result property="bacterialColony1"    column="bacterial_colony_1"    />
        <result property="bacterialClony2"    column="bacterial_clony_2"    />
        <result property="bacterialClony3"    column="bacterial_clony_3"    />
        <result property="bacterialClony4"    column="bacterial_clony_4"    />
        <result property="bacterialClony5"    column="bacterial_clony_5"    />
        <result property="yeast"    column="yeast"    />
        <result property="mould"    column="mould"    />
        <result property="lacto"    column="lacto"    />
        <result property="comment"    column="comment"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectNpYogurtInspVo">
        select id, source, datetime, fat, protein, non_fat,
               acidity, bacterial_colony_1, bacterial_clony_2,
               bacterial_clony_3, bacterial_clony_4, bacterial_clony_5,
               yeast, mould, lacto, comment, create_by, create_time
        from np_yogurt_insp
    </sql>

    <select id="selectNpYogurtInspList" parameterType="NpYogurtInsp" resultMap="NpYogurtInspResult">
        <include refid="selectNpYogurtInspVo"/>
        <where>
            <if test="source != null  and source != ''">
                and source like concat('%', #{source}, '%')
            </if>
            <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>
        </where>
    </select>

    <select id="selectNpYogurtInspById" parameterType="Long" resultMap="NpYogurtInspResult">
        <include refid="selectNpYogurtInspVo"/>
        where id = #{id}
    </select>

    <insert id="insertNpYogurtInsp" parameterType="NpYogurtInsp" useGeneratedKeys="true" keyProperty="id">
        insert into np_yogurt_insp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="source != null">source,</if>
            <if test="datetime != null">datetime,</if>
            <if test="fat != null">fat,</if>
            <if test="protein != null">protein,</if>
            <if test="nonFat != null">non_fat,</if>
            <if test="acidity != null">acidity,</if>
            <if test="bacterialColony1 != null">bacterial_colony_1,</if>
            <if test="bacterialClony2 != null">bacterial_clony_2,</if>
            <if test="bacterialClony3 != null">bacterial_clony_3,</if>
            <if test="bacterialClony4 != null">bacterial_clony_4,</if>
            <if test="bacterialClony5 != null">bacterial_clony_5,</if>
            <if test="yeast != null">yeast,</if>
            <if test="mould != null">mould,</if>
            <if test="lacto != null">lacto,</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="source != null">#{source},</if>
            <if test="datetime != null">#{datetime},</if>
            <if test="fat != null">#{fat},</if>
            <if test="protein != null">#{protein},</if>
            <if test="nonFat != null">#{nonFat},</if>
            <if test="acidity != null">#{acidity},</if>
            <if test="bacterialColony1 != null">#{bacterialColony1},</if>
            <if test="bacterialClony2 != null">#{bacterialClony2},</if>
            <if test="bacterialClony3 != null">#{bacterialClony3},</if>
            <if test="bacterialClony4 != null">#{bacterialClony4},</if>
            <if test="bacterialClony5 != null">#{bacterialClony5},</if>
            <if test="yeast != null">#{yeast},</if>
            <if test="mould != null">#{mould},</if>
            <if test="lacto != null">#{lacto},</if>
            <if test="comment != null">#{comment},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateNpYogurtInsp" parameterType="NpYogurtInsp">
        update np_yogurt_insp
        <trim prefix="SET" suffixOverrides=",">
            <if test="source != null">source = #{source},</if>
            <if test="datetime != null">datetime = #{datetime},</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="acidity != null">acidity = #{acidity},</if>
            <if test="bacterialColony1 != null">bacterial_colony_1 = #{bacterialColony1},</if>
            <if test="bacterialClony2 != null">bacterial_clony_2 = #{bacterialClony2},</if>
            <if test="bacterialClony3 != null">bacterial_clony_3 = #{bacterialClony3},</if>
            <if test="bacterialClony4 != null">bacterial_clony_4 = #{bacterialClony4},</if>
            <if test="bacterialClony5 != null">bacterial_clony_5 = #{bacterialClony5},</if>
            <if test="yeast != null">yeast = #{yeast},</if>
            <if test="mould != null">mould = #{mould},</if>
            <if test="lacto != null">lacto = #{lacto},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNpYogurtInspById" parameterType="Long">
        delete from np_yogurt_insp where id = #{id}
    </delete>

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