<?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.ExternalMemberLogMapper">
  <resultMap type="com.gic.haoban.manage.service.entity.TabExternalMemberLog" id="result-map-tabHaobanExternalMemberLog">
      <result column="log_id"  property="logId"/>
      <result column="enterprise_id"  property="enterpriseId"/>
      <result column="unionid"  property="unionid"/>
      <result column="member_id" property="memberId"/>
      <result column="relation_key"  property="relationKey"/>
      <result column="delete_flag"  property="deleteFlag"/>
      <result column="create_time"  property="createTime"/>
      <result column="update_time"  property="updateTime"/>
      <result column="status_flag"  property="statusFlag"/>
  </resultMap>
  <sql id="Base_Column_List">
	  log_id,
	  enterprise_id,
	  unionid,
	  member_id ,
	  relation_key,
	  delete_flag,
	  create_time,
	  update_time,
	  status_flag
  </sql>
  <!-- ===================== 新增 ======================== -->
  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabExternalMemberLog">
  <![CDATA[
  INSERT INTO tab_haoban_external_member_log(
	  log_id,
	  enterprise_id,
	  unionid,
	  member_id , 
	  relation_key,
	  delete_flag,
	  create_time,
	  update_time,
	  status_flag
  )VALUES(
	  #{logId,jdbcType=BIGINT},
	  #{enterpriseId,jdbcType=CHAR},
	  #{unionid,jdbcType=VARCHAR},
	  #{memberId} ,
	  #{relationKey,jdbcType=VARCHAR},
	  0,
	  now(),
	  now(),
	  1
  )
  ]]>
  </insert>
  
  <update id="updateStatus">
	  <![CDATA[
	  UPDATE tab_haoban_external_member_log SET
		  update_time=now() ,
		  status_flag= #{statusFlag}
	  where enterprise_id = #{enterpriseId} and log_id=#{id}
	  ]]>
  </update>
  
  <!-- ============ 查询=============-->
  <select id="selectRelationKey"  resultMap="result-map-tabHaobanExternalMemberLog">
 	 SELECT <include refid="Base_Column_List" /> FROM tab_haoban_external_member_log 
 	  where enterprise_id = #{enterpriseId} and relation_key=#{relationKey} limit 1
  </select>
  
  <select id="listForTimer"  resultMap="result-map-tabHaobanExternalMemberLog">
  	 SELECT <include refid="Base_Column_List" /> FROM tab_haoban_external_member_log 
 	  	where  create_time >= #{start}  and  create_time <![CDATA[ < ]]>  #{end} and status_flag = 1 
  </select>
  	
</mapper> 