<?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.ruoyi.dz.mapper.DzCardsOpenMapper">

    <resultMap type="DzCardsOpen" id="DzCardsOpenResult">
        <result property="id"    column="id"    />
        <result property="agentId"    column="agent_id"    />
        <result property="startNo"    column="start_no"    />
        <result property="endNo"    column="end_no"    />
        <result property="endDate"    column="end_date"    />
        <result property="location"    column="location"    />
        <result property="schoolId"    column="school_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="sender"    column="sender"    />
        <result property="createTime"    column="create_time"    />
        <result property="isReopen"    column="is_reopen"    />
        <result property="status"    column="status"    />
        <result property="auditDesc"    column="audit_desc"    />
        <result property="cardType"    column="card_type"    />

    </resultMap>

    <sql id="selectDzCardsOpenVo">
        select id, agent_id, start_no, end_no, end_date, location, school_id, dept_id, sender, create_time, is_reopen, status, audit_desc, card_type from dz_cards_open
    </sql>

    <select id="selectDzCardsOpenList" parameterType="DzCardsOpen" resultMap="DzCardsOpenResult">
        <include refid="selectDzCardsOpenVo"/>
        <where>
            <if test="agentId != null "> and agent_id IN ( SELECT t.agent_id FROM dz_agent t WHERE t.agent_id=#{agentId} or t.parent_id=#{agentId} )</if>
            <if test="startNo != null  and startNo != ''"> and start_no = #{startNo}</if>
            <if test="endNo != null  and endNo != ''"> and end_no = #{endNo}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="location != null "> and location = #{location}</if>
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="sender != null  and sender != ''"> and sender = #{sender}</if>
            <if test="isReopen != null "> and is_reopen = #{isReopen}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="cardType != null "> and card_type = #{cardType}</if>
        </where>
        order by id desc
    </select>

    <select id="selectDzCardsOpenById" parameterType="Long" resultMap="DzCardsOpenResult">
        <include refid="selectDzCardsOpenVo"/>
        where id = #{id}
    </select>

    <insert id="insertDzCardsOpen" parameterType="DzCardsOpen" useGeneratedKeys="true" keyProperty="id">
        insert into dz_cards_open
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agentId != null">agent_id,</if>
            <if test="startNo != null">start_no,</if>
            <if test="endNo != null">end_no,</if>
            <if test="endDate != null">end_date,</if>
            <if test="location != null">location,</if>
            <if test="schoolId != null">school_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="sender != null">sender,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isReopen != null">is_reopen,</if>
            <if test="status != null">status,</if>
            <if test="cardType != null">card_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agentId != null">#{agentId},</if>
            <if test="startNo != null">#{startNo},</if>
            <if test="endNo != null">#{endNo},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="location != null">#{location},</if>
            <if test="schoolId != null">#{schoolId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="sender != null">#{sender},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isReopen != null">#{isReopen},</if>
            <if test="status != null">#{status},</if>
            <if test="cardType != null">#{cardType},</if>
         </trim>
    </insert>

    <update id="updateDzCardsOpen" parameterType="DzCardsOpen">
        update dz_cards_open
        <trim prefix="SET" suffixOverrides=",">
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="startNo != null">start_no = #{startNo},</if>
            <if test="endNo != null">end_no = #{endNo},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="location != null">location = #{location},</if>
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="sender != null">sender = #{sender},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isReopen != null">is_reopen = #{isReopen},</if>
            <if test="status != null">status = #{status},</if>
            <if test="cardType != null">card_type = #{cardType},</if>
            <if test="auditDesc != null ">audit_desc = #{auditDesc}</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDzCardsOpenById" parameterType="Long">
        delete from dz_cards_open where id = #{id}
    </delete>

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