<?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.mapper.BzscZczscZbMapper">
    
    <resultMap type="BzscZczscZb" id="BzscZczscZbResult">
        <result property="ID"    column="ID"    />
        <result property="deptId"    column="dept_id"    />
        <result property="nd"    column="nd"    />
        <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"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <resultMap id="BzscZczscZbBzscZczscCbResult" type="BzscZczscZb" extends="BzscZczscZbResult">
        <collection property="bzscZczscCbList" notNullColumn="sub_ID" javaType="java.util.List" resultMap="BzscZczscCbResult" />
    </resultMap>

    <resultMap type="BzscZczscCb" id="BzscZczscCbResult">
        <result property="ID"    column="sub_ID"    />
        <result property="zbId"    column="sub_zb_id"    />
        <result property="deptId"    column="sub_dept_id"    />
        <result property="nd"    column="sub_nd"    />
        <result property="parentId"    column="sub_parent_id"    />
        <result property="mc"    column="sub_mc"    />
        <result property="ms"    column="sub_ms"    />
        <result property="nr"    column="sub_nr"    />
        <result property="px"    column="sub_px"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
        <result property="remark"    column="sub_remark"    />
        <result property="yl1"    column="sub_yl1"    />
        <result property="yl2"    column="sub_yl2"    />
        <result property="yl3"    column="sub_yl3"    />
        <result property="yl4"    column="sub_yl4"    />
        <result property="yl5"    column="sub_yl5"    />
    </resultMap>

    <sql id="selectBzscZczscZbVo">
        select  a.ID, a.dept_id, a.nd, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, a.yl1, a.yl2, a.yl3, a.yl4, a.yl5,d.dept_name from bzsc_zczsc_zb  a
                        left join sys_dept d on a.dept_id=d.dept_id
    </sql>

    <select id="selectBzscZczscZbList" parameterType="BzscZczscZb" resultMap="BzscZczscZbResult">
        <include refid="selectBzscZczscZbVo"/>
        <where>
            <if test="deptId != null "> and (a.dept_id = #{deptId} or  find_in_set(#{deptId},d.ancestors))</if>
            <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
            <if test="yl1 != null "> and a.yl1 like concat('%', #{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>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
    </select>
    
    <select id="selectBzscZczscZbByID" parameterType="Long" resultMap="BzscZczscZbResult">

        select a.ID, a.dept_id, a.nd, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, a.yl1, a.yl2, a.yl3, a.yl4, a.yl5        from bzsc_zczsc_zb a

        where a.ID = #{ID}

    </select>
    <select id="selectBzscZczscCbByID" resultType="com.qianhe.domain.BzscZczscCb">
        select *from bzsc_zczsc_cb where zb_id=#{ID}  order by px

    </select>

    <insert id="insertBzscZczscZb" parameterType="BzscZczscZb" useGeneratedKeys="true" keyProperty="ID">
        insert into bzsc_zczsc_zb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="nd != null">nd,</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="deptId != null">#{deptId},</if>
            <if test="nd != null">#{nd},</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="updateBzscZczscZb" parameterType="BzscZczscZb">
        update bzsc_zczsc_zb
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="nd != null">nd = #{nd},</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="deleteBzscZczscZbByID" parameterType="Long">
        delete from bzsc_zczsc_zb where ID = #{ID}
    </delete>

    <delete id="deleteBzscZczscZbByIDs" parameterType="String">
        delete from bzsc_zczsc_zb where ID in 
        <foreach item="ID" collection="array" open="(" separator="," close=")">
            #{ID}
        </foreach>
    </delete>
    
    <delete id="deleteBzscZczscCbByZbIds" parameterType="String">
        delete from bzsc_zczsc_cb where zb_id in 
        <foreach item="zbId" collection="array" open="(" separator="," close=")">
            #{zbId}
        </foreach>
    </delete>

    <delete id="deleteBzscZczscCbByZbId" parameterType="Long">
        delete from bzsc_zczsc_cb where zb_id = #{zbId}
    </delete>

    <insert id="batchBzscZczscCb">
        insert into bzsc_zczsc_cb( ID, zb_id, dept_id, nd, parent_id, mc, ms, nr, px, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.ID}, #{item.zbId}, #{item.deptId}, #{item.nd}, #{item.parentId}, #{item.mc}, #{item.ms}, #{item.nr}, #{item.px}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}, #{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5})
        </foreach>
    </insert>
    <insert id="insertBzscZczscCb" parameterType="BzscZczscCb" useGeneratedKeys="true" keyProperty="ID">
        insert into bzsc_zczsc_cb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="zbId != null">zb_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="nd != null">nd,</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="deptId != null">#{deptId},</if>
            <if test="nd != null">#{nd},</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>
</mapper>