<?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.nbclass.activity.mapper.WxUserMapper">
	
	<insert id="insertCustom" parameterType="com.nbclass.activity.model.WxUser" useGeneratedKeys="true" keyProperty="id">
		insert into wx_user (userid, name, mobile, department, position, gender, email, weixinid,
		 	isleader, avatar, english_name, status) 
		values (#{userid}, #{name}, #{mobile}, #{department}, #{position}, #{gender}, #{email}, #{weixinid},
			#{isleader}, #{avatar}, #{english_name}, #{status})
	</insert>
    
    <update id="updateByUserId" parameterType="com.nbclass.activity.model.WxUser">
		update wx_user set name = #{name}, mobile = #{mobile}, department = #{department}
		<if test="position != null and position != ''">
			, position = #{position} 
		</if>
		<if test="gender != null and gender != ''">
			, gender = #{gender} 
		</if>
		<if test="email != null and email != ''">
			, email = #{email} 
		</if>
		<if test="weixinid != null and weixinid != ''">
			, weixinid = #{weixinid} 
		</if>
		<if test="isleader != null and isleader != ''">
			, isleader = #{isleader} 
		</if>
		<if test="avatar != null and avatar != ''">
			, avatar = #{avatar} 
		</if>
		<if test="english_name != null and english_name != ''">
			, english_name = #{english_name} 
		</if>
		<if test="status != null and status > 0">
			, `status` = #{status} 
		</if>
		where userid = #{userid} 
	</update>
	
	<select id="getUserIds" resultType="java.lang.String">
		select userid from wx_user
	</select>
    
    <select id="getUsersByDeptIds" parameterType="java.util.List" resultType="com.nbclass.activity.model.WxUser">
    	select userid, name, avatar from wx_user where 
    	<foreach item="deptid" collection="deptids" open="(" separator="or" close=")">
     		FIND_IN_SET(#{deptid}, department) 
		</foreach>
    </select>
	
	<select id="getUsersByUserIds" parameterType="java.util.List" resultType="com.nbclass.activity.model.WxUser">
		select userid, name, avatar from wx_user where userid in 
		<foreach item="userid" collection="userids" open="(" separator="," close=")">
    		#{userid} 
		</foreach>
	</select>
    
	<delete id="delOtherUsers" parameterType="java.util.List">
		delete from wx_user where userid not in 
		<foreach item="userid" collection="userids" open="(" separator="," close=")">
    		#{userid} 
		</foreach>
	</delete>
    
</mapper>