<?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.PartyOrganizationMapper">
    
    <resultMap type="com.ruoyi.party.domain.PartyOrganization" id="PartyOrganizationResult">
        <result property="id"    column="id"    />
        <result property="dzzdm"    column="dzzdm"    />
        <result property="dzzmc"    column="dzzmc"    />
        <result property="dzzsj"    column="dzzsj"    />
        <result property="dzzlxr"    column="dzzlxr"    />
        <result property="dzzlxdh"    column="dzzlxdh"    />
        <result property="zzlb"    column="zzlb"    />
        <result property="sdgx"    column="sdgx"    />
        <result property="sjdzzdm"    column="sjdzzdm"    />
        <result property="txdz"    column="txdz"    />
        <result property="sswg"    column="sswg"    />
        <result property="dw"    column="dw"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
    </resultMap>

    <sql id="selectPartyOrganizationVo">
        select id, dzzdm, dzzmc, dzzsj, dzzlxr, dzzlxdh, zzlb, sdgx, sjdzzdm, txdz, sswg, dw, longitude, latitude from party_organization
    </sql>

    <select id="selectPartyOrganizationList" parameterType="com.ruoyi.party.domain.PartyOrganization" resultMap="PartyOrganizationResult">
        <include refid="selectPartyOrganizationVo"/>
        <where>  
            <if test="dzzdm != null  and dzzdm != ''"> and dzzdm = #{dzzdm}</if>
            <if test="dzzmc != null  and dzzmc != ''"> and dzzmc like CONCAT('%', #{dzzmc}, '%')</if>
            <if test="dzzsj != null  and dzzsj != ''"> and dzzsj = #{dzzsj}</if>
            <if test="dzzlxr != null  and dzzlxr != ''"> and dzzlxr = #{dzzlxr}</if>
            <if test="dzzlxdh != null  and dzzlxdh != ''"> and dzzlxdh = #{dzzlxdh}</if>
            <if test="zzlb != null  and zzlb != ''"> and zzlb = #{zzlb}</if>
            <if test="sdgx != null  and sdgx != ''"> and sdgx = #{sdgx}</if>
            <if test="sjdzzdm != null  and sjdzzdm != ''"> and sjdzzdm = #{sjdzzdm}</if>
            <if test="txdz != null  and txdz != ''"> and txdz = #{txdz}</if>
            <if test="sswg != null  and sswg != ''"> and sswg like concat(#{sswg},'%')</if>
            <if test="dw != null  and dw != ''"> and dw = #{dw}</if>
        </where>
    </select>
    
    <select id="selectPartyOrganizationById" parameterType="String" resultMap="PartyOrganizationResult">
        <include refid="selectPartyOrganizationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPartyOrganization" parameterType="com.ruoyi.party.domain.PartyOrganization">
        insert into party_organization
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="dzzdm != null and dzzdm != ''">dzzdm,</if>
            <if test="dzzmc != null and dzzmc != ''">dzzmc,</if>
            <if test="dzzsj != null and dzzsj != ''">dzzsj,</if>
            <if test="dzzlxr != null and dzzlxr != ''">dzzlxr,</if>
            <if test="dzzlxdh != null and dzzlxdh != ''">dzzlxdh,</if>
            <if test="zzlb != null and zzlb != ''">zzlb,</if>
            <if test="sdgx != null and sdgx != ''">sdgx,</if>
            <if test="sjdzzdm != null">sjdzzdm,</if>
            <if test="txdz != null">txdz,</if>
            <if test="sswg != null">sswg,</if>
            <if test="dw != null">dw,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="dzzdm != null and dzzdm != ''">#{dzzdm},</if>
            <if test="dzzmc != null and dzzmc != ''">#{dzzmc},</if>
            <if test="dzzsj != null and dzzsj != ''">#{dzzsj},</if>
            <if test="dzzlxr != null and dzzlxr != ''">#{dzzlxr},</if>
            <if test="dzzlxdh != null and dzzlxdh != ''">#{dzzlxdh},</if>
            <if test="zzlb != null and zzlb != ''">#{zzlb},</if>
            <if test="sdgx != null and sdgx != ''">#{sdgx},</if>
            <if test="sjdzzdm != null">#{sjdzzdm},</if>
            <if test="txdz != null">#{txdz},</if>
            <if test="sswg != null">#{sswg},</if>
            <if test="dw != null">#{dw},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
         </trim>
    </insert>

    <update id="updatePartyOrganization" parameterType="com.ruoyi.party.domain.PartyOrganization">
        update party_organization
        <trim prefix="SET" suffixOverrides=",">
            <if test="dzzdm != null and dzzdm != ''">dzzdm = #{dzzdm},</if>
            <if test="dzzmc != null and dzzmc != ''">dzzmc = #{dzzmc},</if>
            <if test="dzzsj != null and dzzsj != ''">dzzsj = #{dzzsj},</if>
            <if test="dzzlxr != null and dzzlxr != ''">dzzlxr = #{dzzlxr},</if>
            <if test="dzzlxdh != null and dzzlxdh != ''">dzzlxdh = #{dzzlxdh},</if>
            <if test="zzlb != null and zzlb != ''">zzlb = #{zzlb},</if>
            <if test="sdgx != null and sdgx != ''">sdgx = #{sdgx},</if>
            <if test="sjdzzdm != null">sjdzzdm = #{sjdzzdm},</if>
            <if test="txdz != null">txdz = #{txdz},</if>
            <if test="sswg != null">sswg = #{sswg},</if>
            <if test="dw != null">dw = #{dw},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePartyOrganizationById" parameterType="String">
        delete from party_organization where id = #{id}
    </delete>

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

    <select id="countOrg" resultType="int">
        select  count(*) from  party_organization
    </select>

    <!--党组织构成情况-->
    <select id="getPartyOrgBuild" resultType="java.util.HashMap">
        select count(porg.id) value,zzlb from party_organization porg
        group by porg.zzlb
    </select>

    <select id="getByDzzdm" resultType="com.ruoyi.party.domain.PartyOrganization">
        select * from party_organization where dzzdm = #{dzzdm}
    </select>

    <select id="getByDzzmc" resultType="com.ruoyi.party.domain.PartyOrganization">
        select * from party_organization where dzzmc = #{dzzmc}
    </select>
</mapper>