Spaces:
Sleeping
Sleeping
File size: 12,476 Bytes
58b7bd4 247df42 3d889df 247df42 928d114 8e5411a 247df42 61db43c 8e5411a 61db43c 247df42 5e8f957 247df42 9e660ce 247df42 9c7e2d6 247df42 9c7e2d6 9e660ce 247df42 5e8f957 247df42 3d889df 247df42 355c0ae 5e8f957 e8bfcb9 b785427 e1c03e9 36325f8 e8bfcb9 6b3c2a4 e8bfcb9 36325f8 2bf9484 36325f8 247df42 5e8f957 247df42 5e8f957 247df42 1751a72 247df42 9743332 55081a6 5e8f957 55081a6 5e8f957 55081a6 5e8f957 55081a6 5e8f957 3d889df 8035c0c 9743332 247df42 55081a6 8035c0c e1c03e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
const mongoose = require('mongoose');
// ... (Previous Models: School, User, Student, Course, Score, Class, Subject, Exam Models - No Change)
const SchoolSchema = new mongoose.Schema({ name: String, code: String });
const School = mongoose.model('School', SchoolSchema);
const UserSchema = new mongoose.Schema({
username: String,
password: String,
trueName: String,
phone: String,
email: String,
schoolId: String,
role: String,
status: String,
avatar: String,
createTime: Date,
teachingSubject: String,
homeroomClass: String,
studentNo: String,
parentName: String,
parentPhone: String,
address: String,
gender: String,
seatNo: String,
idCard: String,
aiAccess: { type: Boolean, default: false },
// UPDATED: Stores Doubao Context State
doubaoState: {
responseId: String, // previous_response_id
thinkingState: Boolean // Last thinking state (enabled/disabled)
},
menuOrder: [String],
classApplication: {
type: { type: String },
targetClass: String,
status: String
},
pendingSchoolData: {
name: String,
code: String,
type: { type: String }
}
});
const User = mongoose.model('User', UserSchema);
// ... (Student, Course, Score, Class, Subject, Exam Models - No Change)
const StudentSchema = new mongoose.Schema({
schoolId: String,
studentNo: String,
seatNo: String,
name: String,
gender: String,
birthday: String,
idCard: String,
phone: String,
className: String,
status: String,
parentName: String,
parentPhone: String,
address: String,
teamId: String,
drawAttempts: { type: Number, default: 0 },
dailyDrawLog: { date: String, count: { type: Number, default: 0 } },
flowerBalance: { type: Number, default: 0 },
// Seating Fields
height: Number,
vision: { type: String, default: 'Normal' }, // Normal, Near-Mild, Near-Severe, Far
character: { type: String, default: 'Normal' }, // Active, Quiet, Normal
seatRow: Number,
seatCol: Number
});
const Student = mongoose.model('Student', StudentSchema);
const CourseSchema = new mongoose.Schema({
schoolId: String,
courseCode: String,
courseName: String,
className: String,
teacherName: String,
teacherId: String,
credits: Number,
capacity: Number,
enrolled: Number
});
CourseSchema.index({ schoolId: 1, className: 1, courseName: 1 }, { unique: true });
const Course = mongoose.model('Course', CourseSchema);
const ScoreSchema = new mongoose.Schema({ schoolId: String, studentName: String, studentNo: String, courseName: String, score: Number, semester: String, type: String, examName: String, status: String });
const Score = mongoose.model('Score', ScoreSchema);
// UPDATED CLASS SCHEMA
const ClassSchema = new mongoose.Schema({
schoolId: String,
grade: String,
className: String,
teacherName: String,
homeroomTeacherIds: [String],
periodConfig: [{ period: Number, name: String, startTime: String, endTime: String }],
seatingConfig: { rows: Number, cols: Number }
});
const ClassModel = mongoose.model('Class', ClassSchema);
const SubjectSchema = new mongoose.Schema({ schoolId: String, name: String, code: String, color: String, excellenceThreshold: Number, thresholds: { type: Map, of: Number } });
const SubjectModel = mongoose.model('Subject', SubjectSchema);
const ExamSchema = new mongoose.Schema({ schoolId: String, name: String, date: String, type: String, semester: String });
const ExamModel = mongoose.model('Exam', ExamSchema);
const ScheduleSchema = new mongoose.Schema({
schoolId: String,
className: String,
teacherName: String,
subject: String,
dayOfWeek: Number,
period: Number,
weekType: { type: String, default: 'ALL' } // ALL, ODD, EVEN
});
const ScheduleModel = mongoose.model('Schedule', ScheduleSchema);
const ConfigSchema = new mongoose.Schema({
key: String,
systemName: String,
semester: String,
semesters: [String],
allowRegister: Boolean,
allowAdminRegister: Boolean,
allowPrincipalRegister: Boolean,
allowStudentRegister: Boolean,
maintenanceMode: Boolean,
emailNotify: Boolean,
enableAI: { type: Boolean, default: true },
aiTotalCalls: { type: Number, default: 0 },
// Updated default to include DOUBAO
aiProviderOrder: { type: [String], default: ['GEMINI', 'OPENROUTER', 'DOUBAO', 'GEMMA'] },
periodConfig: [{ period: Number, name: String, startTime: String, endTime: String }],
apiKeys: {
gemini: [String],
openrouter: [String],
doubao: [String] // NEW: Doubao Key Pool
},
// NEW: Doubao Custom Models (Endpoints)
doubaoModels: [{
modelId: String, // The Model ID (e.g. doubao-pro-32k)
endpointId: String, // Endpoint ID (e.g. ep-2024xxxx)
name: String // Friendly Name
}],
openRouterModels: [{
id: String,
name: String,
apiUrl: String, // NEW: Custom API URL for this model
isCustom: { type: Boolean, default: false }
}]
});
const ConfigModel = mongoose.model('Config', ConfigSchema);
// ... (Notification, GameSession, StudentReward, LuckyDrawConfig, etc.)
const NotificationSchema = new mongoose.Schema({ schoolId: String, targetRole: String, targetUserId: String, title: String, content: String, type: String, createTime: { type: Date, default: Date.now } });
const NotificationModel = mongoose.model('Notification', NotificationSchema);
const GameSessionSchema = new mongoose.Schema({ schoolId: String, className: String, isEnabled: Boolean, maxSteps: Number, teams: [{ id: String, name: String, score: Number, avatar: String, color: String, members: [String] }], rewardsConfig: [{ scoreThreshold: Number, rewardType: String, rewardName: String, rewardValue: { type: Number, default: 1 }, achievementId: String }] }); // Added rewardValue default
const GameSessionModel = mongoose.model('GameSession', GameSessionSchema);
const StudentRewardSchema = new mongoose.Schema({ schoolId: String, studentId: String, studentName: String, rewardType: String, name: String, count: { type: Number, default: 1 }, status: String, source: String, createTime: { type: Date, default: Date.now }, ownerId: String });
const StudentRewardModel = mongoose.model('StudentReward', StudentRewardSchema);
const LuckyDrawConfigSchema = new mongoose.Schema({ schoolId: String, className: String, ownerId: String, prizes: [{ id: String, name: String, probability: Number, count: Number, icon: String }], dailyLimit: Number, cardCount: Number, defaultPrize: String, consolationWeight: { type: Number, default: 0 } });
const LuckyDrawConfigModel = mongoose.model('LuckyDrawConfig', LuckyDrawConfigSchema);
const GameMonsterConfigSchema = new mongoose.Schema({
schoolId: String,
className: String,
ownerId: String,
duration: { type: Number, default: 300 },
sensitivity: { type: Number, default: 25 },
difficulty: { type: Number, default: 5 },
useKeyboardMode: { type: Boolean, default: false },
rewardConfig: {
enabled: Boolean,
type: { type: String },
val: String,
count: Number
}
});
const GameMonsterConfigModel = mongoose.model('GameMonsterConfig', GameMonsterConfigSchema);
const GameZenConfigSchema = new mongoose.Schema({
schoolId: String,
className: String,
ownerId: String,
durationMinutes: { type: Number, default: 40 },
threshold: { type: Number, default: 30 },
passRate: { type: Number, default: 90 },
rewardConfig: {
enabled: Boolean,
type: { type: String },
val: String,
count: Number
}
});
const GameZenConfigModel = mongoose.model('GameZenConfig', GameZenConfigSchema);
const AchievementConfigSchema = new mongoose.Schema({
schoolId: String,
className: String,
achievements: [{
id: String,
name: String,
icon: String,
points: Number,
description: String,
addedBy: String,
addedByName: String
}],
exchangeRules: [{ id: String, cost: Number, rewardType: String, rewardName: String, rewardValue: Number }]
});
const AchievementConfigModel = mongoose.model('AchievementConfig', AchievementConfigSchema);
const TeacherExchangeConfigSchema = new mongoose.Schema({
schoolId: String,
teacherId: String,
teacherName: String,
rules: [{ id: String, cost: Number, rewardType: String, rewardName: String, rewardValue: Number }]
});
const TeacherExchangeConfigModel = mongoose.model('TeacherExchangeConfig', TeacherExchangeConfigSchema);
// Updated: Added points field
const StudentAchievementSchema = new mongoose.Schema({
schoolId: String,
studentId: String,
studentName: String,
achievementId: String,
achievementName: String,
achievementIcon: String,
points: { type: Number, default: 0 },
semester: String,
createTime: { type: Date, default: Date.now }
});
const StudentAchievementModel = mongoose.model('StudentAchievement', StudentAchievementSchema);
const AttendanceSchema = new mongoose.Schema({ schoolId: String, studentId: String, studentName: String, className: String, date: String, status: String, checkInTime: Date });
const AttendanceModel = mongoose.model('Attendance', AttendanceSchema);
const LeaveRequestSchema = new mongoose.Schema({ schoolId: String, studentId: String, studentName: String, className: String, reason: String, startDate: String, endDate: String, status: { type: String, default: 'Pending' }, createTime: { type: Date, default: Date.now } });
const LeaveRequestModel = mongoose.model('LeaveRequest', LeaveRequestSchema);
const SchoolCalendarSchema = new mongoose.Schema({ schoolId: String, className: String, type: String, startDate: String, endDate: String, name: String });
const SchoolCalendarModel = mongoose.model('SchoolCalendar', SchoolCalendarSchema);
const WishSchema = new mongoose.Schema({
schoolId: String,
studentId: String,
studentName: String,
className: String,
teacherId: String,
teacherName: String,
content: String,
status: { type: String, default: 'PENDING' },
createTime: { type: Date, default: Date.now },
fulfillTime: Date
});
const WishModel = mongoose.model('Wish', WishSchema);
const FeedbackSchema = new mongoose.Schema({
schoolId: String,
creatorId: String,
creatorName: String,
creatorRole: String,
targetId: String,
targetName: String,
content: String,
type: String,
status: { type: String, default: 'PENDING' },
reply: String,
createTime: { type: Date, default: Date.now },
updateTime: Date
});
const FeedbackModel = mongoose.model('Feedback', FeedbackSchema);
const TodoSchema = new mongoose.Schema({
userId: String,
content: String,
isCompleted: { type: Boolean, default: false },
createTime: { type: Date, default: Date.now }
});
const TodoModel = mongoose.model('Todo', TodoSchema);
// NEW: Detailed AI Usage Stats
const AIUsageSchema = new mongoose.Schema({
date: String, // Format: YYYY-MM-DD
model: String,
provider: String,
count: { type: Number, default: 0 }
});
// Optimize lookups by date and model
AIUsageSchema.index({ date: 1, model: 1, provider: 1 }, { unique: true });
const AIUsageModel = mongoose.model('AIUsage', AIUsageSchema);
// NEW: Persistent Chat History
const ChatHistorySchema = new mongoose.Schema({
userId: { type: String, required: true, index: true },
role: { type: String, enum: ['user', 'model'], required: true },
text: { type: String, required: true },
timestamp: { type: Number, default: Date.now }
});
// Create index for fast retrieval of latest messages
ChatHistorySchema.index({ userId: 1, timestamp: -1 });
const ChatHistoryModel = mongoose.model('ChatHistory', ChatHistorySchema);
module.exports = {
School, User, Student, Course, Score, ClassModel, SubjectModel, ExamModel, ScheduleModel,
ConfigModel, NotificationModel, GameSessionModel, StudentRewardModel, LuckyDrawConfigModel, GameMonsterConfigModel, GameZenConfigModel,
AchievementConfigModel, TeacherExchangeConfigModel, StudentAchievementModel, AttendanceModel, LeaveRequestModel, SchoolCalendarModel,
WishModel, FeedbackModel, TodoModel, AIUsageModel, ChatHistoryModel
}; |