| | |
| | | </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 id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> |
| | | insert into sys_user( |
| | | <if test="userId != null and userId != 0">user_id,</if> |
| | | <if test="deptId != null and deptId != 0">dept_id,</if> |