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
0017b5e7
Commit
0017b5e7
authored
Jan 11, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel导入修改
parent
2846f5d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
239 additions
and
20 deletions
+239
-20
BaseController.cs
Edu.WebApi/Controllers/BaseController.cs
+11
-0
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+226
-19
UploadController.cs
Edu.WebApi/Controllers/Upload/UploadController.cs
+2
-1
No files found.
Edu.WebApi/Controllers/BaseController.cs
View file @
0017b5e7
...
...
@@ -78,6 +78,17 @@ namespace Edu.WebApi.Controllers
}
}
/// <summary>
/// 根据Id获取用户信息
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public
UserInfo
GetUserInfo
(
object
Id
)
{
UserInfo
userInfo
=
UserReidsCache
.
GetUserLoginInfo
(
Id
);
return
userInfo
;
}
/// <summary>
/// 判断用户是否有功能权限
/// </summary>
...
...
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
0017b5e7
...
...
@@ -278,25 +278,37 @@ namespace Edu.WebApi.Controllers.Course
/// 导入Excel问题
/// </summary>
/// <returns></returns>
public
ApiResult
ImportExcelQuestion
(
string
filePath
,
int
CourseId
)
public
ApiResult
ImportExcelQuestion
(
string
filePath
,
int
CourseId
,
int
Uid
)
{
var
userInfo
=
base
.
GetUserInfo
(
Uid
);
var
resultList
=
new
List
<
RB_Question_ViewModel
>();
var
list
=
Common
.
Data
.
QuestionHelper
.
GetXlsQuestionData
(
filePath
);
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
var
difficultyList
=
Common
.
Plugin
.
EnumHelper
.
EnumToList
(
typeof
(
DifficultyTypeEnum
));
var
questionTypeList
=
questionModule
.
GetQuestionTypeListModule
(
new
RB_Question_Type_ViewModel
());
foreach
(
var
item
in
list
)
{
var
model
=
GetQuestionModel
(
item
,
difficultyList
,
questionTypeList
);
var
model
=
GetQuestionModel
(
item
,
questionTypeList
);
model
.
CourseId
=
CourseId
;
model
.
CreateTime
=
DateTime
.
Now
;
model
.
CreateBy
=
userInfo
.
Id
;
model
.
UpdateBy
=
userInfo
.
Id
;
model
.
UpdateTime
=
DateTime
.
Now
;
bool
flag
=
questionModule
.
SetQuestionModule
(
model
);
resultList
.
Add
(
model
);
}
}
return
ApiResult
.
Success
();
return
ApiResult
.
Success
(
data
:
resultList
);
}
private
RB_Question_ViewModel
GetQuestionModel
(
XlsItem
item
,
List
<
EnumItem
>
difficultyList
,
List
<
RB_Question_Type_ViewModel
>
questionTypeList
)
/// <summary>
/// 获取导入数据
/// </summary>
/// <param name="item"></param>
/// <param name="difficultyList"></param>
/// <param name="questionTypeList"></param>
/// <returns></returns>
private
RB_Question_ViewModel
GetQuestionModel
(
XlsItem
item
,
List
<
RB_Question_Type_ViewModel
>
questionTypeList
)
{
var
DifficultyType
=
DifficultyTypeEnum
.
Easy
;
if
(
item
.
EasyType
==
"中"
)
...
...
@@ -450,7 +462,6 @@ namespace Edu.WebApi.Controllers.Course
if
(
ChooseOptionCount
>
0
)
{
List
<
fillInItem
>
fillInList
=
new
List
<
fillInItem
>();
string
answer
=
""
;
for
(
var
i
=
0
;
i
<
ChooseOptionCount
;
i
++)
{
var
singleModel
=
new
fillInItem
()
...
...
@@ -491,11 +502,6 @@ namespace Edu.WebApi.Controllers.Course
}
fillInList
.
Add
(
singleModel
);
}
if
(!
string
.
IsNullOrEmpty
(
answer
))
{
answer
=
answer
.
Substring
(
1
);
}
model
.
Answer
=
answer
;
model
.
QuestionContent
=
Common
.
Plugin
.
JsonHelper
.
Serialize
(
fillInList
);
}
if
(
model
.
QuestionTypeId
==
0
)
...
...
@@ -573,35 +579,35 @@ namespace Edu.WebApi.Controllers.Course
{
if
(
i
==
0
)
{
model
.
QuestionContent
=
item
.
OptionA
;
model
.
Answer
=
item
.
OptionA
;
}
if
(
i
==
1
)
{
model
.
QuestionContent
=
item
.
OptionB
;
model
.
Answer
=
item
.
OptionB
;
}
if
(
i
==
2
)
{
model
.
QuestionContent
=
item
.
OptionC
;
model
.
Answer
=
item
.
OptionC
;
}
if
(
i
==
3
)
{
model
.
QuestionContent
=
item
.
OptionD
;
model
.
Answer
=
item
.
OptionD
;
}
if
(
i
==
4
)
{
model
.
QuestionContent
=
item
.
OptionE
;
model
.
Answer
=
item
.
OptionE
;
}
if
(
i
==
5
)
{
model
.
QuestionContent
=
item
.
OptionF
;
model
.
Answer
=
item
.
OptionF
;
}
if
(
i
==
6
)
{
model
.
QuestionContent
=
item
.
OptionG
;
model
.
Answer
=
item
.
OptionG
;
}
if
(
i
==
7
)
{
model
.
QuestionContent
=
item
.
OptionH
;
model
.
Answer
=
item
.
OptionH
;
}
}
}
...
...
@@ -613,6 +619,207 @@ namespace Edu.WebApi.Controllers.Course
}
break
;
case
"名词解释"
:
if
(
ChooseOptionCount
>
0
)
{
for
(
var
i
=
0
;
i
<
ChooseOptionCount
;
i
++)
{
if
(
i
==
0
)
{
model
.
Answer
=
item
.
OptionA
;
}
if
(
i
==
1
)
{
model
.
Answer
=
item
.
OptionB
;
}
if
(
i
==
2
)
{
model
.
Answer
=
item
.
OptionC
;
}
if
(
i
==
3
)
{
model
.
Answer
=
item
.
OptionD
;
}
if
(
i
==
4
)
{
model
.
Answer
=
item
.
OptionE
;
}
if
(
i
==
5
)
{
model
.
Answer
=
item
.
OptionF
;
}
if
(
i
==
6
)
{
model
.
Answer
=
item
.
OptionG
;
}
if
(
i
==
7
)
{
model
.
Answer
=
item
.
OptionH
;
}
}
}
if
(
model
.
QuestionTypeId
==
0
)
{
var
tempModel
=
questionTypeList
.
Where
(
qitem
=>
qitem
.
Key
==
"noun-explanation"
)?.
FirstOrDefault
();
model
.
QuestionTypeId
=
tempModel
?.
QId
??
0
;
model
.
QuestionTypeKey
=
tempModel
?.
Key
??
""
;
}
break
;
case
"论述题"
:
if
(
ChooseOptionCount
>
0
)
{
for
(
var
i
=
0
;
i
<
ChooseOptionCount
;
i
++)
{
if
(
i
==
0
)
{
model
.
Answer
=
item
.
OptionA
;
}
if
(
i
==
1
)
{
model
.
Answer
=
item
.
OptionB
;
}
if
(
i
==
2
)
{
model
.
Answer
=
item
.
OptionC
;
}
if
(
i
==
3
)
{
model
.
Answer
=
item
.
OptionD
;
}
if
(
i
==
4
)
{
model
.
Answer
=
item
.
OptionE
;
}
if
(
i
==
5
)
{
model
.
Answer
=
item
.
OptionF
;
}
if
(
i
==
6
)
{
model
.
Answer
=
item
.
OptionG
;
}
if
(
i
==
7
)
{
model
.
Answer
=
item
.
OptionH
;
}
}
}
if
(
model
.
QuestionTypeId
==
0
)
{
var
tempModel
=
questionTypeList
.
Where
(
qitem
=>
qitem
.
Key
==
"essay-question"
)?.
FirstOrDefault
();
model
.
QuestionTypeId
=
tempModel
?.
QId
??
0
;
model
.
QuestionTypeKey
=
tempModel
?.
Key
??
""
;
}
break
;
case
"分录题"
:
if
(
ChooseOptionCount
>
0
)
{
List
<
fillInItem
>
fillInList
=
new
List
<
fillInItem
>();
for
(
var
i
=
0
;
i
<
ChooseOptionCount
;
i
++)
{
var
singleModel
=
new
fillInItem
()
{
Content
=
""
,
};
if
(
i
==
0
)
{
singleModel
.
Content
=
item
.
OptionA
;
}
if
(
i
==
1
)
{
singleModel
.
Content
=
item
.
OptionB
;
}
if
(
i
==
2
)
{
singleModel
.
Content
=
item
.
OptionC
;
}
if
(
i
==
3
)
{
singleModel
.
Content
=
item
.
OptionD
;
}
if
(
i
==
4
)
{
singleModel
.
Content
=
item
.
OptionE
;
}
if
(
i
==
5
)
{
singleModel
.
Content
=
item
.
OptionF
;
}
if
(
i
==
6
)
{
singleModel
.
Content
=
item
.
OptionG
;
}
if
(
i
==
7
)
{
singleModel
.
Content
=
item
.
OptionH
;
}
fillInList
.
Add
(
singleModel
);
}
model
.
QuestionContent
=
Common
.
Plugin
.
JsonHelper
.
Serialize
(
fillInList
);
}
if
(
model
.
QuestionTypeId
==
0
)
{
var
tempModel
=
questionTypeList
.
Where
(
qitem
=>
qitem
.
Key
==
"entry-problem"
)?.
FirstOrDefault
();
model
.
QuestionTypeId
=
tempModel
?.
QId
??
0
;
model
.
QuestionTypeKey
=
tempModel
?.
Key
??
""
;
}
break
;
case
"资料题"
:
if
(
ChooseOptionCount
>
0
)
{
List
<
fillInItem
>
fillInList
=
new
List
<
fillInItem
>();
for
(
var
i
=
0
;
i
<
ChooseOptionCount
;
i
++)
{
var
singleModel
=
new
fillInItem
()
{
Content
=
""
,
};
if
(
i
==
0
)
{
singleModel
.
Content
=
item
.
OptionA
;
}
if
(
i
==
1
)
{
singleModel
.
Content
=
item
.
OptionB
;
}
if
(
i
==
2
)
{
singleModel
.
Content
=
item
.
OptionC
;
}
if
(
i
==
3
)
{
singleModel
.
Content
=
item
.
OptionD
;
}
if
(
i
==
4
)
{
singleModel
.
Content
=
item
.
OptionE
;
}
if
(
i
==
5
)
{
singleModel
.
Content
=
item
.
OptionF
;
}
if
(
i
==
6
)
{
singleModel
.
Content
=
item
.
OptionG
;
}
if
(
i
==
7
)
{
singleModel
.
Content
=
item
.
OptionH
;
}
fillInList
.
Add
(
singleModel
);
}
model
.
QuestionContent
=
Common
.
Plugin
.
JsonHelper
.
Serialize
(
fillInList
);
}
if
(
model
.
QuestionTypeId
==
0
)
{
var
tempModel
=
questionTypeList
.
Where
(
qitem
=>
qitem
.
Key
==
"data-question"
)?.
FirstOrDefault
();
model
.
QuestionTypeId
=
tempModel
?.
QId
??
0
;
model
.
QuestionTypeKey
=
tempModel
?.
Key
??
""
;
}
break
;
}
return
model
;
...
...
Edu.WebApi/Controllers/Upload/UploadController.cs
View file @
0017b5e7
...
...
@@ -41,6 +41,7 @@ namespace Edu.WebApi.Controllers.Upload
Int32
.
TryParse
(
json
[
"Analysis"
].
ToString
(),
out
int
Analysis
);
Int32
.
TryParse
(
json
[
"Excel"
].
ToString
(),
out
int
Excel
);
Int32
.
TryParse
(
json
[
"CourseId"
].
ToString
(),
out
int
CourseId
);
Int32
.
TryParse
(
json
[
"Uid"
].
ToString
(),
out
int
Uid
);
string
filename
=
files
[
0
].
FileName
;
string
fileExtention
=
System
.
IO
.
Path
.
GetExtension
(
files
[
0
].
FileName
);
...
...
@@ -70,7 +71,7 @@ namespace Edu.WebApi.Controllers.Upload
//导入Excel文件
if
(
Analysis
==
1
&&
Excel
==
1
&&
CourseId
>
0
)
{
return
new
QuestionController
().
ImportExcelQuestion
(
path_server
,
CourseId
);
return
new
QuestionController
().
ImportExcelQuestion
(
path_server
,
CourseId
,
Uid
);
}
return
ApiResult
.
Success
(
""
,
new
{
Name
=
filename
,
Path
=
path_server
});
}
...
...
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