Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
engine-class-work
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
liuchengjiu
engine-class-work
Commits
72caa0e2
Commit
72caa0e2
authored
Jul 21, 2023
by
Ryan Loong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add 导出成绩到excel
parent
41ed864a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
145 additions
and
76 deletions
+145
-76
StudentPointExcelExportVo.java
...engine/server/db/domain/vo/StudentPointExcelExportVo.java
+49
-22
StudentInfoService.java
...xploring/engine/server/db/service/StudentInfoService.java
+8
-0
StudentPointService.java
...ploring/engine/server/db/service/StudentPointService.java
+40
-30
PointController.java
...va/cn/exploring/engine/server/wx/web/PointController.java
+48
-24
No files found.
server-db/src/main/java/cn/exploring/engine/server/db/domain/vo/StudentPointExcelExportVo.java
View file @
72caa0e2
package
cn
.
exploring
.
engine
.
server
.
db
.
domain
.
vo
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
org.springframework.beans.BeanUtils
;
import
java.time.LocalDateTime
;
public
class
StudentPointExcelExportVo
{
@ExcelProperty
(
"学号"
)
private
String
studentU
i
d
;
private
String
studentU
niqueI
d
;
@ExcelProperty
(
"姓名"
)
private
String
studentN
ame
;
private
String
n
ame
;
@ExcelProperty
(
"
成绩
"
)
private
Integer
scor
e
;
@ExcelProperty
(
"
班级
"
)
private
String
classNam
e
;
@ExcelProperty
(
"
记录创建
时间"
)
private
LocalDateTime
ad
dTime
;
@ExcelProperty
(
"
点名
时间"
)
private
LocalDateTime
recor
dTime
;
public
String
getStudentUid
()
{
return
studentUid
;
@ExcelProperty
(
"分数"
)
private
Integer
point
;
public
StudentPointExcelExportVo
()
{
}
public
StudentPointExcelExportVo
(
String
studentUniqueId
,
String
name
,
String
className
,
LocalDateTime
recordTime
,
Integer
point
)
{
this
.
studentUniqueId
=
studentUniqueId
;
this
.
name
=
name
;
this
.
className
=
className
;
this
.
recordTime
=
recordTime
;
this
.
point
=
point
;
}
public
StudentPointExcelExportVo
(
StudentPointWithStudentInfoVo
studentPointWithStudentInfoVo
)
{
BeanUtils
.
copyProperties
(
studentPointWithStudentInfoVo
,
this
);
}
public
String
getStudentUniqueId
()
{
return
studentUniqueId
;
}
public
void
setStudentUniqueId
(
String
studentUniqueId
)
{
this
.
studentUniqueId
=
studentUniqueId
;
}
public
String
getName
()
{
return
name
;
}
public
void
set
StudentUid
(
String
studentUid
)
{
this
.
studentUid
=
studentUid
;
public
void
set
Name
(
String
name
)
{
this
.
name
=
name
;
}
public
String
get
Student
Name
()
{
return
student
Name
;
public
String
get
Class
Name
()
{
return
class
Name
;
}
public
void
set
StudentName
(
String
student
Name
)
{
this
.
studentName
=
student
Name
;
public
void
set
ClassName
(
String
class
Name
)
{
this
.
className
=
class
Name
;
}
public
Integer
getScor
e
()
{
return
scor
e
;
public
LocalDateTime
getRecordTim
e
()
{
return
recordTim
e
;
}
public
void
set
Score
(
Integer
scor
e
)
{
this
.
score
=
scor
e
;
public
void
set
RecordTime
(
LocalDateTime
recordTim
e
)
{
this
.
recordTime
=
recordTim
e
;
}
public
LocalDateTime
getAddTime
()
{
return
addTime
;
public
Integer
getPoint
()
{
return
point
;
}
public
void
set
AddTime
(
LocalDateTime
addTime
)
{
this
.
addTime
=
addTime
;
public
void
set
Point
(
Integer
point
)
{
this
.
point
=
point
;
}
}
server-db/src/main/java/cn/exploring/engine/server/db/service/StudentInfoService.java
View file @
72caa0e2
...
...
@@ -373,4 +373,12 @@ public class StudentInfoService {
return
null
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
increaseCallTimeByPrimaryKey
(
Integer
id
)
{
studentInfoMapper
.
updateByPrimaryKeySelective
(
StudentInfo
.
builder
().
id
(
id
).
updateTime
(
LocalDateTime
.
now
()).
build
().
increment
(
StudentInfo
.
Increment
.
callTimes
.
inc
(
1
)),
StudentInfo
.
Column
.
callTimes
,
StudentInfo
.
Column
.
updateTime
);
}
}
server-db/src/main/java/cn/exploring/engine/server/db/service/StudentPointService.java
View file @
72caa0e2
...
...
@@ -2,7 +2,6 @@ package cn.exploring.engine.server.db.service;
import
cn.exploring.engine.server.db.dao.SpecialSqlMapper
;
import
cn.exploring.engine.server.db.dao.StudentPointInfoMapper
;
import
cn.exploring.engine.server.db.domain.StudentInfo
;
import
cn.exploring.engine.server.db.domain.StudentPointInfo
;
import
cn.exploring.engine.server.db.domain.StudentPointInfoExample
;
import
cn.exploring.engine.server.db.domain.vo.StudentPointExcelExportVo
;
...
...
@@ -10,15 +9,15 @@ import cn.exploring.engine.server.db.domain.vo.StudentPointWithStudentInfoVo;
import
cn.exploring.engine.server.db.util.DateTimeUtil
;
import
cn.exploring.engine.server.db.util.SqlUtil
;
import
cn.exploring.engine.server.db.util.StrUtil
;
import
cn.exploring.engine.server.db.util.Util
;
import
cn.zhxu.bs.BeanSearcher
;
import
cn.zhxu.bs.SearchResult
;
import
cn.zhxu.bs.operator.*
;
import
cn.zhxu.bs.operator.Contain
;
import
cn.zhxu.bs.operator.Equal
;
import
cn.zhxu.bs.operator.GreaterEqual
;
import
cn.zhxu.bs.operator.LessEqual
;
import
cn.zhxu.bs.util.MapBuilder
;
import
cn.zhxu.bs.util.MapUtils
;
import
com.alibaba.excel.EasyExcel
;
import
com.github.pagehelper.Page
;
import
com.github.pagehelper.PageHelper
;
import
com.google.common.collect.ImmutableMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.logging.Log
;
...
...
@@ -27,15 +26,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
@Service
...
...
@@ -56,19 +55,29 @@ public class StudentPointService {
BeanSearcher
beanSearcher
;
public
Map
<
String
,
Object
>
selectPointByWeb
(
String
studentName
,
String
studentUniqueId
,
Integer
classId
,
String
startTime
,
String
endTime
,
Integer
page
,
Integer
limit
,
String
sort
,
String
order
)
{
SearchResult
<
StudentPointWithStudentInfoVo
>
result
=
beanSearcher
.
search
(
StudentPointWithStudentInfoVo
.
class
,
SqlUtil
.
page
(
voWrapper
(
studentName
,
studentUniqueId
,
classId
,
startTime
,
endTime
),
page
,
limit
,
sort
,
order
).
build
());
return
ImmutableMap
.
of
(
"total"
,
result
.
getTotalCount
().
longValue
(),
"items"
,
result
.
getDataList
());
}
public
File
exportList
(
String
studentName
,
String
studentUniqueId
,
Integer
classId
,
String
startTime
,
String
endTime
)
{
List
<
StudentPointExcelExportVo
>
list
=
beanSearcher
.
searchAll
(
StudentPointWithStudentInfoVo
.
class
,
voWrapper
(
studentName
,
studentUniqueId
,
classId
,
startTime
,
endTime
).
build
())
.
stream
().
map
(
StudentPointExcelExportVo:
:
new
).
collect
(
Collectors
.
toList
());
return
transToExcelFile
(
list
);
}
public
MapBuilder
voWrapper
(
String
studentName
,
String
studentUniqueId
,
Integer
classId
,
String
startTime
,
String
endTime
)
{
LocalDateTime
start
=
Optional
.
ofNullable
(
startTime
).
filter
(
StringUtils:
:
isNotBlank
).
map
(
s
->
LocalDateTime
.
parse
(
s
,
DateTimeUtil
.
DATE_TIME_FORMATTER3
)).
orElse
(
null
);
LocalDateTime
end
=
Optional
.
ofNullable
(
endTime
).
filter
(
StringUtils:
:
isNotBlank
).
map
(
s
->
LocalDateTime
.
parse
(
s
,
DateTimeUtil
.
DATE_TIME_FORMATTER3
)).
orElse
(
null
);
MapBuilder
wrapper
=
MapUtils
.
builder
()
return
MapUtils
.
builder
()
.
field
(
StudentPointWithStudentInfoVo:
:
getDeleted
,
StudentPointInfo
.
NOT_DELETED
).
op
(
Equal
.
class
)
.
field
(
StudentPointWithStudentInfoVo:
:
getName
,
studentName
).
op
(
Contain
.
class
)
.
field
(
StudentPointWithStudentInfoVo:
:
getStudentUniqueId
,
studentUniqueId
).
op
(
Contain
.
class
)
.
field
(
StudentPointWithStudentInfoVo:
:
getClassId
,
classId
).
op
(
Equal
.
class
)
.
field
(
StudentPointWithStudentInfoVo:
:
getRecordTime
,
start
).
op
(
GreaterEqual
.
class
)
.
field
(
StudentPointWithStudentInfoVo:
:
getRecordTime
,
end
).
op
(
LessEqual
.
class
);
SearchResult
<
StudentPointWithStudentInfoVo
>
result
=
beanSearcher
.
search
(
StudentPointWithStudentInfoVo
.
class
,
SqlUtil
.
page
(
wrapper
,
page
,
limit
,
sort
,
order
).
build
());
return
ImmutableMap
.
of
(
"total"
,
result
.
getTotalCount
().
longValue
(),
"items"
,
result
.
getDataList
());
}
/**
...
...
@@ -87,13 +96,14 @@ public class StudentPointService {
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
String
addPoint
(
StudentPointInfo
studentPoint
)
{
LocalDateTime
now
=
LocalDateTime
.
now
();
studentPoint
.
setRecordTime
(
now
);
studentPoint
.
setUpdateTime
(
now
);
studentPoint
.
setAddTime
(
now
);
studentPoint
.
setDeleted
(
false
);
studentPointInfoMapper
.
insert
Selective
(
studentPoint
);
studentPointInfoMapper
.
insert
(
studentPoint
);
return
"add OK"
;
}
...
...
@@ -163,22 +173,22 @@ public class StudentPointService {
.
example
());
}
public
List
<
StudentPointExcelExportVo
>
transToExcelExportVo
(
Collection
<
StudentPointInfo
>
list
)
{
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
Collections
.
emptyList
();
}
Map
<
Integer
,
StudentInfo
>
studentInfoMap
=
studentInfoService
.
selectByPrimaryKey
(
list
.
stream
().
map
(
StudentPointInfo:
:
getStudentId
).
collect
(
Collectors
.
toSet
()))
.
stream
().
collect
(
Collectors
.
toMap
(
StudentInfo:
:
getId
,
x
->
x
,
(
k1
,
k2
)
->
k1
));
return
list
.
stream
().
map
(
pointInfo
->
new
StudentPointExcelExportVo
()
{{
StudentInfo
studentInfo
=
studentInfoMap
.
getOrDefault
(
pointInfo
.
getStudentId
(),
new
StudentInfo
());
setStudentName
(
studentInfo
.
getName
());
setStudentUid
(
studentInfo
.
getStudentUniqueId
());
setScore
(
pointInfo
.
getPoint
());
setAddTime
(
pointInfo
.
getAddTime
());
}}).
collect
(
Collectors
.
toList
());
}
//
public List<StudentPointExcelExportVo> transToExcelExportVo(Collection<StudentPointInfo> list) {
//
if (CollectionUtils.isEmpty(list)) {
//
return Collections.emptyList();
//
}
//
//
Map<Integer, StudentInfo> studentInfoMap = studentInfoService.selectByPrimaryKey(list.stream().map(StudentPointInfo::getStudentId).collect(Collectors.toSet()))
//
.stream().collect(Collectors.toMap(StudentInfo::getId, x -> x, (k1, k2) -> k1));
//
//
return list.stream().map(pointInfo -> new StudentPointExcelExportVo() {{
//
StudentInfo studentInfo = studentInfoMap.getOrDefault(pointInfo.getStudentId(), new StudentInfo());
//
setStudentName(studentInfo.getName());
//
setStudentUid(studentInfo.getStudentUniqueId());
//
setScore(pointInfo.getPoint());
//
setAddTime(pointInfo.getAddTime());
//
}}).collect(Collectors.toList());
//
}
public
File
transToExcelFile
(
List
<
StudentPointExcelExportVo
>
voList
)
{
File
file
=
null
;
...
...
server-wx-api/src/main/java/cn/exploring/engine/server/wx/web/PointController.java
View file @
72caa0e2
...
...
@@ -6,7 +6,6 @@ import cn.exploring.engine.server.db.domain.StudentPointInfo;
import
cn.exploring.engine.server.db.domain.vo.IdVo
;
import
cn.exploring.engine.server.db.service.StudentInfoService
;
import
cn.exploring.engine.server.db.service.StudentPointService
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -44,6 +43,31 @@ public class PointController {
return
ResponseUtil
.
ok
(
pointService
.
selectPointByWeb
(
studentName
,
studentUniqueId
,
classId
,
startTime
,
endTime
,
page
,
limit
,
sort
,
order
));
}
@GetMapping
(
"export"
)
public
Object
export
(
@RequestParam
String
studentName
,
@RequestParam
String
studentUniqueId
,
@RequestParam
Integer
classId
,
@RequestParam
String
startTime
,
@RequestParam
String
endTime
,
@RequestParam
(
required
=
false
,
defaultValue
=
"addTime"
)
String
sort
,
@RequestParam
(
required
=
false
,
defaultValue
=
"desc"
)
String
order
)
{
studentUniqueId
=
StringUtils
.
isEmpty
(
studentUniqueId
)
?
null
:
studentUniqueId
;
studentName
=
StringUtils
.
isEmpty
(
studentName
)
?
null
:
studentName
;
startTime
=
StringUtils
.
isEmpty
(
startTime
)
?
null
:
startTime
;
endTime
=
StringUtils
.
isEmpty
(
endTime
)
?
null
:
endTime
;
File
file
=
pointService
.
exportList
(
studentName
,
studentUniqueId
,
classId
,
startTime
,
endTime
);
FileInputStream
in
=
null
;
try
{
in
=
new
FileInputStream
(
file
);
return
ResponseUtil
.
ok
(
storageService
.
storageStore
(
in
,
file
.
length
(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
,
file
.
getName
(),
storageService
.
generateKey
(
file
.
getName
())));
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
if
(
Objects
.
nonNull
(
in
))
{
try
{
in
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
}
}
@PostMapping
(
"add"
)
public
Object
add
(
@RequestBody
StudentPointInfo
pointInfo
)
{
...
...
@@ -76,28 +100,28 @@ public class PointController {
}
@GetMapping
(
"exportByClass"
)
public
Object
exportByClass
(
Integer
classId
)
{
List
<
StudentPointInfo
>
list
=
pointService
.
listByClassId
(
classId
);
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
ResponseUtil
.
fail
(
402
,
"暂无数据"
);
}
File
file
=
pointService
.
transToExcelFile
(
pointService
.
transToExcelExportVo
(
list
));
FileInputStream
in
=
null
;
try
{
in
=
new
FileInputStream
(
file
);
return
ResponseUtil
.
ok
(
storageService
.
storageStore
(
in
,
file
.
length
(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
,
file
.
getName
(),
storageService
.
generateKey
(
file
.
getName
())));
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
finally
{
if
(
Objects
.
nonNull
(
in
))
{
try
{
in
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
}
}
//
@GetMapping("exportByClass")
//
public Object exportByClass(Integer classId) {
//
List<StudentPointInfo> list = pointService.listByClassId(classId);
//
if (CollectionUtils.isEmpty(list)) {
//
return ResponseUtil.fail(402, "暂无数据");
//
}
//
//
File file = pointService.transToExcelFile(pointService.transToExcelExportVo(list));
//
FileInputStream in = null;
//
try {
//
in = new FileInputStream(file);
//
return ResponseUtil.ok(storageService.storageStore(in, file.length(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", file.getName(), storageService.generateKey(file.getName())));
//
} catch (FileNotFoundException e) {
//
throw new RuntimeException(e);
//
} finally {
//
if (Objects.nonNull(in)) {
//
try {
//
in.close();
//
} catch (IOException ignored) {
//
}
//
}
//
}
//
}
}
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