增加挑战对店铺自定义题库的适配
This commit is contained in:
parent
708d8da054
commit
501ecde7fc
@ -7,6 +7,7 @@ import { PuzzleSession, PuzzleStatusClass } from '../../models/match/PuzzleSessi
|
||||
import { calcExamScore, getRank, transformRecord, updateExamRank } from '../../services/GameLogic'
|
||||
import { Shop, validShopId } from '../../models/shop/Shop'
|
||||
import { UserReward } from '../../models/UserReward'
|
||||
import { ShopPuzzle } from '../../models/shop/ShopPuzzle'
|
||||
|
||||
class ExamController extends BaseController {
|
||||
@role('anon')
|
||||
@ -42,11 +43,22 @@ class ExamController extends BaseController {
|
||||
for (let _r of questions) {
|
||||
history.questions.set(_r.id, _r.compactRecord(true))
|
||||
}
|
||||
} else {
|
||||
} else if (record.source === 1) {
|
||||
results = record.transQuestion()
|
||||
for (let _r of record.questions) {
|
||||
history.questions.set(_r._id + '', _r.compactRecord(true))
|
||||
}
|
||||
} else if (record.source === 2) {
|
||||
if (record.shopCates && record.shopCates.length > 0) {
|
||||
params = { groups: { $in: record.shopCates } }
|
||||
}
|
||||
let questions = await ShopPuzzle.randomQuestions(params, record.qcount)
|
||||
let _results = []
|
||||
for (let _r of questions) {
|
||||
history.questions.set(_r.id, _r.compactRecord(true))
|
||||
_results.push(_r.compactRecord(false))
|
||||
}
|
||||
results = _results
|
||||
}
|
||||
let stat = new PuzzleStatusClass()
|
||||
stat.timeLast = now
|
||||
|
@ -97,6 +97,12 @@ export class ShopExamClass extends BaseModule {
|
||||
*/
|
||||
@prop({ type: () => [String] })
|
||||
public qtypes: string[]
|
||||
/**
|
||||
* 店铺自定义tag
|
||||
* @type {string[]}
|
||||
*/
|
||||
@prop({ type: () => [String] })
|
||||
public shopCates: string[]
|
||||
/**
|
||||
* 单次活动题目数量, 0为所有
|
||||
* @type {number}
|
||||
|
@ -3,7 +3,9 @@ import { getModelForClass, index, modelOptions, prop, ReturnModelType } from '@t
|
||||
import { BaseModule } from '../Base'
|
||||
import { Base, TimeStamps } from '@typegoose/typegoose/lib/defaultClasses'
|
||||
import { checkJson, noJson } from '../../decorators/nojson'
|
||||
import { PuzzleClass } from '../content/Puzzle'
|
||||
import { Puzzle, PuzzleClass } from '../content/Puzzle'
|
||||
import { QCategoryCache } from '../../services/QCategoryCache'
|
||||
import { CompactPuzzleClass } from '../match/PuzzleSession'
|
||||
|
||||
const jsonExcludeKeys = ['updatedAt', '__v']
|
||||
|
||||
@ -150,6 +152,41 @@ export class ShopPuzzleClass extends BaseModule {
|
||||
public static async allTags(shop: string) {
|
||||
return ShopPuzzle.distinct('groups', { shop, deleted: 0 })
|
||||
}
|
||||
|
||||
public static async randomQuestions(this: ReturnModelType<typeof ShopPuzzleClass>, options: any, count: number) {
|
||||
let filters = { status: 1, is_hide: 0, deleted: 0 }
|
||||
Object.assign(filters, options)
|
||||
let records = await this.aggregate([{ $match: filters }, { $sample: { size: count } }]).exec()
|
||||
let results = []
|
||||
for (let record of records) {
|
||||
let o = new ShopPuzzle({})
|
||||
Object.assign(o, record)
|
||||
results.push(o)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
public compactRecord(withAnswer: boolean) {
|
||||
let answers = []
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
if (this[`a${i}`]) {
|
||||
answers.push(this[`a${i}`])
|
||||
}
|
||||
}
|
||||
let result = new CompactPuzzleClass()
|
||||
result.id = this._id + ''
|
||||
result.title = this.question
|
||||
|
||||
result.type = this.type
|
||||
result.category = this.groups.join(',')
|
||||
result.quality = this.quality
|
||||
if (!withAnswer) {
|
||||
answers.randomSort()
|
||||
}
|
||||
result.source = 2
|
||||
result.answers = answers
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export const ShopPuzzle = getModelForClass(ShopPuzzleClass, { existingConnection: ShopPuzzleClass.db })
|
||||
|
Loading…
x
Reference in New Issue
Block a user