<?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.WxEnterpriseRelatedMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated">
        <id column="wx_enterprise_related_id" property="wxEnterpriseRelatedId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR"/>
        <result column="enterprise_id" property="enterpriseId" jdbcType="VARCHAR"/>
        <result column="enterprise_name" property="enterpriseName" jdbcType="VARCHAR"/>
        <result column="version" property="version" jdbcType="VARCHAR"/>
        <result column="staff_id" property="staffId" jdbcType="VARCHAR"/>
        <result column="staff_name" property="staffName" jdbcType="VARCHAR"/>
        <result column="status_flag" property="statusFlag" jdbcType="INTEGER"/>
        <result column="wx_enterprise_type" property="wxEnterpriseType" jdbcType="INTEGER"/>
        <result column="member_open_card_flag" property="memberOpenCardFlag" jdbcType="INTEGER"/>
        <result column="clerk_edit_flag" property="clerkEditFlag" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        wx_enterprise_related_id, wx_enterprise_id, enterprise_id, enterprise_name,version, status_flag, wx_enterprise_type,
    member_open_card_flag,clerk_edit_flag,
    create_time, update_time,staff_id,staff_name
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
    </select>
    
    <update id="deleteByEnterpriseId">
    	update tab_haoban_wx_enterprise_related set status_flag = 0 , update_time=now()  where enterprise_id=#{enterpriseId} and status_flag=1
    </update>
    

    <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated">
        insert into tab_haoban_wx_enterprise_related
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wxEnterpriseRelatedId != null">
                wx_enterprise_related_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="enterpriseId != null">
                enterprise_id,
            </if>
            <if test="enterpriseName != null">
                enterprise_name,
            </if>
            <if test="version != null">
                version,
            </if>
            <if test="statusFlag != null">
                status_flag,
            </if>
            <if test="wxEnterpriseType != null">
                wx_enterprise_type,
            </if>
            <if test="memberOpenCardFlag != null">
                member_open_card_flag,
            </if>
            <if test="clerkEditFlag != null">
                clerk_edit_flag,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="staffId != null">
                staff_id,
            </if>
            <if test="staffName != null">
                staff_name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wxEnterpriseRelatedId != null">
                #{wxEnterpriseRelatedId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseName != null">
                #{enterpriseName},
            </if>
            <if test="version != null">
                #{version,jdbcType=VARCHAR},
            </if>
            <if test="statusFlag != null">
                #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="wxEnterpriseType != null">
                #{wxEnterpriseType,jdbcType=INTEGER},
            </if>
            <if test="memberOpenCardFlag != null">
                #{memberOpenCardFlag,jdbcType=INTEGER},
            </if>
            <if test="clerkEditFlag != null">
                #{clerkEditFlag,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="staffId != null">
                #{staffId},
            </if>
            <if test="staffName != null">
                #{staffName},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective"
            parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated">
        update tab_haoban_wx_enterprise_related
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseName != null">
                enterprise_name = #{enterpriseName},
            </if>
            <if test="version != null">
                version = #{version,jdbcType=VARCHAR},
            </if>
            <if test="statusFlag != null">
                status_flag = #{statusFlag,jdbcType=INTEGER},
            </if>
            <if test="rangeType != null">
                range_type = #{rangeType,jdbcType=INTEGER},
            </if>
            <if test="memberOpenCardFlag != null">
                member_open_card_flag = #{memberOpenCardFlag,jdbcType=INTEGER},
            </if>
            <if test="clerkEditFlag != null">
                clerk_edit_flag = #{clerkEditFlag,jdbcType=INTEGER},
            </if>
            <if test="wxEnterpriseType != null">
                wx_enterprise_type = #{wxEnterpriseType,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="staffId != null">
                staff_id = #{staffId,jdbcType=VARCHAR},
            </if>
            <if test="staffName != null">
                staff_name = #{staffName,jdbcType=VARCHAR},
            </if>
        </set>
        where wx_enterprise_related_id = #{wxEnterpriseRelatedId,jdbcType=VARCHAR}
    </update>

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

    <select id="listByWxenterpriseIdList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from tab_haoban_wx_enterprise_related
        where wx_enterprise_id in
        <foreach collection="wxEnterpriseIdList" item="id" index="index" open="(" close=")" separator=",">
            #{id,jdbcType=VARCHAR}
        </foreach>
        and status_flag = 1
    </select>

    <select id="listByEnterpriseId" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
        and status_flag = 1
    </select>

    <select id="queryAllHasGicEnterpriseId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where status_flag = 1
    </select>
    <select id="listEnterpriseByEnterpriseIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where status_flag = 1
        <if test="enterpriseIds != null and enterpriseIds.size() > 0">
            and enterprise_id IN
            <foreach collection="enterpriseIds" item="id" index="index" open="(" close=")" separator=",">
                #{id,jdbcType=VARCHAR}
            </foreach>
        </if>
    </select>

<!--    <select id="listEnterpriseByTime" resultMap="BaseResultMap">-->
<!--        select-->
<!--        <include refid="Base_Column_List"/>-->
<!--        from tab_haoban_wx_enterprise_related-->
<!--        where status_flag = 1-->
<!--        AND DATE_FORMAT(update_time,'%Y-%m-%d') = #{time}-->
<!--    </select>-->

    <select id="findOneByEIdAndWxEid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
        and status_flag = 1 and wx_enterprise_id=#{wxEnterpriseId}
    </select>

    <select id="findRootWxEnterpriseByEnterpriseId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_wx_enterprise_related
        where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
        and status_flag = 1
        and wx_enterprise_type = 0
    </select>

  <select id="findAllEnterpriseId" resultType="java.lang.String">
    select
    distinct enterprise_id
    from tab_haoban_wx_enterprise_related
    where status_flag = 1
  </select>

  <update id="saveClerkEditFlag">
		update tab_haoban_wx_enterprise_related set clerk_edit_flag = #{clerkEditFlag}
		where  wx_enterprise_id = #{wxEnterpriseId} and  enterprise_id = #{enterpriseId}
  </update>
</mapper>