<?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.content.TabHaobanClerkShareLogMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.content.TabHaobanClerkShareLog"
               id="TabHaobanClerkShareLogMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="clerkId" column="clerk_id" jdbcType="VARCHAR"/>
        <result property="staffId" column="staff_id" jdbcType="VARCHAR"/>
        <result property="storeId" column="store_id" jdbcType="VARCHAR" />
        <result property="shareType" column="share_type" jdbcType="INTEGER"/>
        <result property="bizId" column="biz_id" jdbcType="VARCHAR"/>
        <result property="bizType" column="biz_type" jdbcType="INTEGER"/>
        <result property="extend" column="extend" jdbcType="VARCHAR"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="baseSql">
        id
        , enterprise_id, wx_enterprise_id, clerk_id, staff_id, store_id, share_type, biz_id, biz_type, extend,delete_flag, create_time, update_time
    </sql>
    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanClerkShareLogMap">
        select id,
               enterprise_id,
               wx_enterprise_id,
               clerk_id,
               staff_id,
               store_id,
               share_type,
               biz_id,
               biz_type,
               extend,
               delete_flag,
               create_time,
               update_time
        from tab_haoban_clerk_share_log
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryWithCondition" resultMap="TabHaobanClerkShareLogMap">
        select
        id, enterprise_id, wx_enterprise_id, clerk_id, staff_id, store_id, share_type, biz_id, biz_type, delete_flag, create_time,
        update_time
        from tab_haoban_clerk_share_log
        <where>
            delete_flag = 0
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="clerkId != null and clerkId != ''">
                and clerk_id = #{clerkId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="startTime != null">
                and create_time >= #{startTime}
            </if>
            <if test="endTime != null">
                and create_time <![CDATA[ <= ]]> #{endTime}
            </if>
            <if test="shareLogId != null">
                and id = #{shareLogId}
            </if>
        </where>
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tab_haoban_clerk_share_log
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="clerkId != null and clerkId != ''">
                and clerk_id = #{clerkId}
            </if>
            <if test="staffId != null and staffId != ''">
                and staff_id = #{staffId}
            </if>
            <if test="shareType != null">
                and share_type = #{shareType}
            </if>
            <if test="bizId != null and bizId != ''">
                and biz_id = #{bizId}
            </if>
            <if test="bizType != null">
                and biz_type = #{bizType}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_clerk_share_log(id, enterprise_id, wx_enterprise_id, clerk_id, staff_id, store_id, share_type,
                                               biz_id, biz_type,extend,
                                               delete_flag, create_time, update_time)
        values (#{id}, #{enterpriseId}, #{wxEnterpriseId}, #{clerkId}, #{staffId}, #{storeId}, #{shareType}, #{bizId}, #{bizType},#{extend},
                #{deleteFlag},
                #{createTime}, #{updateTime})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_clerk_share_log(id, enterprise_id, wx_enterprise_id, clerk_id, staff_id, share_type,
        biz_id, biz_type,
        delete_flag, create_time, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.enterpriseId}, #{entity.wxEnterpriseId}, #{entity.clerkId}, #{entity.staffId},
            #{entity.shareType}, #{entity.bizId},
            #{entity.bizType}, #{entity.deleteFlag}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tab_haoban_clerk_share_log(enterprise_id, clerk_id, staff_id, share_type, biz_id, biz_type,
        delete_flag, create_time, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.enterpriseId}, #{entity.clerkId}, #{entity.staffId}, #{entity.shareType}, #{entity.bizId},
            #{entity.bizType}, #{entity.deleteFlag}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
        on duplicate key update
        enterprise_id = values(enterprise_id),
        clerk_id = values(clerk_id),
        staff_id = values(staff_id),
        share_type = values(share_type),
        biz_id = values(biz_id),
        biz_type = values(biz_type),
        delete_flag = values(delete_flag),
        create_time = values(create_time),
        update_time = values(update_time)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_clerk_share_log
        <set>
            <if test="enterpriseId != null and enterpriseId != ''">
                enterprise_id = #{enterpriseId},
            </if>
            <if test="clerkId != null and clerkId != ''">
                clerk_id = #{clerkId},
            </if>
            <if test="staffId != null and staffId != ''">
                staff_id = #{staffId},
            </if>
            <if test="shareType != null">
                share_type = #{shareType},
            </if>
            <if test="bizId != null and bizId != ''">
                biz_id = #{bizId},
            </if>
            <if test="bizType != null">
                biz_type = #{bizType},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from tab_haoban_clerk_share_log
        where id = #{id}
    </delete>

    <update id="markShareLogWithDone">
        update tab_haoban_clerk_share_log set delete_flag = 1
        where enterprise_id = #{enterpriseId} and id in
            <foreach collection="ids" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
    </update>

</mapper>

