jeecgboot/JeecgBoot · warning · JeecgBootException
{realnames}已存在该职位中
Error message
{realnames}已存在该职位中 What it means
Thrown by SysUserPositionServiceImpl when batch-adding users to a position. It collects userIds that already have a user-position row into userBuilder, then resolves their realnames and reports which users are already in the position.
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserPositionServiceImpl.java:66
//获取成员是否存在于职位中
Long count = sysUserPositionMapper.getUserPositionCount(userId, positionId);
if (count == 0) {
//插入到用户职位关系表里面
SysUserPosition userPosition = new SysUserPosition();
userPosition.setPositionId(positionId);
userPosition.setUserId(userId);
sysUserPositionMapper.insert(userPosition);
} else {
userBuilder.append(userId).append(SymbolConstant.COMMA);
}
}
//如果用户id存在,说明已存在用户职位关系表中,提示用户已存在
String uIds = userBuilder.toString();
if (oConvertUtils.isNotEmpty(uIds)) {
//查询用户列表
List<SysUser> sysUsers = userMapper.selectBatchIds(Arrays.asList(uIds.split(SymbolConstant.COMMA)));
String realnames = sysUsers.stream().map(SysUser::getRealname).collect(Collectors.joining(SymbolConstant.COMMA));
throw new JeecgBootException(realnames + "已存在该职位中");
}
}
@Override
public void removeByPositionId(String positionId) {
sysUserPositionMapper.removeByPositionId(positionId);
}
@Override
public void removePositionUser(String userIds, String positionId) {
String[] userIdArray = userIds.split(SymbolConstant.COMMA);
sysUserPositionMapper.removePositionUser(Arrays.asList(userIdArray),positionId);
}
}
View on GitHub (pinned to 96fb33f5ec)
Solutions
- Filter the request client-side to exclude userIds already in the position before submitting.
- On the server, treat already-present as idempotent success instead of error if business allows.
- Check the returned realnames against the intended add list and retry with only the missing users.
- Remove duplicate userIds from the request payload.
Example fix
// before: server throws on any existing user addUsersToPosition(allUserIds, positionId); // after: pre-filter existing members List<String> existing = userPositionMapper.selectExistingUserIds(positionId); List<String> toAdd = allUserIds.stream().filter(id -> !existing.contains(id)).collect(toList()); addUsersToPosition(toAdd, positionId);
Defensive patterns
Strategy: validation
Validate before calling
List<String> existing = userPositionMapper.selectExistingUserIds(positionId);
List<String> toAdd = userIds.stream().filter(id -> !existing.contains(id)).collect(Collectors.toList());
if (toAdd.isEmpty()) return Result.ok("无新增用户"); Type guard
boolean hasNewMembers(List<String> userIds, String positionId) {
List<String> existing = userPositionMapper.selectExistingUserIds(positionId);
return userIds.stream().anyMatch(id -> !existing.contains(id));
} Try / catch
try { userPositionService.addUsers(userIds, positionId); }
catch (JeecgBootException e) {
if (e.getMessage().contains("已存在该职位")) return Result.ok("部分用户已存在: " + e.getMessage());
throw e;
} Prevention
- Filter out existing members client-side before submit.
- Refresh the position's member list after each add.
- Consider idempotent semantics for re-adds.
When it happens
Trigger: POST to add-user-to-position with a userIds list containing one or more userIds that already exist in sys_user_position for the given positionId.
Common situations: Admin re-adds users already in the position; a previous add partially succeeded and was retried; duplicate userIds in the request; stale client-side state showing users as not-yet-added.
Related errors
- 【addComponent】组件"${type}"已存在
- 模板缺少参数:${item}
- The file name can not null
- 非法存储路径,路径包含遍历字符: {storePath}
- url 不能为空
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/fcd77f3a3babcb18.
Report an issue: GitHub.