<?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.bonus.sgzb.base.mapper.BmUnitPersonMapper">
    
    <resultMap type="com.bonus.sgzb.base.domain.BmUnitPerson" id="BmUnitPersonResult">
    	<id     property="unitId"      column="unit_id"      />
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>
    
    <sql id="bmUnitPerson">
        select unit_id, user_id, company_id
		from bm_unit_person
    </sql>


    <select id="getUnitPersonAll"  resultMap="BmUnitPersonResult">
        <!--<include refid="bmUnitInfo"/>-->
        select unit_id, user_id, company_id
        from bm_unit_person
    </select>
    
    <select id="getUnitPerson" parameterType="com.bonus.sgzb.base.domain.BmUnitPerson" resultMap="BmUnitPersonResult">
        <include refid="bmUnitPerson"/>
        <where>
			<if test="unitId != null and unitId != ''">
				AND unit_id = #{unitId}
			</if>
			<if test="userId != null and userId != ''">
				AND user_id = #{userId}
			</if>
            <if test="companyId != null and companyId != ''">
                AND company_id = #{companyId}
            </if>
		</where>
    </select>

    <select id="getUnitPersons" parameterType="Long" resultMap="BmUnitPersonResult">
        <include refid="bmUnitPerson"/>
        where unit_id = #{unitId}
    </select>
    
    <insert id="unitPersonAdd" parameterType="com.bonus.sgzb.base.domain.BmUnitPerson">
        insert into bm_unit_person (
            <if test="unitId != null and unitId != '' ">unit_id,</if>
			<if test="userId != null and userId != '' ">user_id</if>
        )values(
            <if test="unitId != null and unitId != ''">#{unitId},</if>
			<if test="userId != null and userId != ''">#{userId}</if>
		)
    </insert>
	 
    <update id="updateBmUnitPerson" parameterType="com.bonus.sgzb.base.domain.BmUnitPerson">
        update bm_unit_person
        <set>
            <if test="userId != null and userId != ''">user_id = #{userId}</if>
            <if test="companyId != null and companyId != ''">,company_id = #{companyId}</if>
        </set>
        where unit_id = #{unitId}
    </update>
	
    <delete id="deleteUnitInfoById" parameterType="Long">
        delete from bm_unit_person where unit_id = #{unitId}
    </delete>
    
    <delete id="remove" parameterType="Long">
        delete from bm_unit_person where unit_id in
        <foreach item="unitId" collection="array" open="(" separator="," close=")">
        	#{unitId}
        </foreach>
    </delete>
    
</mapper>