WOUAFIX 收口 OA 与企微用户一致性差异

这个提交包含在:
2026-05-19 00:35:50 +08:00
父节点 c8884bb372
当前提交 56a1fc3b1d
共修改 19 个文件,包含 1034 行新增和 51 行删除
+35 -1
查看文件
@@ -208,10 +208,23 @@ async function ensureAdminEmployee(prisma, params) {
const existing = await prisma.employee.findFirst({
where: { OR: [{ email: params.email }, { phone: params.phone }] },
select: { id: true, email: true, phone: true, status: true },
select: { id: true, employee_no: true, email: true, phone: true, status: true, archived_at: true },
});
if (existing) {
if ((existing.status === "archived" || existing.archived_at) && process.env.TRIALRUN_ADMIN_REACTIVATE_ARCHIVED !== "1") {
const fallbackAdmin = await findActiveAdminEmployee(prisma, existing.id);
if (fallbackAdmin) {
return {
employeeId: fallbackAdmin.id,
created: false,
password: null,
skippedArchived: true,
fallbackEmployeeNo: fallbackAdmin.employee_no,
};
}
}
await prisma.employee.update({
where: { id: existing.id },
data: {
@@ -278,6 +291,23 @@ async function ensureAdminEmployee(prisma, params) {
return { employeeId: employee.id, created: true, password };
}
async function findActiveAdminEmployee(prisma, excludedEmployeeId) {
const where = {
status: "active",
archived_at: null,
roles: { some: { role_code: "admin" } },
};
if (excludedEmployeeId) {
where.id = { not: excludedEmployeeId };
}
return prisma.employee.findFirst({
where,
orderBy: { employee_no: "asc" },
select: { id: true, employee_no: true },
});
}
async function main() {
const adminEmail = requiredEnv("TRIALRUN_ADMIN_EMAIL");
const adminPhone = requiredEnv("TRIALRUN_ADMIN_PHONE");
@@ -326,6 +356,10 @@ async function main() {
console.log(`- created: ${result.created}`);
// eslint-disable-next-line no-console
console.log(`- force_on flags: ${forceOnFlags.join(", ")}`);
if (result.skippedArchived) {
// eslint-disable-next-line no-console
console.log(`- archived trialrun admin: kept archived; active admin fallback: ${result.fallbackEmployeeNo}`);
}
if (result.password) {
// eslint-disable-next-line no-console
console.log(`- one-time password: ${result.password}`);