<?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.AlumniImageMapper">
    <resultMap type="com.template.model.vo.ImagePageVo" id="ImagePageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="collegeName" column="college_name"/>
        <result property="periodName" column="period_name"/>
        <result property="majorName" column="major_name"/>
        <result property="className" column="class_name"/>
        <result property="categoryName" column="category_name"/>
        <result property="orgName" column="org_name"/>
        <result property="image" column="image"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <select id="imagePageDatas" resultType="com.template.model.vo.ImagePageVo" resultMap="ImagePageMap">
        select
        ai.id,au.name,au.college_name,au.period_name,au.major_name,au.class_name,ai.category_name,au.org_name,ai.image,ai.create_time
        from alumni_image ai
        inner join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        <if test="userName != null and userName != ''">
            and au.name like '%' #{userName} '%'
        </if>
        <if test="orgName != null and orgName != ''">
            and au.org_name like '%' #{orgName} '%'
        </if>
        <if test="collegeId != null and collegeId != 0">
            and au.college_id = #{collegeId}
        </if>
        <if test="periodId != null and periodId != 0">
            and au.period_id = #{periodId}
        </if>
        <if test="majorId != null and majorId != 0">
            and au.major_id = #{majorId}
        </if>
        <if test="classId != null and classId != 0">
            and au.class_id = #{classId}
        </if>
        where ai.deleted = 0 and ai.is_pass = 2
        order by ai.create_time desc
    </select>


    <resultMap type="com.template.model.vo.ImageApplyPageVo" id="ImageApplyPageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="collegeName" column="college_name"/>
        <result property="periodName" column="period_name"/>
        <result property="majorName" column="major_name"/>
        <result property="className" column="class_name"/>
        <result property="categoryName" column="category_name"/>
        <result property="orgName" column="org_name"/>
        <result property="image" column="image"/>
        <result property="adminName" column="admin_name"/>
        <result property="isPass" column="is_pass"/>
        <result property="passTime" column="pass_time"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <select id="imageApplyPageDatas" resultType="com.template.model.vo.ImageApplyPageVo" resultMap="ImageApplyPageMap">
        select
        ai.id,au.name,au.college_name,au.period_name,au.major_name,au.class_name,ai.category_name,au.org_name,ai.image,ai.apply_user_name
        as admin_name,ai.is_pass,ai.pass_time,ai.create_time
        from alumni_image ai
        inner join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        <if test="userName != null and userName != ''">
            and au.name like '%' #{userName} '%'
        </if>
        <if test="orgName != null and orgName != ''">
            and au.org_name like '%' #{orgName} '%'
        </if>
        <if test="collegeId != null and collegeId != 0">
            and au.college_id = #{collegeId}
        </if>
        <if test="periodId != null and periodId != 0">
            and au.period_id = #{periodId}
        </if>
        <if test="majorId != null and majorId != 0">
            and au.major_id = #{majorId}
        </if>
        <if test="classId != null and classId != 0">
            and au.class_id = #{classId}
        </if>
        where ai.deleted = 0
        <if test="isPass != null and isPass != 0">
            and ai.is_pass =#{isPass}
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and ai.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="userId != null and userId != 0">
            and FIND_IN_SET(${userId},ai.apply_user)
        </if>
        order by ai.create_time desc
    </select>


    <resultMap type="com.template.model.vo.ImageMobilePageVo" id="ImageMobilePageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="collegeName" column="college_name"/>
        <result property="periodName" column="period_name"/>
        <result property="majorName" column="major_name"/>
        <result property="className" column="class_name"/>
        <result property="categoryName" column="category_name"/>
        <result property="orgName" column="org_name"/>
        <result property="image" column="image"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <select id="imageMobilePageDatas" resultType="com.template.model.vo.ImageMobilePageVo"
            resultMap="ImageMobilePageMap">
        select
        ai.id,au.name,au.college_name,au.period_name,au.major_name,au.class_name,ai.category_name,au.org_name,ai.image,ai.create_time
        from alumni_image ai
        inner join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        <if test="keyword != null and keyword != ''">
            and (au.name like '%' #{keyword} '%' or au.org_name like '%' #{keyword} '%')
        </if>
        where ai.deleted = 0
        and ai.is_pass = 2
        <if test="categoryId != null and categoryId != 0">
            and ai.category_id = #{categoryId}
        </if>
        <if test="keyword != null and keyword != ''">
            or ai.category_name like '%' #{keyword} '%'
        </if>
        order by ai.create_time desc
    </select>


    <resultMap type="com.template.model.vo.ImageMyPageVo" id="ImageMyPageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="image" column="image"/>
        <result property="isPass" column="is_pass"/>
        <result property="categoryName" column="category_name"/>
        <result property="createTime" column="create_time"/>
        <result property="passValue" column="pass_value"/>
    </resultMap>
    <select id="imageMyPageDatas" resultType="com.template.model.vo.ImageMyPageVo" resultMap="ImageMyPageMap">
        select ai.id,au.name,ai.is_pass,ai.category_name,ai.create_time,ai.image,ai.pass_value
        from alumni_image ai
        left join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        where ai.deleted = 0
        <if test="isPass != null and isPass != 0">
            and ai.is_pass =#{isPass}
        </if>
        <if test="userId != null and userId != 0">
            and ai.create_user =#{userId}
        </if>
        order by ai.create_time desc
    </select>


    <select id="imageMyApplyPageDatas" resultType="com.template.model.vo.ImageMyPageVo" resultMap="ImageMyPageMap">
        select ai.id,au.name,ai.is_pass,ai.category_name,ai.create_time,ai.image,ai.pass_value
        from alumni_image ai
        inner join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        <if test="name != null and name != 0">
            and au.name like '%' #{name} '%'
        </if>
        where ai.deleted = 0
        <if test="userId != null and userId != 0">
            and ai.create_user =#{userId}
        </if>
        order by ai.create_time desc
    </select>

    <select id="imageApproveApplyPageDatas" resultType="com.template.model.vo.ImageMyPageVo" resultMap="ImageMyPageMap">
        select ai.id,au.name,ai.is_pass,ai.category_name,ai.create_time,ai.image,ai.pass_value
        from alumni_image ai
        inner join alumni_user au on au.deleted = 0 and au.id = ai.create_user
        <if test="name != null and name != 0">
            and au.name like '%' #{name} '%'
        </if>
        where ai.deleted = 0 and ai.is_pass = 1
        <if test="userId != null and userId != 0">
            and FIND_IN_SET(${userId},ai.apply_user)
        </if>
        order by ai.create_time desc
    </select>
</mapper>
