<?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.template.mapper.AlumniClubMapper">
    <resultMap type="com.template.model.pojo.AlumniClub" id="ClubDataPageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="categoryId" column="category_id"/>
        <result property="isTop" column="is_top"/>
        <result property="categoryName" column="category_name"/>
        <result property="description" column="description"/>
        <result property="contact" column="contact"/>
        <result property="contacts" column="contacts"/>
        <result property="phone" column="phone"/>
        <result property="address" column="address"/>
        <result property="email" column="email"/>
        <result property="admin" column="admin"/>
        <result property="adminName" column="admin_name"/>
        <result property="isPass" column="is_pass"/>
        <result property="number" column="number"/>
        <result property="passTime" column="pass_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createUserName" column="create_username"/>
    </resultMap>
    <select id="queryClubPages" resultType="com.template.model.pojo.AlumniClub" resultMap="ClubDataPageMap">
        select
        ac.id,ac.contacts,ac.phone,ac.address,ac.email,ac.name,ac.category_id,ac.category_name,ac.is_top,ac.description,ac.contact,ac.admin,aca.is_pass,
        (select Count(*) from alumni_club_apply where deleted = 0 and club_id = ac.id and is_pass = 2) as number
        ,ac.admin_name,ac.create_time,aca.create_time as pass_time,
        au.name as create_username
        from alumni_club ac
        left join alumni_club_apply aca on aca.deleted =0 and aca.club_id = ac.id
        inner join alumni_user au on au.deleted = 0 and au.id = ac.create_user
        <if test="userName != null and userName != ''">
            and au.name like '%' #{userName} '%'
        </if>
        where ac.deleted = 0
        <if test="name != null and name != ''">
            and ac.name like '%' #{name} '%'
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and ac.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="categoryId != null and categoryId != 0">
            and ac.category_id = #{categoryId}
        </if>
        order by ac.create_time desc
    </select>

    <resultMap type="com.template.model.vo.ClubExcelVo" id="ClubDataMap">
        <result property="name" column="name"/>
        <result property="categoryName" column="category_name"/>
        <result property="number" column="number"/>
        <result property="adminName" column="admin_name"/>
        <result property="createUser" column="create_user"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <select id="queryClubDatas" resultType="com.template.model.vo.ClubExcelVo" resultMap="ClubDataMap">
        select
        ac.name,ac.category_name,
        (select Count(*) from alumni_club_apply where deleted = 0 and club_id = ac.id and is_pass = 2) as number,ac.admin_name,au.name as create_user,ac.create_time
        from alumni_club ac
        inner join alumni_user au on au.deleted = 0 and au.id = ac.create_user
        <if test="userName != null and userName != ''">
            and au.name like '%' #{userName} '%'
        </if>
        where ac.deleted = 0
        <if test="name != null and name != ''">
            and ac.name like '%' #{name} '%'
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and ac.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="categoryId != null and categoryId != 0">
            and ac.category_id = #{categoryId}
        </if>
    </select>

    <resultMap type="com.template.model.vo.OtherClubVo" id="CategoryCountMap">
        <result property="categoryId" column="category_id"/>
        <result property="categoryName" column="category_name"/>
        <result property="count" column="count"/>
    </resultMap>
    <select id="CategoryCountDatas" resultType="com.template.model.vo.OtherClubVo" resultMap="CategoryCountMap">
        select category_id,category_name,count(id) as count from alumni_club
        where deleted = 0
        group by category_id,category_name
    </select>

</mapper>
