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
f0ac346f
Commit
f0ac346f
authored
Jul 20, 2023
by
Ryan Loong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 学生删 && 改
parent
c7438bfe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
24 deletions
+72
-24
StudentInfoService.java
...xploring/engine/server/db/service/StudentInfoService.java
+67
-19
StudentController.java
.../cn/exploring/engine/server/wx/web/StudentController.java
+5
-5
No files found.
server-db/src/main/java/cn/exploring/engine/server/db/service/StudentInfoService.java
View file @
f0ac346f
...
...
@@ -9,39 +9,41 @@ import cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportResultVo;
import
cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportVo
;
import
cn.exploring.engine.server.db.domain.vo.StudentVo
;
import
cn.exploring.engine.server.db.util.SqlUtil
;
import
cn.exploring.engine.server.db.util.StrUtil
;
import
cn.exploring.engine.server.db.util.excel.ExcelReaderListener
;
import
cn.exploring.engine.server.db.util.excel.StudentInfoExcelReaderListener
;
import
cn.zhxu.bs.BeanSearcher
;
import
cn.zhxu.bs.SearchResult
;
import
cn.zhxu.bs.operator.*
;
import
cn.zhxu.bs.operator.Between
;
import
cn.zhxu.bs.operator.Contain
;
import
cn.zhxu.bs.operator.Equal
;
import
cn.zhxu.bs.operator.InList
;
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.github.pagehelper.PageInfo
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.ImmutableMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeanUtils
;
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
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.IOError
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
@Service
public
class
StudentInfoService
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
StudentInfoService
.
class
);
@Resource
StudentInfoMapper
studentInfoMapper
;
...
...
@@ -92,13 +94,42 @@ public class StudentInfoService {
* @return
*/
public
String
updateStudentInfo
(
StudentInfo
studentInfo
)
{
String
logPrefix
=
StrUtil
.
format
(
"[sessionId:{}]【更新学生信息】"
,
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
log
.
info
(
StrUtil
.
format
(
"{} 请求: '{}'"
,
logPrefix
,
JSON
.
toJSONString
(
studentInfo
)));
StudentInfo
record
=
selectByPrimaryKey
(
studentInfo
.
getId
());
if
(
Objects
.
isNull
(
record
))
{
log
.
error
(
StrUtil
.
format
(
"{} 查询失败"
));
return
"记录不存在"
;
}
StudentInfo
studentInfo1
=
selectStudentInfoByUniqueId
(
studentInfo
.
getStudentUniqueId
());
if
(
studentInfo1
!=
null
&&
!
studentInfo1
.
getId
().
equals
(
studentInfo
.
getId
()))
{
return
"Fail 学号重复! 请重新输入学号"
;
log
.
error
(
StrUtil
.
format
(
"{} 学号重复 学号:'{}' 重复学生对象: '{}'"
,
logPrefix
,
studentInfo
.
getStudentUniqueId
(),
JSON
.
toJSONString
(
studentInfo1
)));
return
"学号重复! 请重新输入学号"
;
}
studentInfo
.
setUpdateTime
(
LocalDateTime
.
now
());
studentInfoMapper
.
updateByPrimaryKey
(
studentInfo
);
return
"OK 修改成功"
;
if
(
StringUtils
.
isBlank
(
studentInfo
.
getHead
())
||
StringUtils
.
equalsIgnoreCase
(
studentInfo
.
getHead
().
trim
(),
URL_DEFAULT_HEAD
)
||
StringUtils
.
equalsIgnoreCase
(
studentInfo
.
getHead
().
trim
(),
STRING_DEFAULT_HEAD
))
{
studentInfo
.
setHead
(
STRING_DEFAULT_HEAD
);
log
.
info
(
StrUtil
.
format
(
"{} 配置为默认头像"
,
logPrefix
));
}
BeanUtils
.
copyProperties
(
studentInfo
,
record
,
StudentInfo
.
Column
.
id
.
getJavaProperty
(),
StudentInfo
.
Column
.
addTime
.
getJavaProperty
(),
StudentInfo
.
Column
.
updateTime
.
getJavaProperty
(),
StudentInfo
.
Column
.
deleted
.
getJavaProperty
());
record
.
setUpdateTime
(
LocalDateTime
.
now
());
studentInfoMapper
.
updateByPrimaryKey
(
record
);
log
.
info
(
StrUtil
.
format
(
"{} 更新完成: '{}'"
,
logPrefix
,
JSON
.
toJSONString
(
record
)));
return
null
;
}
/**
...
...
@@ -107,14 +138,25 @@ public class StudentInfoService {
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Object
batchDeleted
(
List
<
Integer
>
idList
)
{
public
String
batchDeleted
(
List
<
Integer
>
idList
)
{
String
logPrefix
=
StrUtil
.
format
(
"[sessionId:{}]【删除学生】"
,
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
log
.
info
(
StrUtil
.
format
(
"{} 请求: {}"
,
logPrefix
,
JSON
.
toJSONString
(
idList
)));
List
<
StudentInfo
>
studentInfoList
=
selectStudentInfo
(
null
,
null
,
idList
);
studentInfoList
.
forEach
(
x
->
{
log
.
info
(
StrUtil
.
format
(
"{} 查询到的学生记录: {}"
,
logPrefix
,
JSON
.
toJSONString
(
studentInfoList
)));
List
<
Integer
>
notExist
=
idList
.
stream
().
filter
(
i
->
studentInfoList
.
stream
().
noneMatch
(
s
->
Objects
.
equals
(
s
.
getId
(),
i
))).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
notExist
))
{
log
.
info
(
StrUtil
.
format
(
"{} 存在无效学生 学生ID: {}"
,
logPrefix
,
JSON
.
toJSONString
(
notExist
)));
return
"学生不存在"
;
}
LocalDateTime
now
=
LocalDateTime
.
now
();
int
update
=
studentInfoMapper
.
batchUpsert
(
studentInfoList
.
stream
().
peek
(
x
->
{
x
.
setUpdateTime
(
now
);
x
.
setDeleted
(
null
);
updateStudentInfo
(
x
);
studentPointService
.
removeByStudentId
(
x
.
getId
());
});
return
"batch deleted OK"
;
}).
collect
(
Collectors
.
toList
()));
log
.
info
(
StrUtil
.
format
(
"{} 删除成功 条目数量: '{}'"
,
logPrefix
,
update
));
return
null
;
}
/**
...
...
@@ -300,7 +342,13 @@ public class StudentInfoService {
}).
collect
(
Collectors
.
toList
());
}
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
,
readOnly
=
true
)
public
StudentInfo
selectByPrimaryKey
(
Integer
id
)
{
return
Objects
.
nonNull
(
id
)
?
studentInfoMapper
.
selectOneByExample
(
new
StudentInfoExample
().
createCriteria
()
.
andDeletedEqualTo
(
StudentInfo
.
NOT_DELETED
)
.
andIdEqualTo
(
id
)
.
example
())
:
null
;
}
public
List
<
StudentInfo
>
selectByPrimaryKey
(
Collection
<
Integer
>
idList
)
{
return
CollectionUtils
.
isEmpty
(
idList
)
?
Collections
.
emptyList
()
:
studentInfoMapper
.
selectByExample
(
new
StudentInfoExample
().
createCriteria
()
...
...
server-wx-api/src/main/java/cn/exploring/engine/server/wx/web/StudentController.java
View file @
f0ac346f
package
cn
.
exploring
.
engine
.
server
.
wx
.
web
;
import
cn.exploring.engine.server.core.util.ResponseUtil
;
import
cn.exploring.engine.server.db.domain.ClassInfo
;
import
cn.exploring.engine.server.db.domain.StudentInfo
;
import
cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportResultVo
;
import
cn.exploring.engine.server.db.domain.vo.StudentInfoExcelImportVo
;
import
cn.exploring.engine.server.db.service.ClassService
;
import
cn.exploring.engine.server.db.service.StudentInfoService
;
import
com.google.common.collect.ImmutableMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -15,7 +15,6 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.annotation.Nullable
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Objects
;
...
...
@@ -53,13 +52,14 @@ public class StudentController {
@PostMapping
(
"update"
)
public
Object
update
(
@RequestBody
StudentInfo
studentInfo
)
{
String
status
=
studentInfoService
.
updateStudentInfo
(
studentInfo
);
return
status
.
contains
(
"OK"
)
?
ResponseUtil
.
ok
(
status
)
:
ResponseUtil
.
fail
(
301
,
status
);
String
err
=
studentInfoService
.
updateStudentInfo
(
studentInfo
);
return
StringUtils
.
isNotBlank
(
err
)
?
ResponseUtil
.
fail
(
301
,
err
)
:
ResponseUtil
.
ok
(
"修改成功"
);
}
@PostMapping
(
"batchDeleted"
)
public
Object
batchDeleted
(
@RequestBody
List
<
Integer
>
idList
)
{
return
ResponseUtil
.
ok
(
studentInfoService
.
batchDeleted
(
idList
));
String
err
=
studentInfoService
.
batchDeleted
(
idList
);
return
StringUtils
.
isNotBlank
(
err
)
?
ResponseUtil
.
fail
(
301
,
err
)
:
ResponseUtil
.
ok
(
"删除成功"
);
}
@PostMapping
(
"import"
)
...
...
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