<?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.zqbfbdw.bfzj.mapper.ZqbfBdwBfzjMapper">
    <!--  返回实体  -->
    <resultMap id="ZqbfBdwBfzjResult" type="ZqbfBdwBfzjVo">
        <result property="zjid" column="zjid"/>
        <result property="dwid" column="dwid"/>
        <result property="dwmc" column="dwmc"/>
        <result property="zjmc" column="zjmc"/>
        <result property="zjxb" column="zjxb"/>
        <result property="csrq" column="csrq"/>
        <result property="zjgz" column="zjgz"/>
        <result property="zyjndj" column="zyjndj"/>
        <result property="zdfx" column="zdfx"/>
        <result property="fzr" column="fzr"/>
        <result property="tyzh" column="tyzh"/>
        <result property="sjh" column="sjh"/>
        <result property="cjr" column="cjr"/>
        <result property="cjsj" column="cjsj"/>
        <result property="gxr" column="gxr"/>
        <result property="gxsj" column="gxsj"/>
        <result property="bz" column="bz"/>
        <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="selectCommon">
        SELECT
            bfzj.zjid,
            bfzj.dwid,
            CONCAT( dept.dept_name, dept.create_by ) AS dwmc,
            bfzj.zjmc,
            bfzj.zjxb,
            bfzj.csrq,
            bfzj.zjgz,
            bfzj.zyjndj,
            bfzj.zdfx,
            bfzj.fzr,
            bfzj.tyzh,
            bfzj.sjh,
            bfzj.cjr,
            bfzj.cjsj,
            bfzj.gxr,
            bfzj.gxsj,
            bfzj.bz,
            bfzj.yl1,
            bfzj.yl2,
            bfzj.yl3,
            bfzj.yl4,
            bfzj.yl5
        FROM
            zqbf_bdw_bfzj bfzj LEFT JOIN sys_dept dept ON bfzj.dwid=dept.dept_id
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="ZqbfBdwBfzjQuery" resultMap="ZqbfBdwBfzjResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="zjid != null ">AND bfzj.zjid = #{zjid}</if>
            <if test="dwid != null ">AND (dept.dept_id = #{dwid} OR FIND_IN_SET(#{dwid}, dept.ancestors))</if>
            <if test="zjmc != null  and zjmc !='' ">AND bfzj.zjmc = like concat('%', #{zjmc}, '%')</if>
            <if test="kssj != null">AND bfzj.gxsj &gt;= #{kssj}</if>
            <if test="jssj != null">AND bfzj.gxsj &lt;= #{kssj}</if>
        </where>
        ORDER BY gxsj DESC
    </select>
    <!--  查询详情  -->
    <select id="info" parameterType="long" resultMap="ZqbfBdwBfzjResult">
        <include refid="selectCommon"></include> WHERE bfzj.zjid = #{zjid}
    </select>
    <!--  新增  -->
    <insert id="add" parameterType="ZqbfBdwBfzj">
        INSERT INTO zqbf_bdw_bfzj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dwid != null ">dwid,</if>
            <if test="zjmc != null  and zjmc != ''">zjmc,</if>
            <if test="zjxb != null  and zjxb != ''">zjxb,</if>
            <if test="csrq != null">csrq,</if>
            <if test="zjgz != null  and zjgz != ''">zjgz,</if>
            <if test="zyjndj != null  and zyjndj != ''">zyjndj,</if>
            <if test="zdfx != null  and zdfx != ''">zdfx,</if>
            <if test="fzr != null  and fzr != ''">fzr,</if>
            <if test="tyzh != null  and tyzh != ''">tyzh,</if>
            <if test="sjh != null  and sjh != ''">sjh,</if>
            <if test="cjr != null  and cjr != ''">cjr,</if>
            <if test="cjsj != null ">cjsj,</if>
            <if test="gxr != null  and gxr != ''">gxr,</if>
            <if test="bz != null  and bz != ''">bz,</if>
            <if test="yl1 != null  and yl1 != ''">yl1,</if>
            <if test="yl2 != null  and yl2 != ''">yl2,</if>
            <if test="yl3 != null  and yl3 != ''">yl3,</if>
            <if test="yl4 != null  and yl4 != ''">yl4,</if>
            <if test="yl5 != null  and yl5 != ''">yl5,</if>
            gxsj
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dwid != null ">#{dwid},</if>
            <if test="zjmc != null  and zjmc != ''">#{zjmc},</if>
            <if test="zjxb != null  and zjxb != ''">#{zjxb},</if>
            <if test="csrq != null">#{csrq},</if>
            <if test="zjgz != null  and zjgz != ''">#{zjgz},</if>
            <if test="zyjndj != null  and zyjndj != ''">#{zyjndj},</if>
            <if test="zdfx != null  and zdfx != ''">#{zdfx},</if>
            <if test="fzr != null  and fzr != ''">#{fzr},</if>
            <if test="tyzh != null  and tyzh != ''">#{tyzh},</if>
            <if test="sjh != null  and sjh != ''">#{sjh},</if>
            <if test="cjr != null  and cjr != ''">#{cjr},</if>
            <if test="cjsj != null ">#{cjsj},</if>
            <if test="gxr != null  and gxr != ''">#{gxr},</if>
            <if test="bz != null  and bz != ''">#{bz},</if>
            <if test="yl1 != null  and yl1 != ''">#{yl1},</if>
            <if test="yl2 != null  and yl2 != ''">#{yl2},</if>
            <if test="yl3 != null  and yl3 != ''">#{yl3},</if>
            <if test="yl4 != null  and yl4 != ''">#{yl4},</if>
            <if test="yl5 != null  and yl5 != ''">#{yl5},</if>
            now()
        </trim>
    </insert>
    <!--  修改  -->
    <update id="edit" parameterType="ZqbfBdwBfzj">
        UPDATE zqbf_bdw_bfzj
        <trim prefix="SET" suffixOverrides=",">
            <if test="dwid != null ">dwid = #{dwid},</if>
            <if test="zjmc != null  and zjmc != ''">zjmc = #{zjmc},</if>
            <if test="zjxb != null  and zjxb != ''">zjxb = #{zjxb},</if>
            <if test="csrq != null">csrq = #{csrq},</if>
            <if test="zjgz != null  and zjgz != ''">zjgz = #{zjgz},</if>
            <if test="zyjndj != null  and zyjndj != ''">zyjndj = #{zyjndj},</if>
            <if test="zdfx != null  and zdfx != ''">zdfx = #{zdfx},</if>
            <if test="fzr != null  and fzr != ''">fzr = #{fzr},</if>
            <if test="tyzh != null  and tyzh != ''">tyzh = #{tyzh},</if>
            <if test="sjh != null  and sjh != ''">sjh = #{sjh},</if>
            <if test="cjr != null  and cjr != ''">cjr = #{cjr},</if>
            <if test="cjsj != null ">cjsj = #{cjsj},</if>
            <if test="gxr != null  and gxr != ''">gxr = #{gxr},</if>
            <if test="bz != null  and bz != ''">bz = #{bz},</if>
            <if test="yl1 != null  and yl1 != ''">yl1 = #{yl1},</if>
            <if test="yl2 != null  and yl2 != ''">yl2 = #{yl2},</if>
            <if test="yl3 != null  and yl3 != ''">yl3 = #{yl3},</if>
            <if test="yl4 != null  and yl4 != ''">yl4 = #{yl4},</if>
            <if test="yl5 != null  and yl5 != ''">yl5 = #{yl5},</if>
            gxsj = now()
        </trim>
        WHERE zjid = #{zjid}
    </update>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqbf_bdw_bfzj WHERE zjid IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>