<?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.basenursinginfo.BaseNursingInfoMapper">

    <resultMap type="BaseNursingInfo" id="BaseNursingInfoResult">
            <result property="id" column="id"/>
            <result property="nursingName" column="nursing_name"/>
            <result property="tobaccoWine" column="tobacco_wine"/>
            <result property="sleep" column="sleep"/>
            <result property="emotion" column="emotion"/>
            <result property="homeSafeguard" column="home_safeguard"/>
            <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="selectBaseNursingInfoVo">
        select id, nursing_name, tobacco_wine, sleep, emotion, home_safeguard, create_time, create_by, update_by, update_time from base_nursing_info
    </sql>

    <select id="selectBaseNursingInfoList" parameterType="BaseNursingInfo" resultMap="BaseNursingInfoResult">
        <include refid="selectBaseNursingInfoVo"/>
        <where>
                        <if test="nursingName != null  and nursingName != ''">
                            and nursing_name like concat('%', #{nursingName}, '%')
                        </if>
                        <if test="tobaccoWine != null  and tobaccoWine != ''">
                            and tobacco_wine = #{tobaccoWine}
                        </if>
                        <if test="sleep != null  and sleep != ''">
                            and sleep = #{sleep}
                        </if>
                        <if test="emotion != null  and emotion != ''">
                            and emotion = #{emotion}
                        </if>
                        <if test="homeSafeguard != null  and homeSafeguard != ''">
                            and home_safeguard = #{homeSafeguard}
                        </if>
        </where>
    </select>

    <select id="selectBaseNursingInfoById" parameterType="Long"
            resultMap="BaseNursingInfoResult">
            <include refid="selectBaseNursingInfoVo"/>
            where id = #{id}
    </select>

    <insert id="insertBaseNursingInfo" parameterType="BaseNursingInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into base_nursing_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="nursingName != null">nursing_name,
                    </if>
                    <if test="tobaccoWine != null">tobacco_wine,
                    </if>
                    <if test="sleep != null">sleep,
                    </if>
                    <if test="emotion != null">emotion,
                    </if>
                    <if test="homeSafeguard != null">home_safeguard,
                    </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="nursingName != null">#{nursingName},
                    </if>
                    <if test="tobaccoWine != null">#{tobaccoWine},
                    </if>
                    <if test="sleep != null">#{sleep},
                    </if>
                    <if test="emotion != null">#{emotion},
                    </if>
                    <if test="homeSafeguard != null">#{homeSafeguard},
                    </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="updateBaseNursingInfo" parameterType="BaseNursingInfo">
        update base_nursing_info
        <trim prefix="SET" suffixOverrides=",">
                    <if test="nursingName != null">nursing_name =
                        #{nursingName},
                    </if>
                    <if test="tobaccoWine != null">tobacco_wine =
                        #{tobaccoWine},
                    </if>
                    <if test="sleep != null">sleep =
                        #{sleep},
                    </if>
                    <if test="emotion != null">emotion =
                        #{emotion},
                    </if>
                    <if test="homeSafeguard != null">home_safeguard =
                        #{homeSafeguard},
                    </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="deleteBaseNursingInfoById" parameterType="Long">
        delete from base_nursing_info where id = #{id}
    </delete>

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