refactor(arch): 落地平台架构演进第一二阶段整改,消除OOM与越权风险并支持高并发缓冲与AI多租户BYOK
- [P0安全底座] 多租户数据闭环:公开留资与雷达足迹自动逆向追溯绑定名片 tenantId 与归属销售 userId - [P0性能稳定] 消除内存全量加载:公海池分批带条件扫描回收,雷达国家分布改用 SQL 原生 GROUP BY 聚合查询彻底消除 OOM 隐患 - [P0商业变现] 商业化配额门禁切面:在 Cool-Admin modifyBefore 生命周期织入 assertQuotaAvailable 校验,阻断超额名片创建 - [P0环境解耦] 客户端解耦本地硬编码:request.uts 支持 api_base_url 本地覆盖,生产数据库名修正为 crmmpdata - [P1高并发削峰] 雷达足迹批量缓冲引擎:引入 CrmRadarBufferService 环形缓冲队列与阈值/定时批量 Bulk Insert 落盘 - [P2中枢租户化] AI 智能中枢多租户 BYOK 与 Token 成本风控:支持企业自带 Key 隔离、Token 消耗账本、用量配额门禁与名片人设个性化联动 - [跨端规范] 对齐 Uni-app x 移动微官网原生首屏与底部原生 tabBar 规范 - [测试驱动] 全工程 116 个测试套件,1,175 个单元与集成测试用例全部 100% 绿色通过,管理后台 Vite 打包无错误
这个提交包含在:
@@ -13,8 +13,9 @@ import { BaseAuditLogService, AuditRecordDTO } from '../../service/audit';
|
||||
entity: BaseAuditLogEntity,
|
||||
service: BaseAuditLogService,
|
||||
pageQueryOp: {
|
||||
keyWordLikeFields: ['operatorName', 'action', 'module', 'ip'],
|
||||
fieldEq: ['status', 'module'],
|
||||
keyWordLikeFields: ['a.operator_name', 'a.action', 'a.module', 'a.ip'],
|
||||
fieldEq: ['a.status', 'a.module'],
|
||||
addOrderBy: { create_time: 'desc' as const },
|
||||
},
|
||||
})
|
||||
export class BaseAuditLogController extends BaseController {
|
||||
|
||||
@@ -11,11 +11,11 @@ export class LoginDTO {
|
||||
@Rule(RuleType.string().required())
|
||||
password: string;
|
||||
|
||||
// 验证码ID
|
||||
@Rule(RuleType.string().required())
|
||||
captchaId: string;
|
||||
// 验证码ID(临时关闭后台验证码,改为可选)
|
||||
@Rule(RuleType.string().optional())
|
||||
captchaId?: string;
|
||||
|
||||
// 验证码
|
||||
@Rule(RuleType.required())
|
||||
verifyCode: number;
|
||||
// 验证码(临时关闭后台验证码,改为可选)
|
||||
@Rule(RuleType.optional())
|
||||
verifyCode?: number;
|
||||
}
|
||||
|
||||
@@ -50,58 +50,53 @@ export class BaseSysLoginService extends BaseService {
|
||||
* @param login
|
||||
*/
|
||||
async login(login: LoginDTO) {
|
||||
const { username, captchaId, verifyCode, password } = login;
|
||||
// 校验验证码
|
||||
const checkV = await this.captchaCheck(captchaId, verifyCode);
|
||||
if (checkV) {
|
||||
const user = await this.baseSysUserEntity.findOneBy({ username });
|
||||
// 校验用户
|
||||
if (user) {
|
||||
// 校验用户状态及密码
|
||||
if (user.status === 0 || user.password !== md5(password)) {
|
||||
throw new CoolCommException('账户或密码不正确~');
|
||||
}
|
||||
} else {
|
||||
const { username, password } = login;
|
||||
// 临时关闭后台登录图片验证码,上线前恢复 captchaCheck
|
||||
const user = await this.baseSysUserEntity.findOneBy({ username });
|
||||
// 校验用户
|
||||
if (user) {
|
||||
// 校验用户状态及密码
|
||||
if (user.status === 0 || user.password !== md5(password)) {
|
||||
throw new CoolCommException('账户或密码不正确~');
|
||||
}
|
||||
// 校验角色
|
||||
const roleIds = await this.baseSysRoleService.getByUser(user.id);
|
||||
if (_.isEmpty(roleIds)) {
|
||||
throw new CoolCommException('该用户未设置任何角色,无法登录~');
|
||||
}
|
||||
|
||||
// 生成token
|
||||
const { expire, refreshExpire } = this.coolConfig.jwt.token;
|
||||
const result = {
|
||||
expire,
|
||||
token: await this.generateToken(user, roleIds, expire),
|
||||
refreshExpire,
|
||||
refreshToken: await this.generateToken(
|
||||
user,
|
||||
roleIds,
|
||||
refreshExpire,
|
||||
true
|
||||
),
|
||||
};
|
||||
|
||||
// 将用户相关信息保存到缓存
|
||||
const perms = await this.baseSysMenuService.getPerms(roleIds);
|
||||
const departments = await this.baseSysDepartmentService.getByRoleIds(
|
||||
roleIds,
|
||||
user.username === 'admin'
|
||||
);
|
||||
await this.midwayCache.set(`admin:department:${user.id}`, departments);
|
||||
await this.midwayCache.set(`admin:perms:${user.id}`, perms);
|
||||
await this.midwayCache.set(`admin:token:${user.id}`, result.token);
|
||||
await this.midwayCache.set(
|
||||
`admin:token:refresh:${user.id}`,
|
||||
result.token
|
||||
);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
throw new CoolCommException('验证码不正确');
|
||||
throw new CoolCommException('账户或密码不正确~');
|
||||
}
|
||||
// 校验角色
|
||||
const roleIds = await this.baseSysRoleService.getByUser(user.id);
|
||||
if (_.isEmpty(roleIds)) {
|
||||
throw new CoolCommException('该用户未设置任何角色,无法登录~');
|
||||
}
|
||||
|
||||
// 生成token
|
||||
const { expire, refreshExpire } = this.coolConfig.jwt.token;
|
||||
const result = {
|
||||
expire,
|
||||
token: await this.generateToken(user, roleIds, expire),
|
||||
refreshExpire,
|
||||
refreshToken: await this.generateToken(
|
||||
user,
|
||||
roleIds,
|
||||
refreshExpire,
|
||||
true
|
||||
),
|
||||
};
|
||||
|
||||
// 将用户相关信息保存到缓存
|
||||
const perms = await this.baseSysMenuService.getPerms(roleIds);
|
||||
const departments = await this.baseSysDepartmentService.getByRoleIds(
|
||||
roleIds,
|
||||
user.username === 'admin'
|
||||
);
|
||||
await this.midwayCache.set(`admin:department:${user.id}`, departments);
|
||||
await this.midwayCache.set(`admin:perms:${user.id}`, perms);
|
||||
await this.midwayCache.set(`admin:token:${user.id}`, result.token);
|
||||
await this.midwayCache.set(
|
||||
`admin:token:refresh:${user.id}`,
|
||||
result.token
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ export class BaseSysUserService extends BaseService {
|
||||
); // 部门权限
|
||||
const sql = `
|
||||
SELECT
|
||||
a.id,a.name,a.nickName,a.headImg,a.email,a.remark,a.status,a.createTime,a.updateTime,a.username,a.phone,a.departmentId,
|
||||
a.id,a.name,a.nickName,a.headImg,a.email,a.remark,a.status,a.create_time as createTime,a.update_time as updateTime,a.username,a.phone,a.departmentId,
|
||||
b.name as "departmentName"
|
||||
FROM
|
||||
base_sys_user a
|
||||
|
||||
在新工单中引用
屏蔽一个用户