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
4fec8383
Commit
4fec8383
authored
Jan 26, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
f68f4aa8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
15 deletions
+92
-15
QuestionHelper.cs
Edu.Common/Data/QuestionHelper.cs
+34
-5
WordHelper.cs
Edu.Common/Plugin/WordHelper.cs
+57
-9
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+1
-1
No files found.
Edu.Common/Data/QuestionHelper.cs
View file @
4fec8383
...
@@ -4,6 +4,7 @@ using System.Data;
...
@@ -4,6 +4,7 @@ using System.Data;
using
System.Text
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
using
System.Linq
;
using
System.Linq
;
using
Edu.Common.Plugin
;
namespace
Edu.Common.Data
namespace
Edu.Common.Data
{
{
...
@@ -114,7 +115,7 @@ namespace Edu.Common.Data
...
@@ -114,7 +115,7 @@ namespace Edu.Common.Data
public
static
List
<
ImportModel
>
GetWordQuestionData
(
string
filePath
)
public
static
List
<
ImportModel
>
GetWordQuestionData
(
string
filePath
)
{
{
List
<
ImportModel
>
list
=
new
List
<
ImportModel
>();
List
<
ImportModel
>
list
=
new
List
<
ImportModel
>();
var
questionList
=
Common
.
Plugin
.
WordHelper
.
GetWordData
(
filePath
,
out
List
<
string
>
htmlList
);
var
questionList
=
Common
.
Plugin
.
WordHelper
.
GetWordData
(
filePath
,
out
List
<
QuestionTitleData
>
htmlList
);
if
(
questionList
!=
null
&&
questionList
.
Count
>
0
)
if
(
questionList
!=
null
&&
questionList
.
Count
>
0
)
{
{
foreach
(
var
rootItem
in
questionList
)
foreach
(
var
rootItem
in
questionList
)
...
@@ -168,7 +169,7 @@ namespace Edu.Common.Data
...
@@ -168,7 +169,7 @@ namespace Edu.Common.Data
/// </summary>
/// </summary>
/// <param name="item"></param>
/// <param name="item"></param>
/// <param name="model"></param>
/// <param name="model"></param>
private
static
void
AnalysisQuestionTitle
(
string
item
,
ImportModel
model
,
List
<
string
>
htmlList
)
private
static
void
AnalysisQuestionTitle
(
string
item
,
ImportModel
model
,
List
<
QuestionTitleData
>
htmlList
)
{
{
string
pattern
=
@"\r\n"
;
string
pattern
=
@"\r\n"
;
var
tempArray
=
Regex
.
Split
(
item
,
pattern
);
var
tempArray
=
Regex
.
Split
(
item
,
pattern
);
...
@@ -176,16 +177,44 @@ namespace Edu.Common.Data
...
@@ -176,16 +177,44 @@ namespace Edu.Common.Data
if
(
tempArray
!=
null
&&
tempArray
.
Length
>
0
)
if
(
tempArray
!=
null
&&
tempArray
.
Length
>
0
)
{
{
string
strTitle
=
tempArray
[
0
].
Trim
();
string
strTitle
=
tempArray
[
0
].
Trim
();
if
(
htmlList
!=
null
&&
htmlList
.
Count
>
0
)
if
(
htmlList
!=
null
&&
htmlList
.
Count
>
0
)
{
{
foreach
(
var
hItem
in
htmlList
)
foreach
(
var
hItem
in
htmlList
)
{
{
if
(
strTitle
.
Contains
(
hItem
))
try
{
if
(
strTitle
.
Contains
(
hItem
.
UnderLine
))
{
foreach
(
var
subItem
in
htmlList
.
Where
(
qitem
=>
qitem
.
UnderLine
==
hItem
.
UnderLine
))
{
if
(
subItem
.
BeforeAfter
!=
null
)
{
if
(
subItem
.
BeforeAfter
.
Count
==
1
)
{
if
(
strTitle
.
Contains
(
subItem
.
BeforeAfter
[
0
]))
{
strTitle
=
strTitle
.
Replace
(
hItem
.
UnderLine
,
Common
.
ConvertHelper
.
GetSpanString
(
hItem
.
UnderLine
));
}
}
else
if
(
subItem
.
BeforeAfter
.
Count
==
2
)
{
if
(
strTitle
.
Contains
(
subItem
.
BeforeAfter
[
0
])
||
strTitle
.
Contains
(
subItem
.
BeforeAfter
[
1
]))
{
strTitle
=
strTitle
.
Replace
(
hItem
.
UnderLine
,
Common
.
ConvertHelper
.
GetSpanString
(
hItem
.
UnderLine
));
}
}
}
}
}
}
catch
(
Exception
ex
)
{
{
strTitle
=
strTitle
.
Replace
(
hItem
,
Common
.
ConvertHelper
.
GetSpanString
(
hItem
)
);
throw
new
Exception
(
);
}
}
}
}
}
}
model
.
QuestionTitle
=
strTitle
;
model
.
QuestionTitle
=
strTitle
;
foreach
(
var
subItem
in
tempArray
)
foreach
(
var
subItem
in
tempArray
)
{
{
...
@@ -534,7 +563,7 @@ namespace Edu.Common.Data
...
@@ -534,7 +563,7 @@ namespace Edu.Common.Data
/// </summary>
/// </summary>
/// <param name="questionStr"></param>
/// <param name="questionStr"></param>
/// <param name="model"></param>
/// <param name="model"></param>
private
static
void
AnalysisReadingQuestion
(
string
questionStr
,
ImportModel
model
,
List
<
string
>
htmlList
)
private
static
void
AnalysisReadingQuestion
(
string
questionStr
,
ImportModel
model
,
List
<
QuestionTitleData
>
htmlList
)
{
{
string
[]
tempArray
=
null
;
string
[]
tempArray
=
null
;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
...
...
Edu.Common/Plugin/WordHelper.cs
View file @
4fec8383
...
@@ -22,7 +22,7 @@ namespace Edu.Common.Plugin
...
@@ -22,7 +22,7 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
/// <param name="filePath"></param>
/// <param name="filePath"></param>
/// <returns></returns>
/// <returns></returns>
public
static
List
<
QuestionWordData
>
GetWordData
(
string
filePath
,
out
List
<
string
>
htmlList
)
public
static
List
<
QuestionWordData
>
GetWordData
(
string
filePath
,
out
List
<
QuestionTitleData
>
htmlList
)
{
{
List
<
QuestionWordData
>
list
=
new
List
<
QuestionWordData
>();
List
<
QuestionWordData
>
list
=
new
List
<
QuestionWordData
>();
Spire
.
Doc
.
Document
document
=
new
Spire
.
Doc
.
Document
();
Spire
.
Doc
.
Document
document
=
new
Spire
.
Doc
.
Document
();
...
@@ -35,28 +35,60 @@ namespace Edu.Common.Plugin
...
@@ -35,28 +35,60 @@ namespace Edu.Common.Plugin
}
}
string
htmlName
=
tempPath
+
DateTime
.
Now
.
Ticks
+
".html"
;
string
htmlName
=
tempPath
+
DateTime
.
Now
.
Ticks
+
".html"
;
document
.
SaveToFile
(
htmlName
,
FileFormat
.
Html
);
document
.
SaveToFile
(
htmlName
,
FileFormat
.
Html
);
htmlList
=
new
List
<
string
>();
htmlList
=
new
List
<
QuestionTitleData
>();
try
try
{
{
Stream
myStream
=
new
FileStream
(
htmlName
,
FileMode
.
Open
);
Stream
myStream
=
new
FileStream
(
htmlName
,
FileMode
.
Open
);
Encoding
encode
=
System
.
Text
.
Encoding
.
GetEncoding
(
"utf-8"
);
//若是格式为utf-8的需要将gb2312替换
Encoding
encode
=
System
.
Text
.
Encoding
.
GetEncoding
(
"utf-8"
);
//若是格式为utf-8的需要将gb2312替换
StreamReader
myStreamReader
=
new
StreamReader
(
myStream
,
encode
);
StreamReader
myStreamReader
=
new
StreamReader
(
myStream
,
encode
);
string
strhtml
=
myStreamReader
.
ReadToEnd
();
string
strhtml
=
myStreamReader
.
ReadToEnd
();
string
htmlRule
=
@"<
span[^>]+>([^<]+)</span
>"
;
string
htmlRule
=
@"<
p.*?>(.*?)</p
>"
;
System
.
Text
.
RegularExpressions
.
MatchCollection
matchCol
=
System
.
Text
.
RegularExpressions
.
Regex
.
Matches
(
strhtml
,
htmlRule
);
MatchCollection
p_matchs
=
Regex
.
Matches
(
strhtml
,
htmlRule
);
foreach
(
var
item
in
matchCol
)
foreach
(
var
item
in
p_matchs
)
{
{
if
(
item
!=
null
&&
!
string
.
IsNullOrEmpty
(
item
.
ToString
())
&&
item
.
ToString
().
Contains
(
"underline"
))
if
(
item
!=
null
&&
!
string
.
IsNullOrEmpty
(
item
.
ToString
())
&&
item
.
ToString
().
Contains
(
"underline"
))
{
{
string
newStr
=
Common
.
Plugin
.
HtmlHelper
.
StripHT
(
item
.
ToString
());
string
spanRule
=
@"<span[^>]+>([^<]+)</span>"
;
if
(!
string
.
IsNullOrEmpty
(
newStr
)
&&
!
htmlList
.
Contains
(
newStr
))
MatchCollection
span_matchs
=
Regex
.
Matches
(
item
.
ToString
(),
spanRule
);
string
key
=
""
;
List
<
string
>
contentList
=
new
List
<
string
>();
for
(
var
i
=
0
;
i
<
span_matchs
.
Count
;
i
++)
{
{
htmlList
.
Add
(
newStr
);
var
subItem
=
span_matchs
[
i
];
string
newStr
=
Common
.
Plugin
.
HtmlHelper
.
StripHT
(
subItem
.
ToString
());
if
(
subItem
!=
null
&&
!
string
.
IsNullOrEmpty
(
subItem
.
ToString
())
&&
subItem
.
ToString
().
Contains
(
"underline"
))
{
key
=
newStr
;
if
(
i
>
0
)
{
string
upContent
=
Common
.
Plugin
.
HtmlHelper
.
StripHT
(
span_matchs
[
i
-
1
].
ToString
());
if
(!
string
.
IsNullOrEmpty
(
upContent
)&&
upContent
.
Length
>
1
)
{
contentList
.
Add
(
upContent
.
TrimStart
(
'、'
));
}
}
if
((
i
+
1
)
<
span_matchs
.
Count
)
{
string
nextContent
=
Common
.
Plugin
.
HtmlHelper
.
StripHT
(
span_matchs
[
i
+
1
].
ToString
());
if
(!
string
.
IsNullOrEmpty
(
nextContent
)&&
nextContent
.
Length
>
1
)
{
contentList
.
Add
(
nextContent
.
TrimStart
(
'、'
));
}
}
if
(!
string
.
IsNullOrEmpty
(
key
)
&&
contentList
!=
null
&&
contentList
.
Count
>
0
)
{
htmlList
.
Add
(
new
QuestionTitleData
()
{
UnderLine
=
key
,
BeforeAfter
=
contentList
});
}
}
}
}
}
}
}
}
}
}
catch
(
Exception
ex
)
catch
{
{
}
}
...
@@ -231,4 +263,20 @@ namespace Edu.Common.Plugin
...
@@ -231,4 +263,20 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
public
List
<
string
>
QuestionList
{
get
;
set
;
}
public
List
<
string
>
QuestionList
{
get
;
set
;
}
}
}
/// <summary>
/// 替换标题下划线实体
/// </summary>
public
class
QuestionTitleData
{
/// <summary>
/// 下划线内容
/// </summary>
public
string
UnderLine
{
get
;
set
;
}
/// <summary>
/// 下划线内容前后文字
/// </summary>
public
List
<
string
>
BeforeAfter
{
get
;
set
;
}
}
}
}
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
4fec8383
...
@@ -108,7 +108,7 @@ namespace Edu.WebApi.Controllers.Course
...
@@ -108,7 +108,7 @@ namespace Edu.WebApi.Controllers.Course
{
{
newTitle
=
Regex
.
Replace
(
item
.
Title
,
str
,
"[图片]"
);
newTitle
=
Regex
.
Replace
(
item
.
Title
,
str
,
"[图片]"
);
}
}
catch
(
Exception
ex
)
catch
{
{
newTitle
=
item
.
Title
;
newTitle
=
item
.
Title
;
}
}
...
...
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