feat: 陪诊师入驻申请与审核链路
- 新增 attendant_application 表与 5 个接口:提交/我的申请/审核列表/ 材料大图/审批,/mine 注册在 /:id 之前 - 提交侧按员工档案岗位分支:在职陪诊师与管理员及其他岗位 409 拒绝, 转岗由管理员后台显式操作;停用陪诊师可重新申请 - 审批两步走不依赖事务:条件更新抢占 pending,ensureEmployee 单条 条件 upsert 幂等建档(只放行无档案或已有 attendant 档案), 失败靠 approvedEmployeeId 为空续跑 - 岗位冲突时申请单条件回滚为 pending,不卡死在"已通过但未建档" - employee.userId 加 partial unique 索引并移除 employeeNo 默认值, 附迁移与存量校验脚本;员工管理端绑定账号查重与 userIdSource 标记 - 证件照复用 parseImage(单张 3MB),入驻前缀放宽请求体上限; 索引创建失败改为记日志,避免启动即崩
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 只读体检:扫描 employee.userId 重复绑定,以及 profile.idNumber 重复。
|
||||
*
|
||||
* 上 unique 索引前必须先跑这个:库里已有重复时索引创建会直接失败,
|
||||
* 且重复档案需要人工裁决保留哪条(脚本只报告,不做任何写操作)。
|
||||
*
|
||||
* 用法(在 api/health 下):node scripts/check_employee_binding.js
|
||||
*/
|
||||
import { DBModel } from "../models/index.js";
|
||||
|
||||
DBModel.init();
|
||||
const conn = DBModel.dbConnection;
|
||||
|
||||
async function main() {
|
||||
const employees = conn.collection("employee");
|
||||
|
||||
// ---------- userId 重复 ----------
|
||||
const userDupes = await employees
|
||||
.aggregate([
|
||||
{ $match: { userId: { $ne: null } } },
|
||||
{ $group: { _id: "$userId", n: { $sum: 1 }, ids: { $push: "$_id" } } },
|
||||
{ $match: { n: { $gt: 1 } } },
|
||||
])
|
||||
.toArray();
|
||||
|
||||
console.log(`\n===== employee.userId 重复绑定 =====`);
|
||||
if (!userDupes.length) {
|
||||
console.log(" (none) 可安全创建 unique 索引");
|
||||
}
|
||||
for (const dupe of userDupes) {
|
||||
console.log(` userId=${dupe._id} 共 ${dupe.n} 条:${dupe.ids.join(", ")}`);
|
||||
// 列出每条的裁决参考信息:保留建议 = status=active 且 createtime 最新
|
||||
const docs = await employees
|
||||
.find({ userId: dupe._id })
|
||||
.project({
|
||||
role: 1,
|
||||
status: 1,
|
||||
name: "$profile.name",
|
||||
employeeNo: 1,
|
||||
createtime: "$meta.createtime",
|
||||
})
|
||||
.toArray();
|
||||
for (const doc of docs) {
|
||||
console.log(
|
||||
` - ${doc._id} role=${doc.role} status=${doc.status} name=${doc.name || "-"} no=${doc.employeeNo || "-"} created=${doc.createtime || "-"}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 身份证号重复(申请查重的数据前提) ----------
|
||||
const idDupes = await employees
|
||||
.aggregate([
|
||||
{ $match: { "profile.idNumber": { $exists: true, $ne: "" } } },
|
||||
{ $group: { _id: "$profile.idNumber", n: { $sum: 1 }, ids: { $push: "$_id" } } },
|
||||
{ $match: { n: { $gt: 1 } } },
|
||||
])
|
||||
.toArray();
|
||||
|
||||
console.log(`\n===== employee.profile.idNumber 重复 =====`);
|
||||
if (!idDupes.length) {
|
||||
console.log(" (none)");
|
||||
}
|
||||
for (const dupe of idDupes) {
|
||||
console.log(` idNumber=${dupe._id} 共 ${dupe.n} 条:${dupe.ids.join(", ")}`);
|
||||
}
|
||||
|
||||
// ---------- userId 为空串的脏数据 ----------
|
||||
// 字段定义无默认值,正常不该出现空串;有的话 unique partial 索引会漏掉它们
|
||||
const emptyUserId = await employees.countDocuments({ userId: "" });
|
||||
console.log(`\n===== userId 为空串的文档数 =====`);
|
||||
console.log(` ${emptyUserId}`);
|
||||
|
||||
console.log("\n(脚本只读,未做任何修改)");
|
||||
}
|
||||
|
||||
function run() {
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(() => conn.close());
|
||||
}
|
||||
|
||||
if (conn.readyState === 1) {
|
||||
run();
|
||||
} else {
|
||||
conn.once("connected", run);
|
||||
conn.once("error", (e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user