MemberMapper.xml 8.26 KB
<?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.subsidy.mapper.MemberMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.subsidy.model.MemberDO">
        <id column="id" property="id"/>
        <result column="create_date" property="createDate"/>
        <result column="update_date" property="updateDate"/>
        <result column="delete_date" property="deleteDate"/>
        <result column="user_name" property="userName"/>
        <result column="telephone" property="telephone"/>
        <result column="password" property="password"/>
        <result column="gender" property="gender"/>
        <result column="image" property="image"/>
        <result column="id_card" property="idCard"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, user_name, telephone, password, gender, image, id_card
    </sql>

    <select id="passwordLogin" parameterType="com.subsidy.dto.member.PasswordLoginDTO"
            resultType="com.subsidy.vo.administer.UserRoleVO">
        SELECT
            t.id,
            t.telephone,
            t.user_name,
            t.image,
            t.status,
            t.first_login,
            t.password
        FROM
            member t
        WHERE
            t.delete_date IS NULL
            AND t.account_name = #{accountName}
            AND t.company_id =#{companyId}
    </select>

    <select id="studyPage" parameterType="com.subsidy.model.MemberDO" resultType="com.subsidy.vo.member.StudyPageVO">
        SELECT
            t3.id,
            t2.id as classId,
            t3.course_name,
            t2.end_date,
            t2.class_name
        FROM
            class_member_mapping t
            LEFT JOIN class_dict t2 ON t.class_id = t2.id
            left join course_dict t3 on t2.course_id = t3.id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            and t3.delete_date is null
            AND t.member_id = #{id}
    </select>

    <select id="myCourses" parameterType="long" resultType="com.subsidy.vo.member.MyCoursesVO">
        SELECT
        t3.id AS courseId,
        t2.id AS classId,
        t2.class_name,
        t3.course_name,
        t2.end_date,
        t4.cnt AS totalCnt,
        t5.result AS studyCnt,
        t6.ttlMember,
        if(
        TIMESTAMPDIFF(
        DAY,
        DATE_FORMAT( NOW(), '%Y-%m-%d' ),
        t2.end_date)>0,TIMESTAMPDIFF(
        DAY,
        DATE_FORMAT( NOW(), '%Y-%m-%d' ),
        t2.end_date),0) AS diffDate
        FROM
        class_member_mapping t
        LEFT JOIN ( SELECT t.class_id, count( 1 ) ttlMember FROM class_member_mapping t WHERE t.delete_date IS NULL
        GROUP BY t.class_id ) t6 ON t.class_id = t6.class_id
        LEFT JOIN class_dict t2 ON t.class_id = t2.id
        LEFT JOIN course_dict t3 ON t2.course_id = t3.id
        LEFT JOIN (
        SELECT
        t.course_id,
        count( 1 ) AS cnt
        FROM
        course_content t
        LEFT JOIN vod_dict t2 ON t.id = t2.content_id
        WHERE
        t.delete_date IS NULL
        AND t2.delete_date IS NULL
        GROUP BY
        t.course_id
        ) t4 ON t3.id = t4.course_id
        LEFT JOIN (
        SELECT
        t1.member_id,
        t1.class_id,
        sum( result ) AS result
        FROM
        (
        SELECT
        t.member_id,
        t.vod_id,
        t.class_id,
        sum( t.play_length ) AS play_length,
        t2.vod_length,
        IF
        ( sum( t.play_length )>= t2.vod_length, 1, 0 ) AS result
        FROM
        vod_play_history t
        LEFT JOIN vod_dict t2 ON t.vod_id = t2.id
        WHERE
        t.member_id = #{memberId}
        GROUP BY
        t.member_id,
        t.vod_id,
        t.class_id
        ) t1
        GROUP BY
        t1.member_id,
        t1.class_id
        ) t5 ON t.class_id = t5.class_id
        AND t.member_id = t5.member_id
        WHERE
        t.delete_date IS NULL
        AND t2.delete_date IS NULL
        AND t3.delete_date IS NULL
        AND t.member_id = #{memberId}
        <if test="status ==1">
            AND now()>= start_date
            AND now() &lt; end_date
        </if>
        <if test="status ==2">
            AND now() &lt; start_date
        </if>
        <if test="status ==3">
            AND now() > end_date
        </if>
        order by t2.end_date desc
    </select>


    <select id="getDepartments" parameterType="long" resultType="com.subsidy.model.DepartmentDictDO">
        SELECT
            t2.id,
            t2.department_name,
            t2.parent_id
        FROM
            member_department_mapping t
            LEFT JOIN department_dict t2 ON t.department_id = t2.id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            AND t.member_id = #{memberId}
    </select>

    <select id="getMembers" resultType="com.subsidy.vo.member.GetAllVO">
        SELECT
        t2.id,
        t2.user_name,
        t2.account_name,
        t2.account_name_en,
        t2.telephone,
        t2.gender,
        t2.id_card,
        t2.status
        FROM
        member_department_mapping t
        LEFT JOIN member t2 ON t.member_id = t2.id
        WHERE
        t.delete_date IS NULL
        AND t2.delete_date IS NULL
        and t.department_id = #{departmentId}
        <if test="userName != null and userName !=''">
            and t2.user_name like concat('%',#{userName} ,'%')
        </if>
        <if test="status != null and status !=''">
            and t2.status = #{status}
        </if>
    </select>

    <select id="manageMember" parameterType="string" resultType="com.subsidy.vo.administer.ManageMemberVO">
        SELECT
            t.id,
            t.user_name,
            t.telephone,
            t.id_card,
            t.account_name,
            t2.company_name
        FROM
            member t
            LEFT JOIN company_dict t2 ON t.company_id = t2.id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            <if test="userName != null and userName != ''">
                AND t.user_name LIKE concat('%',#{userName} ,'%')
            </if>
            <if test="companyId != null and companyId != ''">
                and t.company_id = #{companyId}
            </if>
    </select>

    <select id="getMemberList" resultType="com.subsidy.model.MemberDO">
        select
            m.*
        from member m
        left join class_member_mapping cmm on cmm.member_id = m.id
        where cmm.class_id = #{classId}
        and m.delete_date is null
        and cmm.delete_date is null
    </select>

    <select id="getMemberListBySignInRecord" resultType="com.subsidy.model.MemberDO">
        SELECT
            m.*
        FROM
            member m
            LEFT JOIN class_member_mapping cmm ON cmm.member_id = m.id
            LEFT JOIN ( SELECT member_id, count( id ) AS signInCount FROM sign_in_record WHERE class_id = #{classId} AND delete_date IS NULL GROUP BY member_id ) s ON s.member_id = m.id
        WHERE
            cmm.class_id = #{classId}
          AND m.delete_date IS NULL
          AND cmm.delete_date IS NULL
          AND s.signInCount > 0
        GROUP BY
            m.id
    </select>

    <select id="getUnfinishedMemberList" resultType="com.subsidy.model.MemberDO">
        SELECT
            m.*
        FROM
            member m
            LEFT JOIN class_member_mapping cmm ON cmm.member_id = m.id
            LEFT JOIN (
                SELECT
                    vph.member_id,
                    vph.class_id,
                    vd.vod_length,
                    IF
                        ( sum( vph.play_length ) >= vd.vod_length, 1, 0 ) AS ps
                FROM
                    vod_play_history vph
                    LEFT JOIN vod_dict vd ON vd.id = vph.vod_id
                WHERE
                  vph.delete_date IS NULL
                  AND vd.delete_date IS NULL
                GROUP BY
                    vod_id,
                    member_id
            ) h ON h.member_id = m.id
                AND h.class_id = cmm.class_id
        WHERE
          cmm.class_id = #{classId}
          AND h.ps = 0
        GROUP BY
            m.id
    </select>
</mapper>