<?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.TabHaobanWelcomeSuitRangMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.TabHaobanWelcomeSuitRang" id="TabHaobanWelcomeSuitRangMap">
        <result property="welcomeSuitRangId" column="welcome_suit_rang_id" jdbcType="BIGINT"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="welcomeId" column="welcome_id" jdbcType="VARCHAR"/>
        <result property="suitType" column="suit_type" jdbcType="INTEGER"/>
        <result property="suitDepartmentId" column="suit_department_id" jdbcType="VARCHAR"/>
        <result property="suitDepartmentName" column="suit_department_name" jdbcType="VARCHAR"/>
        <result property="suitStaffId" column="suit_staff_id" jdbcType="VARCHAR"/>
        <result property="suitStaffName" column="suit_staff_name" jdbcType="VARCHAR"/>
        <result property="staffBelongDepartmentId" column="staff_belong_department_id" jdbcType="VARCHAR"/>
        <result property="staffBelongDepartmentName" column="staff_belong_department_name" jdbcType="VARCHAR"/>
        <result property="selectType" column="select_type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanWelcomeSuitRangMap">
        select welcome_suit_rang_id,
               wx_enterprise_id,
               welcome_id,
               suit_type,
               suit_department_id,
               suit_department_name,
               suit_staff_id,
               suit_staff_name,
               staff_belong_department_id,
               staff_belong_department_name,
               select_type,
               create_time,
               update_time,
               delete_flag
        from tab_haoban_welcome_suit_rang
        where welcome_suit_rang_id = #{welcomeSuitRangId}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TabHaobanWelcomeSuitRangMap">
        select welcome_suit_rang_id,
               wx_enterprise_id,
               welcome_id,
               suit_type,
               suit_department_id,
               suit_department_name,
               suit_staff_id,
               suit_staff_name,
               staff_belong_department_id,
               staff_belong_department_name,
               select_type,
               create_time,
               update_time,
               delete_flag
        from tab_haoban_welcome_suit_rang limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="TabHaobanWelcomeSuitRangMap">
        select
        welcome_suit_rang_id, wx_enterprise_id, welcome_id, suit_type, suit_department_id, suit_department_name,
        suit_staff_id, suit_staff_name, staff_belong_department_id, staff_belong_department_name, select_type,
        create_time,
        update_time, delete_flag
        from tab_haoban_welcome_suit_rang
        <where>
            <if test="welcomeSuitRangId != null">
                and welcome_suit_rang_id = #{welcomeSuitRangId}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
            <if test="welcomeId != null and welcomeId != ''">
                and welcome_id = #{welcomeId}
            </if>
            <if test="suitType != null">
                and suit_type = #{suitType}
            </if>
            <if test="suitDepartmentId != null and suitDepartmentId != ''">
                and suit_department_id = #{suitDepartmentId}
            </if>
            <if test="suitDepartmentName != null and suitDepartmentName != ''">
                and suit_department_name = #{suitDepartmentName}
            </if>
            <if test="suitStaffId != null and suitStaffId != ''">
                and suit_staff_id = #{suitStaffId}
            </if>
            <if test="suitStaffName != null and suitStaffName != ''">
                and suit_staff_name = #{suitStaffName}
            </if>
            <if test="staffBelongDepartmentId != null and staffBelongDepartmentId != ''">
                and staff_belong_department_id = #{staffBelongDepartmentId}
            </if>
            <if test="staffBelongDepartmentName != null and staffBelongDepartmentName != ''">
                and staff_belong_department_name = #{staffBelongDepartmentName}
            </if>
            <if test="selectType != null">
                and select_type = #{selectType}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="welcomeSuitRangId" useGeneratedKeys="false">
        insert into tab_haoban_welcome_suit_rang(
                                                 welcome_suit_rang_id,
                                                 wx_enterprise_id,
                                                 welcome_id,
                                                 suit_type,
                                                 suit_department_id,
                                                 suit_department_name,
                                                 suit_staff_id,
                                                 suit_staff_name,
                                                 staff_belong_department_id,
                                                 staff_belong_department_name,
                                                 select_type,
                                                 create_time,
                                                 update_time,
                                                 delete_flag)
        values (#{welcomeSuitRangId},
                #{wxEnterpriseId},
                #{welcomeId},
                #{suitType},
                #{suitDepartmentId},
                #{suitDepartmentName},
                #{suitStaffId},
                #{suitStaffName},
                #{staffBelongDepartmentId},
                #{staffBelongDepartmentName},
                #{selectType},
                #{createTime},
                #{updateTime},
                #{deleteFlag})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_welcome_suit_rang
        <set>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="welcomeId != null and welcomeId != ''">
                welcome_id = #{welcomeId},
            </if>
            <if test="suitType != null">
                suit_type = #{suitType},
            </if>
            <if test="suitDepartmentId != null and suitDepartmentId != ''">
                suit_department_id = #{suitDepartmentId},
            </if>
            <if test="suitDepartmentName != null and suitDepartmentName != ''">
                suit_department_name = #{suitDepartmentName},
            </if>
            <if test="suitStaffId != null and suitStaffId != ''">
                suit_staff_id = #{suitStaffId},
            </if>
            <if test="suitStaffName != null and suitStaffName != ''">
                suit_staff_name = #{suitStaffName},
            </if>
            <if test="staffBelongDepartmentId != null and staffBelongDepartmentId != ''">
                staff_belong_department_id = #{staffBelongDepartmentId},
            </if>
            <if test="staffBelongDepartmentName != null and staffBelongDepartmentName != ''">
                staff_belong_department_name = #{staffBelongDepartmentName},
            </if>
            <if test="selectType != null">
                select_type = #{selectType},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where welcome_suit_rang_id = #{welcomeSuitRangId}
    </update>

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

    <select id="listByWxEnterpriseIdAndDeptList"
            resultMap="TabHaobanWelcomeSuitRangMap">
        select welcome_suit_rang_id,
        wx_enterprise_id,
        welcome_id,
        suit_type,
        suit_department_id,
        suit_department_name,
        suit_staff_id,
        suit_staff_name,
        staff_belong_department_id,
        staff_belong_department_name,
        select_type,
        create_time,
        update_time,
        delete_flag
        from tab_haoban_welcome_suit_rang
        where delete_flag = 0
        and wx_enterprise_id = #{wxEnterpriseId}
        and suit_department_id in
        <foreach collection="departmentIdList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <insert id="batchInsert">
        insert into tab_haoban_welcome_suit_rang
        (
        welcome_suit_rang_id,
        wx_enterprise_id,
        welcome_id,
        suit_type,
        suit_department_id,
        suit_department_name,
        suit_staff_id,
        suit_staff_name,
        staff_belong_department_id,
        staff_belong_department_name,
        select_type,
        create_time,
        update_time,
        delete_flag
        )
         values
        <foreach collection="welcomeSuitRangList" item="model" separator=",">
            (#{model.welcomeSuitRangId}, #{model.wxEnterpriseId}, #{model.welcomeId}, #{model.suitType}, #{model.suitDepartmentId}, #{model.suitDepartmentName},
            #{model.suitStaffId}, #{model.suitStaffName}, #{model.staffBelongDepartmentId}, #{model.staffBelongDepartmentName}, #{model.selectType},
            #{model.createTime}, #{model.updateTime}, #{model.deleteFlag})
        </foreach>
    </insert>

    <update id="batchDeleteBySuitDepartmentIdSet">
        update tab_haoban_welcome_suit_rang
        set delete_flag = 1 where wx_enterprise_id = #{wxEnterpriseId} and welcome_id = #{welcomeId}
        and suit_department_id in
        <foreach collection="suitDepartmentIdSet" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <update id="batchDeleteBySuitStaffIdSet">
        update tab_haoban_welcome_suit_rang
        set delete_flag = 1 where wx_enterprise_id = #{wxEnterpriseId} and welcome_id = #{welcomeId}
        and suit_staff_id in
        <foreach collection="suitStaffIdSet" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

</mapper>
