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

    <resultMap type="DzCards" id="DzCardsResult">
        <result property="cardId"    column="card_id"    />
        <result property="cardNo"    column="card_no"    />
        <result property="password"    column="password"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="distributeStatus"    column="distribute_status"    />
        <result property="timeStatus"    column="time_status"    />
        <result property="payStatus"    column="pay_status"    />
        <result property="isSettlement"    column="is_settlement"    />
        <result property="deptId"    column="dept_id"    />
        <result property="agentId"    column="agent_id"    />
        <result property="leafAgentId"    column="leaf_agent_id"    />
        <result property="campusId"    column="campus_id"    />
        <result property="assignLocation"    column="assign_location"    />
        <result property="assignExamType"    column="assign_exam_type"    />
        <result property="assignSchoolId"    column="assign_school_id"    />
        <result property="schoolId"    column="school_id"    />
        <result property="classId"    column="class_id"    />
        <result property="year"    column="year"    />
        <result property="endYear"    column="end_year"    />
        <result property="openId"    column="open_id"    />
        <result property="remark"    column="remark"    />
        <result property="distributeTime"    column="distribute_time"    />
        <result property="outDate"    column="out_date"    />
        <result property="openTime"    column="open_time"    />
        <result property="payTime"    column="pay_time"    />
        <result property="activeTime"    column="active_time"    />
        <result property="settlementTime"    column="settlement_time"    />
        <result property="refundTime"    column="refund_time"    />
        <result property="closeTime"    column="close_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDzCardsVo">
        select card_id, card_no, password, type, status, distribute_status, time_status, pay_status, is_settlement, dept_id, agent_id, leaf_agent_id, campus_id, assign_location,assign_exam_type,assign_school_id, school_id, class_id, year, end_year, open_id, remark, distribute_time, out_date, open_time, pay_time, active_time, settlement_time, refund_time, close_time, create_time, update_time from dz_cards
    </sql>

    <select id="selectDzCardsList" parameterType="DzCards" resultMap="DzCardsResult">
        <include refid="selectDzCardsVo"/>
        <where>
            <if test="cardNo != null  and cardNo != ''"> and card_no = #{cardNo}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="distributeStatus != null "> and distribute_status = #{distributeStatus}</if>
            <if test="timeStatus != null "> and time_status = #{timeStatus}</if>
            <if test="payStatus != null "> and pay_status = #{payStatus}</if>
            <if test="isSettlement != null "> and is_settlement = #{isSettlement}</if>
            <if test="deptId != null ">
                AND (dept_id = #{deptId} OR dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
            </if>
            <if test="agentId != null ">
                AND (agent_id = #{agentId} OR agent_id IN ( SELECT t.agent_id FROM dz_agent t WHERE t.agent_id=#{agentId} ))
            </if>
            <if test="leafAgentId != null "> and leaf_agent_id = #{leafAgentId}</if>
            <if test="campusId != null "> and campus_id = #{campusId}</if>
            <if test="assignLocation != null "> and assign_location = #{assignLocation}</if>
            <if test="assignExamType != null "> and assign_exam_type = #{assignExamType}</if>
            <if test="assignSchoolId != null "> and assign_school_id = #{assignSchoolId}</if>
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="endYear != null "> and end_year = #{endYear}</if>
            <if test="openId != null "> and open_id = #{openId}</if>
            <if test="distributeTime != null "> and distribute_time = #{distributeTime}</if>
            <if test="outDate != null "> and out_date = #{outDate}</if>
            <if test="openTime != null "> and open_time = #{openTime}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="activeTime != null "> and active_time = #{activeTime}</if>
            <if test="settlementTime != null "> and settlement_time = #{settlementTime}</if>
            <if test="refundTime != null "> and refund_time = #{refundTime}</if>
            <if test="closeTime != null "> and close_time = #{closeTime}</if>
        </where>
    </select>

    <select id="selectDzCardsByCardId" parameterType="Long" resultMap="DzCardsResult">
        <include refid="selectDzCardsVo"/>
        where card_id = #{cardId}
    </select>

    <insert id="insertDzCards" parameterType="DzCards" useGeneratedKeys="true" keyProperty="cardId">
        insert into dz_cards
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cardNo != null">card_no,</if>
            <if test="password != null">password,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="distributeStatus != null">distribute_status,</if>
            <if test="timeStatus != null">time_status,</if>
            <if test="payStatus != null">pay_status,</if>
            <if test="isSettlement != null">is_settlement,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="agentId != null">agent_id,</if>
            <if test="leafAgentId != null">leaf_agent_id,</if>
            <if test="campusId != null">campus_id,</if>
            assign_location,assign_exam_type,assign_school_id,
            <if test="schoolId != null">school_id,</if>
            <if test="classId != null">class_id,</if>
            <if test="year != null">year,</if>
            <if test="endYear != null">end_year,</if>
            <if test="openId != null">open_id,</if>
            <if test="remark != null">remark,</if>
            <if test="distributeTime != null">distribute_time,</if>
            <if test="outDate != null">out_date,</if>
            <if test="openTime != null">open_time,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="activeTime != null">active_time,</if>
            <if test="settlementTime != null">settlement_time,</if>
            <if test="refundTime != null">refund_time,</if>
            <if test="closeTime != null">close_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cardNo != null">#{cardNo},</if>
            <if test="password != null">#{password},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="distributeStatus != null">#{distributeStatus},</if>
            <if test="timeStatus != null">#{timeStatus},</if>
            <if test="payStatus != null">#{payStatus},</if>
            <if test="isSettlement != null">#{isSettlement},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="agentId != null">#{agentId},</if>
            <if test="leafAgentId != null">#{leafAgentId},</if>
            <if test="campusId != null">#{campusId},</if>
            #{assignLocation},#{assignExamType},#{assignSchoolId},
            <if test="schoolId != null">#{schoolId},</if>
            <if test="classId != null">#{classId},</if>
            <if test="year != null">#{year},</if>
            <if test="endYear != null">#{endYear},</if>
            <if test="openId != null">#{openId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="distributeTime != null">#{distributeTime},</if>
            <if test="outDate != null">#{outDate},</if>
            <if test="openTime != null">#{openTime},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="activeTime != null">#{activeTime},</if>
            <if test="settlementTime != null">#{settlementTime},</if>
            <if test="refundTime != null">#{refundTime},</if>
            <if test="closeTime != null">#{closeTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDzCards" parameterType="DzCards">
        update dz_cards
        <trim prefix="SET" suffixOverrides=",">
            <if test="cardNo != null">card_no = #{cardNo},</if>
            <if test="password != null">password = #{password},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="distributeStatus != null">distribute_status = #{distributeStatus},</if>
            <if test="timeStatus != null">time_status = #{timeStatus},</if>
            <if test="payStatus != null">pay_status = #{payStatus},</if>
            <if test="isSettlement != null">is_settlement = #{isSettlement},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="leafAgentId != null">leaf_agent_id = #{leafAgentId},</if>
            <if test="campusId != null">campus_id = #{campusId},</if>
            assign_location = #{assignLocation},assign_exam_type = #{assignExamType},assign_school_id = #{assignSchoolId},
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="year != null">year = #{year},</if>
            <if test="endYear != null">end_year = #{endYear},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="distributeTime != null">distribute_time = #{distributeTime},</if>
            <if test="outDate != null">out_date = #{outDate},</if>
            <if test="openTime != null">open_time = #{openTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="activeTime != null">active_time = #{activeTime},</if>
            <if test="settlementTime != null">settlement_time = #{settlementTime},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="closeTime != null">close_time = #{closeTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where card_id = #{cardId}
    </update>

    <update id="updateDzCardsByNo" parameterType="DzCards">
        update dz_cards
        <trim prefix="SET" suffixOverrides=",">
            <if test="password != null">password = #{password},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="distributeStatus != null">distribute_status = #{distributeStatus},</if>
            <if test="timeStatus != null">time_status = #{timeStatus},</if>
            <if test="payStatus != null">pay_status = #{payStatus},</if>
            <if test="isSettlement != null">is_settlement = #{isSettlement},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="leafAgentId != null">leaf_agent_id = #{leafAgentId},</if>
            <if test="campusId != null">campus_id = #{campusId},</if>
            assign_location = #{assignLocation},assign_exam_type = #{assignExamType},assign_school_id = #{assignSchoolId},
            <if test="schoolId != null">school_id = #{schoolId},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="year != null">year = #{year},</if>
            <if test="endYear != null">end_year = #{endYear},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="distributeTime != null">distribute_time = #{distributeTime},</if>
            <if test="outDate != null">out_date = #{outDate},</if>
            <if test="openTime != null">open_time = #{openTime},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="activeTime != null">active_time = #{activeTime},</if>
            <if test="settlementTime != null">settlement_time = #{settlementTime},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="closeTime != null">close_time = #{closeTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where card_no = #{cardNo}
    </update>

    <delete id="deleteDzCardsByCardId" parameterType="Long">
        delete from dz_cards where card_id = #{cardId}
    </delete>

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


    <select id="selectListByCond" parameterType="com.ruoyi.criteria.CardCriteria" resultMap="DzCardsResult">
        <include refid="selectDzCardsVo"/>
        <where>
            <if test="startNo != null  and startNo != ''"> and card_no &gt;= #{startNo}</if>
            <if test="endNo != null  and endNo != ''"> and card_no &lt;= #{endNo}</if>
            <if test="cardNo != null  and cardNo != ''"> and card_no = #{cardNo}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="distributeStatus != null "> and distribute_status = #{distributeStatus}</if>
            <if test="timeStatus != null "> and time_status = #{timeStatus}</if>
            <if test="payStatus != null "> and pay_status = #{payStatus}</if>
            <if test="isSettlement != null "> and is_settlement = #{isSettlement}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="agentId != null "> and agent_id = #{agentId}</if>
            <if test="leafAgentId != null "> and leaf_agent_id = #{leafAgentId}</if>
            <if test="campusId != null "> and campus_id = #{campusId}</if>
            <if test="assignLocation != null "> and assign_location = #{assignLocation}</if>
            <if test="assignExamType != null "> and assign_exam_type = #{assignExamType}</if>
            <if test="assignSchoolId != null "> and assign_school_id = #{assignSchoolId}</if>
            <if test="schoolId != null "> and school_id = #{schoolId}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="endYear != null "> and end_year = #{endYear}</if>
            <if test="openId != null "> and open_id = #{openId}</if>
            <if test="distributeTime != null "> and distribute_time = #{distributeTime}</if>
            <if test="outDate != null "> and out_date = #{outDate}</if>
            <if test="openTime != null "> and open_time = #{openTime}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="activeTime != null "> and active_time = #{activeTime}</if>
            <if test="settlementTime != null "> and settlement_time = #{settlementTime}</if>
            <if test="refundTime != null "> and refund_time = #{refundTime}</if>
            <if test="closeTime != null "> and close_time = #{closeTime}</if>
        </where>
    </select>

    <select id="selectCardsByCardIds" parameterType="String" resultMap="DzCardsResult">
        <include refid="selectDzCardsVo"/>
        where card_id in <foreach item="cardId" collection="array" open="(" separator="," close=")">#{cardId}</foreach>
    </select>

    <select id="selectMaxNo" parameterType="Integer" resultType="Long">
        select max(card_no) from dz_cards where type = #{type}
    </select>
</mapper>
