<?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.bzsc.mapper.BzscCyglqglscMbcbMapper">
    
    <resultMap type="BzscCyglqglscMbcb" id="BzscCyglqglscMbcbResult">
        <result property="ID"    column="ID"    />
        <result property="zbId"    column="zb_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="mc"    column="mc"    />
        <result property="ms"    column="ms"    />
        <result property="nr"    column="nr"    />
        <result property="px"    column="px"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <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="selectBzscCyglqglscMbcbVo">
        select ID, zb_id,  parent_id, mc, ms, nr, px, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5 from bzsc_cyglqglsc_mbcb
    </sql>

    <select id="selectBzscCyglqglscMbcbList" parameterType="BzscCyglqglscMbcb" resultMap="BzscCyglqglscMbcbResult">
        <include refid="selectBzscCyglqglscMbcbVo"/>
        <where>  
            <if test="zbId != null "> and zb_id = #{zbId}</if>

            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="mc != null  and mc != ''"> and mc = #{mc}</if>
            <if test="ms != null  and ms != ''"> and ms = #{ms}</if>
            <if test="nr != null  and nr != ''"> and nr = #{nr}</if>
            <if test="px != null "> and px = #{px}</if>
            <if test="yl1 != null  and yl1 != ''"> and yl1 = #{yl1}</if>
            <if test="yl2 != null  and yl2 != ''"> and yl2 = #{yl2}</if>
            <if test="yl3 != null  and yl3 != ''"> and yl3 = #{yl3}</if>
            <if test="yl4 != null  and yl4 != ''"> and yl4 = #{yl4}</if>
            <if test="yl5 != null  and yl5 != ''"> and yl5 = #{yl5}</if>
        </where>
    </select>

    <select id="selectBzscCyglqglscMbcbList_ByZbid" parameterType="BzscCyglqglscMbcb" resultMap="BzscCyglqglscMbcbResult">
        <include refid="selectBzscCyglqglscMbcbVo"/>
        <where>
            <if test="zbId != null "> and zb_id = #{zbId}</if>
        </where>
        order by px
    </select>
    
    <select id="selectBzscCyglqglscMbcbByID" parameterType="Long" resultMap="BzscCyglqglscMbcbResult">
        <include refid="selectBzscCyglqglscMbcbVo"/>
        where ID = #{ID}
    </select>
        
    <insert id="insertBzscCyglqglscMbcb" parameterType="BzscCyglqglscMbcb" useGeneratedKeys="true" keyProperty="ID">
        insert into bzsc_cyglqglsc_mbcb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="zbId != null">zb_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="mc != null">mc,</if>
            <if test="ms != null">ms,</if>
            <if test="nr != null">nr,</if>
            <if test="px != null">px,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="yl1 != null">yl1,</if>
            <if test="yl2 != null">yl2,</if>
            <if test="yl3 != null">yl3,</if>
            <if test="yl4 != null">yl4,</if>
            <if test="yl5 != null">yl5,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="zbId != null">#{zbId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="mc != null">#{mc},</if>
            <if test="ms != null">#{ms},</if>
            <if test="nr != null">#{nr},</if>
            <if test="px != null">#{px},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="yl1 != null">#{yl1},</if>
            <if test="yl2 != null">#{yl2},</if>
            <if test="yl3 != null">#{yl3},</if>
            <if test="yl4 != null">#{yl4},</if>
            <if test="yl5 != null">#{yl5},</if>
         </trim>
    </insert>

    <update id="updateBzscCyglqglscMbcb" parameterType="BzscCyglqglscMbcb">
        update bzsc_cyglqglsc_mbcb
        <trim prefix="SET" suffixOverrides=",">
            <if test="zbId != null">zb_id = #{zbId},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="mc != null">mc = #{mc},</if>
            <if test="ms != null">ms = #{ms},</if>
            <if test="nr != null">nr = #{nr},</if>
            <if test="px != null">px = #{px},</if>
            <if test="createBy != null">create_by = #{createBy},</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>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where ID = #{ID}
    </update>

    <delete id="deleteBzscCyglqglscMbcbByID" parameterType="Long">
        delete from bzsc_cyglqglsc_mbcb where ID = #{ID}
    </delete>

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

    <select id="hasChildByID" resultType="Integer">
	    select count(1) from bzsc_cyglqglsc_mbcb where parent_id = #{ID}
	</select>
</mapper>