<?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.ylx.massage.mapper.YlxAlarmMapper">

    <resultMap type="com.ylx.massage.domain.YlxAlarm" id="YlxAlarmMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="userName" column="user_name" jdbcType="VARCHAR"/>
        <result property="userPhone" column="user_phone" jdbcType="VARCHAR"/>
        <result property="address" column="address" jdbcType="VARCHAR"/>
        <result property="jsName" column="js_name" jdbcType="VARCHAR"/>
        <result property="jsPhone" column="js_phone" jdbcType="VARCHAR"/>
        <result property="jsId" column="js_id" jdbcType="VARCHAR"/>
        <result property="openId" column="open_id" jdbcType="VARCHAR"/>
        <result property="alarmStatus" column="alarm_status" jdbcType="INTEGER"/>
        <result property="note" column="note" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="YlxAlarmMap">
        select id,user_name,user_phone,address,js_name,js_phone,js_id,open_id,alarm_status,note,create_time,update_time,is_delete
        from ylx_alarm
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="YlxAlarmMap">
        select
        id,user_name,user_phone,address,js_name,js_phone,js_id,open_id,alarm_status,note,create_time,update_time,is_delete
        from ylx_alarm
        <where>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="userPhone != null and userPhone != ''">
                and user_phone = #{userPhone}
            </if>
            <if test="address != null and address != ''">
                and address = #{address}
            </if>
            <if test="jsName != null and jsName != ''">
                and js_name = #{jsName}
            </if>
            <if test="jsPhone != null and jsPhone != ''">
                and js_phone = #{jsPhone}
            </if>
            <if test="jsId != null and jsId != ''">
                and js_id = #{jsId}
            </if>
            <if test="openId != null and openId != ''">
                and open_id = #{openId}
            </if>
            <if test="alarmStatus != null">
                and alarm_status = #{alarmStatus}
            </if>
            <if test="note != null and note != ''">
                and note = #{note}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="isDelete != null">
                and is_delete = #{isDelete}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from ylx_alarm
        <where>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="userName != null and userName != ''">
                and user_name = #{userName}
            </if>
            <if test="userPhone != null and userPhone != ''">
                and user_phone = #{userPhone}
            </if>
            <if test="address != null and address != ''">
                and address = #{address}
            </if>
            <if test="jsName != null and jsName != ''">
                and js_name = #{jsName}
            </if>
            <if test="jsPhone != null and jsPhone != ''">
                and js_phone = #{jsPhone}
            </if>
            <if test="jsId != null and jsId != ''">
                and js_id = #{jsId}
            </if>
            <if test="openId != null and openId != ''">
                and open_id = #{openId}
            </if>
            <if test="alarmStatus != null">
                and alarm_status = #{alarmStatus}
            </if>
            <if test="note != null and note != ''">
                and note = #{note}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="isDelete != null">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>

    <!--新增所有列-->

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        ylx_alarm(user_name,user_phone,address,js_name,js_phone,js_id,open_id,alarm_status,note,create_time,update_time,is_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userName}#{entity.userPhone}#{entity.address}#{entity.jsName}#{entity.jsPhone}#{entity.jsId}#{entity.openId}#{entity.alarmStatus}#{entity.note}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        ylx_alarm(user_name,user_phone,address,js_name,js_phone,js_id,open_id,alarm_status,note,create_time,update_time,is_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userName}#{entity.userPhone}#{entity.address}#{entity.jsName}#{entity.jsPhone}#{entity.jsId}#{entity.openId}#{entity.alarmStatus}#{entity.note}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
        on duplicate key update
        user_name = values(user_name)user_phone = values(user_phone)address = values(address)js_name =
        values(js_name)js_phone = values(js_phone)js_id = values(js_id)open_id = values(open_id)alarm_status =
        values(alarm_status)note = values(note)create_time = values(create_time)update_time =
        values(update_time)is_delete = values(is_delete)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update ylx_alarm
        <set>
            <if test="userName != null and userName != ''">
                user_name = #{userName},
            </if>
            <if test="userPhone != null and userPhone != ''">
                user_phone = #{userPhone},
            </if>
            <if test="address != null and address != ''">
                address = #{address},
            </if>
            <if test="jsName != null and jsName != ''">
                js_name = #{jsName},
            </if>
            <if test="jsPhone != null and jsPhone != ''">
                js_phone = #{jsPhone},
            </if>
            <if test="jsId != null and jsId != ''">
                js_id = #{jsId},
            </if>
            <if test="openId != null and openId != ''">
                open_id = #{openId},
            </if>
            <if test="alarmStatus != null">
                alarm_status = #{alarmStatus},
            </if>
            <if test="note != null and note != ''">
                note = #{note},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="isDelete != null">
                is_delete = #{isDelete},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from ylx_alarm
        where id = #{id}
    </delete>

</mapper>

