<?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.HandoverStaffMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHandoverStaff">
        <id column="handover_staff_id" jdbcType="VARCHAR" property="handoverStaffId"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="staff_id" jdbcType="VARCHAR" property="staffId"/>
        <result column="store_id" jdbcType="VARCHAR" property="storeId"/>
        <result column="handover_user_id" jdbcType="VARCHAR" property="handoverUserId"/>
        <result column="dimission_time" jdbcType="TIMESTAMP" property="dimissionTime"/>
        <result column="friend_count" jdbcType="INTEGER" property="friendCount"/>
        <result column="haoban_friend_count" jdbcType="INTEGER" property="haobanFriendCount"/>
        <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">
    handover_staff_id, wx_enterprise_id, staff_id,store_id, handover_user_id, dimission_time,
    friend_count, haoban_friend_count, 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_handover_staff
        where handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from tab_haoban_handover_staff
    where handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR}
  </delete>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHandoverStaff">
    insert into tab_haoban_handover_staff (handover_staff_id, wx_enterprise_id, 
      staff_id,store_id, handover_user_id, dimission_time,
      friend_count, haoban_friend_count, status_flag, 
      create_time, update_time)
    values (#{handoverStaffId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR}, 
      #{staffId,jdbcType=VARCHAR},#{storeId,jdbcType=VARCHAR}, #{handoverUserId,jdbcType=VARCHAR}, #{dimissionTime,jdbcType=TIMESTAMP},
      #{friendCount,jdbcType=INTEGER}, #{haobanFriendCount,jdbcType=INTEGER}, #{statusFlag,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
    <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHandoverStaff">
        insert into tab_haoban_handover_staff
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="handoverStaffId != null">
                handover_staff_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="staffId != null">
                staff_id,
            </if>
            <if test="storeId != null">
                store_id,
            </if>
            <if test="handoverUserId != null">
                handover_user_id,
            </if>
            <if test="dimissionTime != null">
                dimission_time,
            </if>
            <if test="friendCount != null">
                friend_count,
            </if>
            <if test="haobanFriendCount != null">
                haoban_friend_count,
            </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="handoverStaffId != null">
                #{handoverStaffId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="staffId != null">
                #{staffId,jdbcType=VARCHAR},
            </if>
            <if test="storeId != null">
                #{storeId,jdbcType=VARCHAR},
            </if>
            <if test="handoverUserId != null">
                #{handoverUserId,jdbcType=VARCHAR},
            </if>
            <if test="dimissionTime != null">
                #{dimissionTime,jdbcType=TIMESTAMP},
            </if>
            <if test="friendCount != null">
                #{friendCount,jdbcType=INTEGER},
            </if>
            <if test="haobanFriendCount != null">
                #{haobanFriendCount,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.TabHandoverStaff">
        update tab_haoban_handover_staff
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="staffId != null">
                staff_id = #{staffId,jdbcType=VARCHAR},
            </if>
            <if test="storeId != null">
                store_id = #{storeId,jdbcType=VARCHAR},
            </if>
            <if test="handoverUserId != null">
                handover_user_id = #{handoverUserId,jdbcType=VARCHAR},
            </if>
            <if test="dimissionTime != null">
                dimission_time = #{dimissionTime,jdbcType=TIMESTAMP},
            </if>
            <if test="friendCount != null">
                friend_count = #{friendCount,jdbcType=INTEGER},
            </if>
            <if test="haobanFriendCount != null">
                haoban_friend_count = #{haobanFriendCount,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 handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHandoverStaff">
    update tab_haoban_handover_staff
    set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      staff_id = #{staffId,jdbcType=VARCHAR},
      store_id = #{storeId,jdbcType=VARCHAR},
      handover_user_id = #{handoverUserId,jdbcType=VARCHAR},
      dimission_time = #{dimissionTime,jdbcType=TIMESTAMP},
      friend_count = #{friendCount,jdbcType=INTEGER},
      haoban_friend_count = #{haobanFriendCount,jdbcType=INTEGER},
      status_flag = #{statusFlag,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR}
  </update>

    <select id="getByStaffId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_staff
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        and staff_id=#{staffId}
        and status_flag = 1
    </select>

    <select id="listByStoreId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_staff
        where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
        and store_id=#{storeId}
        and status_flag=1
    </select>

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

    <update id="delByUserIds">
        update tab_haoban_handover_staff
        set
        status_flag = 0,
        update_time = now()
        where
        wx_enterprise_id=#{wxEnterpriseId}
        and status_flag=1
        <if test="userIds!=null and userIds.size>0">
            and handover_user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </update>
</mapper>