Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
f3c08132
Commit
f3c08132
authored
Aug 20, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
edba8fbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
618 additions
and
427 deletions
+618
-427
PaperModule2.cs
Edu.Module.Exam/PaperModule2.cs
+124
-79
AnalysisQuestionTypeModule.cs
Edu.Module.Question/AnalysisQuestionTypeModule.cs
+484
-0
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+10
-348
No files found.
Edu.Module.Exam/PaperModule2.cs
View file @
f3c08132
...
...
@@ -2,6 +2,7 @@
using
Edu.Repository.Exam
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
Edu.Module.Exam
...
...
@@ -18,15 +19,20 @@ namespace Edu.Module.Exam
private
readonly
RB_Examination_StudentDetailsRepository
examination_StudentDetailsRepository
=
new
RB_Examination_StudentDetailsRepository
();
/// <summary>
/// 自动阅卷
处理类
/// 自动阅卷
方法
/// </summary>
/// <param name="PaperId">试卷编号</param>
/// <param name="PublishId">发布编号</param>
/// <param name="GuestId">学员编号</param>
/// <returns></returns>
public
bool
AutoReviewPaperModule
(
int
PaperId
,
int
PublishId
,
int
GuestId
)
public
bool
AutoReviewPaperModule
(
int
PaperId
,
int
PublishId
,
int
GuestId
)
{
bool
flag
=
false
;
var
paperConfig
=
examination_PublishRepository
.
GetEntity
(
PublishId
);
//多选题未选全是否给一半的分
var
IsHalfScore
=
paperConfig
?.
IsHalfScore
??
0
;
List
<
RB_Examination_StudentDetails_ViewModel
>
answerList
=
new
List
<
RB_Examination_StudentDetails_ViewModel
>();
//试卷题目
var
sourceQuestionList
=
examination_DetailsRepository
.
GetExaminationDetailsListRepository
(
new
RB_Examination_Details_ViewModel
()
{
PaperId
=
PaperId
});
//学员提交答案列表
...
...
@@ -40,84 +46,123 @@ namespace Edu.Module.Exam
{
foreach
(
var
sItem
in
sourceQuestionList
)
{
switch
(
sItem
.
QuestionTypeKey
)
var
answerModel
=
stuQuesList
?.
Where
(
qitem
=>
qitem
.
DetailsId
==
sItem
.
Id
)?.
FirstOrDefault
();
if
(
answerModel
!=
null
&&
answerModel
.
Id
>
0
)
{
//单选题
case
"single"
:
break
;
//多选题
case
"multiple"
:
break
;
//填空题
case
"fill-in"
:
break
;
//判断题
case
"judge"
:
break
;
//简答题
case
"short-answer"
:
break
;
//名词解释
case
"noun-explanation"
:
break
;
//论述题
case
"essay-question"
:
break
;
//计算题
case
"calculation"
:
break
;
//分录题
case
"entry-problem"
:
break
;
//资料题
case
"data-question"
:
break
;
//连线题
case
"matching"
:
break
;
//排序题
case
"sorting-problem"
:
break
;
//完型填空
case
"cloze"
:
break
;
//阅读理解
case
"reading-comprehensio"
:
break
;
//口语题
case
"spoken"
:
break
;
//听力题
case
"listening"
:
break
;
//公用选项题
case
"sharing-choose"
:
break
;
//其它题
case
"other"
:
break
;
//单选题-数字
case
"single-number"
:
break
;
switch
(
sItem
.
QuestionTypeKey
)
{
//单选题
case
"single"
:
if
(
sItem
.
Answer
==
answerModel
.
StundetAnswer
)
{
answerList
.
Add
(
new
RB_Examination_StudentDetails_ViewModel
()
{
Id
=
answerModel
.
Id
,
StundetScore
=
sItem
.
Score
});
}
break
;
//多选题
case
"multiple"
:
break
;
//填空题
case
"fill-in"
:
break
;
//判断题
case
"judge"
:
if
(
sItem
.
Answer
==
answerModel
.
StundetAnswer
)
{
answerList
.
Add
(
new
RB_Examination_StudentDetails_ViewModel
()
{
Id
=
answerModel
.
Id
,
StundetScore
=
sItem
.
Score
});
}
break
;
//简答题
case
"short-answer"
:
break
;
//名词解释
case
"noun-explanation"
:
break
;
//论述题
case
"essay-question"
:
break
;
//计算题
case
"calculation"
:
break
;
//分录题
case
"entry-problem"
:
break
;
//资料题
case
"data-question"
:
break
;
//连线题
case
"matching"
:
if
(
sItem
.
Answer
==
answerModel
.
StundetAnswer
)
{
answerList
.
Add
(
new
RB_Examination_StudentDetails_ViewModel
()
{
Id
=
answerModel
.
Id
,
StundetScore
=
sItem
.
Score
});
}
break
;
//排序题
case
"sorting-problem"
:
if
(
sItem
.
Answer
==
answerModel
.
StundetAnswer
)
{
answerList
.
Add
(
new
RB_Examination_StudentDetails_ViewModel
()
{
Id
=
answerModel
.
Id
,
StundetScore
=
sItem
.
Score
});
}
break
;
//完型填空
case
"cloze"
:
break
;
//阅读理解
case
"reading-comprehensio"
:
break
;
//口语题
case
"spoken"
:
break
;
//听力题
case
"listening"
:
break
;
//公用选项题
case
"sharing-choose"
:
break
;
//其它题
case
"other"
:
break
;
//单选题-数字
case
"single-number"
:
if
(
sItem
.
Answer
==
answerModel
.
StundetAnswer
)
{
answerList
.
Add
(
new
RB_Examination_StudentDetails_ViewModel
()
{
Id
=
answerModel
.
Id
,
StundetScore
=
sItem
.
Score
});
}
break
;
}
}
}
}
...
...
Edu.Module.Question/AnalysisQuestionTypeModule.cs
View file @
f3c08132
using
Edu.Model.ViewModel.Question
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
Edu.Module.Question
...
...
@@ -188,5 +189,488 @@ namespace Edu.Module.Question
}
return
obj
;
}
/// <summary>
/// 问题验证
/// </summary>
/// <param name="QuestionTypeKey">问题类型</param>
/// <param name="QuestionTypeKey">问题内容</param>
/// <param name="Answer">问题答案</param>
/// <param name="AnalysisAnswer">解析答案</param>
/// <returns></returns>
public
string
CheckQuestion
(
string
QuestionTypeKey
,
string
QuestionContent
,
string
Answer
,
out
string
AnalysisAnswer
)
{
AnalysisAnswer
=
""
;
string
message
=
""
;
//单选、多选、单选(数字)题
if
(
QuestionTypeKey
==
"single"
||
QuestionTypeKey
==
"multiple"
||
QuestionTypeKey
==
"single-number"
)
{
var
optionItems
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
QuestionContent
);
message
=
CheckChoose
(
optionItems
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
message
;
}
else
{
AnalysisAnswer
=
string
.
Join
(
","
,
optionItems
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Select
(
qitem
=>
qitem
.
Name
));
}
}
//判断题
else
if
(
QuestionTypeKey
==
"judge"
)
{
var
optionItems
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
QuestionContent
);
message
=
CheckChoose
(
optionItems
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
message
;
}
else
{
AnalysisAnswer
=
optionItems
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
)?.
FirstOrDefault
()?.
Name
;
}
}
//填空题
else
if
(
QuestionTypeKey
==
"fill-in"
)
{
var
fillInList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
QuestionContent
);
message
=
CheckFillIn
(
fillInList
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
message
;
}
else
{
AnalysisAnswer
=
string
.
Join
(
"★"
,
fillInList
.
Select
(
qitem
=>
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
qitem
.
Content
)));
}
}
//简答题
else
if
(
QuestionTypeKey
==
"short-answer"
)
{
message
=
CheckShortAnswer
(
Answer
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//名词解释
else
if
(
QuestionTypeKey
==
"noun-explanation"
)
{
if
(
string
.
IsNullOrEmpty
(
Answer
))
{
message
=
"请填写名词解释答案"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//论述题
else
if
(
QuestionTypeKey
==
"essay-question"
)
{
if
(
string
.
IsNullOrEmpty
(
Answer
))
{
message
=
"请填写论述题答案"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//计算题
else
if
(
QuestionTypeKey
==
"calculation"
)
{
if
(
string
.
IsNullOrEmpty
(
Answer
))
{
message
=
"请填写计算题答案"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//分录题、资料题
else
if
(
QuestionTypeKey
==
"entry-problem"
||
QuestionTypeKey
==
"data-question"
)
{
var
entryList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
QuestionContent
);
if
(
entryList
!=
null
&&
entryList
.
Count
>
0
)
{
if
(
entryList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"请输入答案"
;
return
message
;
}
else
{
AnalysisAnswer
=
string
.
Join
(
"★"
,
entryList
.
Select
(
qitem
=>
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
qitem
.
Content
)));
}
}
else
{
message
=
"请添加答案"
;
return
message
;
}
}
//排序题
else
if
(
QuestionTypeKey
==
"sorting-problem"
)
{
var
sortList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
QuestionContent
);
if
(
sortList
!=
null
&&
sortList
.
Count
>
0
)
{
if
(
sortList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"请输入选项内容"
;
return
message
;
}
if
(
sortList
.
Count
>
1
)
{
AnalysisAnswer
=
string
.
Join
(
","
,
sortList
[
1
].
Select
(
qitem
=>
qitem
.
Name
));
}
}
else
{
message
=
"请添加选项"
;
return
message
;
}
}
//连线题
else
if
(
QuestionTypeKey
==
"matching"
)
{
var
matchList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
QuestionContent
);
if
(
matchList
!=
null
&&
matchList
.
Count
>
0
)
{
if
(
matchList
[
0
]
!=
null
&&
matchList
[
0
].
Count
>
0
)
{
if
(
matchList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"第一组选项内容不能为空"
;
return
message
;
}
}
else
{
message
=
"请添加第一组选项"
;
return
message
;
}
if
(
matchList
.
Count
>
1
&&
matchList
[
1
]
!=
null
&&
matchList
[
1
].
Count
>
0
)
{
if
(
matchList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"第二组选项内容不能为空"
;
return
message
;
}
}
else
{
message
=
"请添加第二组选项"
;
return
message
;
}
if
(
matchList
.
Count
>
2
)
{
if
(
matchList
[
2
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"请设置答案"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
JsonHelper
.
Serialize
(
matchList
[
2
]);
}
}
}
else
{
message
=
"请添加选项"
;
return
message
;
}
}
//完型填空
else
if
(
QuestionTypeKey
==
"cloze"
)
{
var
clozeList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
optionItem
>>>(
QuestionContent
);
if
(
clozeList
!=
null
&&
clozeList
.
Count
>
0
)
{
int
index
=
1
;
string
clozeAnswer
=
""
;
foreach
(
var
subList
in
clozeList
)
{
if
(
subList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
string
.
Format
(
"第{0}小题选项内容不能为空!"
,
index
);
return
message
;
}
if
(!(
subList
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Count
()
>
0
))
{
message
=
string
.
Format
(
"请设置第{0}小题选项的正确答案!"
,
index
);
return
message
;
}
clozeAnswer
+=
","
+
subList
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
)?.
FirstOrDefault
()?.
Name
;
index
++;
}
AnalysisAnswer
=
clozeAnswer
.
TrimStart
(
','
);
}
else
{
message
=
"请添加小题!"
;
return
message
;
}
}
//口语题
else
if
(
QuestionTypeKey
==
"spoken"
)
{
if
(
string
.
IsNullOrEmpty
(
Answer
))
{
message
=
"请填写口语题答案!"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//其它题
else
if
(
QuestionTypeKey
==
"other"
)
{
if
(
string
.
IsNullOrEmpty
(
Answer
))
{
message
=
"请填写其它题答案!"
;
return
message
;
}
else
{
AnalysisAnswer
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
Answer
);
}
}
//阅读理解和听力题
else
if
(
QuestionTypeKey
==
"reading-comprehensio"
||
QuestionTypeKey
==
"listening"
)
{
var
readingList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
readingComprehensioItem
>>(
QuestionContent
);
if
(
readingList
!=
null
&&
readingList
.
Count
>
0
)
{
List
<
matchingItem
>
resultList
=
new
List
<
matchingItem
>();
int
Index
=
1
;
foreach
(
var
item
in
readingList
)
{
if
(
string
.
IsNullOrEmpty
(
item
.
SubTitle
))
{
message
=
"请填写题干!"
;
return
message
;
}
switch
(
item
.
QuestionKey
)
{
//单选题
case
"single"
:
var
singleAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
string
singleMessage
=
CheckChoose
(
singleAnwser
);
if
(!
string
.
IsNullOrEmpty
(
singleMessage
))
{
return
singleMessage
;
}
else
{
resultList
.
Add
(
new
matchingItem
{
Name
=
Index
.
ToString
(),
Content
=
singleAnwser
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
)?.
FirstOrDefault
()?.
Name
});
}
break
;
//多选题
case
"multiple"
:
var
multipleAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
string
multipleMessage
=
CheckChoose
(
multipleAnwser
);
if
(!
string
.
IsNullOrEmpty
(
multipleMessage
))
{
return
multipleMessage
;
}
else
{
resultList
.
Add
(
new
matchingItem
{
Name
=
Index
.
ToString
(),
Content
=
string
.
Join
(
","
,
multipleAnwser
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Select
(
qitem
=>
qitem
.
Name
))
});
}
break
;
//填空题
case
"fill-in"
:
var
r_fillInList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
item
.
SubAnwser
.
ToString
());
string
r_fillMessage
=
CheckFillIn
(
r_fillInList
);
if
(!
string
.
IsNullOrEmpty
(
r_fillMessage
))
{
return
r_fillMessage
;
}
else
{
resultList
.
Add
(
new
matchingItem
{
Name
=
Index
.
ToString
(),
Content
=
string
.
Join
(
","
,
r_fillInList
.
Select
(
qitem
=>
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
qitem
.
Content
)))
});
}
break
;
//判断题
case
"judge"
:
var
judgeList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
resultList
.
Add
(
new
matchingItem
{
Name
=
Index
.
ToString
(),
Content
=
judgeList
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
)?.
FirstOrDefault
()?.
Name
});
break
;
//简答题
case
"short-answer"
:
var
shortAnswer
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
item
.
SubAnwser
.
ToString
());
string
r_shortMessage
=
CheckShortAnswer
(
shortAnswer
[
0
].
Content
);
if
(!
string
.
IsNullOrEmpty
(
r_shortMessage
))
{
return
r_shortMessage
;
}
else
{
resultList
.
Add
(
new
matchingItem
{
Name
=
Index
.
ToString
(),
Content
=
Common
.
Plugin
.
StringHelper
.
AppHtmlFilterr
(
shortAnswer
[
0
].
Content
)
});
}
break
;
}
Index
++;
}
if
(
resultList
!=
null
&&
resultList
.
Count
>
0
)
{
AnalysisAnswer
=
Common
.
Plugin
.
JsonHelper
.
Serialize
(
resultList
);
}
}
else
{
message
=
"请添加小题!"
;
return
message
;
}
}
//共用选择题
else
if
(
QuestionTypeKey
==
"sharing-choose"
)
{
var
shareList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
QuestionContent
);
if
(
shareList
!=
null
&&
shareList
.
Count
==
2
)
{
if
(
shareList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
string
.
Format
(
"选项内容不能为空!"
);
return
message
;
}
//判断选项是否重复
if
(
shareList
[
0
].
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
message
=
string
.
Format
(
"选项内容不能相同!"
);
return
message
;
}
if
(
shareList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
string
.
Format
(
"题干不能为空!"
);
return
message
;
}
//判断题干是否重复
if
(
shareList
[
1
].
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
message
=
string
.
Format
(
"题干不能相同!"
);
return
message
;
}
//判断题干是否设置正确选项
if
(
shareList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Name
)).
Count
()
>
0
)
{
message
=
string
.
Format
(
"请设置题干的正确选项!"
);
return
message
;
}
else
{
AnalysisAnswer
=
string
.
Join
(
","
,
shareList
[
1
].
Select
(
qitem
=>
qitem
.
Name
));
}
}
else
{
message
=
string
.
Format
(
"请添加选项!"
);
return
message
;
}
}
return
message
;
}
/// <summary>
/// 选择题验证
/// </summary>
/// <param name="optionItems"></param>
/// <returns></returns>
private
string
CheckChoose
(
List
<
optionItem
>
optionItems
)
{
string
message
=
""
;
if
(
optionItems
!=
null
&&
optionItems
.
Count
>
0
)
{
if
(
optionItems
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"选项不能为空!"
;
}
//判断选项是否重复
if
(
optionItems
.
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
message
=
"选项不能相同!"
;
}
if
(!(
optionItems
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Count
()
>
0
))
{
message
=
"请设置正确的选项!"
;
}
}
else
{
message
=
"请添加选择题选项!"
;
}
return
message
;
}
/// <summary>
/// 验证填空题
/// </summary>
/// <param name="fillInList"></param>
/// <returns></returns>
private
string
CheckFillIn
(
List
<
fillInItem
>
fillInList
)
{
string
message
=
""
;
if
(
fillInList
!=
null
&&
fillInList
.
Count
>
0
)
{
if
(
fillInList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"请输入答案!"
;
}
}
else
{
message
=
"请添加答案!"
;
}
return
message
;
}
/// <summary>
/// 验证简答题
/// </summary>
/// <param name="answer"></param>
/// <returns></returns>
private
string
CheckShortAnswer
(
string
answer
)
{
string
message
=
""
;
if
(
string
.
IsNullOrEmpty
(
answer
))
{
message
=
"请填写简答题答案!"
;
}
return
message
;
}
}
}
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
f3c08132
...
...
@@ -27,6 +27,11 @@ namespace Edu.WebApi.Controllers.Course
/// </summary>
private
readonly
QuestionModule
questionModule
=
AOP
.
AOPHelper
.
CreateAOPObject
<
QuestionModule
>();
/// <summary>
/// 问题验证处理类
/// </summary>
private
readonly
AnalysisQuestionTypeModule
analysisQuestion
=
new
AnalysisQuestionTypeModule
();
#
region
题库管理
/// <summary>
/// 获取课程问题分页列表
...
...
@@ -343,289 +348,14 @@ namespace Edu.WebApi.Controllers.Course
{
return
ApiResult
.
Failed
(
message
:
"请填写问题题干!"
);
}
//单选、多选、单选(数字)题
if
(
extModel
.
QuestionTypeKey
==
"single"
||
extModel
.
QuestionTypeKey
==
"multiple"
||
extModel
.
QuestionTypeKey
==
"single-number"
)
{
var
optionItems
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
extModel
.
QuestionContent
);
string
message
=
CheckChoose
(
optionItems
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
ApiResult
.
Failed
(
message
:
message
);
}
}
//判断题
else
if
(
extModel
.
QuestionTypeKey
==
"judge"
)
{
var
optionItems
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
extModel
.
QuestionContent
);
string
message
=
CheckChoose
(
optionItems
);
if
(!
string
.
IsNullOrEmpty
(
message
))
{
return
ApiResult
.
Failed
(
message
:
message
);
}
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
extModel
.
Answer
=
optionItems
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
)?.
FirstOrDefault
()?.
Name
;
}
}
//填空题
else
if
(
extModel
.
QuestionTypeKey
==
"fill-in"
)
string
str
=
analysisQuestion
.
CheckQuestion
(
extModel
.
QuestionTypeKey
,
extModel
.
QuestionContent
,
extModel
.
Answer
,
out
string
newAnswer
);
if
(!
string
.
IsNullOrEmpty
(
str
))
{
var
fillInList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
extModel
.
QuestionContent
);
string
fillMessage
=
CheckFillIn
(
fillInList
);
if
(!
string
.
IsNullOrEmpty
(
fillMessage
))
{
return
ApiResult
.
Failed
(
message
:
fillMessage
);
}
return
ApiResult
.
Failed
(
message
:
str
);
}
//简答题
else
if
(
extModel
.
QuestionTypeKey
==
"short-answer"
)
{
string
shortMessage
=
CheckShortAnswer
(
extModel
.
Answer
);
if
(!
string
.
IsNullOrEmpty
(
shortMessage
))
{
return
ApiResult
.
Failed
(
message
:
shortMessage
);
}
extModel
.
QuestionContent
=
""
;
}
//名词解释
else
if
(
extModel
.
QuestionTypeKey
==
"noun-explanation"
)
{
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
return
ApiResult
.
Failed
(
message
:
"请填写名词解释答案!"
);
}
extModel
.
QuestionContent
=
""
;
}
//论述题
else
if
(
extModel
.
QuestionTypeKey
==
"essay-question"
)
{
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
return
ApiResult
.
Failed
(
message
:
"请填写论述题答案!"
);
}
extModel
.
QuestionContent
=
""
;
}
//计算题
else
if
(
extModel
.
QuestionTypeKey
==
"calculation"
)
{
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
return
ApiResult
.
Failed
(
message
:
"请填写计算题答案!"
);
}
extModel
.
QuestionContent
=
""
;
}
//分录题、资料题
else
if
(
extModel
.
QuestionTypeKey
==
"entry-problem"
||
extModel
.
QuestionTypeKey
==
"data-question"
)
{
var
entryList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
extModel
.
QuestionContent
);
if
(
entryList
!=
null
&&
entryList
.
Count
>
0
)
{
if
(
entryList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
"请输入答案!"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加答案!"
);
}
}
//排序题
else
if
(
extModel
.
QuestionTypeKey
==
"sorting-problem"
)
{
var
sortList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
extModel
.
QuestionContent
);
if
(
sortList
!=
null
&&
sortList
.
Count
>
0
)
{
if
(
sortList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
"请输入选项内容!"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加选项!"
);
}
}
//连线题
else
if
(
extModel
.
QuestionTypeKey
==
"matching"
)
{
var
matchList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
extModel
.
QuestionContent
);
if
(
matchList
!=
null
&&
matchList
.
Count
>
0
)
{
if
(
matchList
[
0
]
!=
null
&&
matchList
[
0
].
Count
>
0
)
{
if
(
matchList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
"第一组选项内容不能为空!"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加第一组选项!"
);
}
if
(
matchList
.
Count
>
1
&&
matchList
[
1
]
!=
null
&&
matchList
[
1
].
Count
>
0
)
{
if
(
matchList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
"第二组选项内容不能为空!"
);
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加第二组选项!"
);
}
if
(
matchList
.
Count
>
2
)
{
if
(
matchList
[
2
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
"请设置答案!"
);
}
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加选项!"
);
}
}
//完型填空
else
if
(
extModel
.
QuestionTypeKey
==
"cloze"
)
{
var
clozeList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
optionItem
>>>(
extModel
.
QuestionContent
);
if
(
clozeList
!=
null
&&
clozeList
.
Count
>
0
)
{
int
index
=
1
;
foreach
(
var
subList
in
clozeList
)
{
if
(
subList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"第{0}小题选项内容不能为空!"
,
index
));
}
if
(!(
subList
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Count
()
>
0
))
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"请设置第{0}小题选项的正确答案!"
,
index
));
}
index
++;
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加小题!"
);
}
}
//口语题
else
if
(
extModel
.
QuestionTypeKey
==
"spoken"
)
{
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
return
ApiResult
.
Failed
(
message
:
"请填写口语题答案!"
);
}
}
//其它题
else
if
(
extModel
.
QuestionTypeKey
==
"other"
)
{
if
(
string
.
IsNullOrEmpty
(
extModel
.
Answer
))
{
return
ApiResult
.
Failed
(
message
:
"请填写其它题答案!"
);
}
}
//阅读理解和听力题
else
if
(
extModel
.
QuestionTypeKey
==
"reading-comprehensio"
||
extModel
.
QuestionTypeKey
==
"listening"
)
{
var
readingList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
readingComprehensioItem
>>(
extModel
.
QuestionContent
);
if
(
readingList
!=
null
&&
readingList
.
Count
>
0
)
{
foreach
(
var
item
in
readingList
)
{
if
(
string
.
IsNullOrEmpty
(
item
.
SubTitle
))
{
return
ApiResult
.
Failed
(
message
:
"请填写题干!"
);
}
switch
(
item
.
QuestionKey
)
{
//单选题
case
"single"
:
var
singleAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
string
singleMessage
=
CheckChoose
(
singleAnwser
);
if
(!
string
.
IsNullOrEmpty
(
singleMessage
))
{
return
ApiResult
.
Failed
(
message
:
singleMessage
);
}
break
;
//多选题
case
"multiple"
:
var
multipleAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
string
multipleMessage
=
CheckChoose
(
multipleAnwser
);
if
(!
string
.
IsNullOrEmpty
(
multipleMessage
))
{
return
ApiResult
.
Failed
(
message
:
multipleMessage
);
}
break
;
//填空题
case
"fill-in"
:
var
r_fillInList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
item
.
SubAnwser
.
ToString
());
string
r_fillMessage
=
CheckFillIn
(
r_fillInList
);
if
(!
string
.
IsNullOrEmpty
(
r_fillMessage
))
{
return
ApiResult
.
Failed
(
message
:
r_fillMessage
);
}
break
;
//判断题
case
"judge"
:
item
.
SubAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
break
;
//简答题
case
"short-answer"
:
var
shortAnswer
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
item
.
SubAnwser
.
ToString
());
string
r_shortMessage
=
CheckShortAnswer
(
shortAnswer
[
0
].
Content
);
if
(!
string
.
IsNullOrEmpty
(
r_shortMessage
))
{
return
ApiResult
.
Failed
(
message
:
r_shortMessage
);
}
break
;
}
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加小题!"
);
}
}
//共用选择题
else
if
(
extModel
.
QuestionTypeKey
==
"sharing-choose"
)
else
{
var
shareList
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
List
<
matchingItem
>>>(
extModel
.
QuestionContent
);
if
(
shareList
!=
null
&&
shareList
.
Count
==
2
)
{
if
(
shareList
[
0
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"选项内容不能为空!"
));
}
//判断选项是否重复
if
(
shareList
[
0
].
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"选项内容不能相同!"
));
}
if
(
shareList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"题干不能为空!"
));
}
//判断题干是否重复
if
(
shareList
[
1
].
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"题干不能相同!"
));
}
//判断题干是否设置正确选项
if
(
shareList
[
1
].
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Name
)).
Count
()
>
0
)
{
return
ApiResult
.
Failed
(
message
:
string
.
Format
(
"请设置题干的正确选项!"
));
}
}
else
{
return
ApiResult
.
Failed
(
message
:
"请添加选项!"
);
}
extModel
.
Answer
=
newAnswer
;
}
extModel
.
CreateTime
=
DateTime
.
Now
;
extModel
.
CreateBy
=
base
.
UserInfo
.
Id
;
...
...
@@ -648,74 +378,6 @@ namespace Edu.WebApi.Controllers.Course
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
/// <summary>
/// 选择题验证
/// </summary>
/// <param name="optionItems"></param>
/// <returns></returns>
private
string
CheckChoose
(
List
<
optionItem
>
optionItems
)
{
string
message
=
""
;
if
(
optionItems
!=
null
&&
optionItems
.
Count
>
0
)
{
if
(
optionItems
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"选项不能为空!"
;
}
//判断选项是否重复
if
(
optionItems
.
GroupBy
(
qitem
=>
new
{
qitem
.
Content
}).
Where
(
qitem
=>
qitem
.
Count
()
>
1
).
Count
()
>
0
)
{
message
=
"选项不能相同!"
;
}
if
(!(
optionItems
.
Where
(
qitem
=>
qitem
.
IsAnswer
==
true
).
Count
()
>
0
))
{
message
=
"请设置正确的选项!"
;
}
}
else
{
message
=
"请添加选择题选项!"
;
}
return
message
;
}
/// <summary>
/// 验证填空题
/// </summary>
/// <param name="fillInList"></param>
/// <returns></returns>
private
string
CheckFillIn
(
List
<
fillInItem
>
fillInList
)
{
string
message
=
""
;
if
(
fillInList
!=
null
&&
fillInList
.
Count
>
0
)
{
if
(
fillInList
.
Where
(
qitem
=>
string
.
IsNullOrEmpty
(
qitem
.
Content
)).
Count
()
>
0
)
{
message
=
"请输入答案!"
;
}
}
else
{
message
=
"请添加答案!"
;
}
return
message
;
}
/// <summary>
/// 验证简答题
/// </summary>
/// <param name="answer"></param>
/// <returns></returns>
private
string
CheckShortAnswer
(
string
answer
)
{
string
message
=
""
;
if
(
string
.
IsNullOrEmpty
(
answer
))
{
message
=
"请填写简答题答案!"
;
}
return
message
;
}
/// <summary>
/// 获取课程问题
/// </summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment