<?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.BzscYsjglggzscMapper">

    <resultMap type="BzscYsjglggzsc" id="BzscYsjglggzscResult">
        <result property="ID"    column="ID"    />
        <result property="deptId"    column="dept_id"    />
        <result property="bt"    column="bt"    />
        <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"    />
    </resultMap>

    <resultMap id="BzscYsjglggzscBzscYsjglggzscZbResult" type="BzscYsjglggzsc" extends="BzscYsjglggzscResult">
        <collection property="bzscYsjglggzscZbList" notNullColumn="sub_ID" javaType="java.util.List" resultMap="BzscYsjglggzscZbResult" />
    </resultMap>

    <resultMap type="BzscYsjglggzscZb" id="BzscYsjglggzscZbResult">
        <result property="ID"    column="sub_ID"    />
        <result property="zbId"    column="sub_zb_id"    />
        <result property="deptId"    column="sub_dept_id"    />
        <result property="bt"    column="sub_bt"    />
        <result property="nd"    column="sub_nd"    />
        <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="selectBzscYsjglggzscVo">
        select ID, dept_id, bt, nd, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5 from bzsc_ysjglggzsc
    </sql>

    <select id="selectBzscYsjglggzscList" parameterType="BzscYsjglggzsc" resultMap="BzscYsjglggzscResult">
        <include refid="selectBzscYsjglggzscVo"/>
        <where>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="bt != null  and bt != ''"> and bt = #{bt}</if>
            <if test="nd != null  and nd != ''"> and nd = #{nd}</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="selectBzscYsjglggzscByID" parameterType="Long" resultMap="BzscYsjglggzscBzscYsjglggzscZbResult">
        select a.ID, a.dept_id, a.bt, 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,
 b.ID as sub_ID, b.zb_id as sub_zb_id, b.dept_id as sub_dept_id, b.bt as sub_bt, b.nd as sub_nd,px as sub_px, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time, b.remark as sub_remark, b.yl1 as sub_yl1, b.yl2 as sub_yl2, b.yl3 as sub_yl3, b.yl4 as sub_yl4, b.yl5 as sub_yl5
        from bzsc_ysjglggzsc a
        left join bzsc_ysjglggzsc_zb b on b.zb_id = a.ID
        where a.ID = #{ID}
    </select>

    <insert id="insertBzscYsjglggzsc" parameterType="BzscYsjglggzsc" useGeneratedKeys="true" keyProperty="ID">
        insert into bzsc_ysjglggzsc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="bt != null">bt,</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="bt != null">#{bt},</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="updateBzscYsjglggzsc" parameterType="BzscYsjglggzsc">
        update bzsc_ysjglggzsc
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="bt != null">bt = #{bt},</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="deleteBzscYsjglggzscByID" parameterType="Long">
        delete from bzsc_ysjglggzsc where ID = #{ID}
    </delete>

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

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

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

    <insert id="batchBzscYsjglggzscZb">
        insert into bzsc_ysjglggzsc_zb( ID, zb_id, dept_id, bt, nd, 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.bt}, #{item.nd},#{item.px}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}, #{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5})
        </foreach>
    </insert>
</mapper>
