<?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.qianhe.zqbf.mapper.ZqbfXmzBfxmMapper">
    <!--  返回实体  -->
    <resultMap id="ZqbfXmzBfxmResult" type="ZqbfXmzBfxmVo">
        <result property="xmid" column="xmid"/>
        <result property="parent_id" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="xmmc" column="xmmc"/>
        <result property="xmzb" column="xmzb"/>
        <result property="xmlx" column="xmlx"/>
        <result property="order_num" column="order_num"/>
        <result property="level_1_org_name" column="level_1_org_name"/>
        <result property="level_2_org_name" column="level_2_org_name"/>
        <result property="level_3_org_name" column="level_3_org_name"/>
        <result property="level_4_org_name" column="level_4_org_name"/>
        <result property="level_5_org_name" column="level_5_org_name"/>
        <result property="cjr" column="cjr"/>
        <result property="cjsj" column="cjsj"/>
        <result property="gxr" column="gxr"/>
        <result property="gxsj" column="gxsj"/>
        <result property="bz" column="bz"/>
        <result property="yl1" column="yl1"/>
        <result property="yl2" column="yl2"/>
        <result property="yl3" column="yl3"/>
        <result property="yl4" column="yl4"/>
        <result property="yl5" column="yl5"/>
    </resultMap>
    <!--  通用查询  -->
    <sql id="selectCommon">
        SELECT xmid, parent_id, ancestors, xmmc, xmzb, xmlx, order_num, level_1_org_name, level_2_org_name, level_3_org_name, level_4_org_name, level_5_org_name, cjr, cjsj, gxr, gxsj, bz, yl1, yl2, yl3, yl4, yl5 from zqbf_xmz_bfxm
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="ZqbfXmzBfxmQuery" resultMap="ZqbfXmzBfxmResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="xmmc != null  and xmmc !='' ">AND xmmc like concat('%', #{xmmc}, '%')</if>
            <if test="xmzb != null  and xmzb !='' ">AND xmzb =#{xmzb}</if>
        </where>
        ORDER BY xmzb, gxsj DESC
    </select>
    <!--  查询详情  -->
    <select id="info" parameterType="long" resultMap="ZqbfXmzBfxmResult">
        <include refid="selectCommon"></include> WHERE xmid = #{id}
    </select>
    <!--  新增  -->
    <insert id="add" parameterType="ZqbfXmzBfxm">
        INSERT INTO zqbf_xmz_bfxm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parent_id != null">parent_id,</if>
            <if test="ancestors != null and ancestors != ''">ancestors,</if>
            <if test="xmmc != null and xmmc != ''">xmmc,</if>
            <if test="xmzb != null and xmzb != ''">xmzb,</if>
            <if test="xmlx != null and xmlx != ''">xmlx,</if>
            <if test="order_num != null">order_num,</if>
            <if test="level_1_org_name != null and level_1_org_name != ''">level_1_org_name,</if>
            <if test="level_2_org_name != null and level_2_org_name != ''">level_2_org_name,</if>
            <if test="level_3_org_name != null and level_3_org_name != ''">level_3_org_name,</if>
            <if test="level_4_org_name != null and level_4_org_name != ''">level_4_org_name,</if>
            <if test="level_5_org_name != null and level_5_org_name != ''">level_5_org_name,</if>
            <if test="cjr != null and cjr != ''">cjr,</if>
            <if test="cjsj != null">cjsj,</if>
            <if test="gxr != null and gxr != ''">gxr,</if>
            <if test="bz != null and bz != ''">bz,</if>
            <if test="yl1 != null and yl1 != ''">yl1,</if>
            <if test="yl2 != null and yl2 != ''">yl2,</if>
            <if test="yl3 != null and yl3 != ''">yl3,</if>
            <if test="yl4 != null and yl4 != ''">yl4,</if>
            <if test="yl5 != null and yl5 != ''">yl5,</if>
            gxsj
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parent_id != null">#{parent_id},</if>
            <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
            <if test="xmmc != null and xmmc != ''">#{xmmc},</if>
            <if test="xmzb != null and xmzb != ''">#{xmzb},</if>
            <if test="xmlx != null and xmlx != ''">#{xmlx},</if>
            <if test="order_num != null">#{order_num},</if>
            <if test="level_1_org_name != null and level_1_org_name != ''">#{level_1_org_name},</if>
            <if test="level_2_org_name != null and level_2_org_name != ''">#{level_2_org_name},</if>
            <if test="level_3_org_name != null and level_3_org_name != ''">#{level_3_org_name},</if>
            <if test="level_4_org_name != null and level_4_org_name != ''">#{level_4_org_name},</if>
            <if test="level_5_org_name != null and level_5_org_name != ''">#{level_5_org_name},</if>
            <if test="cjr != null and cjr != ''">#{cjr},</if>
            <if test="cjsj != null">#{cjsj},</if>
            <if test="gxr != null and gxr != ''">#{gxr},</if>
            <if test="bz != null and bz != ''">#{bz},</if>
            <if test="yl1 != null and yl1 != ''">#{yl1},</if>
            <if test="yl2 != null and yl2 != ''">#{yl2},</if>
            <if test="yl3 != null and yl3 != ''">#{yl3},</if>
            <if test="yl4 != null and yl4 != ''">#{yl4},</if>
            <if test="yl5 != null and yl5 != ''">#{yl5},</if>
            now()
        </trim>
    </insert>
    <!--  修改  -->
    <update id="edit" parameterType="ZqbfXmzBfxm">
        UPDATE zqbf_xmz_bfxm
        <trim prefix="SET" suffixOverrides=",">
            <if test="parent_id != null">parent_id = #{parent_id},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="xmmc != null and xmmc != ''">xmmc = #{xmmc},</if>
            <if test="xmzb != null and xmzb != ''">xmzb = #{xmzb},</if>
            <if test="xmlx != null and xmlx != ''">xmlx = #{xmlx},</if>
            <if test="order_num != null">order_num = #{order_num},</if>
            <if test="level_1_org_name != null and level_1_org_name != ''">level_1_org_name = #{level_1_org_name},</if>
            <if test="level_2_org_name != null and level_2_org_name != ''">level_2_org_name = #{level_2_org_name},</if>
            <if test="level_3_org_name != null and level_3_org_name != ''">level_3_org_name = #{level_3_org_name},</if>
            <if test="level_4_org_name != null and level_4_org_name != ''">level_4_org_name = #{level_4_org_name},</if>
            <if test="level_5_org_name != null and level_5_org_name != ''">level_5_org_name = #{level_5_org_name},</if>
            <if test="cjr != null and cjr != ''">cjr = #{cjr},</if>
            <if test="cjsj != null">cjsj = #{cjsj},</if>
            <if test="gxr != null and gxr != ''">gxr = #{gxr},</if>
            <if test="bz != null">bz = #{bz},</if>
            <if test="yl1 != null">yl1 = #{yl1},</if>
            <if test="yl2 != null">yl2 = #{yl2},</if>
            <if test="yl3 != null">yl3 = #{yl3},</if>
            <if test="yl4 != null">yl4 = #{yl4},</if>
            <if test="yl5 != null">yl5 = #{yl5},</if>
            gxsj = now()
        </trim>
        WHERE xmid = #{xmid}
    </update>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqbf_xmz_bfxm WHERE BBM IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>