|
|
@@ -4,6 +4,7 @@ import { redisService } from './redis.service';
|
|
|
import { AppDataSource } from '@/server/data-source';
|
|
|
import { SubmissionRecords } from '@/server/modules/submission/submission-records.entity';
|
|
|
import debug from 'debug';
|
|
|
+import type { Answer } from '@/client/mobile/components/Exam/types';
|
|
|
|
|
|
const log = debug('socket:exam');
|
|
|
|
|
|
@@ -67,7 +68,7 @@ export class ExamService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async storeAnswer(socket: AuthenticatedSocket, roomId: string, questionId: string, answer: any): Promise<boolean> {
|
|
|
+ async storeAnswer(socket: AuthenticatedSocket, roomId: string, questionId: string, answer: Answer): Promise<boolean> {
|
|
|
try {
|
|
|
if (!socket.user) throw new Error('用户未认证');
|
|
|
|
|
|
@@ -87,7 +88,7 @@ export class ExamService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getAnswers(roomId: string, questionId?: string) {
|
|
|
+ async getAnswers(roomId: string, questionId?: string): Promise<Answer[]> {
|
|
|
try {
|
|
|
return await redisService.getAnswers(roomId, questionId);
|
|
|
} catch (error) {
|
|
|
@@ -96,7 +97,7 @@ export class ExamService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getUserAnswers(roomId: string, userId: number) {
|
|
|
+ async getUserAnswers(roomId: string, userId: number): Promise<Answer[]> {
|
|
|
try {
|
|
|
return await redisService.getUserAnswers(roomId, userId);
|
|
|
} catch (error) {
|
|
|
@@ -203,7 +204,7 @@ export class ExamService {
|
|
|
// 转换Redis中的答案数据为提交记录实体
|
|
|
const submissionRecord = new SubmissionRecords();
|
|
|
submissionRecord.classroomNo = roomId;
|
|
|
- submissionRecord.userId = answer.userId?.toString() || null;
|
|
|
+ submissionRecord.userId = answer.userId || null;
|
|
|
submissionRecord.score = this.calculateScore(answer);
|
|
|
submissionRecord.code = answer.code || null;
|
|
|
submissionRecord.trainingDate = answer.date ? new Date(answer.date) : null;
|
|
|
@@ -211,7 +212,7 @@ export class ExamService {
|
|
|
submissionRecord.status = 1; // 状态:1-正常
|
|
|
submissionRecord.holdingStock = answer.holdingStock || null;
|
|
|
submissionRecord.holdingCash = answer.holdingCash || null;
|
|
|
- submissionRecord.price = answer.price ? parseFloat(answer.price) : null;
|
|
|
+ submissionRecord.price = Number(answer.price);
|
|
|
submissionRecord.profitAmount = answer.profitAmount || null;
|
|
|
submissionRecord.profitPercent = answer.profitPercent || null;
|
|
|
submissionRecord.totalProfitAmount = answer.totalProfitAmount || null;
|
|
|
@@ -234,7 +235,7 @@ export class ExamService {
|
|
|
/**
|
|
|
* 计算得分(可根据业务需求自定义评分逻辑)
|
|
|
*/
|
|
|
- private calculateScore(answer: any): number | null {
|
|
|
+ private calculateScore(answer: Answer): number | null {
|
|
|
// 这里可以根据答题内容计算得分
|
|
|
// 示例:根据收益率计算得分,收益率越高得分越高
|
|
|
if (answer.profitPercent !== undefined && answer.profitPercent !== null) {
|