<?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.ExcellentPartyMapper">
    
    <resultMap type="com.ruoyi.party.domain.ExcellentParty" id="ExcellentPartyResult">
        <result property="id"    column="id"    />
        <result property="partyId"    column="party_id"    />
        <result property="dzzmc"    column="dzzmc"    />
        <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="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="byzd1"    column="byzd1"    />
        <result property="byzd2"    column="byzd2"    />
        <result property="byzd3"    column="byzd3"    />
        <result property="byzd4"    column="byzd4"    />
        <result property="byzd5"    column="byzd5"    />
    </resultMap>

    <sql id="selectExcellentPartyVo">
        select id, party_id, dzzmc, year, effective_time_start, effective_time_end, title, create_user, create_time, update_user, update_time, byzd1, byzd2, byzd3, byzd4, byzd5 from excellent_party
    </sql>

    <select id="selectExcellentPartyList" parameterType="com.ruoyi.party.domain.ExcellentParty" resultMap="ExcellentPartyResult">
        <include refid="selectExcellentPartyVo"/>
        <where>  
            <if test="partyId != null  and partyId != ''"> and party_id = #{partyId}</if>
            <if test="dzzmc != null  and dzzmc != ''"> and dzzmc like concat('%',#{dzzmc},'%')</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="createUser != null  and createUser != ''"> and create_user = #{createUser}</if>
            <if test="updateUser != null  and updateUser != ''"> and update_user = #{updateUser}</if>
            <if test="byzd1 != null  and byzd1 != ''"> and byzd1 = #{byzd1}</if>
            <if test="byzd2 != null  and byzd2 != ''"> and byzd2 = #{byzd2}</if>
            <if test="byzd3 != null  and byzd3 != ''"> and byzd3 = #{byzd3}</if>
            <if test="byzd4 != null  and byzd4 != ''"> and byzd4 = #{byzd4}</if>
            <if test="byzd5 != null  and byzd5 != ''"> and byzd5 = #{byzd5}</if>
        </where>
    </select>
    
    <select id="selectExcellentPartyById" parameterType="String" resultMap="ExcellentPartyResult">
        <include refid="selectExcellentPartyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertExcellentParty" parameterType="com.ruoyi.party.domain.ExcellentParty">
        insert into excellent_party
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="partyId != null">party_id,</if>
            <if test="dzzmc != null">dzzmc,</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="createUser != null">create_user,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUser != null">update_user,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="byzd1 != null">byzd1,</if>
            <if test="byzd2 != null">byzd2,</if>
            <if test="byzd3 != null">byzd3,</if>
            <if test="byzd4 != null">byzd4,</if>
            <if test="byzd5 != null">byzd5,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="partyId != null">#{partyId},</if>
            <if test="dzzmc != null">#{dzzmc},</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="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="byzd1 != null">#{byzd1},</if>
            <if test="byzd2 != null">#{byzd2},</if>
            <if test="byzd3 != null">#{byzd3},</if>
            <if test="byzd4 != null">#{byzd4},</if>
            <if test="byzd5 != null">#{byzd5},</if>
         </trim>
    </insert>

    <update id="updateExcellentParty" parameterType="com.ruoyi.party.domain.ExcellentParty">
        update excellent_party
        <trim prefix="SET" suffixOverrides=",">
            <if test="partyId != null">party_id = #{partyId},</if>
            <if test="dzzmc != null">dzzmc = #{dzzmc},</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="createUser != null">create_user = #{createUser},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUser != null">update_user = #{updateUser},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="byzd1 != null">byzd1 = #{byzd1},</if>
            <if test="byzd2 != null">byzd2 = #{byzd2},</if>
            <if test="byzd3 != null">byzd3 = #{byzd3},</if>
            <if test="byzd4 != null">byzd4 = #{byzd4},</if>
            <if test="byzd5 != null">byzd5 = #{byzd5},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteExcellentPartyById" parameterType="String">
        delete from excellent_party where id = #{id}
    </delete>

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


    <!--获取优秀党组织总数-->
    <select id="getGoodPartyOrgCounts" resultType="java.lang.String">
        select DISTINCT count(party_id) from excellent_party where 1=1
        <if test="year !=null and year != ''">
            and year=#{year}
        </if>
        <if test="beginDate !=null and beginDate != ''">
            and Start_date <![CDATA[ <= ]]> #{beginDate} and End_date <![CDATA[ >= ]]> #{beginDate}
        </if>
    </select>


</mapper>