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
f5a7356e
Commit
f5a7356e
authored
Jan 25, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增解析方法
parent
0d2dd957
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
14 deletions
+153
-14
QuestionHelper.cs
Edu.Common/Data/QuestionHelper.cs
+18
-7
LevelTypeEnum.cs
Edu.Common/Enum/Question/LevelTypeEnum.cs
+44
-0
ConvertHelper.cs
Edu.Common/Plugin/ConvertHelper.cs
+7
-0
WordHelper.cs
Edu.Common/Plugin/WordHelper.cs
+38
-6
RB_Question.cs
Edu.Model/Entity/Question/RB_Question.cs
+5
-0
RB_Question_ViewModel.cs
Edu.Model/ViewModel/Question/RB_Question_ViewModel.cs
+11
-0
QuestionModule.cs
Edu.Module.Question/QuestionModule.cs
+1
-0
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+29
-1
No files found.
Edu.Common/Data/QuestionHelper.cs
View file @
f5a7356e
...
...
@@ -114,7 +114,7 @@ namespace Edu.Common.Data
public
static
List
<
ImportModel
>
GetWordQuestionData
(
string
filePath
)
{
List
<
ImportModel
>
list
=
new
List
<
ImportModel
>();
var
questionList
=
Common
.
Plugin
.
WordHelper
.
GetWordData
(
filePath
);
var
questionList
=
Common
.
Plugin
.
WordHelper
.
GetWordData
(
filePath
,
out
List
<
string
>
htmlList
);
if
(
questionList
!=
null
&&
questionList
.
Count
>
0
)
{
foreach
(
var
rootItem
in
questionList
)
...
...
@@ -136,7 +136,7 @@ namespace Edu.Common.Data
SubQuestionList
=
new
List
<
ImportModel
>(),
QuestionTypeName
=
"阅读理解"
};
AnalysisReadingQuestion
(
item
,
model
);
AnalysisReadingQuestion
(
item
,
model
,
htmlList
);
list
.
Add
(
model
);
}
}
...
...
@@ -152,7 +152,7 @@ namespace Edu.Common.Data
};
if
(!
string
.
IsNullOrEmpty
(
item
))
{
AnalysisQuestionTitle
(
item
,
model
);
AnalysisQuestionTitle
(
item
,
model
,
htmlList
);
list
.
Add
(
model
);
}
}
...
...
@@ -168,14 +168,25 @@ namespace Edu.Common.Data
/// </summary>
/// <param name="item"></param>
/// <param name="model"></param>
private
static
void
AnalysisQuestionTitle
(
string
item
,
ImportModel
model
)
private
static
void
AnalysisQuestionTitle
(
string
item
,
ImportModel
model
,
List
<
string
>
htmlList
)
{
string
pattern
=
@"\r\n"
;
var
tempArray
=
Regex
.
Split
(
item
,
pattern
);
string
answerObj
=
""
;
//答案
if
(
tempArray
!=
null
&&
tempArray
.
Length
>
0
)
{
model
.
QuestionTitle
=
tempArray
[
0
].
Trim
();
string
strTitle
=
tempArray
[
0
].
Trim
();
if
(
htmlList
!=
null
&&
htmlList
.
Count
>
0
)
{
foreach
(
var
hItem
in
htmlList
)
{
if
(
strTitle
.
Contains
(
hItem
))
{
strTitle
=
strTitle
.
Replace
(
hItem
,
Common
.
ConvertHelper
.
GetSpanString
(
hItem
));
}
}
}
model
.
QuestionTitle
=
strTitle
;
foreach
(
var
subItem
in
tempArray
)
{
if
(!
string
.
IsNullOrEmpty
(
subItem
))
...
...
@@ -523,7 +534,7 @@ namespace Edu.Common.Data
/// </summary>
/// <param name="questionStr"></param>
/// <param name="model"></param>
private
static
void
AnalysisReadingQuestion
(
string
questionStr
,
ImportModel
model
)
private
static
void
AnalysisReadingQuestion
(
string
questionStr
,
ImportModel
model
,
List
<
string
>
htmlList
)
{
string
[]
tempArray
=
null
;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
...
...
@@ -539,7 +550,7 @@ namespace Edu.Common.Data
if
(
index
>
0
)
{
ImportModel
subQuestion
=
new
ImportModel
();
AnalysisQuestionTitle
(
item
,
subQuestion
);
AnalysisQuestionTitle
(
item
,
subQuestion
,
htmlList
);
model
.
SubQuestionList
.
Add
(
subQuestion
);
model
.
AnswerAnalysis
+=
"<p>"
+(
index
)
+
"、"
+
subQuestion
.
AnswerAnalysis
+
"</p>"
;
}
...
...
Edu.Common/Enum/Question/LevelTypeEnum.cs
0 → 100644
View file @
f5a7356e
using
Edu.Common.Plugin
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Edu.Common.Enum.Question
{
/// <summary>
/// 考级程度
/// </summary>
public
enum
LevelTypeEnum
{
/// <summary>
/// N5
/// </summary>
[
EnumField
(
"N5"
)]
N5
=
5
,
/// <summary>
///N4
/// </summary>
[
EnumField
(
"N4"
)]
N4
=
4
,
/// <summary>
///N3
/// </summary>
[
EnumField
(
"N3"
)]
N3
=
3
,
/// <summary>
///N2
/// </summary>
[
EnumField
(
"N2"
)]
N2
=
2
,
/// <summary>
///N1
/// </summary>
[
EnumField
(
"N1"
)]
N1
=
1
,
}
}
Edu.Common/Plugin/ConvertHelper.cs
View file @
f5a7356e
...
...
@@ -291,5 +291,12 @@ namespace Edu.Common
builder
.
AppendFormat
(
@"<p><img src='data:image/png;base64,{0}' /></p>"
,
base64
);
return
builder
.
ToString
();
}
public
static
string
GetSpanString
(
string
value
)
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"<span style='text-decoration: underline;'>{0}</span>"
,
value
);
return
builder
.
ToString
();
}
}
}
\ No newline at end of file
Edu.Common/Plugin/WordHelper.cs
View file @
f5a7356e
...
...
@@ -6,7 +6,9 @@ using System.Collections;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Xml
;
namespace
Edu.Common.Plugin
{
...
...
@@ -20,18 +22,47 @@ namespace Edu.Common.Plugin
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public
static
List
<
QuestionWordData
>
GetWordData
(
string
filePath
)
public
static
List
<
QuestionWordData
>
GetWordData
(
string
filePath
,
out
List
<
string
>
htmlList
)
{
List
<
QuestionWordData
>
list
=
new
List
<
QuestionWordData
>();
Spire
.
Doc
.
Document
document
=
new
Spire
.
Doc
.
Document
();
document
.
LoadFromFile
(
filePath
);
string
basepath
=
AppContext
.
BaseDirectory
;
string
tempPath
=
basepath
+
"\\upfile\\temporary\\"
+
DateTime
.
Now
.
ToString
(
"yyyyMMdd"
)
+
"\\"
;
List
<
string
>
imageList
=
new
List
<
string
>(
);
string
tempPath
=
basepath
+
"\\upfile\\temporary\\"
+
DateTime
.
Now
.
ToString
(
"yyyyMMdd"
)
+
"\\
html\\
"
;
document
.
LoadFromFile
(
filePath
);
if
(!
Directory
.
Exists
(
tempPath
))
{
Directory
.
CreateDirectory
(
tempPath
);
}
string
htmlName
=
basepath
+
DateTime
.
Now
.
Ticks
+
".html"
;
document
.
SaveToFile
(
htmlName
,
FileFormat
.
Html
);
htmlList
=
new
List
<
string
>();
try
{
Stream
myStream
=
new
FileStream
(
htmlName
,
FileMode
.
Open
);
Encoding
encode
=
System
.
Text
.
Encoding
.
GetEncoding
(
"utf-8"
);
//若是格式为utf-8的需要将gb2312替换
StreamReader
myStreamReader
=
new
StreamReader
(
myStream
,
encode
);
string
strhtml
=
myStreamReader
.
ReadToEnd
();
string
htmlRule
=
@"<span[^>]+>([^<]+)</span>"
;
System
.
Text
.
RegularExpressions
.
MatchCollection
matchCol
=
System
.
Text
.
RegularExpressions
.
Regex
.
Matches
(
strhtml
,
htmlRule
);
foreach
(
var
item
in
matchCol
)
{
if
(
item
!=
null
&&
!
string
.
IsNullOrEmpty
(
item
.
ToString
())
&&
item
.
ToString
().
Contains
(
"underline"
))
{
string
newStr
=
Common
.
Plugin
.
HtmlHelper
.
StripHT
(
item
.
ToString
());
if
(!
string
.
IsNullOrEmpty
(
newStr
)
&&
!
htmlList
.
Contains
(
newStr
))
{
htmlList
.
Add
(
newStr
);
}
}
}
}
catch
(
Exception
ex
)
{
}
List
<
string
>
imageList
=
new
List
<
string
>();
foreach
(
Section
section
in
document
.
Sections
)
{
foreach
(
Paragraph
paragraph
in
section
.
Paragraphs
)
...
...
@@ -52,6 +83,7 @@ namespace Edu.Common.Plugin
}
}
string
str
=
document
.
GetText
();
str
=
str
.
Replace
(
"Evaluation Warning: The document was created with Spire.Doc for .NET."
,
""
);
//解析大类
string
categoryRule1
=
@"[第][一二三四五六七八九十][部][分]"
;
...
...
@@ -66,7 +98,7 @@ namespace Edu.Common.Plugin
{
if
(!
string
.
IsNullOrEmpty
(
item
))
{
var
model
=
AnalysisQuestionCategory
(
item
,
imageList
,
isBigType
:
true
);
var
model
=
AnalysisQuestionCategory
(
item
,
imageList
,
isBigType
:
true
);
if
(
model
!=
null
&&
!
string
.
IsNullOrEmpty
(
model
.
BigTitle
))
{
list
.
Add
(
model
);
...
...
@@ -88,7 +120,7 @@ namespace Edu.Common.Plugin
/// <param name="questionStr"></param>
/// <param name="isBigType">是否是大类</param>
/// <returns></returns>
private
static
QuestionWordData
AnalysisQuestionCategory
(
string
questionStr
,
List
<
string
>
imageList
,
bool
isBigType
=
false
)
private
static
QuestionWordData
AnalysisQuestionCategory
(
string
questionStr
,
List
<
string
>
imageList
,
bool
isBigType
=
false
)
{
QuestionWordData
questionWordData
=
new
QuestionWordData
();
// \r\n【图一】\r\n
...
...
Edu.Model/Entity/Question/RB_Question.cs
View file @
f5a7356e
...
...
@@ -107,5 +107,10 @@ namespace Edu.Model.Entity.Question
/// 题目所属大类
/// </summary>
public
QuestionCategoryEnum
?
Category
{
get
;
set
;
}
/// <summary>
/// 考级程度
/// </summary>
public
LevelTypeEnum
?
LevelType
{
get
;
set
;
}
}
}
Edu.Model/ViewModel/Question/RB_Question_ViewModel.cs
View file @
f5a7356e
...
...
@@ -85,5 +85,16 @@ namespace Edu.Model.ViewModel.Question
/// 分类编号
/// </summary>
public
string
QCategoryId
{
get
;
set
;
}
/// <summary>
/// 考级程度
/// </summary>
public
string
LevelTypeName
{
get
{
return
Common
.
Plugin
.
EnumHelper
.
ToName
(
this
.
LevelType
);
}
}
}
}
\ No newline at end of file
Edu.Module.Question/QuestionModule.cs
View file @
f5a7356e
...
...
@@ -92,6 +92,7 @@ namespace Edu.Module.Question
{
nameof
(
RB_Question_ViewModel
.
Answer
),
model
.
Answer
},
{
nameof
(
RB_Question_ViewModel
.
IsMutex
),
model
.
IsMutex
},
{
nameof
(
RB_Question_ViewModel
.
Category
),
model
.
Category
},
{
nameof
(
RB_Question_ViewModel
.
LevelType
),
model
.
LevelType
},
};
flag
=
questionRepository
.
Update
(
fileds
,
new
WhereHelper
(
nameof
(
RB_Question_ViewModel
.
QuestionId
),
model
.
QuestionId
));
}
...
...
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
f5a7356e
...
...
@@ -119,7 +119,7 @@ namespace Edu.WebApi.Controllers.Course
Title
=
newTitle
,
item
.
QuestionTypeId
,
item
.
QuestionTypeKey
,
item
.
QuestionTypeName
,
QuestionTypeName
=
item
.
QuestionTypeKey
!=
"single-number"
?
item
.
QuestionTypeName
:
"选择题"
,
item
.
CreateByName
,
item
.
CreateTimeStr
,
item
.
DifficultyType
,
...
...
@@ -604,6 +604,34 @@ namespace Edu.WebApi.Controllers.Course
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
/// <summary>
/// 复制问题
/// </summary>
/// <returns></returns>
[
HttpPost
]
public
ApiResult
CopyQuestion
()
{
var
questionId
=
base
.
ParmJObj
.
GetInt
(
"QuestionId"
,
0
);
if
(
questionId
>
0
)
{
var
copyModel
=
questionModule
.
GetQuestionModule
(
questionId
);
if
(
copyModel
!=
null
)
{
copyModel
.
QuestionId
=
0
;
copyModel
.
CreateTime
=
DateTime
.
Now
;
copyModel
.
CreateBy
=
base
.
UserInfo
.
Id
;
copyModel
.
UpdateBy
=
base
.
UserInfo
.
Id
;
copyModel
.
UpdateTime
=
DateTime
.
Now
;
}
var
flag
=
false
;
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
else
{
return
ApiResult
.
Failed
(
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