ClassesDictServiceImpl.java
17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.dto.classes.*;
import com.meishu.mapper.*;
import com.meishu.model.*;
import com.meishu.service.ClassesDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.classes.GetClassStudentsVO;
import com.meishu.vo.classes.GetClassesVO;
import com.meishu.vo.classes.SubjectDictVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* <p>
* 学校班级字典表 服务实现类
* </p>
*
* @author Tuyp
* @since 2021-08-11
*/
@Service
public class ClassesDictServiceImpl extends ServiceImpl<ClassesDictMapper, ClassesDictDO> implements ClassesDictService {
@Autowired
private SubjectDictMapper subjectDictMapper;
@Autowired
private SubjectSemesterMapper subjectSemesterMapper;
@Autowired
private UserSubjectMappingMapper userSubjectMappingMapper;
@Autowired
private ClassesUserMappingMapper classesUserMappingMapper;
@Autowired
private ClassesDictHistoryMapper classesDictHistoryMapper;
@Autowired
private UserSubjectPermissionDictMapper userSubjectPermissionDictMapper;
@Autowired
private KnowledgeSubjectDictMapper knowledgeSubjectDictMapper;
public IPage<GetClassesVO> getClasses(GetClassesDTO getClassesDTO) {
Page pager = new Page(getClassesDTO.getPageNum(), getClassesDTO.getPageSize());
IPage<GetClassesVO> getClassesVOIPage = this.baseMapper.getClasses(pager, getClassesDTO.getClassName(), getClassesDTO.getGrade(), getClassesDTO.getSession(), getClassesDTO.getStatus());
List<GetClassesVO> getClassesVOS = getClassesVOIPage.getRecords();
//找出班级所有的科目
for (GetClassesVO getClassesVO : getClassesVOS) {
List<SubjectDictDO> subjectDictDOS = subjectDictMapper.selectList(new QueryWrapper<SubjectDictDO>()
.lambda()
.eq(SubjectDictDO::getGrade, getClassesVO.getGrade())
.eq(SubjectDictDO::getClasses, getClassesVO.getClasses())
.eq(SubjectDictDO::getSession, getClassesVO.getSession()));
List<SubjectDictVO> subjectDictVOS = new ArrayList<>();
for (SubjectDictDO subjectDictDO : subjectDictDOS) {
SubjectDictVO subjectDictVO = new SubjectDictVO();
BeanUtils.copyProperties(subjectDictDO, subjectDictVO);
//查询该科目下的授课老师
List<AdministerDO> administerDOS = userSubjectMappingMapper.querySubjectTeachers(subjectDictDO.getId());
subjectDictVO.setAdministerDOS(administerDOS);
KnowledgeSubjectDictDO knowledgeSubjectDict = knowledgeSubjectDictMapper.selectOne(new QueryWrapper<KnowledgeSubjectDictDO>()
.lambda()
.eq(KnowledgeSubjectDictDO::getSubjectName, subjectDictDO.getSubject()));
if (null != knowledgeSubjectDict) {
subjectDictVO.setId(knowledgeSubjectDict.getId().intValue());
} else {
subjectDictVO.setId(null);
}
subjectDictVOS.add(subjectDictVO);
}
getClassesVO.setSubjectDictDOS(subjectDictVOS);
}
getClassesVOIPage.setRecords(getClassesVOS);
return getClassesVOIPage;
}
@Transactional(rollbackFor = Exception.class)
public String addClass(AddClassDTO addClassDTO) {
ClassesDictDO classesDictDO = new ClassesDictDO();
BeanUtils.copyProperties(addClassDTO, classesDictDO);
classesDictDO.setClassName(classesDictDO.getGrade() + "(" + classesDictDO.getClasses() + ")班");
classesDictDO.setSchool(ConstantUtils.SCHOOL);
classesDictDO.setSubjectType("高中");
classesDictDO.setStatus("在读");
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH)+1;//获取月份
Date date = new Date();
if (month>=7){
date.setYear(year-1899);
date.setMonth(7);
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
}else {
date.setYear(year-1900);
date.setMonth(7);
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
}
classesDictDO.setUpgradeDate(date);
this.baseMapper.insert(classesDictDO);
ClassesDictHistoryDO classesDictHistoryDO = new ClassesDictHistoryDO();
BeanUtils.copyProperties(addClassDTO, classesDictHistoryDO);
classesDictHistoryDO.setClassName(classesDictDO.getClassName());
classesDictHistoryDO.setSchool(classesDictDO.getSchool());
classesDictHistoryDO.setSubjectType(classesDictDO.getSubjectType());
classesDictHistoryDO.setStatus("在读");
classesDictHistoryDO.setClassDictId(classesDictDO.getId());
classesDictHistoryMapper.insert(classesDictHistoryDO);
//找到班级所有学生
List<ClassesUserMappingDO> classesUserMappingDOS = classesUserMappingMapper.selectList(new QueryWrapper<ClassesUserMappingDO>()
.lambda()
.eq(ClassesUserMappingDO::getClassesId,addClassDTO.getId()));
//添加 班级里的科目信息
List<String> subjects = addClassDTO.getSubjects();
for (String str : subjects) {
SubjectDictDO subjectDictDO = new SubjectDictDO();
subjectDictDO.setSchool(ConstantUtils.SCHOOL);
subjectDictDO.setGrade(addClassDTO.getGrade());
subjectDictDO.setClasses(addClassDTO.getClasses());
subjectDictDO.setClassName(classesDictDO.getClassName());
subjectDictDO.setSubject(knowledgeSubjectDictMapper.selectById(str).getSubjectName());
subjectDictDO.setSubjectType("高中");
subjectDictDO.setSession(classesDictDO.getSession());
subjectDictDO.setStatus("在读");
subjectDictMapper.insert(subjectDictDO);
SubjectSemesterDO subjectSemesterDO = new SubjectSemesterDO();
subjectSemesterDO.setSubjectId(subjectDictDO.getId());
subjectSemesterDO.setSemester("上");
subjectSemesterMapper.insert(subjectSemesterDO);
// for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
// PtStudentScoreDO ptStudentScoreDO = new PtStudentScoreDO();
// ptStudentScoreDO.setScore(30.0);
// ptStudentScoreDO.setScoreRecord(30.0);
// ptStudentScoreDO.setSemesterId(subjectSemesterDO.getId());
// ptStudentScoreDO.setStudentId(classesUserMappingDO.getUserId());
// ptStudentScoreDO.setSubjectId(subjectDictDO.getId());
// }
subjectSemesterDO.setSemester("下");
subjectSemesterMapper.insert(subjectSemesterDO);
// for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
// PtStudentScoreDO ptStudentScoreDO = new PtStudentScoreDO();
// ptStudentScoreDO.setScore(30.0);
// ptStudentScoreDO.setScoreRecord(30.0);
// ptStudentScoreDO.setSemesterId(subjectSemesterDO.getId());
// ptStudentScoreDO.setStudentId(classesUserMappingDO.getUserId());
// ptStudentScoreDO.setSubjectId(subjectDictDO.getId());
// }
}
return ConstantUtils.ADD_SUCCESS;
}
public String updateClass(AddClassDTO addClassDTO) {
ClassesDictHistoryDO classesDictHistoryDO = classesDictHistoryMapper.selectOne(new QueryWrapper<ClassesDictHistoryDO>()
.lambda()
.eq(ClassesDictHistoryDO::getStatus,"在读")
.eq(ClassesDictHistoryDO::getClassDictId,addClassDTO.getId()));
classesDictHistoryDO.setGrade(addClassDTO.getGrade());
classesDictHistoryDO.setClasses(addClassDTO.getClasses());
classesDictHistoryDO.setSession(addClassDTO.getSession());
classesDictHistoryDO.setClassName(classesDictHistoryDO.getGrade() + "(" + classesDictHistoryDO.getClasses() + ")班");
classesDictHistoryMapper.updateById(classesDictHistoryDO);
ClassesDictDO classesDictDO = new ClassesDictDO();
BeanUtils.copyProperties(classesDictHistoryDO, classesDictDO);
classesDictDO.setId(addClassDTO.getId());
classesDictDO.setClassName(classesDictDO.getGrade() + "(" + classesDictDO.getClasses() + ")班");
this.baseMapper.updateById(classesDictDO);
//查找该班级下已经有的科目
List<String> existSubject = subjectDictMapper.getClassSubjectName(classesDictHistoryDO.getGrade(),classesDictHistoryDO.getClasses(),classesDictHistoryDO.getSession());
//找到班级所有学生
List<ClassesUserMappingDO> classesUserMappingDOS = classesUserMappingMapper.selectList(new QueryWrapper<ClassesUserMappingDO>()
.lambda()
.eq(ClassesUserMappingDO::getClassesId,addClassDTO.getId()));
List<String> subjects = addClassDTO.getSubjects();
for (String str : subjects) {
KnowledgeSubjectDictDO knowledgeSubjectDictDO = knowledgeSubjectDictMapper.selectById(str);
if (!existSubject.contains(knowledgeSubjectDictDO.getSubjectName())){
SubjectDictDO subjectDictDO = new SubjectDictDO();
subjectDictDO.setSchool(ConstantUtils.SCHOOL);
subjectDictDO.setGrade(addClassDTO.getGrade());
subjectDictDO.setClasses(addClassDTO.getClasses());
subjectDictDO.setClassName(classesDictDO.getClassName());
subjectDictDO.setSubject(knowledgeSubjectDictMapper.selectById(str).getSubjectName());
subjectDictDO.setSubjectType("高中");
subjectDictDO.setSession(classesDictDO.getSession());
subjectDictDO.setStatus("1");
subjectDictMapper.insert(subjectDictDO);
SubjectSemesterDO subjectSemesterDO = new SubjectSemesterDO();
subjectSemesterDO.setSubjectId(subjectDictDO.getId());
subjectSemesterDO.setSemester("上");
subjectSemesterMapper.insert(subjectSemesterDO);
for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
PtStudentScoreDO ptStudentScoreDO = new PtStudentScoreDO();
ptStudentScoreDO.setScore(30.0);
ptStudentScoreDO.setScoreRecord(30.0);
ptStudentScoreDO.setSemesterId(subjectSemesterDO.getId());
ptStudentScoreDO.setStudentId(classesUserMappingDO.getUserId());
ptStudentScoreDO.setSubjectId(subjectDictDO.getId());
}
subjectSemesterDO.setSemester("下");
subjectSemesterMapper.insert(subjectSemesterDO);
for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
PtStudentScoreDO ptStudentScoreDO = new PtStudentScoreDO();
ptStudentScoreDO.setScore(30.0);
ptStudentScoreDO.setScoreRecord(30.0);
ptStudentScoreDO.setSemesterId(subjectSemesterDO.getId());
ptStudentScoreDO.setStudentId(classesUserMappingDO.getUserId());
ptStudentScoreDO.setSubjectId(subjectDictDO.getId());
}
}
}
return ConstantUtils.SUCCESS_UPDATE;
}
@Transactional(rollbackFor = Exception.class)
public String addSubjectTeacherMapping(AddSubjectTeacherDTO addSubjectTeacherDTO) {
ClassesDictDO classesDictDO = this.baseMapper.selectById(addSubjectTeacherDTO.getClassId());
List<AddSubjectTeacherMappingDTO> addSubjectTeacherMappingDTOS = addSubjectTeacherDTO.getAddSubjectTeacherMappingDTOS();
for (AddSubjectTeacherMappingDTO addSubjectTeacherMappingDTO :addSubjectTeacherMappingDTOS){
KnowledgeSubjectDictDO knowledgeSubjectDict = knowledgeSubjectDictMapper.selectById(addSubjectTeacherMappingDTO.getSubjectId());
List<Integer> integers = addSubjectTeacherMappingDTO.getTeacherIds();
SubjectDictDO subjectDictDO = subjectDictMapper.selectOne(new QueryWrapper<SubjectDictDO>()
.lambda()
.eq(SubjectDictDO::getGrade, classesDictDO.getGrade())
.eq(SubjectDictDO::getSession, classesDictDO.getSession())
.eq(SubjectDictDO::getClasses, classesDictDO.getClasses())
.eq(SubjectDictDO::getSubject, knowledgeSubjectDict.getSubjectName()));
userSubjectMappingMapper.delete(new QueryWrapper<UserSubjectMappingDO>()
.lambda()
.eq(UserSubjectMappingDO::getSubjectId,subjectDictDO.getId()));
userSubjectPermissionDictMapper.delete(new QueryWrapper<UserSubjectPermissionDictDO>()
.lambda()
.eq(UserSubjectPermissionDictDO::getSubjectId,subjectDictDO.getId()));
if (null != subjectDictDO) {
for (Integer integer : integers) {
UserSubjectMappingDO userSubjectMappingDO = new UserSubjectMappingDO();
userSubjectMappingDO.setSubjectId(subjectDictDO.getId());
userSubjectMappingDO.setUserId(integer);
userSubjectMappingDO.setClassType(0);
userSubjectMappingMapper.insert(userSubjectMappingDO);
UserSubjectPermissionDictDO userSubjectPermissionDictDO = new UserSubjectPermissionDictDO();
userSubjectPermissionDictDO.setSubjectId(subjectDictDO.getId());
userSubjectPermissionDictDO.setUserId(integer);
userSubjectPermissionDictMapper.insert(userSubjectPermissionDictDO);
}
}
}
return ConstantUtils.ADD_SUCCESS;
}
public List<GetClassStudentsVO> getClassStudents(GetClassStudentsDTO getClassStudentsDTO) {
// Page pager = new Page(getClassStudentsDTO.getPageNum(), getClassStudentsDTO.getPageSize());
return this.baseMapper.getClassStudents(getClassStudentsDTO.getClassId(), getClassStudentsDTO.getUserName());
}
public IPage<UserRoleDO> queryNoClassStudents(QueryNoClassStudentsDTO queryNoClassStudentsDTO) {
Page pager = new Page(queryNoClassStudentsDTO.getPageNum(), queryNoClassStudentsDTO.getPageSize());
return this.baseMapper.queryNoClassStudents(pager, queryNoClassStudentsDTO.getUserName());
}
@Transactional(rollbackFor = Exception.class)
public String batchAddStudentToClass(BatchAddStudentToClassDTO batchAddStudentToClassDTO) {
List<Integer> integers = batchAddStudentToClassDTO.getIds();
for (Integer integer : integers) {
classesUserMappingMapper.delete(new QueryWrapper<ClassesUserMappingDO>()
.lambda()
.eq(ClassesUserMappingDO::getUserId, integer));
ClassesUserMappingDO classesUserMappingDO = new ClassesUserMappingDO();
classesUserMappingDO.setClassesId(batchAddStudentToClassDTO.getClassId());
classesUserMappingDO.setUserId(integer);
classesUserMappingDO.setStatus(1);
classesUserMappingMapper.insert(classesUserMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
public String batchDeleteStudent(BatchAddStudentToClassDTO batchAddStudentToClassDTO) {
List<Integer> integers = batchAddStudentToClassDTO.getIds();
for (Integer integer : integers) {
classesUserMappingMapper.delete(new QueryWrapper<ClassesUserMappingDO>()
.lambda()
.eq(ClassesUserMappingDO::getClassesId, batchAddStudentToClassDTO.getClassId())
.eq(ClassesUserMappingDO::getUserId, integer));
}
return ConstantUtils.DELETE_SUCCESS;
}
public List<ClassesDictDO> getClassesWithPage() {
return this.baseMapper.selectList(new QueryWrapper<ClassesDictDO>()
.lambda()
.eq(ClassesDictDO::getStatus, "在读"));
}
@Override
public ClassesDictDO getClassesById(Long studentId) {
return this.baseMapper.getClassesById(studentId);
}
public String batchUpGrade(BatchUpGradeDTO batchUpGradeDTO){
List<Integer> ids = batchUpGradeDTO.getIds();
for (Integer id : ids){
ClassesDictDO classesDictDO = new ClassesDictDO();
classesDictDO.setId(id);
classesDictDO.setUpgradeDate(batchUpGradeDTO.getUpgradeDate());
this.baseMapper.updateById(classesDictDO);
}
return ConstantUtils.SUCCESS_UPDATE;
}
}