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
a16a667d
Commit
a16a667d
authored
Jan 06, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
9f7b3a77
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
189 additions
and
10 deletions
+189
-10
CourseWordsHelper.cs
Edu.Common/Data/CourseWordsHelper.cs
+64
-8
NPOIHelper.cs
Edu.Common/Plugin/NPOIHelper.cs
+40
-1
RB_Course_Words.cs
Edu.Model/Entity/Course/RB_Course_Words.cs
+8
-0
CourseWordsModule.cs
Edu.Module.Course/CourseWordsModule.cs
+11
-0
RB_Course_WordsRepository.cs
Edu.Repository/Course/RB_Course_WordsRepository.cs
+25
-0
CourseWordsController.cs
Edu.WebApi/Controllers/Course/CourseWordsController.cs
+41
-1
No files found.
Edu.Common/Data/CourseWordsHelper.cs
View file @
a16a667d
...
...
@@ -15,12 +15,16 @@ namespace Edu.Common.Data
public
static
List
<
WordsItem
>
GetXlsWordsData
(
string
filePath
)
{
List
<
WordsItem
>
xlsItems
=
new
List
<
WordsItem
>();
var
d
t
=
Common
.
Plugin
.
NPOIHelper
.
ImportExcelToDatatable
(
filePath
,
0
,
0
,
true
);
if
(
d
t
!=
null
&&
dt
.
Row
s
.
Count
>
0
)
var
d
s
=
Common
.
Plugin
.
NPOIHelper
.
ExcelToDataSet
(
filePath
);
if
(
d
s
!=
null
&&
ds
.
Table
s
.
Count
>
0
)
{
for
each
(
DataRow
item
in
dt
.
Rows
)
for
(
var
i
=
0
;
i
<
ds
.
Tables
.
Count
;
i
++
)
{
xlsItems
.
Add
(
DataRowToModel
(
item
));
var
dataRow
=
ds
.
Tables
[
i
].
Rows
;
for
(
var
j
=
0
;
j
<
ds
.
Tables
[
i
].
Rows
.
Count
;
j
++)
{
xlsItems
.
Add
(
DataRowToModel
((
i
+
1
),
ds
.
Tables
[
i
].
Rows
[
j
]));
}
}
}
return
xlsItems
;
...
...
@@ -29,21 +33,73 @@ namespace Edu.Common.Data
/// <summary>
/// DataRow转实体
/// </summary>
/// <param name="tableName"></param>
/// <param name="dr"></param>
/// <returns></returns>
private
static
WordsItem
DataRowToModel
(
DataRow
dr
)
private
static
WordsItem
DataRowToModel
(
int
ChapterId
,
DataRow
dr
)
{
WordsItem
model
=
new
WordsItem
();
model
.
ChapterId
=
ChapterId
;
if
(
dr
!=
null
)
{
if
(
dr
.
Table
.
Columns
.
Contains
(
"品詞名"
)
&&
!
string
.
IsNullOrEmpty
(
dr
[
"品詞名"
].
ToString
()))
{
model
.
WordType
=
dr
[
"品詞名"
].
ToString
();
}
if
(
dr
.
Table
.
Columns
.
Contains
(
"語彙・表現"
)
&&
!
string
.
IsNullOrEmpty
(
dr
[
"語彙・表現"
].
ToString
()))
{
model
.
WordContent
=
dr
[
"語彙・表現"
].
ToString
();
}
if
(
dr
.
Table
.
Columns
.
Contains
(
"声调"
)
&&
!
string
.
IsNullOrEmpty
(
dr
[
"声调"
].
ToString
()))
{
model
.
WordTone
=
dr
[
"声调"
].
ToString
();
}
if
(
dr
.
Table
.
Columns
.
Contains
(
"日文书写"
)
&&
!
string
.
IsNullOrEmpty
(
dr
[
"日文书写"
].
ToString
()))
{
model
.
WordWrite
=
dr
[
"日文书写"
].
ToString
();
}
if
(
dr
.
Table
.
Columns
.
Contains
(
"中文意思"
)
&&
!
string
.
IsNullOrEmpty
(
dr
[
"中文意思"
].
ToString
()))
{
model
.
ChineseMean
=
dr
[
"中文意思"
].
ToString
();
}
}
return
model
;
}
}
/// <summary>
/// 单词项
/// </summary>
public
class
WordsItem
{
{
/// <summary>
/// 章节编号
/// </summary>
public
int
ChapterId
{
get
;
set
;
}
/// <summary>
/// 单词类型(名词、动词、形容词等)
/// </summary>
public
string
WordType
{
get
;
set
;
}
/// <summary>
/// 单词内容
/// </summary>
public
string
WordContent
{
get
;
set
;
}
/// <summary>
/// 单词声调
/// </summary>
public
string
WordTone
{
get
;
set
;
}
/// <summary>
/// 单词书写
/// </summary>
public
string
WordWrite
{
get
;
set
;
}
/// <summary>
/// 中文意思
/// </summary>
public
string
ChineseMean
{
get
;
set
;
}
}
}
Edu.Common/Plugin/NPOIHelper.cs
View file @
a16a667d
...
...
@@ -586,6 +586,45 @@ namespace Edu.Common.Plugin
return
table
;
}
/// <summary>
/// Excel转DataSet
/// </summary>
/// <param name="excelPath"></param>
/// <returns></returns>
public
static
DataSet
ExcelToDataSet
(
string
excelPath
)
{
int
sheetCount
;
return
ExcelToDataSet
(
excelPath
,
true
,
out
sheetCount
);
}
/// <summary>
/// Excel转DataSet
/// </summary>
/// <param name="excelPath"></param>
/// <param name="firstRowAsHeader"></param>
/// <param name="sheetCount"></param>
/// <returns></returns>
static
DataSet
ExcelToDataSet
(
string
excelPath
,
bool
firstRowAsHeader
,
out
int
sheetCount
)
{
using
(
DataSet
ds
=
new
DataSet
())
{
using
(
FileStream
fileStream
=
new
FileStream
(
excelPath
,
FileMode
.
Open
,
FileAccess
.
Read
))
{
HSSFWorkbook
workbook
=
new
HSSFWorkbook
(
fileStream
);
HSSFFormulaEvaluator
evaluator
=
new
HSSFFormulaEvaluator
(
workbook
);
sheetCount
=
workbook
.
NumberOfSheets
;
for
(
int
i
=
0
;
i
<
sheetCount
;
++
i
)
{
HSSFSheet
sheet
=
workbook
.
GetSheetAt
(
i
)
as
HSSFSheet
;
DataTable
dt
=
ImportDataTable
(
sheet
,
0
,
firstRowAsHeader
);
dt
.
TableName
=
workbook
.
GetSheetName
(
i
);
ds
.
Tables
.
Add
(
dt
);
}
return
ds
;
}
}
}
#
endregion
/// <summary>
...
...
@@ -785,7 +824,7 @@ namespace Edu.Common.Plugin
{
XSSFCell
newCell
=
dataRow
.
CreateCell
(
column
.
Ordinal
)
as
XSSFCell
;
newCell
.
CellStyle
=
cellSource
.
CellStyle
;
String
drValue
=
row
[
column
].
ToString
();
newCell
.
SetCellValue
(
drValue
);
}
...
...
Edu.Model/Entity/Course/RB_Course_Words.cs
View file @
a16a667d
...
...
@@ -2,12 +2,15 @@
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
VT.FW.DB
;
namespace
Edu.Model.Entity.Course
{
/// <summary>
/// 课程章节单词实体类
/// </summary>
[
Serializable
]
[
DB
(
ConnectionName
=
"DefaultConnection"
)]
public
class
RB_Course_Words
{
/// <summary>
...
...
@@ -50,6 +53,11 @@ namespace Edu.Model.Entity.Course
/// </summary>
public
string
ChineseMean
{
get
;
set
;
}
/// <summary>
/// 文件路径
/// </summary>
public
string
FileUrl
{
get
;
set
;
}
/// <summary>
/// 状态
/// </summary>
...
...
Edu.Module.Course/CourseWordsModule.cs
View file @
a16a667d
...
...
@@ -29,6 +29,16 @@ namespace Edu.Module.Course
return
list
;
}
/// <summary>
/// 批量添加课程单词
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public
bool
BatchInsertCourseWordsModule
(
List
<
RB_Course_Words_Extend
>
list
)
{
return
course_WordsRepository
.
BatchInsertCourseWordsRepository
(
list
);
}
/// <summary>
/// 新增修改课程单词
/// </summary>
...
...
@@ -47,6 +57,7 @@ namespace Edu.Module.Course
{
nameof
(
RB_Course_Words_Extend
.
WordTone
),
model
.
WordTone
},
{
nameof
(
RB_Course_Words_Extend
.
WordWrite
),
model
.
WordWrite
},
{
nameof
(
RB_Course_Words_Extend
.
ChineseMean
),
model
.
ChineseMean
},
{
nameof
(
RB_Course_Words_Extend
.
FileUrl
),
model
.
FileUrl
},
{
nameof
(
RB_Course_Words_Extend
.
UpdateBy
),
model
.
UpdateBy
},
{
nameof
(
RB_Course_Words_Extend
.
UpdateTime
),
model
.
UpdateTime
},
};
...
...
Edu.Repository/Course/RB_Course_WordsRepository.cs
View file @
a16a667d
...
...
@@ -40,5 +40,30 @@ WHERE 1=1
}
return
Get
<
RB_Course_Words_Extend
>(
builder
.
ToString
()).
ToList
();
}
/// <summary>
/// 批量添加课程单词
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public
bool
BatchInsertCourseWordsRepository
(
List
<
RB_Course_Words_Extend
>
list
)
{
bool
flag
=
true
;
if
(
list
!=
null
&&
list
.
Count
>
0
)
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
" INSERT INTO RB_Course_Words(CourseId,ChapterId,WordType,WordContent,WordTone,WordWrite,ChineseMean,Status,Group_Id,CreateBy,CreateTime,UpdateBy,UpdateTime) "
);
builder
.
AppendFormat
(
" VALUES "
);
string
tempStr
=
""
;
foreach
(
var
item
in
list
)
{
tempStr
+=
$",(
{
item
.
CourseId
}
,
{
item
.
ChapterId
}
,'
{
item
.
WordType
}
','
{
item
.
WordContent
}
','
{
item
.
WordTone
}
','
{
item
.
WordWrite
}
','
{
item
.
ChineseMean
}
',0,
{
item
.
Group_Id
}
,
{
item
.
CreateBy
}
,'
{
item
.
CreateTime
}
',
{
item
.
UpdateBy
}
,'
{
item
.
UpdateTime
}
') "
;
}
builder
.
Append
(
tempStr
.
TrimStart
(
','
));
flag
=
base
.
Execute
(
builder
.
ToString
())
>
0
;
}
return
flag
;
}
}
}
Edu.WebApi/Controllers/Course/CourseWordsController.cs
View file @
a16a667d
using
Edu.Common.API
;
using
Edu.Model.ViewModel.Course
;
using
Edu.Module.Course
;
using
Edu.WebApi.Filter
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Http
;
...
...
@@ -16,6 +18,11 @@ namespace Edu.WebApi.Controllers.Course
[
EnableCors
(
"AllowCors"
)]
public
class
CourseWordsController
:
BaseController
{
/// <summary>
/// 课程单词处理类对象
/// </summary>
private
readonly
CourseWordsModule
courseWordsModule
=
new
CourseWordsModule
();
/// <summary>
/// 导入Excel单词
/// </summary>
...
...
@@ -24,7 +31,40 @@ namespace Edu.WebApi.Controllers.Course
{
var
userInfo
=
base
.
GetUserInfo
(
Uid
);
var
dataList
=
Common
.
Data
.
CourseWordsHelper
.
GetXlsWordsData
(
filePath
);
return
ApiResult
.
Success
(
data
:
dataList
);
List
<
RB_Course_Words_Extend
>
result
=
new
List
<
RB_Course_Words_Extend
>();
if
(
dataList
!=
null
&&
dataList
.
Count
>
0
)
{
foreach
(
var
item
in
dataList
)
{
var
model
=
new
RB_Course_Words_Extend
()
{
Id
=
0
,
CourseId
=
CourseId
,
ChapterId
=
item
.
ChapterId
,
WordType
=
item
.
WordType
,
WordContent
=
item
.
WordContent
,
WordTone
=
item
.
WordTone
,
WordWrite
=
item
.
WordWrite
,
ChineseMean
=
item
.
ChineseMean
,
Status
=
Common
.
Enum
.
DateStateEnum
.
Normal
,
Group_Id
=
userInfo
.
Group_Id
,
CreateBy
=
userInfo
.
Id
,
CreateTime
=
DateTime
.
Now
,
UpdateBy
=
userInfo
.
Id
,
UpdateTime
=
DateTime
.
Now
};
if
(!
string
.
IsNullOrEmpty
(
model
.
WordContent
))
{
result
.
Add
(
model
);
}
}
}
bool
flag
=
false
;
if
(
result
!=
null
&&
result
.
Count
>
0
)
{
flag
=
courseWordsModule
.
BatchInsertCourseWordsModule
(
result
);
}
return
flag
?
ApiResult
.
Success
()
:
ApiResult
.
Failed
();
}
}
}
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