<?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.jeeplus.test.luckyDraw.mapper.LuckyDrawEventsMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.test.luckyDraw.service.dto.LuckyDrawEventsDTO">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createBy.id" column="create_by" jdbcType="VARCHAR"/>
            <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
            <result property="updateBy.id" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="detail" column="detail" jdbcType="VARCHAR"/>
            <result property="switchFlag" column="switch_flag" jdbcType="VARCHAR"></result>
            <collection property="luckyDrawAwardsDTOList" ofType="com.jeeplus.test.luckyDraw.service.dto.LuckyDrawAwardsDTO" column="id" select="getLuckyDrawAwards"></collection>
    </resultMap>

    <sql id="Events_Column_List">
        lde.id,
        lde.create_by,
        lde.create_date,
        lde.update_by,
        lde.update_date,
        lde.del_flag,
        lde.remarks,
        lde.name,
        lde.detail,
        lde.switch_flag
    </sql>

    <sql id="Awards_Column_List">
        lda.id,
        lda.create_by,
        lda.create_date,
        lda.update_by,
        lda.update_date,
        lda.del_flag,
        lda.remarks,
        lda.events_id,
        lda.name,
        lda.number,
        lda.prize_name
    </sql>

    <select id="getLuckyDrawAwards" resultType="com.jeeplus.test.luckyDraw.service.dto.LuckyDrawAwardsDTO">
        select
            <include refid="Awards_Column_List"></include>
        from lucky_draw_awards lda where lda.events_id = #{id} and lda.del_flag = '0' order by lda.create_date asc
    </select>

    <select id="findList" resultMap="BaseResultMap">
        select
            <include refid="Events_Column_List"></include>
        from lucky_draw_events lde
        ${ew.customSqlSegment}
    </select>

    <select id="queryById" resultMap="BaseResultMap">
        select
            <include refid="Events_Column_List"></include>
        from lucky_draw_events lde
        where lde.del_flag = '0' and lde.id = #{id}
    </select>

    <update id="changeSwitchOpen">
        update lucky_draw_events lde set lde.switch_flag = '1' where lde.id = #{id}
    </update>

    <update id="changeSwitchClose">
        update lucky_draw_events lde set lde.switch_flag = '0' where lde.id = #{id}
    </update>
</mapper>
