import { QuestionBankFacade , QuestionStatus , Question , } from "./question" ; import { Application } from "../application" ; import { SystemConfig } from "@App/config" ; export interface QueryQuestions { QueryQuestions ( ) : Question [ ] ; } export abstract class Topic { protected lock : boolean ; protected answer : QuestionBankFacade ; protected context : any ; protected queryQuestions : QueryQuestions ; constructor ( content , answer ) { this . answer = answer ; this . context = content ; } public SetQueryQuestions ( queryQuestions ) { this . queryQuestions = queryQuestions ; } public abstract Init ( ) ; protected addQuestion ( ) { let questions = this . queryQuestions . QueryQuestions ( ) ; this . answer . ClearQuestion ( ) ; questions . forEach ( ( val ) => { this . answer . AddQuestion ( val ) ; } ) ; } public QueryAnswer ( ) { return new Promise < QuestionStatus > ( resolve => { if ( this . lock ) { return resolve ( "processing" ) ; } this . lock = true ; Application . App . log . Info ( "题目搜索中..." ) ; this . addQuestion ( ) ; this . answer . Answer ( ( status ) => { this . lock = false ; resolve ( status ) ; if ( status == "network" ) { return Application . App . log . Error ( "题库无法访问,请查看:" + SystemConfig . url ) ; } else if ( status == "incomplete" ) { return Application . App . log . Warn ( "题库答案不全,请手动填写操作" ) ; } } ) ; } ) ; } public CollectAnswer ( ) { return new Promise ( resolve => { Application . App . log . Debug ( "收集题目答案" , this . context ) ; this . addQuestion ( ) ; this . answer . Push ( ( status ) => { Application . App . log . Debug ( "采集答案返回" , status ) ; resolve ( ) ; } ) ; } ) ; } public abstract Submit ( ) ; }