Joburgess il y a 5 ans
Parent
commit
32cc15d1e1

+ 3 - 8
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/ExamSongController.java

@@ -2,7 +2,6 @@ package com.keao.edu.user.controller;
 
 import com.keao.edu.common.controller.BaseController;
 import com.keao.edu.common.entity.HttpResponseResult;
-import com.keao.edu.common.exception.BizException;
 import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.page.QueryInfo;
 import com.keao.edu.common.tenant.TenantContextHolder;
@@ -12,12 +11,8 @@ import com.keao.edu.user.service.ExamSongService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
 import java.util.List;
@@ -55,7 +50,7 @@ public class ExamSongController extends BaseController {
 
     @ApiOperation("新增曲库")
     @PostMapping(value = "/add")
-    public HttpResponseResult add(ExamSong examSong) {
+    public HttpResponseResult add(@RequestBody ExamSong examSong) {
         examSong.setTenantId(TenantContextHolder.getTenantId().toString());
         examSongService.insert(examSong);
         return succeed();
@@ -63,7 +58,7 @@ public class ExamSongController extends BaseController {
 
     @ApiOperation("更新曲库")
     @PostMapping(value = "/update")
-    public HttpResponseResult update(ExamSong examSong) {
+    public HttpResponseResult update(@RequestBody ExamSong examSong) {
         examSong.setUpdateTime(new Date());
         examSongService.update(examSong);
         return succeed();

+ 65 - 4
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -3,6 +3,7 @@ package com.keao.edu.user.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.keao.edu.auth.api.entity.SysUser;
 import com.keao.edu.common.dal.BaseDAO;
 import com.keao.edu.common.enums.YesOrNoEnum;
 import com.keao.edu.common.exception.BizException;
@@ -10,10 +11,7 @@ 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.ExamRegistrationDao;
-import com.keao.edu.user.dao.ExamRoomDao;
-import com.keao.edu.user.dao.ExamRoomStudentRelationDao;
-import com.keao.edu.user.dao.ExaminationBasicDao;
+import com.keao.edu.user.dao.*;
 import com.keao.edu.user.dto.ExamRoomDto;
 import com.keao.edu.user.dto.ExamRoomStatisticsDto;
 import com.keao.edu.user.api.enums.ExamModeEnum;
@@ -45,6 +43,8 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	private ExamRegistrationDao examRegistrationDao;
 	@Autowired
 	private ExaminationBasicDao examinationBasicDao;
+	@Autowired
+	private SysUserDao sysUserDao;
 
 	@Override
 	public BaseDAO<Long, ExamRoom> getDAO() {
@@ -118,8 +118,12 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			if(Objects.isNull(er.getExamStartTime())||Objects.isNull(er.getExamEndTime())){
 				throw new BizException("请指定考试时间");
 			}
+			if(er.getExamStartTime().compareTo(er.getExamEndTime())>=0){
+				throw new BizException("考试时间异常");
+			}
 			examRooms.add(er);
 		}
+		checkRoomTeachers(examRooms);
 		examRoomDao.batchInsert(examRooms);
 	}
 
@@ -182,7 +186,11 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 
 	@Override
 	public void checkRoomTeachers(List<ExamRoom> examRooms) {
+		if(CollectionUtils.isEmpty(examRooms)){
+			throw new BizException("考场信息异常");
+		}
 		Set<String> days=new HashSet<>();
+		Map<Integer, List<ExamRoom>> teacherRoomMap = new HashMap<>();
 		for (ExamRoom examRoom : examRooms) {
 			if(Objects.nonNull(examRoom.getExamStartTime())){
 				days.add(DateUtil.dateToString(examRoom.getExamStartTime(), "yyyy-MM-dd"));
@@ -190,7 +198,60 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			if(Objects.nonNull(examRoom.getExamEndTime())){
 				days.add(DateUtil.dateToString(examRoom.getExamEndTime(), "yyyy-MM-dd"));
 			}
+			if(Objects.nonNull(examRoom.getMainTeacherUserId())&&!teacherRoomMap.containsKey(examRoom.getMainTeacherUserId())){
+				List<ExamRoom> teacherExamRooms=new ArrayList<>();
+				teacherExamRooms.add(examRoom);
+				teacherRoomMap.put(examRoom.getMainTeacherUserId(), teacherExamRooms);
+			}else if(teacherRoomMap.containsKey(examRoom.getMainTeacherUserId())){
+				teacherRoomMap.get(examRoom.getMainTeacherUserId()).add(examRoom);
+			}
+			if(StringUtils.isBlank(examRoom.getAssistantTeacherUserIdList())){
+				continue;
+			}
+			String[] teacherStrIds = examRoom.getAssistantTeacherUserIdList().split(",");
+			for (String teacherStrId : teacherStrIds) {
+				if(!teacherRoomMap.containsKey(Integer.valueOf(teacherStrId))){
+					List<ExamRoom> teacherExamRooms=new ArrayList<>();
+					teacherExamRooms.add(examRoom);
+					teacherRoomMap.put(Integer.valueOf(teacherStrId), teacherExamRooms);
+				}else if(teacherRoomMap.containsKey(Integer.valueOf(teacherStrId))){
+					teacherRoomMap.get(Integer.valueOf(teacherStrId)).add(examRoom);
+				}
+			}
+		}
+		if(CollectionUtils.isEmpty(days)){
+			throw new BizException("考场信息异常");
+		}
+		List<ExamRoom> withDays = examRoomDao.getWithDays(new ArrayList<>(days));
+		for (ExamRoom examRoom : withDays) {
+			if(teacherRoomMap.containsKey(examRoom.getMainTeacherUserId())){
+				teacherRoomMap.get(examRoom.getMainTeacherUserId()).add(examRoom);
+			}
+			if(StringUtils.isBlank(examRoom.getAssistantTeacherUserIdList())){
+				continue;
+			}
+			String[] teacherStrIds = examRoom.getAssistantTeacherUserIdList().split(",");
+			for (String teacherStrId : teacherStrIds) {
+				if(teacherRoomMap.containsKey(Integer.valueOf(teacherStrId))){
+					teacherRoomMap.get(Integer.valueOf(teacherStrId)).add(examRoom);
+				}
+			}
 		}
 
+		for (Map.Entry<Integer, List<ExamRoom>> teacherRoomEntry : teacherRoomMap.entrySet()) {
+			List<ExamRoom> teacherRooms = teacherRoomEntry.getValue();
+			teacherRooms.sort(Comparator.comparing(ExamRoom::getExamStartTime));
+			for (int i = 0; i < teacherRooms.size(); i++) {
+				if(i==0){
+					continue;
+				}
+				ExamRoom preExamRoom=teacherRooms.get(i-1);
+				ExamRoom currentExamRoom = teacherRooms.get(i);
+				if(preExamRoom.getExamEndTime().compareTo(currentExamRoom.getExamStartTime())>0){
+					SysUser sysUser = sysUserDao.get(teacherRoomEntry.getKey());
+					throw new BizException("{}教师时间存在冲突", sysUser.getRealName());
+				}
+			}
+		}
 	}
 }

+ 1 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamRegistrationMapper.xml

@@ -29,7 +29,7 @@
 		<result column="update_time_" property="updateTime" />
 		<result column="tenant_id_" property="tenantId" />
 		<result column="memo_" property="memo" />
-		<association property="sysUser" columnPrefix="sys_user_" resultMap="com.keao.edu.user.dao.SysUserDao.SysUser"/>
+		<association property="sysUser" columnPrefix="sys_user_" resultMap="com.keao.edu.user.dao.StudentDao.Student"/>
 		<association property="subject" columnPrefix="subject_" resultMap="com.keao.edu.user.dao.SubjectDao.Subject"/>
 	</resultMap>
 

+ 7 - 2
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamRoomMapper.xml

@@ -247,7 +247,12 @@
 			exam_room 
 		WHERE
 			DATE_FORMAT( exam_start_time_, '%Y-%m-%d' ) IN 
-			<!--<foreach collection="" -->
-			<!--OR DATE_FORMAT( exam_end_time_, '%Y-%m-%d' ) IN ( )-->
+			<foreach collection="days" item="day" separator="," open="(" close=")" >
+				#{day}
+			</foreach>
+			OR DATE_FORMAT( exam_end_time_, '%Y-%m-%d' ) IN
+			<foreach collection="days" item="day" separator="," open="(" close=")" >
+				#{day}
+			</foreach>
 	</select>
 </mapper>