<?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.flossom.common.core.mapper.WxNursingLogMapper">
    
    <resultMap type="WxNursingLog" id="WxNursingLogResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="instrumentName"    column="instrument_name"    />
        <result property="online"    column="online"    />
        <result property="modeId"    column="mode_id"    />
        <result property="modeName"    column="mode_name"    />
        <result property="nursingTime"    column="nursing_time"    />
        <result property="completionPercentage"    column="completion_percentage"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWxNursingLogVo">
        select id, user_id, instrument_id, instrument_name, online, mode_id, mode_name, nursing_time, completion_percentage, status, create_by, create_time, update_by, update_time from wx_nursing_log
    </sql>

    <select id="selectWxNursingLogList" parameterType="WxNursingLog" resultMap="WxNursingLogResult">
        <include refid="selectWxNursingLogVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="instrumentName != null "> and instrument_name = #{instrumentName}</if>
            <if test="online != null "> and online = #{online}</if>
            <if test="modeId != null "> and mode_id = #{modeId}</if>
            <if test="modeName != null  and modeName != ''"> and mode_name like concat('%', #{modeName}, '%')</if>
            <if test="nursingTime != null "> and nursing_time = #{nursingTime}</if>
            <if test="completionPercentage != null "> and completion_percentage = #{completionPercentage}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="params != null and params.beginTime != null">
                and create_time &gt;= #{params.beginTime}
            </if>
            <if test="params != null and params.endTime != null">
                and create_time &lt;= #{params.endTime}
            </if>
        </where>
        ORDER BY update_time DESC
    </select>

    <select id="selectNursingLogListByVm" parameterType="UserNursingLogVm" resultMap="WxNursingLogResult">
        <include refid="selectWxNursingLogVo"/>
        <where>
            <if test="userIdList != null and userIdList.size > 0">
                and user_id in
                <foreach item="item" collection="userIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="instrumentIdList != null and instrumentIdList.size > 0">
                and instrument_id in
                <foreach item="item" collection="instrumentIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="modeIdList != null and modeIdList.size > 0 ">
                and mode_id in
                <foreach item="item" collection="modeIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="nursingTimeRange != null and nursingTimeRange.size > 0">
                and nursing_time &gt;= #{nursingTimeRange[0]}
            </if>
            <if test="nursingTimeRange != null and nursingTimeRange.size > 1">
                and nursing_time &lt;= #{nursingTimeRange[1]}
            </if>
            <if test="updateTimeRange != null and updateTimeRange.size > 0">
                and update_time &gt;= #{updateTimeRange[0]}
            </if>
            <if test="updateTimeRange != null and updateTimeRange.size > 1">
                and update_time &lt;= #{updateTimeRange[1]}
            </if>
        </where>
        ORDER BY update_time DESC
    </select>
    
    <select id="selectWxNursingLogById" parameterType="Long" resultMap="WxNursingLogResult">
        <include refid="selectWxNursingLogVo"/>
        where id = #{id}
    </select>

    <select id="selectWxNursingLogByIdList" resultMap="WxNursingLogResult">
        <include refid="selectWxNursingLogVo"/>
        where id in
        <foreach item="id" collection="idList" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertWxNursingLog" parameterType="WxNursingLog" useGeneratedKeys="true" keyProperty="id">
        insert into wx_nursing_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="instrumentName != null">instrument_name,</if>
            <if test="online != null">online,</if>
            <if test="modeId != null">mode_id,</if>
            <if test="modeName != null">mode_name,</if>
            <if test="nursingTime != null">nursing_time,</if>
            <if test="completionPercentage != null">completion_percentage,</if>
            <if test="status != null">status,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="instrumentName != null">#{instrumentName},</if>
            <if test="online != null">#{online},</if>
            <if test="modeId != null">#{modeId},</if>
            <if test="modeName != null">#{modeName},</if>
            <if test="nursingTime != null">#{nursingTime},</if>
            <if test="completionPercentage != null">#{completionPercentage},</if>
            <if test="status != null">#{status},</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>
         </trim>
    </insert>

    <update id="updateWxNursingLog" parameterType="WxNursingLog">
        update wx_nursing_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="instrumentName != null">instrument_name = #{instrumentName},</if>
            <if test="online != null">online = #{online},</if>
            <if test="modeId != null">mode_id = #{modeId},</if>
            <if test="modeName != null">mode_name = #{modeName},</if>
            <if test="nursingTime != null">nursing_time = #{nursingTime},</if>
            <if test="completionPercentage != null">completion_percentage = #{completionPercentage},</if>
            <if test="status != null">status = #{status},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxNursingLogById" parameterType="Long">
        delete from wx_nursing_log where id = #{id}
    </delete>

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