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

    <resultMap type="PlatGreenFoods" id="PlatGreenFoodsResult">
        <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="appName"    column="app_name"    />
        <result property="foodInfo"    column="food_info"    />
    </resultMap>

    <sql id="selectPlatGreenFoodsVo">
        select id, del_flag, create_by, create_time, update_by, update_time, app_org, app_name, food_info from large_plat_green_foods
    </sql>

    <select id="selectPlatGreenFoodsList" parameterType="PlatGreenFoods" resultMap="PlatGreenFoodsResult">
        <include refid="selectPlatGreenFoodsVo"/>
        <where>
            <if test="appOrg != null  and appOrg != ''"> and app_org = #{appOrg}</if>
            <if test="appName != null  and appName != ''"> and app_name like concat('%', #{appName}, '%')</if>
            <if test="foodInfo != null  and foodInfo != ''"> and food_info = #{foodInfo}</if>
        </where>
    </select>

    <select id="selectPlatGreenFoodsById" parameterType="Long" resultMap="PlatGreenFoodsResult">
        <include refid="selectPlatGreenFoodsVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlatGreenFoods" parameterType="PlatGreenFoods" useGeneratedKeys="true" keyProperty="id">
        insert into large_plat_green_foods
        <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="appName != null">app_name,</if>
            <if test="foodInfo != null">food_info,</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="appName != null">#{appName},</if>
            <if test="foodInfo != null">#{foodInfo},</if>
         </trim>
    </insert>

    <update id="updatePlatGreenFoods" parameterType="PlatGreenFoods">
        update large_plat_green_foods
        <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="appName != null">app_name = #{appName},</if>
            <if test="foodInfo != null">food_info = #{foodInfo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlatGreenFoodsById" parameterType="Long">
        delete from large_plat_green_foods where id = #{id}
    </delete>

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

    <select id="getFoodsTypeNum" parameterType="String" resultType="String">
        select food_info from large_plat_green_foods where app_org = #{appOrg}
    </select>
</mapper>
