<?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.zqbf.mapper.ZqbfXmzBfxqMapper">
    <!--  返回实体  -->
    <resultMap id="ZqbfXmzBfxqResult" type="ZqbfXmzBfxqVo">
        <result property="xqid" column="xqid"/>
        <result property="dwid" column="dwid"/>
        <result property="dwmc" column="dwmc"/>
        <result property="xmid" column="xmid"/>
        <result property="xmmc" column="xmmc"/>
        <result property="xmzb" column="xmzb"/>
        <result property="xqms" column="xqms"/>
        <result property="dqzt" column="dqzt"/>
        <result property="bfkssj" column="bfkssj"/>
        <result property="bfjssj" column="bfjssj"/>
        <result property="lxr" column="lxr"/>
        <result property="lxdh" column="lxdh"/>
        <result property="gxsj" column="gxsj"/>
        <result property="wcsj" column="wcsj"/>
        <result property="bfms" column="bfms"/>
    </resultMap>
    <!--  通用查询  -->
    <sql id="selectCommon">
        SELECT
            bfxq.xqid,
            bfxq.dwid,
            CONCAT( dept.dept_name, dept.create_by ) AS dwmc,
            bfxq.xmid,
            bfxm.xmmc,
            bfxm.xmzb,
            bfxq.xqms,
            bfxq.dqzt,
            bfxq.bfkssj,
            bfxq.bfjssj,
            bfxq.lxr,
            bfxq.lxdh,
            bfxq.gxsj,
            bfxq.wcsj,
            bfxq.bfms
        FROM
            zqbf_xmz_bfxq bfxq
            LEFT JOIN sys_dept dept ON bfxq.dwid = dept.dept_id
            LEFT JOIN zqbf_xmz_bfxm bfxm ON bfxq.xmid = bfxm.xmid
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="ZqbfXmzBfxqQuery" resultMap="ZqbfXmzBfxqResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="xqid != null ">AND bfxq.xqid = #{xqid}</if>
            <if test="user_id != null ">AND ddzj.ddzj = #{user_id}</if>
            <if test="dwid != null ">AND (dept.dept_id = #{dwid} OR FIND_IN_SET(#{dwid}, dept.ancestors))</if>
            <if test="xmmc != null and xmmc != ''">AND bfxm.xmmc like concat('%', #{xmmc}, '%')</if>
            <if test="dqzt != null and dqzt != ''">AND bfxq.dqzt &gt;= #{dqzt}</if>
            <if test="kssj != null">AND bfxq.bfkssj &gt;= #{kssj}</if>
            <if test="jssj != null">AND bfxq.bfjssj &lt;= #{jssj}</if>
            ${params.dataScope}
        </where>
        GROUP BY
            bfxq.xqid,
            bfxq.dwid,
            CONCAT( dept.dept_name, dept.create_by ),
            bfxq.xmid,
            bfxm.xmmc,
            bfxm.xmzb,
            bfxq.xqms,
            bfxq.dqzt,
            bfxq.bfkssj,
            bfxq.bfjssj,
            bfxq.lxr,
            bfxq.lxdh,
            bfxq.wcsj,
            bfxq.bfms
        ORDER BY bfxq.gxsj DESC
    </select>
    <!--  查询详情  -->
    <select id="info" parameterType="long" resultMap="ZqbfXmzBfxqResult">
        <include refid="selectCommon"></include> WHERE bfxq.xqid = #{id}
    </select>
    <!--  新增  -->
    <insert id="add" parameterType="ZqbfXmzBfxq" useGeneratedKeys="true" keyProperty="xqid">
        INSERT INTO zqbf_xmz_bfxq
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dwid != null ">dwid,</if>
            <if test="xmid != null ">xmid,</if>
            <if test="bfkssj != null ">bfkssj,</if>
            <if test="bfjssj != null ">bfjssj,</if>
            <if test="lxr != null  and lxr != ''">lxr,</if>
            <if test="lxdh != null  and lxdh != ''">lxdh,</if>
            <if test="dqzt != null  and dqzt != ''">dqzt,</if>
            <if test="xqms != null  and xqms != ''">xqms,</if>
            <if test="htms != null  and htms != ''">htms,</if>
            <if test="wcsj != null ">wcsj,</if>
            <if test="bfms != null  and bfms != ''">bfms,</if>
            <if test="pjdj != null  and pjdj != ''">pjdj,</if>
            <if test="pdms != null  and pdms != ''">pdms,</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="xmid != null ">#{xmid},</if>
            <if test="bfkssj != null ">#{bfkssj},</if>
            <if test="bfjssj != null ">#{bfjssj},</if>
            <if test="lxr != null  and lxr != ''">#{lxr},</if>
            <if test="lxdh != null  and lxdh != ''">#{lxdh},</if>
            <if test="dqzt != null  and dqzt != ''">#{dqzt},</if>
            <if test="xqms != null  and xqms != ''">#{xqms},</if>
            <if test="htms != null  and htms != ''">#{htms},</if>
            <if test="wcsj != null ">#{wcsj},</if>
            <if test="bfms != null  and bfms != ''">#{bfms},</if>
            <if test="pjdj != null  and pjdj != ''">#{pjdj},</if>
            <if test="pdms != null  and pdms != ''">#{pdms},</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="ZqbfXmzBfxq">
        UPDATE zqbf_xmz_bfxq
        <trim prefix="SET" suffixOverrides=",">
            <if test="dwid != null ">dwid = #{dwid},</if>
            <if test="xmid != null ">xmid = #{xmid},</if>
            <if test="bfkssj != null ">bfkssj = #{bfkssj},</if>
            <if test="bfjssj != null ">bfjssj = #{bfjssj},</if>
            <if test="lxr != null  and lxr != ''">lxr = #{lxr},</if>
            <if test="lxdh != null  and lxdh != ''">lxdh = #{lxdh},</if>
            <if test="dqzt != null  and dqzt != ''">dqzt = #{dqzt},</if>
            <if test="xqms != null  and xqms != ''">xqms = #{xqms},</if>
            <if test="htms != null  and htms != ''">htms = #{htms},</if>
            <if test="wcsj != null ">wcsj = #{wcsj},</if>
            <if test="bfms != null  and bfms != ''">bfms = #{bfms},</if>
            <if test="pjdj != null  and pjdj != ''">pjdj = #{pjdj},</if>
            <if test="pdms != null  and pdms != ''">pdms = #{pdms},</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 xqid = #{xqid}
    </update>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqbf_xmz_bfxq WHERE xqid IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>