<?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.tuya.mapper.SysUsersMapper">

    <resultMap type="SysUsers" id="SysUsersResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="age"    column="age"    />
        <result property="pass"    column="pass"    />
        <result property="phone"    column="phone"    />
        <result property="jdrq"    column="jdrq"    />
        <result property="headpir"    column="headpir"    />
        <result property="remake"    column="remake"    />
        <result property="wxid"    column="wxid"    />
        <result property="wxtoken"    column="wxtoken"    />
        <result property="flag"    column="flag"    />
        <result property="captcha"    column="captcha"    />
        <result property="city"    column="city"    />
        <result property="email"    column="email"    />
        <result property="birthday"    column="birthday"    />
    </resultMap>

    <sql id="selectSysUsersVo">
        select id, code, name, sex, age, pass, phone, jdrq, headpir, remake, wxid, wxtoken,
               flag, captcha, city, email, birthday
        from sys_users
    </sql>

    <select id="selectSysUsersList" parameterType="SysUsers" resultMap="SysUsersResult">
        <include refid="selectSysUsersVo"/>
        <where>
            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="age != null "> and age = #{age}</if>
            <if test="pass != null  and pass != ''"> and pass = #{pass}</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="jdrq != null "> and DATEADD(ms, -DATEPART(ms, jdrq), jdrq) = #{jdrq}</if>
            <if test="headpir != null  and headpir != ''"> and headpir = #{headpir}</if>
            <if test="remake != null  and remake != ''"> and remake = #{remake}</if>
            <if test="wxid != null  and wxid != ''"> and wxid like concat('%', #{wxid}, '%')</if>
            <if test="wxtoken != null  and wxtoken != ''"> and wxtoken = #{wxtoken}</if>
            <if test="flag != null "> and flag = #{flag}</if>
            <if test="captcha != null  and captcha != ''"> and captcha = #{captcha}</if>
            <if test="city != null  and city != ''"> and city like concat('%', #{city}, '%')</if>
            <if test="email != null  and email != ''"> and email like concat('%', #{email}, '%')</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
        </where>
    </select>

    <select id="selectSysUsersById" parameterType="Long" resultMap="SysUsersResult">
        <include refid="selectSysUsersVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysUsers" parameterType="SysUsers">
        insert into sys_users
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="age != null">age,</if>
            <if test="pass != null">pass,</if>
            <if test="phone != null">phone,</if>
            <if test="jdrq != null">jdrq,</if>
            <if test="headpir != null">headpir,</if>
            <if test="remake != null">remake,</if>
            <if test="wxid != null">wxid,</if>
            <if test="wxtoken != null">wxtoken,</if>
            <if test="flag != null">flag,</if>
            <if test="captcha != null">captcha,</if>
            <if test="city != null">city,</if>
            <if test="email != null">email,</if>
            <if test="birthday != null">birthday,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="age != null">#{age},</if>
            <if test="pass != null">#{pass},</if>
            <if test="phone != null">#{phone},</if>
            <if test="jdrq != null">#{jdrq},</if>
            <if test="headpir != null">#{headpir},</if>
            <if test="remake != null">#{remake},</if>
            <if test="wxid != null">#{wxid},</if>
            <if test="wxtoken != null">#{wxtoken},</if>
            <if test="flag != null">#{flag},</if>
            <if test="captcha != null">#{captcha},</if>
            <if test="city != null">#{city},</if>
            <if test="email != null">#{email},</if>
            <if test="birthday != null">#{birthday},</if>
         </trim>
    </insert>

    <update id="updateSysUsers" parameterType="SysUsers">
        update sys_users
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="age != null">age = #{age},</if>
            <if test="pass != null">pass = #{pass},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="jdrq != null">jdrq = #{jdrq},</if>
            <if test="headpir != null">headpir = #{headpir},</if>
            <if test="remake != null">remake = #{remake},</if>
            <if test="wxid != null">wxid = #{wxid},</if>
            <if test="wxtoken != null">wxtoken = #{wxtoken},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="captcha != null">captcha = #{captcha},</if>
            <if test="city != null">city = #{city},</if>
            <if test="email != null">email = #{email},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysUsersById" parameterType="Long">
        delete from sys_users where id = #{id}
    </delete>

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