feat(training): 新增培训考证报名与静态资源访问
This commit is contained in:
@@ -6,6 +6,7 @@ import { HealthProfileSchema } from "./schema/health_profile.js"
|
||||
import { OrganizationSchema } from "./schema/organization.js"
|
||||
import { EmployeeSchema } from "./schema/employee.js"
|
||||
import { EmployeeReviewSchema } from "./schema/employee_review.js"
|
||||
import { TrainingApplicationSchema } from "./schema/training_application.js"
|
||||
import config from '../config.js';
|
||||
import logger from '../utils/logger.js';
|
||||
|
||||
@@ -18,6 +19,7 @@ class MongoDBSchema {
|
||||
this.Employee = null;
|
||||
this.HealthProfile = null;
|
||||
this.EmployeeReview = null;
|
||||
this.TrainingApplication = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -48,6 +50,7 @@ class MongoDBSchema {
|
||||
this.Organization = this.dbConnection.model('organization', OrganizationSchema)
|
||||
this.Employee = this.dbConnection.model('employee', EmployeeSchema)
|
||||
this.EmployeeReview = this.dbConnection.model('employee_review', EmployeeReviewSchema)
|
||||
this.TrainingApplication = this.dbConnection.model('training_application', TrainingApplicationSchema)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
"use strict";
|
||||
|
||||
import mongoose from "mongoose";
|
||||
|
||||
/**
|
||||
* TrainingApplication Schema
|
||||
* 2026 年国开培训中心「医疗陪诊(高级)」考位报名。
|
||||
*
|
||||
* 证书口径:颁发主体是国家开放大学培训中心,本报名只采集考位信息,
|
||||
* 不表示职业资格证书或就业承诺。照片与身份证电子版仅用于报名和办证,
|
||||
* 查询列表时默认不返回,避免在列表接口中反复传输敏感大图。
|
||||
*/
|
||||
const TrainingApplicationSchema = mongoose.Schema(
|
||||
{
|
||||
userId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "user",
|
||||
required: true,
|
||||
index: true,
|
||||
comment: "报名用户ID",
|
||||
},
|
||||
|
||||
applicant: {
|
||||
name: { type: String, required: true, trim: true, maxlength: 20, comment: "姓名" },
|
||||
idNumber: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true,
|
||||
uppercase: true,
|
||||
match: /^\d{17}[\dX]$/,
|
||||
comment: "身份证号",
|
||||
},
|
||||
mobile: { type: String, required: true, trim: true, comment: "手机号" },
|
||||
education: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ["初中及以下", "高中/中专", "大专", "本科", "硕士及以上"],
|
||||
comment: "学历",
|
||||
},
|
||||
},
|
||||
|
||||
// 2026 年考位:前端只允许选择 2026-01 至 2026-12
|
||||
exam: {
|
||||
year: { type: Number, default: 2026, min: 2026, max: 2026, comment: "考试年份" },
|
||||
month: { type: Number, required: true, min: 1, max: 12, comment: "考试月份" },
|
||||
},
|
||||
|
||||
// 图片以 data URL 落库;每张原图服务端限制 5MB。
|
||||
// 列表查询使用 .select('-materials'),只有后续确需办证查看时才单独读取
|
||||
materials: {
|
||||
photo: {
|
||||
data: { type: String, required: true, comment: "2寸蓝底照片 data URL" },
|
||||
mime: { type: String, enum: ["image/jpeg", "image/png"], required: true },
|
||||
},
|
||||
idCard: {
|
||||
data: { type: String, required: true, comment: "身份证电子版 data URL" },
|
||||
mime: { type: String, enum: ["image/jpeg", "image/png"], required: true },
|
||||
},
|
||||
},
|
||||
|
||||
course: {
|
||||
name: { type: String, default: "医疗陪诊顾问(高级)", comment: "报考项目" },
|
||||
issuer: { type: String, default: "国家开放大学培训中心", comment: "颁发机构" },
|
||||
},
|
||||
|
||||
status: {
|
||||
type: String,
|
||||
enum: ["pending", "contacted", "enrolled", "cancelled"],
|
||||
default: "pending",
|
||||
index: true,
|
||||
comment: "pending 待审核 / contacted 已联系 / enrolled 已入班 / cancelled 已取消",
|
||||
},
|
||||
|
||||
meta: {
|
||||
createtime: { type: Number, default: () => Date.now(), comment: "创建时间" },
|
||||
updatetime: { type: Number, default: () => Date.now(), comment: "更新时间" },
|
||||
},
|
||||
},
|
||||
{
|
||||
minimize: false,
|
||||
strict: true,
|
||||
collection: "training_application",
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
TrainingApplicationSchema.statics.createApplication = async function (data) {
|
||||
data.meta = { createtime: Date.now(), updatetime: Date.now() };
|
||||
const doc = new this(data);
|
||||
return await doc.save();
|
||||
};
|
||||
|
||||
TrainingApplicationSchema.statics.findLatestByUser = async function (userId) {
|
||||
return await this.findOne({ userId })
|
||||
.select("-materials")
|
||||
.sort({ "meta.createtime": -1 })
|
||||
.exec();
|
||||
};
|
||||
|
||||
// 拦截短时间内的重复提交;已取消的报名不阻挡用户重新报名
|
||||
TrainingApplicationSchema.statics.findRecentActiveByUser = async function (userId, since) {
|
||||
return await this.findOne({
|
||||
userId,
|
||||
status: { $ne: "cancelled" },
|
||||
"meta.createtime": { $gte: since },
|
||||
})
|
||||
.select("-materials")
|
||||
.sort({ "meta.createtime": -1 })
|
||||
.exec();
|
||||
};
|
||||
|
||||
TrainingApplicationSchema.statics.findApplicationPage = async function (options = {}) {
|
||||
const { page = 1, pageSize = 20, status } = options;
|
||||
const filter = {};
|
||||
if (status) filter.status = status;
|
||||
|
||||
const skip = (page - 1) * pageSize;
|
||||
const [applications, total] = await Promise.all([
|
||||
this.find(filter)
|
||||
.select("-materials")
|
||||
.sort({ "meta.createtime": -1 })
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.exec(),
|
||||
this.countDocuments(filter).exec(),
|
||||
]);
|
||||
|
||||
return { applications, total };
|
||||
};
|
||||
|
||||
TrainingApplicationSchema.index({ userId: 1, "meta.createtime": -1 });
|
||||
TrainingApplicationSchema.index({ status: 1, "meta.createtime": -1 });
|
||||
|
||||
export { TrainingApplicationSchema };
|
||||
Reference in New Issue
Block a user