<?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.project.zcustom.mapper.smart.PlatGreenSmartSafetyMapper">
    
    <resultMap type="PlatGreenSmartSafety" id="PlatGreenSmartSafetyResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="appOrg"    column="app_org"    />
        <result property="canteenName"    column="canteen_name"    />
        <result property="sampleNum"    column="sample_num"    />
        <result property="positiveNum"    column="positive_num"    />
        <result property="negativeNum"    column="negative_num"    />
        <result property="ingredientsRate"    column="ingredients_rate"    />
        <result property="leaveSampleRate"    column="leave_sample_rate"    />
    </resultMap>

    <sql id="selectPlatGreenSmartSafetyVo">
        select id, del_flag, create_by, create_time, update_by, update_time, app_org, canteen_name, sample_num, positive_num, negative_num, ingredients_rate, leave_sample_rate from large_plat_green_smart_safety
    </sql>

    <select id="selectPlatGreenSmartSafetyList" parameterType="PlatGreenSmartSafety" resultMap="PlatGreenSmartSafetyResult">
        <include refid="selectPlatGreenSmartSafetyVo"/>
        <where>  
            <if test="appOrg != null  and appOrg != ''"> and app_org = #{appOrg}</if>
            <if test="canteenName != null  and canteenName != ''"> and canteen_name like concat('%', #{canteenName}, '%')</if>
            <if test="sampleNum != null "> and sample_num = #{sampleNum}</if>
            <if test="positiveNum != null "> and positive_num = #{positiveNum}</if>
            <if test="negativeNum != null "> and negative_num = #{negativeNum}</if>
            <if test="ingredientsRate != null "> and ingredients_rate = #{ingredientsRate}</if>
            <if test="leaveSampleRate != null "> and leave_sample_rate = #{leaveSampleRate}</if>
        </where>
    </select>
    
    <select id="selectPlatGreenSmartSafetyById" parameterType="Long" resultMap="PlatGreenSmartSafetyResult">
        <include refid="selectPlatGreenSmartSafetyVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlatGreenSmartSafety" parameterType="PlatGreenSmartSafety" useGeneratedKeys="true" keyProperty="id">
        insert into large_plat_green_smart_safety
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="appOrg != null">app_org,</if>
            <if test="canteenName != null">canteen_name,</if>
            <if test="sampleNum != null">sample_num,</if>
            <if test="positiveNum != null">positive_num,</if>
            <if test="negativeNum != null">negative_num,</if>
            <if test="ingredientsRate != null">ingredients_rate,</if>
            <if test="leaveSampleRate != null">leave_sample_rate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="appOrg != null">#{appOrg},</if>
            <if test="canteenName != null">#{canteenName},</if>
            <if test="sampleNum != null">#{sampleNum},</if>
            <if test="positiveNum != null">#{positiveNum},</if>
            <if test="negativeNum != null">#{negativeNum},</if>
            <if test="ingredientsRate != null">#{ingredientsRate},</if>
            <if test="leaveSampleRate != null">#{leaveSampleRate},</if>
         </trim>
    </insert>

    <update id="updatePlatGreenSmartSafety" parameterType="PlatGreenSmartSafety">
        update large_plat_green_smart_safety
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="appOrg != null">app_org = #{appOrg},</if>
            <if test="canteenName != null">canteen_name = #{canteenName},</if>
            <if test="sampleNum != null">sample_num = #{sampleNum},</if>
            <if test="positiveNum != null">positive_num = #{positiveNum},</if>
            <if test="negativeNum != null">negative_num = #{negativeNum},</if>
            <if test="ingredientsRate != null">ingredients_rate = #{ingredientsRate},</if>
            <if test="leaveSampleRate != null">leave_sample_rate = #{leaveSampleRate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlatGreenSmartSafetyById" parameterType="Long">
        delete from large_plat_green_smart_safety where id = #{id}
    </delete>

    <delete id="deletePlatGreenSmartSafetyByIds" parameterType="String">
        delete from large_plat_green_smart_safety where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="reallyDeleteByWrapper">
        DELETE FROM large_plat_green_smart_safety ${ew.customSqlSegment}
    </delete>
</mapper>