|
@@ -1,18 +1,35 @@
|
|
|
package com.keao.edu.user.service.impl;
|
|
|
|
|
|
+import com.keao.edu.auth.api.entity.SysUser;
|
|
|
import com.keao.edu.common.dal.BaseDAO;
|
|
|
+import com.keao.edu.common.exception.BizException;
|
|
|
+import com.keao.edu.common.page.PageInfo;
|
|
|
import com.keao.edu.common.service.impl.BaseServiceImpl;
|
|
|
+import com.keao.edu.common.tenant.TenantContextHolder;
|
|
|
+import com.keao.edu.user.api.entity.ExamRoom;
|
|
|
+import com.keao.edu.user.dao.ExamRoomDao;
|
|
|
import com.keao.edu.user.dao.ExamRoomStudentRelationDao;
|
|
|
+import com.keao.edu.user.dto.ExamRoomStudentRelationDto;
|
|
|
import com.keao.edu.user.entity.ExamRoomStudentRelation;
|
|
|
+import com.keao.edu.user.entity.Subject;
|
|
|
+import com.keao.edu.user.page.ExamRoomStudentRelationQueryInfo;
|
|
|
import com.keao.edu.user.service.ExamRoomStudentRelationService;
|
|
|
+import com.keao.edu.util.collection.MapUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, ExamRoomStudentRelation> implements ExamRoomStudentRelationService {
|
|
|
|
|
|
@Autowired
|
|
|
private ExamRoomStudentRelationDao examRoomStudentRelationDao;
|
|
|
+ @Autowired
|
|
|
+ private ExamRoomDao examRoomDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, ExamRoomStudentRelation> getDAO() {
|
|
@@ -23,4 +40,73 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
public void switchClassRoom(Integer openFlag, Integer examinationBasicId, Integer studentId) {
|
|
|
examRoomStudentRelationDao.switchClassRoom(openFlag,examinationBasicId,studentId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addStudentForRoom(Long examRoomId, String studentIdsStr) {
|
|
|
+ if(Objects.isNull(examRoomId)){
|
|
|
+ throw new BizException("请指定教室");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(studentIdsStr)){
|
|
|
+ throw new BizException("请指定学员");
|
|
|
+ }
|
|
|
+ ExamRoom examRoom = examRoomDao.get(examRoomId);
|
|
|
+ if(Objects.isNull(examRoom)){
|
|
|
+ throw new BizException("教室不存在");
|
|
|
+ }
|
|
|
+ List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
|
|
|
+ Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
|
|
|
+ String[] studentIds = studentIdsStr.split(",");
|
|
|
+ List<ExamRoomStudentRelation> examRoomStudentRelations=new ArrayList<>();
|
|
|
+ for (String studentId : studentIds) {
|
|
|
+ if(existStudentIds.contains(Integer.valueOf(studentId))){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ExamRoomStudentRelation e=new ExamRoomStudentRelation();
|
|
|
+ e.setExaminationBasicId(examRoom.getExaminationBasicId());
|
|
|
+ e.setExamRoomId(examRoom.getId());
|
|
|
+ e.setStudentId(Integer.valueOf(studentId));
|
|
|
+ e.setTenantId(TenantContextHolder.getTenantId().toString());
|
|
|
+ examRoomStudentRelations.add(e);
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(examRoomStudentRelations)){
|
|
|
+ examRoomStudentRelationDao.batchInsert(examRoomStudentRelations);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<ExamRoomStudentRelationDto> findExamRoomStudents(ExamRoomStudentRelationQueryInfo queryInfo) {
|
|
|
+ PageInfo<ExamRoomStudentRelationDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
+
|
|
|
+ List<ExamRoomStudentRelationDto> dataList = new ArrayList<>();
|
|
|
+ int count = this.findCount(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = examRoomStudentRelationDao.findExamRoomStudents(params);
|
|
|
+ List<Integer> studentIds = dataList.stream().map(ExamRoomStudentRelationDto::getStudentId).collect(Collectors.toList());
|
|
|
+ List<Integer> subjectIds = dataList.stream().map(e->e.getExamRegistration().getSubjectId()).collect(Collectors.toList());
|
|
|
+ Map<Integer, String> studentIdNameMap = this.getMap("sys_user", "id_", "real_name_", studentIds, Integer.class, String.class);
|
|
|
+ Map<Integer, String> subjectIdNameMap = this.getMap("subject", "id_", "name_", subjectIds, Integer.class, String.class);
|
|
|
+ for (ExamRoomStudentRelationDto e : dataList) {
|
|
|
+ e.setStudentInfo(new SysUser(e.getStudentId(),studentIdNameMap.get(e.getStudentId())));
|
|
|
+ e.setSubject(new Subject(e.getExamRegistration().getSubjectId(), subjectIdNameMap.get(e.getExamRegistration().getSubjectId())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteStudentFromRoom(Long examRoomId, String studentIdsStr) {
|
|
|
+ if(Objects.isNull(examRoomId)){
|
|
|
+ throw new BizException("请指定教室");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(studentIdsStr)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Integer> studentIds = Arrays.asList(studentIdsStr.split(",")).stream().map(e -> Integer.valueOf(e)).collect(Collectors.toList());
|
|
|
+ examRoomStudentRelationDao.deleteStudentsFromExamRoom(examRoomId, studentIds);
|
|
|
+ }
|
|
|
}
|