<?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.PartyMemberMapper">
    
    <resultMap type="com.ruoyi.party.domain.PartyMember" id="PartyMemberResult">
        <result property="id"    column="id"    />
        <result property="xm"    column="xm"    />
        <result property="xb"    column="xb"    />
        <result property="sfzh"    column="sfzh"    />
        <result property="csrq"    column="csrq"    />
        <result property="mz"    column="mz"    />
        <result property="jg"    column="jg"    />
        <result property="xl"    column="xl"    />
        <result property="rdrq"    column="rdrq"    />
        <result property="zzrq"    column="zzrq"    />
        <result property="rylb"    column="rylb"    />
        <result property="lxdh"    column="lxdh"    />
        <result property="dzzmc"    column="dzzmc"    />
        <result property="dyphoto"    column="dyphoto"    />
        <result property="rksj"    column="rksj"    />
        <result property="wgCode"    column="wg_code"    />
    </resultMap>

    <sql id="selectPartyMemberVo">
        select id, xm, xb, sfzh, csrq, mz, jg, xl, rdrq, zzrq, rylb, lxdh, dzzmc, dyphoto, rksj, wg_code from party_member
    </sql>

    <select id="selectPartyMemberList" parameterType="com.ruoyi.party.domain.PartyMember" resultMap="PartyMemberResult">
        <include refid="selectPartyMemberVo"/>
        <where>  
            <if test="xm != null  and xm != ''"> and xm like concat('%',#{xm},'%')</if>
            <if test="xb != null  and xb != ''"> and xb = #{xb}</if>
            <if test="sfzh != null  and sfzh != ''"> and sfzh = #{sfzh}</if>
            <if test="csrq != null  and csrq != ''"> and csrq = #{csrq}</if>
            <if test="mz != null  and mz != ''"> and mz = #{mz}</if>
            <if test="jg != null  and jg != ''"> and jg = #{jg}</if>
            <if test="xl != null  and xl != ''"> and xl = #{xl}</if>
            <if test="rdrq != null "> and rdrq = #{rdrq}</if>
            <if test="zzrq != null "> and zzrq = #{zzrq}</if>
            <if test="rylb != null  and rylb != ''"> and rylb = #{rylb}</if>
            <if test="lxdh != null  and lxdh != ''"> and lxdh = #{lxdh}</if>
            <if test="dzzmc != null  and dzzmc != ''"> and dzzmc = #{dzzmc}</if>
            <if test="dyphoto != null  and dyphoto != ''"> and dyphoto = #{dyphoto}</if>
            <if test="rksj != null "> and rksj = #{rksj}</if>
            <if test="wgCode != null "> and wg_code = #{wgCode}</if>
        </where>
    </select>
    
    <select id="selectPartyMemberById" parameterType="Long" resultMap="PartyMemberResult">
        <include refid="selectPartyMemberVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPartyMember" parameterType="com.ruoyi.party.domain.PartyMember">
        insert into party_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xm != null">xm,</if>
            <if test="xb != null">xb,</if>
            <if test="sfzh != null">sfzh,</if>
            <if test="csrq != null">csrq,</if>
            <if test="mz != null">mz,</if>
            <if test="jg != null">jg,</if>
            <if test="xl != null">xl,</if>
            <if test="rdrq != null">rdrq,</if>
            <if test="zzrq != null">zzrq,</if>
            <if test="rylb != null">rylb,</if>
            <if test="lxdh != null">lxdh,</if>
            <if test="dzzmc != null">dzzmc,</if>
            <if test="dyphoto != null">dyphoto,</if>
            <if test="rksj != null">rksj,</if>
            <if test="wgCode != null">wg_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xm != null">#{xm},</if>
            <if test="xb != null">#{xb},</if>
            <if test="sfzh != null">#{sfzh},</if>
            <if test="csrq != null">#{csrq},</if>
            <if test="mz != null">#{mz},</if>
            <if test="jg != null">#{jg},</if>
            <if test="xl != null">#{xl},</if>
            <if test="rdrq != null">#{rdrq},</if>
            <if test="zzrq != null">#{zzrq},</if>
            <if test="rylb != null">#{rylb},</if>
            <if test="lxdh != null">#{lxdh},</if>
            <if test="dzzmc != null">#{dzzmc},</if>
            <if test="dyphoto != null">#{dyphoto},</if>
            <if test="rksj != null">#{rksj},</if>
            <if test="wgCode != null">#{wgCode},</if>
         </trim>
    </insert>

    <update id="updatePartyMember" parameterType="com.ruoyi.party.domain.PartyMember">
        update party_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="xm != null">xm = #{xm},</if>
            <if test="xb != null">xb = #{xb},</if>
            <if test="sfzh != null">sfzh = #{sfzh},</if>
            <if test="csrq != null">csrq = #{csrq},</if>
            <if test="mz != null">mz = #{mz},</if>
            <if test="jg != null">jg = #{jg},</if>
            <if test="xl != null">xl = #{xl},</if>
            <if test="rdrq != null">rdrq = #{rdrq},</if>
            <if test="zzrq != null">zzrq = #{zzrq},</if>
            <if test="rylb != null">rylb = #{rylb},</if>
            <if test="lxdh != null">lxdh = #{lxdh},</if>
            <if test="dzzmc != null">dzzmc = #{dzzmc},</if>
            <if test="dyphoto != null">dyphoto = #{dyphoto},</if>
            <if test="rksj != null">rksj = #{rksj},</if>
            <if test="wgCode != null">wg_code = #{wgCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePartyMemberById" parameterType="Long">
        delete from party_member where id = #{id}
    </delete>

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


    <select id="getPartyCount" resultType="java.lang.Integer">
        select count(id) from party_member
    </select>

    <!--学历分布-->
    <select id="getXLFB"  resultType="java.util.HashMap">
        select xl, count(id) counts
        from party_member pm where xl is not null
        <if test="orgId != null and orgId != ''">
            and dzzmc = #{orgId}
        </if>
        GROUP BY xl
    </select>

    <!--获取党龄-->
    <select id="getDl"  resultType="java.util.HashMap">
        select TIMESTAMPDIFF(YEAR, up.zzrq, CURDATE()) dyear,up.xb
        from party_member up where zzrq is not null
        <if test="orgId != null and orgId != ''">
            and dzzmc = #{orgId}
        </if>
        and zzrq != ''
    </select>
    <select id="getAgeList" resultType="java.lang.String">
        select TIMESTAMPDIFF(YEAR, up.csrq, CURDATE()) + 1 dyear
        from party_member up where csrq is not null and csrq != ''
    </select>

</mapper>