<?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.ZqczXmzDdzjMapper">
    <!--  返回实体  -->
    <resultMap id="ZqczXmzDdzjResult" type="ZqczXmzDdzj">
        <result property="ddid" column="ddid"/>
        <result property="dwid" column="dwid"/>
        <result property="dwmc" column="dwmc"/>
        <result property="xqid" column="xqid"/>
        <result property="ddzj" column="ddzj"/>
        <result property="zjmc" column="zjmc"/>
        <result property="sjh" column="sjh"/>
        <result property="fzr" column="fzr"/>
    </resultMap>
    <!--  通用查询  -->
    <sql id="selectCommon">
        SELECT
            ddzj.ddid,
            bfzj.dwid,
            CONCAT( dept.dept_name, dept.create_by ) AS dwmc,
            ddzj.xqid,
            ddzj.ddzj,
            bfzj.zjmc,
            bfzj.sjh,
            ddzj.fzr
        FROM
            zqcz_xmz_ddzj ddzj
            LEFT JOIN zqbf_xmz_bfzj bfzj ON ddzj.ddzj = bfzj.zjid
            LEFT JOIN sys_dept dept ON bfzj.dwid = dept.dept_id
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="ZqczXmzDdzj" resultMap="ZqczXmzDdzjResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="xqid != null ">AND ddzj.xqid = #{xqid}</if>
            <if test="ddzj != null ">AND ddzj.ddzj = #{ddzj}</if>
        </where>
        ORDER BY ddzj.ddid
    </select>
    <!--  新增  -->
    <insert id="batchAdd" parameterType="ZqczXmzDdzj">
        INSERT INTO zqcz_xmz_ddzj (xqid, ddzj, fzr)
        VALUES
        <foreach collection="dataList" item="item" separator=",">
            (#{item.xqid}, #{item.ddzj}, #{item.fzr})
        </foreach>
    </insert>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqcz_xmz_ddzj WHERE xqid = #{id}
    </delete>
</mapper>