<?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="cn.pluss.platform.mapper.UserOrganMapper">

	   	<insert id="saveUserOrgan" parameterType="cn.pluss.platform.entity.UserOrgan">
        	insert into tb_pluss_user_organ(userId,organCode,organName,organTypeCode,organTypeName)VALUES(#{userId},#{organCode},#{organName},#{organTypeCode},#{organTypeName})
    	</insert>

	   	<insert id="saveUserOrganBatch">
        	insert into tb_pluss_user_organ(userId,organCode,organName,organTypeCode,organTypeName) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{userId},#{organCode},#{organName},#{organTypeCode},#{organTypeName}		)
				</foreach>
    	</insert>

		<select id="queryUserOrgan" parameterType="cn.pluss.platform.entity.UserOrgan" resultType="cn.pluss.platform.entity.UserOrgan">
			SELECT * from tb_pluss_user_organ 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 	and userId = #{userId}
					 </if> 
					<if test="organCode!= null"> 
					 	and organCode = #{organCode}
					 </if> 
					<if test="organName!= null"> 
					 	and organName = #{organName}
					 </if> 
					<if test="organTypeCode!= null"> 
					 	and organTypeCode = #{organTypeCode}
					 </if> 
					<if test="organTypeName!= null"> 
					 	and organTypeName = #{organTypeName}
					 </if> 
				 </where> 
		</select>

		<select id="queryUserOrganList" parameterType="cn.pluss.platform.entity.UserOrgan" resultType="cn.pluss.platform.entity.UserOrgan">
			SELECT * from tb_pluss_user_organ 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and 	userId = #{userId}
					 </if> 
					<if test="organCode!= null"> 
					 and 	organCode = #{organCode}
					 </if> 
					<if test="organName!= null"> 
					 and 	organName = #{organName}
					 </if> 
					<if test="organTypeCode!= null"> 
					 and 	organTypeCode = #{organTypeCode}
					 </if> 
					<if test="organTypeName!= null"> 
					 and 	organTypeName = #{organTypeName}
					 </if> 
				 </where> 
		</select>

		<update id="updateUserOrgan" parameterType="cn.pluss.platform.entity.UserOrgan" >
			update tb_pluss_user_organ 
				  <set> 
					<if test="userId!= null"> 
					 	userId = #{userId},
					 </if> 
					<if test="organCode!= null"> 
					 	organCode = #{organCode},
					 </if> 
					<if test="organName!= null"> 
					 	organName = #{organName},
					 </if> 
					<if test="organTypeCode!= null"> 
					 	organTypeCode = #{organTypeCode},
					 </if> 
					<if test="organTypeName!= null"> 
					 	organTypeName = #{organTypeName}
					 </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteUserOrgan" parameterType="cn.pluss.platform.entity.UserOrgan" >
			DELETE FROM tb_pluss_user_organ where id=#{id}
		</delete>

		<select id="queryUserOrganPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.UserOrgan">
			SELECT * from tb_pluss_user_organ 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					and userId = #{userId}
					 </if> 
					<if test="organCode!= null"> 
					and organCode = #{organCode}
					 </if> 
					<if test="organName!= null"> 
					and organName = #{organName}
					 </if> 
					<if test="organTypeCode!= null"> 
					and organTypeCode = #{organTypeCode}
					 </if> 
					<if test="organTypeName!= null"> 
					and organTypeName = #{organTypeName}
					 </if> 
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryUserOrganPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_user_organ 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and userId = #{userId}
					 </if> 
					<if test="organCode!= null"> 
					 and organCode = #{organCode}
					 </if> 
					<if test="organName!= null"> 
					 and organName = #{organName}
					 </if> 
					<if test="organTypeCode!= null"> 
					 and organTypeCode = #{organTypeCode}
					 </if> 
					<if test="organTypeName!= null"> 
					 and organTypeName = #{organTypeName}
					 </if> 
				</where>
		</select>

</mapper>
