feat(认证/通知): 单设备登录互踢 + 站内通知铃铛系统
- 单设备登录:登录成功即 last-login-wins 绑定 users.machine;非超管旧 token 在下一次受保护请求抛 4011 下线,超管豁免;仅认 token 内签名 deviceId,不用请求头。 前端两端接入踢下线跳转(?kicked=1 提示),V118 清空历史 machine - 站内通知:新增 notification 模块(任务失败扫描 / 密钥欠费 / 下游服务探测三类来源), 前后台铃铛组件 + 轮询;后台列表按主管数据范围(UserDataScopeSupport)过滤;V116 建表 均已于 2026-09-13 部署上线,此次补提交源码(此前仅存在于已部署 JAR/构建产物中)
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
package com.nanri.aiimage.modules.permission.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.nanri.aiimage.modules.permission.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.entity.ShopManageGroupEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 数据权限范围解析:由主管(admin)uid 得到其可见/管辖的用户 id 集合。
|
||||
* 与后台密钥管理页(UserApiSecretService.adminPage)同源规则:
|
||||
* 自己带的「数据权限分组」成员(组长本人 + 名下子账户),无分组记录时回退按「名下子账户」兜底。
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UserDataScopeSupport {
|
||||
|
||||
private static final int FALLBACK_LIMIT = 2000;
|
||||
|
||||
private final AdminUserMapper adminUserMapper;
|
||||
private final ShopManageGroupMapper shopManageGroupMapper;
|
||||
|
||||
/** 主管可见用户:自己 + 自己带的分组下的子账户(名下 users.created_by_id=自己)。 */
|
||||
public List<Long> resolveVisibleUserIds(Long operatorId) {
|
||||
if (operatorId == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<Long> ledGroupIds = listLedGroupIds(operatorId);
|
||||
Set<Long> userIds = new LinkedHashSet<>();
|
||||
for (Long groupId : ledGroupIds) {
|
||||
userIds.addAll(shopManageGroupMapper.selectUserIdsByGroupId(groupId));
|
||||
}
|
||||
// 没有分组记录的主管(历史数据)回退按「名下子账户」兜底,避免可见范围整体为空。
|
||||
if (userIds.isEmpty()) {
|
||||
adminUserMapper.selectList(new LambdaQueryWrapper<AdminUserEntity>()
|
||||
.eq(AdminUserEntity::getCreatedById, operatorId)
|
||||
.last("limit " + FALLBACK_LIMIT))
|
||||
.forEach(user -> {
|
||||
if (user.getId() != null) {
|
||||
userIds.add(user.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
userIds.add(operatorId);
|
||||
return new ArrayList<>(userIds);
|
||||
}
|
||||
|
||||
/** 主管带的分组 ID(created_by_id / user_id = 自己)。 */
|
||||
public List<Long> listLedGroupIds(Long operatorId) {
|
||||
if (operatorId == null) {
|
||||
return List.of();
|
||||
}
|
||||
return shopManageGroupMapper.selectLedGroups(operatorId).stream()
|
||||
.map(ShopManageGroupEntity::getId)
|
||||
.filter(id -> id != null && id > 0)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user