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

    <resultMap type="SjZdbfZsdwkhpjZb" id="SjZdbfZsdwkhpjZbResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="parentDeptId"    column="parent_dept_id"    />
        <result property="nd"    column="nd"    />
        <result property="zqfw"    column="zqfw"    />
        <result property="zqlx"    column="zqlx"    />
        <result property="jb"    column="jb"    />
        <result property="deptDfl"    column="dept_dfl"    />
        <result property="deptLx"    column="dept_lx"    />
        <result property="deptYwfl"    column="dept_ywfl"    />
        <result property="djyjzfs"    column="djyjzfs"    />
        <result property="djyjkfs"    column="djyjkfs"    />
        <result property="djyjkfbl"    column="djyjkfbl"    />
        <result property="djyjdf"    column="djyjdf"    />
        <result property="sztszfs"    column="sztszfs"    />
        <result property="sztskfs"    column="sztskfs"    />
        <result property="sztsfbl"    column="sztsfbl"    />
        <result property="sztsdf"    column="sztsdf"    />
        <result property="glgfzfs"    column="glgfzfs"    />
        <result property="glgfkfs"    column="glgfkfs"    />
        <result property="glgfbl"    column="glgfbl"    />
        <result property="glgfdf"    column="glgfdf"    />
        <result property="ywcxzfs"    column="ywcxzfs"    />
        <result property="ywcxkfs"    column="ywcxkfs"    />
        <result property="ywcxbl"    column="ywcxbl"    />
        <result property="ywcxdf"    column="ywcxdf"    />
        <result property="sffjxs"    column="sffjxs"    />
        <result property="zkf"    column="zkf"    />
        <result property="zkfbl"    column="zkfbl"    />
        <result property="zdf"    column="zdf"    />
        <result property="zhdf"    column="zhdf"    />
        <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"    />
        <result property="parentName"    column="parent_name"    />
    </resultMap>

    <sql id="selectSjZdbfZsdwkhpjZbVo">

        select id,
               a.dept_id,
               parent_dept_id,
               nd,
               zqfw,
               zqlx,
               jb,
               d.dept_dfl,
               d.dept_lx,
               d.dept_ywfl,
               djyjzfs,
               djyjkfs,
               djyjkfbl,
               djyjdf,
               sztszfs,
               sztskfs,
               sztsfbl,
               sztsdf,
               glgfzfs,
               glgfkfs,
               glgfbl,
               glgfdf,
               ywcxzfs,
               ywcxkfs,
               ywcxbl,
               ywcxdf,
               sffjxs,
               zkf,
               zkfbl,
               zdf,
               zhdf,
               a.create_by,
               a.create_time,
               a.update_by,
               a.update_time,
               remark,
               yl1,
               yl2,
               yl3,
               yl4,
               yl5,d.dept_name,p.dept_name parent_name
        from sj_zdbf_zsdwkhpj_zb a
                 left join sys_dept d on a.dept_id=d.dept_id
                 left join sys_dept p on a.parent_dept_id=p.dept_id    </sql>

    <select id="selectSjZdbfZsdwkhpjZbList" parameterType="SjZdbfZsdwkhpjZb" resultMap="SjZdbfZsdwkhpjZbResult">
        <include refid="selectSjZdbfZsdwkhpjZbVo"/>
        <where>
            <if test="deptId != null ">and (a.dept_id = #{deptId} or  find_in_set(#{deptId},d.ancestors))</if>
            <if test="parentDeptId != null "> and parent_dept_id = #{parentDeptId}</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="deptDfl != null  and deptDfl != ''"> and a.dept_dfl = #{deptDfl}</if>
            <if test="deptLx != null  and deptLx != ''"> and dept_lx = #{deptLx}</if>
            <if test="deptYwfl != null  and deptYwfl != ''"> and a.dept_ywfl = #{deptYwfl}</if>
            <if test="djyjzfs != null "> and djyjzfs = #{djyjzfs}</if>
            <if test="djyjkfs != null "> and djyjkfs = #{djyjkfs}</if>
            <if test="djyjkfbl != null "> and djyjkfbl = #{djyjkfbl}</if>
            <if test="djyjdf != null "> and djyjdf = #{djyjdf}</if>
            <if test="sztszfs != null "> and sztszfs = #{sztszfs}</if>
            <if test="sztskfs != null "> and sztskfs = #{sztskfs}</if>
            <if test="sztsfbl != null "> and sztsfbl = #{sztsfbl}</if>
            <if test="sztsdf != null "> and sztsdf = #{sztsdf}</if>
            <if test="glgfzfs != null "> and glgfzfs = #{glgfzfs}</if>
            <if test="glgfkfs != null "> and glgfkfs = #{glgfkfs}</if>
            <if test="glgfbl != null "> and glgfbl = #{glgfbl}</if>
            <if test="glgfdf != null "> and glgfdf = #{glgfdf}</if>
            <if test="ywcxzfs != null "> and ywcxzfs = #{ywcxzfs}</if>
            <if test="ywcxkfs != null "> and ywcxkfs = #{ywcxkfs}</if>
            <if test="ywcxbl != null "> and ywcxbl = #{ywcxbl}</if>
            <if test="ywcxdf != null "> and ywcxdf = #{ywcxdf}</if>
            <if test="sffjxs != null "> and sffjxs = #{sffjxs}</if>
            <if test="zkf != null "> and zkf = #{zkf}</if>
            <if test="zkfbl != null "> and zkfbl = #{zkfbl}</if>
            <if test="zdf != null "> and zdf = #{zdf}</if>
            <if test="zhdf != null "> and zhdf = #{zhdf}</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>
            <if test="df != null "> and zdf &lt;= #{df}</if>
            <if test="kfbl != null "> and zkfbl >= #{kfbl}</if>
            <if test="fjx != null and fjx.toString()=='1'.toString() "> and sffjxs >= #{fjx}</if>
            <if test="fjx != null and fjx.toString()=='0'.toString() "> and sffjxs = #{fjx}</if>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
        order by zhdf desc
    </select>

    <select id="selectSjZdbfZsdwkhpjZbById" parameterType="Long" resultMap="SjZdbfZsdwkhpjZbResult">
        <include refid="selectSjZdbfZsdwkhpjZbVo"/>
        where id = #{id}
    </select>
    <select id="selectSjZdbfZsdwkhpjZb" resultType="com.qianhe.domain.SjZdbfZsdwkhpjZb">
        select *from sj_zdbf_zsdwkhpj_zb where nd=#{nd}  and dept_id=#{deptId} and zqfw=#{zqfw}
    </select>

    <insert id="insertSjZdbfZsdwkhpjZb" parameterType="SjZdbfZsdwkhpjZb" useGeneratedKeys="true" keyProperty="id">
        insert into sj_zdbf_zsdwkhpj_zb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="parentDeptId != null">parent_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="deptDfl != null">dept_dfl,</if>
            <if test="deptLx != null">dept_lx,</if>
            <if test="deptYwfl != null">dept_ywfl,</if>
            <if test="djyjzfs != null">djyjzfs,</if>
            <if test="djyjkfs != null">djyjkfs,</if>
            <if test="djyjkfbl != null">djyjkfbl,</if>
            <if test="djyjdf != null">djyjdf,</if>
            <if test="sztszfs != null">sztszfs,</if>
            <if test="sztskfs != null">sztskfs,</if>
            <if test="sztsfbl != null">sztsfbl,</if>
            <if test="sztsdf != null">sztsdf,</if>
            <if test="glgfzfs != null">glgfzfs,</if>
            <if test="glgfkfs != null">glgfkfs,</if>
            <if test="glgfbl != null">glgfbl,</if>
            <if test="glgfdf != null">glgfdf,</if>
            <if test="ywcxzfs != null">ywcxzfs,</if>
            <if test="ywcxkfs != null">ywcxkfs,</if>
            <if test="ywcxbl != null">ywcxbl,</if>
            <if test="ywcxdf != null">ywcxdf,</if>
            <if test="sffjxs != null">sffjxs,</if>
            <if test="zkf != null">zkf,</if>
            <if test="zkfbl != null">zkfbl,</if>
            <if test="zdf != null">zdf,</if>
            <if test="zhdf != null">zhdf,</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="parentDeptId != null">#{parentDeptId},</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="deptDfl != null">#{deptDfl},</if>
            <if test="deptLx != null">#{deptLx},</if>
            <if test="deptYwfl != null">#{deptYwfl},</if>
            <if test="djyjzfs != null">#{djyjzfs},</if>
            <if test="djyjkfs != null">#{djyjkfs},</if>
            <if test="djyjkfbl != null">#{djyjkfbl},</if>
            <if test="djyjdf != null">#{djyjdf},</if>
            <if test="sztszfs != null">#{sztszfs},</if>
            <if test="sztskfs != null">#{sztskfs},</if>
            <if test="sztsfbl != null">#{sztsfbl},</if>
            <if test="sztsdf != null">#{sztsdf},</if>
            <if test="glgfzfs != null">#{glgfzfs},</if>
            <if test="glgfkfs != null">#{glgfkfs},</if>
            <if test="glgfbl != null">#{glgfbl},</if>
            <if test="glgfdf != null">#{glgfdf},</if>
            <if test="ywcxzfs != null">#{ywcxzfs},</if>
            <if test="ywcxkfs != null">#{ywcxkfs},</if>
            <if test="ywcxbl != null">#{ywcxbl},</if>
            <if test="ywcxdf != null">#{ywcxdf},</if>
            <if test="sffjxs != null">#{sffjxs},</if>
            <if test="zkf != null">#{zkf},</if>
            <if test="zkfbl != null">#{zkfbl},</if>
            <if test="zdf != null">#{zdf},</if>
            <if test="zhdf != null">#{zhdf},</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="updateSjZdbfZsdwkhpjZb" parameterType="SjZdbfZsdwkhpjZb">
        update sj_zdbf_zsdwkhpj_zb
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="parentDeptId != null">parent_dept_id = #{parentDeptId},</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="deptDfl != null">dept_dfl = #{deptDfl},</if>
            <if test="deptLx != null">dept_lx = #{deptLx},</if>
            <if test="deptYwfl != null">dept_ywfl = #{deptYwfl},</if>
            <if test="djyjzfs != null">djyjzfs = #{djyjzfs},</if>
            <if test="djyjkfs != null">djyjkfs = #{djyjkfs},</if>
            <if test="djyjkfbl != null">djyjkfbl = #{djyjkfbl},</if>
            <if test="djyjdf != null">djyjdf = #{djyjdf},</if>
            <if test="sztszfs != null">sztszfs = #{sztszfs},</if>
            <if test="sztskfs != null">sztskfs = #{sztskfs},</if>
            <if test="sztsfbl != null">sztsfbl = #{sztsfbl},</if>
            <if test="sztsdf != null">sztsdf = #{sztsdf},</if>
            <if test="glgfzfs != null">glgfzfs = #{glgfzfs},</if>
            <if test="glgfkfs != null">glgfkfs = #{glgfkfs},</if>
            <if test="glgfbl != null">glgfbl = #{glgfbl},</if>
            <if test="glgfdf != null">glgfdf = #{glgfdf},</if>
            <if test="ywcxzfs != null">ywcxzfs = #{ywcxzfs},</if>
            <if test="ywcxkfs != null">ywcxkfs = #{ywcxkfs},</if>
            <if test="ywcxbl != null">ywcxbl = #{ywcxbl},</if>
            <if test="ywcxdf != null">ywcxdf = #{ywcxdf},</if>
            <if test="sffjxs != null">sffjxs = #{sffjxs},</if>
            <if test="zkf != null">zkf = #{zkf},</if>
            <if test="zkfbl != null">zkfbl = #{zkfbl},</if>
            <if test="zdf != null">zdf = #{zdf},</if>
            <if test="zhdf != null">zhdf = #{zhdf},</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="deleteSjZdbfZsdwkhpjZbById" parameterType="Long">
        delete from sj_zdbf_zsdwkhpj_zb where id = #{id}
    </delete>

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