<?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.SjZdbfFjxbzMapper">
    
    <resultMap type="SjZdbfFjxbz" id="SjZdbfFjxbzResult">
        <result property="id"    column="id"    />
        <result property="nd"    column="nd"    />
        <result property="flmc"    column="flmc"    />
        <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>

    <resultMap id="SjZdbfFjxbzSjZdbfFjxbzCbResult" type="SjZdbfFjxbz" extends="SjZdbfFjxbzResult">
        <collection property="sjZdbfFjxbzCbList" notNullColumn="id" javaType="java.util.List" resultMap="SjZdbfFjxbzCbResult" />
    </resultMap>

    <resultMap type="SjZdbfFjxbzCb" id="SjZdbfFjxbzCbResult">
        <result property="id"    column="id"    />
        <result property="zbId"    column="zb_id"    />
        <result property="nd"    column="nd"    />
        <result property="flmc"    column="flmc"    />
        <result property="pjbz"    column="pjbz"    />
        <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="selectSjZdbfFjxbzVo">
        select id, nd, flmc, px, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5 from sj_zdbf_fjxbz
    </sql>

    <select id="selectSjZdbfFjxbzList" parameterType="SjZdbfFjxbz" resultMap="SjZdbfFjxbzResult">
        <include refid="selectSjZdbfFjxbzVo"/>
        <where>  
            <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
            <if test="flmc != null  and flmc != ''"> and flmc = #{flmc}</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="selectSjZdbfFjxbzById" parameterType="Long" resultMap="SjZdbfFjxbzResult">
        select a.id, a.nd, a.flmc, a.px, 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 sj_zdbf_fjxbz a

        where a.id = #{id}
    </select>
    <select id="selectSjZdbfFjxbzCxList" resultType="com.qianhe.domain.SjZdbfFjxbz">
        select a.id, a.nd,a.flmc,a.px,b.pjbz,b.px
        from sj_zdbf_fjxbz a
                 left join sj_zdbf_fjxbz_cb b on a.id = b.zb_id
        where 1=1
        <if test="nd != null  and nd != ''"> and a.nd = #{nd}</if>
        <if test="flmc != null  and flmc != ''"> and a.flmc = #{flmc}</if>
        order by a.px,b.px

    </select>
    <select id="selectSjZdbfFjxbzCbById" resultType="com.qianhe.domain.SjZdbfFjxbzCb">
        select *from sj_zdbf_fjxbz_cb where zb_id=#{id}
    </select>
    <select id="getFlmcList" resultType="java.lang.String">
        select distinct flmc from sj_zdbf_fjxbz_cb where nd=#{nd}
    </select>
    <select id="getPjbzList" resultType="com.qianhe.domain.SjZdbfFjxbzCb">
        select id,pjbz from sj_zdbf_fjxbz_cb where nd=#{nd} and flmc=#{flmc}
    </select>
    <select id="selectSjZdbfFjxbzCb" resultType="com.qianhe.domain.SjZdbfFjxbzCb">
        select * from sj_zdbf_fjxbz_cb where nd=#{nd} and flmc=#{flmc} and px=#{px}
    </select>
    <select id="selectSjZdbfFjxbzCxBzList" resultType="com.qianhe.domain.SjZdbfFjxbzCb">
        select b.id,a.flmc,b.pjbz
        from sj_zdbf_fjxbz a
                 left join sj_zdbf_fjxbz_cb b on a.id = b.zb_id
        where 1=1
          and   a.nd = #{nd}
        order by a.px,b.px
    </select>

    <insert id="insertSjZdbfFjxbz" parameterType="SjZdbfFjxbz" useGeneratedKeys="true" keyProperty="id">
        insert into sj_zdbf_fjxbz
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nd != null">nd,</if>
            <if test="flmc != null">flmc,</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="nd != null">#{nd},</if>
            <if test="flmc != null">#{flmc},</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="updateSjZdbfFjxbz" parameterType="SjZdbfFjxbz">
        update sj_zdbf_fjxbz
        <trim prefix="SET" suffixOverrides=",">
            <if test="nd != null">nd = #{nd},</if>
            <if test="flmc != null">flmc = #{flmc},</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="deleteSjZdbfFjxbzById" parameterType="Long">
        delete from sj_zdbf_fjxbz where id = #{id}
    </delete>

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

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

    <insert id="batchSjZdbfFjxbzCb">
        insert into sj_zdbf_fjxbz_cb( id, zb_id, nd, flmc, pjbz, px,   remark, yl1, yl2, yl3, yl4, yl5) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.zbId}, #{item.nd}, #{item.flmc}, #{item.pjbz}, #{item.px},   #{item.remark}, #{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5})
        </foreach>
    </insert>
</mapper>