<?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.SjZdbfZsdwkhpjfjxMapper">
    
    <resultMap type="SjZdbfZsdwkhpjfjx" id="SjZdbfZsdwkhpjfjxResult">
        <result property="id"    column="id"    />
        <result property="zbId"    column="zb_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="nd"    column="nd"    />
        <result property="zqfw"    column="zqfw"    />
        <result property="zqlx"    column="zqlx"    />
        <result property="jb"    column="jb"    />
        <result property="flmc"    column="flmc"    />
        <result property="pjbzid"    column="pjbzid"    />
        <result property="pjbzmc"    column="pjbzmc"    />
        <result property="sffs"    column="sffs"    />
        <result property="wtms"    column="wtms"    />
        <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>

    <sql id="selectSjZdbfZsdwkhpjfjxVo">
        select id,
               zb_id,
               a.dept_id,
               nd,
               zqfw,
               zqlx,
               jb,
               flmc,
               pjbzid,
               pjbzmc,
               sffs,
               wtms,
               a.create_by,
               a.create_time,
               a.update_by,
               a.update_time,
               remark,
               yl1,
               yl2,
               yl3,
               yl4,
               yl5,d.dept_name
        from sj_zdbf_zsdwkhpjfjx a
                 left join  sys_dept d on a.dept_id=d.dept_id
</sql>

    <select id="selectSjZdbfZsdwkhpjfjxList" parameterType="SjZdbfZsdwkhpjfjx" resultMap="SjZdbfZsdwkhpjfjxResult">
        <include refid="selectSjZdbfZsdwkhpjfjxVo"/>
        <where>  
            <if test="zbId != null "> and zb_id = #{zbId}</if>
            <if test="deptId != null "> and a.dept_id = #{deptId}</if>
            <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
            <if test="zqfw != null  and zqfw != ''"> and zqfw = #{zqfw}</if>
            <if test="zqlx != null  and zqlx != ''"> and zqlx = #{zqlx}</if>
            <if test="jb != null  and jb != ''"> and jb = #{jb}</if>
            <if test="flmc != null  and flmc != ''"> and flmc = #{flmc}</if>
            <if test="pjbzid != null  and pjbzid != ''"> and pjbzid = #{pjbzid}</if>
            <if test="pjbzmc != null  and pjbzmc != ''"> and pjbzmc = #{pjbzmc}</if>
            <if test="sffs != null  and sffs != ''"> and sffs = #{sffs}</if>
            <if test="wtms != null  and wtms != ''"> and wtms = #{wtms}</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>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
        order by  yl1
    </select>
    
    <select id="selectSjZdbfZsdwkhpjfjxById" parameterType="Long" resultMap="SjZdbfZsdwkhpjfjxResult">
        <include refid="selectSjZdbfZsdwkhpjfjxVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSjZdbfZsdwkhpjfjx" parameterType="SjZdbfZsdwkhpjfjx" useGeneratedKeys="true" keyProperty="id">
        insert into sj_zdbf_zsdwkhpjfjx
        <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="zqfw != null">zqfw,</if>
            <if test="zqlx != null">zqlx,</if>
            <if test="jb != null">jb,</if>
            <if test="flmc != null">flmc,</if>
            <if test="pjbzid != null">pjbzid,</if>
            <if test="pjbzmc != null">pjbzmc,</if>
            <if test="sffs != null">sffs,</if>
            <if test="wtms != null">wtms,</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="zqfw != null">#{zqfw},</if>
            <if test="zqlx != null">#{zqlx},</if>
            <if test="jb != null">#{jb},</if>
            <if test="flmc != null">#{flmc},</if>
            <if test="pjbzid != null">#{pjbzid},</if>
            <if test="pjbzmc != null">#{pjbzmc},</if>
            <if test="sffs != null">#{sffs},</if>
            <if test="wtms != null">#{wtms},</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>
    <insert id="batchSave">
        insert into sj_zdbf_zsdwkhpjfjx( id, zb_id, dept_id, nd, zqfw, zqlx, jb, flmc, pjbzid, pjbzmc, sffs, wtms,   remark, yl1, yl2, yl3, yl4, yl5) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.zbId}, #{item.deptId}, #{item.nd}, #{item.zqfw}, #{item.zqlx}, #{item.jb}, #{item.flmc}, #{item.pjbzid}, #{item.pjbzmc}, #{item.sffs}, #{item.wtms},  #{item.remark}, #{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5})
        </foreach>
    </insert>

    <update id="updateSjZdbfZsdwkhpjfjx" parameterType="SjZdbfZsdwkhpjfjx">
        update sj_zdbf_zsdwkhpjfjx
        <trim prefix="SET" suffixOverrides=",">
            <if test="zbId != null">zb_id = #{zbId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="nd != null">nd = #{nd},</if>
            <if test="zqfw != null">zqfw = #{zqfw},</if>
            <if test="zqlx != null">zqlx = #{zqlx},</if>
            <if test="jb != null">jb = #{jb},</if>
            <if test="flmc != null">flmc = #{flmc},</if>
            <if test="pjbzid != null">pjbzid = #{pjbzid},</if>
            <if test="pjbzmc != null">pjbzmc = #{pjbzmc},</if>
            <if test="sffs != null">sffs = #{sffs},</if>
            <if test="wtms != null">wtms = #{wtms},</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>
    <update id="pledit">
       <foreach collection="list" item="item" index="index" separator=";">
           update sj_zdbf_zsdwkhpjfjx set sffs=#{item.sffs},wtms=#{item.wtms} where id =#{item.id}
       </foreach>
    </update>

    <delete id="deleteSjZdbfZsdwkhpjfjxById" parameterType="Long">
        delete from sj_zdbf_zsdwkhpjfjx where id = #{id}
    </delete>

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