123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?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="selectPage1" 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 -- 自连接获取 supervisor 的信息
- 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 != null and reqVO.grade != ''">
- AND a.grade LIKE CONCAT('%', #{reqVO.grade.substring(0, 4)}, '%')
- </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.dept_id = #{deptId}
- 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>
- GROUP BY
- a.id
- ORDER BY
- a.id DESC
- LIMIT #{offset}, #{reqVO.pageSize}
- </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>
- <if test="reqVO.grade != null and reqVO.grade != ''">
- AND a.grade LIKE CONCAT('%', #{reqVO.grade.substring(0, 4)}, '%')
- </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.dept_id = #{deptId}
- 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.dept_id 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>
- GROUP BY a.id
- ) AS subquery;
- </select>
- </mapper>
|