<?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.QywxTagRelationMapper">
  <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
    <id column="qywx_tag_relation_id" jdbcType="VARCHAR" property="qywxTagRelationId"/>
    <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
    <result column="enterprise_id" jdbcType="VARCHAR" property="enterpriseId"/>
    <result column="member_tag_id" jdbcType="VARCHAR" property="memberTagId"/>
    <result column="tag_item_id" jdbcType="VARCHAR" property="tagItemId"/>
    <result column="relation_type" jdbcType="INTEGER" property="relationType"/>
    <result column="sync_flag" jdbcType="INTEGER" property="syncFlag"/>
    <result column="order" jdbcType="BIGINT" property="order"/>
    <result column="qywx_tag_id" jdbcType="VARCHAR" property="qywxTagId"/>
    <result column="qywx_tag_item_id" jdbcType="VARCHAR" property="qywxTagItemId"/>
    <result column="status_flag" jdbcType="INTEGER" property="statusFlag"/>
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  </resultMap>
  <sql id="Base_Column_List">
    qywx_tag_relation_id, wx_enterprise_id, enterprise_id, member_tag_id, tag_item_id,
    relation_type, sync_flag, `order`, qywx_tag_id, qywx_tag_item_id, status_flag, create_time,
    update_time
  </sql>
<!--  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">-->
<!--    select-->
<!--    <include refid="Base_Column_List"/>-->
<!--    from tab_haoban_qywx_tag_relation-->
<!--    where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}-->
<!--  </select>-->
  <update id="deleteByPrimaryKey" parameterType="java.lang.String">
    update  tab_haoban_qywx_tag_relation set status_flag = 0 , update_time =now()
    where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}
  </update>

  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
    insert into tab_haoban_qywx_tag_relation (qywx_tag_relation_id, wx_enterprise_id, 
      enterprise_id, member_tag_id, tag_item_id, 
      relation_type, sync_flag, `order`,
      qywx_tag_id, qywx_tag_item_id, status_flag, 
      create_time, update_time)
    values (#{qywxTagRelationId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR}, 
      #{enterpriseId,jdbcType=VARCHAR}, #{memberTagId,jdbcType=VARCHAR}, #{tagItemId,jdbcType=VARCHAR}, 
      #{relationType,jdbcType=INTEGER}, #{syncFlag,jdbcType=INTEGER}, #{order,jdbcType=BIGINT}, 
      #{qywxTagId,jdbcType=VARCHAR}, #{qywxTagItemId,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
    insert into tab_haoban_qywx_tag_relation
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="qywxTagRelationId != null">
        qywx_tag_relation_id,
      </if>
      <if test="wxEnterpriseId != null">
        wx_enterprise_id,
      </if>
      <if test="enterpriseId != null">
        enterprise_id,
      </if>
      <if test="memberTagId != null">
        member_tag_id,
      </if>
      <if test="tagItemId != null">
        tag_item_id,
      </if>
      <if test="relationType != null">
        relation_type,
      </if>
      <if test="syncFlag != null">
        sync_flag,
      </if>
      <if test="order != null">
          `order`,
      </if>
      <if test="qywxTagId != null">
        qywx_tag_id,
      </if>
      <if test="qywxTagItemId != null">
        qywx_tag_item_id,
      </if>
      <if test="statusFlag != null">
        status_flag,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="qywxTagRelationId != null">
        #{qywxTagRelationId,jdbcType=VARCHAR},
      </if>
      <if test="wxEnterpriseId != null">
        #{wxEnterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="enterpriseId != null">
        #{enterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="memberTagId != null">
        #{memberTagId,jdbcType=VARCHAR},
      </if>
      <if test="tagItemId != null">
        #{tagItemId,jdbcType=VARCHAR},
      </if>
      <if test="relationType != null">
        #{relationType,jdbcType=INTEGER},
      </if>
      <if test="syncFlag != null">
        #{syncFlag,jdbcType=INTEGER},
      </if>
      <if test="order != null">
        #{order,jdbcType=BIGINT},
      </if>
      <if test="qywxTagId != null">
        #{qywxTagId,jdbcType=VARCHAR},
      </if>
      <if test="qywxTagItemId != null">
        #{qywxTagItemId,jdbcType=VARCHAR},
      </if>
      <if test="statusFlag != null">
        #{statusFlag,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
    update tab_haoban_qywx_tag_relation
    <set>
      <if test="wxEnterpriseId != null">
        wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="enterpriseId != null">
        enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
      </if>
      <if test="memberTagId != null">
        member_tag_id = #{memberTagId,jdbcType=VARCHAR},
      </if>
      <if test="tagItemId != null">
        tag_item_id = #{tagItemId,jdbcType=VARCHAR},
      </if>
      <if test="relationType != null">
        relation_type = #{relationType,jdbcType=INTEGER},
      </if>
      <if test="syncFlag != null">
        sync_flag = #{syncFlag,jdbcType=INTEGER},
      </if>
      <if test="order != null">
          `order` = #{order,jdbcType=BIGINT},
      </if>
      <if test="qywxTagId != null">
        qywx_tag_id = #{qywxTagId,jdbcType=VARCHAR},
      </if>
      <if test="qywxTagItemId != null">
        qywx_tag_item_id = #{qywxTagItemId,jdbcType=VARCHAR},
      </if>
      <if test="statusFlag != null">
        status_flag = #{statusFlag,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
    update tab_haoban_qywx_tag_relation
    set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
      member_tag_id = #{memberTagId,jdbcType=VARCHAR},
      tag_item_id = #{tagItemId,jdbcType=VARCHAR},
      relation_type = #{relationType,jdbcType=INTEGER},
      sync_flag = #{syncFlag,jdbcType=INTEGER},
      `order` = #{order,jdbcType=BIGINT},
      qywx_tag_id = #{qywxTagId,jdbcType=VARCHAR},
      qywx_tag_item_id = #{qywxTagItemId,jdbcType=VARCHAR},
      status_flag = #{statusFlag,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}
  </update>

  <select id="listBySyncStatus" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and status_flag=1
  </select>

  <select id="listByMemberTagId" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where
    member_tag_id = #{memberTagId,jdbcType=VARCHAR}
    <if test="wxEnterpriseId!=null">
      and wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    </if>
    and status_flag=1
  </select>

  <select id="getQywxTagRelationByTagItemId" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and tag_item_id = #{tagItemId,jdbcType=VARCHAR}
    and status_flag=1
  </select>

  <update id="delByMemberTagId">
    update tab_haoban_qywx_tag_relation
    set
      status_flag = 0,
      update_time = now()
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and  member_tag_id = #{memberTagId,jdbcType=VARCHAR}
    and status_flag=1
  </update>

  <select id="listByQywxTagId" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and qywx_tag_id = #{qywxTagId,jdbcType=VARCHAR}
    and status_flag=1
  </select>

  <select id="getQywxGroupByQywxTagId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
    and qywx_tag_id = #{qywxTagId,jdbcType=VARCHAR}
    and relation_type=0
    and status_flag=1
  </select>

  <select id="getQywxTagByQywxTagItemId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from tab_haoban_qywx_tag_relation
    where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
      and qywx_tag_item_id = #{qywxTagItemId,jdbcType=VARCHAR}
    and relation_type=1
    and status_flag=1
  </select>

  <update id="changeRelationSyncFlag">
    UPDATE tab_haoban_qywx_tag_relation
    SET
      sync_flag=#{syncFlag},
      update_time=now()
    where
     wx_enterprise_id = #{wxEnterpriseId}
    and  member_tag_id = #{memberTagId,jdbcType=VARCHAR}
    and status_flag=1
  </update>
</mapper>