<?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.TabHaobanStoreRangeMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabStoreRange">
        <id column="store_range_id" jdbcType="VARCHAR" property="storeRangeId"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="enterprise_id" jdbcType="VARCHAR" property="enterpriseId"/>
        <result column="relation_id" jdbcType="VARCHAR" property="relationId"/>
        <result column="relation_type" jdbcType="INTEGER" property="relationType"/>
        <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">
    store_range_id, wx_enterprise_id, enterprise_id, relation_id, relation_type, 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_store_range
        where store_range_id = #{storeRangeId,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from tab_haoban_store_range
    where store_range_id = #{storeRangeId,jdbcType=VARCHAR}
  </delete>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabStoreRange">
    insert into tab_haoban_store_range (store_range_id, wx_enterprise_id, enterprise_id, 
      relation_id, relation_type, status_flag, 
      create_time, update_time)
    values (#{storeRangeId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR}, #{enterpriseId,jdbcType=VARCHAR}, 
      #{relationId,jdbcType=VARCHAR}, #{relationType,jdbcType=INTEGER}, #{statusFlag,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
    <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabStoreRange">
        insert into tab_haoban_store_range
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeRangeId != null">
                store_range_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="enterpriseId != null">
                enterprise_id,
            </if>
            <if test="relationId != null">
                relation_id,
            </if>
            <if test="relationType != null">
                relation_type,
            </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="storeRangeId != null">
                #{storeRangeId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="relationId != null">
                #{relationId,jdbcType=VARCHAR},
            </if>
            <if test="relationType != null">
                #{relationType,jdbcType=INTEGER},
            </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.TabStoreRange">
        update tab_haoban_store_range
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="relationId != null">
                relation_id = #{relationId,jdbcType=VARCHAR},
            </if>
            <if test="relationType != null">
                relation_type = #{relationType,jdbcType=INTEGER},
            </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 store_range_id = #{storeRangeId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabStoreRange">
    update tab_haoban_store_range
    set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
      relation_id = #{relationId,jdbcType=VARCHAR},
      relation_type = #{relationType,jdbcType=INTEGER},
      status_flag = #{statusFlag,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where store_range_id = #{storeRangeId,jdbcType=VARCHAR}
  </update>

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

    <update id="deleteByEnterpriseId">
    update tab_haoban_store_range
    SET
        status_flag = 0,
        update_time = now()
    where
        enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
        and wx_enterprise_id=#{wxEnterpriseId}
        and status_flag =1
  </update>

    <insert id="insertBatch">
        insert into tab_haoban_store_range (store_range_id, wx_enterprise_id, enterprise_id,
        relation_id, relation_type, status_flag,
        create_time, update_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.storeRangeId,jdbcType=VARCHAR}, #{item.wxEnterpriseId,jdbcType=VARCHAR},
            #{item.enterpriseId,jdbcType=VARCHAR},
            #{item.relationId,jdbcType=VARCHAR}, #{item.relationType,jdbcType=INTEGER}, 1,
            now(), now())
        </foreach>

    </insert>

    <select id="listStoreRangeByRelationId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_store_range
        where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
        and relation_id in
        <foreach collection="relationIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and status_flag =1
    </select>

</mapper>