<?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.fs.qw.mapper.QwContactWayGroupMapper">

    <resultMap type="QwContactWayGroup" id="QwContactWayGroupResult">
        <result property="id"    column="id"    />
        <result property="groupName"    column="group_name"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="corpId"    column="corp_id"    />
    </resultMap>

    <sql id="selectQwContactWayGroupVo">
        select id,corp_id,  group_name, company_id, create_time from qw_contact_way_group
    </sql>

    <select id="selectQwContactWayGroupList" parameterType="QwContactWayGroup" resultMap="QwContactWayGroupResult">
        <include refid="selectQwContactWayGroupVo"/>
        <where>
            <if test="groupName != null  and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
        </where>
    </select>

    <select id="selectQwContactWayGroupById" parameterType="Long" resultMap="QwContactWayGroupResult">
        <include refid="selectQwContactWayGroupVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwContactWayGroup" parameterType="QwContactWayGroup" useGeneratedKeys="true" keyProperty="id">
        insert into qw_contact_way_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupName != null">group_name,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="corpId != null">corp_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupName != null">#{groupName},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="corpId != null">#{corpId},</if>
         </trim>
    </insert>

    <update id="updateQwContactWayGroup" parameterType="QwContactWayGroup">
        update qw_contact_way_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupName != null">group_name = #{groupName},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwContactWayGroupById" parameterType="Long">
        delete from qw_contact_way_group where id = #{id}
    </delete>

    <delete id="deleteQwContactWayGroupByIds" parameterType="String">
        delete from qw_contact_way_group where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
