BatchDictServiceImpl.java
5.93 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
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.batch.AddBatchDTO;
import com.meishu.mapper.BatchExamMapper;
import com.meishu.mapper.BatchExamsStudentsMapper;
import com.meishu.mapper.BatchStudentMappingMapper;
import com.meishu.model.BatchDictDO;
import com.meishu.mapper.BatchDictMapper;
import com.meishu.model.BatchExamDO;
import com.meishu.model.BatchExamStudentsDO;
import com.meishu.model.BatchStudentMappingDO;
import com.meishu.service.BatchDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.batch.BatchesVO;
import com.meishu.vo.student.BatchStudentsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* <p>
* 批次字典表 服务实现类
* </p>
*
* @author Tuyp
* @since 2023-07-12
*/
@Service
public class BatchDictServiceImpl extends ServiceImpl<BatchDictMapper, BatchDictDO> implements BatchDictService {
@Autowired
private BatchExamMapper batchExamMapper;
@Autowired
private BatchStudentMappingMapper batchStudentMappingMapper;
@Autowired
private BatchExamsStudentsMapper batchExamsStudentsMapper;
public String addBatch(AddBatchDTO addBatchDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<BatchDictDO>()
.lambda()
.eq(BatchDictDO::getBatchName, addBatchDTO.getBatchName()));
if (count > 0) {
throw new HttpException(40001);
}
BatchDictDO batchDictDO = new BatchDictDO();
BeanUtils.copyProperties(addBatchDTO,batchDictDO);
this.baseMapper.insert(batchDictDO);
List<BatchStudentMappingDO> batchExamStudentsDOS = addBatchDTO.getStudentIds();
for (BatchStudentMappingDO besd : batchExamStudentsDOS) {
besd.setBatchId(batchDictDO.getId());
batchStudentMappingMapper.insert(besd);
//批次下的考试
List<BatchExamDO> batchExamDOS = batchExamMapper.selectList(new QueryWrapper<BatchExamDO>()
.lambda()
.eq(BatchExamDO::getBatchId,batchDictDO.getId()));
for (BatchExamDO batchExamDO : batchExamDOS){
BatchExamStudentsDO batchExamStudentsDO = new BatchExamStudentsDO();
batchExamStudentsDO.setBatchExamId(batchExamDO.getId());
batchExamStudentsDO.setStudentId(besd.getStudentId());
batchExamStudentsDO.setExamCode(besd.getExamCode());
batchExamMapper.insert(batchExamDO);
}
}
return ConstantUtils.ADD_SUCCESS;
}
public String updateBatch(AddBatchDTO addBatchDTO) {
int count = this.baseMapper.selectCount(new QueryWrapper<BatchDictDO>()
.lambda()
.eq(BatchDictDO::getBatchName, addBatchDTO.getBatchName())
.ne(BatchDictDO::getId, addBatchDTO.getId()));
if (count > 0) {
throw new HttpException(40001);
}
BatchDictDO batchDictDO = new BatchDictDO();
BeanUtils.copyProperties(addBatchDTO,batchDictDO);
this.baseMapper.updateById(batchDictDO);
//先删
batchStudentMappingMapper.delete(new QueryWrapper<BatchStudentMappingDO>()
.lambda()
.eq(BatchStudentMappingDO::getBatchId,batchDictDO.getId()));
//批次下的考试
List<BatchExamDO> batchExamDOS = batchExamMapper.selectList(new QueryWrapper<BatchExamDO>()
.lambda()
.eq(BatchExamDO::getBatchId,batchDictDO.getId()));
for (BatchExamDO batchExamDO : batchExamDOS){
batchExamsStudentsMapper.delete(new QueryWrapper<BatchExamStudentsDO>()
.lambda()
.eq(BatchExamStudentsDO::getBatchExamId,batchExamDO.getId()));
}
//后增
List<BatchStudentMappingDO> batchStudentMappingDOS = addBatchDTO.getStudentIds();
for (BatchStudentMappingDO batchStudentMappingDO : batchStudentMappingDOS){
batchStudentMappingDO.setBatchId(batchDictDO.getId());
batchStudentMappingMapper.insert(batchStudentMappingDO);
for (BatchExamDO batchExamDO : batchExamDOS){
BatchExamStudentsDO batchExamStudentsDO = new BatchExamStudentsDO();
batchExamStudentsDO.setBatchExamId(batchExamDO.getId());
batchExamStudentsDO.setStudentId(batchStudentMappingDO.getStudentId());
batchExamStudentsDO.setExamCode(batchExamStudentsDO.getExamCode());
batchExamsStudentsMapper.insert(batchExamStudentsDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
public String deleteBatch(BatchDictDO batchDictDO){
//当前批次下有考试 的话删不掉
Integer count = batchExamMapper.selectCount(new QueryWrapper<BatchExamDO>()
.lambda()
.eq(BatchExamDO::getBatchId, batchDictDO.getId()));
if (count>0){
throw new HttpException(50001);
}
this.baseMapper.deleteById(batchDictDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
public List<BatchesVO> batches(){
List<BatchesVO> batchesVOS = new ArrayList<>();
List<BatchDictDO> batchDictDOS = this.baseMapper.selectList(null);
for (BatchDictDO batchDictDO : batchDictDOS){
BatchesVO batchesVO = new BatchesVO();
BeanUtils.copyProperties(batchDictDO,batchesVO);
//查看 该批次下的学生
List<BatchStudentsVO> batchStudentsVOS = batchStudentMappingMapper.batchStudents(batchDictDO.getId());
batchesVO.setBatchStudentsVOS(batchStudentsVOS);
batchesVOS.add(batchesVO);
}
return batchesVOS;
}
}