<?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.vote.system.mapper.VoteEventsMapper">

    <resultMap id="BaseResultMap" type="com.vote.system.domain.VoteEvents">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="coverImage" column="cover_image" jdbcType="VARCHAR"/>
            <result property="organizerId" column="organizer_id" jdbcType="BIGINT"/>
            <result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
            <result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
            <result property="registrationStartTime" column="registration_start_time" jdbcType="TIMESTAMP"/>
            <result property="registrationEndTime" column="registration_end_time" jdbcType="TIMESTAMP"/>
            <result property="registrationFormId" column="registration_form_id" jdbcType="BIGINT"/>
            <result property="description" column="description" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="CHAR"/>
            <result property="isDeleted" column="is_deleted" jdbcType="CHAR"/>
            <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
            <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,name,cover_image,
        organizer_id,start_time,end_time,
        registration_start_time,registration_end_time,registration_form_id,
        description,status,is_deleted,
        created_at,updated_at
    </sql>
    <delete id="deleteEvents" parameterType="java.lang.Long">
        update vote_events
        set is_deleted = '1'
        where id = #{id}
    </delete>
    <select id="queryById" resultType="java.lang.Integer">
        SELECT COUNT(ews.work_type_id) as quantity
        FROM vote_events
                 INNER JOIN vote_event_work_settings ews ON vote_events.id = ews.event_id
        WHERE vote_events.id = #{id}
    </select>
    <select id="queryNumberById" resultType="java.lang.Integer">
        SELECT COUNT(ver.event_id) as number
        FROM vote_events
                 INNER JOIN vote_event_evaluation_rounds ver ON vote_events.id = ver.event_id
        WHERE vote_events.id = #{id}
    </select>
</mapper>
