<?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.ruoyi.model.mapper.AppFeedingFoodMapper">
    
    <resultMap type="AppFeedingFood" id="AppFeedingFoodResult">
        <result property="feedingFoodId"    column="feeding_food_id"    />
        <result property="serviceFileId"    column="service_file_id"    />
        <result property="feedingFoodImage"    column="feeding_food_image"    />
        <result property="feedingFoodWeight"    column="feeding_food_weight"    />
        <result property="feedingFoodFrequencyDay"    column="feeding_food_frequency_day"    />
        <result property="feedingFoodFrequencyTimes"    column="feeding_food_frequency_times"    />
        <result property="serviceFileInfo"    column="service_file_info"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <resultMap type="com.ruoyi.model.vo.AppFeedingFoodVo" id="AppFeedingFoodResultVo">
        <result property="feedingFoodId"    column="feeding_food_id"    />
        <result property="serviceFileId"    column="service_file_id"    />
        <result property="feedingFoodImage"    column="feeding_food_image"    />
        <result property="feedingFoodWeight"    column="feeding_food_weight"    />
        <result property="feedingFoodFrequencyDay"    column="feeding_food_frequency_day"    />
        <result property="feedingFoodFrequencyTimes"    column="feeding_food_frequency_times"    />
        <result property="serviceFileInfo"    column="service_file_info"    />
        <result property="remark"    column="remark"    />
        <collection property="children" ofType="com.ruoyi.model.domain.AppFeedingFoodType">
            <result property="feedingFoodTypeId"    column="feeding_food_type_id"    />
            <result property="feedingFoodTypeName"    column="feeding_food_type_name"    />
            <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="delFlag"    column="del_flag"    />
        </collection>
    </resultMap>

    <sql id="selectAppFeedingFoodVo">
        select feeding_food_id, service_file_id, feeding_food_image, feeding_food_weight, feeding_food_frequency_day, feeding_food_frequency_times, service_file_info, remark from app_feeding_food
    </sql>

    <select id="selectAppFeedingFoodList" parameterType="AppFeedingFood" resultMap="AppFeedingFoodResult">
        <include refid="selectAppFeedingFoodVo"/>
        <where>  
            <if test="serviceFileId != null "> and service_file_id = #{serviceFileId}</if>
            <if test="feedingFoodImage != null  and feedingFoodImage != ''"> and feeding_food_image = #{feedingFoodImage}</if>
            <if test="feedingFoodWeight != null "> and feeding_food_weight = #{feedingFoodWeight}</if>
            <if test="feedingFoodFrequencyDay != null "> and feeding_food_frequency_day = #{feedingFoodFrequencyDay}</if>
            <if test="feedingFoodFrequencyTimes != null "> and feeding_food_frequency_times = #{feedingFoodFrequencyTimes}</if>
            <if test="serviceFileInfo != null  and serviceFileInfo != ''"> and service_file_info = #{serviceFileInfo}</if>
        </where>
    </select>
    
    <select id="selectAppFeedingFoodByFeedingFoodId" parameterType="Long" resultMap="AppFeedingFoodResult">
        <include refid="selectAppFeedingFoodVo"/>
        where feeding_food_id = #{feedingFoodId}
    </select>
    <select id="getAppFeedingFoodList" resultMap="AppFeedingFoodResultVo">
        select
            *
        from
            app_feeding_food food
                left join app_feeding_food_type type
                          on food.feeding_food_id = type.feeding_food_type_id
    </select>

    <insert id="insertAppFeedingFood" parameterType="AppFeedingFood">
        insert into app_feeding_food
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="feedingFoodId != null">feeding_food_id,</if>
            <if test="serviceFileId != null">service_file_id,</if>
            <if test="feedingFoodImage != null">feeding_food_image,</if>
            <if test="feedingFoodWeight != null">feeding_food_weight,</if>
            <if test="feedingFoodFrequencyDay != null">feeding_food_frequency_day,</if>
            <if test="feedingFoodFrequencyTimes != null">feeding_food_frequency_times,</if>
            <if test="serviceFileInfo != null">service_file_info,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="feedingFoodId != null">#{feedingFoodId},</if>
            <if test="serviceFileId != null">#{serviceFileId},</if>
            <if test="feedingFoodImage != null">#{feedingFoodImage},</if>
            <if test="feedingFoodWeight != null">#{feedingFoodWeight},</if>
            <if test="feedingFoodFrequencyDay != null">#{feedingFoodFrequencyDay},</if>
            <if test="feedingFoodFrequencyTimes != null">#{feedingFoodFrequencyTimes},</if>
            <if test="serviceFileInfo != null">#{serviceFileInfo},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAppFeedingFood" parameterType="AppFeedingFood">
        update app_feeding_food
        <trim prefix="SET" suffixOverrides=",">
            <if test="serviceFileId != null">service_file_id = #{serviceFileId},</if>
            <if test="feedingFoodImage != null">feeding_food_image = #{feedingFoodImage},</if>
            <if test="feedingFoodWeight != null">feeding_food_weight = #{feedingFoodWeight},</if>
            <if test="feedingFoodFrequencyDay != null">feeding_food_frequency_day = #{feedingFoodFrequencyDay},</if>
            <if test="feedingFoodFrequencyTimes != null">feeding_food_frequency_times = #{feedingFoodFrequencyTimes},</if>
            <if test="serviceFileInfo != null">service_file_info = #{serviceFileInfo},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where feeding_food_id = #{feedingFoodId}
    </update>

    <delete id="deleteAppFeedingFoodByFeedingFoodId" parameterType="Long">
        delete from app_feeding_food where feeding_food_id = #{feedingFoodId}
    </delete>

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