<?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.system.mapper.RegisterParentsMapper">
    
    <resultMap type="RegisterParents" id="RegisterParentsResult">
        <result property="id"    column="id"    />
        <result property="openId"    column="open_id"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="isPass"    column="is_pass"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectRegisterParentsVo">
        select id,open_id, user_name, user_phone,is_pass, create_by, create_time, update_by, update_time, remark from register_parents
    </sql>

    <select id="selectRegisterParentsList" parameterType="RegisterParents" resultMap="RegisterParentsResult">
        <include refid="selectRegisterParentsVo"/>
        <where>
            <if test="openId != null  and openId != ''"> and open_id = #{openId},</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
        </where>
    </select>
    
    <select id="selectRegisterParentsById" parameterType="Long" resultMap="RegisterParentsResult">
        <include refid="selectRegisterParentsVo"/>
        where id = #{id}
    </select>
    <select id="selectRegisterParentsByOppenId" resultMap="RegisterParentsResult" parameterType="java.lang.String">
        <include refid="selectRegisterParentsVo"/>
        where  open_id = #{openId} limit 1
    </select>

    <select id="selectRegisterParentsByPhonenumber" resultMap="RegisterParentsResult">
        <include refid="selectRegisterParentsVo"/>
        where  user_phone = #{phonenumber} limit 1
    </select>

    <insert id="insertRegisterParents" parameterType="RegisterParents" useGeneratedKeys="true" keyProperty="id">
        insert into register_parents
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="openId != null  and openId != ''">open_id ,</if>
            <if test="userName != null">user_name,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="isPass != null">is_pass,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="openId != null  and openId != ''">#{openId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="isPass != null">#{isPass},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateRegisterParents" parameterType="RegisterParents">
        update register_parents
        <trim prefix="SET" suffixOverrides=",">
            <if test="openId != null  and openId != ''">  open_id = #{openId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="isPass != null">is_pass = #{isPass},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRegisterParentsById" parameterType="Long">
        delete from register_parents where id = #{id}
    </delete>

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