<?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.gic.haoban.manage.service.dao.mapper.StaffPrivacyUseLogMapper">

    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabStaffPrivacyUseLog">
        <result column="id" property="id"/>
        <result column="staff_id" property="staffId"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId"/>
        <result column="privacy_use_flag" property="privacyUseFlag"/>
        <result column="phone_number" property="phoneNumber"/>
        <result column="welldone_version" property="welldoneVersion"/>
        <result column="wework_version" property="weworkVersion"/>
        <result column="staff_phone_brand" property="staffPhoneBrand"/>
        <result column="staff_phone_model" property="staffPhoneModel"/>
        <result column="staff_phone_version" property="staffPhoneVersion"/>
        <result column="staff_ip" property="staffIp"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="wx_open_user_id" property="wxOpenUseId"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,
                staff_id,
                wx_enterprise_id,
                privacy_use_flag,
                phone_number,
                welldone_version,
                wework_version,
                staff_phone_brand,
                staff_phone_model,
                staff_phone_version,
                staff_ip,
                create_time,
                update_time,
                wx_open_user_id
    </sql>

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id"
            parameterType="com.gic.haoban.manage.service.entity.TabStaffPrivacyUseLog">
        INSERT INTO tab_staff_privacy_use_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="null != staffId and '' != staffId">
                staff_id,
            </if>
            <if test="null != wxOpenUseId and '' != wxOpenUseId ">
                wx_open_user_id,
            </if>
            <if test="null != wxEnterpriseId and '' != wxEnterpriseId">
                wx_enterprise_id,
            </if>
            <if test="null != privacyUseFlag">
                privacy_use_flag,
            </if>
            <if test="null != phoneNumber and '' != phoneNumber">
                phone_number,
            </if>
            <if test="null != welldoneVersion and '' != welldoneVersion">
                welldone_version,
            </if>
            <if test="null != weworkVersion and '' != weworkVersion">
                wework_version,
            </if>
            <if test="null != staffPhoneBrand and '' != staffPhoneBrand">
                staff_phone_brand,
            </if>
            <if test="null != staffPhoneModel and '' != staffPhoneModel">
                staff_phone_model,
            </if>
            <if test="null != staffPhoneVersion and '' != staffPhoneVersion">
                staff_phone_version,
            </if>
            <if test="null != staffIp and '' != staffIp">
                staff_ip,
            </if>
            <if test="null != createTime">
                create_time,
            </if>
            <if test="null != updateTime">
                update_time
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="null != staffId and '' != staffId">
                #{staffId},
            </if>
            <if test="null != wxOpenUseId and '' != wxOpenUseId ">
                #{wxOpenUseId},
            </if>
            <if test="null != wxEnterpriseId and '' != wxEnterpriseId">
                #{wxEnterpriseId},
            </if>
            <if test="null != privacyUseFlag">
                #{privacyUseFlag},
            </if>
            <if test="null != phoneNumber and '' != phoneNumber">
                #{phoneNumber},
            </if>
            <if test="null != welldoneVersion and '' != welldoneVersion">
                #{welldoneVersion},
            </if>
            <if test="null != weworkVersion and '' != weworkVersion">
                #{weworkVersion},
            </if>
            <if test="null != staffPhoneBrand and '' != staffPhoneBrand">
                #{staffPhoneBrand},
            </if>
            <if test="null != staffPhoneModel and '' != staffPhoneModel">
                #{staffPhoneModel},
            </if>
            <if test="null != staffPhoneVersion and '' != staffPhoneVersion">
                #{staffPhoneVersion},
            </if>
            <if test="null != staffIp and '' != staffIp">
                #{staffIp},
            </if>
            <if test="null != createTime">
                #{createTime},
            </if>
            <if test="null != updateTime">
                #{updateTime}
            </if>
        </trim>
    </insert>



    <select id="getByStaffId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM tab_staff_privacy_use_log
        WHERE staff_id = #{staffId} order by create_time desc limit 1
    </select>

    <select id="getByUserId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM tab_staff_privacy_use_log
        WHERE wx_open_user_id = #{userId} order by create_time desc limit 1
    </select>

</mapper>