<?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.OpenStaffMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabOpenStaff">
        <id column="open_staff_id" javaType="long" jdbcType="BIGINT" property="openStaffId"/>
        <result column="wx_enterprise_id" javaType="String" jdbcType="CHAR" property="wxEnterpriseId"/>
        <result column="enterprise_id" property="enterpriseId" />
        <result column="staff_id" javaType="String" jdbcType="CHAR" property="staffId"/>
        <result column="create_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="uuid" javaType="String" jdbcType="VARCHAR" property="uuid"/>
        <result column="delete_flag" javaType="int" jdbcType="INTEGER" property="deleteFlag"/>
        <result column="status_flag" javaType="int" jdbcType="INTEGER" property="statusFlag"/>
        <result column="step" javaType="int" jdbcType="INTEGER" property="step"/>
        <result column="qw_user_id" javaType="long" jdbcType="BIGINT" property="qwUserId"/>
        <result column="wx_corp_id" javaType="long" jdbcType="BIGINT" property="wxCorpId"/>
        <result column="qr_code_1" javaType="String" jdbcType="VARCHAR" property="qrCode1"/>
        <result column="key_1" javaType="String" jdbcType="VARCHAR" property="key1"/>
        <result column="qr_code_2" javaType="String" jdbcType="VARCHAR" property="qrCode2"/>
        <result column="key_2" javaType="String" jdbcType="VARCHAR" property="key2"/>
        <result column="valid_flag" javaType="int" jdbcType="INTEGER" property="validFlag"/>
        <result column="auth_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="authTime"/>
        <result column="first_auth_time" javaType="java.util.Date" jdbcType="TIMESTAMP" property="firstAuthTime"/>
        <result column="valid_qrcode_flag" property="validQrcodeFlag" />
    </resultMap>

    <sql id="Base_Column_List">
        open_staff_id, wx_enterprise_id,enterprise_id, staff_id, create_time, update_time, uuid, delete_flag,status_flag, step, qw_user_id, wx_corp_id, qr_code_1, key_1,
	    qr_code_2, key_2, valid_flag, auth_time,first_auth_time , valid_qrcode_flag
    </sql>

    <insert id="insert" parameterType="com.gic.haoban.manage.service.dao.mapper.OpenStaffMapper">
            <![CDATA[
            INSERT INTO tab_haoban_open_staff(
                open_staff_id, wx_enterprise_id, staff_id, create_time,  update_time, uuid,  delete_flag,  status_flag,   step, qw_user_id,  wx_corp_id,   qr_code_1, key_1,
                qr_code_2,  key_2,valid_flag, auth_time, first_auth_time , enterprise_id , valid_qrcode_flag
            )VALUES(
                       #{openStaffId,jdbcType=BIGINT},      #{wxEnterpriseId,jdbcType=CHAR},   #{staffId,jdbcType=CHAR},   #{createTime,jdbcType=TIMESTAMP},
                       #{updateTime,jdbcType=TIMESTAMP},    #{uuid,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},    #{statusFlag,jdbcType=INTEGER},
                       #{step,jdbcType=INTEGER},     #{qwUserId,jdbcType=BIGINT},  #{wxCorpId,jdbcType=BIGINT},     #{qrCode1,jdbcType=VARCHAR},
                       #{key1,jdbcType=VARCHAR},    #{qrCode2,jdbcType=VARCHAR},  #{key2,jdbcType=VARCHAR},    #{validFlag,jdbcType=INTEGER},
                       #{authTime,jdbcType=TIMESTAMP},   #{firstAuthTime,jdbcType=TIMESTAMP} , #{enterpriseId} , #{validQrcodeFlag}
                   )
            ]]>
    </insert>

    <update id="update" parameterType="com.gic.haoban.manage.service.entity.TabOpenStaff">
        update tab_haoban_open_staff set uuid = #{uuid} , update_time=now(),
                                     status_flag=#{statusFlag,jdbcType=INTEGER},
                                     step=#{step,jdbcType=INTEGER},
                                     qw_user_id=#{qwUserId,jdbcType=BIGINT},
                                     wx_corp_id=#{wxCorpId,jdbcType=BIGINT},
                                     qr_code_1=#{qrCode1,jdbcType=VARCHAR},
                                     key_1=#{key1,jdbcType=VARCHAR},
                                     qr_code_2=#{qrCode2,jdbcType=VARCHAR},
                                     key_2=#{key2,jdbcType=VARCHAR},
                                     valid_flag=#{validFlag,jdbcType=INTEGER},
                                     auth_time=#{authTime,jdbcType=TIMESTAMP},
                                     <if test="null != firstAuthTime">
                                         first_auth_time=#{firstAuthTime} ,
                                     </if>
        where open_staff_id = #{openStaffId}
    </update>
    <update id="updateValiFlag">
        update tab_haoban_open_staff set valid_flag = 1 where uuid = #{uuid}
    </update>

    <delete id="deleteByPrimaryKey">
        update tab_haoban_open_staff set delete_flag = 1 , update_time =now() where open_staff_id = #{id}
    </delete>

    <select id="getByStaffId"  resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> from tab_haoban_open_staff where staff_id = #{staffId} and delete_flag = 0
    </select>
    <select id="getById" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from tab_haoban_open_staff where open_staff_id = #{id} and delete_flag = 0
    </select>
    <select id="getByUUID" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from tab_haoban_open_staff where uuid = #{uuid} and delete_flag = 0
    </select>

</mapper>