123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582 |
- <?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="cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper">
- <select id="selectPageForGraduate" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
- SELECT
- a.*,
- COALESCE(
- (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
- 1
- ) AS is_graduate,
- CASE
- WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
- ELSE 0
- END AS photoIsExist,
- COALESCE(system_dept.name, "测绘学院") AS deptName,
- supervisor_user.nickname as supervisor,
- supervisor_user.mobile as supervisorMobile
- FROM
- system_users a
- LEFT JOIN
- system_user_achievement ua ON ua.user_id = a.id
- LEFT JOIN
- system_users supervisor_user
- ON supervisor_user.id = a.supervisor_id
- AND supervisor_user.deleted = 0
- LEFT JOIN
- system_dept system_dept ON system_dept.id = a.dept_id
- WHERE
- 1=1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
- <if test="gradePrefix != ''">
- AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
- </if>
- <if test="reqVO.supervisorId != null">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null">
- AND a.status = #{reqVO.status}
- </if>
- <if test="deptIds != null and !deptIds.isEmpty()">
- AND a.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </if>
- <choose>
- <when test="type == 0">
- AND a.user_type = 1
- </when>
- <when test="type == 1">
- AND a.user_type = 1
- AND (
- ( a.dept_id != 0
- AND a.dept_id = #{deptId}
- AND a.dept_id IS NOT NULL
- AND a.dept_id != ''
- )
- OR (
- a.supervisor_id = #{loginId}
- AND a.supervisor_id IS NOT NULL
- AND a.supervisor_id != ''
- )
- )
- </when>
- </choose>
- <if test="reqVO.isGraduate != null">
- <if test="reqVO.isGraduate == 1">
- AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
- </if>
- <if test="reqVO.isGraduate == 0">
- AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
- AND ua.is_graduate = 0
- </if>
- </if>
- <if test="reqVO.photoIsExist != null">
- <if test="reqVO.photoIsExist == 0">
- AND a.photo_url IS NULL
- </if>
- <if test="reqVO.photoIsExist == 1">
- AND a.photo_url IS NOT NULL AND a.photo_url != ''
- </if>
- </if>
- AND a.deleted = 0
- GROUP BY
- a.id
- ORDER BY
- a.id DESC
- <if test="offset != -1">
- LIMIT #{offset}, #{reqVO.pageSize}
- </if>
- </select>
- <select id="selectPage1Count" resultType="Long">
- SELECT COUNT(*) AS total_count
- FROM (
- SELECT a.id
- FROM system_users a
- LEFT JOIN system_user_achievement ua ON ua.user_id = a.id
- WHERE 1=1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
- <if test="gradePrefix != ''">
- AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
- </if>
- <if test="reqVO.supervisorId != null">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null">
- AND a.status = #{reqVO.status}
- </if>
- <if test="deptIds != null and !deptIds.isEmpty()">
- AND a.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </if>
- <choose>
- <when test="type == 0">
- AND a.user_type = 1
- </when>
- <when test="type == 1">
- AND a.user_type = 1
- AND (
- ( a.dept_id != 0
- AND a.dept_id = #{deptId}
- AND a.dept_id IS NOT NULL
- AND a.dept_id != ''
- )
- OR (
- a.supervisor_id = #{loginId}
- AND a.supervisor_id IS NOT NULL
- AND a.supervisor_id != ''
- )
- )
- </when>
- </choose>
- <if test="reqVO.isGraduate != null">
- <if test="reqVO.isGraduate == 1">
- AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
- </if>
- <if test="reqVO.isGraduate == 0">
- AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
- AND ua.is_graduate = 0
- </if>
- </if>
- <if test="reqVO.photoIsExist != null">
- <if test="reqVO.photoIsExist == 0">
- AND a.photo_url IS NULL
- </if>
- <if test="reqVO.photoIsExist == 1">
- AND a.photo_url IS NOT NULL AND a.photo_url != ''
- </if>
- </if>
- AND a.deleted = 0
- GROUP BY a.id
- ) AS subquery;
- </select>
- <select id="selectList1" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
- SELECT
- a.*,
- COALESCE(
- (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
- 1
- ) AS is_graduate,
- CASE
- WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
- ELSE 0
- END AS photoIsExist,
- COALESCE(system_dept.name, "测绘学院") AS deptName,
- supervisor_user.nickname as supervisor,
- supervisor_user.mobile as supervisorMobile
- FROM
- system_users a
- LEFT JOIN
- system_user_achievement ua ON ua.user_id = a.id
- LEFT JOIN
- system_users supervisor_user
- ON supervisor_user.id = a.supervisor_id
- AND supervisor_user.deleted = 0
- LEFT JOIN
- system_dept system_dept ON system_dept.id = a.dept_id
- WHERE
- 1=1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
- <if test="gradePrefix != ''">
- AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
- </if>
- <if test="reqVO.supervisorId != null">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null">
- AND a.status = #{reqVO.status}
- </if>
- <if test="deptIds != null and !deptIds.isEmpty()">
- AND a.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </if>
- <if test="roleIds != null and roleIds.contains(113L)">
- AND a.supervisor_id =#{loginId}
- AND a.user_type = 1
- </if>
- <if test="roleIds != null and roleIds.contains(114L)">
- AND a.user_type = 1
- </if>
- <if test="roleIds != null and roleIds.contains(1L)">
- AND a.user_type IN (1, 2)
- </if>
- <if test="reqVO.isGraduate != null">
- <if test="reqVO.isGraduate == 1">
- AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
- </if>
- <if test="reqVO.isGraduate == 0">
- AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
- AND ua.is_graduate = 0
- </if>
- </if>
- <if test="reqVO.photoIsExist != null">
- <if test="reqVO.photoIsExist == 0">
- AND a.photo_url IS NULL
- </if>
- <if test="reqVO.photoIsExist == 1">
- AND a.photo_url IS NOT NULL AND a.photo_url != ''
- </if>
- </if>
- AND a.deleted = 0
- GROUP BY
- a.id
- ORDER BY
- a.id
- </select>
- <select id="selectAllList" resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
- SELECT
- a.*,
- COALESCE(
- (SELECT MIN(ua.is_graduate) FROM system_user_achievement ua WHERE ua.user_id = a.id),
- 1
- ) AS is_graduate,
- CASE
- WHEN a.photo_url IS NOT NULL AND TRIM(a.photo_url) != '' THEN 1
- ELSE 0
- END AS photoIsExist,
- COALESCE(system_dept.name, "测绘学院") AS deptName,
- supervisor_user.nickname as supervisor,
- supervisor_user.mobile as supervisorMobile
- FROM
- system_users a
- LEFT JOIN
- system_user_achievement ua ON ua.user_id = a.id
- LEFT JOIN
- system_users supervisor_user
- ON supervisor_user.id = a.supervisor_id
- AND supervisor_user.deleted = 0
- LEFT JOIN
- system_dept system_dept ON system_dept.id = a.dept_id
- WHERE
- 1=1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <bind name="gradePrefix" value="reqVO.grade != null and reqVO.grade.length() >= 4 ? reqVO.grade.substring(0, 4) : ''"/>
- <if test="gradePrefix != ''">
- AND a.grade LIKE CONCAT('%', #{gradePrefix}, '%')
- </if>
- <if test="reqVO.supervisorId != null">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null">
- AND a.status = #{reqVO.status}
- </if>
- <if test="deptIds != null and !deptIds.isEmpty()">
- AND a.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </if>
- <if test="reqVO.isGraduate != null">
- <if test="reqVO.isGraduate == 1">
- AND a.id NOT IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = 0)
- </if>
- <if test="reqVO.isGraduate == 0">
- AND a.id IN (SELECT user_id FROM system_user_achievement WHERE user_id = a.id AND is_graduate = #{reqVO.isGraduate})
- AND ua.is_graduate = 0
- </if>
- </if>
- <if test="reqVO.photoIsExist != null">
- <if test="reqVO.photoIsExist == 0">
- AND a.photo_url IS NULL
- </if>
- <if test="reqVO.photoIsExist == 1">
- AND a.photo_url IS NOT NULL AND a.photo_url != ''
- </if>
- </if>
- AND a.deleted = 0
- GROUP BY
- a.id
- ORDER BY
- a.id
- </select>
- <select id="getIsPassedStudentsPage" resultType="cn.iocoder.yudao.module.system.controller.admin.user.vo.user.StudentProjectRespVO">
- SELECT
- a.*,r.id,r.project_id,r.supervisor_id,
- CASE
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
- ELSE 0 -- 其他情况
- END AS selectStatus,
- -- 计算 selectStatus 为 1 或 2 的记录 id
- CASE
- WHEN COALESCE(MAX(r.select_type), null) IN (1, 2) THEN r.id
- ELSE NULL
- END AS recordId,
- COALESCE(system_dept.name, "测绘学院") AS deptName,
- supervisor_user.nickname AS supervisor,
- supervisor_user.mobile AS supervisorMobile,
- externalSupervisor_user.nickname AS externalSupervisor,
- selectSupervisor_user.nickname AS selectSupervisor,
- r.supervisor_id AS selectSupervisorId
- FROM
- system_users a
- LEFT JOIN
- student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0 AND r.project_id = #{projectId}
- LEFT JOIN
- system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
- LEFT JOIN
- system_users externalSupervisor_user ON externalSupervisor_user.id = a.external_supervisor_id AND externalSupervisor_user.deleted = 0
- LEFT JOIN
- system_users selectSupervisor_user ON selectSupervisor_user.id = a.id AND selectSupervisor_user.deleted = 0
- LEFT JOIN
- system_dept system_dept ON system_dept.id = a.dept_id
- WHERE
- 1=1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <if test="reqVO.grade != '' and reqVO.grade != null ">
- AND a.grade = #{reqVO.grade}
- </if>
- <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null and reqVO.major != '' ">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null and reqVO.masterType != '' ">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null and reqVO.status != '' ">
- AND a.status = #{reqVO.status}
- </if>
- AND a.deleted = 0
- GROUP BY
- a.id
- <!-- 合并 HAVING 子句 -->
- HAVING
- CASE
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
- ELSE 0
- END
- <choose>
- <when test="isPassed == 0">IN (0, 1)</when>
- <when test="isPassed == 1">= 2</when>
- </choose>
- ORDER BY
- a.id DESC
- <if test="offset != -1">
- LIMIT #{offset}, #{reqVO.pageSize}
- </if>
- </select>
- <select id="getIsPassedStudentsPageCount" resultType="Long">
- SELECT COUNT(*) AS total_count
- FROM (
- SELECT a.id
- FROM system_users a
- LEFT JOIN student_select_supervisor_record r ON r.student_id = a.id AND r.deleted = 0 AND r.project_id = #{projectId}
- LEFT JOIN system_users supervisor_user ON supervisor_user.id = a.supervisor_id AND supervisor_user.deleted = 0
- LEFT JOIN system_users externalSupervisor_user ON externalSupervisor_user.id = a.external_supervisor_id AND externalSupervisor_user.deleted = 0
- LEFT JOIN system_users selectSupervisor_user ON selectSupervisor_user.id = a.id AND selectSupervisor_user.deleted = 0
- LEFT JOIN system_dept system_dept ON system_dept.id = a.dept_id
- WHERE 1 = 1
- <if test="reqVO.username != null and reqVO.username != ''">
- AND a.username LIKE CONCAT('%', #{reqVO.username}, '%')
- </if>
- <if test="reqVO.email != null and reqVO.email != ''">
- AND a.email LIKE CONCAT('%', #{reqVO.email}, '%')
- </if>
- <if test="reqVO.mobile != null and reqVO.mobile != ''">
- AND a.mobile LIKE CONCAT('%', #{reqVO.mobile}, '%')
- </if>
- <if test="reqVO.userNumber != null and reqVO.userNumber != ''">
- AND a.user_number LIKE CONCAT('%', #{reqVO.userNumber}, '%')
- </if>
- <if test="reqVO.nickname != null and reqVO.nickname != ''">
- AND a.nickname LIKE CONCAT('%', #{reqVO.nickname}, '%')
- </if>
- <if test="reqVO.userType != null">
- AND a.user_type = #{reqVO.userType}
- </if>
- <if test="reqVO.grade != '' and reqVO.grade != null ">
- AND a.grade = #{reqVO.grade}
- </if>
- <if test="reqVO.supervisorId != null and reqVO.supervisorId != '' ">
- AND a.supervisor_id = #{reqVO.supervisorId}
- </if>
- <if test="reqVO.major != null and reqVO.major != '' ">
- AND a.major = #{reqVO.major}
- </if>
- <if test="reqVO.masterType != null and reqVO.masterType != '' ">
- AND a.masterType = #{reqVO.masterType}
- </if>
- <if test="reqVO.status != null and reqVO.status != '' ">
- AND a.status = #{reqVO.status}
- </if>
- AND a.deleted = 0
- GROUP BY a.id
- <!-- 合并 HAVING 条件 -->
- HAVING
- CASE
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 2 THEN 1 ELSE 0 END),0) = 1 THEN 2 -- 如果有 2
- WHEN COALESCE(MAX(CASE WHEN r.select_type = 1 THEN 1 ELSE 0 END),0) = 1 THEN 1 -- 如果没有 2,但有 1
- ELSE 0
- END
- <choose>
- <when test="isPassed == 0">IN (0, 1)</when>
- <when test="isPassed == 1">= 2</when>
- </choose>
- ) AS subquery;
- </select>
- </mapper>
|