<?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.xinelu.manage.mapper.basedietinfo.BaseDietInfoMapper">

    <resultMap type="BaseDietInfo" id="BaseDietInfoResult">
            <result property="id" column="id"/>
            <result property="dietName" column="diet_name"/>
            <result property="dietPrinciple" column="diet_principle"/>
            <result property="mainFood" column="main_food"/>
            <result property="vegetable" column="vegetable"/>
            <result property="fruit" column="fruit"/>
            <result property="meat" column="meat"/>
            <result property="dietRemark" column="diet_remark"/>
            <result property="createTime" column="create_time"/>
            <result property="createBy" column="create_by"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBaseDietInfoVo">
        select id, diet_name, diet_principle, main_food, vegetable, fruit, meat, diet_remark, create_time, create_by, update_by, update_time from base_diet_info
    </sql>

    <select id="selectBaseDietInfoList" parameterType="BaseDietInfo" resultMap="BaseDietInfoResult">
        <include refid="selectBaseDietInfoVo"/>
        <where>
                        <if test="dietName != null  and dietName != ''">
                            and diet_name like concat('%', #{dietName}, '%')
                        </if>
                        <if test="dietPrinciple != null  and dietPrinciple != ''">
                            and diet_principle = #{dietPrinciple}
                        </if>
                        <if test="mainFood != null  and mainFood != ''">
                            and main_food = #{mainFood}
                        </if>
                        <if test="vegetable != null  and vegetable != ''">
                            and vegetable = #{vegetable}
                        </if>
                        <if test="fruit != null  and fruit != ''">
                            and fruit = #{fruit}
                        </if>
                        <if test="meat != null  and meat != ''">
                            and meat = #{meat}
                        </if>
                        <if test="dietRemark != null  and dietRemark != ''">
                            and diet_remark = #{dietRemark}
                        </if>
        </where>
    </select>

    <select id="selectBaseDietInfoById" parameterType="Long"
            resultMap="BaseDietInfoResult">
            <include refid="selectBaseDietInfoVo"/>
            where id = #{id}
    </select>

    <insert id="insertBaseDietInfo" parameterType="BaseDietInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into base_diet_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="dietName != null">diet_name,
                    </if>
                    <if test="dietPrinciple != null">diet_principle,
                    </if>
                    <if test="mainFood != null">main_food,
                    </if>
                    <if test="vegetable != null">vegetable,
                    </if>
                    <if test="fruit != null">fruit,
                    </if>
                    <if test="meat != null">meat,
                    </if>
                    <if test="dietRemark != null">diet_remark,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="dietName != null">#{dietName},
                    </if>
                    <if test="dietPrinciple != null">#{dietPrinciple},
                    </if>
                    <if test="mainFood != null">#{mainFood},
                    </if>
                    <if test="vegetable != null">#{vegetable},
                    </if>
                    <if test="fruit != null">#{fruit},
                    </if>
                    <if test="meat != null">#{meat},
                    </if>
                    <if test="dietRemark != null">#{dietRemark},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
        </trim>
    </insert>

    <update id="updateBaseDietInfo" parameterType="BaseDietInfo">
        update base_diet_info
        <trim prefix="SET" suffixOverrides=",">
                    <if test="dietName != null">diet_name =
                        #{dietName},
                    </if>
                    <if test="dietPrinciple != null">diet_principle =
                        #{dietPrinciple},
                    </if>
                    <if test="mainFood != null">main_food =
                        #{mainFood},
                    </if>
                    <if test="vegetable != null">vegetable =
                        #{vegetable},
                    </if>
                    <if test="fruit != null">fruit =
                        #{fruit},
                    </if>
                    <if test="meat != null">meat =
                        #{meat},
                    </if>
                    <if test="dietRemark != null">diet_remark =
                        #{dietRemark},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseDietInfoById" parameterType="Long">
        delete from base_diet_info where id = #{id}
    </delete>

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