<?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.SjGfjsKhwtMapper">
    
    <resultMap type="SjGfjsKhwt" id="SjGfjsKhwtResult">
        <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="SjGfjsKhwtSjGfjsKhwtCbResult" type="SjGfjsKhwt" extends="SjGfjsKhwtResult">
        <collection property="sjGfjsKhwtCbList" notNullColumn="id" javaType="java.util.List" resultMap="SjGfjsKhwtCbResult" />
    </resultMap>

    <resultMap type="SjGfjsKhwtCb" id="SjGfjsKhwtCbResult">
        <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="selectSjGfjsKhwtVo">
        select id, nd, flmc, px, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5 from sj_gfjs_khwt
    </sql>

    <select id="selectSjGfjsKhwtList" parameterType="SjGfjsKhwt" resultMap="SjGfjsKhwtResult">
        <include refid="selectSjGfjsKhwtVo"/>
        <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="selectSjGfjsKhwtById" parameterType="Long" resultMap="SjGfjsKhwtResult">
        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_gfjs_khwt a

        where a.id = #{id}
    </select>
    <select id="selectSjGfjsKhwtCxList" resultType="com.qianhe.domain.SjGfjsKhwt">
        select a.id, a.nd,a.flmc,a.px,b.pjbz,b.px
        from sj_gfjs_khwt a
                 left join sj_gfjs_khwt_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="selectSjGfjsKhwtCbById" resultType="com.qianhe.domain.SjGfjsKhwtCb">
        select *from sj_gfjs_khwt_cb where zb_id=#{id}
    </select>
    <select id="getFlmcList" resultType="java.lang.String">
        select distinct flmc from sj_gfjs_khwt_cb where nd=#{nd}
    </select>
    <select id="getPjbzList" resultType="com.qianhe.domain.SjGfjsKhwtCb">
        select id,pjbz from sj_gfjs_khwt_cb where nd=#{nd} and flmc=#{flmc}
    </select>
    <select id="selectSjGfjsKhwtCb" resultType="com.qianhe.domain.SjGfjsKhwtCb">
        select * from sj_gfjs_khwt_cb where nd=#{nd} and flmc=#{flmc} and px=#{px}
    </select>
    <select id="selectSjGfjsKhwtCxBzList" resultType="com.qianhe.domain.SjGfjsKhwtCb">
        select b.id,a.flmc,b.pjbz
        from sj_gfjs_khwt a
                 left join sj_gfjs_khwt_cb b on a.id = b.zb_id
        where 1=1
          and   a.nd = #{nd}
        order by a.px,b.px
    </select>

    <insert id="insertSjGfjsKhwt" parameterType="SjGfjsKhwt" useGeneratedKeys="true" keyProperty="id">
        insert into sj_gfjs_khwt
        <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="updateSjGfjsKhwt" parameterType="SjGfjsKhwt">
        update sj_gfjs_khwt
        <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="deleteSjGfjsKhwtById" parameterType="Long">
        delete from sj_gfjs_khwt where id = #{id}
    </delete>

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

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

    <insert id="batchSjGfjsKhwtCb">
        insert into sj_gfjs_khwt_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>