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
26f3c19d
Commit
26f3c19d
authored
Jan 15, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
cc4c188f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
31 deletions
+102
-31
ConvertHelper.cs
Edu.Common/Plugin/ConvertHelper.cs
+18
-1
WordHelper.cs
Edu.Common/Plugin/WordHelper.cs
+25
-0
QuestionModule.cs
Edu.Module.Question/QuestionModule.cs
+10
-0
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+49
-30
No files found.
Edu.Common/Plugin/ConvertHelper.cs
View file @
26f3c19d
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
...
...
@@ -213,6 +215,21 @@ namespace Edu.Common
}
return
""
;
}
}
/// <summary>
/// 根据文件路径转base64
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public
static
string
ConvertImageToBase64
(
string
filePath
)
{
Image
file
=
Image
.
FromFile
(
filePath
);
using
(
MemoryStream
memoryStream
=
new
MemoryStream
())
{
file
.
Save
(
memoryStream
,
file
.
RawFormat
);
byte
[]
imageBytes
=
memoryStream
.
ToArray
();
return
Convert
.
ToBase64String
(
imageBytes
);
}
}
}
}
\ No newline at end of file
Edu.Common/Plugin/WordHelper.cs
View file @
26f3c19d
using
Spire.Doc
;
using
Spire.Doc.Documents
;
using
Spire.Doc.Fields
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Text
;
using
System.Text.RegularExpressions
;
...
...
@@ -22,7 +25,29 @@ namespace Edu.Common.Plugin
List
<
string
>
list
=
new
List
<
string
>();
Spire
.
Doc
.
Document
document
=
new
Spire
.
Doc
.
Document
();
document
.
LoadFromFile
(
filePath
);
document
.
SaveToFile
(
"toDoc.html"
,
FileFormat
.
Html
);
foreach
(
Section
section
in
document
.
Sections
)
{
foreach
(
Paragraph
paragraph
in
section
.
Paragraphs
)
{
string
para
=
paragraph
.
Text
;
foreach
(
DocumentObject
docObject
in
paragraph
.
ChildObjects
)
{
var
pic
=
docObject
as
DocPicture
;
if
(
pic
!=
null
)
{
string
imageName
=
string
.
Format
(
@"Image-{0}.png"
,
DateTime
.
Now
.
Ticks
);
using
(
MemoryStream
ms
=
new
MemoryStream
(
pic
.
ImageBytes
))
{
Image
outputImg
=
Image
.
FromStream
(
ms
);
outputImg
.
Save
(
@"D:\"
+
imageName
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
}
}
}
}
}
string
str
=
document
.
GetText
();
str
=
str
.
Replace
(
"Evaluation Warning: The document was created with Spire.Doc for .NET."
,
""
);
//“\r\n”开始+“1234567890”出现1次到多次+“、”结尾
string
pattern
=
@"\r\n[1234567890]*、"
;
...
...
Edu.Module.Question/QuestionModule.cs
View file @
26f3c19d
...
...
@@ -103,6 +103,16 @@ namespace Edu.Module.Question
return
flag
;
}
/// <summary>
/// 批量添加问题
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public
virtual
bool
SetQuestionBatchModule
(
List
<
RB_Question_ViewModel
>
list
)
{
return
questionRepository
.
InsertBatch
(
list
);
}
/// <summary>
/// 删除问题
/// </summary>
...
...
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
26f3c19d
...
...
@@ -23,7 +23,7 @@ namespace Edu.WebApi.Controllers.Course
/// <summary>
/// 题库处理类对象
/// </summary>
private
readonly
QuestionModule
questionModule
=
new
QuestionModule
();
private
readonly
QuestionModule
questionModule
=
AOP
.
AOPHelper
.
CreateAOPObject
<
QuestionModule
>
();
#
region
题库管理
...
...
@@ -157,6 +157,22 @@ namespace Edu.WebApi.Controllers.Course
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
/// <summary>
/// 批量添加修改问题
/// </summary>
/// <returns></returns>
[
HttpPost
]
public
ApiResult
SetQuestionBeatch
()
{
bool
flag
=
false
;
var
list
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
RB_Question_ViewModel
>>(
RequestParm
.
Msg
.
ToString
());
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
flag
=
questionModule
.
SetQuestionBatchModule
(
list
);
}
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
/// <summary>
/// 获取课程问题
/// </summary>
...
...
@@ -294,13 +310,43 @@ namespace Edu.WebApi.Controllers.Course
model
.
CreateBy
=
userInfo
.
Id
;
model
.
UpdateBy
=
userInfo
.
Id
;
model
.
UpdateTime
=
DateTime
.
Now
;
//bool flag = questionModule.SetQuestionModule(model);
resultList
.
Add
(
model
);
}
}
System
.
IO
.
File
.
Delete
(
filePath
);
return
ApiResult
.
Success
(
data
:
resultList
);
}
/// <summary>
/// 解析Word
/// </summary>
/// <param name="filePath"></param>
/// <param name="CourseId"></param>
/// <param name="Uid"></param>
/// <returns></returns>
public
ApiResult
ImportWordQuestion
(
string
filePath
,
int
CourseId
,
int
Uid
)
{
var
userInfo
=
base
.
GetUserInfo
(
Uid
);
var
resultList
=
new
List
<
RB_Question_ViewModel
>();
var
list
=
Common
.
Data
.
QuestionHelper
.
GetWordQuestionData
(
filePath
);
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
var
questionTypeList
=
questionModule
.
GetQuestionTypeListModule
(
new
RB_Question_Type_ViewModel
());
foreach
(
var
item
in
list
)
{
var
model
=
GetQuestionModel
(
item
,
questionTypeList
);
model
.
CourseId
=
CourseId
;
model
.
CreateTime
=
DateTime
.
Now
;
model
.
CreateBy
=
userInfo
.
Id
;
model
.
UpdateBy
=
userInfo
.
Id
;
model
.
UpdateTime
=
DateTime
.
Now
;
resultList
.
Add
(
model
);
}
}
System
.
IO
.
File
.
Delete
(
filePath
);
return
ApiResult
.
Success
(
data
:
resultList
);
}
/// <summary>
/// 获取导入数据
/// </summary>
...
...
@@ -826,33 +872,6 @@ namespace Edu.WebApi.Controllers.Course
return
model
;
}
/// <summary>
/// 解析Word
/// </summary>
/// <param name="filePath"></param>
/// <param name="CourseId"></param>
/// <param name="Uid"></param>
/// <returns></returns>
public
ApiResult
ImportWordQuestion
(
string
filePath
,
int
CourseId
,
int
Uid
)
{
var
userInfo
=
base
.
GetUserInfo
(
Uid
);
var
resultList
=
new
List
<
RB_Question_ViewModel
>();
var
list
=
Common
.
Data
.
QuestionHelper
.
GetWordQuestionData
(
filePath
);
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
var
questionTypeList
=
questionModule
.
GetQuestionTypeListModule
(
new
RB_Question_Type_ViewModel
());
foreach
(
var
item
in
list
)
{
var
model
=
GetQuestionModel
(
item
,
questionTypeList
);
model
.
CourseId
=
CourseId
;
model
.
CreateTime
=
DateTime
.
Now
;
model
.
CreateBy
=
userInfo
.
Id
;
model
.
UpdateBy
=
userInfo
.
Id
;
model
.
UpdateTime
=
DateTime
.
Now
;
resultList
.
Add
(
model
);
}
}
return
ApiResult
.
Success
(
data
:
resultList
);
}
}
}
\ No newline at end of file
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