<?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.StaffClerkBindLogMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanStaffClerkBindLog">
        <id column="log_id" jdbcType="INTEGER" property="logId"/>
        <result column="staff_id" jdbcType="VARCHAR" property="staffId"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="opt_staff_id" jdbcType="VARCHAR" property="optStaffId"/>
        <result column="opt_type" jdbcType="INTEGER" property="optType"/>
        <result column="channel_code" jdbcType="INTEGER" property="channelCode"/>
        <result column="enterprise_id" jdbcType="VARCHAR" property="enterpriseId"/>
        <result column="clerk_id" jdbcType="VARCHAR" property="clerkId"/>
        <result column="clerk_code" jdbcType="VARCHAR" property="clerkCode"/>
        <result column="clerk_phone" jdbcType="VARCHAR" property="clerkPhone"/>
        <result column="status_flag" jdbcType="INTEGER" property="statusFlag"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
         <result column="oper_name"  property="operName"/>
         <result column="clerk_name"  property="clerkName"/>
        
    </resultMap>
    <sql id="Base_Column_List">
        log_id, staff_id, wx_enterprise_id, opt_staff_id, opt_type, channel_code, enterprise_id,
    clerk_id, clerk_code,clerk_phone, status_flag, create_time, update_time , oper_name , clerk_name
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_staff_clerk_bind_log
        where log_id = #{logId,jdbcType=INTEGER}
    </select>
    
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanStaffClerkBindLog">
        insert into tab_haoban_staff_clerk_bind_log (staff_id, wx_enterprise_id,
                                                     opt_staff_id, opt_type, channel_code,
                                                     enterprise_id, clerk_id, clerk_code, clerk_phone,
                                                     status_flag, create_time, update_time , oper_name,clerk_name)
        values (#{staffId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR},
                #{optStaffId,jdbcType=VARCHAR}, #{optType,jdbcType=INTEGER}, #{channelCode,jdbcType=INTEGER},
                #{enterpriseId,jdbcType=VARCHAR}, #{clerkId,jdbcType=VARCHAR}, #{clerkCode,jdbcType=VARCHAR},
                #{clerkPhone,jdbcType=VARCHAR},
                #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} , #{operName} , #{clerkName})
    </insert>
    
    <select id="listStaffClerkBindLog" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_staff_clerk_bind_log
        where wx_enterprise_id=#{wxEnterpriseId}  and enterprise_id = #{enterpriseId} 
        <if test="optType!=-1">
            and opt_type=#{optType}
        </if>
        <if test="search!=null and search.length()>0">
            and (clerk_code = #{search} or clerk_phone = #{search})
        </if>
        order by create_time desc
    </select>
    <select id="staffClerkUnBindLog" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_staff_clerk_bind_log
        where wx_enterprise_id = #{wxEnterpriseId}
        <if test="clerkId!=null ">
            and clerk_id = #{clerkId}
        </if>
        <if test="enterpriseId!=null">
            and enterprise_id = #{enterpriseId}
        </if>
        <if test="optType!=-1">
            and opt_type= #{optType}
        </if>
        order by create_time desc
    </select>
</mapper>