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

    <resultMap type="NpFreshMilkInsp" id="NpFreshMilkInspResult">
        <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="bacterialColony2" column="bacterial_colony_2" />
        <result property="bacterialColony3" column="bacterial_colony_3" />
        <result property="bacterialColony4" column="bacterial_colony_4" />
        <result property="bacterialColony5" column="bacterial_colony_5" />
        <result property="coli" column="coli" />
        <result property="lactoferrin" column="lactoferrin" />
        <result property="ig" column="ig" />
        <result property="commnet" column="commnet" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
    </resultMap>

    <sql id="selectNpFreshMilkInspVo">
        SELECT
            id, source, datetime, fat, protein, non_fat, acidity,
            bacterial_colony_1, bacterial_colony_2, bacterial_colony_3,
            bacterial_colony_4, bacterial_colony_5, coli, lactoferrin,
            ig, commnet, create_by, create_time
        FROM np_fresh_milk_insp a
    </sql>

    <select id="selectNpFreshMilkInspList" parameterType="NpFreshMilkInsp" resultMap="NpFreshMilkInspResult">
        <include refid="selectNpFreshMilkInspVo"/>
        <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>

            ${params.dataScope}
        </where>
    </select>

    <select id="selectNpFreshMilkInspById" parameterType="Long" resultMap="NpFreshMilkInspResult">
        <include refid="selectNpFreshMilkInspVo"/>
        WHERE id = #{id}
    </select>

    <insert id="insertNpFreshMilkInsp" parameterType="NpFreshMilkInsp" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO np_fresh_milk_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="bacterialColony2 != null">bacterial_colony_2,</if>
            <if test="bacterialColony3 != null">bacterial_colony_3,</if>
            <if test="bacterialColony4 != null">bacterial_colony_4,</if>
            <if test="bacterialColony5 != null">bacterial_colony_5,</if>
            <if test="coli != null">coli,</if>
            <if test="lactoferrin != null">lactoferrin,</if>
            <if test="ig != null">ig,</if>
            <if test="commnet != null">commnet,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</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="bacterialColony2 != null">#{bacterialColony2},</if>
            <if test="bacterialColony3 != null">#{bacterialColony3},</if>
            <if test="bacterialColony4 != null">#{bacterialColony4},</if>
            <if test="bacterialColony5 != null">#{bacterialColony5},</if>
            <if test="coli != null">#{coli},</if>
            <if test="lactoferrin != null">#{lactoferrin},</if>
            <if test="ig != null">#{ig},</if>
            <if test="commnet != null">#{commnet},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateNpFreshMilkInsp" parameterType="NpFreshMilkInsp">
        UPDATE np_fresh_milk_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="bacterialColony2 != null">bacterial_colony_2 = #{bacterialColony2},</if>
            <if test="bacterialColony3 != null">bacterial_colony_3 = #{bacterialColony3},</if>
            <if test="bacterialColony4 != null">bacterial_colony_4 = #{bacterialColony4},</if>
            <if test="bacterialColony5 != null">bacterial_colony_5 = #{bacterialColony5},</if>
            <if test="coli != null">coli = #{coli},</if>
            <if test="lactoferrin != null">lactoferrin = #{lactoferrin},</if>
            <if test="ig != null">ig = #{ig},</if>
            <if test="commnet != null">commnet = #{commnet},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteNpFreshMilkInspById" parameterType="Long">
        DELETE FROM np_fresh_milk_insp WHERE id = #{id}
    </delete>

    <delete id="deleteNpFreshMilkInspByIds" parameterType="String">
        DELETE FROM np_fresh_milk_insp WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>