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

    <resultMap type="SjGfjsZsdwwtcj" id="SjGfjsZsdwwtcjResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="rq"    column="rq"    />
        <result property="jcjb"    column="jcjb"    />
        <result property="wtmc"    column="wtmc"    />
        <result property="khnr"    column="khnr"    />
        <result property="khxd"    column="khxd"    />
        <result property="pjbzid"    column="pjbzid"    />
        <result property="pjbzmc"    column="pjbzmc"    />
        <result property="zgzrr"    column="zgzrr"    />
        <result property="zgcs"    column="zgcs"    />
        <result property="zgqx"    column="zgqx"    />
        <result property="zgzt"    column="zgzt"    />
        <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="pid"    column="pid"    />
        <result property="zt"    column="zt"    />
        <result property="deptName"    column="dept_name"    />
        <result property="deptLx"    column="dept_lx"    />
    </resultMap>

    <sql id="selectSjGfjsZsdwwtcjVo">
        select id,
               a.dept_id,
               rq,
               jcjb,
               wtmc,
               khnr,
               khxd,
               pjbzid,
               pjbzmc,
               zgzrr,
               zgcs,
               zgqx,
               zgzt,
               a.create_by,
               a.create_time,
               a.update_by,
               a.update_time,
               a.remark,
               a.yl1,
               a.yl2,
               a.yl3,
               a.yl4,
               a.yl5, a.pid, a.zt,
                 CONCAT(p.dept_name,'/',d.dept_name) dept_name,
                d.dept_lx
        from sj_gfjs_zsdwwtcj a
                 left join sys_dept d on a.dept_id=d.dept_id
                  LEFT JOIN  sys_dept p on d.parent_id = p.dept_id
        </sql>

    <select id="selectSjGfjsZsdwwtcjList" parameterType="SjGfjsZsdwwtcj" resultMap="SjGfjsZsdwwtcjResult">
        <include refid="selectSjGfjsZsdwwtcjVo"/>
        <where>
            <if test="deptId != null ">and (a.dept_id = #{deptId} or  find_in_set(#{deptId},d.ancestors))</if>
            <if test="rq != null  and rq != ''"> and rq = #{rq}</if>
            <if test="jcjb != null  and jcjb != ''"> and jcjb = #{jcjb}</if>
            <if test="wtmc != null  and wtmc != ''"> and wtmc = #{wtmc}</if>
            <if test="khnr != null  and khnr != ''"> and khnr = #{khnr}</if>
            <if test="khxd != null  and khxd != ''"> and khxd = #{khxd}</if>
            <if test="pjbzid != null  and pjbzid != ''"> and pjbzid = #{pjbzid}</if>
            <if test="pjbzmc != null  and pjbzmc != ''"> and pjbzmc = #{pjbzmc}</if>
            <if test="zgzrr != null  and zgzrr != ''"> and zgzrr = #{zgzrr}</if>
            <if test="zgcs != null  and zgcs != ''"> and zgcs = #{zgcs}</if>
            <if test="zgqx != null  and zgqx != ''"> and zgqx = #{zgqx}</if>
            <if test="zgzt != null  and zgzt != ''"> and zgzt = #{zgzt}</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="pid != null  and pid != ''"> and pid = #{pid}</if>
            <if test="zt != null  and zt != ''"> and zt = #{zt}</if>
            <if test="startRq != null  and startRq != ''"> and rq >= #{startRq}</if>
            <if test="endRq != null  and endRq != ''"> and rq &lt;= #{endRq}</if>
            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
        order by  a.rq desc
    </select>

    <select id="selectSjGfjsZsdwwtcjById" parameterType="Long" resultMap="SjGfjsZsdwwtcjResult">
        <include refid="selectSjGfjsZsdwwtcjVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertSjGfjsZsdwwtcj" parameterType="SjGfjsZsdwwtcj" useGeneratedKeys="true" keyProperty="id">
        insert into sj_gfjs_zsdwwtcj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="rq != null">rq,</if>
            <if test="jcjb != null">jcjb,</if>
            <if test="wtmc != null">wtmc,</if>
            <if test="khnr != null">khnr,</if>
            <if test="khxd != null">khxd,</if>
            <if test="pjbzid != null">pjbzid,</if>
            <if test="pjbzmc != null">pjbzmc,</if>
            <if test="zgzrr != null">zgzrr,</if>
            <if test="zgcs != null">zgcs,</if>
            <if test="zgqx != null">zgqx,</if>
            <if test="zgzt != null">zgzt,</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>
            <if test="pid != null">pid,</if>
            <if test="zt != null">zt,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="rq != null">#{rq},</if>
            <if test="jcjb != null">#{jcjb},</if>
            <if test="wtmc != null">#{wtmc},</if>
            <if test="khnr != null">#{khnr},</if>
            <if test="khxd != null">#{khxd},</if>
            <if test="pjbzid != null">#{pjbzid},</if>
            <if test="pjbzmc != null">#{pjbzmc},</if>
            <if test="zgzrr != null">#{zgzrr},</if>
            <if test="zgcs != null">#{zgcs},</if>
            <if test="zgqx != null">#{zgqx},</if>
            <if test="zgzt != null">#{zgzt},</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>
            <if test="pid != null">#{pid},</if>
            <if test="zt != null">#{zt},</if>
         </trim>
    </insert>
    <insert id="batchSave">
        insert into sj_gfjs_zsdwwtcj( dept_id, rq, jcjb, wtmc, khnr, khxd, pjbzid, pjbzmc, zgzrr, zgcs, zgqx, zgzt,create_by,create_time,remark,yl1,yl2,yl3,yl4,yl5,pid,zt) values
        <foreach item="item" index="index" collection="list" separator=",">
            (  #{item.deptId}, #{item.rq}, #{item.jcjb}, #{item.wtmc}, #{item.khnr}, #{item.khxd}, #{item.pjbzid}, #{item.pjbzmc}, #{item.zgzrr}, #{item.zgcs}, #{item.zgqx}, #{item.zgzt}
            , #{item.createBy}, #{item.createTime},  #{item.remark},#{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5}, #{item.pid}, #{item.zt})
        </foreach>
    </insert>

    <update id="updateSjGfjsZsdwwtcj" parameterType="SjGfjsZsdwwtcj">
        update sj_gfjs_zsdwwtcj
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="rq != null">rq = #{rq},</if>
            <if test="jcjb != null">jcjb = #{jcjb},</if>
            <if test="wtmc != null">wtmc = #{wtmc},</if>
            <if test="khnr != null">khnr = #{khnr},</if>
            <if test="khxd != null">khxd = #{khxd},</if>
            <if test="pjbzid != null">pjbzid = #{pjbzid},</if>
            <if test="pjbzmc != null">pjbzmc = #{pjbzmc},</if>
            <if test="zgzrr != null">zgzrr = #{zgzrr},</if>
            <if test="zgcs != null">zgcs = #{zgcs},</if>
            <if test="zgqx != null">zgqx = #{zgqx},</if>
            <if test="zgzt != null">zgzt = #{zgzt},</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>
            <if test="pid != null">pid = #{pid},</if>
            <if test="zt != null">zt = #{zt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSjGfjsZsdwwtcjById" parameterType="Long">
        delete from sj_gfjs_zsdwwtcj where id = #{id}
    </delete>

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

    <!--批量修改 根据ids-->
    <update id="plxg" parameterType="SjGfjsZsdwwtcj">
        update sj_gfjs_zsdwwtcj
        <trim prefix="SET" suffixOverrides=",">
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="zt != null">zt = #{zt},</if>
        </trim>
        where FIND_IN_SET(id, #{ids})
    </update>
</mapper>
