liding
4 天以前 49e1bc66ebaf696ebd3fc3ed33d65c8795fd3cde
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -79,7 +79,7 @@
         AND date_format(u.create_time,'%Y%m%d') <= date_format(#{params.endTime},'%Y%m%d')
      </if>
      <if test="deptId != null and deptId != 0">
         AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
         AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE #{deptId} = ANY(string_to_array(t.ancestors, ',')::bigint[]) ))
      </if>
      <!-- 数据范围过滤 -->
      ${params.dataScope}
@@ -141,7 +141,54 @@
   <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
      select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
   </select>
   <select id="selectUserListAll" resultType="com.ruoyi.common.core.domain.entity.SysUser">
      select user_id, nick_name from sys_user where del_flag = '0'
   </select>
    <select id="selectList" resultType="com.ruoyi.common.core.domain.entity.SysUser">
      SELECT user_id, nick_name FROM sys_user
      <where>
         <if test="list != null and list.size() > 0">
            user_id IN
            <foreach item="id" collection="list" open="(" separator="," close=")">
               #{id}
            </foreach>
         </if>
         <if test="list == null or list.size() == 0">
            1=0  <!-- 空列表时返回空结果 -->
         </if>
      </where>
   </select>
    <select id="selectUsersByIds" resultType="com.ruoyi.common.core.domain.entity.SysUser">
      SELECT user_id, nick_name
      FROM sys_user
      WHERE user_id IN
      <foreach collection="userIds" item="id" open="(" separator="," close=")">
         #{id}
      </foreach>
   </select>
   <select id="selectBatchIds" resultType="com.ruoyi.common.core.domain.entity.SysUser">
      SELECT * FROM sys_user
      <!-- 处理空集合:若 userIds 为空,不执行 WHERE 条件(避免 SQL 语法错误) -->
      <where>
         <if test="userIds != null and userIds.size() > 0">
            user_id = ANY(
            <foreach collection="userIds" item="id" open="ARRAY[" separator="," close="]">
               #{id}
            </foreach>
            )
         </if>
      </where>
      <!-- 排序:按传入的 userIds 顺序返回结果(PostgreSQL 专用) -->
      <if test="userIds != null and userIds.size() > 0">
         ORDER BY array_position(
         <foreach collection="userIds" item="id" open="ARRAY[" separator="," close="]" index="index">
            #{id}
         </foreach>,
         user_id  -- 表中的 id 字段,与数组中的元素匹配
         )
      </if>
   </select>
   <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
       insert into sys_user(
          <if test="userId != null and userId != 0">user_id,</if>
@@ -170,7 +217,7 @@
          <if test="status != null and status != ''">#{status},</if>
          <if test="createBy != null and createBy != ''">#{createBy},</if>
          <if test="remark != null and remark != ''">#{remark},</if>
          sysdate()
          now()
       )
   </insert>
   
@@ -189,7 +236,7 @@
          <if test="loginDate != null">login_date = #{loginDate},</if>
          <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
          <if test="remark != null">remark = #{remark},</if>
          update_time = sysdate()
          update_time = now()
       </set>
       where user_id = #{userId}
   </update>