DrawLotsGroupJudgesServiceImpl.java
10.3 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
package com.zhongzhi.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.zhongzhi.common.constant.RoleType;
import com.zhongzhi.common.constant.TeachType;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.ConstantUtils;
import com.zhongzhi.dao.DrawLotGroupDictMapper;
import com.zhongzhi.dao.DrawLotsGroupItemsMapper;
import com.zhongzhi.dao.MatchDictDAO;
import com.zhongzhi.dto.drawlots.AddJudgeDTO;
import com.zhongzhi.dto.drawlots.DrawLoginDTO;
import com.zhongzhi.dto.drawlots.JudgeScoreScreenDTO;
import com.zhongzhi.dto.judge.MatchJudgesDTO;
import com.zhongzhi.model.*;
import com.zhongzhi.dao.DrawLotsGroupJudgesMapper;
import com.zhongzhi.service.DrawLotsGroupJudgesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.drawlots.*;
import com.zhongzhi.vo.judge.JudgeInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static com.zhongzhi.service.impl.DrawLotsGroupItemsServiceImpl.findUnselectedElements;
/**
* <p>
* 赛组评委表 服务实现类
* </p>
*
* @author DengMin
* @since 2025-06-19
*/
@Service
public class DrawLotsGroupJudgesServiceImpl extends ServiceImpl<DrawLotsGroupJudgesMapper, DrawLotsGroupJudgesDO> implements DrawLotsGroupJudgesService {
@Autowired
private DrawLotsGroupItemsMapper drawLotsGroupItemsMapper;
@Autowired
private DrawLotGroupDictMapper drawLotGroupDictMapper;
@Override
public IPage<MatchJudgesVO> matchJudges(MatchJudgesDTO matchJudgesDTO) {
Page page = new Page(matchJudgesDTO.getPageNum(), matchJudgesDTO.getPageSize());
return this.baseMapper.matchJudges(page, matchJudgesDTO.getSceneId(), matchJudgesDTO.getUserName(), matchJudgesDTO.getExpectorType(), matchJudgesDTO.getRoleType());
}
@Override
public IPage<SelectJudgesVO> selectJudges(MatchJudgesDTO matchJudgesDTO) {
Page page = new Page(matchJudgesDTO.getPageNum(), matchJudgesDTO.getPageSize());
return this.baseMapper.selectJudges(page, matchJudgesDTO.getSceneId(), matchJudgesDTO.getUserName());
}
@Override
public String removeJudge(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
this.baseMapper.deleteById(drawLotsGroupJudgesDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
@Override
public String updateJudge(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
this.baseMapper.updateById(drawLotsGroupJudgesDO);
return ConstantUtils.SUCCESS_UPDATE;
}
@Override
public String addJudge(AddJudgeDTO addJudgeDTO) {
List<Long> judgeIds = addJudgeDTO.getJudgeIds();
for (Long judgeId : judgeIds) {
DrawLotsGroupJudgesDO drawLotsGroupJudgesDO = new DrawLotsGroupJudgesDO();
drawLotsGroupJudgesDO.setJudgeId(judgeId);
drawLotsGroupJudgesDO.setSceneId(addJudgeDTO.getSceneId());
this.baseMapper.insert(drawLotsGroupJudgesDO);
}
return ConstantUtils.ADD_SUCCESS;
}
@Override
public List<DrawLotsGroupJudgesDO> selectNoDrawLotsJudge(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
return this.baseMapper.selectList(new QueryWrapper<DrawLotsGroupJudgesDO>()
.lambda()
.eq(DrawLotsGroupJudgesDO::getSceneId, drawLotsGroupJudgesDO.getSceneId())
.eq(DrawLotsGroupJudgesDO::getRoleType, drawLotsGroupJudgesDO.getRoleType())
.isNull(DrawLotsGroupJudgesDO::getGroupId));
}
@Override
public String assignJudge(AddJudgeDTO addJudgeDTO) {
List<Long> ids = addJudgeDTO.getIds();
for (Long id : ids) {
DrawLotsGroupJudgesDO drawLotsGroupJudgesDO = this.baseMapper.selectById(id);
drawLotsGroupJudgesDO.setGroupId(addJudgeDTO.getGroupId());
drawLotsGroupJudgesDO.setExpectorType(addJudgeDTO.getExpectorType());
drawLotsGroupJudgesDO.setRoleType(addJudgeDTO.getRoleType());
this.baseMapper.updateById(drawLotsGroupJudgesDO);
}
return ConstantUtils.SUCCESS_UPDATE;
}
@Override
@Transactional(rollbackFor = Exception.class)
public DrawlotsVO drawlots(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
DrawlotsVO drawlotsVO = new DrawlotsVO();
//判断是否已经抽过了
int count = this.baseMapper.selectCount(new QueryWrapper<DrawLotsGroupJudgesDO>()
.lambda()
.eq(DrawLotsGroupJudgesDO::getSceneId, drawLotsGroupJudgesDO.getSceneId())
.eq(DrawLotsGroupJudgesDO::getJudgeId, drawLotsGroupJudgesDO.getJudgeId())
.isNotNull(DrawLotsGroupJudgesDO::getGroupId));
if (count > 0) {
throw new HttpException(10038);
}
//当前老师是什么角色
DrawLotsGroupJudgesDO judge = this.baseMapper.selectOne(new QueryWrapper<DrawLotsGroupJudgesDO>()
.lambda()
.eq(DrawLotsGroupJudgesDO::getSceneId,drawLotsGroupJudgesDO.getSceneId())
.eq(DrawLotsGroupJudgesDO::getJudgeId,drawLotsGroupJudgesDO.getJudgeId()));
List<DrawLotGroupDictDO> drawLotGroupDictDOS = new ArrayList<>();
//判断是组长抽还是组员抽
if (RoleType.TEAMLEADER.equals(judge.getRoleType())) {
//返回还没有组长的组
drawLotGroupDictDOS = this.baseMapper.noLeaderGroup(drawLotsGroupJudgesDO.getSceneId());
} else {
//返回专家类型还没有满员的组 expectorType
drawLotGroupDictDOS = this.baseMapper.noMemberGroup(drawLotsGroupJudgesDO.getSceneId(), judge.getExpectorType());
}
if (drawLotGroupDictDOS.size() == 0) {
throw new HttpException(10036);
}
//随机一个组别
DrawLotGroupDictDO drawLotGroupDictDO = drawLotGroupDictDOS.get(new Random().nextInt(drawLotGroupDictDOS.size()));
//这个组别所有的编号
List<Integer> allNum = this.baseMapper.allNum(drawLotGroupDictDO.getId());
//这个组已经随机的编号
List<Integer> exists = this.baseMapper.existNum(drawLotGroupDictDO.getId());
List<Integer> unselectedElements = findUnselectedElements(allNum, exists);
judge.setGroupNum(unselectedElements.get(new Random().nextInt(unselectedElements.size())));
judge.setGroupId(drawLotGroupDictDO.getId());
this.baseMapper.updateById(judge);
drawlotsVO.setGroupName(drawLotGroupDictDO.getGroupName());
drawlotsVO.setGroupNum(judge.getGroupNum());
drawlotsVO.setExpectorType(judge.getExpectorType());
drawlotsVO.setRoleType(judge.getRoleType());
return drawlotsVO;
}
@Override
public List<JudgeScreenVO> judgeScreen(DrawLotsGroupJudgesDO drawLotsGroupJudgesDO) {
List<JudgeScreenVO> judgeScreenVOS = new ArrayList<>();
// 查每个组别
List<DrawLotGroupDictDO> drawLotGroupDictDOS = drawLotGroupDictMapper.selectList(new QueryWrapper<DrawLotGroupDictDO>()
.lambda()
.eq(DrawLotGroupDictDO::getSceneId, drawLotsGroupJudgesDO.getSceneId())
.orderByAsc(DrawLotGroupDictDO::getId));
for (DrawLotGroupDictDO dlgd : drawLotGroupDictDOS) {
JudgeScreenVO judgeScreenVO = new JudgeScreenVO();
judgeScreenVO.setId(dlgd.getId());
judgeScreenVO.setGroupName(dlgd.getGroupName());
//组别下的评委
List<DrawJudgeInfoVO> drawJudgeInfoVOS = this.baseMapper.drawJudgeInfo(dlgd.getId());
judgeScreenVO.setGroupProjectInfoVOS(drawJudgeInfoVOS);
judgeScreenVOS.add(judgeScreenVO);
}
return judgeScreenVOS;
}
@Override
public LoginVO login(DrawLoginDTO drawLoginDTO) {
return this.baseMapper.login(drawLoginDTO.getName());
}
@Override
public List<JudgeScoreScreenVO> judgeScoreScreen(JudgeScoreScreenDTO judgeScoreScreenDTO) {
List<JudgeScoreScreenVO> result = new ArrayList<>();
//项目编号
List<Integer> integers = judgeScoreScreenDTO.getGroupNums();
DrawLotGroupDictDO drawLotGroupDictDO = drawLotGroupDictMapper.selectById(judgeScoreScreenDTO.getGroupId());
for (Integer integer : integers) {
JudgeScoreScreenVO judgeScoreScreenVO = new JudgeScoreScreenVO();
judgeScoreScreenVO.setGroupName(drawLotGroupDictDO.getGroupName());
judgeScoreScreenVO.setGroupNum(integer);
List<ScoreScreenVO> scoreScreenVOS = this.baseMapper.judgeScoreScreen(judgeScoreScreenDTO.getGroupId(), integer);
judgeScoreScreenVO.setScoreScreenVOS(scoreScreenVOS);
DrawLotsGroupItemsDO drawLotsGroupItemsDO = drawLotsGroupItemsMapper.selectOne(new QueryWrapper<DrawLotsGroupItemsDO>()
.lambda()
.eq(DrawLotsGroupItemsDO::getGroupId, judgeScoreScreenDTO.getGroupId())
.eq(DrawLotsGroupItemsDO::getGroupNum, integer));
judgeScoreScreenVO.setTotalScore(drawLotsGroupItemsDO.getTotalScore());
result.add(judgeScoreScreenVO);
}
return result;
}
@Override
public LeaderFullVO leaderFull(DrawLotGroupDictDO drawLotGroupDictDO) {
LeaderFullVO leaderFullVO = new LeaderFullVO();
//判断组长有没有抽齐
int cnt = this.baseMapper.selectCount(new QueryWrapper<DrawLotsGroupJudgesDO>()
.lambda()
.eq(DrawLotsGroupJudgesDO::getSceneId, drawLotGroupDictDO.getSceneId())
.eq(DrawLotsGroupJudgesDO::getRoleType, RoleType.TEAMLEADER)
.isNull(DrawLotsGroupJudgesDO::getGroupId));
if (cnt > 0) {
leaderFullVO.setFullFlag(false);
}else {
leaderFullVO.setFullFlag(true);
}
return leaderFullVO;
}
@Override
public JudgeFullInfoVO judgeInfo(DrawLotsJudgeNumDO drawLotsJudgeNumDO) {
return this.baseMapper.judgeInfo(drawLotsJudgeNumDO.getGroupId(),drawLotsJudgeNumDO.getGroupNum());
}
}