<?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="wifiGroupInfoSqlMapper">
	<sql id="column">
		id,name,status,updated,operator_id as operatorId
	</sql>
	<insert id="addWifiGroupInfo" parameterType="com.cloudcross.ssp.model.WifiGroupInfo">
		insert into t_wifi_group_info
		 <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">
                name,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="updated != null">
                updated,
            </if>
            <if test="operatorId != null">
            	operator_id
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">
                #{name},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="updated != null">
                #{updated},
            </if>
            <if test="operatorId != null">
            	#{operatorId}
            </if>
        </trim>
	</insert>
	
	<!-- operatorId查询分组信息 -->
	<select id="queryGroupNames" resultType="com.cloudcross.ssp.model.WifiGroupInfo" parameterType="java.util.Map">
		select <include refid="column"/> from t_wifi_group_info where status = 0 and operator_id = #{operatorId} limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="queryGroupNamesCount" resultType="java.lang.Integer" parameterType="java.util.Map">
		select count(id) from t_wifi_group_info where status = 0 and operator_id = #{operatorId}
	</select>
	
	<select id="queryWifiGroupInfoByCondition" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.WifiGroupInfo">
		select <include refid="column"/> from t_wifi_group_info where status = 0 and operator_id = #{operatorId} 
		<if test="name != null">
			and name = #{name} 
		</if>
	</select>
	
	<select id="queryWifiGroupInfoByadgroupId" parameterType="java.lang.Long" resultType="com.cloudcross.ssp.model.WifiGroupInfo">
		select twgi.id id,twgi.name name  from t_wifi_group_info twgi,t_adgroup_wifigroup taw where twgi.id = taw.wifigroup_id 
		and taw.status = 0 and twgi.status = 0 and taw.adgroup_id=#{adgroupId}
	</select>
	
	<select id="queryGroupNameAll" resultType="com.cloudcross.ssp.model.WifiGroupInfo" parameterType="java.util.Map">
		select <include refid="column"/> from t_wifi_group_info where status = 0 and operator_id = #{operatorId} 
	</select>
	
	<!-- 删除分组 -->
	<update id="updateStatusById" parameterType="java.util.Map">
		update t_wifi_group_info 
			set status = #{status},updated = #{updated}
			where t_wifi_group_info.id = #{id}
	</update>
	
</mapper>