<?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.wxUser.mapper.CompanyWxUserGroupMapper">
    
    <resultMap type="CompanyWxUserGroup" id="CompanyWxUserGroupResult">
        <result property="groupId"    column="group_id"    />
        <result property="groupName"    column="group_name"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectCompanyWxUserGroupVo">
        select group_id, group_name, company_id from company_wx_user_group
    </sql>

    <select id="selectCompanyWxUserGroupList" parameterType="CompanyWxUserGroup" resultMap="CompanyWxUserGroupResult">
        <include refid="selectCompanyWxUserGroupVo"/>
        <where>
            <if test="groupName != null  and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectCompanyWxUserGroupByGroupId" parameterType="Long" resultMap="CompanyWxUserGroupResult">
        <include refid="selectCompanyWxUserGroupVo"/>
        where group_id = #{groupId}
    </select>
        
    <insert id="insertCompanyWxUserGroup" parameterType="CompanyWxUserGroup">
        insert into company_wx_user_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupId != null">group_id,</if>
            <if test="groupName != null">group_name,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">#{groupId},</if>
            <if test="groupName != null">#{groupName},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateCompanyWxUserGroup" parameterType="CompanyWxUserGroup">
        update company_wx_user_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupName != null">group_name = #{groupName},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where group_id = #{groupId}
    </update>

    <delete id="deleteCompanyWxUserGroupByGroupId" parameterType="Long">
        delete from company_wx_user_group where group_id = #{groupId}
    </delete>

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