<?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.api.manage.dao.operationManagement.SysSponsorManagementDao">
    <select id="list" parameterType="com.api.model.operationManagement.SearchSponsorManagement" resultType="com.api.vo.operationManagement.VoSponsorManagement">
        select * from sys_sponsor_management
        <where>
            and is_delete = 1
            <if test="sponsorUnit != null and sponsorUnit != ''">
                and sponsor_unit like concat('%',#{sponsorUnit},'%')
            </if>
            <if test="director != null and director != ''">
                and director like concat('%',#{director},'%')
            </if>
            <if test="tel != null and tel != ''">
                and tel like concat('%',#{tel},'%')
            </if>
            <if test="idType != null">
                and id_type = #{idType}
            </if>
            <if test="idNumber != null and idNumber != ''">
                and id_number like concat('%',#{idNumber},'%')
            </if>
        </where>
    </select>

    <insert id="insert" parameterType="com.api.model.operationManagement.SponsorManagement">
        insert into
        <trim prefix="sys_sponsor_management(" suffix=")" suffixOverrides=",">
            <if test="sponsorUnit != null and sponsorUnit != ''">
                sponsor_unit,
            </if>
            <if test="director != null and director != ''">
                director,
            </if>
            <if test="tel != null and tel != ''">
                tel,
            </if>
            <if test="idType != null">
                id_type,
            </if>
            <if test="idNumber != null and idNumber != ''">
                id_number,
            </if>
            create_id,
            create_date,
            is_delete
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sponsorUnit != null and sponsorUnit != ''">
                #{sponsorUnit},
            </if>
            <if test="director != null and director != ''">
                #{director},
            </if>
            <if test="tel != null and tel != ''">
                #{tel},
            </if>
            <if test="idType != null">
                #{idType},
            </if>
            <if test="idNumber != null and idNumber != ''">
                #{idNumber},
            </if>
            #{createId},
            #{createDate},
            #{isDelete}
        </trim>

        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.operationManagement.VoFindByIdSponsorManagement">
        select * from sys_sponsor_management where id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.operationManagement.SponsorManagement">
        update sys_sponsor_management
        <set>
            <if test="sponsorUnit != null and sponsorUnit != ''">
                sponsor_unit = #{sponsorUnit},
            </if>
            <if test="director != null and director != ''">
                director = #{director},
            </if>
            <if test="tel != null and tel != ''">
                tel = #{tel},
            </if>
            <if test="idType != null">
                id_type = #{idType},
            </if>
            <if test="idNumber != null and idNumber != ''">
                id_number = #{idNumber},
            </if>
            modify_id = #{modifyId},
            modify_date = #{modifyDate},
        </set>
        where id =#{id}
    </update>

    <update id="falseDelete" parameterType="java.lang.Integer">
        update sys_sponsor_management set is_delete = 0 where id =#{id}
    </update>

    <select id="sponsorActivityDetail" parameterType="java.lang.Integer" resultType="com.api.vo.operationManagement.VoSponsorActivityDetail">
        select id,title from sys_activity_management where sponsor_id = #{id}
    </select>
</mapper>