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
314dd3c9
Commit
314dd3c9
authored
Jul 27, 2023
by
Ryan Loong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 删除班级前校验班级是否有学生
parent
192df78f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
3 deletions
+31
-3
ClassService.java
...a/cn/exploring/engine/server/db/service/ClassService.java
+17
-2
StudentInfoService.java
...xploring/engine/server/db/service/StudentInfoService.java
+11
-0
ClassController.java
...va/cn/exploring/engine/server/wx/web/ClassController.java
+3
-1
No files found.
server-db/src/main/java/cn/exploring/engine/server/db/service/ClassService.java
View file @
314dd3c9
...
...
@@ -3,11 +3,14 @@ package cn.exploring.engine.server.db.service;
import
cn.exploring.engine.server.db.dao.ClassInfoMapper
;
import
cn.exploring.engine.server.db.domain.ClassInfo
;
import
cn.exploring.engine.server.db.domain.ClassInfoExample
;
import
cn.exploring.engine.server.db.domain.StudentInfo
;
import
cn.exploring.engine.server.db.util.StrUtil
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
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.util.StringUtils
;
import
javax.annotation.Resource
;
...
...
@@ -16,6 +19,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
@Service
public
class
ClassService
{
...
...
@@ -23,6 +27,9 @@ public class ClassService {
@Resource
ClassInfoMapper
classInfoMapper
;
@Resource
private
StudentInfoService
studentInfoService
;
public
Map
<
Integer
,
String
>
getClassNameMap
()
{
ClassInfoExample
example
=
new
ClassInfoExample
();
ClassInfoExample
.
Criteria
criteria
=
example
.
createCriteria
();
...
...
@@ -95,13 +102,21 @@ public class ClassService {
classInfoMapper
.
updateByPrimaryKey
(
classInfo
);
}
public
Object
batchDeletedData
(
List
<
Integer
>
idList
)
{
public
String
batchDeletedData
(
List
<
Integer
>
idList
)
{
List
<
ClassInfo
>
classInfoList
=
selectClass
(
null
,
idList
);
Map
<
Integer
,
String
>
classNameMap
=
classInfoList
.
stream
().
collect
(
Collectors
.
toMap
(
ClassInfo:
:
getId
,
ClassInfo:
:
getClassName
));
Map
<
Integer
,
List
<
StudentInfo
>>
classStudentMap
=
studentInfoService
.
selectStudentByClassIdListGroupByClassId
(
idList
);
if
(!
CollectionUtils
.
isEmpty
(
classStudentMap
)
&&
classStudentMap
.
values
().
stream
().
anyMatch
(
list
->
!
CollectionUtils
.
isEmpty
(
list
)))
{
return
classStudentMap
.
entrySet
().
stream
().
filter
(
entry
->
!
CollectionUtils
.
isEmpty
(
entry
.
getValue
()))
.
map
(
entry
->
StrUtil
.
format
(
"班级[({}){}]存在学生{}名无法删除"
,
entry
.
getKey
(),
classNameMap
.
get
(
entry
.
getKey
()),
entry
.
getValue
().
size
()))
.
collect
(
Collectors
.
joining
(
", "
));
}
classInfoList
.
forEach
(
x
->
{
x
.
setDeleted
(
null
);
updateClassInfo
(
x
);
});
return
"batch deleted OK"
;
return
null
;
}
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
,
readOnly
=
true
)
...
...
server-db/src/main/java/cn/exploring/engine/server/db/service/StudentInfoService.java
View file @
314dd3c9
...
...
@@ -26,6 +26,7 @@ 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
;
...
...
@@ -413,4 +414,14 @@ public class StudentInfoService {
throw
new
RuntimeException
(
"更新点名次数失败"
);
}
}
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
,
readOnly
=
true
)
public
Map
<
Integer
,
List
<
StudentInfo
>>
selectStudentByClassIdListGroupByClassId
(
Collection
<
Integer
>
classIdList
)
{
return
CollectionUtils
.
isEmpty
(
classIdList
)
?
ImmutableMap
.
of
()
:
studentInfoMapper
.
selectByExample
(
new
StudentInfoExample
().
createCriteria
()
.
andDeletedEqualTo
(
StudentInfo
.
NOT_DELETED
)
.
andClassIdIn
(
new
ArrayList
<>(
classIdList
))
.
example
())
.
stream
().
collect
(
Collectors
.
groupingBy
(
StudentInfo:
:
getClassId
,
Collectors
.
toList
()));
}
}
server-wx-api/src/main/java/cn/exploring/engine/server/wx/web/ClassController.java
View file @
314dd3c9
...
...
@@ -3,6 +3,7 @@ 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.service.ClassService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -37,7 +38,8 @@ public class ClassController {
@PostMapping
(
"batchDeleted"
)
public
Object
batchDeleted
(
@RequestBody
List
<
Integer
>
idList
)
{
return
ResponseUtil
.
ok
(
classService
.
batchDeletedData
(
idList
));
String
errMsg
=
classService
.
batchDeletedData
(
idList
);
return
StringUtils
.
isNotBlank
(
errMsg
)
?
ResponseUtil
.
ok
(
"成功"
)
:
ResponseUtil
.
fail
(
402
,
errMsg
);
}
@GetMapping
(
"/listAll"
)
...
...
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