<?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.yiqi.activity.mapper.ActivityApplyOrgMapper">

    <resultMap type="ActivityApplyOrg" id="ActivityApplyOrgResult">
        <result property="id" column="id"/>
        <result property="activityId" column="activity_id"/>
        <result property="orgId" column="org_id"/>
        <result property="sourceType" column="source_type"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectActivityApplyOrgVo">
        select id, activity_id, org_id, source_type, create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from activity_apply_org
    </sql>

    <select id="selectActivityApplyOrgList" parameterType="ActivityApplyOrg" resultMap="ActivityApplyOrgResult">
        <include refid="selectActivityApplyOrgVo"/>
        <where>
            <if test="activityId != null ">
                and activity_id = #{activityId}
            </if>
            <if test="orgId != null ">
                and org_id = #{orgId}
            </if>
            <if test="sourceType != null  and sourceType != ''">
                and source_type = #{sourceType}
            </if>
        </where>
    </select>

    <select id="selectActivityApplyOrgById" parameterType="Long"
            resultMap="ActivityApplyOrgResult">
        <include refid="selectActivityApplyOrgVo"/>
        where id = #{id}
    </select>

    <insert id="insertActivityApplyOrg" parameterType="ActivityApplyOrg" useGeneratedKeys="true"
            keyProperty="id">
        insert into activity_apply_org
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="activityId != null">activity_id,
            </if>
            <if test="orgId != null">org_id,
            </if>
            <if test="sourceType != null">source_type,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="activityId != null">#{activityId},
            </if>
            <if test="orgId != null">#{orgId},
            </if>
            <if test="sourceType != null">#{sourceType},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateActivityApplyOrg" parameterType="ActivityApplyOrg">
        update activity_apply_org
        <trim prefix="SET" suffixOverrides=",">
            <if test="activityId != null">activity_id =
                #{activityId},
            </if>
            <if test="orgId != null">org_id =
                #{orgId},
            </if>
            <if test="sourceType != null">source_type =
                #{sourceType},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteActivityApplyOrgById" parameterType="Long">
            delete from activity_apply_org where id = #{id}
        </delete>

    <delete id="deleteActivityApplyOrgByIds" parameterType="String">
        delete from activity_apply_org where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>



</mapper>