<?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.HandoverTransferMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHandoverTransfer">
        <id column="handover_transfer_id" jdbcType="VARCHAR" property="handoverTransferId"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="store_id" jdbcType="VARCHAR" property="storeId"/>
        <result column="handover_staff_id" jdbcType="VARCHAR" property="handoverStaffId"/>
        <result column="takeover_staff_id" jdbcType="VARCHAR" property="takeoverStaffId"/>
        <result column="external_count" jdbcType="INTEGER" property="externalCount"/>
        <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_transfer_id, wx_enterprise_id, store_id, handover_staff_id, takeover_staff_id, 
    external_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_transfer
        where handover_transfer_id = #{handoverTransferId,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from tab_haoban_handover_transfer
    where handover_transfer_id = #{handoverTransferId,jdbcType=VARCHAR}
  </delete>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHandoverTransfer">
    insert into tab_haoban_handover_transfer (handover_transfer_id, wx_enterprise_id, 
      store_id, handover_staff_id, takeover_staff_id, 
      external_count, status_flag, create_time, 
      update_time)
    values (#{handoverTransferId,jdbcType=VARCHAR}, #{wxEnterpriseId,jdbcType=VARCHAR}, 
      #{storeId,jdbcType=VARCHAR}, #{handoverStaffId,jdbcType=VARCHAR}, #{takeoverStaffId,jdbcType=VARCHAR}, 
      #{externalCount,jdbcType=INTEGER}, #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP})
  </insert>
    <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHandoverTransfer">
        insert into tab_haoban_handover_transfer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="handoverTransferId != null">
                handover_transfer_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="storeId != null">
                store_id,
            </if>
            <if test="handoverStaffId != null">
                handover_staff_id,
            </if>
            <if test="takeoverStaffId != null">
                takeover_staff_id,
            </if>
            <if test="externalCount != null">
                external_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="handoverTransferId != null">
                #{handoverTransferId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="storeId != null">
                #{storeId,jdbcType=VARCHAR},
            </if>
            <if test="handoverStaffId != null">
                #{handoverStaffId,jdbcType=VARCHAR},
            </if>
            <if test="takeoverStaffId != null">
                #{takeoverStaffId,jdbcType=VARCHAR},
            </if>
            <if test="externalCount != null">
                #{externalCount,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.TabHandoverTransfer">
        update tab_haoban_handover_transfer
        <set>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="storeId != null">
                store_id = #{storeId,jdbcType=VARCHAR},
            </if>
            <if test="handoverStaffId != null">
                handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR},
            </if>
            <if test="takeoverStaffId != null">
                takeover_staff_id = #{takeoverStaffId,jdbcType=VARCHAR},
            </if>
            <if test="externalCount != null">
                external_count = #{externalCount,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_transfer_id = #{handoverTransferId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHandoverTransfer">
    update tab_haoban_handover_transfer
    set wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
      store_id = #{storeId,jdbcType=VARCHAR},
      handover_staff_id = #{handoverStaffId,jdbcType=VARCHAR},
      takeover_staff_id = #{takeoverStaffId,jdbcType=VARCHAR},
      external_count = #{externalCount,jdbcType=INTEGER},
      status_flag = #{statusFlag,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where handover_transfer_id = #{handoverTransferId,jdbcType=VARCHAR}
  </update>

    <select id="getByHandoverStaffIdAndTakeoverStaffId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_transfer
        where wx_enterprise_id=#{wxEnterpriseId}
        and handover_staff_id = #{handoverStaffId}
        and takeover_staff_id = #{takeoverStaffId}
        and status_flag=1
    </select>

    <update id="addCount">
    update tab_haoban_handover_transfer
    set
    external_count =external_count+${count},
    update_time = now()
    where handover_transfer_id = #{id}
  </update>

    <select id="listTransferByStoreId" resultMap="BaseResultMap">
    select
    handover_staff_id,
    max(update_time) as update_time,
    sum(external_count) as external_count
    from tab_haoban_handover_transfer
    where wx_enterprise_id=#{wxEnterpriseId}
        and store_id = #{storeId}
    and status_flag=1
        group by handover_staff_id
  </select>

    <select id="listTransferByHandoverStaffId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_transfer
        where wx_enterprise_id=#{wxEnterpriseId}
        and handover_staff_id = #{handoverStaffId}
        and status_flag=1
    </select>

    <select id="listTransferByTakeoverStaffId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_transfer
        where wx_enterprise_id=#{wxEnterpriseId}
        and takeover_staff_id = #{takeoverStaffId}
        and status_flag=1
    </select>

    <select id="listTransferByIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_transfer
        where wx_enterprise_id=#{wxEnterpriseId}
        and handover_transfer_id in
        <foreach collection="ids" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        and status_flag=1
    </select>

    <select id="listTransferByWxEnterpriseId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_handover_transfer
        where wx_enterprise_id=#{wxEnterpriseId}
        and update_time > #{date}
        and status_flag=1
    </select>

</mapper>