<?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.ruoyi.party.mapper.ExcellentPartyMemberMapper">
    
    <resultMap type="com.ruoyi.party.domain.ExcellentPartyMember" id="ExcellentPartyMemberResult">
        <result property="id"    column="id"    />
        <result property="partyMemberId"    column="party_member_id"    />
        <result property="xm"    column="xm"    />
        <result property="phone"    column="phone"    />
        <result property="dzzdm"    column="dzzdm"    />
        <result property="year"    column="year"    />
        <result property="effectiveTimeStart"    column="effective_time_start"    />
        <result property="effectiveTimeEnd"    column="effective_time_end"    />
        <result property="title"    column="title"    />
        <result property="careateBy"    column="careate_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectExcellentPartyMemberVo">
        select id, party_member_id, xm, phone, dzzdm, year, effective_time_start, effective_time_end, title, careate_by, create_time, update_by, update_time from excellent_party_member
    </sql>

    <select id="selectExcellentPartyMemberList" parameterType="com.ruoyi.party.domain.ExcellentPartyMember" resultType="com.ruoyi.party.domain.vo.ExcellentPartyMemberVo">
        <include refid="selectExcellentPartyMemberVo"/>
        <where>  
            <if test="partyMemberId != null "> and party_member_id = #{partyMemberId}</if>
            <if test="xm != null  and xm != ''"> and xm = #{xm}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="dzzdm != null  and dzzdm != ''"> and dzzdm = #{dzzdm}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="effectiveTimeStart != null "> and effective_time_start = #{effectiveTimeStart}</if>
            <if test="effectiveTimeEnd != null "> and effective_time_end = #{effectiveTimeEnd}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="careateBy != null  and careateBy != ''"> and careate_by = #{careateBy}</if>
        </where>
    </select>

    <select id="selectExcellentPartyMemberVoList"
            resultType="com.ruoyi.party.domain.vo.ExcellentPartyMemberVo">
        select
        t1.id,
        t1.party_member_id partyMemberId,
        t1.xm,
        t1.phone,
        t1.dzzdm,
        t3.dzzmc dzzName,
        t1.year,
        t1.effective_time_start effectiveTimeStart,
        t1.effective_time_end effectiveTimeEnd,
        t1.title,
        t1.careate_by createBy,
        t2.dyphoto
        from excellent_party_member t1
        left join party_member t2 on t1.party_member_id = t2.id
        left join party_organization t3 on t1.dzzdm = t3.dzzdm
        <where>
            <if test="partyMemberId != null "> and t1.party_member_id = #{partyMemberId}</if>
            <if test="xm != null  and xm != ''"> and t1.xm like concat('%', #{xm}, '%')</if>
            <if test="phone != null  and phone != ''"> and t1.phone = #{phone}</if>
            <if test="dzzdm != null  and dzzdm != ''"> and t1.dzzdm = #{dzzdm}</if>
            <if test="year != null "> and t1.year = #{year}</if>
            <if test="effectiveTimeStart != null "> and t1.effective_time_start = #{effectiveTimeStart}</if>
            <if test="effectiveTimeEnd != null "> and t1.effective_time_end = #{effectiveTimeEnd}</if>
            <if test="title != null  and title != ''"> and t1.title = #{title}</if>
            <if test="careateBy != null  and careateBy != ''"> and t1.careate_by = #{careateBy}</if>
        </where>
        order by effective_time_end desc
    </select>
    
    <select id="selectExcellentPartyMemberById" parameterType="Long" resultMap="ExcellentPartyMemberResult">
        <include refid="selectExcellentPartyMemberVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertExcellentPartyMember" parameterType="com.ruoyi.party.domain.ExcellentPartyMember" useGeneratedKeys="true" keyProperty="id">
        insert into excellent_party_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="partyMemberId != null">party_member_id,</if>
            <if test="xm != null">xm,</if>
            <if test="phone != null">phone,</if>
            <if test="dzzdm != null">dzzdm,</if>
            <if test="year != null">year,</if>
            <if test="effectiveTimeStart != null">effective_time_start,</if>
            <if test="effectiveTimeEnd != null">effective_time_end,</if>
            <if test="title != null">title,</if>
            <if test="careateBy != null">careate_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="partyMemberId != null">#{partyMemberId},</if>
            <if test="xm != null">#{xm},</if>
            <if test="phone != null">#{phone},</if>
            <if test="dzzdm != null">#{dzzdm},</if>
            <if test="year != null">#{year},</if>
            <if test="effectiveTimeStart != null">#{effectiveTimeStart},</if>
            <if test="effectiveTimeEnd != null">#{effectiveTimeEnd},</if>
            <if test="title != null">#{title},</if>
            <if test="careateBy != null">#{careateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateExcellentPartyMember" parameterType="com.ruoyi.party.domain.ExcellentPartyMember">
        update excellent_party_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="partyMemberId != null">party_member_id = #{partyMemberId},</if>
            <if test="xm != null">xm = #{xm},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="dzzdm != null">dzzdm = #{dzzdm},</if>
            <if test="year != null">year = #{year},</if>
            <if test="effectiveTimeStart != null">effective_time_start = #{effectiveTimeStart},</if>
            <if test="effectiveTimeEnd != null">effective_time_end = #{effectiveTimeEnd},</if>
            <if test="title != null">title = #{title},</if>
            <if test="careateBy != null">careate_by = #{careateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteExcellentPartyMemberById" parameterType="Long">
        delete from excellent_party_member where id = #{id}
    </delete>

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

    <select id="selectExcellentPartyMemberCounts" resultType="java.lang.Long">
        select DISTINCT count(id) from excellent_party_member where 1=1
        <if test="year != null">
            and year = #{year}
        </if>
        <if test="beginDate !=null and beginDate != ''">
            and effective_time_start <![CDATA[ <= ]]> #{beginDate} and effective_time_end <![CDATA[ >= ]]> #{beginDate}
        </if>
    </select>
</mapper>